OSDN Git Service

[Refactor] #37353 使われていないVERIFY_SAVEFILEを削除 / Removed unused preprocessors VERIFY_SAV...
[hengband/hengband.git] / src / init.c
1 /*!
2  * @file init2.c
3  * @brief ゲームデータ初期化2 / Initialization (part 2) -BEN-
4  * @date 2014/01/28
5  * @author
6  * <pre>
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
12  * </pre>
13  * @details
14  * <pre>
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
18  * at a time.
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.
30  * </pre>
31  */
32
33 #include "angband.h"
34 #include "util.h"
35 #include "files.h"
36 #include "core.h"
37 #include "term.h"
38
39 #include "artifact.h"
40 #include "bldg.h"
41 #include "init.h"
42 #include "quest.h"
43 #include "trap.h"
44 #include "rooms.h"
45 #include "store.h"
46 #include "wild.h"
47 #include "dungeon-file.h"
48 #include "files.h"
49 #include "feature.h"
50 #include "floor.h"
51 #include "floor-town.h"
52 #include "dungeon.h"
53 #include "rooms-vault.h"
54 #include "player-skill.h"
55 #include "player-class.h"
56 #include "objectkind.h"
57 #include "object-ego.h"
58 #include "rooms-vault.h"
59 #include "world.h"
60
61 #include <sys/types.h>
62 #include <sys/stat.h>
63
64 static void put_title(void);
65
66 /*!
67  * @brief 各データファイルを読み取るためのパスを取得する
68  * Find the default paths to all of our important sub-directories.
69  * @param path パス保管先の文字列
70  * @return なし
71  * @details
72  * <pre>
73  * The purpose of each sub-directory is described in "variable.c".
74  * All of the sub-directories should, by default, be located inside
75  * the main "lib" directory, whose location is very system dependant.
76  * This function takes a writable buffer, initially containing the
77  * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
78  * or a system dependant string, for example, ":lib:".  The buffer
79  * must be large enough to contain at least 32 more characters.
80  * Various command line options may allow some of the important
81  * directories to be changed to user-specified directories, most
82  * importantly, the "info" and "user" and "save" directories,
83  * but this is done after this function, see "main.c".
84  * In general, the initial path should end in the appropriate "PATH_SEP"
85  * string.  All of the "sub-directory" paths (created below or supplied
86  * by the user) will NOT end in the "PATH_SEP" string, see the special
87  * "path_build()" function in "util.c" for more information.
88  * Mega-Hack -- support fat raw files under NEXTSTEP, using special
89  * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
90  * requiring the directories to be created by hand by the user.
91  * Hack -- first we free all the strings, since this is known
92  * to succeed even if the strings have not been allocated yet,
93  * as long as the variables start out as "NULL".  This allows
94  * this function to be called multiple times, for example, to
95  * try several base "path" values until a good one is found.
96  * </pre>
97  */
98 void init_file_paths(char *path)
99 {
100         char *tail;
101
102 #ifdef PRIVATE_USER_PATH
103         char buf[1024];
104 #endif /* PRIVATE_USER_PATH */
105
106         /*** Free everything ***/
107
108         /* Free the main path */
109         string_free(ANGBAND_DIR);
110
111         /* Free the sub-paths */
112         string_free(ANGBAND_DIR_APEX);
113         string_free(ANGBAND_DIR_BONE);
114         string_free(ANGBAND_DIR_DATA);
115         string_free(ANGBAND_DIR_EDIT);
116         string_free(ANGBAND_DIR_SCRIPT);
117         string_free(ANGBAND_DIR_FILE);
118         string_free(ANGBAND_DIR_HELP);
119         string_free(ANGBAND_DIR_INFO);
120         string_free(ANGBAND_DIR_SAVE);
121         string_free(ANGBAND_DIR_USER);
122         string_free(ANGBAND_DIR_XTRA);
123
124         /*** Prepare the "path" ***/
125
126         /* Hack -- save the main directory */
127         ANGBAND_DIR = string_make(path);
128
129         /* Prepare to append to the Base Path */
130         tail = path + strlen(path);
131
132         /*** Build the sub-directory names ***/
133
134         /* Build a path name */
135         strcpy(tail, "apex");
136         ANGBAND_DIR_APEX = string_make(path);
137
138         /* Build a path name */
139         strcpy(tail, "bone");
140         ANGBAND_DIR_BONE = string_make(path);
141
142         /* Build a path name */
143         strcpy(tail, "data");
144         ANGBAND_DIR_DATA = string_make(path);
145
146         /* Build a path name */
147         strcpy(tail, "edit");
148         ANGBAND_DIR_EDIT = string_make(path);
149
150         /* Build a path name */
151         strcpy(tail, "script");
152         ANGBAND_DIR_SCRIPT = string_make(path);
153
154         /* Build a path name */
155         strcpy(tail, "file");
156         ANGBAND_DIR_FILE = string_make(path);
157
158         /* Build a path name */
159         strcpy(tail, "help");
160         ANGBAND_DIR_HELP = string_make(path);
161
162         /* Build a path name */
163         strcpy(tail, "info");
164         ANGBAND_DIR_INFO = string_make(path);
165
166         /* Build a path name */
167         strcpy(tail, "pref");
168         ANGBAND_DIR_PREF = string_make(path);
169
170         /* Build a path name */
171         strcpy(tail, "save");
172         ANGBAND_DIR_SAVE = string_make(path);
173
174 #ifdef PRIVATE_USER_PATH
175
176         /* Build the path to the user specific directory */
177         path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
178
179         /* Build a relative path name */
180         ANGBAND_DIR_USER = string_make(buf);
181
182 #else /* PRIVATE_USER_PATH */
183
184         /* Build a path name */
185         strcpy(tail, "user");
186         ANGBAND_DIR_USER = string_make(path);
187
188 #endif /* PRIVATE_USER_PATH */
189
190         /* Build a path name */
191         strcpy(tail, "xtra");
192         ANGBAND_DIR_XTRA = string_make(path);
193
194
195 #ifdef NeXT
196
197         /* Allow "fat binary" usage with NeXT */
198         if (TRUE)
199         {
200                 concptr next = NULL;
201
202 # if defined(m68k)
203                 next = "m68k";
204 # endif
205
206 # if defined(i386)
207                 next = "i386";
208 # endif
209
210 # if defined(sparc)
211                 next = "sparc";
212 # endif
213
214 # if defined(hppa)
215                 next = "hppa";
216 # endif
217
218                 /* Use special directory */
219                 if (next)
220                 {
221                         /* Forget the old path name */
222                         string_free(ANGBAND_DIR_DATA);
223
224                         /* Build a new path name */
225                         sprintf(tail, "data-%s", next);
226                         ANGBAND_DIR_DATA = string_make(path);
227                 }
228         }
229
230 #endif /* NeXT */
231
232 }
233
234
235 /*
236  * Hack -- help give useful error messages
237  */
238 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
239 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
240
241 /*!
242  * エラーメッセージの名称定義 / Standard error message text
243  */
244 concptr err_str[PARSE_ERROR_MAX] =
245 {
246         NULL,
247 #ifdef JP
248         "文法エラー",
249         "古いファイル",
250         "記録ヘッダがない",
251         "不連続レコード",
252         "おかしなフラグ存在",
253         "未定義命令",
254         "メモリ不足",
255         "座標範囲外",
256         "引数不足",
257         "未定義地形タグ",
258 #else
259         "parse error",
260         "obsolete file",
261         "missing record header",
262         "non-sequential records",
263         "invalid flag specification",
264         "undefined directive",
265         "out of memory",
266         "coordinates out of bounds",
267         "too few arguments",
268         "undefined terrain tag",
269 #endif
270
271 };
272
273
274 /*
275  * File headers
276  */
277 header v_head; /*!< Vault情報のヘッダ構造体 */
278 header f_head; /*!< 地形情報のヘッダ構造体 */
279 header k_head; /*!< ペースアイテム情報のヘッダ構造体 */
280 header a_head; /*!< 固定アーティファクト情報のヘッダ構造体 */
281 header e_head; /*!< アイテムエゴ情報のヘッダ構造体 */
282 header r_head; /*!< モンスター種族情報のヘッダ構造体 */
283 header d_head; /*!< ダンジョン情報のヘッダ構造体 */
284 header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
285 header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
286
287 /*!
288  * @brief テキストファイルとrawファイルの更新時刻を比較する
289  * Find the default paths to all of our important sub-directories.
290  * @param fd ファイルディスクリプタ
291  * @param template_file ファイル名
292  * @return テキストの方が新しいか、rawファイルがなく更新の必要がある場合-1、更新の必要がない場合0。
293  */
294 static errr check_modification_date(int fd, concptr template_file)
295 {
296         struct stat txt_stat, raw_stat;
297         char buf[1024];
298         path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
299
300         /* Access stats on text file */
301         if (stat(buf, &txt_stat))
302         {
303                 return 0;
304         }
305
306         /* Access stats on raw file */
307         if (fstat(fd, &raw_stat))
308         {
309                 return -1;
310         }
311
312         /* Ensure text file is not newer than raw file */
313         if (txt_stat.st_mtime > raw_stat.st_mtime)
314         {
315                 return -1;
316         }
317
318         return 0;
319 }
320
321
322 /*** Initialize from binary image files ***/
323
324 /*!
325  * @brief rawファイルからのデータの読み取り処理
326  * Initialize the "*_info" array, by parsing a binary "image" file
327  * @param fd ファイルディスクリプタ
328  * @param head rawファイルのヘッダ
329  * @return エラーコード
330  */
331 static errr init_info_raw(int fd, header *head)
332 {
333         header test;
334
335         /* Read and Verify the header */
336         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
337                 (test.v_major != head->v_major) ||
338                 (test.v_minor != head->v_minor) ||
339                 (test.v_patch != head->v_patch) ||
340                 (test.info_num != head->info_num) ||
341                 (test.info_len != head->info_len) ||
342                 (test.head_size != head->head_size) ||
343                 (test.info_size != head->info_size))
344         {
345                 /* Error */
346                 return -1;
347         }
348
349         /* Accept the header */
350         (*head) = test;
351
352         /* Allocate the "*_info" array */
353         C_MAKE(head->info_ptr, head->info_size, char);
354
355         /* Read the "*_info" array */
356         fd_read(fd, head->info_ptr, head->info_size);
357
358         if (head->name_size)
359         {
360                 /* Allocate the "*_name" array */
361                 C_MAKE(head->name_ptr, head->name_size, char);
362
363                 /* Read the "*_name" array */
364                 fd_read(fd, head->name_ptr, head->name_size);
365         }
366
367         if (head->text_size)
368         {
369                 /* Allocate the "*_text" array */
370                 C_MAKE(head->text_ptr, head->text_size, char);
371
372                 /* Read the "*_text" array */
373                 fd_read(fd, head->text_ptr, head->text_size);
374         }
375
376         if (head->tag_size)
377         {
378                 /* Allocate the "*_tag" array */
379                 C_MAKE(head->tag_ptr, head->tag_size, char);
380
381                 /* Read the "*_tag" array */
382                 fd_read(fd, head->tag_ptr, head->tag_size);
383         }
384
385         return 0;
386 }
387
388
389
390 /*!
391  * @brief ヘッダ構造体の更新
392  * Initialize the header of an *_info.raw file.
393  * @param head rawファイルのヘッダ
394  * @param num データ数
395  * @param len データの長さ
396  * @return エラーコード
397  */
398 static void init_header(header *head, IDX num, int len)
399 {
400         /* Save the "version" */
401         head->v_major = FAKE_VER_MAJOR;
402         head->v_minor = FAKE_VER_MINOR;
403         head->v_patch = FAKE_VER_PATCH;
404         head->v_extra = 0;
405
406         /* Save the "record" information */
407         head->info_num = (IDX)num;
408         head->info_len = len;
409
410         /* Save the size of "*_head" and "*_info" */
411         head->head_size = sizeof(header);
412         head->info_size = head->info_num * head->info_len;
413 }
414
415
416 static void update_header(header *head, void **info, char **name, char **text, char **tag)
417 {
418         if (info) *info = head->info_ptr;
419         if (name) *name = head->name_ptr;
420         if (text) *text = head->text_ptr;
421         if (tag)  *tag = head->tag_ptr;
422 }
423
424
425 /*!
426  * @brief ヘッダ構造体の更新
427  * Initialize the "*_info" array
428  * @param filename ファイル名(拡張子txt/raw)
429  * @param head 処理に用いるヘッダ構造体
430  * @param info データ保管先の構造体ポインタ
431  * @param name 名称用可変文字列の保管先
432  * @param text テキスト用可変文字列の保管先
433  * @param tag タグ用可変文字列の保管先
434  * @return エラーコード
435  * @note
436  * Note that we let each entry have a unique "name" and "text" string,
437  * even if the string happens to be empty (everyone has a unique '\0').
438  */
439 static errr init_info(concptr filename, header *head, void **info, char **name, char **text, char **tag)
440 {
441         /* General buffer */
442         char buf[1024];
443
444         /*** Load the binary image file ***/
445         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
446
447         /* Attempt to open the "raw" file */
448         int fd = fd_open(buf, O_RDONLY);
449
450         /* Process existing "raw" file */
451         errr err = 1;
452         if (fd >= 0)
453         {
454                 err = check_modification_date(fd, format("%s.txt", filename));
455
456                 /* Attempt to parse the "raw" file */
457                 if (!err)
458                         err = init_info_raw(fd, head);
459                 (void)fd_close(fd);
460         }
461
462         /* Do we have to parse the *.txt file? */
463         BIT_FLAGS file_permission = 0644;
464         if (err == 0)
465         {
466                 update_header(head, info, name, text, tag);
467                 return 0;
468         }
469
470         /*** Make the fake arrays ***/
471         C_MAKE(head->info_ptr, head->info_size, char);
472
473         /* Hack -- make "fake" arrays */
474         if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
475         if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
476         if (tag)  C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
477
478         if (info) (*info) = head->info_ptr;
479         if (name) (*name) = head->name_ptr;
480         if (text) (*text) = head->text_ptr;
481         if (tag)  (*tag) = head->tag_ptr;
482
483         /*** Load the ascii template file ***/
484         path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
485         FILE *fp;
486         fp = my_fopen(buf, "r");
487
488         /* Parse it */
489         if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
490
491         /* Parse the file */
492         err = init_info_txt(fp, buf, head, head->parse_info_txt);
493         my_fclose(fp);
494
495         /* Errors */
496         if (err)
497         {
498                 concptr oops;
499
500 #ifdef JP
501                 /* Error string */
502                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
503
504                 msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
505                 msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
506                 msg_format("構文 '%s'。", buf);
507                 msg_print(NULL);
508
509                 /* Quit */
510                 quit(format("'%s.txt'ファイルにエラー", filename));
511 #else
512                 /* Error string */
513                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
514
515                 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
516                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
517                 msg_format("Parsing '%s'.", buf);
518                 msg_print(NULL);
519
520                 /* Quit */
521                 quit(format("Error in '%s.txt' file.", filename));
522 #endif
523         }
524
525         /*** Make final retouch on fake tags ***/
526         if (head->retouch)
527         {
528                 (*head->retouch)(head);
529         }
530
531         /*** Dump the binary image file ***/
532         /* File type is "DATA" */
533         FILE_TYPE(FILE_TYPE_DATA);
534         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
535
536         /* Grab permissions */
537         safe_setuid_grab();
538
539         /* Kill the old file */
540         (void)fd_kill(buf);
541
542         /* Attempt to create the raw file */
543         fd = fd_make(buf, file_permission);
544
545         /* Drop permissions */
546         safe_setuid_drop();
547
548         /* Dump to the file */
549         if (fd >= 0)
550         {
551                 /* Dump it */
552                 fd_write(fd, (concptr)(head), head->head_size);
553
554                 /* Dump the "*_info" array */
555                 fd_write(fd, head->info_ptr, head->info_size);
556
557                 /* Dump the "*_name" array */
558                 fd_write(fd, head->name_ptr, head->name_size);
559
560                 /* Dump the "*_text" array */
561                 fd_write(fd, head->text_ptr, head->text_size);
562
563                 /* Dump the "*_tag" array */
564                 fd_write(fd, head->tag_ptr, head->tag_size);
565
566                 /* Close */
567                 (void)fd_close(fd);
568         }
569
570         /*** Kill the fake arrays ***/
571
572         /* Free the "*_info" array */
573         C_KILL(head->info_ptr, head->info_size, char);
574
575         /* Hack -- Free the "fake" arrays */
576         if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
577         if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
578         if (tag)  C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
579
580         /*** Load the binary image file ***/
581         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
582
583         /* Attempt to open the "raw" file */
584         fd = fd_open(buf, O_RDONLY);
585
586         /* Process existing "raw" file */
587         if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
588
589         /* Attempt to parse the "raw" file */
590         err = init_info_raw(fd, head);
591         (void)fd_close(fd);
592
593         /* Error */
594         if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
595
596         update_header(head, info, name, text, tag);
597         return 0;
598 }
599
600
601 /*!
602  * @brief 地形情報読み込みのメインルーチン /
603  * Initialize the "f_info" array
604  * @return エラーコード
605  */
606 static errr init_f_info(void)
607 {
608         /* Init the header */
609         init_header(&f_head, max_f_idx, sizeof(feature_type));
610
611         /* Save a pointer to the parsing function */
612         f_head.parse_info_txt = parse_f_info;
613
614         /* Save a pointer to the retouch fake tags */
615         f_head.retouch = retouch_f_info;
616
617         return init_info("f_info", &f_head,
618                 (void*)&f_info, &f_name, NULL, &f_tag);
619 }
620
621
622 /*!
623  * @brief ベースアイテム情報読み込みのメインルーチン /
624  * Initialize the "k_info" array
625  * @return エラーコード
626  */
627 static errr init_k_info(void)
628 {
629         /* Init the header */
630         init_header(&k_head, max_k_idx, sizeof(object_kind));
631
632         /* Save a pointer to the parsing function */
633         k_head.parse_info_txt = parse_k_info;
634
635         return init_info("k_info", &k_head,
636                 (void*)&k_info, &k_name, &k_text, NULL);
637 }
638
639
640 /*!
641  * @brief 固定アーティファクト情報読み込みのメインルーチン /
642  * Initialize the "a_info" array
643  * @return エラーコード
644  */
645 static errr init_a_info(void)
646 {
647         /* Init the header */
648         init_header(&a_head, max_a_idx, sizeof(artifact_type));
649
650         /* Save a pointer to the parsing function */
651         a_head.parse_info_txt = parse_a_info;
652
653         return init_info("a_info", &a_head,
654                 (void*)&a_info, &a_name, &a_text, NULL);
655 }
656
657
658 /*!
659  * @brief 固定アーティファクト情報読み込みのメインルーチン /
660  * Initialize the "e_info" array
661  * @return エラーコード
662  */
663 static errr init_e_info(void)
664 {
665         /* Init the header */
666         init_header(&e_head, max_e_idx, sizeof(ego_item_type));
667
668         /* Save a pointer to the parsing function */
669         e_head.parse_info_txt = parse_e_info;
670
671         return init_info("e_info", &e_head,
672                 (void*)&e_info, &e_name, &e_text, NULL);
673 }
674
675
676 /*!
677  * @brief モンスター種族情報読み込みのメインルーチン /
678  * Initialize the "r_info" array
679  * @return エラーコード
680  */
681 static errr init_r_info(void)
682 {
683         /* Init the header */
684         init_header(&r_head, max_r_idx, sizeof(monster_race));
685
686         /* Save a pointer to the parsing function */
687         r_head.parse_info_txt = parse_r_info;
688
689         return init_info("r_info", &r_head,
690                 (void*)&r_info, &r_name, &r_text, NULL);
691 }
692
693
694 /*!
695  * @brief ダンジョン情報読み込みのメインルーチン /
696  * Initialize the "d_info" array
697  * @return エラーコード
698  */
699 static errr init_d_info(void)
700 {
701         /* Init the header */
702         init_header(&d_head, current_world_ptr->max_d_idx, sizeof(dungeon_type));
703
704         /* Save a pointer to the parsing function */
705         d_head.parse_info_txt = parse_d_info;
706
707         return init_info("d_info", &d_head,
708                 (void*)&d_info, &d_name, &d_text, NULL);
709 }
710
711
712 /*!
713  * @brief Vault情報読み込みのメインルーチン /
714  * Initialize the "v_info" array
715  * @return エラーコード
716  * @note
717  * Note that we let each entry have a unique "name" and "text" string,
718  * even if the string happens to be empty (everyone has a unique '\0').
719  */
720 errr init_v_info(void)
721 {
722         /* Init the header */
723         init_header(&v_head, max_v_idx, sizeof(vault_type));
724
725         /* Save a pointer to the parsing function */
726         v_head.parse_info_txt = parse_v_info;
727
728         return init_info("v_info", &v_head,
729                 (void*)&v_info, &v_name, &v_text, NULL);
730 }
731
732
733 /*!
734  * @brief 職業技能情報読み込みのメインルーチン /
735  * Initialize the "s_info" array
736  * @return エラーコード
737  */
738 static errr init_s_info(void)
739 {
740         /* Init the header */
741         init_header(&s_head, MAX_CLASS, sizeof(skill_table));
742
743         /* Save a pointer to the parsing function */
744         s_head.parse_info_txt = parse_s_info;
745
746         return init_info("s_info", &s_head,
747                 (void*)&s_info, NULL, NULL, NULL);
748 }
749
750
751 /*!
752  * @brief 職業魔法情報読み込みのメインルーチン /
753  * Initialize the "m_info" array
754  * @return エラーコード
755  */
756 static errr init_m_info(void)
757 {
758         /* Init the header */
759         init_header(&m_head, MAX_CLASS, sizeof(player_magic));
760
761         /* Save a pointer to the parsing function */
762         m_head.parse_info_txt = parse_m_info;
763
764         return init_info("m_info", &m_head,
765                 (void*)&m_info, NULL, NULL, NULL);
766 }
767
768
769 /*!
770  * @brief 基本情報読み込みのメインルーチン /
771  * Initialize misc. values
772  * @param player_ptr プレーヤーへの参照ポインタ
773  * @return エラーコード
774  */
775 static errr init_misc(player_type *player_ptr)
776 {
777         return process_dungeon_file(player_ptr, "misc.txt", 0, 0, 0, 0);
778 }
779
780
781 /*!
782  * @brief 町情報読み込みのメインルーチン /
783  * Initialize town array
784  * @return エラーコード
785  */
786 static errr init_towns(void)
787 {
788         /* Allocate the towns */
789         C_MAKE(town_info, max_towns, town_type);
790
791         for (int i = 1; i < max_towns; i++)
792         {
793                 /*** Prepare the Stores ***/
794
795                 /* Allocate the stores */
796                 C_MAKE(town_info[i].store, MAX_STORES, store_type);
797
798                 /* Fill in each store */
799                 for (int j = 0; j < MAX_STORES; j++)
800                 {
801                         /* Access the store */
802                         store_type *st_ptr = &town_info[i].store[j];
803
804                         if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
805
806                         /* Assume full stock */
807
808                         /*
809                          * 我が家が 20 ページまで使える隠し機能のための準備。
810                          * オプションが有効でもそうでなくても一応スペースを作っておく。
811                          */
812                         if (j == STORE_HOME)
813                         {
814                                 st_ptr->stock_size = (STORE_INVEN_MAX * 10);
815                         }
816                         else if (j == STORE_MUSEUM)
817                         {
818                                 st_ptr->stock_size = (STORE_INVEN_MAX * 50);
819                         }
820                         else
821                         {
822                                 st_ptr->stock_size = STORE_INVEN_MAX;
823                         }
824
825                         /* Allocate the stock */
826                         C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
827
828                         /* No table for the black market or home */
829                         if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
830
831                         /* Assume full table */
832                         st_ptr->table_size = STORE_CHOICES;
833
834                         /* Allocate the stock */
835                         C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
836
837                         /* Scan the choices */
838                         for (int k = 0; k < STORE_CHOICES; k++)
839                         {
840                                 KIND_OBJECT_IDX k_idx;
841
842                                 /* Extract the tval/sval codes */
843                                 int tv = store_table[j][k][0];
844                                 int sv = store_table[j][k][1];
845
846                                 /* Look for it */
847                                 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
848                                 {
849                                         object_kind *k_ptr = &k_info[k_idx];
850
851                                         /* Found a match */
852                                         if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
853                                 }
854
855                                 /* Catch errors */
856                                 if (k_idx == max_k_idx) continue;
857
858                                 /* Add that item index to the table */
859                                 st_ptr->table[st_ptr->table_num++] = k_idx;
860                         }
861                 }
862         }
863
864         return 0;
865 }
866
867 /*!
868  * @brief 店情報初期化のメインルーチン /
869  * Initialize buildings
870  * @return エラーコード
871  */
872 errr init_buildings(void)
873 {
874         for (int i = 0; i < MAX_BLDG; i++)
875         {
876                 building[i].name[0] = '\0';
877                 building[i].owner_name[0] = '\0';
878                 building[i].owner_race[0] = '\0';
879
880                 for (int j = 0; j < 8; j++)
881                 {
882                         building[i].act_names[j][0] = '\0';
883                         building[i].member_costs[j] = 0;
884                         building[i].other_costs[j] = 0;
885                         building[i].letters[j] = 0;
886                         building[i].actions[j] = 0;
887                         building[i].action_restr[j] = 0;
888                 }
889
890                 for (int j = 0; j < MAX_CLASS; j++)
891                 {
892                         building[i].member_class[j] = 0;
893                 }
894
895                 for (int j = 0; j < MAX_RACES; j++)
896                 {
897                         building[i].member_race[j] = 0;
898                 }
899
900                 for (int j = 0; j < MAX_MAGIC + 1; j++)
901                 {
902                         building[i].member_realm[j] = 0;
903                 }
904         }
905
906         return 0;
907 }
908
909
910 /*!
911  * @brief クエスト情報初期化のメインルーチン /
912  * Initialize quest array
913  * @return エラーコード
914  */
915 static errr init_quests(void)
916 {
917         /* Allocate the quests */
918         C_MAKE(quest, max_q_idx, quest_type);
919
920         /* Set all quest to "untaken" */
921         for (int i = 0; i < max_q_idx; i++)
922         {
923                 quest[i].status = QUEST_STATUS_UNTAKEN;
924         }
925
926         return 0;
927 }
928
929 /*! 地形タグ情報から地形IDを得られなかった場合にTRUEを返すグローバル変数 */
930 static bool feat_tag_is_not_found = FALSE;
931
932 /*!
933  * @brief 地形タグからIDを得る /
934  * Initialize quest array
935  * @return 地形ID
936  */
937 s16b f_tag_to_index_in_init(concptr str)
938 {
939         FEAT_IDX feat = f_tag_to_index(str);
940
941         if (feat < 0) feat_tag_is_not_found = TRUE;
942
943         return feat;
944 }
945
946
947 /*!
948  * @brief 地形の汎用定義をタグを通じて取得する /
949  * Initialize feature variables
950  * @return エラーコード
951  */
952 static errr init_feat_variables(void)
953 {
954         feat_none = f_tag_to_index_in_init("NONE");
955
956         feat_floor = f_tag_to_index_in_init("FLOOR");
957         feat_glyph = f_tag_to_index_in_init("GLYPH");
958         feat_explosive_rune = f_tag_to_index_in_init("EXPLOSIVE_RUNE");
959         feat_mirror = f_tag_to_index_in_init("MIRROR");
960         
961         feat_door[DOOR_DOOR].open = f_tag_to_index_in_init("OPEN_DOOR");
962         feat_door[DOOR_DOOR].broken = f_tag_to_index_in_init("BROKEN_DOOR");
963         feat_door[DOOR_DOOR].closed = f_tag_to_index_in_init("CLOSED_DOOR");
964
965         /* Locked doors */
966         FEAT_IDX i;
967         for (i = 1; i < MAX_LJ_DOORS; i++)
968         {
969                 s16b door = f_tag_to_index(format("LOCKED_DOOR_%d", i));
970                 if (door < 0) break;
971                 feat_door[DOOR_DOOR].locked[i - 1] = door;
972         }
973
974         if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
975         feat_door[DOOR_DOOR].num_locked = i - 1;
976
977         /* Jammed doors */
978         for (i = 0; i < MAX_LJ_DOORS; i++)
979         {
980                 s16b door = f_tag_to_index(format("JAMMED_DOOR_%d", i));
981                 if (door < 0) break;
982                 feat_door[DOOR_DOOR].jammed[i] = door;
983         }
984
985         if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
986         feat_door[DOOR_DOOR].num_jammed = i;
987
988         /* Glass doors */
989         feat_door[DOOR_GLASS_DOOR].open = f_tag_to_index_in_init("OPEN_GLASS_DOOR");
990         feat_door[DOOR_GLASS_DOOR].broken = f_tag_to_index_in_init("BROKEN_GLASS_DOOR");
991         feat_door[DOOR_GLASS_DOOR].closed = f_tag_to_index_in_init("CLOSED_GLASS_DOOR");
992
993         /* Locked glass doors */
994         for (i = 1; i < MAX_LJ_DOORS; i++)
995         {
996                 s16b door = f_tag_to_index(format("LOCKED_GLASS_DOOR_%d", i));
997                 if (door < 0) break;
998                 feat_door[DOOR_GLASS_DOOR].locked[i - 1] = door;
999         }
1000
1001         if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1002         feat_door[DOOR_GLASS_DOOR].num_locked = i - 1;
1003
1004         /* Jammed glass doors */
1005         for (i = 0; i < MAX_LJ_DOORS; i++)
1006         {
1007                 s16b door = f_tag_to_index(format("JAMMED_GLASS_DOOR_%d", i));
1008                 if (door < 0) break;
1009                 feat_door[DOOR_GLASS_DOOR].jammed[i] = door;
1010         }
1011
1012         if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1013         feat_door[DOOR_GLASS_DOOR].num_jammed = i;
1014
1015         /* Curtains */
1016         feat_door[DOOR_CURTAIN].open = f_tag_to_index_in_init("OPEN_CURTAIN");
1017         feat_door[DOOR_CURTAIN].broken = feat_door[DOOR_CURTAIN].open;
1018         feat_door[DOOR_CURTAIN].closed = f_tag_to_index_in_init("CLOSED_CURTAIN");
1019         feat_door[DOOR_CURTAIN].locked[0] = feat_door[DOOR_CURTAIN].closed;
1020         feat_door[DOOR_CURTAIN].num_locked = 1;
1021         feat_door[DOOR_CURTAIN].jammed[0] = feat_door[DOOR_CURTAIN].closed;
1022         feat_door[DOOR_CURTAIN].num_jammed = 1;
1023
1024         /* Stairs */
1025         feat_up_stair = f_tag_to_index_in_init("UP_STAIR");
1026         feat_down_stair = f_tag_to_index_in_init("DOWN_STAIR");
1027         feat_entrance = f_tag_to_index_in_init("ENTRANCE");
1028
1029         /* Normal traps */
1030         init_normal_traps();
1031
1032         /* Special traps */
1033         feat_trap_open = f_tag_to_index_in_init("TRAP_OPEN");
1034         feat_trap_armageddon = f_tag_to_index_in_init("TRAP_ARMAGEDDON");
1035         feat_trap_piranha = f_tag_to_index_in_init("TRAP_PIRANHA");
1036
1037         /* Rubble */
1038         feat_rubble = f_tag_to_index_in_init("RUBBLE");
1039
1040         /* Seams */
1041         feat_magma_vein = f_tag_to_index_in_init("MAGMA_VEIN");
1042         feat_quartz_vein = f_tag_to_index_in_init("QUARTZ_VEIN");
1043
1044         /* Walls */
1045         feat_granite = f_tag_to_index_in_init("GRANITE");
1046         feat_permanent = f_tag_to_index_in_init("PERMANENT");
1047
1048         /* Glass floor */
1049         feat_glass_floor = f_tag_to_index_in_init("GLASS_FLOOR");
1050
1051         /* Glass walls */
1052         feat_glass_wall = f_tag_to_index_in_init("GLASS_WALL");
1053         feat_permanent_glass_wall = f_tag_to_index_in_init("PERMANENT_GLASS_WALL");
1054
1055         /* Pattern */
1056         feat_pattern_start = f_tag_to_index_in_init("PATTERN_START");
1057         feat_pattern_1 = f_tag_to_index_in_init("PATTERN_1");
1058         feat_pattern_2 = f_tag_to_index_in_init("PATTERN_2");
1059         feat_pattern_3 = f_tag_to_index_in_init("PATTERN_3");
1060         feat_pattern_4 = f_tag_to_index_in_init("PATTERN_4");
1061         feat_pattern_end = f_tag_to_index_in_init("PATTERN_END");
1062         feat_pattern_old = f_tag_to_index_in_init("PATTERN_OLD");
1063         feat_pattern_exit = f_tag_to_index_in_init("PATTERN_EXIT");
1064         feat_pattern_corrupted = f_tag_to_index_in_init("PATTERN_CORRUPTED");
1065
1066         /* Various */
1067         feat_black_market = f_tag_to_index_in_init("BLACK_MARKET");
1068         feat_town = f_tag_to_index_in_init("TOWN");
1069
1070         /* Terrains */
1071         feat_deep_water = f_tag_to_index_in_init("DEEP_WATER");
1072         feat_shallow_water = f_tag_to_index_in_init("SHALLOW_WATER");
1073         feat_deep_lava = f_tag_to_index_in_init("DEEP_LAVA");
1074         feat_shallow_lava = f_tag_to_index_in_init("SHALLOW_LAVA");
1075         feat_heavy_cold_zone = f_tag_to_index_in_init("HEAVY_COLD_ZONE");
1076         feat_cold_zone = f_tag_to_index_in_init("COLD_ZONE");
1077         feat_heavy_electrical_zone = f_tag_to_index_in_init("HEAVY_ELECTRICAL_ZONE");
1078         feat_electrical_zone = f_tag_to_index_in_init("ELECTRICAL_ZONE");
1079         feat_deep_acid_puddle = f_tag_to_index_in_init("DEEP_ACID_PUDDLE");
1080         feat_shallow_acid_puddle = f_tag_to_index_in_init("SHALLOW_ACID_PUDDLE");
1081         feat_deep_poisonous_puddle = f_tag_to_index_in_init("DEEP_POISONOUS_PUDDLE");
1082         feat_shallow_poisonous_puddle = f_tag_to_index_in_init("SHALLOW_POISONOUS_PUDDLE");
1083         feat_dirt = f_tag_to_index_in_init("DIRT");
1084         feat_grass = f_tag_to_index_in_init("GRASS");
1085         feat_flower = f_tag_to_index_in_init("FLOWER");
1086         feat_brake = f_tag_to_index_in_init("BRAKE");
1087         feat_tree = f_tag_to_index_in_init("TREE");
1088         feat_mountain = f_tag_to_index_in_init("MOUNTAIN");
1089         feat_swamp = f_tag_to_index_in_init("SWAMP");
1090
1091         feat_undetected = f_tag_to_index_in_init("UNDETECTED");
1092
1093         init_wilderness_terrains();
1094         return feat_tag_is_not_found ? PARSE_ERROR_UNDEFINED_TERRAIN_TAG : 0;
1095 }
1096
1097
1098 /*!
1099  * @brief その他の初期情報更新 /
1100  * Initialize some other arrays
1101  * @return エラーコード
1102  */
1103 static errr init_other(player_type *player_ptr)
1104 {
1105         player_ptr->current_floor_ptr = &floor_info; // TODO:本当はこんなところで初期化したくない
1106         floor_type *floor_ptr = player_ptr->current_floor_ptr;
1107
1108         /*** Prepare the "dungeon" information ***/
1109
1110         /* Allocate and Wipe the object list */
1111         C_MAKE(floor_ptr->o_list, current_world_ptr->max_o_idx, object_type);
1112
1113         /* Allocate and Wipe the monster list */
1114         C_MAKE(floor_ptr->m_list, current_world_ptr->max_m_idx, monster_type);
1115
1116         /* Allocate and Wipe the monster process list */
1117         for (int i = 0; i < MAX_MTIMED; i++)
1118         {
1119                 C_MAKE(floor_ptr->mproc_list[i], current_world_ptr->max_m_idx, s16b);
1120         }
1121
1122         /* Allocate and Wipe the max dungeon level */
1123         C_MAKE(max_dlv, current_world_ptr->max_d_idx, DEPTH);
1124
1125         for (int i = 0; i < MAX_HGT; i++)
1126         {
1127                 C_MAKE(floor_ptr->grid_array[i], MAX_WID, grid_type);
1128         }
1129
1130         /*** Prepare the various "bizarre" arrays ***/
1131
1132         /* Macro variables */
1133         C_MAKE(macro__pat, MACRO_MAX, concptr);
1134         C_MAKE(macro__act, MACRO_MAX, concptr);
1135         C_MAKE(macro__cmd, MACRO_MAX, bool);
1136
1137         /* Macro action buffer */
1138         C_MAKE(macro__buf, 1024, char);
1139
1140         /* Quark variables */
1141         quark_init();
1142
1143         /* Message variables */
1144         C_MAKE(message__ptr, MESSAGE_MAX, u32b);
1145         C_MAKE(message__buf, MESSAGE_BUF, char);
1146
1147         /* Hack -- No messages yet */
1148         message__tail = MESSAGE_BUF;
1149
1150         /*** Prepare the options ***/
1151
1152         /* Scan the options */
1153         for (int i = 0; option_info[i].o_desc; i++)
1154         {
1155                 int os = option_info[i].o_set;
1156                 int ob = option_info[i].o_bit;
1157
1158                 /* Set the "default" options */
1159                 if (!option_info[i].o_var) continue;
1160
1161                 /* Accept */
1162                 option_mask[os] |= (1L << ob);
1163
1164                 /* Set */
1165                 if (option_info[i].o_norm)
1166                 {
1167                         /* Set */
1168                         option_flag[os] |= (1L << ob);
1169                 }
1170                 else
1171                 {
1172                         option_flag[os] &= ~(1L << ob);
1173                 }
1174         }
1175
1176         /* Analyze the windows */
1177         for (int n = 0; n < 8; n++)
1178         {
1179                 /* Analyze the options */
1180                 for (int i = 0; i < 32; i++)
1181                 {
1182                         /* Accept */
1183                         if (window_flag_desc[i])
1184                         {
1185                                 /* Accept */
1186                                 window_mask[n] |= (1L << i);
1187                         }
1188                 }
1189         }
1190
1191         /*
1192          *  Set the "default" window flags
1193          *  Window 1 : Display messages
1194          *  Window 2 : Display inven/equip
1195          */
1196         window_flag[1] = 1L << A_MAX;
1197         window_flag[2] = 1L << 0;
1198
1199         /*** Pre-allocate space for the "format()" buffer ***/
1200
1201         /* Hack -- Just call the "format()" function */
1202         (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1203         return 0;
1204 }
1205
1206
1207 /*!
1208  * @brief オブジェクト配列を初期化する /
1209  * Initialize some other arrays
1210  * @return エラーコード
1211  */
1212 static errr init_object_alloc(void)
1213 {
1214         s16b aux[MAX_DEPTH];
1215         (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1216
1217         s16b num[MAX_DEPTH];
1218         (void)C_WIPE(&num, MAX_DEPTH, s16b);
1219
1220         /* Free the old "alloc_kind_table" (if it exists) */
1221         if (alloc_kind_table)
1222         {
1223                 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1224         }
1225
1226         /* Size of "alloc_kind_table" */
1227         alloc_kind_size = 0;
1228
1229         /* Scan the objects */
1230         for (int i = 1; i < max_k_idx; i++)
1231         {
1232                 object_kind *k_ptr;
1233                 k_ptr = &k_info[i];
1234
1235                 /* Scan allocation pairs */
1236                 for (int j = 0; j < 4; j++)
1237                 {
1238                         /* Count the "legal" entries */
1239                         if (k_ptr->chance[j])
1240                         {
1241                                 /* Count the entries */
1242                                 alloc_kind_size++;
1243
1244                                 /* Group by level */
1245                                 num[k_ptr->locale[j]]++;
1246                         }
1247                 }
1248         }
1249
1250         /* Collect the level indexes */
1251         for (int i = 1; i < MAX_DEPTH; i++)
1252         {
1253                 /* Group by level */
1254                 num[i] += num[i - 1];
1255         }
1256
1257         if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1258
1259         /*** Initialize object allocation info ***/
1260
1261         /* Allocate the alloc_kind_table */
1262         C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1263
1264         /* Access the table entry */
1265         alloc_entry *table;
1266         table = alloc_kind_table;
1267
1268         /* Scan the objects */
1269         for (int i = 1; i < max_k_idx; i++)
1270         {
1271                 object_kind *k_ptr;
1272                 k_ptr = &k_info[i];
1273
1274                 /* Scan allocation pairs */
1275                 for (int j = 0; j < 4; j++)
1276                 {
1277                         /* Count the "legal" entries */
1278                         if (k_ptr->chance[j] == 0) continue;
1279
1280                         /* Extract the base level */
1281                         int x = k_ptr->locale[j];
1282
1283                         /* Extract the base probability */
1284                         int p = (100 / k_ptr->chance[j]);
1285
1286                         /* Skip entries preceding our locale */
1287                         int y = (x > 0) ? num[x - 1] : 0;
1288
1289                         /* Skip previous entries at this locale */
1290                         int z = y + aux[x];
1291
1292                         /* Load the entry */
1293                         table[z].index = (KIND_OBJECT_IDX)i;
1294                         table[z].level = (DEPTH)x;
1295                         table[z].prob1 = (PROB)p;
1296                         table[z].prob2 = (PROB)p;
1297                         table[z].prob3 = (PROB)p;
1298
1299                         /* Another entry complete for this locale */
1300                         aux[x]++;
1301                 }
1302         }
1303
1304         return 0;
1305 }
1306
1307
1308 /*!
1309  * @brief モンスター配列と生成テーブルを初期化する /
1310  * Initialize some other arrays
1311  * @return エラーコード
1312  */
1313 static errr init_alloc(void)
1314 {
1315         monster_race *r_ptr;
1316         tag_type *elements;
1317
1318         /* Allocate the "r_info" array */
1319         C_MAKE(elements, max_r_idx, tag_type);
1320
1321         /* Scan the monsters */
1322         for (int i = 1; i < max_r_idx; i++)
1323         {
1324                 elements[i].tag = r_info[i].level;
1325                 elements[i].index = i;
1326         }
1327
1328         tag_sort(elements, max_r_idx);
1329
1330         /*** Initialize monster allocation info ***/
1331
1332         /* Size of "alloc_race_table" */
1333         alloc_race_size = max_r_idx;
1334
1335         /* Allocate the alloc_race_table */
1336         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1337
1338         /* Scan the monsters */
1339         for (int i = 1; i < max_r_idx; i++)
1340         {
1341                 /* Get the i'th race */
1342                 r_ptr = &r_info[elements[i].index];
1343
1344                 /* Count valid pairs */
1345                 if (r_ptr->rarity == 0) continue;
1346
1347                 /* Extract the base level */
1348                 int x = r_ptr->level;
1349
1350                 /* Extract the base probability */
1351                 int p = (100 / r_ptr->rarity);
1352
1353                 /* Load the entry */
1354                 alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
1355                 alloc_race_table[i].level = (DEPTH)x;
1356                 alloc_race_table[i].prob1 = (PROB)p;
1357                 alloc_race_table[i].prob2 = (PROB)p;
1358                 alloc_race_table[i].prob3 = (PROB)p;
1359         }
1360
1361         /* Free the "r_info" array */
1362         C_KILL(elements, max_r_idx, tag_type);
1363         (void)init_object_alloc();
1364         return 0;
1365 }
1366
1367
1368 /*!
1369  * @brief 画面左下にシステムメッセージを表示する /
1370  * Hack -- take notes on line 23
1371  * @return なし
1372  */
1373 static void note(concptr str)
1374 {
1375         Term_erase(0, 23, 255);
1376         Term_putstr(20, 23, -1, TERM_WHITE, str);
1377         Term_fresh();
1378 }
1379
1380
1381 /*!
1382  * @brief 全ゲームデータ読み込みのサブルーチン /
1383  * Hack -- Explain a broken "lib" folder and quit (see below).
1384  * @return なし
1385  * @note
1386  * <pre>
1387  * This function is "messy" because various things
1388  * may or may not be initialized, but the "plog()" and "quit()"
1389  * functions are "supposed" to work under any conditions.
1390  * </pre>
1391  */
1392 static void init_angband_aux(concptr why)
1393 {
1394         plog(why);
1395
1396 #ifdef JP
1397         /* Explain */
1398         plog("'lib'ディレクトリが存在しないか壊れているようです。");
1399
1400         /* More details */
1401         plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
1402
1403         /* Explain */
1404         plog("該当する'README'ファイルを読んで確認してみて下さい。");
1405
1406         /* Quit with error */
1407         quit("致命的なエラー。");
1408 #else
1409         /* Explain */
1410         plog("The 'lib' directory is probably missing or broken.");
1411
1412         /* More details */
1413         plog("Perhaps the archive was not extracted correctly.");
1414
1415         /* Explain */
1416         plog("See the 'README' file for more information.");
1417
1418         /* Quit with error */
1419         quit("Fatal Error.");
1420 #endif
1421
1422 }
1423
1424
1425 /*!
1426  * @brief 全ゲームデータ読み込みのメインルーチン /
1427  * Hack -- main Angband initialization entry point
1428  * @return なし
1429  * @note
1430  * <pre>
1431  * This function is "messy" because various things
1432  * may or may not be initialized, but the "plog()" and "quit()"
1433  * functions are "supposed" to work under any conditions.
1434  * Verify some files, display the "news.txt" file, create
1435  * the high score file, initialize all internal arrays, and
1436  * load the basic "user pref files".
1437  * Be very careful to keep track of the order in which things
1438  * are initialized, in particular, the only thing *known* to
1439  * be available when this function is called is the "z-term.c"
1440  * package, and that may not be fully initialized until the
1441  * end of this function, when the default "user pref files"
1442  * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1443  * Note that this function attempts to verify the "news" file,
1444  * and the game aborts (cleanly) on failure, since without the
1445  * "news" file, it is likely that the "lib" folder has not been
1446  * correctly located.  Otherwise, the news file is displayed for
1447  * the user.
1448  * Note that this function attempts to verify (or create) the
1449  * "high score" file, and the game aborts (cleanly) on failure,
1450  * since one of the most common "extraction" failures involves
1451  * failing to extract all sub-directories (even empty ones), such
1452  * as by failing to use the "-d" option of "pkunzip", or failing
1453  * to use the "save empty directories" option with "Compact Pro".
1454  * This error will often be caught by the "high score" creation
1455  * code below, since the "lib/apex" directory, being empty in the
1456  * standard distributions, is most likely to be "lost", making it
1457  * impossible to create the high score file.
1458  * Note that various things are initialized by this function,
1459  * including everything that was once done by "init_some_arrays".
1460  * This initialization involves the parsing of special files
1461  * in the "lib/data" and sometimes the "lib/edit" directories.
1462  * Note that the "template" files are initialized first, since they
1463  * often contain errors.  This means that macros and message recall
1464  * and things like that are not available until after they are done.
1465  * We load the default "user pref files" here in case any "color"
1466  * changes are needed before character creation.
1467  * Note that the "graf-xxx.prf" file must be loaded separately,
1468  * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1469  * </pre>
1470  */
1471 void init_angband(player_type *player_ptr)
1472 {
1473         /*** Verify the "news" file ***/
1474         char buf[1024];
1475         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1476
1477         /* Attempt to open the file */
1478         int fd = fd_open(buf, O_RDONLY);
1479
1480         /* Failure */
1481         if (fd < 0)
1482         {
1483                 char why[1024];
1484
1485                 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
1486
1487                 /* Crash and burn */
1488                 init_angband_aux(why);
1489         }
1490
1491         (void)fd_close(fd);
1492
1493         /*** Display the "news" file ***/
1494         Term_clear();
1495         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
1496
1497         /* Open the News file */
1498         FILE *fp;
1499         fp = my_fopen(buf, "r");
1500
1501         /* Dump */
1502         if (fp)
1503         {
1504                 /* Dump the file to the screen */
1505                 int i = 0;
1506                 while (0 == my_fgets(fp, buf, sizeof(buf)))
1507                 {
1508                         /* Display and advance */
1509                         Term_putstr(0, i++, -1, TERM_WHITE, buf);
1510                 }
1511
1512                 my_fclose(fp);
1513         }
1514
1515         Term_flush();
1516
1517         /*** Verify (or create) the "high score" file ***/
1518         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
1519
1520         /* Attempt to open the high score file */
1521         fd = fd_open(buf, O_RDONLY);
1522
1523         BIT_FLAGS file_permission = 0664;
1524         if (fd < 0)
1525         {
1526                 /* File type is "DATA" */
1527                 FILE_TYPE(FILE_TYPE_DATA);
1528
1529                 /* Grab permissions */
1530                 safe_setuid_grab();
1531
1532                 /* Create a new high score file */
1533                 fd = fd_make(buf, file_permission);
1534
1535                 /* Drop permissions */
1536                 safe_setuid_drop();
1537
1538                 /* Failure */
1539                 if (fd < 0)
1540                 {
1541                         char why[1024];
1542
1543                         sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
1544
1545                         /* Crash and burn */
1546                         init_angband_aux(why);
1547                 }
1548         }
1549
1550         (void)fd_close(fd);
1551
1552         put_title();
1553
1554         /*** Initialize some arrays ***/
1555
1556         /* Initialize misc. values */
1557         note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
1558         if (init_misc(player_ptr)) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
1559
1560         /* Initialize feature info */
1561 #ifdef JP
1562         note("[データの初期化中... (地形)]");
1563         if (init_f_info()) quit("地形初期化不能");
1564         if (init_feat_variables()) quit("地形初期化不能");
1565 #else
1566         note("[Initializing arrays... (features)]");
1567         if (init_f_info()) quit("Cannot initialize features");
1568         if (init_feat_variables()) quit("Cannot initialize features");
1569 #endif
1570
1571         /* Initialize object info */
1572         note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
1573         if (init_k_info()) quit(_("アイテム初期化不能", "Cannot initialize objects"));
1574
1575         /* Initialize artifact info */
1576         note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
1577         if (init_a_info()) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
1578
1579
1580         /* Initialize ego-item info */
1581         note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
1582         if (init_e_info()) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
1583
1584
1585         /* Initialize monster info */
1586         note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
1587         if (init_r_info()) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
1588
1589
1590         /* Initialize dungeon info */
1591         note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
1592         if (init_d_info()) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
1593         {
1594                 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
1595                         if (d_info[i].final_guardian)
1596                                 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
1597         }
1598
1599         /* Initialize magic info */
1600         note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
1601         if (init_m_info()) quit(_("魔法初期化不能", "Cannot initialize magic"));
1602
1603         /* Initialize weapon_exp info */
1604         note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
1605         if (init_s_info()) quit(_("熟練度初期化不能", "Cannot initialize skill"));
1606
1607         /* Initialize wilderness array */
1608         note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
1609
1610         if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
1611
1612         /* Initialize town array */
1613         note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
1614         if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
1615
1616         /* Initialize building array */
1617         note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
1618         if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
1619
1620         /* Initialize quest array */
1621         note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
1622         if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
1623
1624         /* Initialize vault info */
1625         if (init_v_info()) quit(_("vault 初期化不能", "Cannot initialize vaults"));
1626
1627         /* Initialize some other arrays */
1628         note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
1629         if (init_other(player_ptr)) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
1630
1631         /* Initialize some other arrays */
1632         note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
1633         if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
1634
1635         /*** Load default user pref files ***/
1636
1637         /* Initialize feature info */
1638         note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
1639
1640         /* Access the "basic" pref file */
1641         strcpy(buf, "pref.prf");
1642
1643         /* Process that file */
1644         process_pref_file(player_ptr, buf);
1645
1646         /* Access the "basic" system pref file */
1647         sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
1648
1649         /* Process that file */
1650         process_pref_file(player_ptr, buf);
1651
1652         note(_("[初期化終了]", "[Initialization complete]"));
1653 }
1654
1655
1656 /*!
1657  * @brief タイトル記述
1658  * @return なし
1659  */
1660 static void put_title(void)
1661 {
1662         char title[120];
1663 #if H_VER_EXTRA > 0
1664         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,
1665 #else
1666         sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
1667 #endif
1668                 IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
1669         int col = (80 - strlen(title)) / 2;
1670         col = col < 0 ? 0 : col;
1671         prt(title, VER_INFO_ROW, col);
1672 }
1673
1674
1675 /*!
1676  * @brief サムチェック情報を出力 / Get check sum in string form
1677  * @return サムチェック情報の文字列
1678  */
1679 concptr get_check_sum(void)
1680 {
1681         return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1682                 f_head.v_extra,
1683                 k_head.v_extra,
1684                 a_head.v_extra,
1685                 e_head.v_extra,
1686                 r_head.v_extra,
1687                 d_head.v_extra,
1688                 m_head.v_extra,
1689                 s_head.v_extra,
1690                 v_head.v_extra);
1691 }