OSDN Git Service

b27d7cb687abceb60fd5bc035c81b0335d9b5511
[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 /*** Music constants ***/
170
171 #define MUSIC_BASIC_DEFAULT    0
172 #define MUSIC_BASIC_GAMEOVER   1
173 #define MUSIC_BASIC_EXIT       2
174 #define MUSIC_BASIC_TOWN       3
175 #define MUSIC_BASIC_FIELD1     4
176 #define MUSIC_BASIC_FIELD2     5
177 #define MUSIC_BASIC_FIELD3     6
178 #define MUSIC_BASIC_DUN_LOW    7
179 #define MUSIC_BASIC_DUN_MED    8
180 #define MUSIC_BASIC_DUN_HIGH   9
181 #define MUSIC_BASIC_DUN_FEEL1 10
182 #define MUSIC_BASIC_DUN_FEEL2 11
183 #define MUSIC_BASIC_WINNER    12
184 #define MUSIC_BASIC_BUILD     13
185 #define MUSIC_BASIC_WILD      14
186 #define MUSIC_BASIC_QUEST     15
187 #define MUSIC_BASIC_ARENA     16
188 #define MUSIC_BASIC_BATTLE    17
189 #define MUSIC_BASIC_QUEST_CLEAR 18
190 #define MUSIC_BASIC_FINAL_QUEST_CLEAR 19
191 #define MUSIC_BASIC_AMBUSH    20
192 #define MUSIC_BASIC_MAX       21 /*!< BGM定義の最大数 */
193
194 /*** Sound constants ***/
195
196 /*
197  * Mega-Hack -- some primitive sound support (see "main-win.c")
198  *
199  * Some "sound" constants for "Term_xtra(TERM_XTRA_SOUND, val)"
200  */
201 #define SOUND_HIT        1
202 #define SOUND_MISS       2
203 #define SOUND_FLEE       3
204 #define SOUND_DROP       4
205 #define SOUND_KILL       5
206 #define SOUND_LEVEL      6
207 #define SOUND_DEATH      7
208 #define SOUND_STUDY      8
209 #define SOUND_TELEPORT   9
210 #define SOUND_SHOOT     10
211 #define SOUND_QUAFF     11
212 #define SOUND_ZAP       12
213 #define SOUND_WALK      13
214 #define SOUND_TPOTHER   14
215 #define SOUND_HITWALL   15
216 #define SOUND_EAT       16
217 #define SOUND_STORE1    17
218 #define SOUND_STORE2    18
219 #define SOUND_STORE3    19
220 #define SOUND_STORE4    20
221 #define SOUND_DIG       21
222 #define SOUND_OPENDOOR  22
223 #define SOUND_SHUTDOOR  23
224 #define SOUND_TPLEVEL   24
225 #define SOUND_SCROLL    25
226 #define SOUND_BUY           26
227 #define SOUND_SELL          27
228 #define SOUND_WARN          28
229 #define SOUND_ROCKET    29 /*!< Somebody's shooting rockets */
230 #define SOUND_N_KILL    30 /*!< The player kills a non-living/undead monster */
231 #define SOUND_U_KILL    31 /*!< The player kills a unique */
232 #define SOUND_QUEST     32 /*!< The player has just completed a quest */
233 #define SOUND_HEAL      33 /*!< The player was healed a little bit */
234 #define SOUND_X_HEAL    34 /*!< The player was healed full health */
235 #define SOUND_BITE      35 /*!< A monster bites you */
236 #define SOUND_CLAW      36 /*!< A monster claws you */
237 #define SOUND_M_SPELL   37 /*!< A monster casts a miscellaneous spell */
238 #define SOUND_SUMMON    38 /*!< A monster casts a summoning spell  */
239 #define SOUND_BREATH    39 /*!< A monster breathes */
240 #define SOUND_BALL      40 /*!< A monster casts a ball / bolt spell */
241 #define SOUND_M_HEAL    41 /*!< A monster heals itself somehow */
242 #define SOUND_ATK_SPELL 42 /*!< A monster casts a misc. offensive spell */
243 #define SOUND_EVIL      43 /*!< Something nasty has just happened! */
244 #define SOUND_TOUCH     44 /*!< A monster touches you */
245 #define SOUND_STING     45 /*!< A monster stings you */
246 #define SOUND_CRUSH     46 /*!< A monster crushes / envelopes you */
247 #define SOUND_SLIME     47 /*!< A monster drools/spits/etc on you */
248 #define SOUND_WAIL      48 /*!< A monster wails */
249 #define SOUND_WINNER    49 /*!< Just won the game! */
250 #define SOUND_FIRE      50 /*!< An item was burned  */
251 #define SOUND_ACID      51 /*!< An item was destroyed by acid */
252 #define SOUND_ELEC      52 /*!< An item was destroyed by electricity */
253 #define SOUND_COLD      53 /*!< An item was shattered */
254 #define SOUND_ILLEGAL   54 /*!< Illegal command attempted */
255 #define SOUND_FAIL      55 /*!< Fail to get a spell off / activate an item */
256 #define SOUND_WAKEUP    56 /*!< A monster wakes up */
257 #define SOUND_INVULN    57 /*!< Invulnerability! */
258 #define SOUND_FALL      58 /*!< Falling through a trapdoor... */
259 #define SOUND_PAIN      59 /*!< A monster is in pain! */
260 #define SOUND_DESTITEM  60 /*!< An item was destroyed by misc. means */
261 #define SOUND_MOAN      61 /*!< A monster makes a moan/beg/insult attack */
262 #define SOUND_SHOW      62 /*!< A monster makes a "show" attack */
263 #define SOUND_UNUSED    63 /*!< (no sound for gaze attacks) */
264 #define SOUND_EXPLODE   64 /*!< Something (or somebody) explodes */
265 #define SOUND_GLASS     65 /*!< A glass feature was crashed */
266 #define SOUND_REFLECT   66 /*!< A bolt was reflected */
267
268   /*!
269    * @brief 銘情報の最大数 / Maximum number of "quarks" (see "io.c")
270    * @note
271    * Default: assume at most 512 different inscriptions are used<br>
272    * Was 512... 256 quarks added for random artifacts<br>
273    */
274 #define QUARK_MAX       768
275
276    /*
277         * OPTION: Maximum number of messages to remember (see "io.c")
278         * Default: assume maximal memorization of 2048 total messages
279         */
280 #define MESSAGE_MAX  81920
281
282         /*
283          * OPTION: Maximum space for the message text buffer (see "io.c")
284          * Default: assume that each of the 2048 messages is repeated an
285          * average of three times, and has an average length of 48
286          */
287 #define MESSAGE_BUF 655360
288
289          /*
290           * Hack -- The main "screen"
291           */
292 #define term_screen     (angband_term[0])
293
294           /*
295            * Hack -- conditional (or "bizarre") externs
296            */
297
298 #ifdef SET_UID
299 extern void user_name(char *buf, int id);
300 #endif
301
302 #ifndef HAVE_USLEEP
303 extern int usleep(huge usecs);
304 #endif
305
306 #if defined(MACH_O_CARBON)
307 extern void fsetfileinfo(concptr path, u32b fcreator, u32b ftype);
308 #endif
309
310 #if defined(MACH_O_CARBON)
311 /* Globals needed */
312 extern  u32b _ftype;
313 extern  u32b _fcreator;
314 #endif
315
316 /*
317  * Hack -- force definitions -- see fd_seek()
318  */
319 #ifndef SEEK_SET
320 # define SEEK_SET       0
321 #endif
322 #ifndef SEEK_CUR
323 # define SEEK_CUR       1
324 #endif
325 #ifndef SEEK_END
326 # define SEEK_END       2
327 #endif
328
329  /*
330   * Hack -- force definitions -- see fd_lock()
331   */
332 #ifndef F_UNLCK
333 # define F_UNLCK        0
334 #endif
335 #ifndef F_RDLCK
336 # define F_RDLCK        1
337 #endif
338 #ifndef F_WRLCK
339 # define F_WRLCK        2
340 #endif
341
342 extern const char hexsym[16];
343
344 // todo ファイル処理関数・メッセージ処理関数・画面病が関数で最低限分割する.
345 extern errr path_parse(char *buf, int max, concptr file);
346 extern errr path_build(char *buf, int max, concptr path, concptr file);
347 extern FILE *my_fopen(concptr file, concptr mode);
348 extern FILE *my_fopen_temp(char *buf, int max);
349 extern errr my_fgets(FILE *fff, char *buf, huge n);
350 extern errr my_fputs(FILE *fff, concptr buf, huge n);
351 extern errr my_fclose(FILE *fff);
352 extern errr fd_kill(concptr file);
353 extern errr fd_move(concptr file, concptr what);
354 extern errr fd_copy(concptr file, concptr what);
355 extern int fd_make(concptr file, BIT_FLAGS mode);
356 extern int fd_open(concptr file, int flags);
357 extern errr fd_lock(int fd, int what);
358 extern errr fd_seek(int fd, huge n);
359 extern errr fd_chop(int fd, huge n);
360 extern errr fd_read(int fd, char *buf, huge n);
361 extern errr fd_write(int fd, concptr buf, huge n);
362 extern errr fd_close(int fd);
363 extern void flush(void);
364 extern void bell(void);
365 extern errr play_music(int type, int num);
366 extern void select_floor_music(player_type *player_ptr);
367 extern void sound(int num);
368 extern void move_cursor(int row, int col);
369 extern void text_to_ascii(char *buf, concptr str);
370 extern void ascii_to_text(char *buf, concptr str);
371 extern errr macro_add(concptr pat, concptr act);
372 extern sint macro_find_exact(concptr pat);
373 extern char inkey(void);
374 extern concptr quark_str(STR_OFFSET num);
375 extern void quark_init(void);
376 extern u16b quark_add(concptr str);
377 extern s32b message_num(void);
378 extern concptr message_str(int age);
379 extern void message_add(concptr msg);
380 extern void msg_erase(void);
381 extern void msg_print(concptr msg);
382 extern void msg_print_wizard(int cheat_type, concptr msg);
383 #ifndef SWIG
384 extern void msg_format(concptr fmt, ...);
385 extern void msg_format_wizard(int cheat_type, concptr fmt, ...);
386 #endif /* SWIG */
387 extern void screen_save();
388 extern void screen_load();
389 extern void c_put_str(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col);
390 extern void put_str(concptr str, TERM_LEN row, TERM_LEN col);
391 extern void c_prt(TERM_COLOR attr, concptr str, TERM_LEN row, TERM_LEN col);
392 extern void prt(concptr str, TERM_LEN row, TERM_LEN col);
393 extern void c_roff(TERM_COLOR attr, concptr str);
394 extern void roff(concptr str);
395 extern void clear_from(int row);
396 extern bool askfor_aux(char *buf, int len, bool numpad_cursor);
397 extern bool askfor(char *buf, int len);
398 extern bool get_string(concptr prompt, char *buf, int len);
399
400 /*
401  * Bit flags for control of get_check_strict()
402  */
403 #define CHECK_OKAY_CANCEL 0x01
404 #define CHECK_NO_ESCAPE   0x02
405 #define CHECK_NO_HISTORY  0x04
406 #define CHECK_DEFAULT_Y   0x08
407 extern bool get_check(concptr prompt);
408 extern bool get_check_strict(concptr prompt, BIT_FLAGS mode);
409
410 extern bool get_com(concptr prompt, char *command, bool z_escape);
411 extern QUANTITY get_quantity(concptr prompt, QUANTITY max);
412 extern void pause_line(int row);
413 extern void request_command(player_type *player_ptr, int shopping);
414 extern bool is_a_vowel(int ch);
415 extern int get_keymap_dir(char ch);
416 extern errr type_string(concptr str, uint len);
417 extern void roff_to_buf(concptr str, int wlen, char *tbuf, size_t bufsize);
418
419 extern void tag_sort(tag_type elements[], int number);
420
421 extern byte gamma_table[256];
422 extern void build_gamma_table(int gamma);
423
424 extern size_t my_strcpy(char *buf, concptr src, size_t bufsize);
425 extern size_t my_strcat(char *buf, concptr src, size_t bufsize);
426 extern char *my_strstr(concptr haystack, concptr needle);
427 extern char *my_strchr(concptr ptr, char ch);
428 extern void str_tolower(char *str);
429
430 /*
431  * Special key code used for inkey_special()
432  */
433 #define SKEY_MOD_MASK     0x0f00
434 #define SKEY_MOD_SHIFT    0x0100
435 #define SKEY_MOD_CONTROL  0x0200
436
437 #define SKEY_MASK         0xf000
438 #define SKEY_DOWN         0xf001
439 #define SKEY_LEFT         0xf002
440 #define SKEY_RIGHT        0xf003
441 #define SKEY_UP           0xf004
442 #define SKEY_PGUP         0xf005
443 #define SKEY_PGDOWN       0xf006
444 #define SKEY_TOP          0xf007
445 #define SKEY_BOTTOM       0xf008
446 extern int inkey_special(bool numpad_cursor);
447
448 /* util.c */
449 extern void repeat_push(COMMAND_CODE what);
450 extern bool repeat_pull(COMMAND_CODE *what);
451 extern void repeat_check(void);