OSDN Git Service

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