OSDN Git Service

[Refactor] #37353 object-kind.c/h を作成して関連構造体と変数を移動.
[hengband/hengband.git] / src / variable.c
1 /*!
2  * @file variable.c
3  * @brief グローバル変数定義 / Angband variables
4  * @date 2014/10/05
5  * @author
6  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke<br>
7  * <br>
8  * This software may be copied and distributed for educational, research,<br>
9  * and not for profit purposes provided that this copyright and statement<br>
10  * are included in all such copies.  Other copyrights may also apply.<br>
11  */
12
13 #include "angband.h"
14 #include "geometry.h"
15
16 /*!
17  * コピーライト情報 /
18  * Hack -- Link a copyright message into the executable
19  */
20 const concptr copyright[5] =
21 {
22         "Copyright (c) 1989 James E. Wilson, Robert A. Keoneke",
23         "",
24         "This software may be copied and distributed for educational, research,",
25         "and not for profit purposes provided that this copyright and statement",
26         "are included in all such copies."
27 };
28
29 int max_macrotrigger = 0; /*!< 現在登録中のマクロ(トリガー)の数 */
30 concptr macro_template = NULL; /*!< Angband設定ファイルのT: タグ情報から読み込んだ長いTコードを処理するために利用する文字列ポインタ */
31 concptr macro_modifier_chr; /*!< &x# で指定されるマクロトリガーに関する情報を記録する文字列ポインタ */
32 concptr macro_modifier_name[MAX_MACRO_MOD]; /*!< マクロ上で取り扱う特殊キーを文字列上で表現するためのフォーマットを記録した文字列ポインタ配列 */
33 concptr macro_trigger_name[MAX_MACRO_TRIG]; /*!< マクロのトリガーコード */
34 concptr macro_trigger_keycode[2][MAX_MACRO_TRIG];  /*!< マクロの内容 */
35
36 int level_up = 0; /*!< レベルアップの際に遅延してcalc_mana()関数上で上昇量を表示するかどうかの判定フラグ */
37
38
39 /* 
40  * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
41  */
42 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
43 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
44 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
45
46 /*
47  * Savefile version
48  */
49 byte h_ver_major; /* Savefile version for Hengband 1.1.1 and later */
50 byte h_ver_minor;
51 byte h_ver_patch;
52 byte h_ver_extra;
53
54 byte sf_extra;          /* Savefile's encoding key */
55
56 byte z_major;           /* Savefile version for Hengband */
57 byte z_minor;
58 byte z_patch;
59
60 /*
61  * Savefile information
62  */
63 u32b sf_system;                 /* Operating system info */
64 u32b sf_when;                   /* Time when savefile created */
65 u16b sf_lives;                  /* Number of past "lives" with this file */
66 u16b sf_saves;                  /* Number of "saves" during this life */
67
68 /*
69  * Run-time arguments
70  */
71 bool arg_fiddle;                        /* Command arg -- Request fiddle mode */
72 bool arg_wizard;                        /* Command arg -- Request wizard mode */
73 bool arg_sound;                         /* Command arg -- Request special sounds */
74 bool arg_music;                         /* Command arg -- Request special musics */
75 byte arg_graphics;                      /* Command arg -- Request graphics mode */
76 bool arg_monochrome;            /* Command arg -- Request monochrome mode */
77 bool arg_force_original;        /* Command arg -- Request original keyset */
78 bool arg_force_roguelike;       /* Command arg -- Request roguelike keyset */
79 bool arg_bigtile = FALSE;       /* Command arg -- Request big tile mode */
80
81 /*
82  * Various things
83  */
84 bool character_generated;       /* The character exists */
85 bool character_dungeon;         /* The character has a dungeon */
86 bool character_loaded;          /* The character was loaded from a savefile */
87 bool character_saved;           /* The character was just saved to a savefile */
88
89 bool character_icky;            /* The game is in an icky full screen mode */
90 bool character_xtra;            /* The game is in an icky startup mode */
91
92 bool creating_savefile;         /* New savefile is currently created */
93
94 s16b command_cmd;               /* Current "Angband Command" */
95
96 COMMAND_ARG command_arg;        /*!< 各種コマンドの汎用的な引数として扱う / Gives argument of current command */
97 COMMAND_NUM command_rep;        /*!< 各種コマンドの汎用的なリピート数として扱う / Gives repetition of current command */
98 DIRECTION command_dir;          /*!< 各種コマンドの汎用的な方向値処理として扱う/ Gives direction of current command */
99
100 s16b command_see;               /* See "object1.c" */
101 s16b command_wrk;               /* See "object1.c" */
102
103 TERM_LEN command_gap = 999;         /* See "object1.c" */
104
105 s16b command_new;               /* Command chaining from inven/equip view */
106
107 bool msg_flag;                  /* Used in msg_print() for "buffering" */
108
109 s16b running;                   /* Current counter for running, if any */
110
111 bool invoking_midnight_curse; /*!< 悪夢モード時の真夜中太古の呪い発生処理フラグ */
112
113 GAME_TURN old_battle;
114
115 bool use_sound;                 /* The "sound" mode is enabled */
116 bool use_music;                 /* The "music" mode is enabled */
117 bool use_graphics;              /* The "graphics" mode is enabled */
118 bool use_bigtile = FALSE;
119
120 s16b signal_count;              /* Hack -- Count interupts */
121
122 bool inkey_base;                /* See the "inkey()" function */
123 bool inkey_xtra;                /* See the "inkey()" function */
124 bool inkey_scan;                /* See the "inkey()" function */
125 bool inkey_flag;                /* See the "inkey()" function */
126 bool get_com_no_macros = FALSE; /* Expand macros in "get_com" or not */
127
128 OBJECT_SUBTYPE_VALUE coin_type; /* Hack -- force coin type */
129
130 bool opening_chest;             /* Hack -- prevent chest generation */
131
132 bool shimmer_monsters;  /* Hack -- optimize multi-hued monsters */
133 bool shimmer_objects;   /* Hack -- optimize multi-hued objects */
134
135 bool repair_monsters;   /* Hack -- optimize detect monsters */
136 bool repair_objects;    /* Hack -- optimize detect objects */
137
138 bool is_loading_now;    /*!< ロード直後にcalc_bonus()時の徳変化、及びsanity_blast()による異常を抑止する */
139
140 MONSTER_IDX hack_m_idx = 0;     /* Hack -- see "process_monsters()" */
141 MONSTER_IDX hack_m_idx_ii = 0;
142
143 bool multi_rew = FALSE;
144 char summon_kin_type;   /* Hack, by Julian Lighton: summon 'relatives' */
145
146 int total_friends = 0;
147 int leaving_quest = 0;
148 bool reinit_wilderness = FALSE;
149
150 /*
151  * Dungeon size info
152  */
153
154 POSITION panel_row_min, panel_row_max;
155 POSITION panel_col_min, panel_col_max;
156 POSITION panel_col_prt, panel_row_prt;
157
158
159 /*
160  * Targetting variables
161  */
162 MONSTER_IDX target_who;
163 POSITION target_col;
164 POSITION target_row;
165
166
167 /*
168  * User info
169  */
170 int player_uid;
171 int player_euid;
172 int player_egid;
173
174 /*
175  * Stripped version of "player_name"
176  */
177 char player_base[32];
178
179
180 /*
181  * Buffer to hold the current savefile name
182  * 'savefile' holds full path name. 'savefile_base' holds only base name.
183  */
184 char savefile[1024];
185 char savefile_base[40];
186
187
188 pos_list tmp_pos;
189
190
191 /*
192  * Number of active macros.
193  */
194 s16b macro__num;
195
196 /*
197  * Array of macro patterns [MACRO_MAX]
198  */
199 concptr *macro__pat;
200
201 /*
202  * Array of macro actions [MACRO_MAX]
203  */
204 concptr *macro__act;
205
206 /*
207  * Array of macro types [MACRO_MAX]
208  */
209 bool *macro__cmd;
210
211 /*
212  * Current macro action [1024]
213  */
214 char *macro__buf;
215
216
217 /*
218  * The number of quarks
219  */
220 STR_OFFSET quark__num;
221
222 /*
223  * The pointers to the quarks [QUARK_MAX]
224  */
225 concptr *quark__str;
226
227
228 /*
229  * The next "free" index to use
230  */
231 u32b message__next;
232
233 /*
234  * The index of the oldest message (none yet)
235  */
236 u32b message__last;
237
238 /*
239  * The next "free" offset
240  */
241 u32b message__head;
242
243 /*
244  * The offset to the oldest used char (none yet)
245  */
246 u32b message__tail;
247
248 /*
249  * The array of offsets, by index [MESSAGE_MAX]
250  */
251 u32b *message__ptr;
252
253 /*
254  * The array of chars, by offset [MESSAGE_BUF]
255  */
256 char *message__buf;
257
258 BIT_FLAGS option_flag[8]; //!< The array of normal options
259 BIT_FLAGS option_mask[8]; //!< The array of normal options
260 BIT_FLAGS window_flag[8]; //!< The array of window options
261 BIT_FLAGS window_mask[8]; //!< The array of window options
262
263 /*
264  * The array of window pointers
265  */
266 term *angband_term[8];
267
268 /*
269  * Standard window names
270  */
271 const char angband_term_name[8][16] =
272 {
273         "Hengband",
274         "Term-1",
275         "Term-2",
276         "Term-3",
277         "Term-4",
278         "Term-5",
279         "Term-6",
280         "Term-7"
281 };
282
283
284 /*
285  * Global table of color definitions
286  */
287 byte angband_color_table[256][4] =
288 {
289         {0x00, 0x00, 0x00, 0x00},       /* TERM_DARK */
290         {0x00, 0xFF, 0xFF, 0xFF},       /* TERM_WHITE */
291         {0x00, 0x80, 0x80, 0x80},       /* TERM_SLATE */
292         {0x00, 0xFF, 0x80, 0x00},       /* TERM_ORANGE */
293         {0x00, 0xC0, 0x00, 0x00},       /* TERM_RED */
294         {0x00, 0x00, 0x80, 0x40},       /* TERM_GREEN */
295         {0x00, 0x00, 0x00, 0xFF},       /* TERM_BLUE */
296         {0x00, 0x80, 0x40, 0x00},       /* TERM_UMBER */
297         {0x00, 0x40, 0x40, 0x40},       /* TERM_L_DARK */
298         {0x00, 0xC0, 0xC0, 0xC0},       /* TERM_L_WHITE */
299         {0x00, 0xFF, 0x00, 0xFF},       /* TERM_VIOLET */
300         {0x00, 0xFF, 0xFF, 0x00},       /* TERM_YELLOW */
301         {0x00, 0xFF, 0x00, 0x00},       /* TERM_L_RED */
302         {0x00, 0x00, 0xFF, 0x00},       /* TERM_L_GREEN */
303         {0x00, 0x00, 0xFF, 0xFF},       /* TERM_L_BLUE */
304         {0x00, 0xC0, 0x80, 0x40}        /* TERM_L_UMBER */
305 };
306
307
308 /*
309  * Standard sound names
310  */
311 const concptr angband_sound_name[SOUND_MAX] =
312 {
313         "dummy",
314         "hit",
315         "miss",
316         "flee",
317         "drop",
318         "kill",
319         "level",
320         "death",
321         "study",
322         "teleport",
323         "shoot",
324         "quaff",
325         "zap",
326         "walk",
327         "tpother",
328         "hitwall",
329         "eat",
330         "store1",
331         "store2",
332         "store3",
333         "store4",
334         "dig",
335         "opendoor",
336         "shutdoor",
337         "tplevel",
338         "scroll",
339         "buy",
340         "sell",
341         "warn",
342         "rocket",
343         "n_kill",
344         "u_kill",
345         "quest",
346         "heal",
347         "x_heal",
348         "bite",
349         "claw",
350         "m_spell",
351         "summon",
352         "breath",
353         "ball",
354         "m_heal",
355         "atkspell",
356         "evil",
357         "touch",
358         "sting",
359         "crush",
360         "slime",
361         "wail",
362         "winner",
363         "fire",
364         "acid",
365         "elec",
366         "cold",
367         "illegal",
368         "fail",
369         "wakeup",
370         "invuln",
371         "fall",
372         "pain",
373         "destitem",
374         "moan",
375         "show",
376         "unused",
377         "explode",
378         "glass",
379         "reflect",
380 };
381
382 /*
383  * Standard music names
384  */
385 const concptr angband_music_basic_name[MUSIC_BASIC_MAX] =
386 {
387         "default",
388         "gameover",
389         "exit",
390         "town",
391         "field1",
392         "field2",
393         "field3",
394         "dun_low",
395         "dun_med",
396         "dun_high",
397         "feel1",
398         "feel2",
399         "winner",
400         "build",
401         "wild",
402         "quest",
403         "arena",
404         "battle",
405         "quest_clear",
406         "final_quest_clear",
407         "ambush",
408 };
409
410
411 /*
412  * Number of floor_id used from birth
413  */
414 FLOOR_IDX max_floor_id;
415
416 /*
417  * Sign for current process used in temporal files.
418  * Actually it is the start time of current process.
419  */
420 u32b saved_floor_file_sign;
421
422 /*
423  * Maximum number of towns
424  */
425 TOWN_IDX max_towns;
426
427 /*
428  * The towns [max_towns]
429  */
430 town_type *town_info;
431
432 /*
433  * The size of "alloc_kind_table" (at most max_k_idx * 4)
434  */
435 s16b alloc_kind_size;
436
437 /*
438  * The entries in the "kind allocator table"
439  */
440 alloc_entry *alloc_kind_table;
441
442
443 /*
444  * The size of "alloc_race_table" (at most max_r_idx)
445  */
446 s16b alloc_race_size;
447
448 /*
449  * The entries in the "race allocator table"
450  */
451 alloc_entry *alloc_race_table;
452
453
454 /*
455  * Specify attr/char pairs for visual special effects
456  * Be sure to use "index & 0x7F" to avoid illegal access
457  */
458 TERM_COLOR misc_to_attr[256];
459 SYMBOL_CODE misc_to_char[256];
460
461
462 /*
463  * Specify attr/char pairs for p_ptr->inventory_list items (by tval)
464  * Be sure to use "index & 0x7F" to avoid illegal access
465  */
466 TERM_COLOR tval_to_attr[128];
467 SYMBOL_CODE tval_to_char[128];
468
469
470 /*
471  * Keymaps for each "mode" associated with each keypress.
472  */
473 concptr keymap_act[KEYMAP_MODES][256];
474
475
476
477 /*** Player information ***/
478
479 /*
480  * Static player info record
481  */
482 player_type p_body;
483
484 /*
485  * Pointer to the player info
486  */
487 player_type *p_ptr = &p_body;
488
489 /*
490  * Pointer to the player tables
491  * (sex, race, class, magic)
492  */
493 const player_sex *sp_ptr;
494 const player_race *rp_ptr;
495 const player_seikaku *ap_ptr;
496
497
498 /*
499  * The last character rolled,
500  * holded for quick start
501  */
502 birther previous_char;
503
504 /*
505  * The ego-item arrays
506  */
507 ego_item_type *e_info;
508 char *e_name;
509 char *e_text;
510
511
512 /*
513  * The monster race arrays
514  */
515 monster_race *r_info;
516 char *r_name;
517 char *r_text;
518
519 concptr ANGBAND_SYS = "xxx"; //!< Hack -- The special Angband "System Suffix" This variable is used to choose an appropriate "pref-xxx" file
520
521
522 #ifdef JP
523 concptr ANGBAND_KEYBOARD = "JAPAN"; //!< Hack -- The special Angband "Keyboard Suffix" This variable is used to choose an appropriate macro-trigger definition
524 #else
525 concptr ANGBAND_KEYBOARD = "0";
526 #endif
527
528 concptr ANGBAND_GRAF = "ascii"; //!< Hack -- The special Angband "Graphics Suffix" This variable is used to choose an appropriate "graf-xxx" file
529 concptr ANGBAND_DIR; //!< Path name: The main "lib" directory This variable is not actually used anywhere in the code
530 concptr ANGBAND_DIR_APEX; //!< High score files (binary) These files may be portable between platforms
531 concptr ANGBAND_DIR_BONE; //!< Bone files for player ghosts (ascii) These files are portable between platforms
532 concptr ANGBAND_DIR_DATA; //!< Binary image files for the "*_info" arrays (binary) These files are not portable between platforms
533 concptr ANGBAND_DIR_EDIT; //!< Textual template files for the "*_info" arrays (ascii) These files are portable between platforms
534 concptr ANGBAND_DIR_SCRIPT; //!< Script files These files are portable between platforms.
535 concptr ANGBAND_DIR_FILE; //!< Various extra files (ascii) These files may be portable between platforms
536 concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) These files are portable between platforms
537 concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
538 concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
539 concptr ANGBAND_DIR_SAVE; //!< Savefiles for current characters (binary)
540 concptr ANGBAND_DIR_USER; //!< User "preference" files (ascii) These files are rarely portable between platforms
541 concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
542
543
544 /*
545  * Here is a "pseudo-hook" used during calls to "get_item()" and
546  * "show_inven()" and "show_equip()", and the choice window routines.
547  */
548 OBJECT_TYPE_VALUE item_tester_tval;
549
550
551 /*
552  * Here is a "hook" used during calls to "get_item()" and
553  * "show_inven()" and "show_equip()", and the choice window routines.
554  */
555 bool (*item_tester_hook)(object_type*);
556
557
558
559
560 /*
561  * Hack -- function hooks to restrict "get_mon_num_prep()" function
562  */
563 monsterrace_hook_type get_mon_num_hook;
564 monsterrace_hook_type get_mon_num2_hook;
565
566
567 /*
568  * Hack -- function hook to restrict "get_obj_num_prep()" function
569  */
570 bool (*get_obj_num_hook)(KIND_OBJECT_IDX k_idx);
571
572 /*
573  * Maximum number of quests
574  */
575 QUEST_IDX max_q_idx;
576
577 /*
578  * Maximum number of monsters in r_info.txt
579  */
580 MONRACE_IDX max_r_idx;
581
582 /*
583  * Maximum number of items in k_info.txt
584  */
585 KIND_OBJECT_IDX max_k_idx;
586
587 /*
588  * Maximum number of vaults in v_info.txt
589  */
590 VAULT_IDX max_v_idx;
591
592 /*
593  * Maximum number of terrain features in f_info.txt
594  */
595 FEAT_IDX max_f_idx;
596
597 /*
598  * Maximum number of artifacts in a_info.txt
599  */
600 ARTIFACT_IDX max_a_idx;
601
602 /*
603  * Maximum number of ego-items in e_info.txt
604  */
605 EGO_IDX max_e_idx;
606
607 /*
608  * Maximum number of dungeon in e_info.txt
609  */
610 DUNGEON_IDX max_d_idx;
611
612
613 /*
614  * Quest text
615  */
616 char quest_text[10][80];
617
618 /*
619  * Current line of the quest text
620  */
621 int quest_text_line;
622
623 /*
624  * Flags for initialization
625  */
626 int init_flags;
627
628
629 /*
630  * The "highscore" file descriptor, if available.
631  */
632 int highscore_fd = -1;
633
634 bool can_save = FALSE;        /* Game can be saved */
635
636
637 int cap_mon;
638 int cap_mspeed;
639 HIT_POINT cap_hp;
640 HIT_POINT cap_maxhp;
641 STR_OFFSET cap_nickname;
642
643 MONRACE_IDX battle_mon[4];
644 int sel_monster;
645 int battle_odds;
646 PRICE kakekin;
647 u32b mon_odds[4];
648
649 MONSTER_IDX pet_t_m_idx;
650 MONSTER_IDX riding_t_m_idx;
651
652 MONSTER_IDX today_mon;
653
654 bool write_level;
655
656 u32b start_time;
657
658 bool sukekaku;
659 bool new_mane;
660
661 bool mon_fight;
662
663 bool generate_encounter;
664
665 concptr screen_dump = NULL;
666
667
668 /*
669  * Which dungeon ?
670  */
671 DEPTH *max_dlv;
672
673 FEAT_IDX feat_wall_outer;
674 FEAT_IDX feat_wall_inner;
675 FEAT_IDX feat_wall_solid;
676 FEAT_IDX feat_ground_type[100], feat_wall_type[100];
677
678 COMMAND_CODE now_message;
679 bool use_menu;
680
681 #ifdef CHUUKEI
682 bool chuukei_server;
683 bool chuukei_client;
684 char *server_name;
685 int server_port;
686 #endif
687
688 /* for movie */
689 bool browsing_movie;
690
691 #ifdef TRAVEL
692 /* for travel */
693 travel_type travel;
694 #endif
695
696 /* for snipers */
697 bool reset_concent = FALSE;   /* Concentration reset flag */
698 bool is_fired = FALSE;
699