OSDN Git Service

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