OSDN Git Service

#37287 #37353 (2.2.0.89) direction型を定義し、型の置換を継続中。 / Define typedef direction, ongoing...
[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 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 double real;      /*!< doubleをreal型として定義 / Since float's are silly, hard code real numbers as doubles */
48
49
50 /*!
51  * @brief エラーコードの定義 / Error codes for function return values
52  * @details
53  * 一般に成功時0、失敗時負数、何らかの問題時整数とする。
54  * Success = 0, Failure = -N, Problem = +N 
55  */
56 typedef int errr;
57
58 #undef uint
59 #define uint uint_hack /*!< 非マッキントッシュ環境で重複を避けるためのuint_hack型定義 / Hack -- prevent problems with non-MACINTOSH */
60
61 #undef huge
62 #define huge huge_hack /*!< WINDOWS環境で重複を避けるためのhuge_hack定義 / Hack -- prevent problems with WINDOWS */
63
64 #undef byte
65 #define byte byte_hack /*!< AMIGA環境で重複を避けるためのbyte_hack定義 / Hack -- prevent problems with AMIGA */
66
67 #undef bool
68 #define bool bool_hack /*!< C++環境で重複を避けるためのbool_hack定義 Hack -- prevent problems with C++ */
69
70
71 /* Note that "signed char" is not always "defined" */
72 /* So always use "s16b" to hold small signed values */
73 /* A signed byte of memory */
74 /* typedef signed char syte; */
75
76 typedef unsigned char byte; /*!< byte型をunsighned charとして定義 / Note that unsigned values can cause math problems / An unsigned byte of memory */
77 typedef char bool; /*!< bool型をcharとして定義 / Note that a bool is smaller than a full "int" / Simple True/False type */
78 typedef int sint; /*!< sint型をintとして定義 / A signed, standard integer (at least 2 bytes) */
79 typedef unsigned int uint; /* uint型をintとして定義 /  An unsigned, "standard" integer (often pre-defined) */
80
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 typedef s16b idx;                       /*!< ゲーム中のID型を定義 */
108 typedef byte position;          /*!< ゲーム中の座標型を定義 */
109 typedef s16b hit_point;         /*!< ゲーム中のHP/ダメージ型を定義 */
110 typedef s16b hit_prob;          /*!< ゲーム中の命中修正値を定義 */
111 typedef s16b base_status;       /*!< ゲーム中の基礎能力値型を定義 */
112 typedef byte item_number;       /*!< ゲーム中のアイテム数型を定義 */
113 typedef s16b action_energy;     /*!< ゲーム中の行動エネルギー型を定義 */
114 typedef s16b armour_class;      /*!< ゲーム中の行動アーマークラス型を定義 */
115 typedef s16b time_effect;   /*!< ゲーム中の時限期間の型を定義 */
116 typedef byte character_idx; /*!< ゲーム中のキャラクター特性各種IDの型を定義 */
117 typedef byte discount_rate; /*!< ゲーム中の値引き率の型を定義 */
118
119 typedef s16b player_level;  /*!< ゲーム中のプレイヤーレベルの型を定義 */
120 typedef int direction;          /*!< ゲーム中の方角の型定義*/
121
122 /*** Pointers to all the basic types defined above ***/
123
124 typedef real *real_ptr;
125 typedef errr *errr_ptr;
126 typedef char *char_ptr;
127 typedef byte *byte_ptr;
128 typedef bool *bool_ptr;
129 typedef sint *sint_ptr;
130 typedef uint *uint_ptr;
131 typedef long *long_ptr;
132 typedef huge *huge_ptr;
133 typedef s16b *s16b_ptr;
134 typedef u16b *u16b_ptr;
135 typedef s32b *s32b_ptr;
136 typedef u32b *u32b_ptr;
137 typedef vptr *vptr_ptr;
138 typedef cptr *cptr_ptr;
139
140
141
142 /*** Pointers to Functions of special types (for various purposes) ***/
143
144 /* A generic function takes a user data and a special data */
145 typedef errr    (*func_gen)(vptr, vptr);
146
147 /* An equality testing function takes two things to compare (bool) */
148 typedef bool    (*func_eql)(vptr, vptr);
149
150 /* A comparison function takes two things and to compare (-1,0,+1) */
151 typedef sint    (*func_cmp)(vptr, vptr);
152
153 /* A hasher takes a thing (and a max hash size) to hash (0 to siz - 1) */
154 typedef uint    (*func_hsh)(vptr, uint);
155
156 /* A key extractor takes a thing and returns (a pointer to) some key */
157 typedef vptr    (*func_key)(vptr);
158
159
160
161 #endif
162