OSDN Git Service

#37324 (2.2.0.28) obj-desc.spo の出力内容に、にアイテム生成chance値を追加。 / Add chance values to info...
[hengband/hengband.git] / src / h-type.h
1 /*!
2  * @file h-type.h
3  * @brief ゲーム中に用いる変数型定義 /
4  * Basic "types".
5  * @date 2014/08/17
6  * @author
7  * 不明(変愚蛮怒スタッフ?)
8  * @details
9  * <pre>
10  * Note the attempt to make all basic types have 4 letters.
11  * This improves readibility and standardizes the code.
12  * Likewise, all complex types are at least 4 letters.
13  * Thus, almost every three letter word is a legal variable.
14  * But beware of certain reserved words ('for' and 'if' and 'do').
15  * Note that the type used in structures for bit flags should be uint.
16  * As long as these bit flags are sequential, they will be space smart.
17  * Note that on some machines, apparently "signed char" is illegal.
18  * It must be true that char/byte takes exactly 1 byte
19  * It must be true that sind/uind takes exactly 2 bytes
20  * It must be true that sbig/ubig takes exactly 4 bytes
21  * On Sparc's, a sint takes 4 bytes (2 is legal)
22  * On Sparc's, a uint takes 4 bytes (2 is legal)
23  * On Sparc's, a long takes 4 bytes (8 is legal)
24  * On Sparc's, a huge takes 4 bytes (8 is legal)
25  * On Sparc's, a vptr takes 4 bytes (8 is legal)
26  * On Sparc's, a real takes 8 bytes (4 is legal)
27  * Note that some files have already been included by "h-include.h"
28  * These include <stdio.h> and <sys/types>, which define some types
29  * In particular, uint is defined so we do not have to define it
30  * Also, see <limits.h> for min/max values for sind, uind, long, huge
31  * (SHRT_MIN, SHRT_MAX, USHRT_MAX, LONG_MIN, LONG_MAX, ULONG_MAX)
32  * These limits should be verified and coded into "h-constant.h".
33  * </pre>
34  */
35
36 #ifndef INCLUDED_H_TYPE_H
37 #define INCLUDED_H_TYPE_H
38
39 #ifdef HAVE_STDINT_H
40 #include <stdint.h>
41 #endif
42
43 /*** Special 4-5 letter names for some standard types ***/
44
45 typedef void *vptr;       /*!< void型ポインタ定義 / A standard pointer (to "void" because ANSI C says so) */
46 typedef const char *cptr; /*!< 文字列定数用ポインタ定義 / A simple pointer (to unmodifiable strings) */
47 typedef const unsigned char *ucptr; /*!< 非負文字列定数用ポインタ定義 / A simple pointer (to unmodifiable strings) */
48 typedef double real;      /*!< doubleをreal型として定義 / Since float's are silly, hard code real numbers as doubles */
49
50
51 /*!
52  * @brief エラーコードの定義 / Error codes for function return values
53  * @details
54  * 一般に成功時0、失敗時負数、何らかの問題時整数とする。
55  * Success = 0, Failure = -N, Problem = +N 
56  */
57 typedef int errr;
58
59 #undef uint
60 #define uint uint_hack /*!< 非マッキントッシュ環境で重複を避けるためのuint_hack型定義 / Hack -- prevent problems with non-MACINTOSH */
61
62 #undef huge
63 #define huge huge_hack /*!< WINDOWS環境で重複を避けるためのhuge_hack定義 / Hack -- prevent problems with WINDOWS */
64
65 #undef byte
66 #define byte byte_hack /*!< AMIGA環境で重複を避けるためのbyte_hack定義 / Hack -- prevent problems with AMIGA */
67
68 #undef bool
69 #define bool bool_hack /*!< C++環境で重複を避けるためのbool_hack定義 Hack -- prevent problems with C++ */
70
71
72 /* Note that "signed char" is not always "defined" */
73 /* So always use "s16b" to hold small signed values */
74 /* A signed byte of memory */
75 /* typedef signed char syte; */
76
77 typedef unsigned char byte; /*!< byte型をunsighned charとして定義 / Note that unsigned values can cause math problems / An unsigned byte of memory */
78 typedef char bool; /*!< bool型をcharとして定義 / Note that a bool is smaller than a full "int" / Simple True/False type */
79 typedef int sint; /*!< sint型をintとして定義 / A signed, standard integer (at least 2 bytes) */
80 typedef unsigned int uint; /* uint型をintとして定義 /  An unsigned, "standard" integer (often pre-defined) */
81
82 /* The largest possible signed integer (pre-defined) */
83 /* typedef long long; */
84
85 /* The largest possible unsigned integer */
86 typedef unsigned long huge;
87
88 /* Signed/Unsigned 16 bit value */
89 #ifdef HAVE_STDINT_H
90 typedef int16_t s16b;
91 typedef uint16_t u16b;
92 #else
93 typedef signed short s16b;
94 typedef unsigned short u16b;
95 #endif
96
97 /* Signed/Unsigned 32 bit value */
98 #ifdef HAVE_STDINT_H
99 typedef int32_t s32b;
100 typedef uint32_t u32b;
101 #else
102 typedef signed long s32b;
103 typedef unsigned long u32b;
104 #endif
105
106
107
108
109 /*** Pointers to all the basic types defined above ***/
110
111 typedef real *real_ptr;
112 typedef errr *errr_ptr;
113 typedef char *char_ptr;
114 typedef byte *byte_ptr;
115 typedef bool *bool_ptr;
116 typedef sint *sint_ptr;
117 typedef uint *uint_ptr;
118 typedef long *long_ptr;
119 typedef huge *huge_ptr;
120 typedef s16b *s16b_ptr;
121 typedef u16b *u16b_ptr;
122 typedef s32b *s32b_ptr;
123 typedef u32b *u32b_ptr;
124 typedef vptr *vptr_ptr;
125 typedef cptr *cptr_ptr;
126
127
128
129 /*** Pointers to Functions of special types (for various purposes) ***/
130
131 /* A generic function takes a user data and a special data */
132 typedef errr    (*func_gen)(vptr, vptr);
133
134 /* An equality testing function takes two things to compare (bool) */
135 typedef bool    (*func_eql)(vptr, vptr);
136
137 /* A comparison function takes two things and to compare (-1,0,+1) */
138 typedef sint    (*func_cmp)(vptr, vptr);
139
140 /* A hasher takes a thing (and a max hash size) to hash (0 to siz - 1) */
141 typedef uint    (*func_hsh)(vptr, uint);
142
143 /* A key extractor takes a thing and returns (a pointer to) some key */
144 typedef vptr    (*func_key)(vptr);
145
146
147
148 #endif
149