2 * @brief ゲームデータ初期化2 / Initialization (part 2) -BEN-
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
7 * This software may be copied and distributed for educational, research,
8 * and not for profit purposes provided that this copyright and statement
9 * are included in all such copies. Other copyrights may also apply.
10 * 2014 Deskull rearranged comment for Doxygen.\n
14 * This file is used to initialize various variables and arrays for the
15 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
16 * the common limitation of "read()" and "write()" to only 32767 bytes
18 * Several of the arrays for Angband are built from "template" files in
19 * the "lib/file" directory, from which quick-load binary "image" files
20 * are constructed whenever they are not present in the "lib/data"
21 * directory, or if those files become obsolete, if we are allowed.
22 * Warning -- the "ascii" file parsers use a minor hack to collect the
23 * name and text information in a single pass. Thus, the game will not
24 * be able to load any template file with more than 20K of names or 60K
25 * of text, even though technically, up to 64K should be legal.
26 * The "init1.c" file is used only to parse the ascii template files,
27 * to create the binary image files. Note that the binary image files
28 * are extremely system dependant.
32 #include "main/init.h"
33 #include "cmd-building/cmd-building.h"
34 #include "cmd-io/macro-util.h"
35 #include "info-reader/fixed-map-parser.h" // 相互参照、後で何とかする.
36 #include "dungeon/dungeon.h"
37 #include "dungeon/quest.h"
38 #include "floor/floor-town.h"
39 #include "floor/floor.h"
40 #include "floor/wild.h"
41 #include "game-option/option-flags.h"
42 #include "game-option/option-types-table.h"
43 #include "grid/feature.h"
44 #include "grid/grid.h"
45 #include "grid/trap.h"
46 #include "info-reader/artifact-reader.h"
47 #include "info-reader/dungeon-reader.h"
48 #include "info-reader/ego-reader.h"
49 #include "info-reader/feature-reader.h"
50 #include "info-reader/general-parser.h"
51 #include "info-reader/kind-reader.h"
52 #include "info-reader/magic-reader.h"
53 #include "info-reader/race-reader.h"
54 #include "info-reader/skill-reader.h"
55 #include "info-reader/parse-error-types.h"
56 #include "info-reader/vault-reader.h"
57 #include "io/files-util.h"
58 #include "io/read-pref-file.h"
59 #include "io/uid-checker.h"
60 #include "market/articles-on-sale.h"
61 #include "monster-race/monster-race.h"
62 #include "monster-race/race-flags7.h"
63 #include "object-enchant/object-ego.h"
64 #include "object/object-kind.h"
65 #include "player/player-class.h"
66 #include "player/player-skill.h"
67 #include "room/rooms-vault.h"
68 #include "room/rooms.h"
69 #include "store/store-util.h"
70 #include "store/store.h"
71 #include "system/alloc-entries.h"
72 #include "system/angband-version.h"
73 #include "system/artifact-type-definition.h"
74 #include "system/building-type-definition.h"
75 #include "system/floor-type-definition.h"
76 #include "system/system-variables.h"
77 #include "term/gameterm.h"
78 #include "term/screen-processor.h"
79 #include "term/term-color-types.h"
80 #include "util/angband-files.h"
81 #include "util/quarks.h"
82 #include "util/tag-sorter.h"
83 #include "view/display-messages.h"
84 #include "world/world.h"
87 #include <sys/types.h>
90 * @brief マクロ登録の最大数 / Maximum number of macros (see "io.c")
91 * @note Default: assume at most 256 macros are used
93 static const int MACRO_MAX = 256;
95 static void put_title(void);
98 * @brief 各データファイルを読み取るためのパスを取得する
99 * Find the default paths to all of our important sub-directories.
100 * @param path パス保管先の文字列
104 * The purpose of each sub-directory is described in "variable.c".
105 * All of the sub-directories should, by default, be located inside
106 * the main "lib" directory, whose location is very system dependant.
107 * This function takes a writable buffer, initially containing the
108 * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
109 * or a system dependant string, for example, ":lib:". The buffer
110 * must be large enough to contain at least 32 more characters.
111 * Various command line options may allow some of the important
112 * directories to be changed to user-specified directories, most
113 * importantly, the "info" and "user" and "save" directories,
114 * but this is done after this function, see "main.c".
115 * In general, the initial path should end in the appropriate "PATH_SEP"
116 * string. All of the "sub-directory" paths (created below or supplied
117 * by the user) will NOT end in the "PATH_SEP" string, see the special
118 * "path_build()" function in "util.c" for more information.
119 * Mega-Hack -- support fat raw files under NEXTSTEP, using special
120 * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
121 * requiring the directories to be created by hand by the user.
122 * Hack -- first we free all the strings, since this is known
123 * to succeed even if the strings have not been allocated yet,
124 * as long as the variables start out as "NULL". This allows
125 * this function to be called multiple times, for example, to
126 * try several base "path" values until a good one is found.
129 void init_file_paths(char *path)
133 #ifdef PRIVATE_USER_PATH
135 #endif /* PRIVATE_USER_PATH */
137 /*** Free everything ***/
139 /* Free the main path */
140 string_free(ANGBAND_DIR);
142 /* Free the sub-paths */
143 string_free(ANGBAND_DIR_APEX);
144 string_free(ANGBAND_DIR_BONE);
145 string_free(ANGBAND_DIR_DATA);
146 string_free(ANGBAND_DIR_EDIT);
147 string_free(ANGBAND_DIR_SCRIPT);
148 string_free(ANGBAND_DIR_FILE);
149 string_free(ANGBAND_DIR_HELP);
150 string_free(ANGBAND_DIR_INFO);
151 string_free(ANGBAND_DIR_SAVE);
152 string_free(ANGBAND_DIR_USER);
153 string_free(ANGBAND_DIR_XTRA);
155 /*** Prepare the "path" ***/
157 /* Hack -- save the main directory */
158 ANGBAND_DIR = string_make(path);
160 /* Prepare to append to the Base Path */
161 tail = path + strlen(path);
163 /*** Build the sub-directory names ***/
165 /* Build a path name */
166 strcpy(tail, "apex");
167 ANGBAND_DIR_APEX = string_make(path);
169 /* Build a path name */
170 strcpy(tail, "bone");
171 ANGBAND_DIR_BONE = string_make(path);
173 /* Build a path name */
174 strcpy(tail, "data");
175 ANGBAND_DIR_DATA = string_make(path);
177 /* Build a path name */
178 strcpy(tail, "edit");
179 ANGBAND_DIR_EDIT = string_make(path);
181 /* Build a path name */
182 strcpy(tail, "script");
183 ANGBAND_DIR_SCRIPT = string_make(path);
185 /* Build a path name */
186 strcpy(tail, "file");
187 ANGBAND_DIR_FILE = string_make(path);
189 /* Build a path name */
190 strcpy(tail, "help");
191 ANGBAND_DIR_HELP = string_make(path);
193 /* Build a path name */
194 strcpy(tail, "info");
195 ANGBAND_DIR_INFO = string_make(path);
197 /* Build a path name */
198 strcpy(tail, "pref");
199 ANGBAND_DIR_PREF = string_make(path);
201 /* Build a path name */
202 strcpy(tail, "save");
203 ANGBAND_DIR_SAVE = string_make(path);
205 #ifdef PRIVATE_USER_PATH
207 /* Build the path to the user specific directory */
208 path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
210 /* Build a relative path name */
211 ANGBAND_DIR_USER = string_make(buf);
213 #else /* PRIVATE_USER_PATH */
215 /* Build a path name */
216 strcpy(tail, "user");
217 ANGBAND_DIR_USER = string_make(path);
219 #endif /* PRIVATE_USER_PATH */
221 /* Build a path name */
222 strcpy(tail, "xtra");
223 ANGBAND_DIR_XTRA = string_make(path);
228 * Hack -- help give useful error messages
230 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
231 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
234 * エラーメッセージの名称定義 / Standard error message text
236 concptr err_str[PARSE_ERROR_MAX] =
253 "missing record header",
254 "non-sequential records",
255 "invalid flag specification",
256 "undefined directive",
258 "coordinates out of bounds",
260 "undefined terrain tag",
268 static angband_header v_head; /*!< Vault情報のヘッダ構造体 */
269 static angband_header k_head; /*!< ペースアイテム情報のヘッダ構造体 */
270 static angband_header a_head; /*!< 固定アーティファクト情報のヘッダ構造体 */
271 static angband_header e_head; /*!< アイテムエゴ情報のヘッダ構造体 */
272 static angband_header r_head; /*!< モンスター種族情報のヘッダ構造体 */
273 static angband_header d_head; /*!< ダンジョン情報のヘッダ構造体 */
274 static angband_header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
275 static angband_header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
278 * @brief テキストファイルとrawファイルの更新時刻を比較する
279 * Find the default paths to all of our important sub-directories.
280 * @param fd ファイルディスクリプタ
281 * @param template_file ファイル名
282 * @return テキストの方が新しいか、rawファイルがなく更新の必要がある場合-1、更新の必要がない場合0。
284 static errr check_modification_date(int fd, concptr template_file)
286 struct stat txt_stat, raw_stat;
288 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
290 /* Access stats on text file */
291 if (stat(buf, &txt_stat))
296 /* Access stats on raw file */
297 if (fstat(fd, &raw_stat))
302 /* Ensure text file is not newer than raw file */
303 if (txt_stat.st_mtime > raw_stat.st_mtime)
312 /*** Initialize from binary image files ***/
315 * @brief rawファイルからのデータの読み取り処理
316 * Initialize the "*_info" array, by parsing a binary "image" file
317 * @param fd ファイルディスクリプタ
318 * @param head rawファイルのヘッダ
321 static errr init_info_raw(int fd, angband_header *head)
325 /* Read and Verify the header */
326 if (fd_read(fd, (char*)(&test), sizeof(angband_header)) ||
327 (test.v_major != head->v_major) ||
328 (test.v_minor != head->v_minor) ||
329 (test.v_patch != head->v_patch) ||
330 (test.info_num != head->info_num) ||
331 (test.info_len != head->info_len) ||
332 (test.head_size != head->head_size) ||
333 (test.info_size != head->info_size))
339 /* Accept the header */
342 /* Allocate the "*_info" array */
343 C_MAKE(head->info_ptr, head->info_size, char);
345 /* Read the "*_info" array */
346 fd_read(fd, head->info_ptr, head->info_size);
350 /* Allocate the "*_name" array */
351 C_MAKE(head->name_ptr, head->name_size, char);
353 /* Read the "*_name" array */
354 fd_read(fd, head->name_ptr, head->name_size);
359 /* Allocate the "*_text" array */
360 C_MAKE(head->text_ptr, head->text_size, char);
362 /* Read the "*_text" array */
363 fd_read(fd, head->text_ptr, head->text_size);
368 /* Allocate the "*_tag" array */
369 C_MAKE(head->tag_ptr, head->tag_size, char);
371 /* Read the "*_tag" array */
372 fd_read(fd, head->tag_ptr, head->tag_size);
382 * Initialize the header of an *_info.raw file.
383 * @param head rawファイルのヘッダ
388 static void init_header(angband_header *head, IDX num, int len)
390 /* Save the "version" */
391 head->v_major = FAKE_VER_MAJOR;
392 head->v_minor = FAKE_VER_MINOR;
393 head->v_patch = FAKE_VER_PATCH;
396 /* Save the "record" information */
397 head->info_num = (IDX)num;
398 head->info_len = len;
400 /* Save the size of "*_head" and "*_info" */
401 head->head_size = sizeof(angband_header);
402 head->info_size = head->info_num * head->info_len;
406 static void update_header(angband_header *head, void **info, char **name, char **text, char **tag)
408 if (info) *info = head->info_ptr;
409 if (name) *name = head->name_ptr;
410 if (text) *text = head->text_ptr;
411 if (tag) *tag = head->tag_ptr;
417 * Initialize the "*_info" array
418 * @param filename ファイル名(拡張子txt/raw)
419 * @param head 処理に用いるヘッダ構造体
420 * @param info データ保管先の構造体ポインタ
421 * @param name 名称用可変文字列の保管先
422 * @param text テキスト用可変文字列の保管先
423 * @param tag タグ用可変文字列の保管先
426 * Note that we let each entry have a unique "name" and "text" string,
427 * even if the string happens to be empty (everyone has a unique '\0').
429 static errr init_info(player_type *player_ptr, concptr filename, angband_header *head, void **info, char **name, char **text, char **tag)
434 /*** Load the binary image file ***/
435 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
437 /* Attempt to open the "raw" file */
438 int fd = fd_open(buf, O_RDONLY);
440 /* Process existing "raw" file */
444 err = check_modification_date(fd, format("%s.txt", filename));
446 /* Attempt to parse the "raw" file */
448 err = init_info_raw(fd, head);
452 /* Do we have to parse the *.txt file? */
453 BIT_FLAGS file_permission = 0644;
456 update_header(head, info, name, text, tag);
460 /*** Make the fake arrays ***/
461 C_MAKE(head->info_ptr, head->info_size, char);
463 /* Hack -- make "fake" arrays */
464 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
465 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
466 if (tag) C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
468 if (info) (*info) = head->info_ptr;
469 if (name) (*name) = head->name_ptr;
470 if (text) (*text) = head->text_ptr;
471 if (tag) (*tag) = head->tag_ptr;
473 /*** Load the ascii template file ***/
474 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
476 fp = angband_fopen(buf, "r");
479 if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
482 err = init_info_txt(fp, buf, head, head->parse_info_txt);
492 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
494 msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
495 msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
496 msg_format("構文 '%s'。", buf);
500 quit(format("'%s.txt'ファイルにエラー", filename));
503 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
505 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
506 msg_format("Record %d contains a '%s' error.", error_idx, oops);
507 msg_format("Parsing '%s'.", buf);
511 quit(format("Error in '%s.txt' file.", filename));
515 /*** Make final retouch on fake tags ***/
518 (*head->retouch)(head);
521 /*** Dump the binary image file ***/
522 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
524 /* Grab permissions */
525 safe_setuid_grab(player_ptr);
527 /* Kill the old file */
530 /* Attempt to create the raw file */
531 fd = fd_make(buf, file_permission);
533 /* Drop permissions */
536 /* Dump to the file */
540 fd_write(fd, (concptr)(head), head->head_size);
542 /* Dump the "*_info" array */
543 fd_write(fd, head->info_ptr, head->info_size);
545 /* Dump the "*_name" array */
546 fd_write(fd, head->name_ptr, head->name_size);
548 /* Dump the "*_text" array */
549 fd_write(fd, head->text_ptr, head->text_size);
551 /* Dump the "*_tag" array */
552 fd_write(fd, head->tag_ptr, head->tag_size);
558 /*** Kill the fake arrays ***/
560 /* Free the "*_info" array */
561 C_KILL(head->info_ptr, head->info_size, char);
563 /* Hack -- Free the "fake" arrays */
564 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
565 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
566 if (tag) C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
568 /*** Load the binary image file ***/
569 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
571 /* Attempt to open the "raw" file */
572 fd = fd_open(buf, O_RDONLY);
574 /* Process existing "raw" file */
575 if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
577 /* Attempt to parse the "raw" file */
578 err = init_info_raw(fd, head);
582 if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
584 update_header(head, info, name, text, tag);
590 * @brief 地形情報読み込みのメインルーチン /
591 * Initialize the "f_info" array
594 static errr init_f_info(player_type *player_ptr)
596 /* Init the header */
597 init_header(&f_head, max_f_idx, sizeof(feature_type));
599 /* Save a pointer to the parsing function */
600 f_head.parse_info_txt = parse_f_info;
602 /* Save a pointer to the retouch fake tags */
603 f_head.retouch = retouch_f_info;
605 return init_info(player_ptr, "f_info", &f_head,
606 (void*)&f_info, &f_name, NULL, &f_tag);
611 * @brief ベースアイテム情報読み込みのメインルーチン /
612 * Initialize the "k_info" array
615 static errr init_k_info(player_type *player_ptr)
617 /* Init the header */
618 init_header(&k_head, max_k_idx, sizeof(object_kind));
620 /* Save a pointer to the parsing function */
621 k_head.parse_info_txt = parse_k_info;
623 return init_info(player_ptr, "k_info", &k_head,
624 (void*)&k_info, &k_name, &k_text, NULL);
629 * @brief 固定アーティファクト情報読み込みのメインルーチン /
630 * Initialize the "a_info" array
633 static errr init_a_info(player_type *player_ptr)
635 /* Init the header */
636 init_header(&a_head, max_a_idx, sizeof(artifact_type));
638 /* Save a pointer to the parsing function */
639 a_head.parse_info_txt = parse_a_info;
641 return init_info(player_ptr, "a_info", &a_head,
642 (void*)&a_info, &a_name, &a_text, NULL);
647 * @brief 固定アーティファクト情報読み込みのメインルーチン /
648 * Initialize the "e_info" array
651 static errr init_e_info(player_type *player_ptr)
653 /* Init the header */
654 init_header(&e_head, max_e_idx, sizeof(ego_item_type));
656 /* Save a pointer to the parsing function */
657 e_head.parse_info_txt = parse_e_info;
659 return init_info(player_ptr, "e_info", &e_head,
660 (void*)&e_info, &e_name, &e_text, NULL);
665 * @brief モンスター種族情報読み込みのメインルーチン /
666 * Initialize the "r_info" array
669 static errr init_r_info(player_type *player_ptr)
671 /* Init the header */
672 init_header(&r_head, max_r_idx, sizeof(monster_race));
674 /* Save a pointer to the parsing function */
675 r_head.parse_info_txt = parse_r_info;
677 return init_info(player_ptr, "r_info", &r_head,
678 (void*)&r_info, &r_name, &r_text, NULL);
683 * @brief ダンジョン情報読み込みのメインルーチン /
684 * Initialize the "d_info" array
687 static errr init_d_info(player_type *player_ptr)
689 /* Init the header */
690 init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
692 /* Save a pointer to the parsing function */
693 d_head.parse_info_txt = parse_d_info;
695 return init_info(player_ptr, "d_info", &d_head,
696 (void*)&d_info, &d_name, &d_text, NULL);
701 * @brief Vault情報読み込みのメインルーチン /
702 * Initialize the "v_info" array
705 * Note that we let each entry have a unique "name" and "text" string,
706 * even if the string happens to be empty (everyone has a unique '\0').
708 errr init_v_info(player_type *player_ptr)
710 /* Init the header */
711 init_header(&v_head, max_v_idx, sizeof(vault_type));
713 /* Save a pointer to the parsing function */
714 v_head.parse_info_txt = parse_v_info;
716 return init_info(player_ptr, "v_info", &v_head,
717 (void*)&v_info, &v_name, &v_text, NULL);
722 * @brief 職業技能情報読み込みのメインルーチン /
723 * Initialize the "s_info" array
726 static errr init_s_info(player_type *player_ptr)
728 /* Init the header */
729 init_header(&s_head, MAX_CLASS, sizeof(skill_table));
731 /* Save a pointer to the parsing function */
732 s_head.parse_info_txt = parse_s_info;
734 return init_info(player_ptr, "s_info", &s_head,
735 (void*)&s_info, NULL, NULL, NULL);
740 * @brief 職業魔法情報読み込みのメインルーチン /
741 * Initialize the "m_info" array
744 static errr init_m_info(player_type *player_ptr)
746 /* Init the header */
747 init_header(&m_head, MAX_CLASS, sizeof(player_magic));
749 /* Save a pointer to the parsing function */
750 m_head.parse_info_txt = parse_m_info;
752 return init_info(player_ptr, "m_info", &m_head,
753 (void*)&m_info, NULL, NULL, NULL);
758 * @brief 基本情報読み込みのメインルーチン /
759 * Initialize misc. values
760 * @param player_ptr プレーヤーへの参照ポインタ
763 static errr init_misc(player_type *player_ptr)
765 return parse_fixed_map(player_ptr, "misc.txt", 0, 0, 0, 0);
770 * @brief 町情報読み込みのメインルーチン /
771 * Initialize town array
774 static errr init_towns(void)
776 /* Allocate the towns */
777 C_MAKE(town_info, max_towns, town_type);
779 for (int i = 1; i < max_towns; i++)
781 /*** Prepare the Stores ***/
783 /* Allocate the stores */
784 C_MAKE(town_info[i].store, MAX_STORES, store_type);
786 /* Fill in each store */
787 for (int j = 0; j < MAX_STORES; j++)
789 /* Access the store */
790 store_type *store_ptr = &town_info[i].store[j];
792 if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
794 /* Assume full stock */
797 * 我が家が 20 ページまで使える隠し機能のための準備。
798 * オプションが有効でもそうでなくても一応スペースを作っておく。
802 store_ptr->stock_size = (STORE_INVEN_MAX * 10);
804 else if (j == STORE_MUSEUM)
806 store_ptr->stock_size = (STORE_INVEN_MAX * 50);
810 store_ptr->stock_size = STORE_INVEN_MAX;
813 /* Allocate the stock */
814 C_MAKE(store_ptr->stock, store_ptr->stock_size, object_type);
816 /* No table for the black market or home */
817 if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
819 /* Assume full table */
820 store_ptr->table_size = STORE_CHOICES;
822 /* Allocate the stock */
823 C_MAKE(store_ptr->table, store_ptr->table_size, s16b);
825 /* Scan the choices */
826 for (int k = 0; k < STORE_CHOICES; k++)
828 KIND_OBJECT_IDX k_idx;
830 /* Extract the tval/sval codes */
831 int tv = store_table[j][k][0];
832 int sv = store_table[j][k][1];
835 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
837 object_kind *k_ptr = &k_info[k_idx];
840 if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
844 if (k_idx == max_k_idx) continue;
846 /* Add that item index to the table */
847 store_ptr->table[store_ptr->table_num++] = k_idx;
856 * @brief 店情報初期化のメインルーチン /
857 * Initialize buildings
860 errr init_buildings(void)
862 for (int i = 0; i < MAX_BLDG; i++)
864 building[i].name[0] = '\0';
865 building[i].owner_name[0] = '\0';
866 building[i].owner_race[0] = '\0';
868 for (int j = 0; j < 8; j++)
870 building[i].act_names[j][0] = '\0';
871 building[i].member_costs[j] = 0;
872 building[i].other_costs[j] = 0;
873 building[i].letters[j] = 0;
874 building[i].actions[j] = 0;
875 building[i].action_restr[j] = 0;
878 for (int j = 0; j < MAX_CLASS; j++)
880 building[i].member_class[j] = 0;
883 for (int j = 0; j < MAX_RACES; j++)
885 building[i].member_race[j] = 0;
888 for (int j = 0; j < MAX_MAGIC + 1; j++)
890 building[i].member_realm[j] = 0;
899 * @brief クエスト情報初期化のメインルーチン /
900 * Initialize quest array
903 static errr init_quests(void)
905 /* Allocate the quests */
906 C_MAKE(quest, max_q_idx, quest_type);
908 /* Set all quest to "untaken" */
909 for (int i = 0; i < max_q_idx; i++)
911 quest[i].status = QUEST_STATUS_UNTAKEN;
918 * @brief その他の初期情報更新 /
919 * Initialize some other arrays
922 static errr init_other(player_type *player_ptr)
924 player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
925 floor_type *floor_ptr = player_ptr->current_floor_ptr;
927 /*** Prepare the "dungeon" information ***/
929 /* Allocate and Wipe the object list */
930 C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
932 /* Allocate and Wipe the monster list */
933 C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
935 /* Allocate and Wipe the monster process list */
936 for (int i = 0; i < MAX_MTIMED; i++)
938 C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
941 /* Allocate and Wipe the max dungeon level */
942 C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
944 for (int i = 0; i < MAX_HGT; i++)
946 C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
949 /*** Prepare the various "bizarre" arrays ***/
951 /* Macro variables */
952 C_MAKE(macro__pat, MACRO_MAX, concptr);
953 C_MAKE(macro__act, MACRO_MAX, concptr);
954 C_MAKE(macro__cmd, MACRO_MAX, bool);
956 /* Macro action buffer */
957 C_MAKE(macro__buf, 1024, char);
959 /* Quark variables */
962 /* Message variables */
963 C_MAKE(message__ptr, MESSAGE_MAX, u32b);
964 C_MAKE(message__buf, MESSAGE_BUF, char);
966 /* Hack -- No messages yet */
967 message__tail = MESSAGE_BUF;
969 /*** Prepare the options ***/
971 /* Scan the options */
972 for (int i = 0; option_info[i].o_desc; i++)
974 int os = option_info[i].o_set;
975 int ob = option_info[i].o_bit;
977 /* Set the "default" options */
978 if (!option_info[i].o_var) continue;
981 option_mask[os] |= (1L << ob);
984 if (option_info[i].o_norm)
987 option_flag[os] |= (1L << ob);
991 option_flag[os] &= ~(1L << ob);
995 /* Analyze the windows */
996 for (int n = 0; n < 8; n++)
998 /* Analyze the options */
999 for (int i = 0; i < 32; i++)
1002 if (window_flag_desc[i])
1005 window_mask[n] |= (1L << i);
1011 * Set the "default" window flags
1012 * Window 1 : Display messages
1013 * Window 2 : Display inven/equip
1015 window_flag[1] = 1L << A_MAX;
1016 window_flag[2] = 1L << 0;
1018 /*** Pre-allocate space for the "format()" buffer ***/
1020 /* Hack -- Just call the "format()" function */
1021 (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1027 * @brief オブジェクト配列を初期化する /
1028 * Initialize some other arrays
1031 static errr init_object_alloc(void)
1033 s16b aux[MAX_DEPTH];
1034 (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1036 s16b num[MAX_DEPTH];
1037 (void)C_WIPE(&num, MAX_DEPTH, s16b);
1039 /* Free the old "alloc_kind_table" (if it exists) */
1040 if (alloc_kind_table)
1042 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1045 /* Size of "alloc_kind_table" */
1046 alloc_kind_size = 0;
1048 /* Scan the objects */
1049 for (int i = 1; i < max_k_idx; i++)
1054 /* Scan allocation pairs */
1055 for (int j = 0; j < 4; j++)
1057 /* Count the "legal" entries */
1058 if (k_ptr->chance[j])
1060 /* Count the entries */
1063 /* Group by level */
1064 num[k_ptr->locale[j]]++;
1069 /* Collect the level indexes */
1070 for (int i = 1; i < MAX_DEPTH; i++)
1072 /* Group by level */
1073 num[i] += num[i - 1];
1076 if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1078 /*** Initialize object allocation info ***/
1080 /* Allocate the alloc_kind_table */
1081 C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1083 /* Access the table entry */
1085 table = alloc_kind_table;
1087 /* Scan the objects */
1088 for (int i = 1; i < max_k_idx; i++)
1093 /* Scan allocation pairs */
1094 for (int j = 0; j < 4; j++)
1096 /* Count the "legal" entries */
1097 if (k_ptr->chance[j] == 0) continue;
1099 /* Extract the base level */
1100 int x = k_ptr->locale[j];
1102 /* Extract the base probability */
1103 int p = (100 / k_ptr->chance[j]);
1105 /* Skip entries preceding our locale */
1106 int y = (x > 0) ? num[x - 1] : 0;
1108 /* Skip previous entries at this locale */
1111 /* Load the entry */
1112 table[z].index = (KIND_OBJECT_IDX)i;
1113 table[z].level = (DEPTH)x;
1114 table[z].prob1 = (PROB)p;
1115 table[z].prob2 = (PROB)p;
1116 table[z].prob3 = (PROB)p;
1118 /* Another entry complete for this locale */
1128 * @brief モンスター配列と生成テーブルを初期化する /
1129 * Initialize some other arrays
1132 static errr init_alloc(void)
1134 monster_race *r_ptr;
1137 /* Allocate the "r_info" array */
1138 C_MAKE(elements, max_r_idx, tag_type);
1140 /* Scan the monsters */
1141 for (int i = 1; i < max_r_idx; i++)
1143 elements[i].tag = r_info[i].level;
1144 elements[i].index = i;
1147 tag_sort(elements, max_r_idx);
1149 /*** Initialize monster allocation info ***/
1151 /* Size of "alloc_race_table" */
1152 alloc_race_size = max_r_idx;
1154 /* Allocate the alloc_race_table */
1155 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1157 /* Scan the monsters */
1158 for (int i = 1; i < max_r_idx; i++)
1160 /* Get the i'th race */
1161 r_ptr = &r_info[elements[i].index];
1163 /* Count valid pairs */
1164 if (r_ptr->rarity == 0) continue;
1166 /* Extract the base level */
1167 int x = r_ptr->level;
1169 /* Extract the base probability */
1170 int p = (100 / r_ptr->rarity);
1172 /* Load the entry */
1173 alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
1174 alloc_race_table[i].level = (DEPTH)x;
1175 alloc_race_table[i].prob1 = (PROB)p;
1176 alloc_race_table[i].prob2 = (PROB)p;
1177 alloc_race_table[i].prob3 = (PROB)p;
1180 /* Free the "r_info" array */
1181 C_KILL(elements, max_r_idx, tag_type);
1182 (void)init_object_alloc();
1188 * @brief 画面左下にシステムメッセージを表示する /
1189 * Hack -- take notes on line 23
1192 static void init_note(concptr str)
1194 term_erase(0, 23, 255);
1195 term_putstr(20, 23, -1, TERM_WHITE, str);
1201 * @brief 全ゲームデータ読み込みのサブルーチン /
1202 * Hack -- Explain a broken "lib" folder and quit (see below).
1206 * This function is "messy" because various things
1207 * may or may not be initialized, but the "plog()" and "quit()"
1208 * functions are "supposed" to work under any conditions.
1211 static void init_angband_aux(concptr why)
1217 plog("'lib'ディレクトリが存在しないか壊れているようです。");
1220 plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
1223 plog("該当する'README'ファイルを読んで確認してみて下さい。");
1225 /* Quit with error */
1229 plog("The 'lib' directory is probably missing or broken.");
1232 plog("Perhaps the archive was not extracted correctly.");
1235 plog("See the 'README' file for more information.");
1237 /* Quit with error */
1238 quit("Fatal Error.");
1245 * @brief 全ゲームデータ読み込みのメインルーチン /
1246 * Hack -- main Angband initialization entry point
1250 * This function is "messy" because various things
1251 * may or may not be initialized, but the "plog()" and "quit()"
1252 * functions are "supposed" to work under any conditions.
1253 * Verify some files, display the "news.txt" file, create
1254 * the high score file, initialize all internal arrays, and
1255 * load the basic "user pref files".
1256 * Be very careful to keep track of the order in which things
1257 * are initialized, in particular, the only thing *known* to
1258 * be available when this function is called is the "z-term.c"
1259 * package, and that may not be fully initialized until the
1260 * end of this function, when the default "user pref files"
1261 * are loaded and "term_xtra(TERM_XTRA_REACT,0)" is called.
1262 * Note that this function attempts to verify the "news" file,
1263 * and the game aborts (cleanly) on failure, since without the
1264 * "news" file, it is likely that the "lib" folder has not been
1265 * correctly located. Otherwise, the news file is displayed for
1267 * Note that this function attempts to verify (or create) the
1268 * "high score" file, and the game aborts (cleanly) on failure,
1269 * since one of the most common "extraction" failures involves
1270 * failing to extract all sub-directories (even empty ones), such
1271 * as by failing to use the "-d" option of "pkunzip", or failing
1272 * to use the "save empty directories" option with "Compact Pro".
1273 * This error will often be caught by the "high score" creation
1274 * code below, since the "lib/apex" directory, being empty in the
1275 * standard distributions, is most likely to be "lost", making it
1276 * impossible to create the high score file.
1277 * Note that various things are initialized by this function,
1278 * including everything that was once done by "init_some_arrays".
1279 * This initialization involves the parsing of special files
1280 * in the "lib/data" and sometimes the "lib/edit" directories.
1281 * Note that the "template" files are initialized first, since they
1282 * often contain errors. This means that macros and message recall
1283 * and things like that are not available until after they are done.
1284 * We load the default "user pref files" here in case any "color"
1285 * changes are needed before character creation.
1286 * Note that the "graf-xxx.prf" file must be loaded separately,
1287 * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1290 void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*))
1292 /*** Verify the "news" file ***/
1294 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1296 /* Attempt to open the file */
1297 int fd = fd_open(buf, O_RDONLY);
1304 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
1306 /* Crash and burn */
1307 init_angband_aux(why);
1312 /*** Display the "news" file ***/
1314 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1316 /* Open the News file */
1318 fp = angband_fopen(buf, "r");
1323 /* Dump the file to the screen */
1325 while (0 == angband_fgets(fp, buf, sizeof(buf)))
1327 /* Display and advance */
1328 term_putstr(0, i++, -1, TERM_WHITE, buf);
1336 /*** Verify (or create) the "high score" file ***/
1337 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1339 /* Attempt to open the high score file */
1340 fd = fd_open(buf, O_RDONLY);
1342 BIT_FLAGS file_permission = 0664;
1345 /* Grab permissions */
1346 safe_setuid_grab(player_ptr);
1348 /* Create a new high score file */
1349 fd = fd_make(buf, file_permission);
1351 /* Drop permissions */
1359 sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
1361 /* Crash and burn */
1362 init_angband_aux(why);
1370 /*** Initialize some arrays ***/
1372 /* Initialize misc. values */
1373 init_note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
1374 if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
1376 init_note(_("[データの初期化中... (地形)]", "[Initializing arrays... (features)]"));
1377 if (init_f_info(player_ptr)) quit(_("地形初期化不能", "Cannot initialize features"));
1378 if (init_feat_variables()) quit(_("地形初期化不能", "Cannot initialize features"));
1380 /* Initialize object info */
1381 init_note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
1382 if (init_k_info(player_ptr)) quit(_("アイテム初期化不能", "Cannot initialize objects"));
1384 /* Initialize artifact info */
1385 init_note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
1386 if (init_a_info(player_ptr)) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
1389 /* Initialize ego-item info */
1390 init_note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
1391 if (init_e_info(player_ptr)) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
1394 /* Initialize monster info */
1395 init_note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
1396 if (init_r_info(player_ptr)) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
1399 /* Initialize dungeon info */
1400 init_note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
1401 if (init_d_info(player_ptr)) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
1403 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
1404 if (d_info[i].final_guardian)
1405 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
1408 /* Initialize magic info */
1409 init_note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
1410 if (init_m_info(player_ptr)) quit(_("魔法初期化不能", "Cannot initialize magic"));
1412 /* Initialize weapon_exp info */
1413 init_note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
1414 if (init_s_info(player_ptr)) quit(_("熟練度初期化不能", "Cannot initialize skill"));
1416 /* Initialize wilderness array */
1417 init_note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
1419 if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
1421 /* Initialize town array */
1422 init_note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
1423 if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
1425 /* Initialize building array */
1426 init_note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
1427 if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
1429 /* Initialize quest array */
1430 init_note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
1431 if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
1433 /* Initialize vault info */
1434 if (init_v_info(player_ptr)) quit(_("vault 初期化不能", "Cannot initialize vaults"));
1436 /* Initialize some other arrays */
1437 init_note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
1438 if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
1440 /* Initialize some other arrays */
1441 init_note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
1442 if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
1444 /*** Load default user pref files ***/
1446 /* Initialize feature info */
1447 init_note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
1449 /* Access the "basic" pref file */
1450 strcpy(buf, "pref.prf");
1452 /* Process that file */
1453 process_pref_file(player_ptr, buf, process_autopick_file_command);
1455 /* Access the "basic" system pref file */
1456 sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
1458 /* Process that file */
1459 process_pref_file(player_ptr, buf, process_autopick_file_command);
1461 init_note(_("[初期化終了]", "[Initialization complete]"));
1469 static void put_title(void)
1473 sprintf(title, _("変愚蛮怒 %d.%d.%d.%d(%s)", "Hengband %d.%d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH, H_VER_EXTRA,
1475 sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
1477 IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
1478 int col = (80 - strlen(title)) / 2;
1479 col = col < 0 ? 0 : col;
1480 const int VER_INFO_ROW = 3; //!< タイトル表記(行)
1481 prt(title, VER_INFO_ROW, col);
1486 * @brief チェックサム情報を出力 / Get check sum in string form
1487 * @return チェックサム情報の文字列
1489 concptr get_check_sum(void)
1491 return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",