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/trap.h"
45 #include "info-reader/artifact-reader.h"
46 #include "info-reader/dungeon-reader.h"
47 #include "info-reader/ego-reader.h"
48 #include "info-reader/feature-reader.h"
49 #include "info-reader/general-parser.h"
50 #include "info-reader/kind-reader.h"
51 #include "info-reader/magic-reader.h"
52 #include "info-reader/race-reader.h"
53 #include "info-reader/skill-reader.h"
54 #include "info-reader/parse-error-types.h"
55 #include "info-reader/vault-reader.h"
56 #include "io/files-util.h"
57 #include "io/read-pref-file.h"
58 #include "io/uid-checker.h"
59 #include "market/articles-on-sale.h"
60 #include "monster-race/monster-race.h"
61 #include "monster-race/race-flags7.h"
62 #include "object-enchant/artifact.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/building-type-definition.h"
74 #include "system/system-variables.h"
75 #include "term/gameterm.h"
76 #include "term/screen-processor.h"
77 #include "term/term-color-types.h"
78 #include "util/angband-files.h"
79 #include "util/quarks.h"
80 #include "util/tag-sorter.h"
81 #include "view/display-messages.h"
82 #include "world/world.h"
85 #include <sys/types.h>
88 * @brief マクロ登録の最大数 / Maximum number of macros (see "io.c")
89 * @note Default: assume at most 256 macros are used
91 static const int MACRO_MAX = 256;
93 static void put_title(void);
96 * @brief 各データファイルを読み取るためのパスを取得する
97 * Find the default paths to all of our important sub-directories.
98 * @param path パス保管先の文字列
102 * The purpose of each sub-directory is described in "variable.c".
103 * All of the sub-directories should, by default, be located inside
104 * the main "lib" directory, whose location is very system dependant.
105 * This function takes a writable buffer, initially containing the
106 * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
107 * or a system dependant string, for example, ":lib:". The buffer
108 * must be large enough to contain at least 32 more characters.
109 * Various command line options may allow some of the important
110 * directories to be changed to user-specified directories, most
111 * importantly, the "info" and "user" and "save" directories,
112 * but this is done after this function, see "main.c".
113 * In general, the initial path should end in the appropriate "PATH_SEP"
114 * string. All of the "sub-directory" paths (created below or supplied
115 * by the user) will NOT end in the "PATH_SEP" string, see the special
116 * "path_build()" function in "util.c" for more information.
117 * Mega-Hack -- support fat raw files under NEXTSTEP, using special
118 * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
119 * requiring the directories to be created by hand by the user.
120 * Hack -- first we free all the strings, since this is known
121 * to succeed even if the strings have not been allocated yet,
122 * as long as the variables start out as "NULL". This allows
123 * this function to be called multiple times, for example, to
124 * try several base "path" values until a good one is found.
127 void init_file_paths(char *path)
131 #ifdef PRIVATE_USER_PATH
133 #endif /* PRIVATE_USER_PATH */
135 /*** Free everything ***/
137 /* Free the main path */
138 string_free(ANGBAND_DIR);
140 /* Free the sub-paths */
141 string_free(ANGBAND_DIR_APEX);
142 string_free(ANGBAND_DIR_BONE);
143 string_free(ANGBAND_DIR_DATA);
144 string_free(ANGBAND_DIR_EDIT);
145 string_free(ANGBAND_DIR_SCRIPT);
146 string_free(ANGBAND_DIR_FILE);
147 string_free(ANGBAND_DIR_HELP);
148 string_free(ANGBAND_DIR_INFO);
149 string_free(ANGBAND_DIR_SAVE);
150 string_free(ANGBAND_DIR_USER);
151 string_free(ANGBAND_DIR_XTRA);
153 /*** Prepare the "path" ***/
155 /* Hack -- save the main directory */
156 ANGBAND_DIR = string_make(path);
158 /* Prepare to append to the Base Path */
159 tail = path + strlen(path);
161 /*** Build the sub-directory names ***/
163 /* Build a path name */
164 strcpy(tail, "apex");
165 ANGBAND_DIR_APEX = string_make(path);
167 /* Build a path name */
168 strcpy(tail, "bone");
169 ANGBAND_DIR_BONE = string_make(path);
171 /* Build a path name */
172 strcpy(tail, "data");
173 ANGBAND_DIR_DATA = string_make(path);
175 /* Build a path name */
176 strcpy(tail, "edit");
177 ANGBAND_DIR_EDIT = string_make(path);
179 /* Build a path name */
180 strcpy(tail, "script");
181 ANGBAND_DIR_SCRIPT = string_make(path);
183 /* Build a path name */
184 strcpy(tail, "file");
185 ANGBAND_DIR_FILE = string_make(path);
187 /* Build a path name */
188 strcpy(tail, "help");
189 ANGBAND_DIR_HELP = string_make(path);
191 /* Build a path name */
192 strcpy(tail, "info");
193 ANGBAND_DIR_INFO = string_make(path);
195 /* Build a path name */
196 strcpy(tail, "pref");
197 ANGBAND_DIR_PREF = string_make(path);
199 /* Build a path name */
200 strcpy(tail, "save");
201 ANGBAND_DIR_SAVE = string_make(path);
203 #ifdef PRIVATE_USER_PATH
205 /* Build the path to the user specific directory */
206 path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
208 /* Build a relative path name */
209 ANGBAND_DIR_USER = string_make(buf);
211 #else /* PRIVATE_USER_PATH */
213 /* Build a path name */
214 strcpy(tail, "user");
215 ANGBAND_DIR_USER = string_make(path);
217 #endif /* PRIVATE_USER_PATH */
219 /* Build a path name */
220 strcpy(tail, "xtra");
221 ANGBAND_DIR_XTRA = string_make(path);
226 * Hack -- help give useful error messages
228 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
229 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
232 * エラーメッセージの名称定義 / Standard error message text
234 concptr err_str[PARSE_ERROR_MAX] =
251 "missing record header",
252 "non-sequential records",
253 "invalid flag specification",
254 "undefined directive",
256 "coordinates out of bounds",
258 "undefined terrain tag",
266 static angband_header v_head; /*!< Vault情報のヘッダ構造体 */
267 static angband_header k_head; /*!< ペースアイテム情報のヘッダ構造体 */
268 static angband_header a_head; /*!< 固定アーティファクト情報のヘッダ構造体 */
269 static angband_header e_head; /*!< アイテムエゴ情報のヘッダ構造体 */
270 static angband_header r_head; /*!< モンスター種族情報のヘッダ構造体 */
271 static angband_header d_head; /*!< ダンジョン情報のヘッダ構造体 */
272 static angband_header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
273 static angband_header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
276 * @brief テキストファイルとrawファイルの更新時刻を比較する
277 * Find the default paths to all of our important sub-directories.
278 * @param fd ファイルディスクリプタ
279 * @param template_file ファイル名
280 * @return テキストの方が新しいか、rawファイルがなく更新の必要がある場合-1、更新の必要がない場合0。
282 static errr check_modification_date(int fd, concptr template_file)
284 struct stat txt_stat, raw_stat;
286 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
288 /* Access stats on text file */
289 if (stat(buf, &txt_stat))
294 /* Access stats on raw file */
295 if (fstat(fd, &raw_stat))
300 /* Ensure text file is not newer than raw file */
301 if (txt_stat.st_mtime > raw_stat.st_mtime)
310 /*** Initialize from binary image files ***/
313 * @brief rawファイルからのデータの読み取り処理
314 * Initialize the "*_info" array, by parsing a binary "image" file
315 * @param fd ファイルディスクリプタ
316 * @param head rawファイルのヘッダ
319 static errr init_info_raw(int fd, angband_header *head)
323 /* Read and Verify the header */
324 if (fd_read(fd, (char*)(&test), sizeof(angband_header)) ||
325 (test.v_major != head->v_major) ||
326 (test.v_minor != head->v_minor) ||
327 (test.v_patch != head->v_patch) ||
328 (test.info_num != head->info_num) ||
329 (test.info_len != head->info_len) ||
330 (test.head_size != head->head_size) ||
331 (test.info_size != head->info_size))
337 /* Accept the header */
340 /* Allocate the "*_info" array */
341 C_MAKE(head->info_ptr, head->info_size, char);
343 /* Read the "*_info" array */
344 fd_read(fd, head->info_ptr, head->info_size);
348 /* Allocate the "*_name" array */
349 C_MAKE(head->name_ptr, head->name_size, char);
351 /* Read the "*_name" array */
352 fd_read(fd, head->name_ptr, head->name_size);
357 /* Allocate the "*_text" array */
358 C_MAKE(head->text_ptr, head->text_size, char);
360 /* Read the "*_text" array */
361 fd_read(fd, head->text_ptr, head->text_size);
366 /* Allocate the "*_tag" array */
367 C_MAKE(head->tag_ptr, head->tag_size, char);
369 /* Read the "*_tag" array */
370 fd_read(fd, head->tag_ptr, head->tag_size);
380 * Initialize the header of an *_info.raw file.
381 * @param head rawファイルのヘッダ
386 static void init_header(angband_header *head, IDX num, int len)
388 /* Save the "version" */
389 head->v_major = FAKE_VER_MAJOR;
390 head->v_minor = FAKE_VER_MINOR;
391 head->v_patch = FAKE_VER_PATCH;
394 /* Save the "record" information */
395 head->info_num = (IDX)num;
396 head->info_len = len;
398 /* Save the size of "*_head" and "*_info" */
399 head->head_size = sizeof(angband_header);
400 head->info_size = head->info_num * head->info_len;
404 static void update_header(angband_header *head, void **info, char **name, char **text, char **tag)
406 if (info) *info = head->info_ptr;
407 if (name) *name = head->name_ptr;
408 if (text) *text = head->text_ptr;
409 if (tag) *tag = head->tag_ptr;
415 * Initialize the "*_info" array
416 * @param filename ファイル名(拡張子txt/raw)
417 * @param head 処理に用いるヘッダ構造体
418 * @param info データ保管先の構造体ポインタ
419 * @param name 名称用可変文字列の保管先
420 * @param text テキスト用可変文字列の保管先
421 * @param tag タグ用可変文字列の保管先
424 * Note that we let each entry have a unique "name" and "text" string,
425 * even if the string happens to be empty (everyone has a unique '\0').
427 static errr init_info(concptr filename, angband_header *head, void **info, char **name, char **text, char **tag)
432 /*** Load the binary image file ***/
433 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
435 /* Attempt to open the "raw" file */
436 int fd = fd_open(buf, O_RDONLY);
438 /* Process existing "raw" file */
442 err = check_modification_date(fd, format("%s.txt", filename));
444 /* Attempt to parse the "raw" file */
446 err = init_info_raw(fd, head);
450 /* Do we have to parse the *.txt file? */
451 BIT_FLAGS file_permission = 0644;
454 update_header(head, info, name, text, tag);
458 /*** Make the fake arrays ***/
459 C_MAKE(head->info_ptr, head->info_size, char);
461 /* Hack -- make "fake" arrays */
462 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
463 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
464 if (tag) C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
466 if (info) (*info) = head->info_ptr;
467 if (name) (*name) = head->name_ptr;
468 if (text) (*text) = head->text_ptr;
469 if (tag) (*tag) = head->tag_ptr;
471 /*** Load the ascii template file ***/
472 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
474 fp = angband_fopen(buf, "r");
477 if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
480 err = init_info_txt(fp, buf, head, head->parse_info_txt);
490 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
492 msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
493 msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
494 msg_format("構文 '%s'。", buf);
498 quit(format("'%s.txt'ファイルにエラー", filename));
501 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
503 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
504 msg_format("Record %d contains a '%s' error.", error_idx, oops);
505 msg_format("Parsing '%s'.", buf);
509 quit(format("Error in '%s.txt' file.", filename));
513 /*** Make final retouch on fake tags ***/
516 (*head->retouch)(head);
519 /*** Dump the binary image file ***/
520 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
522 /* Grab permissions */
525 /* Kill the old file */
528 /* Attempt to create the raw file */
529 fd = fd_make(buf, file_permission);
531 /* Drop permissions */
534 /* Dump to the file */
538 fd_write(fd, (concptr)(head), head->head_size);
540 /* Dump the "*_info" array */
541 fd_write(fd, head->info_ptr, head->info_size);
543 /* Dump the "*_name" array */
544 fd_write(fd, head->name_ptr, head->name_size);
546 /* Dump the "*_text" array */
547 fd_write(fd, head->text_ptr, head->text_size);
549 /* Dump the "*_tag" array */
550 fd_write(fd, head->tag_ptr, head->tag_size);
556 /*** Kill the fake arrays ***/
558 /* Free the "*_info" array */
559 C_KILL(head->info_ptr, head->info_size, char);
561 /* Hack -- Free the "fake" arrays */
562 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
563 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
564 if (tag) C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
566 /*** Load the binary image file ***/
567 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
569 /* Attempt to open the "raw" file */
570 fd = fd_open(buf, O_RDONLY);
572 /* Process existing "raw" file */
573 if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
575 /* Attempt to parse the "raw" file */
576 err = init_info_raw(fd, head);
580 if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
582 update_header(head, info, name, text, tag);
588 * @brief 地形情報読み込みのメインルーチン /
589 * Initialize the "f_info" array
592 static errr init_f_info(void)
594 /* Init the header */
595 init_header(&f_head, max_f_idx, sizeof(feature_type));
597 /* Save a pointer to the parsing function */
598 f_head.parse_info_txt = parse_f_info;
600 /* Save a pointer to the retouch fake tags */
601 f_head.retouch = retouch_f_info;
603 return init_info("f_info", &f_head,
604 (void*)&f_info, &f_name, NULL, &f_tag);
609 * @brief ベースアイテム情報読み込みのメインルーチン /
610 * Initialize the "k_info" array
613 static errr init_k_info(void)
615 /* Init the header */
616 init_header(&k_head, max_k_idx, sizeof(object_kind));
618 /* Save a pointer to the parsing function */
619 k_head.parse_info_txt = parse_k_info;
621 return init_info("k_info", &k_head,
622 (void*)&k_info, &k_name, &k_text, NULL);
627 * @brief 固定アーティファクト情報読み込みのメインルーチン /
628 * Initialize the "a_info" array
631 static errr init_a_info(void)
633 /* Init the header */
634 init_header(&a_head, max_a_idx, sizeof(artifact_type));
636 /* Save a pointer to the parsing function */
637 a_head.parse_info_txt = parse_a_info;
639 return init_info("a_info", &a_head,
640 (void*)&a_info, &a_name, &a_text, NULL);
645 * @brief 固定アーティファクト情報読み込みのメインルーチン /
646 * Initialize the "e_info" array
649 static errr init_e_info(void)
651 /* Init the header */
652 init_header(&e_head, max_e_idx, sizeof(ego_item_type));
654 /* Save a pointer to the parsing function */
655 e_head.parse_info_txt = parse_e_info;
657 return init_info("e_info", &e_head,
658 (void*)&e_info, &e_name, &e_text, NULL);
663 * @brief モンスター種族情報読み込みのメインルーチン /
664 * Initialize the "r_info" array
667 static errr init_r_info(void)
669 /* Init the header */
670 init_header(&r_head, max_r_idx, sizeof(monster_race));
672 /* Save a pointer to the parsing function */
673 r_head.parse_info_txt = parse_r_info;
675 return init_info("r_info", &r_head,
676 (void*)&r_info, &r_name, &r_text, NULL);
681 * @brief ダンジョン情報読み込みのメインルーチン /
682 * Initialize the "d_info" array
685 static errr init_d_info(void)
687 /* Init the header */
688 init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
690 /* Save a pointer to the parsing function */
691 d_head.parse_info_txt = parse_d_info;
693 return init_info("d_info", &d_head,
694 (void*)&d_info, &d_name, &d_text, NULL);
699 * @brief Vault情報読み込みのメインルーチン /
700 * Initialize the "v_info" array
703 * Note that we let each entry have a unique "name" and "text" string,
704 * even if the string happens to be empty (everyone has a unique '\0').
706 errr init_v_info(void)
708 /* Init the header */
709 init_header(&v_head, max_v_idx, sizeof(vault_type));
711 /* Save a pointer to the parsing function */
712 v_head.parse_info_txt = parse_v_info;
714 return init_info("v_info", &v_head,
715 (void*)&v_info, &v_name, &v_text, NULL);
720 * @brief 職業技能情報読み込みのメインルーチン /
721 * Initialize the "s_info" array
724 static errr init_s_info(void)
726 /* Init the header */
727 init_header(&s_head, MAX_CLASS, sizeof(skill_table));
729 /* Save a pointer to the parsing function */
730 s_head.parse_info_txt = parse_s_info;
732 return init_info("s_info", &s_head,
733 (void*)&s_info, NULL, NULL, NULL);
738 * @brief 職業魔法情報読み込みのメインルーチン /
739 * Initialize the "m_info" array
742 static errr init_m_info(void)
744 /* Init the header */
745 init_header(&m_head, MAX_CLASS, sizeof(player_magic));
747 /* Save a pointer to the parsing function */
748 m_head.parse_info_txt = parse_m_info;
750 return init_info("m_info", &m_head,
751 (void*)&m_info, NULL, NULL, NULL);
756 * @brief 基本情報読み込みのメインルーチン /
757 * Initialize misc. values
758 * @param player_ptr プレーヤーへの参照ポインタ
761 static errr init_misc(player_type *player_ptr)
763 return parse_fixed_map(player_ptr, "misc.txt", 0, 0, 0, 0);
768 * @brief 町情報読み込みのメインルーチン /
769 * Initialize town array
772 static errr init_towns(void)
774 /* Allocate the towns */
775 C_MAKE(town_info, max_towns, town_type);
777 for (int i = 1; i < max_towns; i++)
779 /*** Prepare the Stores ***/
781 /* Allocate the stores */
782 C_MAKE(town_info[i].store, MAX_STORES, store_type);
784 /* Fill in each store */
785 for (int j = 0; j < MAX_STORES; j++)
787 /* Access the store */
788 store_type *store_ptr = &town_info[i].store[j];
790 if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
792 /* Assume full stock */
795 * 我が家が 20 ページまで使える隠し機能のための準備。
796 * オプションが有効でもそうでなくても一応スペースを作っておく。
800 store_ptr->stock_size = (STORE_INVEN_MAX * 10);
802 else if (j == STORE_MUSEUM)
804 store_ptr->stock_size = (STORE_INVEN_MAX * 50);
808 store_ptr->stock_size = STORE_INVEN_MAX;
811 /* Allocate the stock */
812 C_MAKE(store_ptr->stock, store_ptr->stock_size, object_type);
814 /* No table for the black market or home */
815 if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
817 /* Assume full table */
818 store_ptr->table_size = STORE_CHOICES;
820 /* Allocate the stock */
821 C_MAKE(store_ptr->table, store_ptr->table_size, s16b);
823 /* Scan the choices */
824 for (int k = 0; k < STORE_CHOICES; k++)
826 KIND_OBJECT_IDX k_idx;
828 /* Extract the tval/sval codes */
829 int tv = store_table[j][k][0];
830 int sv = store_table[j][k][1];
833 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
835 object_kind *k_ptr = &k_info[k_idx];
838 if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
842 if (k_idx == max_k_idx) continue;
844 /* Add that item index to the table */
845 store_ptr->table[store_ptr->table_num++] = k_idx;
854 * @brief 店情報初期化のメインルーチン /
855 * Initialize buildings
858 errr init_buildings(void)
860 for (int i = 0; i < MAX_BLDG; i++)
862 building[i].name[0] = '\0';
863 building[i].owner_name[0] = '\0';
864 building[i].owner_race[0] = '\0';
866 for (int j = 0; j < 8; j++)
868 building[i].act_names[j][0] = '\0';
869 building[i].member_costs[j] = 0;
870 building[i].other_costs[j] = 0;
871 building[i].letters[j] = 0;
872 building[i].actions[j] = 0;
873 building[i].action_restr[j] = 0;
876 for (int j = 0; j < MAX_CLASS; j++)
878 building[i].member_class[j] = 0;
881 for (int j = 0; j < MAX_RACES; j++)
883 building[i].member_race[j] = 0;
886 for (int j = 0; j < MAX_MAGIC + 1; j++)
888 building[i].member_realm[j] = 0;
897 * @brief クエスト情報初期化のメインルーチン /
898 * Initialize quest array
901 static errr init_quests(void)
903 /* Allocate the quests */
904 C_MAKE(quest, max_q_idx, quest_type);
906 /* Set all quest to "untaken" */
907 for (int i = 0; i < max_q_idx; i++)
909 quest[i].status = QUEST_STATUS_UNTAKEN;
916 * @brief その他の初期情報更新 /
917 * Initialize some other arrays
920 static errr init_other(player_type *player_ptr)
922 player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
923 floor_type *floor_ptr = player_ptr->current_floor_ptr;
925 /*** Prepare the "dungeon" information ***/
927 /* Allocate and Wipe the object list */
928 C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
930 /* Allocate and Wipe the monster list */
931 C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
933 /* Allocate and Wipe the monster process list */
934 for (int i = 0; i < MAX_MTIMED; i++)
936 C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
939 /* Allocate and Wipe the max dungeon level */
940 C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
942 for (int i = 0; i < MAX_HGT; i++)
944 C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
947 /*** Prepare the various "bizarre" arrays ***/
949 /* Macro variables */
950 C_MAKE(macro__pat, MACRO_MAX, concptr);
951 C_MAKE(macro__act, MACRO_MAX, concptr);
952 C_MAKE(macro__cmd, MACRO_MAX, bool);
954 /* Macro action buffer */
955 C_MAKE(macro__buf, 1024, char);
957 /* Quark variables */
960 /* Message variables */
961 C_MAKE(message__ptr, MESSAGE_MAX, u32b);
962 C_MAKE(message__buf, MESSAGE_BUF, char);
964 /* Hack -- No messages yet */
965 message__tail = MESSAGE_BUF;
967 /*** Prepare the options ***/
969 /* Scan the options */
970 for (int i = 0; option_info[i].o_desc; i++)
972 int os = option_info[i].o_set;
973 int ob = option_info[i].o_bit;
975 /* Set the "default" options */
976 if (!option_info[i].o_var) continue;
979 option_mask[os] |= (1L << ob);
982 if (option_info[i].o_norm)
985 option_flag[os] |= (1L << ob);
989 option_flag[os] &= ~(1L << ob);
993 /* Analyze the windows */
994 for (int n = 0; n < 8; n++)
996 /* Analyze the options */
997 for (int i = 0; i < 32; i++)
1000 if (window_flag_desc[i])
1003 window_mask[n] |= (1L << i);
1009 * Set the "default" window flags
1010 * Window 1 : Display messages
1011 * Window 2 : Display inven/equip
1013 window_flag[1] = 1L << A_MAX;
1014 window_flag[2] = 1L << 0;
1016 /*** Pre-allocate space for the "format()" buffer ***/
1018 /* Hack -- Just call the "format()" function */
1019 (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1025 * @brief オブジェクト配列を初期化する /
1026 * Initialize some other arrays
1029 static errr init_object_alloc(void)
1031 s16b aux[MAX_DEPTH];
1032 (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1034 s16b num[MAX_DEPTH];
1035 (void)C_WIPE(&num, MAX_DEPTH, s16b);
1037 /* Free the old "alloc_kind_table" (if it exists) */
1038 if (alloc_kind_table)
1040 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1043 /* Size of "alloc_kind_table" */
1044 alloc_kind_size = 0;
1046 /* Scan the objects */
1047 for (int i = 1; i < max_k_idx; i++)
1052 /* Scan allocation pairs */
1053 for (int j = 0; j < 4; j++)
1055 /* Count the "legal" entries */
1056 if (k_ptr->chance[j])
1058 /* Count the entries */
1061 /* Group by level */
1062 num[k_ptr->locale[j]]++;
1067 /* Collect the level indexes */
1068 for (int i = 1; i < MAX_DEPTH; i++)
1070 /* Group by level */
1071 num[i] += num[i - 1];
1074 if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1076 /*** Initialize object allocation info ***/
1078 /* Allocate the alloc_kind_table */
1079 C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1081 /* Access the table entry */
1083 table = alloc_kind_table;
1085 /* Scan the objects */
1086 for (int i = 1; i < max_k_idx; i++)
1091 /* Scan allocation pairs */
1092 for (int j = 0; j < 4; j++)
1094 /* Count the "legal" entries */
1095 if (k_ptr->chance[j] == 0) continue;
1097 /* Extract the base level */
1098 int x = k_ptr->locale[j];
1100 /* Extract the base probability */
1101 int p = (100 / k_ptr->chance[j]);
1103 /* Skip entries preceding our locale */
1104 int y = (x > 0) ? num[x - 1] : 0;
1106 /* Skip previous entries at this locale */
1109 /* Load the entry */
1110 table[z].index = (KIND_OBJECT_IDX)i;
1111 table[z].level = (DEPTH)x;
1112 table[z].prob1 = (PROB)p;
1113 table[z].prob2 = (PROB)p;
1114 table[z].prob3 = (PROB)p;
1116 /* Another entry complete for this locale */
1126 * @brief モンスター配列と生成テーブルを初期化する /
1127 * Initialize some other arrays
1130 static errr init_alloc(void)
1132 monster_race *r_ptr;
1135 /* Allocate the "r_info" array */
1136 C_MAKE(elements, max_r_idx, tag_type);
1138 /* Scan the monsters */
1139 for (int i = 1; i < max_r_idx; i++)
1141 elements[i].tag = r_info[i].level;
1142 elements[i].index = i;
1145 tag_sort(elements, max_r_idx);
1147 /*** Initialize monster allocation info ***/
1149 /* Size of "alloc_race_table" */
1150 alloc_race_size = max_r_idx;
1152 /* Allocate the alloc_race_table */
1153 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1155 /* Scan the monsters */
1156 for (int i = 1; i < max_r_idx; i++)
1158 /* Get the i'th race */
1159 r_ptr = &r_info[elements[i].index];
1161 /* Count valid pairs */
1162 if (r_ptr->rarity == 0) continue;
1164 /* Extract the base level */
1165 int x = r_ptr->level;
1167 /* Extract the base probability */
1168 int p = (100 / r_ptr->rarity);
1170 /* Load the entry */
1171 alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
1172 alloc_race_table[i].level = (DEPTH)x;
1173 alloc_race_table[i].prob1 = (PROB)p;
1174 alloc_race_table[i].prob2 = (PROB)p;
1175 alloc_race_table[i].prob3 = (PROB)p;
1178 /* Free the "r_info" array */
1179 C_KILL(elements, max_r_idx, tag_type);
1180 (void)init_object_alloc();
1186 * @brief 画面左下にシステムメッセージを表示する /
1187 * Hack -- take notes on line 23
1190 static void note(concptr str)
1192 Term_erase(0, 23, 255);
1193 Term_putstr(20, 23, -1, TERM_WHITE, str);
1199 * @brief 全ゲームデータ読み込みのサブルーチン /
1200 * Hack -- Explain a broken "lib" folder and quit (see below).
1204 * This function is "messy" because various things
1205 * may or may not be initialized, but the "plog()" and "quit()"
1206 * functions are "supposed" to work under any conditions.
1209 static void init_angband_aux(concptr why)
1215 plog("'lib'ディレクトリが存在しないか壊れているようです。");
1218 plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
1221 plog("該当する'README'ファイルを読んで確認してみて下さい。");
1223 /* Quit with error */
1227 plog("The 'lib' directory is probably missing or broken.");
1230 plog("Perhaps the archive was not extracted correctly.");
1233 plog("See the 'README' file for more information.");
1235 /* Quit with error */
1236 quit("Fatal Error.");
1243 * @brief 全ゲームデータ読み込みのメインルーチン /
1244 * Hack -- main Angband initialization entry point
1248 * This function is "messy" because various things
1249 * may or may not be initialized, but the "plog()" and "quit()"
1250 * functions are "supposed" to work under any conditions.
1251 * Verify some files, display the "news.txt" file, create
1252 * the high score file, initialize all internal arrays, and
1253 * load the basic "user pref files".
1254 * Be very careful to keep track of the order in which things
1255 * are initialized, in particular, the only thing *known* to
1256 * be available when this function is called is the "z-term.c"
1257 * package, and that may not be fully initialized until the
1258 * end of this function, when the default "user pref files"
1259 * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1260 * Note that this function attempts to verify the "news" file,
1261 * and the game aborts (cleanly) on failure, since without the
1262 * "news" file, it is likely that the "lib" folder has not been
1263 * correctly located. Otherwise, the news file is displayed for
1265 * Note that this function attempts to verify (or create) the
1266 * "high score" file, and the game aborts (cleanly) on failure,
1267 * since one of the most common "extraction" failures involves
1268 * failing to extract all sub-directories (even empty ones), such
1269 * as by failing to use the "-d" option of "pkunzip", or failing
1270 * to use the "save empty directories" option with "Compact Pro".
1271 * This error will often be caught by the "high score" creation
1272 * code below, since the "lib/apex" directory, being empty in the
1273 * standard distributions, is most likely to be "lost", making it
1274 * impossible to create the high score file.
1275 * Note that various things are initialized by this function,
1276 * including everything that was once done by "init_some_arrays".
1277 * This initialization involves the parsing of special files
1278 * in the "lib/data" and sometimes the "lib/edit" directories.
1279 * Note that the "template" files are initialized first, since they
1280 * often contain errors. This means that macros and message recall
1281 * and things like that are not available until after they are done.
1282 * We load the default "user pref files" here in case any "color"
1283 * changes are needed before character creation.
1284 * Note that the "graf-xxx.prf" file must be loaded separately,
1285 * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1288 void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*))
1290 /*** Verify the "news" file ***/
1292 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1294 /* Attempt to open the file */
1295 int fd = fd_open(buf, O_RDONLY);
1302 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
1304 /* Crash and burn */
1305 init_angband_aux(why);
1310 /*** Display the "news" file ***/
1312 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1314 /* Open the News file */
1316 fp = angband_fopen(buf, "r");
1321 /* Dump the file to the screen */
1323 while (0 == angband_fgets(fp, buf, sizeof(buf)))
1325 /* Display and advance */
1326 Term_putstr(0, i++, -1, TERM_WHITE, buf);
1334 /*** Verify (or create) the "high score" file ***/
1335 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1337 /* Attempt to open the high score file */
1338 fd = fd_open(buf, O_RDONLY);
1340 BIT_FLAGS file_permission = 0664;
1343 /* Grab permissions */
1346 /* Create a new high score file */
1347 fd = fd_make(buf, file_permission);
1349 /* Drop permissions */
1357 sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
1359 /* Crash and burn */
1360 init_angband_aux(why);
1368 /*** Initialize some arrays ***/
1370 /* Initialize misc. values */
1371 note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
1372 if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
1374 /* Initialize feature info */
1376 note("[データの初期化中... (地形)]");
1377 if (init_f_info()) quit("地形初期化不能");
1378 if (init_feat_variables()) quit("地形初期化不能");
1380 note("[Initializing arrays... (features)]");
1381 if (init_f_info()) quit("Cannot initialize features");
1382 if (init_feat_variables()) quit("Cannot initialize features");
1385 /* Initialize object info */
1386 note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
1387 if (init_k_info()) quit(_("アイテム初期化不能", "Cannot initialize objects"));
1389 /* Initialize artifact info */
1390 note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
1391 if (init_a_info()) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
1394 /* Initialize ego-item info */
1395 note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
1396 if (init_e_info()) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
1399 /* Initialize monster info */
1400 note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
1401 if (init_r_info()) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
1404 /* Initialize dungeon info */
1405 note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
1406 if (init_d_info()) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
1408 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
1409 if (d_info[i].final_guardian)
1410 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
1413 /* Initialize magic info */
1414 note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
1415 if (init_m_info()) quit(_("魔法初期化不能", "Cannot initialize magic"));
1417 /* Initialize weapon_exp info */
1418 note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
1419 if (init_s_info()) quit(_("熟練度初期化不能", "Cannot initialize skill"));
1421 /* Initialize wilderness array */
1422 note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
1424 if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
1426 /* Initialize town array */
1427 note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
1428 if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
1430 /* Initialize building array */
1431 note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
1432 if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
1434 /* Initialize quest array */
1435 note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
1436 if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
1438 /* Initialize vault info */
1439 if (init_v_info()) quit(_("vault 初期化不能", "Cannot initialize vaults"));
1441 /* Initialize some other arrays */
1442 note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
1443 if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
1445 /* Initialize some other arrays */
1446 note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
1447 if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
1449 /*** Load default user pref files ***/
1451 /* Initialize feature info */
1452 note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
1454 /* Access the "basic" pref file */
1455 strcpy(buf, "pref.prf");
1457 /* Process that file */
1458 process_pref_file(player_ptr, buf, process_autopick_file_command);
1460 /* Access the "basic" system pref file */
1461 sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
1463 /* Process that file */
1464 process_pref_file(player_ptr, buf, process_autopick_file_command);
1466 note(_("[初期化終了]", "[Initialization complete]"));
1474 static void put_title(void)
1478 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,
1480 sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
1482 IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
1483 int col = (80 - strlen(title)) / 2;
1484 col = col < 0 ? 0 : col;
1485 const int VER_INFO_ROW = 3; //!< タイトル表記(行)
1486 prt(title, VER_INFO_ROW, col);
1491 * @brief チェックサム情報を出力 / Get check sum in string form
1492 * @return チェックサム情報の文字列
1494 concptr get_check_sum(void)
1496 return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",