OSDN Git Service

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