3 * @brief ゲームデータ初期化2 / Initialization (part 2) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file is used to initialize various variables and arrays for the
16 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
17 * the common limitation of "read()" and "write()" to only 32767 bytes
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
27 * The "init1.c" file is used only to parse the ascii template files,
28 * to create the binary image files. Note that the binary image files
29 * are extremely system dependant.
35 #include "uid-checker.h"
38 #include "io/read-pref-file.h"
49 #include "dungeon-file.h"
53 #include "floor-town.h"
55 #include "rooms-vault.h"
56 #include "player-skill.h"
57 #include "player-class.h"
58 #include "objectkind.h"
59 #include "object-ego.h"
60 #include "rooms-vault.h"
62 #include "market/articles-on-sale.h"
63 #include "market/store-util.h"
65 #include <sys/types.h>
68 static void put_title(void);
71 * @brief 各データファイルを読み取るためのパスを取得する
72 * Find the default paths to all of our important sub-directories.
73 * @param path パス保管先の文字列
77 * The purpose of each sub-directory is described in "variable.c".
78 * All of the sub-directories should, by default, be located inside
79 * the main "lib" directory, whose location is very system dependant.
80 * This function takes a writable buffer, initially containing the
81 * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
82 * or a system dependant string, for example, ":lib:". The buffer
83 * must be large enough to contain at least 32 more characters.
84 * Various command line options may allow some of the important
85 * directories to be changed to user-specified directories, most
86 * importantly, the "info" and "user" and "save" directories,
87 * but this is done after this function, see "main.c".
88 * In general, the initial path should end in the appropriate "PATH_SEP"
89 * string. All of the "sub-directory" paths (created below or supplied
90 * by the user) will NOT end in the "PATH_SEP" string, see the special
91 * "path_build()" function in "util.c" for more information.
92 * Mega-Hack -- support fat raw files under NEXTSTEP, using special
93 * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
94 * requiring the directories to be created by hand by the user.
95 * Hack -- first we free all the strings, since this is known
96 * to succeed even if the strings have not been allocated yet,
97 * as long as the variables start out as "NULL". This allows
98 * this function to be called multiple times, for example, to
99 * try several base "path" values until a good one is found.
102 void init_file_paths(char *path)
106 #ifdef PRIVATE_USER_PATH
108 #endif /* PRIVATE_USER_PATH */
110 /*** Free everything ***/
112 /* Free the main path */
113 string_free(ANGBAND_DIR);
115 /* Free the sub-paths */
116 string_free(ANGBAND_DIR_APEX);
117 string_free(ANGBAND_DIR_BONE);
118 string_free(ANGBAND_DIR_DATA);
119 string_free(ANGBAND_DIR_EDIT);
120 string_free(ANGBAND_DIR_SCRIPT);
121 string_free(ANGBAND_DIR_FILE);
122 string_free(ANGBAND_DIR_HELP);
123 string_free(ANGBAND_DIR_INFO);
124 string_free(ANGBAND_DIR_SAVE);
125 string_free(ANGBAND_DIR_USER);
126 string_free(ANGBAND_DIR_XTRA);
128 /*** Prepare the "path" ***/
130 /* Hack -- save the main directory */
131 ANGBAND_DIR = string_make(path);
133 /* Prepare to append to the Base Path */
134 tail = path + strlen(path);
136 /*** Build the sub-directory names ***/
138 /* Build a path name */
139 strcpy(tail, "apex");
140 ANGBAND_DIR_APEX = string_make(path);
142 /* Build a path name */
143 strcpy(tail, "bone");
144 ANGBAND_DIR_BONE = string_make(path);
146 /* Build a path name */
147 strcpy(tail, "data");
148 ANGBAND_DIR_DATA = string_make(path);
150 /* Build a path name */
151 strcpy(tail, "edit");
152 ANGBAND_DIR_EDIT = string_make(path);
154 /* Build a path name */
155 strcpy(tail, "script");
156 ANGBAND_DIR_SCRIPT = string_make(path);
158 /* Build a path name */
159 strcpy(tail, "file");
160 ANGBAND_DIR_FILE = string_make(path);
162 /* Build a path name */
163 strcpy(tail, "help");
164 ANGBAND_DIR_HELP = string_make(path);
166 /* Build a path name */
167 strcpy(tail, "info");
168 ANGBAND_DIR_INFO = string_make(path);
170 /* Build a path name */
171 strcpy(tail, "pref");
172 ANGBAND_DIR_PREF = string_make(path);
174 /* Build a path name */
175 strcpy(tail, "save");
176 ANGBAND_DIR_SAVE = string_make(path);
178 #ifdef PRIVATE_USER_PATH
180 /* Build the path to the user specific directory */
181 path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
183 /* Build a relative path name */
184 ANGBAND_DIR_USER = string_make(buf);
186 #else /* PRIVATE_USER_PATH */
188 /* Build a path name */
189 strcpy(tail, "user");
190 ANGBAND_DIR_USER = string_make(path);
192 #endif /* PRIVATE_USER_PATH */
194 /* Build a path name */
195 strcpy(tail, "xtra");
196 ANGBAND_DIR_XTRA = string_make(path);
201 * Hack -- help give useful error messages
203 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
204 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
207 * エラーメッセージの名称定義 / Standard error message text
209 concptr err_str[PARSE_ERROR_MAX] =
226 "missing record header",
227 "non-sequential records",
228 "invalid flag specification",
229 "undefined directive",
231 "coordinates out of bounds",
233 "undefined terrain tag",
242 header v_head; /*!< Vault情報のヘッダ構造体 */
243 header f_head; /*!< 地形情報のヘッダ構造体 */
244 header k_head; /*!< ペースアイテム情報のヘッダ構造体 */
245 header a_head; /*!< 固定アーティファクト情報のヘッダ構造体 */
246 header e_head; /*!< アイテムエゴ情報のヘッダ構造体 */
247 header r_head; /*!< モンスター種族情報のヘッダ構造体 */
248 header d_head; /*!< ダンジョン情報のヘッダ構造体 */
249 header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
250 header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
253 * @brief テキストファイルとrawファイルの更新時刻を比較する
254 * Find the default paths to all of our important sub-directories.
255 * @param fd ファイルディスクリプタ
256 * @param template_file ファイル名
257 * @return テキストの方が新しいか、rawファイルがなく更新の必要がある場合-1、更新の必要がない場合0。
259 static errr check_modification_date(int fd, concptr template_file)
261 struct stat txt_stat, raw_stat;
263 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
265 /* Access stats on text file */
266 if (stat(buf, &txt_stat))
271 /* Access stats on raw file */
272 if (fstat(fd, &raw_stat))
277 /* Ensure text file is not newer than raw file */
278 if (txt_stat.st_mtime > raw_stat.st_mtime)
287 /*** Initialize from binary image files ***/
290 * @brief rawファイルからのデータの読み取り処理
291 * Initialize the "*_info" array, by parsing a binary "image" file
292 * @param fd ファイルディスクリプタ
293 * @param head rawファイルのヘッダ
296 static errr init_info_raw(int fd, header *head)
300 /* Read and Verify the header */
301 if (fd_read(fd, (char*)(&test), sizeof(header)) ||
302 (test.v_major != head->v_major) ||
303 (test.v_minor != head->v_minor) ||
304 (test.v_patch != head->v_patch) ||
305 (test.info_num != head->info_num) ||
306 (test.info_len != head->info_len) ||
307 (test.head_size != head->head_size) ||
308 (test.info_size != head->info_size))
314 /* Accept the header */
317 /* Allocate the "*_info" array */
318 C_MAKE(head->info_ptr, head->info_size, char);
320 /* Read the "*_info" array */
321 fd_read(fd, head->info_ptr, head->info_size);
325 /* Allocate the "*_name" array */
326 C_MAKE(head->name_ptr, head->name_size, char);
328 /* Read the "*_name" array */
329 fd_read(fd, head->name_ptr, head->name_size);
334 /* Allocate the "*_text" array */
335 C_MAKE(head->text_ptr, head->text_size, char);
337 /* Read the "*_text" array */
338 fd_read(fd, head->text_ptr, head->text_size);
343 /* Allocate the "*_tag" array */
344 C_MAKE(head->tag_ptr, head->tag_size, char);
346 /* Read the "*_tag" array */
347 fd_read(fd, head->tag_ptr, head->tag_size);
357 * Initialize the header of an *_info.raw file.
358 * @param head rawファイルのヘッダ
363 static void init_header(header *head, IDX num, int len)
365 /* Save the "version" */
366 head->v_major = FAKE_VER_MAJOR;
367 head->v_minor = FAKE_VER_MINOR;
368 head->v_patch = FAKE_VER_PATCH;
371 /* Save the "record" information */
372 head->info_num = (IDX)num;
373 head->info_len = len;
375 /* Save the size of "*_head" and "*_info" */
376 head->head_size = sizeof(header);
377 head->info_size = head->info_num * head->info_len;
381 static void update_header(header *head, void **info, char **name, char **text, char **tag)
383 if (info) *info = head->info_ptr;
384 if (name) *name = head->name_ptr;
385 if (text) *text = head->text_ptr;
386 if (tag) *tag = head->tag_ptr;
392 * Initialize the "*_info" array
393 * @param filename ファイル名(拡張子txt/raw)
394 * @param head 処理に用いるヘッダ構造体
395 * @param info データ保管先の構造体ポインタ
396 * @param name 名称用可変文字列の保管先
397 * @param text テキスト用可変文字列の保管先
398 * @param tag タグ用可変文字列の保管先
401 * Note that we let each entry have a unique "name" and "text" string,
402 * even if the string happens to be empty (everyone has a unique '\0').
404 static errr init_info(concptr filename, header *head, void **info, char **name, char **text, char **tag)
409 /*** Load the binary image file ***/
410 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
412 /* Attempt to open the "raw" file */
413 int fd = fd_open(buf, O_RDONLY);
415 /* Process existing "raw" file */
419 err = check_modification_date(fd, format("%s.txt", filename));
421 /* Attempt to parse the "raw" file */
423 err = init_info_raw(fd, head);
427 /* Do we have to parse the *.txt file? */
428 BIT_FLAGS file_permission = 0644;
431 update_header(head, info, name, text, tag);
435 /*** Make the fake arrays ***/
436 C_MAKE(head->info_ptr, head->info_size, char);
438 /* Hack -- make "fake" arrays */
439 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
440 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
441 if (tag) C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
443 if (info) (*info) = head->info_ptr;
444 if (name) (*name) = head->name_ptr;
445 if (text) (*text) = head->text_ptr;
446 if (tag) (*tag) = head->tag_ptr;
448 /*** Load the ascii template file ***/
449 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
451 fp = my_fopen(buf, "r");
454 if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
457 err = init_info_txt(fp, buf, head, head->parse_info_txt);
467 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
469 msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
470 msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
471 msg_format("構文 '%s'。", buf);
475 quit(format("'%s.txt'ファイルにエラー", filename));
478 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
480 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
481 msg_format("Record %d contains a '%s' error.", error_idx, oops);
482 msg_format("Parsing '%s'.", buf);
486 quit(format("Error in '%s.txt' file.", filename));
490 /*** Make final retouch on fake tags ***/
493 (*head->retouch)(head);
496 /*** Dump the binary image file ***/
497 /* File type is "DATA" */
498 FILE_TYPE(FILE_TYPE_DATA);
499 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
501 /* Grab permissions */
504 /* Kill the old file */
507 /* Attempt to create the raw file */
508 fd = fd_make(buf, file_permission);
510 /* Drop permissions */
513 /* Dump to the file */
517 fd_write(fd, (concptr)(head), head->head_size);
519 /* Dump the "*_info" array */
520 fd_write(fd, head->info_ptr, head->info_size);
522 /* Dump the "*_name" array */
523 fd_write(fd, head->name_ptr, head->name_size);
525 /* Dump the "*_text" array */
526 fd_write(fd, head->text_ptr, head->text_size);
528 /* Dump the "*_tag" array */
529 fd_write(fd, head->tag_ptr, head->tag_size);
535 /*** Kill the fake arrays ***/
537 /* Free the "*_info" array */
538 C_KILL(head->info_ptr, head->info_size, char);
540 /* Hack -- Free the "fake" arrays */
541 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
542 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
543 if (tag) C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
545 /*** Load the binary image file ***/
546 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
548 /* Attempt to open the "raw" file */
549 fd = fd_open(buf, O_RDONLY);
551 /* Process existing "raw" file */
552 if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
554 /* Attempt to parse the "raw" file */
555 err = init_info_raw(fd, head);
559 if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
561 update_header(head, info, name, text, tag);
567 * @brief 地形情報読み込みのメインルーチン /
568 * Initialize the "f_info" array
571 static errr init_f_info(void)
573 /* Init the header */
574 init_header(&f_head, max_f_idx, sizeof(feature_type));
576 /* Save a pointer to the parsing function */
577 f_head.parse_info_txt = parse_f_info;
579 /* Save a pointer to the retouch fake tags */
580 f_head.retouch = retouch_f_info;
582 return init_info("f_info", &f_head,
583 (void*)&f_info, &f_name, NULL, &f_tag);
588 * @brief ベースアイテム情報読み込みのメインルーチン /
589 * Initialize the "k_info" array
592 static errr init_k_info(void)
594 /* Init the header */
595 init_header(&k_head, max_k_idx, sizeof(object_kind));
597 /* Save a pointer to the parsing function */
598 k_head.parse_info_txt = parse_k_info;
600 return init_info("k_info", &k_head,
601 (void*)&k_info, &k_name, &k_text, NULL);
606 * @brief 固定アーティファクト情報読み込みのメインルーチン /
607 * Initialize the "a_info" array
610 static errr init_a_info(void)
612 /* Init the header */
613 init_header(&a_head, max_a_idx, sizeof(artifact_type));
615 /* Save a pointer to the parsing function */
616 a_head.parse_info_txt = parse_a_info;
618 return init_info("a_info", &a_head,
619 (void*)&a_info, &a_name, &a_text, NULL);
624 * @brief 固定アーティファクト情報読み込みのメインルーチン /
625 * Initialize the "e_info" array
628 static errr init_e_info(void)
630 /* Init the header */
631 init_header(&e_head, max_e_idx, sizeof(ego_item_type));
633 /* Save a pointer to the parsing function */
634 e_head.parse_info_txt = parse_e_info;
636 return init_info("e_info", &e_head,
637 (void*)&e_info, &e_name, &e_text, NULL);
642 * @brief モンスター種族情報読み込みのメインルーチン /
643 * Initialize the "r_info" array
646 static errr init_r_info(void)
648 /* Init the header */
649 init_header(&r_head, max_r_idx, sizeof(monster_race));
651 /* Save a pointer to the parsing function */
652 r_head.parse_info_txt = parse_r_info;
654 return init_info("r_info", &r_head,
655 (void*)&r_info, &r_name, &r_text, NULL);
660 * @brief ダンジョン情報読み込みのメインルーチン /
661 * Initialize the "d_info" array
664 static errr init_d_info(void)
666 /* Init the header */
667 init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
669 /* Save a pointer to the parsing function */
670 d_head.parse_info_txt = parse_d_info;
672 return init_info("d_info", &d_head,
673 (void*)&d_info, &d_name, &d_text, NULL);
678 * @brief Vault情報読み込みのメインルーチン /
679 * Initialize the "v_info" array
682 * Note that we let each entry have a unique "name" and "text" string,
683 * even if the string happens to be empty (everyone has a unique '\0').
685 errr init_v_info(void)
687 /* Init the header */
688 init_header(&v_head, max_v_idx, sizeof(vault_type));
690 /* Save a pointer to the parsing function */
691 v_head.parse_info_txt = parse_v_info;
693 return init_info("v_info", &v_head,
694 (void*)&v_info, &v_name, &v_text, NULL);
699 * @brief 職業技能情報読み込みのメインルーチン /
700 * Initialize the "s_info" array
703 static errr init_s_info(void)
705 /* Init the header */
706 init_header(&s_head, MAX_CLASS, sizeof(skill_table));
708 /* Save a pointer to the parsing function */
709 s_head.parse_info_txt = parse_s_info;
711 return init_info("s_info", &s_head,
712 (void*)&s_info, NULL, NULL, NULL);
717 * @brief 職業魔法情報読み込みのメインルーチン /
718 * Initialize the "m_info" array
721 static errr init_m_info(void)
723 /* Init the header */
724 init_header(&m_head, MAX_CLASS, sizeof(player_magic));
726 /* Save a pointer to the parsing function */
727 m_head.parse_info_txt = parse_m_info;
729 return init_info("m_info", &m_head,
730 (void*)&m_info, NULL, NULL, NULL);
735 * @brief 基本情報読み込みのメインルーチン /
736 * Initialize misc. values
737 * @param player_ptr プレーヤーへの参照ポインタ
740 static errr init_misc(player_type *player_ptr)
742 return process_dungeon_file(player_ptr, "misc.txt", 0, 0, 0, 0);
747 * @brief 町情報読み込みのメインルーチン /
748 * Initialize town array
751 static errr init_towns(void)
753 /* Allocate the towns */
754 C_MAKE(town_info, max_towns, town_type);
756 for (int i = 1; i < max_towns; i++)
758 /*** Prepare the Stores ***/
760 /* Allocate the stores */
761 C_MAKE(town_info[i].store, MAX_STORES, store_type);
763 /* Fill in each store */
764 for (int j = 0; j < MAX_STORES; j++)
766 /* Access the store */
767 store_type *st_ptr = &town_info[i].store[j];
769 if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
771 /* Assume full stock */
774 * 我が家が 20 ページまで使える隠し機能のための準備。
775 * オプションが有効でもそうでなくても一応スペースを作っておく。
779 st_ptr->stock_size = (STORE_INVEN_MAX * 10);
781 else if (j == STORE_MUSEUM)
783 st_ptr->stock_size = (STORE_INVEN_MAX * 50);
787 st_ptr->stock_size = STORE_INVEN_MAX;
790 /* Allocate the stock */
791 C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
793 /* No table for the black market or home */
794 if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
796 /* Assume full table */
797 st_ptr->table_size = STORE_CHOICES;
799 /* Allocate the stock */
800 C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
802 /* Scan the choices */
803 for (int k = 0; k < STORE_CHOICES; k++)
805 KIND_OBJECT_IDX k_idx;
807 /* Extract the tval/sval codes */
808 int tv = store_table[j][k][0];
809 int sv = store_table[j][k][1];
812 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
814 object_kind *k_ptr = &k_info[k_idx];
817 if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
821 if (k_idx == max_k_idx) continue;
823 /* Add that item index to the table */
824 st_ptr->table[st_ptr->table_num++] = k_idx;
833 * @brief 店情報初期化のメインルーチン /
834 * Initialize buildings
837 errr init_buildings(void)
839 for (int i = 0; i < MAX_BLDG; i++)
841 building[i].name[0] = '\0';
842 building[i].owner_name[0] = '\0';
843 building[i].owner_race[0] = '\0';
845 for (int j = 0; j < 8; j++)
847 building[i].act_names[j][0] = '\0';
848 building[i].member_costs[j] = 0;
849 building[i].other_costs[j] = 0;
850 building[i].letters[j] = 0;
851 building[i].actions[j] = 0;
852 building[i].action_restr[j] = 0;
855 for (int j = 0; j < MAX_CLASS; j++)
857 building[i].member_class[j] = 0;
860 for (int j = 0; j < MAX_RACES; j++)
862 building[i].member_race[j] = 0;
865 for (int j = 0; j < MAX_MAGIC + 1; j++)
867 building[i].member_realm[j] = 0;
876 * @brief クエスト情報初期化のメインルーチン /
877 * Initialize quest array
880 static errr init_quests(void)
882 /* Allocate the quests */
883 C_MAKE(quest, max_q_idx, quest_type);
885 /* Set all quest to "untaken" */
886 for (int i = 0; i < max_q_idx; i++)
888 quest[i].status = QUEST_STATUS_UNTAKEN;
894 /*! 地形タグ情報から地形IDを得られなかった場合にTRUEを返すグローバル変数 */
895 static bool feat_tag_is_not_found = FALSE;
898 * @brief 地形タグからIDを得る /
899 * Initialize quest array
902 s16b f_tag_to_index_in_init(concptr str)
904 FEAT_IDX feat = f_tag_to_index(str);
906 if (feat < 0) feat_tag_is_not_found = TRUE;
913 * @brief 地形の汎用定義をタグを通じて取得する /
914 * Initialize feature variables
917 static errr init_feat_variables(void)
919 feat_none = f_tag_to_index_in_init("NONE");
921 feat_floor = f_tag_to_index_in_init("FLOOR");
922 feat_glyph = f_tag_to_index_in_init("GLYPH");
923 feat_explosive_rune = f_tag_to_index_in_init("EXPLOSIVE_RUNE");
924 feat_mirror = f_tag_to_index_in_init("MIRROR");
926 feat_door[DOOR_DOOR].open = f_tag_to_index_in_init("OPEN_DOOR");
927 feat_door[DOOR_DOOR].broken = f_tag_to_index_in_init("BROKEN_DOOR");
928 feat_door[DOOR_DOOR].closed = f_tag_to_index_in_init("CLOSED_DOOR");
932 for (i = 1; i < MAX_LJ_DOORS; i++)
934 s16b door = f_tag_to_index(format("LOCKED_DOOR_%d", i));
936 feat_door[DOOR_DOOR].locked[i - 1] = door;
939 if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
940 feat_door[DOOR_DOOR].num_locked = i - 1;
943 for (i = 0; i < MAX_LJ_DOORS; i++)
945 s16b door = f_tag_to_index(format("JAMMED_DOOR_%d", i));
947 feat_door[DOOR_DOOR].jammed[i] = door;
950 if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
951 feat_door[DOOR_DOOR].num_jammed = i;
954 feat_door[DOOR_GLASS_DOOR].open = f_tag_to_index_in_init("OPEN_GLASS_DOOR");
955 feat_door[DOOR_GLASS_DOOR].broken = f_tag_to_index_in_init("BROKEN_GLASS_DOOR");
956 feat_door[DOOR_GLASS_DOOR].closed = f_tag_to_index_in_init("CLOSED_GLASS_DOOR");
958 /* Locked glass doors */
959 for (i = 1; i < MAX_LJ_DOORS; i++)
961 s16b door = f_tag_to_index(format("LOCKED_GLASS_DOOR_%d", i));
963 feat_door[DOOR_GLASS_DOOR].locked[i - 1] = door;
966 if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
967 feat_door[DOOR_GLASS_DOOR].num_locked = i - 1;
969 /* Jammed glass doors */
970 for (i = 0; i < MAX_LJ_DOORS; i++)
972 s16b door = f_tag_to_index(format("JAMMED_GLASS_DOOR_%d", i));
974 feat_door[DOOR_GLASS_DOOR].jammed[i] = door;
977 if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
978 feat_door[DOOR_GLASS_DOOR].num_jammed = i;
981 feat_door[DOOR_CURTAIN].open = f_tag_to_index_in_init("OPEN_CURTAIN");
982 feat_door[DOOR_CURTAIN].broken = feat_door[DOOR_CURTAIN].open;
983 feat_door[DOOR_CURTAIN].closed = f_tag_to_index_in_init("CLOSED_CURTAIN");
984 feat_door[DOOR_CURTAIN].locked[0] = feat_door[DOOR_CURTAIN].closed;
985 feat_door[DOOR_CURTAIN].num_locked = 1;
986 feat_door[DOOR_CURTAIN].jammed[0] = feat_door[DOOR_CURTAIN].closed;
987 feat_door[DOOR_CURTAIN].num_jammed = 1;
990 feat_up_stair = f_tag_to_index_in_init("UP_STAIR");
991 feat_down_stair = f_tag_to_index_in_init("DOWN_STAIR");
992 feat_entrance = f_tag_to_index_in_init("ENTRANCE");
998 feat_trap_open = f_tag_to_index_in_init("TRAP_OPEN");
999 feat_trap_armageddon = f_tag_to_index_in_init("TRAP_ARMAGEDDON");
1000 feat_trap_piranha = f_tag_to_index_in_init("TRAP_PIRANHA");
1003 feat_rubble = f_tag_to_index_in_init("RUBBLE");
1006 feat_magma_vein = f_tag_to_index_in_init("MAGMA_VEIN");
1007 feat_quartz_vein = f_tag_to_index_in_init("QUARTZ_VEIN");
1010 feat_granite = f_tag_to_index_in_init("GRANITE");
1011 feat_permanent = f_tag_to_index_in_init("PERMANENT");
1014 feat_glass_floor = f_tag_to_index_in_init("GLASS_FLOOR");
1017 feat_glass_wall = f_tag_to_index_in_init("GLASS_WALL");
1018 feat_permanent_glass_wall = f_tag_to_index_in_init("PERMANENT_GLASS_WALL");
1021 feat_pattern_start = f_tag_to_index_in_init("PATTERN_START");
1022 feat_pattern_1 = f_tag_to_index_in_init("PATTERN_1");
1023 feat_pattern_2 = f_tag_to_index_in_init("PATTERN_2");
1024 feat_pattern_3 = f_tag_to_index_in_init("PATTERN_3");
1025 feat_pattern_4 = f_tag_to_index_in_init("PATTERN_4");
1026 feat_pattern_end = f_tag_to_index_in_init("PATTERN_END");
1027 feat_pattern_old = f_tag_to_index_in_init("PATTERN_OLD");
1028 feat_pattern_exit = f_tag_to_index_in_init("PATTERN_EXIT");
1029 feat_pattern_corrupted = f_tag_to_index_in_init("PATTERN_CORRUPTED");
1032 feat_black_market = f_tag_to_index_in_init("BLACK_MARKET");
1033 feat_town = f_tag_to_index_in_init("TOWN");
1036 feat_deep_water = f_tag_to_index_in_init("DEEP_WATER");
1037 feat_shallow_water = f_tag_to_index_in_init("SHALLOW_WATER");
1038 feat_deep_lava = f_tag_to_index_in_init("DEEP_LAVA");
1039 feat_shallow_lava = f_tag_to_index_in_init("SHALLOW_LAVA");
1040 feat_heavy_cold_zone = f_tag_to_index_in_init("HEAVY_COLD_ZONE");
1041 feat_cold_zone = f_tag_to_index_in_init("COLD_ZONE");
1042 feat_heavy_electrical_zone = f_tag_to_index_in_init("HEAVY_ELECTRICAL_ZONE");
1043 feat_electrical_zone = f_tag_to_index_in_init("ELECTRICAL_ZONE");
1044 feat_deep_acid_puddle = f_tag_to_index_in_init("DEEP_ACID_PUDDLE");
1045 feat_shallow_acid_puddle = f_tag_to_index_in_init("SHALLOW_ACID_PUDDLE");
1046 feat_deep_poisonous_puddle = f_tag_to_index_in_init("DEEP_POISONOUS_PUDDLE");
1047 feat_shallow_poisonous_puddle = f_tag_to_index_in_init("SHALLOW_POISONOUS_PUDDLE");
1048 feat_dirt = f_tag_to_index_in_init("DIRT");
1049 feat_grass = f_tag_to_index_in_init("GRASS");
1050 feat_flower = f_tag_to_index_in_init("FLOWER");
1051 feat_brake = f_tag_to_index_in_init("BRAKE");
1052 feat_tree = f_tag_to_index_in_init("TREE");
1053 feat_mountain = f_tag_to_index_in_init("MOUNTAIN");
1054 feat_swamp = f_tag_to_index_in_init("SWAMP");
1056 feat_undetected = f_tag_to_index_in_init("UNDETECTED");
1058 init_wilderness_terrains();
1059 return feat_tag_is_not_found ? PARSE_ERROR_UNDEFINED_TERRAIN_TAG : 0;
1064 * @brief その他の初期情報更新 /
1065 * Initialize some other arrays
1068 static errr init_other(player_type *player_ptr)
1070 player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
1071 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1073 /*** Prepare the "dungeon" information ***/
1075 /* Allocate and Wipe the object list */
1076 C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
1078 /* Allocate and Wipe the monster list */
1079 C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
1081 /* Allocate and Wipe the monster process list */
1082 for (int i = 0; i < MAX_MTIMED; i++)
1084 C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
1087 /* Allocate and Wipe the max dungeon level */
1088 C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
1090 for (int i = 0; i < MAX_HGT; i++)
1092 C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
1095 /*** Prepare the various "bizarre" arrays ***/
1097 /* Macro variables */
1098 C_MAKE(macro__pat, MACRO_MAX, concptr);
1099 C_MAKE(macro__act, MACRO_MAX, concptr);
1100 C_MAKE(macro__cmd, MACRO_MAX, bool);
1102 /* Macro action buffer */
1103 C_MAKE(macro__buf, 1024, char);
1105 /* Quark variables */
1108 /* Message variables */
1109 C_MAKE(message__ptr, MESSAGE_MAX, u32b);
1110 C_MAKE(message__buf, MESSAGE_BUF, char);
1112 /* Hack -- No messages yet */
1113 message__tail = MESSAGE_BUF;
1115 /*** Prepare the options ***/
1117 /* Scan the options */
1118 for (int i = 0; option_info[i].o_desc; i++)
1120 int os = option_info[i].o_set;
1121 int ob = option_info[i].o_bit;
1123 /* Set the "default" options */
1124 if (!option_info[i].o_var) continue;
1127 option_mask[os] |= (1L << ob);
1130 if (option_info[i].o_norm)
1133 option_flag[os] |= (1L << ob);
1137 option_flag[os] &= ~(1L << ob);
1141 /* Analyze the windows */
1142 for (int n = 0; n < 8; n++)
1144 /* Analyze the options */
1145 for (int i = 0; i < 32; i++)
1148 if (window_flag_desc[i])
1151 window_mask[n] |= (1L << i);
1157 * Set the "default" window flags
1158 * Window 1 : Display messages
1159 * Window 2 : Display inven/equip
1161 window_flag[1] = 1L << A_MAX;
1162 window_flag[2] = 1L << 0;
1164 /*** Pre-allocate space for the "format()" buffer ***/
1166 /* Hack -- Just call the "format()" function */
1167 (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1173 * @brief オブジェクト配列を初期化する /
1174 * Initialize some other arrays
1177 static errr init_object_alloc(void)
1179 s16b aux[MAX_DEPTH];
1180 (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1182 s16b num[MAX_DEPTH];
1183 (void)C_WIPE(&num, MAX_DEPTH, s16b);
1185 /* Free the old "alloc_kind_table" (if it exists) */
1186 if (alloc_kind_table)
1188 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1191 /* Size of "alloc_kind_table" */
1192 alloc_kind_size = 0;
1194 /* Scan the objects */
1195 for (int i = 1; i < max_k_idx; i++)
1200 /* Scan allocation pairs */
1201 for (int j = 0; j < 4; j++)
1203 /* Count the "legal" entries */
1204 if (k_ptr->chance[j])
1206 /* Count the entries */
1209 /* Group by level */
1210 num[k_ptr->locale[j]]++;
1215 /* Collect the level indexes */
1216 for (int i = 1; i < MAX_DEPTH; i++)
1218 /* Group by level */
1219 num[i] += num[i - 1];
1222 if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1224 /*** Initialize object allocation info ***/
1226 /* Allocate the alloc_kind_table */
1227 C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1229 /* Access the table entry */
1231 table = alloc_kind_table;
1233 /* Scan the objects */
1234 for (int i = 1; i < max_k_idx; i++)
1239 /* Scan allocation pairs */
1240 for (int j = 0; j < 4; j++)
1242 /* Count the "legal" entries */
1243 if (k_ptr->chance[j] == 0) continue;
1245 /* Extract the base level */
1246 int x = k_ptr->locale[j];
1248 /* Extract the base probability */
1249 int p = (100 / k_ptr->chance[j]);
1251 /* Skip entries preceding our locale */
1252 int y = (x > 0) ? num[x - 1] : 0;
1254 /* Skip previous entries at this locale */
1257 /* Load the entry */
1258 table[z].index = (KIND_OBJECT_IDX)i;
1259 table[z].level = (DEPTH)x;
1260 table[z].prob1 = (PROB)p;
1261 table[z].prob2 = (PROB)p;
1262 table[z].prob3 = (PROB)p;
1264 /* Another entry complete for this locale */
1274 * @brief モンスター配列と生成テーブルを初期化する /
1275 * Initialize some other arrays
1278 static errr init_alloc(void)
1280 monster_race *r_ptr;
1283 /* Allocate the "r_info" array */
1284 C_MAKE(elements, max_r_idx, tag_type);
1286 /* Scan the monsters */
1287 for (int i = 1; i < max_r_idx; i++)
1289 elements[i].tag = r_info[i].level;
1290 elements[i].index = i;
1293 tag_sort(elements, max_r_idx);
1295 /*** Initialize monster allocation info ***/
1297 /* Size of "alloc_race_table" */
1298 alloc_race_size = max_r_idx;
1300 /* Allocate the alloc_race_table */
1301 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1303 /* Scan the monsters */
1304 for (int i = 1; i < max_r_idx; i++)
1306 /* Get the i'th race */
1307 r_ptr = &r_info[elements[i].index];
1309 /* Count valid pairs */
1310 if (r_ptr->rarity == 0) continue;
1312 /* Extract the base level */
1313 int x = r_ptr->level;
1315 /* Extract the base probability */
1316 int p = (100 / r_ptr->rarity);
1318 /* Load the entry */
1319 alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
1320 alloc_race_table[i].level = (DEPTH)x;
1321 alloc_race_table[i].prob1 = (PROB)p;
1322 alloc_race_table[i].prob2 = (PROB)p;
1323 alloc_race_table[i].prob3 = (PROB)p;
1326 /* Free the "r_info" array */
1327 C_KILL(elements, max_r_idx, tag_type);
1328 (void)init_object_alloc();
1334 * @brief 画面左下にシステムメッセージを表示する /
1335 * Hack -- take notes on line 23
1338 static void note(concptr str)
1340 Term_erase(0, 23, 255);
1341 Term_putstr(20, 23, -1, TERM_WHITE, str);
1347 * @brief 全ゲームデータ読み込みのサブルーチン /
1348 * Hack -- Explain a broken "lib" folder and quit (see below).
1352 * This function is "messy" because various things
1353 * may or may not be initialized, but the "plog()" and "quit()"
1354 * functions are "supposed" to work under any conditions.
1357 static void init_angband_aux(concptr why)
1363 plog("'lib'ディレクトリが存在しないか壊れているようです。");
1366 plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
1369 plog("該当する'README'ファイルを読んで確認してみて下さい。");
1371 /* Quit with error */
1375 plog("The 'lib' directory is probably missing or broken.");
1378 plog("Perhaps the archive was not extracted correctly.");
1381 plog("See the 'README' file for more information.");
1383 /* Quit with error */
1384 quit("Fatal Error.");
1391 * @brief 全ゲームデータ読み込みのメインルーチン /
1392 * Hack -- main Angband initialization entry point
1396 * This function is "messy" because various things
1397 * may or may not be initialized, but the "plog()" and "quit()"
1398 * functions are "supposed" to work under any conditions.
1399 * Verify some files, display the "news.txt" file, create
1400 * the high score file, initialize all internal arrays, and
1401 * load the basic "user pref files".
1402 * Be very careful to keep track of the order in which things
1403 * are initialized, in particular, the only thing *known* to
1404 * be available when this function is called is the "z-term.c"
1405 * package, and that may not be fully initialized until the
1406 * end of this function, when the default "user pref files"
1407 * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1408 * Note that this function attempts to verify the "news" file,
1409 * and the game aborts (cleanly) on failure, since without the
1410 * "news" file, it is likely that the "lib" folder has not been
1411 * correctly located. Otherwise, the news file is displayed for
1413 * Note that this function attempts to verify (or create) the
1414 * "high score" file, and the game aborts (cleanly) on failure,
1415 * since one of the most common "extraction" failures involves
1416 * failing to extract all sub-directories (even empty ones), such
1417 * as by failing to use the "-d" option of "pkunzip", or failing
1418 * to use the "save empty directories" option with "Compact Pro".
1419 * This error will often be caught by the "high score" creation
1420 * code below, since the "lib/apex" directory, being empty in the
1421 * standard distributions, is most likely to be "lost", making it
1422 * impossible to create the high score file.
1423 * Note that various things are initialized by this function,
1424 * including everything that was once done by "init_some_arrays".
1425 * This initialization involves the parsing of special files
1426 * in the "lib/data" and sometimes the "lib/edit" directories.
1427 * Note that the "template" files are initialized first, since they
1428 * often contain errors. This means that macros and message recall
1429 * and things like that are not available until after they are done.
1430 * We load the default "user pref files" here in case any "color"
1431 * changes are needed before character creation.
1432 * Note that the "graf-xxx.prf" file must be loaded separately,
1433 * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1436 void init_angband(player_type *player_ptr)
1438 /*** Verify the "news" file ***/
1440 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1442 /* Attempt to open the file */
1443 int fd = fd_open(buf, O_RDONLY);
1450 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
1452 /* Crash and burn */
1453 init_angband_aux(why);
1458 /*** Display the "news" file ***/
1460 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1462 /* Open the News file */
1464 fp = my_fopen(buf, "r");
1469 /* Dump the file to the screen */
1471 while (0 == my_fgets(fp, buf, sizeof(buf)))
1473 /* Display and advance */
1474 Term_putstr(0, i++, -1, TERM_WHITE, buf);
1482 /*** Verify (or create) the "high score" file ***/
1483 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1485 /* Attempt to open the high score file */
1486 fd = fd_open(buf, O_RDONLY);
1488 BIT_FLAGS file_permission = 0664;
1491 /* File type is "DATA" */
1492 FILE_TYPE(FILE_TYPE_DATA);
1494 /* Grab permissions */
1497 /* Create a new high score file */
1498 fd = fd_make(buf, file_permission);
1500 /* Drop permissions */
1508 sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
1510 /* Crash and burn */
1511 init_angband_aux(why);
1519 /*** Initialize some arrays ***/
1521 /* Initialize misc. values */
1522 note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
1523 if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
1525 /* Initialize feature info */
1527 note("[データの初期化中... (地形)]");
1528 if (init_f_info()) quit("地形初期化不能");
1529 if (init_feat_variables()) quit("地形初期化不能");
1531 note("[Initializing arrays... (features)]");
1532 if (init_f_info()) quit("Cannot initialize features");
1533 if (init_feat_variables()) quit("Cannot initialize features");
1536 /* Initialize object info */
1537 note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
1538 if (init_k_info()) quit(_("アイテム初期化不能", "Cannot initialize objects"));
1540 /* Initialize artifact info */
1541 note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
1542 if (init_a_info()) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
1545 /* Initialize ego-item info */
1546 note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
1547 if (init_e_info()) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
1550 /* Initialize monster info */
1551 note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
1552 if (init_r_info()) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
1555 /* Initialize dungeon info */
1556 note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
1557 if (init_d_info()) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
1559 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
1560 if (d_info[i].final_guardian)
1561 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
1564 /* Initialize magic info */
1565 note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
1566 if (init_m_info()) quit(_("魔法初期化不能", "Cannot initialize magic"));
1568 /* Initialize weapon_exp info */
1569 note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
1570 if (init_s_info()) quit(_("熟練度初期化不能", "Cannot initialize skill"));
1572 /* Initialize wilderness array */
1573 note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
1575 if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
1577 /* Initialize town array */
1578 note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
1579 if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
1581 /* Initialize building array */
1582 note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
1583 if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
1585 /* Initialize quest array */
1586 note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
1587 if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
1589 /* Initialize vault info */
1590 if (init_v_info()) quit(_("vault 初期化不能", "Cannot initialize vaults"));
1592 /* Initialize some other arrays */
1593 note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
1594 if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
1596 /* Initialize some other arrays */
1597 note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
1598 if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
1600 /*** Load default user pref files ***/
1602 /* Initialize feature info */
1603 note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
1605 /* Access the "basic" pref file */
1606 strcpy(buf, "pref.prf");
1608 /* Process that file */
1609 process_pref_file(player_ptr, buf);
1611 /* Access the "basic" system pref file */
1612 sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
1614 /* Process that file */
1615 process_pref_file(player_ptr, buf);
1617 note(_("[初期化終了]", "[Initialization complete]"));
1625 static void put_title(void)
1629 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,
1631 sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
1633 IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
1634 int col = (80 - strlen(title)) / 2;
1635 col = col < 0 ? 0 : col;
1636 prt(title, VER_INFO_ROW, col);
1641 * @brief サムチェック情報を出力 / Get check sum in string form
1642 * @return サムチェック情報の文字列
1644 concptr get_check_sum(void)
1646 return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",