OSDN Git Service

[Refactor] #37353 _ftype, _fcreator 宣言を util.h へ移動.
[hengband/hengband.git] / src / util.h
1 #pragma once
2
3 /*
4  * Hack -- Prepare to use the "Secure" routines
5  */
6 #if defined(SET_UID) && defined(SECURE)
7 extern int PlayerUID;
8 # define getuid() PlayerUID
9 # define geteuid() PlayerUID
10 #endif
11
12 #define KEYMAP_MODE_ORIG        0 /*!< \83I\83\8a\83W\83i\83\8b\83L\81[\94z\92u / Mode for original keyset commands */
13 #define KEYMAP_MODE_ROGUE       1 /*!< \83\8d\81[\83O\83\89\83C\83N\83L\81[\94z\92u / Mode for roguelike keyset commands */
14 #define KEYMAP_MODES            2 /*!< \83L\81[\94z\92u\82Ì\90\94 / Number of keymap modes */
15
16 #define SCREEN_BUF_MAX_SIZE (4 * 65536) /*!< Max size of screen dump buffer */
17
18 /* Cheat Info Type */
19 #define CHEAT_OBJECT 0
20 #define CHEAT_MONSTER 1
21 #define CHEAT_DUNGEON 2
22 #define CHEAT_MISC 3
23
24 /*
25  * Max numbers of macro trigger names
26  */
27 #define MAX_MACRO_MOD 12
28 #define MAX_MACRO_TRIG 200 /*!< \93o\98^\82ð\8b\96\82·\83}\83N\83\8d\81i\83g\83\8a\83K\81[\81j\82Ì\8dÅ\91å\90\94 */
29
30 /*
31  * Object flags
32  *
33  * Old variables for object flags such as flags1, flags2, and flags3
34  * are obsolated.  Now single array flgs[TR_FLAG_SIZE] contains all
35  * object flags.  And each flag is refered by single index number
36  * instead of a bit mask.
37  *
38  * Therefore it's very easy to add a lot of new flags; no one need to
39  * worry about in which variable a new flag should be put, nor to
40  * modify a huge number of files all over the source directory at once
41  * to add new flag variables such as flags4, a_ability_flags1, etc...
42  *
43  * All management of flags is now treated using a set of macros
44  * instead of bit operations.
45  * Note: These macros are using division, modulo, and bit shift
46  * operations, and it seems that these operations are rather slower
47  * than original bit operation.  But since index numbers are almost
48  * always given as constant, such slow operations are performed in the
49  * compile time.  So there is no problem on the speed.
50  *
51  * Exceptions of new flag management is a set of flags to control
52  * object generation and the curse flags.  These are not yet rewritten
53  * in new index form; maybe these have no merit of rewriting.
54  */
55
56 #define have_flag(ARRAY, INDEX) !!((ARRAY)[(INDEX)/32] & (1L << ((INDEX)%32)))
57 #define add_flag(ARRAY, INDEX) ((ARRAY)[(INDEX)/32] |= (1L << ((INDEX)%32)))
58 #define remove_flag(ARRAY, INDEX) ((ARRAY)[(INDEX)/32] &= ~(1L << ((INDEX)%32)))
59 #define is_pval_flag(INDEX) ((TR_STR <= (INDEX) && (INDEX) <= TR_MAGIC_MASTERY) || (TR_STEALTH <= (INDEX) && (INDEX) <= TR_BLOWS))
60 #define have_pval_flags(ARRAY) !!((ARRAY)[0] & (0x00003f7f))
61
62  /*
63    Language selection macro
64  */
65 #ifdef JP
66 #define _(JAPANESE,ENGLISH) (JAPANESE)
67 #else
68 #define _(JAPANESE,ENGLISH) (ENGLISH)
69 #endif
70
71
72  /*
73  * Sort-array element
74  */
75 typedef struct tag_type tag_type;
76
77 struct tag_type
78 {
79         int tag;
80         int index;
81 };
82
83 /*
84  * An entry for the object/monster allocation functions
85  *
86  * Pass 1 is determined from allocation information
87  * Pass 2 is determined from allocation restriction
88  * Pass 3 is determined from allocation calculation
89  */
90
91 typedef struct alloc_entry alloc_entry;
92
93 struct alloc_entry
94 {
95         KIND_OBJECT_IDX index;          /* The actual index */
96
97         DEPTH level;            /* Base dungeon level */
98         PROB prob1;             /* Probability, pass 1 */
99         PROB prob2;             /* Probability, pass 2 */
100         PROB prob3;             /* Probability, pass 3 */
101
102         u16b total;             /* Unused for now */
103 };
104
105 extern u32b message__next;
106 extern u32b message__last;
107 extern u32b message__head;
108 extern u32b message__tail;
109 extern u32b *message__ptr;
110 extern char *message__buf;
111
112 extern bool msg_flag;
113
114 extern s16b macro__num;
115 extern concptr *macro__pat;
116 extern concptr *macro__act;
117 extern bool *macro__cmd;
118 extern char *macro__buf;
119
120 extern bool get_com_no_macros;
121
122 extern bool inkey_base;
123 extern bool inkey_xtra;
124 extern bool inkey_scan;
125 extern bool inkey_flag;
126
127 /*
128  * Automatically generated "variable" declarations
129  */
130 extern int max_macrotrigger;
131 extern concptr macro_template;
132 extern concptr macro_modifier_chr;
133 extern concptr macro_modifier_name[MAX_MACRO_MOD];
134 extern concptr macro_trigger_name[MAX_MACRO_TRIG];
135 extern concptr macro_trigger_keycode[2][MAX_MACRO_TRIG];
136
137 extern COMMAND_CODE command_cmd;
138 extern COMMAND_ARG command_arg;
139 extern s16b command_rep;
140 extern DIRECTION command_dir;
141 extern s16b command_see;
142 extern TERM_LEN command_gap;
143 extern s16b command_wrk;
144 extern s16b command_new;
145
146 extern concptr keymap_act[KEYMAP_MODES][256];
147
148 /*** Music constants ***/
149
150 #define MUSIC_BASIC_DEFAULT    0
151 #define MUSIC_BASIC_GAMEOVER   1
152 #define MUSIC_BASIC_EXIT       2
153 #define MUSIC_BASIC_TOWN       3
154 #define MUSIC_BASIC_FIELD1     4
155 #define MUSIC_BASIC_FIELD2     5
156 #define MUSIC_BASIC_FIELD3     6
157 #define MUSIC_BASIC_DUN_LOW    7
158 #define MUSIC_BASIC_DUN_MED    8
159 #define MUSIC_BASIC_DUN_HIGH   9
160 #define MUSIC_BASIC_DUN_FEEL1 10
161 #define MUSIC_BASIC_DUN_FEEL2 11
162 #define MUSIC_BASIC_WINNER    12
163 #define MUSIC_BASIC_BUILD     13
164 #define MUSIC_BASIC_WILD      14
165 #define MUSIC_BASIC_QUEST     15
166 #define MUSIC_BASIC_ARENA     16
167 #define MUSIC_BASIC_BATTLE    17
168 #define MUSIC_BASIC_QUEST_CLEAR 18
169 #define MUSIC_BASIC_FINAL_QUEST_CLEAR 19
170 #define MUSIC_BASIC_AMBUSH    20
171 #define MUSIC_BASIC_MAX       21 /*!< BGM\92è\8b`\82Ì\8dÅ\91å\90\94 */
172
173 /*** Sound constants ***/
174
175 /*
176  * Mega-Hack -- some primitive sound support (see "main-win.c")
177  *
178  * Some "sound" constants for "Term_xtra(TERM_XTRA_SOUND, val)"
179  */
180 #define SOUND_HIT        1
181 #define SOUND_MISS       2
182 #define SOUND_FLEE       3
183 #define SOUND_DROP       4
184 #define SOUND_KILL       5
185 #define SOUND_LEVEL      6
186 #define SOUND_DEATH      7
187 #define SOUND_STUDY      8
188 #define SOUND_TELEPORT   9
189 #define SOUND_SHOOT     10
190 #define SOUND_QUAFF     11
191 #define SOUND_ZAP       12
192 #define SOUND_WALK      13
193 #define SOUND_TPOTHER   14
194 #define SOUND_HITWALL   15
195 #define SOUND_EAT       16
196 #define SOUND_STORE1    17
197 #define SOUND_STORE2    18
198 #define SOUND_STORE3    19
199 #define SOUND_STORE4    20
200 #define SOUND_DIG       21
201 #define SOUND_OPENDOOR  22
202 #define SOUND_SHUTDOOR  23
203 #define SOUND_TPLEVEL   24
204 #define SOUND_SCROLL    25
205 #define SOUND_BUY           26
206 #define SOUND_SELL          27
207 #define SOUND_WARN          28
208 #define SOUND_ROCKET    29 /*!< Somebody's shooting rockets */
209 #define SOUND_N_KILL    30 /*!< The player kills a non-living/undead monster */
210 #define SOUND_U_KILL    31 /*!< The player kills a unique */
211 #define SOUND_QUEST     32 /*!< The player has just completed a quest */
212 #define SOUND_HEAL      33 /*!< The player was healed a little bit */
213 #define SOUND_X_HEAL    34 /*!< The player was healed full health */
214 #define SOUND_BITE      35 /*!< A monster bites you */
215 #define SOUND_CLAW      36 /*!< A monster claws you */
216 #define SOUND_M_SPELL   37 /*!< A monster casts a miscellaneous spell */
217 #define SOUND_SUMMON    38 /*!< A monster casts a summoning spell  */
218 #define SOUND_BREATH    39 /*!< A monster breathes */
219 #define SOUND_BALL      40 /*!< A monster casts a ball / bolt spell */
220 #define SOUND_M_HEAL    41 /*!< A monster heals itself somehow */
221 #define SOUND_ATK_SPELL 42 /*!< A monster casts a misc. offensive spell */
222 #define SOUND_EVIL      43 /*!< Something nasty has just happened! */
223 #define SOUND_TOUCH     44 /*!< A monster touches you */
224 #define SOUND_STING     45 /*!< A monster stings you */
225 #define SOUND_CRUSH     46 /*!< A monster crushes / envelopes you */
226 #define SOUND_SLIME     47 /*!< A monster drools/spits/etc on you */
227 #define SOUND_WAIL      48 /*!< A monster wails */
228 #define SOUND_WINNER    49 /*!< Just won the game! */
229 #define SOUND_FIRE      50 /*!< An item was burned  */
230 #define SOUND_ACID      51 /*!< An item was destroyed by acid */
231 #define SOUND_ELEC      52 /*!< An item was destroyed by electricity */
232 #define SOUND_COLD      53 /*!< An item was shattered */
233 #define SOUND_ILLEGAL   54 /*!< Illegal command attempted */
234 #define SOUND_FAIL      55 /*!< Fail to get a spell off / activate an item */
235 #define SOUND_WAKEUP    56 /*!< A monster wakes up */
236 #define SOUND_INVULN    57 /*!< Invulnerability! */
237 #define SOUND_FALL      58 /*!< Falling through a trapdoor... */
238 #define SOUND_PAIN      59 /*!< A monster is in pain! */
239 #define SOUND_DESTITEM  60 /*!< An item was destroyed by misc. means */
240 #define SOUND_MOAN      61 /*!< A monster makes a moan/beg/insult attack */
241 #define SOUND_SHOW      62 /*!< A monster makes a "show" attack */
242 #define SOUND_UNUSED    63 /*!< (no sound for gaze attacks) */
243 #define SOUND_EXPLODE   64 /*!< Something (or somebody) explodes */
244 #define SOUND_GLASS     65 /*!< A glass feature was crashed */
245 #define SOUND_REFLECT   66 /*!< A bolt was reflected */
246
247 /*
248  * Mega-Hack -- maximum known sounds
249  */
250 #define SOUND_MAX 67 /*!< \8cø\89Ê\89¹\92è\8b`\82Ì\8dÅ\91å\90\94 */
251
252 /*!
253  * @brief \96Á\8fî\95ñ\82Ì\8dÅ\91å\90\94 / Maximum number of "quarks" (see "io.c")
254  * @note
255  * Default: assume at most 512 different inscriptions are used<br>
256  * Was 512... 256 quarks added for random artifacts<br>
257  */
258 #define QUARK_MAX       768
259
260 /*
261  * OPTION: Maximum number of messages to remember (see "io.c")
262  * Default: assume maximal memorization of 2048 total messages
263  */
264 #define MESSAGE_MAX  81920
265
266 /*
267  * OPTION: Maximum space for the message text buffer (see "io.c")
268  * Default: assume that each of the 2048 messages is repeated an
269  * average of three times, and has an average length of 48
270  */
271 #define MESSAGE_BUF 655360
272
273 /*
274  * Hack -- The main "screen"
275  */
276 #define term_screen     (angband_term[0])
277
278 /*
279  * Hack -- conditional (or "bizarre") externs
280  */
281
282 #ifdef SET_UID
283 extern void user_name(char *buf, int id);
284 #endif
285
286 #if 0
287 #ifndef HAS_STRICMP
288 extern int stricmp(concptr a, concptr b);
289 #endif
290 #endif
291
292 #ifndef HAVE_USLEEP
293 extern int usleep(huge usecs);
294 #endif
295
296 #if defined(MAC_MPW) && defined(CARBON)
297 extern void convert_pathname(char *path);
298 #endif
299
300 #if defined(MACH_O_CARBON)
301 extern void fsetfileinfo(concptr path, u32b fcreator, u32b ftype);
302 #endif
303
304 #if defined(MAC_MPW) || defined(MACH_O_CARBON)
305 /* Globals needed */
306 extern  u32b _ftype;
307 extern  u32b _fcreator;
308 #endif
309
310 extern const char hexsym[16];
311
312 extern errr path_parse(char *buf, int max, concptr file);
313 extern errr path_build(char *buf, int max, concptr path, concptr file);
314 extern FILE *my_fopen(concptr file, concptr mode);
315 extern FILE *my_fopen_temp(char *buf, int max);
316 extern errr my_fgets(FILE *fff, char *buf, huge n);
317 extern errr my_fputs(FILE *fff, concptr buf, huge n);
318 extern errr my_fclose(FILE *fff);
319 extern errr fd_kill(concptr file);
320 extern errr fd_move(concptr file, concptr what);
321 extern errr fd_copy(concptr file, concptr what);
322 extern int fd_make(concptr file, BIT_FLAGS mode);
323 extern int fd_open(concptr file, int flags);
324 extern errr fd_lock(int fd, int what);
325 extern errr fd_seek(int fd, huge n);
326 extern errr fd_chop(int fd, huge n);
327 extern errr fd_read(int fd, char *buf, huge n);
328 extern errr fd_write(int fd, concptr buf, huge n);
329 extern errr fd_close(int fd);
330 extern void flush(void);
331 extern void bell(void);
332 extern errr play_music(int type, int num);
333 extern void select_floor_music(void);
334 extern void sound(int num);
335 extern void move_cursor(int row, int col);
336 extern void text_to_ascii(char *buf, concptr str);
337 extern void ascii_to_text(char *buf, concptr str);
338 extern errr macro_add(concptr pat, concptr act);
339 extern sint macro_find_exact(concptr pat);
340 extern char inkey(void);
341 extern concptr quark_str(STR_OFFSET num);
342 extern void quark_init(void);
343 extern u16b quark_add(concptr str);
344 extern s32b message_num(void);
345 extern concptr message_str(int age);
346 extern void message_add(concptr msg);
347 extern void msg_erase(void);
348 extern void msg_print(concptr msg);
349 extern void msg_print_wizard(int cheat_type, concptr msg);
350 #ifndef SWIG
351 extern void msg_format(concptr fmt, ...);
352 extern void msg_format_wizard(int cheat_type, concptr fmt, ...);
353 #endif /* SWIG */
354 extern void screen_save(void);
355 extern void screen_load(void);
356 extern void c_put_str(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col);
357 extern void put_str(concptr str, TERM_LEN row, TERM_LEN col);
358 extern void c_prt(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col);
359 extern void prt(concptr str, TERM_LEN row, TERM_LEN col);
360 extern void c_roff(TERM_COLOR attr, concptr str);
361 extern void roff(concptr str);
362 extern void clear_from(int row);
363 extern bool askfor_aux(char *buf, int len, bool numpad_cursor);
364 extern bool askfor(char *buf, int len);
365 extern bool get_string(concptr prompt, char *buf, int len);
366
367 /*
368  * Bit flags for control of get_check_strict()
369  */
370 #define CHECK_OKAY_CANCEL 0x01
371 #define CHECK_NO_ESCAPE   0x02
372 #define CHECK_NO_HISTORY  0x04
373 #define CHECK_DEFAULT_Y   0x08
374 extern bool get_check(concptr prompt);
375 extern bool get_check_strict(concptr prompt, BIT_FLAGS mode);
376
377 extern bool get_com(concptr prompt, char *command, bool z_escape);
378 extern QUANTITY get_quantity(concptr prompt, QUANTITY max);
379 extern void pause_line(int row);
380 extern void request_command(int shopping);
381 extern bool is_a_vowel(int ch);
382 extern int get_keymap_dir(char ch);
383 extern errr type_string(concptr str, uint len);
384 extern void roff_to_buf(concptr str, int wlen, char *tbuf, size_t bufsize);
385
386 #ifdef SORT_R_INFO
387 extern void tag_sort(tag_type elements[], int number);
388 #endif /* SORT_R_INFO */
389
390 #ifdef SUPPORT_GAMMA
391 extern byte gamma_table[256];
392 extern void build_gamma_table(int gamma);
393 #endif /* SUPPORT_GAMMA */
394
395 extern size_t my_strcpy(char *buf, concptr src, size_t bufsize);
396 extern size_t my_strcat(char *buf, concptr src, size_t bufsize);
397 extern char *my_strstr(concptr haystack, concptr needle);
398 extern char *my_strchr(concptr ptr, char ch);
399 extern void str_tolower(char *str);
400
401 /*
402  * Special key code used for inkey_special()
403  */
404 #define SKEY_MOD_MASK     0x0f00
405 #define SKEY_MOD_SHIFT    0x0100
406 #define SKEY_MOD_CONTROL  0x0200
407
408 #define SKEY_MASK         0xf000
409 #define SKEY_DOWN         0xf001
410 #define SKEY_LEFT         0xf002
411 #define SKEY_RIGHT        0xf003
412 #define SKEY_UP           0xf004
413 #define SKEY_PGUP         0xf005
414 #define SKEY_PGDOWN       0xf006
415 #define SKEY_TOP          0xf007
416 #define SKEY_BOTTOM       0xf008
417 extern int inkey_special(bool numpad_cursor);
418
419 /* util.c */
420 extern void repeat_push(COMMAND_CODE what);
421 extern bool repeat_pull(COMMAND_CODE *what);
422 extern void repeat_check(void);