OSDN Git Service

[Refactor] #40569 Separated floor-type-definition.h from floor.h
[hengband/hengband.git] / src / main / init.c
1 /*!
2  * @brief ゲームデータ初期化2 / Initialization (part 2) -BEN-
3  * @date 2014/01/28
4  * @author
5  * <pre>
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
11  * </pre>
12  * @details
13  * <pre>
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
17  * at a time.
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.
29  * </pre>
30  */
31
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"
85
86 #include <sys/stat.h>
87 #include <sys/types.h>
88
89 /*!
90  * @brief マクロ登録の最大数 / Maximum number of macros (see "io.c")
91  * @note Default: assume at most 256 macros are used
92  */
93 static const int MACRO_MAX = 256;
94
95 static void put_title(void);
96
97 /*!
98  * @brief 各データファイルを読み取るためのパスを取得する
99  * Find the default paths to all of our important sub-directories.
100  * @param path パス保管先の文字列
101  * @return なし
102  * @details
103  * <pre>
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.
127  * </pre>
128  */
129 void init_file_paths(char *path)
130 {
131         char *tail;
132
133 #ifdef PRIVATE_USER_PATH
134         char buf[1024];
135 #endif /* PRIVATE_USER_PATH */
136
137         /*** Free everything ***/
138
139         /* Free the main path */
140         string_free(ANGBAND_DIR);
141
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);
154
155         /*** Prepare the "path" ***/
156
157         /* Hack -- save the main directory */
158         ANGBAND_DIR = string_make(path);
159
160         /* Prepare to append to the Base Path */
161         tail = path + strlen(path);
162
163         /*** Build the sub-directory names ***/
164
165         /* Build a path name */
166         strcpy(tail, "apex");
167         ANGBAND_DIR_APEX = string_make(path);
168
169         /* Build a path name */
170         strcpy(tail, "bone");
171         ANGBAND_DIR_BONE = string_make(path);
172
173         /* Build a path name */
174         strcpy(tail, "data");
175         ANGBAND_DIR_DATA = string_make(path);
176
177         /* Build a path name */
178         strcpy(tail, "edit");
179         ANGBAND_DIR_EDIT = string_make(path);
180
181         /* Build a path name */
182         strcpy(tail, "script");
183         ANGBAND_DIR_SCRIPT = string_make(path);
184
185         /* Build a path name */
186         strcpy(tail, "file");
187         ANGBAND_DIR_FILE = string_make(path);
188
189         /* Build a path name */
190         strcpy(tail, "help");
191         ANGBAND_DIR_HELP = string_make(path);
192
193         /* Build a path name */
194         strcpy(tail, "info");
195         ANGBAND_DIR_INFO = string_make(path);
196
197         /* Build a path name */
198         strcpy(tail, "pref");
199         ANGBAND_DIR_PREF = string_make(path);
200
201         /* Build a path name */
202         strcpy(tail, "save");
203         ANGBAND_DIR_SAVE = string_make(path);
204
205 #ifdef PRIVATE_USER_PATH
206
207         /* Build the path to the user specific directory */
208         path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
209
210         /* Build a relative path name */
211         ANGBAND_DIR_USER = string_make(buf);
212
213 #else /* PRIVATE_USER_PATH */
214
215         /* Build a path name */
216         strcpy(tail, "user");
217         ANGBAND_DIR_USER = string_make(path);
218
219 #endif /* PRIVATE_USER_PATH */
220
221         /* Build a path name */
222         strcpy(tail, "xtra");
223         ANGBAND_DIR_XTRA = string_make(path);
224 }
225
226
227 /*
228  * Hack -- help give useful error messages
229  */
230 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
231 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
232
233 /*!
234  * エラーメッセージの名称定義 / Standard error message text
235  */
236 concptr err_str[PARSE_ERROR_MAX] =
237 {
238         NULL,
239 #ifdef JP
240         "文法エラー",
241         "古いファイル",
242         "記録ヘッダがない",
243         "不連続レコード",
244         "おかしなフラグ存在",
245         "未定義命令",
246         "メモリ不足",
247         "座標範囲外",
248         "引数不足",
249         "未定義地形タグ",
250 #else
251         "parse error",
252         "obsolete file",
253         "missing record header",
254         "non-sequential records",
255         "invalid flag specification",
256         "undefined directive",
257         "out of memory",
258         "coordinates out of bounds",
259         "too few arguments",
260         "undefined terrain tag",
261 #endif
262
263 };
264
265 /*
266  * File headers
267  */
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; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
276
277 /*!
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。
283  */
284 static errr check_modification_date(int fd, concptr template_file)
285 {
286         struct stat txt_stat, raw_stat;
287         char buf[1024];
288         path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
289
290         /* Access stats on text file */
291         if (stat(buf, &txt_stat))
292         {
293                 return 0;
294         }
295
296         /* Access stats on raw file */
297         if (fstat(fd, &raw_stat))
298         {
299                 return -1;
300         }
301
302         /* Ensure text file is not newer than raw file */
303         if (txt_stat.st_mtime > raw_stat.st_mtime)
304         {
305                 return -1;
306         }
307
308         return 0;
309 }
310
311
312 /*** Initialize from binary image files ***/
313
314 /*!
315  * @brief rawファイルからのデータの読み取り処理
316  * Initialize the "*_info" array, by parsing a binary "image" file
317  * @param fd ファイルディスクリプタ
318  * @param head rawファイルのヘッダ
319  * @return エラーコード
320  */
321 static errr init_info_raw(int fd, angband_header *head)
322 {
323         angband_header test;
324
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))
334         {
335                 /* Error */
336                 return -1;
337         }
338
339         /* Accept the header */
340         (*head) = test;
341
342         /* Allocate the "*_info" array */
343         C_MAKE(head->info_ptr, head->info_size, char);
344
345         /* Read the "*_info" array */
346         fd_read(fd, head->info_ptr, head->info_size);
347
348         if (head->name_size)
349         {
350                 /* Allocate the "*_name" array */
351                 C_MAKE(head->name_ptr, head->name_size, char);
352
353                 /* Read the "*_name" array */
354                 fd_read(fd, head->name_ptr, head->name_size);
355         }
356
357         if (head->text_size)
358         {
359                 /* Allocate the "*_text" array */
360                 C_MAKE(head->text_ptr, head->text_size, char);
361
362                 /* Read the "*_text" array */
363                 fd_read(fd, head->text_ptr, head->text_size);
364         }
365
366         if (head->tag_size)
367         {
368                 /* Allocate the "*_tag" array */
369                 C_MAKE(head->tag_ptr, head->tag_size, char);
370
371                 /* Read the "*_tag" array */
372                 fd_read(fd, head->tag_ptr, head->tag_size);
373         }
374
375         return 0;
376 }
377
378
379
380 /*!
381  * @brief ヘッダ構造体の更新
382  * Initialize the header of an *_info.raw file.
383  * @param head rawファイルのヘッダ
384  * @param num データ数
385  * @param len データの長さ
386  * @return エラーコード
387  */
388 static void init_header(angband_header *head, IDX num, int len)
389 {
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;
394         head->v_extra = 0;
395
396         /* Save the "record" information */
397         head->info_num = (IDX)num;
398         head->info_len = len;
399
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;
403 }
404
405
406 static void update_header(angband_header *head, void **info, char **name, char **text, char **tag)
407 {
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;
412 }
413
414
415 /*!
416  * @brief ヘッダ構造体の更新
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 タグ用可変文字列の保管先
424  * @return エラーコード
425  * @note
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').
428  */
429 static errr init_info(player_type *player_ptr, concptr filename, angband_header *head, void **info, char **name, char **text, char **tag)
430 {
431         /* General buffer */
432         char buf[1024];
433
434         /*** Load the binary image file ***/
435         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
436
437         /* Attempt to open the "raw" file */
438         int fd = fd_open(buf, O_RDONLY);
439
440         /* Process existing "raw" file */
441         errr err = 1;
442         if (fd >= 0)
443         {
444                 err = check_modification_date(fd, format("%s.txt", filename));
445
446                 /* Attempt to parse the "raw" file */
447                 if (!err)
448                         err = init_info_raw(fd, head);
449                 (void)fd_close(fd);
450         }
451
452         /* Do we have to parse the *.txt file? */
453         BIT_FLAGS file_permission = 0644;
454         if (err == 0)
455         {
456                 update_header(head, info, name, text, tag);
457                 return 0;
458         }
459
460         /*** Make the fake arrays ***/
461         C_MAKE(head->info_ptr, head->info_size, char);
462
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);
467
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;
472
473         /*** Load the ascii template file ***/
474         path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
475         FILE *fp;
476         fp = angband_fopen(buf, "r");
477
478         /* Parse it */
479         if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
480
481         /* Parse the file */
482         err = init_info_txt(fp, buf, head, head->parse_info_txt);
483         angband_fclose(fp);
484
485         /* Errors */
486         if (err)
487         {
488                 concptr oops;
489
490 #ifdef JP
491                 /* Error string */
492                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
493
494                 msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
495                 msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
496                 msg_format("構文 '%s'。", buf);
497                 msg_print(NULL);
498
499                 /* Quit */
500                 quit(format("'%s.txt'ファイルにエラー", filename));
501 #else
502                 /* Error string */
503                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
504
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);
508                 msg_print(NULL);
509
510                 /* Quit */
511                 quit(format("Error in '%s.txt' file.", filename));
512 #endif
513         }
514
515         /*** Make final retouch on fake tags ***/
516         if (head->retouch)
517         {
518                 (*head->retouch)(head);
519         }
520
521         /*** Dump the binary image file ***/
522         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
523
524         /* Grab permissions */
525         safe_setuid_grab(player_ptr);
526
527         /* Kill the old file */
528         (void)fd_kill(buf);
529
530         /* Attempt to create the raw file */
531         fd = fd_make(buf, file_permission);
532
533         /* Drop permissions */
534         safe_setuid_drop();
535
536         /* Dump to the file */
537         if (fd >= 0)
538         {
539                 /* Dump it */
540                 fd_write(fd, (concptr)(head), head->head_size);
541
542                 /* Dump the "*_info" array */
543                 fd_write(fd, head->info_ptr, head->info_size);
544
545                 /* Dump the "*_name" array */
546                 fd_write(fd, head->name_ptr, head->name_size);
547
548                 /* Dump the "*_text" array */
549                 fd_write(fd, head->text_ptr, head->text_size);
550
551                 /* Dump the "*_tag" array */
552                 fd_write(fd, head->tag_ptr, head->tag_size);
553
554                 /* Close */
555                 (void)fd_close(fd);
556         }
557
558         /*** Kill the fake arrays ***/
559
560         /* Free the "*_info" array */
561         C_KILL(head->info_ptr, head->info_size, char);
562
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);
567
568         /*** Load the binary image file ***/
569         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
570
571         /* Attempt to open the "raw" file */
572         fd = fd_open(buf, O_RDONLY);
573
574         /* Process existing "raw" file */
575         if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
576
577         /* Attempt to parse the "raw" file */
578         err = init_info_raw(fd, head);
579         (void)fd_close(fd);
580
581         /* Error */
582         if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
583
584         update_header(head, info, name, text, tag);
585         return 0;
586 }
587
588
589 /*!
590  * @brief 地形情報読み込みのメインルーチン /
591  * Initialize the "f_info" array
592  * @return エラーコード
593  */
594 static errr init_f_info(player_type *player_ptr)
595 {
596         /* Init the header */
597         init_header(&f_head, max_f_idx, sizeof(feature_type));
598
599         /* Save a pointer to the parsing function */
600         f_head.parse_info_txt = parse_f_info;
601
602         /* Save a pointer to the retouch fake tags */
603         f_head.retouch = retouch_f_info;
604
605         return init_info(player_ptr, "f_info", &f_head,
606                 (void*)&f_info, &f_name, NULL, &f_tag);
607 }
608
609
610 /*!
611  * @brief ベースアイテム情報読み込みのメインルーチン /
612  * Initialize the "k_info" array
613  * @return エラーコード
614  */
615 static errr init_k_info(player_type *player_ptr)
616 {
617         /* Init the header */
618         init_header(&k_head, max_k_idx, sizeof(object_kind));
619
620         /* Save a pointer to the parsing function */
621         k_head.parse_info_txt = parse_k_info;
622
623         return init_info(player_ptr, "k_info", &k_head,
624                 (void*)&k_info, &k_name, &k_text, NULL);
625 }
626
627
628 /*!
629  * @brief 固定アーティファクト情報読み込みのメインルーチン /
630  * Initialize the "a_info" array
631  * @return エラーコード
632  */
633 static errr init_a_info(player_type *player_ptr)
634 {
635         /* Init the header */
636         init_header(&a_head, max_a_idx, sizeof(artifact_type));
637
638         /* Save a pointer to the parsing function */
639         a_head.parse_info_txt = parse_a_info;
640
641         return init_info(player_ptr, "a_info", &a_head,
642                 (void*)&a_info, &a_name, &a_text, NULL);
643 }
644
645
646 /*!
647  * @brief 固定アーティファクト情報読み込みのメインルーチン /
648  * Initialize the "e_info" array
649  * @return エラーコード
650  */
651 static errr init_e_info(player_type *player_ptr)
652 {
653         /* Init the header */
654         init_header(&e_head, max_e_idx, sizeof(ego_item_type));
655
656         /* Save a pointer to the parsing function */
657         e_head.parse_info_txt = parse_e_info;
658
659         return init_info(player_ptr, "e_info", &e_head,
660                 (void*)&e_info, &e_name, &e_text, NULL);
661 }
662
663
664 /*!
665  * @brief モンスター種族情報読み込みのメインルーチン /
666  * Initialize the "r_info" array
667  * @return エラーコード
668  */
669 static errr init_r_info(player_type *player_ptr)
670 {
671         /* Init the header */
672         init_header(&r_head, max_r_idx, sizeof(monster_race));
673
674         /* Save a pointer to the parsing function */
675         r_head.parse_info_txt = parse_r_info;
676
677         return init_info(player_ptr, "r_info", &r_head,
678                 (void*)&r_info, &r_name, &r_text, NULL);
679 }
680
681
682 /*!
683  * @brief ダンジョン情報読み込みのメインルーチン /
684  * Initialize the "d_info" array
685  * @return エラーコード
686  */
687 static errr init_d_info(player_type *player_ptr)
688 {
689         /* Init the header */
690         init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
691
692         /* Save a pointer to the parsing function */
693         d_head.parse_info_txt = parse_d_info;
694
695         return init_info(player_ptr, "d_info", &d_head,
696                 (void*)&d_info, &d_name, &d_text, NULL);
697 }
698
699
700 /*!
701  * @brief Vault情報読み込みのメインルーチン /
702  * Initialize the "v_info" array
703  * @return エラーコード
704  * @note
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').
707  */
708 errr init_v_info(player_type *player_ptr)
709 {
710         /* Init the header */
711         init_header(&v_head, max_v_idx, sizeof(vault_type));
712
713         /* Save a pointer to the parsing function */
714         v_head.parse_info_txt = parse_v_info;
715
716         return init_info(player_ptr, "v_info", &v_head,
717                 (void*)&v_info, &v_name, &v_text, NULL);
718 }
719
720
721 /*!
722  * @brief 職業技能情報読み込みのメインルーチン /
723  * Initialize the "s_info" array
724  * @return エラーコード
725  */
726 static errr init_s_info(player_type *player_ptr)
727 {
728         /* Init the header */
729         init_header(&s_head, MAX_CLASS, sizeof(skill_table));
730
731         /* Save a pointer to the parsing function */
732         s_head.parse_info_txt = parse_s_info;
733
734         return init_info(player_ptr, "s_info", &s_head,
735                 (void*)&s_info, NULL, NULL, NULL);
736 }
737
738
739 /*!
740  * @brief 職業魔法情報読み込みのメインルーチン /
741  * Initialize the "m_info" array
742  * @return エラーコード
743  */
744 static errr init_m_info(player_type *player_ptr)
745 {
746         /* Init the header */
747         init_header(&m_head, MAX_CLASS, sizeof(player_magic));
748
749         /* Save a pointer to the parsing function */
750         m_head.parse_info_txt = parse_m_info;
751
752         return init_info(player_ptr, "m_info", &m_head,
753                 (void*)&m_info, NULL, NULL, NULL);
754 }
755
756
757 /*!
758  * @brief 基本情報読み込みのメインルーチン /
759  * Initialize misc. values
760  * @param player_ptr プレーヤーへの参照ポインタ
761  * @return エラーコード
762  */
763 static errr init_misc(player_type *player_ptr)
764 {
765         return parse_fixed_map(player_ptr, "misc.txt", 0, 0, 0, 0);
766 }
767
768
769 /*!
770  * @brief 町情報読み込みのメインルーチン /
771  * Initialize town array
772  * @return エラーコード
773  */
774 static errr init_towns(void)
775 {
776         /* Allocate the towns */
777         C_MAKE(town_info, max_towns, town_type);
778
779         for (int i = 1; i < max_towns; i++)
780         {
781                 /*** Prepare the Stores ***/
782
783                 /* Allocate the stores */
784                 C_MAKE(town_info[i].store, MAX_STORES, store_type);
785
786                 /* Fill in each store */
787                 for (int j = 0; j < MAX_STORES; j++)
788                 {
789                         /* Access the store */
790                         store_type *store_ptr = &town_info[i].store[j];
791
792                         if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
793
794                         /* Assume full stock */
795
796                         /*
797                          * 我が家が 20 ページまで使える隠し機能のための準備。
798                          * オプションが有効でもそうでなくても一応スペースを作っておく。
799                          */
800                         if (j == STORE_HOME)
801                         {
802                                 store_ptr->stock_size = (STORE_INVEN_MAX * 10);
803                         }
804                         else if (j == STORE_MUSEUM)
805                         {
806                                 store_ptr->stock_size = (STORE_INVEN_MAX * 50);
807                         }
808                         else
809                         {
810                                 store_ptr->stock_size = STORE_INVEN_MAX;
811                         }
812
813                         /* Allocate the stock */
814                         C_MAKE(store_ptr->stock, store_ptr->stock_size, object_type);
815
816                         /* No table for the black market or home */
817                         if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
818
819                         /* Assume full table */
820                         store_ptr->table_size = STORE_CHOICES;
821
822                         /* Allocate the stock */
823                         C_MAKE(store_ptr->table, store_ptr->table_size, s16b);
824
825                         /* Scan the choices */
826                         for (int k = 0; k < STORE_CHOICES; k++)
827                         {
828                                 KIND_OBJECT_IDX k_idx;
829
830                                 /* Extract the tval/sval codes */
831                                 int tv = store_table[j][k][0];
832                                 int sv = store_table[j][k][1];
833
834                                 /* Look for it */
835                                 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
836                                 {
837                                         object_kind *k_ptr = &k_info[k_idx];
838
839                                         /* Found a match */
840                                         if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
841                                 }
842
843                                 /* Catch errors */
844                                 if (k_idx == max_k_idx) continue;
845
846                                 /* Add that item index to the table */
847                                 store_ptr->table[store_ptr->table_num++] = k_idx;
848                         }
849                 }
850         }
851
852         return 0;
853 }
854
855 /*!
856  * @brief 店情報初期化のメインルーチン /
857  * Initialize buildings
858  * @return エラーコード
859  */
860 errr init_buildings(void)
861 {
862         for (int i = 0; i < MAX_BLDG; i++)
863         {
864                 building[i].name[0] = '\0';
865                 building[i].owner_name[0] = '\0';
866                 building[i].owner_race[0] = '\0';
867
868                 for (int j = 0; j < 8; j++)
869                 {
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;
876                 }
877
878                 for (int j = 0; j < MAX_CLASS; j++)
879                 {
880                         building[i].member_class[j] = 0;
881                 }
882
883                 for (int j = 0; j < MAX_RACES; j++)
884                 {
885                         building[i].member_race[j] = 0;
886                 }
887
888                 for (int j = 0; j < MAX_MAGIC + 1; j++)
889                 {
890                         building[i].member_realm[j] = 0;
891                 }
892         }
893
894         return 0;
895 }
896
897
898 /*!
899  * @brief クエスト情報初期化のメインルーチン /
900  * Initialize quest array
901  * @return エラーコード
902  */
903 static errr init_quests(void)
904 {
905         /* Allocate the quests */
906         C_MAKE(quest, max_q_idx, quest_type);
907
908         /* Set all quest to "untaken" */
909         for (int i = 0; i < max_q_idx; i++)
910         {
911                 quest[i].status = QUEST_STATUS_UNTAKEN;
912         }
913
914         return 0;
915 }
916
917 /*!
918  * @brief その他の初期情報更新 /
919  * Initialize some other arrays
920  * @return エラーコード
921  */
922 static errr init_other(player_type *player_ptr)
923 {
924         player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
925         floor_type *floor_ptr = player_ptr->current_floor_ptr;
926
927         /*** Prepare the "dungeon" information ***/
928
929         /* Allocate and Wipe the object list */
930         C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
931
932         /* Allocate and Wipe the monster list */
933         C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
934
935         /* Allocate and Wipe the monster process list */
936         for (int i = 0; i < MAX_MTIMED; i++)
937         {
938                 C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
939         }
940
941         /* Allocate and Wipe the max dungeon level */
942         C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
943
944         for (int i = 0; i < MAX_HGT; i++)
945         {
946                 C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
947         }
948
949         /*** Prepare the various "bizarre" arrays ***/
950
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);
955
956         /* Macro action buffer */
957         C_MAKE(macro__buf, 1024, char);
958
959         /* Quark variables */
960         quark_init();
961
962         /* Message variables */
963         C_MAKE(message__ptr, MESSAGE_MAX, u32b);
964         C_MAKE(message__buf, MESSAGE_BUF, char);
965
966         /* Hack -- No messages yet */
967         message__tail = MESSAGE_BUF;
968
969         /*** Prepare the options ***/
970
971         /* Scan the options */
972         for (int i = 0; option_info[i].o_desc; i++)
973         {
974                 int os = option_info[i].o_set;
975                 int ob = option_info[i].o_bit;
976
977                 /* Set the "default" options */
978                 if (!option_info[i].o_var) continue;
979
980                 /* Accept */
981                 option_mask[os] |= (1L << ob);
982
983                 /* Set */
984                 if (option_info[i].o_norm)
985                 {
986                         /* Set */
987                         option_flag[os] |= (1L << ob);
988                 }
989                 else
990                 {
991                         option_flag[os] &= ~(1L << ob);
992                 }
993         }
994
995         /* Analyze the windows */
996         for (int n = 0; n < 8; n++)
997         {
998                 /* Analyze the options */
999                 for (int i = 0; i < 32; i++)
1000                 {
1001                         /* Accept */
1002                         if (window_flag_desc[i])
1003                         {
1004                                 /* Accept */
1005                                 window_mask[n] |= (1L << i);
1006                         }
1007                 }
1008         }
1009
1010         /*
1011          *  Set the "default" window flags
1012          *  Window 1 : Display messages
1013          *  Window 2 : Display inven/equip
1014          */
1015         window_flag[1] = 1L << A_MAX;
1016         window_flag[2] = 1L << 0;
1017
1018         /*** Pre-allocate space for the "format()" buffer ***/
1019
1020         /* Hack -- Just call the "format()" function */
1021         (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1022         return 0;
1023 }
1024
1025
1026 /*!
1027  * @brief オブジェクト配列を初期化する /
1028  * Initialize some other arrays
1029  * @return エラーコード
1030  */
1031 static errr init_object_alloc(void)
1032 {
1033         s16b aux[MAX_DEPTH];
1034         (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1035
1036         s16b num[MAX_DEPTH];
1037         (void)C_WIPE(&num, MAX_DEPTH, s16b);
1038
1039         /* Free the old "alloc_kind_table" (if it exists) */
1040         if (alloc_kind_table)
1041         {
1042                 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1043         }
1044
1045         /* Size of "alloc_kind_table" */
1046         alloc_kind_size = 0;
1047
1048         /* Scan the objects */
1049         for (int i = 1; i < max_k_idx; i++)
1050         {
1051                 object_kind *k_ptr;
1052                 k_ptr = &k_info[i];
1053
1054                 /* Scan allocation pairs */
1055                 for (int j = 0; j < 4; j++)
1056                 {
1057                         /* Count the "legal" entries */
1058                         if (k_ptr->chance[j])
1059                         {
1060                                 /* Count the entries */
1061                                 alloc_kind_size++;
1062
1063                                 /* Group by level */
1064                                 num[k_ptr->locale[j]]++;
1065                         }
1066                 }
1067         }
1068
1069         /* Collect the level indexes */
1070         for (int i = 1; i < MAX_DEPTH; i++)
1071         {
1072                 /* Group by level */
1073                 num[i] += num[i - 1];
1074         }
1075
1076         if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1077
1078         /*** Initialize object allocation info ***/
1079
1080         /* Allocate the alloc_kind_table */
1081         C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1082
1083         /* Access the table entry */
1084         alloc_entry *table;
1085         table = alloc_kind_table;
1086
1087         /* Scan the objects */
1088         for (int i = 1; i < max_k_idx; i++)
1089         {
1090                 object_kind *k_ptr;
1091                 k_ptr = &k_info[i];
1092
1093                 /* Scan allocation pairs */
1094                 for (int j = 0; j < 4; j++)
1095                 {
1096                         /* Count the "legal" entries */
1097                         if (k_ptr->chance[j] == 0) continue;
1098
1099                         /* Extract the base level */
1100                         int x = k_ptr->locale[j];
1101
1102                         /* Extract the base probability */
1103                         int p = (100 / k_ptr->chance[j]);
1104
1105                         /* Skip entries preceding our locale */
1106                         int y = (x > 0) ? num[x - 1] : 0;
1107
1108                         /* Skip previous entries at this locale */
1109                         int z = y + aux[x];
1110
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;
1117
1118                         /* Another entry complete for this locale */
1119                         aux[x]++;
1120                 }
1121         }
1122
1123         return 0;
1124 }
1125
1126
1127 /*!
1128  * @brief モンスター配列と生成テーブルを初期化する /
1129  * Initialize some other arrays
1130  * @return エラーコード
1131  */
1132 static errr init_alloc(void)
1133 {
1134         monster_race *r_ptr;
1135         tag_type *elements;
1136
1137         /* Allocate the "r_info" array */
1138         C_MAKE(elements, max_r_idx, tag_type);
1139
1140         /* Scan the monsters */
1141         for (int i = 1; i < max_r_idx; i++)
1142         {
1143                 elements[i].tag = r_info[i].level;
1144                 elements[i].index = i;
1145         }
1146
1147         tag_sort(elements, max_r_idx);
1148
1149         /*** Initialize monster allocation info ***/
1150
1151         /* Size of "alloc_race_table" */
1152         alloc_race_size = max_r_idx;
1153
1154         /* Allocate the alloc_race_table */
1155         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1156
1157         /* Scan the monsters */
1158         for (int i = 1; i < max_r_idx; i++)
1159         {
1160                 /* Get the i'th race */
1161                 r_ptr = &r_info[elements[i].index];
1162
1163                 /* Count valid pairs */
1164                 if (r_ptr->rarity == 0) continue;
1165
1166                 /* Extract the base level */
1167                 int x = r_ptr->level;
1168
1169                 /* Extract the base probability */
1170                 int p = (100 / r_ptr->rarity);
1171
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;
1178         }
1179
1180         /* Free the "r_info" array */
1181         C_KILL(elements, max_r_idx, tag_type);
1182         (void)init_object_alloc();
1183         return 0;
1184 }
1185
1186
1187 /*!
1188  * @brief 画面左下にシステムメッセージを表示する /
1189  * Hack -- take notes on line 23
1190  * @return なし
1191  */
1192 static void init_note(concptr str)
1193 {
1194         term_erase(0, 23, 255);
1195         term_putstr(20, 23, -1, TERM_WHITE, str);
1196         term_fresh();
1197 }
1198
1199
1200 /*!
1201  * @brief 全ゲームデータ読み込みのサブルーチン /
1202  * Hack -- Explain a broken "lib" folder and quit (see below).
1203  * @return なし
1204  * @note
1205  * <pre>
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.
1209  * </pre>
1210  */
1211 static void init_angband_aux(concptr why)
1212 {
1213         plog(why);
1214
1215 #ifdef JP
1216         /* Explain */
1217         plog("'lib'ディレクトリが存在しないか壊れているようです。");
1218
1219         /* More details */
1220         plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
1221
1222         /* Explain */
1223         plog("該当する'README'ファイルを読んで確認してみて下さい。");
1224
1225         /* Quit with error */
1226         quit("致命的なエラー。");
1227 #else
1228         /* Explain */
1229         plog("The 'lib' directory is probably missing or broken.");
1230
1231         /* More details */
1232         plog("Perhaps the archive was not extracted correctly.");
1233
1234         /* Explain */
1235         plog("See the 'README' file for more information.");
1236
1237         /* Quit with error */
1238         quit("Fatal Error.");
1239 #endif
1240
1241 }
1242
1243
1244 /*!
1245  * @brief 全ゲームデータ読み込みのメインルーチン /
1246  * Hack -- main Angband initialization entry point
1247  * @return なし
1248  * @note
1249  * <pre>
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
1266  * the user.
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".
1288  * </pre>
1289  */
1290 void init_angband(player_type *player_ptr, void(*process_autopick_file_command)(char*))
1291 {
1292         /*** Verify the "news" file ***/
1293         char buf[1024];
1294         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1295
1296         /* Attempt to open the file */
1297         int fd = fd_open(buf, O_RDONLY);
1298
1299         /* Failure */
1300         if (fd < 0)
1301         {
1302                 char why[1024];
1303
1304                 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
1305
1306                 /* Crash and burn */
1307                 init_angband_aux(why);
1308         }
1309
1310         (void)fd_close(fd);
1311
1312         /*** Display the "news" file ***/
1313         term_clear();
1314         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1315
1316         /* Open the News file */
1317         FILE *fp;
1318         fp = angband_fopen(buf, "r");
1319
1320         /* Dump */
1321         if (fp)
1322         {
1323                 /* Dump the file to the screen */
1324                 int i = 0;
1325                 while (0 == angband_fgets(fp, buf, sizeof(buf)))
1326                 {
1327                         /* Display and advance */
1328                         term_putstr(0, i++, -1, TERM_WHITE, buf);
1329                 }
1330
1331                 angband_fclose(fp);
1332         }
1333
1334         term_flush();
1335
1336         /*** Verify (or create) the "high score" file ***/
1337         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1338
1339         /* Attempt to open the high score file */
1340         fd = fd_open(buf, O_RDONLY);
1341
1342         BIT_FLAGS file_permission = 0664;
1343         if (fd < 0)
1344         {
1345                 /* Grab permissions */
1346                 safe_setuid_grab(player_ptr);
1347
1348                 /* Create a new high score file */
1349                 fd = fd_make(buf, file_permission);
1350
1351                 /* Drop permissions */
1352                 safe_setuid_drop();
1353
1354                 /* Failure */
1355                 if (fd < 0)
1356                 {
1357                         char why[1024];
1358
1359                         sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
1360
1361                         /* Crash and burn */
1362                         init_angband_aux(why);
1363                 }
1364         }
1365
1366         (void)fd_close(fd);
1367
1368         put_title();
1369
1370         /*** Initialize some arrays ***/
1371
1372         /* Initialize misc. values */
1373         init_note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
1374         if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
1375
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"));
1379
1380         /* Initialize object info */
1381         init_note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
1382         if (init_k_info(player_ptr)) quit(_("アイテム初期化不能", "Cannot initialize objects"));
1383
1384         /* Initialize artifact info */
1385         init_note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
1386         if (init_a_info(player_ptr)) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
1387
1388
1389         /* Initialize ego-item info */
1390         init_note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
1391         if (init_e_info(player_ptr)) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
1392
1393
1394         /* Initialize monster info */
1395         init_note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
1396         if (init_r_info(player_ptr)) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
1397
1398
1399         /* Initialize dungeon info */
1400         init_note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
1401         if (init_d_info(player_ptr)) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
1402         {
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;
1406         }
1407
1408         /* Initialize magic info */
1409         init_note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
1410         if (init_m_info(player_ptr)) quit(_("魔法初期化不能", "Cannot initialize magic"));
1411
1412         /* Initialize weapon_exp info */
1413         init_note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
1414         if (init_s_info(player_ptr)) quit(_("熟練度初期化不能", "Cannot initialize skill"));
1415
1416         /* Initialize wilderness array */
1417         init_note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
1418
1419         if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
1420
1421         /* Initialize town array */
1422         init_note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
1423         if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
1424
1425         /* Initialize building array */
1426         init_note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
1427         if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
1428
1429         /* Initialize quest array */
1430         init_note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
1431         if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
1432
1433         /* Initialize vault info */
1434         if (init_v_info(player_ptr)) quit(_("vault 初期化不能", "Cannot initialize vaults"));
1435
1436         /* Initialize some other arrays */
1437         init_note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
1438         if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
1439
1440         /* Initialize some other arrays */
1441         init_note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
1442         if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
1443
1444         /*** Load default user pref files ***/
1445
1446         /* Initialize feature info */
1447         init_note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
1448
1449         /* Access the "basic" pref file */
1450         strcpy(buf, "pref.prf");
1451
1452         /* Process that file */
1453         process_pref_file(player_ptr, buf, process_autopick_file_command);
1454
1455         /* Access the "basic" system pref file */
1456         sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
1457
1458         /* Process that file */
1459         process_pref_file(player_ptr, buf, process_autopick_file_command);
1460
1461         init_note(_("[初期化終了]", "[Initialization complete]"));
1462 }
1463
1464
1465 /*!
1466  * @brief タイトル記述
1467  * @return なし
1468  */
1469 static void put_title(void)
1470 {
1471         char title[120];
1472 #if H_VER_EXTRA > 0
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,
1474 #else
1475         sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
1476 #endif
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);
1482 }
1483
1484
1485 /*!
1486  * @brief チェックサム情報を出力 / Get check sum in string form
1487  * @return チェックサム情報の文字列
1488  */
1489 concptr get_check_sum(void)
1490 {
1491         return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1492                 f_head.v_extra,
1493                 k_head.v_extra,
1494                 a_head.v_extra,
1495                 e_head.v_extra,
1496                 r_head.v_extra,
1497                 d_head.v_extra,
1498                 m_head.v_extra,
1499                 s_head.v_extra,
1500                 v_head.v_extra);
1501 }