OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / init2.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.  If you include the binary image
29  * files instead of the ascii template files, then you can undefine
30  * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c".  Note
31  * that the binary image files are extremely system dependant.
32  * </pre>
33  */
34
35 #include "angband.h"
36
37 #include "init.h"
38 #include "trap.h"
39
40 #ifndef MACINTOSH
41 #ifdef CHECK_MODIFICATION_TIME
42 #include <sys/types.h>
43 #include <sys/stat.h>
44 #endif /* CHECK_MODIFICATION_TIME */
45 #endif
46
47 static void put_title(void);
48
49 /*!
50  * @brief 各データファイルを読み取るためのパスを取得する
51  * Find the default paths to all of our important sub-directories.
52  * @param path パス保管先の文字列
53  * @return なし
54  * @details
55  * <pre>
56  * The purpose of each sub-directory is described in "variable.c".
57  * All of the sub-directories should, by default, be located inside
58  * the main "lib" directory, whose location is very system dependant.
59  * This function takes a writable buffer, initially containing the
60  * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
61  * or a system dependant string, for example, ":lib:".  The buffer
62  * must be large enough to contain at least 32 more characters.
63  * Various command line options may allow some of the important
64  * directories to be changed to user-specified directories, most
65  * importantly, the "info" and "user" and "save" directories,
66  * but this is done after this function, see "main.c".
67  * In general, the initial path should end in the appropriate "PATH_SEP"
68  * string.  All of the "sub-directory" paths (created below or supplied
69  * by the user) will NOT end in the "PATH_SEP" string, see the special
70  * "path_build()" function in "util.c" for more information.
71  * Mega-Hack -- support fat raw files under NEXTSTEP, using special
72  * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
73  * requiring the directories to be created by hand by the user.
74  * Hack -- first we free all the strings, since this is known
75  * to succeed even if the strings have not been allocated yet,
76  * as long as the variables start out as "NULL".  This allows
77  * this function to be called multiple times, for example, to
78  * try several base "path" values until a good one is found.
79  * </pre>
80  */
81 void init_file_paths(char *path)
82 {
83         char *tail;
84
85 #ifdef PRIVATE_USER_PATH
86         char buf[1024];
87 #endif /* PRIVATE_USER_PATH */
88
89         /*** Free everything ***/
90
91         /* Free the main path */
92         string_free(ANGBAND_DIR);
93
94         /* Free the sub-paths */
95         string_free(ANGBAND_DIR_APEX);
96         string_free(ANGBAND_DIR_BONE);
97         string_free(ANGBAND_DIR_DATA);
98         string_free(ANGBAND_DIR_EDIT);
99         string_free(ANGBAND_DIR_SCRIPT);
100         string_free(ANGBAND_DIR_FILE);
101         string_free(ANGBAND_DIR_HELP);
102         string_free(ANGBAND_DIR_INFO);
103         string_free(ANGBAND_DIR_SAVE);
104         string_free(ANGBAND_DIR_USER);
105         string_free(ANGBAND_DIR_XTRA);
106
107
108         /*** Prepare the "path" ***/
109
110         /* Hack -- save the main directory */
111         ANGBAND_DIR = string_make(path);
112
113         /* Prepare to append to the Base Path */
114         tail = path + strlen(path);
115
116         /*** Build the sub-directory names ***/
117
118         /* Build a path name */
119         strcpy(tail, "apex");
120         ANGBAND_DIR_APEX = string_make(path);
121
122         /* Build a path name */
123         strcpy(tail, "bone");
124         ANGBAND_DIR_BONE = string_make(path);
125
126         /* Build a path name */
127         strcpy(tail, "data");
128         ANGBAND_DIR_DATA = string_make(path);
129
130         /* Build a path name */
131         strcpy(tail, "edit");
132         ANGBAND_DIR_EDIT = string_make(path);
133
134         /* Build a path name */
135         strcpy(tail, "script");
136         ANGBAND_DIR_SCRIPT = string_make(path);
137
138         /* Build a path name */
139         strcpy(tail, "file");
140         ANGBAND_DIR_FILE = string_make(path);
141
142         /* Build a path name */
143         strcpy(tail, "help");
144         ANGBAND_DIR_HELP = string_make(path);
145
146         /* Build a path name */
147         strcpy(tail, "info");
148         ANGBAND_DIR_INFO = string_make(path);
149
150         /* Build a path name */
151         strcpy(tail, "pref");
152         ANGBAND_DIR_PREF = string_make(path);
153
154         /* Build a path name */
155         strcpy(tail, "save");
156         ANGBAND_DIR_SAVE = string_make(path);
157
158 #ifdef PRIVATE_USER_PATH
159
160         /* Build the path to the user specific directory */
161         path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
162
163         /* Build a relative path name */
164         ANGBAND_DIR_USER = string_make(buf);
165
166 #else /* PRIVATE_USER_PATH */
167
168         /* Build a path name */
169         strcpy(tail, "user");
170         ANGBAND_DIR_USER = string_make(path);
171
172 #endif /* PRIVATE_USER_PATH */
173
174         /* Build a path name */
175         strcpy(tail, "xtra");
176         ANGBAND_DIR_XTRA = string_make(path);
177
178
179 #ifdef NeXT
180
181         /* Allow "fat binary" usage with NeXT */
182         if (TRUE)
183         {
184                 cptr next = NULL;
185
186 # if defined(m68k)
187                 next = "m68k";
188 # endif
189
190 # if defined(i386)
191                 next = "i386";
192 # endif
193
194 # if defined(sparc)
195                 next = "sparc";
196 # endif
197
198 # if defined(hppa)
199                 next = "hppa";
200 # endif
201
202                 /* Use special directory */
203                 if (next)
204                 {
205                         /* Forget the old path name */
206                         string_free(ANGBAND_DIR_DATA);
207
208                         /* Build a new path name */
209                         sprintf(tail, "data-%s", next);
210                         ANGBAND_DIR_DATA = string_make(path);
211                 }
212         }
213
214 #endif /* NeXT */
215
216 }
217
218
219
220 #ifdef ALLOW_TEMPLATES
221
222
223 /*
224  * Hack -- help give useful error messages
225  */
226 int error_idx; /*!< データ読み込み/初期化時に汎用的にエラーコードを保存するグローバル変数 */
227 int error_line; /*!< データ読み込み/初期化時に汎用的にエラー行数を保存するグローバル変数 */
228
229
230 /*!
231  * エラーメッセージの名称定義 / Standard error message text
232  */
233 cptr err_str[PARSE_ERROR_MAX] =
234 {
235         NULL,
236 #ifdef JP
237         "文法エラー",
238         "古いファイル",
239         "記録ヘッダがない",
240         "不連続レコード",
241         "おかしなフラグ存在",
242         "未定義命令",
243         "メモリ不足",
244         "座標範囲外",
245         "引数不足",
246         "未定義地形タグ",
247 #else
248         "parse error",
249         "obsolete file",
250         "missing record header",
251         "non-sequential records",
252         "invalid flag specification",
253         "undefined directive",
254         "out of memory",
255         "coordinates out of bounds",
256         "too few arguments",
257         "undefined terrain tag",
258 #endif
259
260 };
261
262
263 #endif /* ALLOW_TEMPLATES */
264
265
266 /*
267  * File headers
268  */
269 header v_head; /*!< Vault情報のヘッダ構造体 */
270 header f_head; /*!< 地形情報のヘッダ構造体 */
271 header k_head; /*!< ペースアイテム情報のヘッダ構造体 */
272 header a_head; /*!< 固定アーティファクト情報のヘッダ構造体 */
273 header e_head; /*!< アイテムエゴ情報のヘッダ構造体 */
274 header r_head; /*!< モンスター種族情報のヘッダ構造体 */
275 header d_head; /*!< ダンジョン情報のヘッダ構造体 */
276 header s_head; /*!< プレイヤー職業技能情報のヘッダ構造体 */
277 header m_head; /*!< プレイヤー職業魔法情報のヘッダ構造体 */
278
279 #ifdef CHECK_MODIFICATION_TIME
280
281 /*!
282  * @brief テキストファイルとrawファイルの更新時刻を比較する
283  * Find the default paths to all of our important sub-directories.
284  * @param fd ファイルディスクリプタ
285  * @param template_file ファイル名
286  * @return テキストの方が新しいか、rawファイルがなく更新の必要がある場合-1、更新の必要がない場合0。
287  */
288 static errr check_modification_date(int fd, cptr template_file)
289 {
290         char buf[1024];
291
292         struct stat txt_stat, raw_stat;
293
294         /* Build the filename */
295         path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
296
297         /* Access stats on text file */
298         if (stat(buf, &txt_stat))
299         {
300                 /* No text file - continue */
301         }
302
303         /* Access stats on raw file */
304         else if (fstat(fd, &raw_stat))
305         {
306                 /* Error */
307                 return (-1);
308         }
309
310         /* Ensure text file is not newer than raw file */
311         else if (txt_stat.st_mtime > raw_stat.st_mtime)
312         {
313                 /* Reprocess text file */
314                 return (-1);
315         }
316
317         return (0);
318 }
319
320 #endif /* CHECK_MODIFICATION_TIME */
321
322
323
324 /*** Initialize from binary image files ***/
325
326
327 /*!
328  * @brief rawファイルからのデータの読み取り処理
329  * Initialize the "*_info" array, by parsing a binary "image" file
330  * @param fd ファイルディスクリプタ
331  * @param head rawファイルのヘッダ
332  * @return エラーコード
333  */
334 static errr init_info_raw(int fd, header *head)
335 {
336         header test;
337
338         /* Read and Verify the header */
339         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
340             (test.v_major != head->v_major) ||
341             (test.v_minor != head->v_minor) ||
342             (test.v_patch != head->v_patch) ||
343             (test.info_num != head->info_num) ||
344             (test.info_len != head->info_len) ||
345             (test.head_size != head->head_size) ||
346             (test.info_size != head->info_size))
347         {
348                 /* Error */
349                 return (-1);
350         }
351
352
353         /* Accept the header */
354         (*head) = test;
355
356
357         /* Allocate the "*_info" array */
358         C_MAKE(head->info_ptr, head->info_size, char);
359
360         /* Read the "*_info" array */
361         fd_read(fd, head->info_ptr, head->info_size);
362
363
364         if (head->name_size)
365         {
366                 /* Allocate the "*_name" array */
367                 C_MAKE(head->name_ptr, head->name_size, char);
368
369                 /* Read the "*_name" array */
370                 fd_read(fd, head->name_ptr, head->name_size);
371         }
372
373
374         if (head->text_size)
375         {
376                 /* Allocate the "*_text" array */
377                 C_MAKE(head->text_ptr, head->text_size, char);
378
379                 /* Read the "*_text" array */
380                 fd_read(fd, head->text_ptr, head->text_size);
381         }
382
383
384         if (head->tag_size)
385         {
386                 /* Allocate the "*_tag" array */
387                 C_MAKE(head->tag_ptr, head->tag_size, char);
388
389                 /* Read the "*_tag" array */
390                 fd_read(fd, head->tag_ptr, head->tag_size);
391         }
392
393
394         /* Success */
395         return (0);
396 }
397
398
399
400 /*!
401  * @brief ヘッダ構造体の更新
402  * Initialize the header of an *_info.raw file.
403  * @param head rawファイルのヘッダ
404  * @param num データ数
405  * @param len データの長さ
406  * @return エラーコード
407  */
408 static void init_header(header *head, IDX num, int len)
409 {
410         /* Save the "version" */
411         head->v_major = FAKE_VER_MAJOR;
412         head->v_minor = FAKE_VER_MINOR;
413         head->v_patch = FAKE_VER_PATCH;
414         head->v_extra = 0;
415
416         /* Save the "record" information */
417         head->info_num = (IDX)num;
418         head->info_len = len;
419
420         /* Save the size of "*_head" and "*_info" */
421         head->head_size = sizeof(header);
422         head->info_size = head->info_num * head->info_len;
423 }
424
425
426 /*!
427  * @brief ヘッダ構造体の更新
428  * Initialize the "*_info" array
429  * @param filename ファイル名(拡張子txt/raw)
430  * @param head 処理に用いるヘッダ構造体
431  * @param info データ保管先の構造体ポインタ
432  * @param name 名称用可変文字列の保管先
433  * @param text テキスト用可変文字列の保管先
434  * @param tag タグ用可変文字列の保管先
435  * @return エラーコード
436  * @note
437  * Note that we let each entry have a unique "name" and "text" string,
438  * even if the string happens to be empty (everyone has a unique '\0').
439  */
440 static errr init_info(cptr filename, header *head,
441                       void **info, char **name, char **text, char **tag)
442 {
443         int fd;
444
445         BIT_FLAGS mode = 0644;
446
447         errr err = 1;
448
449         FILE *fp;
450
451         /* General buffer */
452         char buf[1024];
453
454
455 #ifdef ALLOW_TEMPLATES
456
457         /*** Load the binary image file ***/
458
459         /* Build the filename */
460         path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
461
462
463         /* Attempt to open the "raw" file */
464         fd = fd_open(buf, O_RDONLY);
465
466         /* Process existing "raw" file */
467         if (fd >= 0)
468         {
469 #ifdef CHECK_MODIFICATION_TIME
470
471                 err = check_modification_date(fd, format("%s.txt", filename));
472
473 #endif /* CHECK_MODIFICATION_TIME */
474
475                 /* Attempt to parse the "raw" file */
476                 if (!err)
477                         err = init_info_raw(fd, head);
478
479                 /* Close it */
480                 (void)fd_close(fd);
481         }
482
483
484         /* Do we have to parse the *.txt file? */
485         if (err)
486         {
487                 /*** Make the fake arrays ***/
488
489                 /* Allocate the "*_info" array */
490                 C_MAKE(head->info_ptr, head->info_size, char);
491
492                 /* Hack -- make "fake" arrays */
493                 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
494                 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
495                 if (tag)  C_MAKE(head->tag_ptr, FAKE_TAG_SIZE, char);
496
497                 if (info) (*info) = head->info_ptr;
498                 if (name) (*name) = head->name_ptr;
499                 if (text) (*text) = head->text_ptr;
500                 if (tag)  (*tag)  = head->tag_ptr;
501
502                 /*** Load the ascii template file ***/
503
504                 /* Build the filename */
505
506                 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
507
508                 /* Open the file */
509                 fp = my_fopen(buf, "r");
510
511                 /* Parse it */
512                 if (!fp) quit(format(_("'%s.txt'ファイルをオープンできません。", "Cannot open '%s.txt' file."), filename));
513
514                 /* Parse the file */
515                 err = init_info_txt(fp, buf, head, head->parse_info_txt);
516
517                 /* Close it */
518                 my_fclose(fp);
519
520                 /* Errors */
521                 if (err)
522                 {
523                         cptr oops;
524
525 #ifdef JP
526                         /* Error string */
527                         oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "未知の");
528
529                         /* Oops */
530                         msg_format("'%s.txt'ファイルの %d 行目にエラー。", filename, error_line);
531                         msg_format("レコード %d は '%s' エラーがあります。", error_idx, oops);
532                         msg_format("構文 '%s'。", buf);
533                         msg_print(NULL);
534
535                         /* Quit */
536                         quit(format("'%s.txt'ファイルにエラー", filename));
537 #else
538                         /* Error string */
539                         oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
540
541                         /* Oops */
542                         msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
543                         msg_format("Record %d contains a '%s' error.", error_idx, oops);
544                         msg_format("Parsing '%s'.", buf);
545                         msg_print(NULL);
546
547                         /* Quit */
548                         quit(format("Error in '%s.txt' file.", filename));
549 #endif
550
551                 }
552
553
554                 /*** Make final retouch on fake tags ***/
555
556                 if (head->retouch)
557                 {
558                         (*head->retouch)(head);
559                 }
560
561
562                 /*** Dump the binary image file ***/
563
564                 /* File type is "DATA" */
565                 FILE_TYPE(FILE_TYPE_DATA);
566
567                 /* Build the filename */
568                 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
569
570
571                 /* Grab permissions */
572                 safe_setuid_grab();
573
574                 /* Kill the old file */
575                 (void)fd_kill(buf);
576
577                 /* Attempt to create the raw file */
578                 fd = fd_make(buf, mode);
579
580                 /* Drop permissions */
581                 safe_setuid_drop();
582
583                 /* Dump to the file */
584                 if (fd >= 0)
585                 {
586                         /* Dump it */
587                         fd_write(fd, (cptr)(head), head->head_size);
588
589                         /* Dump the "*_info" array */
590                         fd_write(fd, head->info_ptr, head->info_size);
591
592                         /* Dump the "*_name" array */
593                         fd_write(fd, head->name_ptr, head->name_size);
594
595                         /* Dump the "*_text" array */
596                         fd_write(fd, head->text_ptr, head->text_size);
597
598                         /* Dump the "*_tag" array */
599                         fd_write(fd, head->tag_ptr, head->tag_size);
600
601                         /* Close */
602                         (void)fd_close(fd);
603                 }
604
605
606                 /*** Kill the fake arrays ***/
607
608                 /* Free the "*_info" array */
609                 C_KILL(head->info_ptr, head->info_size, char);
610
611                 /* Hack -- Free the "fake" arrays */
612                 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
613                 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
614                 if (tag)  C_KILL(head->tag_ptr, FAKE_TAG_SIZE, char);
615
616 #endif  /* ALLOW_TEMPLATES */
617
618
619                 /*** Load the binary image file ***/
620
621                 /* Build the filename */
622                 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format(_("%s_j.raw", "%s.raw"), filename));
623
624                 /* Attempt to open the "raw" file */
625                 fd = fd_open(buf, O_RDONLY);
626
627                 /* Process existing "raw" file */
628                 if (fd < 0) quit(format(_("'%s_j.raw'ファイルをロードできません。", "Cannot load '%s.raw' file."), filename));
629
630                 /* Attempt to parse the "raw" file */
631                 err = init_info_raw(fd, head);
632
633                 /* Close it */
634                 (void)fd_close(fd);
635
636                 /* Error */
637                 if (err) quit(format(_("'%s_j.raw'ファイルを解析できません。", "Cannot parse '%s.raw' file."), filename));
638
639 #ifdef ALLOW_TEMPLATES
640         }
641 #endif
642
643         if (info) (*info) = head->info_ptr;
644         if (name) (*name) = head->name_ptr;
645         if (text) (*text) = head->text_ptr;
646         if (tag)  (*tag)  = head->tag_ptr;
647
648         /* Success */
649         return (0);
650 }
651
652
653 /*!
654  * @brief 地形情報読み込みのメインルーチン /
655  * Initialize the "f_info" array
656  * @return エラーコード
657  */
658 static errr init_f_info(void)
659 {
660         /* Init the header */
661         init_header(&f_head, max_f_idx, sizeof(feature_type));
662
663 #ifdef ALLOW_TEMPLATES
664
665         /* Save a pointer to the parsing function */
666         f_head.parse_info_txt = parse_f_info;
667
668         /* Save a pointer to the retouch fake tags */
669         f_head.retouch = retouch_f_info;
670
671 #endif /* ALLOW_TEMPLATES */
672
673         return init_info("f_info", &f_head,
674                          (void*)&f_info, &f_name, NULL, &f_tag);
675 }
676
677
678 /*!
679  * @brief ベースアイテム情報読み込みのメインルーチン /
680  * Initialize the "k_info" array
681  * @return エラーコード
682  */
683 static errr init_k_info(void)
684 {
685         /* Init the header */
686         init_header(&k_head, max_k_idx, sizeof(object_kind));
687
688 #ifdef ALLOW_TEMPLATES
689
690         /* Save a pointer to the parsing function */
691         k_head.parse_info_txt = parse_k_info;
692
693 #endif /* ALLOW_TEMPLATES */
694
695         return init_info("k_info", &k_head,
696                          (void*)&k_info, &k_name, &k_text, NULL);
697 }
698
699
700
701 /*!
702  * @brief 固定アーティファクト情報読み込みのメインルーチン /
703  * Initialize the "a_info" array
704  * @return エラーコード
705  */
706 static errr init_a_info(void)
707 {
708         /* Init the header */
709         init_header(&a_head, max_a_idx, sizeof(artifact_type));
710
711 #ifdef ALLOW_TEMPLATES
712
713         /* Save a pointer to the parsing function */
714         a_head.parse_info_txt = parse_a_info;
715
716 #endif /* ALLOW_TEMPLATES */
717
718         return init_info("a_info", &a_head,
719                          (void*)&a_info, &a_name, &a_text, NULL);
720 }
721
722
723
724 /*!
725  * @brief 固定アーティファクト情報読み込みのメインルーチン /
726  * Initialize the "e_info" array
727  * @return エラーコード
728  */
729 static errr init_e_info(void)
730 {
731         /* Init the header */
732         init_header(&e_head, max_e_idx, sizeof(ego_item_type));
733
734 #ifdef ALLOW_TEMPLATES
735
736         /* Save a pointer to the parsing function */
737         e_head.parse_info_txt = parse_e_info;
738
739 #endif /* ALLOW_TEMPLATES */
740
741         return init_info("e_info", &e_head,
742                          (void*)&e_info, &e_name, &e_text, NULL);
743 }
744
745
746
747 /*!
748  * @brief モンスター種族情報読み込みのメインルーチン /
749  * Initialize the "r_info" array
750  * @return エラーコード
751  */
752 static errr init_r_info(void)
753 {
754         /* Init the header */
755         init_header(&r_head, max_r_idx, sizeof(monster_race));
756
757 #ifdef ALLOW_TEMPLATES
758
759         /* Save a pointer to the parsing function */
760         r_head.parse_info_txt = parse_r_info;
761
762 #endif /* ALLOW_TEMPLATES */
763
764         return init_info("r_info", &r_head,
765                          (void*)&r_info, &r_name, &r_text, NULL);
766 }
767
768
769
770 /*!
771  * @brief ダンジョン情報読み込みのメインルーチン /
772  * Initialize the "d_info" array
773  * @return エラーコード
774  */
775 static errr init_d_info(void)
776 {
777         /* Init the header */
778         init_header(&d_head, max_d_idx, sizeof(dungeon_info_type));
779
780 #ifdef ALLOW_TEMPLATES
781
782         /* Save a pointer to the parsing function */
783         d_head.parse_info_txt = parse_d_info;
784
785 #endif /* ALLOW_TEMPLATES */
786
787         return init_info("d_info", &d_head,
788                          (void*)&d_info, &d_name, &d_text, NULL);
789 }
790
791
792 /*!
793  * @brief Vault情報読み込みのメインルーチン /
794  * Initialize the "v_info" array
795  * @return エラーコード
796  * @note
797  * Note that we let each entry have a unique "name" and "text" string,
798  * even if the string happens to be empty (everyone has a unique '\0').
799  */
800 errr init_v_info(void)
801 {
802         /* Init the header */
803         init_header(&v_head, max_v_idx, sizeof(vault_type));
804
805 #ifdef ALLOW_TEMPLATES
806
807         /* Save a pointer to the parsing function */
808         v_head.parse_info_txt = parse_v_info;
809
810 #endif /* ALLOW_TEMPLATES */
811
812         return init_info("v_info", &v_head,
813                          (void*)&v_info, &v_name, &v_text, NULL);
814 }
815
816
817 /*!
818  * @brief 職業技能情報読み込みのメインルーチン /
819  * Initialize the "s_info" array
820  * @return エラーコード
821  */
822 static errr init_s_info(void)
823 {
824         /* Init the header */
825         init_header(&s_head, MAX_CLASS, sizeof(skill_table));
826
827 #ifdef ALLOW_TEMPLATES
828
829         /* Save a pointer to the parsing function */
830         s_head.parse_info_txt = parse_s_info;
831
832 #endif /* ALLOW_TEMPLATES */
833
834         return init_info("s_info", &s_head,
835                          (void*)&s_info, NULL, NULL, NULL);
836 }
837
838
839 /*!
840  * @brief 職業魔法情報読み込みのメインルーチン /
841  * Initialize the "m_info" array
842  * @return エラーコード
843  */
844 static errr init_m_info(void)
845 {
846         /* Init the header */
847         init_header(&m_head, MAX_CLASS, sizeof(player_magic));
848
849 #ifdef ALLOW_TEMPLATES
850
851         /* Save a pointer to the parsing function */
852         m_head.parse_info_txt = parse_m_info;
853
854 #endif /* ALLOW_TEMPLATES */
855
856         return init_info("m_info", &m_head,
857                          (void*)&m_info, NULL, NULL, NULL);
858 }
859
860
861
862 /*** Initialize others ***/
863
864 /*!
865  * 店舗で販売するオブジェクトを定義する / Hack -- Objects sold in the stores -- by tval/sval pair.
866  */
867 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
868 {
869         {
870                 /* General Store */
871
872                 { TV_FOOD, SV_FOOD_RATION },
873                 { TV_FOOD, SV_FOOD_RATION },
874                 { TV_FOOD, SV_FOOD_RATION },
875                 { TV_FOOD, SV_FOOD_RATION },
876
877                 { TV_FOOD, SV_FOOD_RATION },
878                 { TV_FOOD, SV_FOOD_BISCUIT },
879                 { TV_FOOD, SV_FOOD_JERKY },
880                 { TV_FOOD, SV_FOOD_JERKY },
881
882                 { TV_FOOD, SV_FOOD_PINT_OF_WINE },
883                 { TV_FOOD, SV_FOOD_PINT_OF_ALE },
884                 { TV_LITE, SV_LITE_TORCH },
885                 { TV_LITE, SV_LITE_TORCH },
886
887                 { TV_LITE, SV_LITE_TORCH },
888                 { TV_LITE, SV_LITE_TORCH },
889                 { TV_LITE, SV_LITE_LANTERN },
890                 { TV_LITE, SV_LITE_LANTERN },
891
892                 { TV_FLASK, 0 },
893                 { TV_FLASK, 0 },
894                 { TV_FLASK, 0 },
895                 { TV_FLASK, 0 },
896
897                 { TV_FLASK, 0 },
898                 { TV_FLASK, 0 },
899                 { TV_SPIKE, 0 },
900                 { TV_SPIKE, 0 },
901
902                 { TV_SHOT, SV_AMMO_NORMAL },
903                 { TV_ARROW, SV_AMMO_NORMAL },
904                 { TV_BOLT, SV_AMMO_NORMAL },
905                 { TV_DIGGING, SV_SHOVEL },
906
907                 { TV_DIGGING, SV_PICK },
908                 { TV_CLOAK, SV_CLOAK },
909                 { TV_CLOAK, SV_CLOAK },
910                 { TV_CLOAK, SV_FUR_CLOAK },
911
912                 { TV_FOOD, SV_FOOD_RATION },
913                 { TV_FOOD, SV_FOOD_RATION },
914                 { TV_FOOD, SV_FOOD_RATION },
915                 { TV_FOOD, SV_FOOD_RATION },
916
917                 { TV_POTION, SV_POTION_WATER },
918                 { TV_POTION, SV_POTION_WATER },
919                 { TV_LITE, SV_LITE_LANTERN },
920                 { TV_LITE, SV_LITE_LANTERN },
921
922                 { TV_FOOD, SV_FOOD_WAYBREAD },
923                 { TV_FOOD, SV_FOOD_WAYBREAD },
924                 { TV_CAPTURE, 0 },
925                 { TV_FIGURINE, 0 },
926
927                 { TV_SHOT, SV_AMMO_NORMAL },
928                 { TV_ARROW, SV_AMMO_NORMAL },
929                 { TV_BOLT, SV_AMMO_NORMAL },
930                 { TV_DIGGING, SV_SHOVEL }
931         },
932
933         {
934                 /* Armoury */
935
936                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
937                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
938                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
939                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
940
941                 { TV_HELM, SV_HARD_LEATHER_CAP },
942                 { TV_HELM, SV_HARD_LEATHER_CAP },
943                 { TV_HELM, SV_METAL_CAP },
944                 { TV_HELM, SV_IRON_HELM },
945
946                 { TV_SOFT_ARMOR, SV_ROBE },
947                 { TV_SOFT_ARMOR, SV_ROBE },
948                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
949                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
950
951                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
952                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
953                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
954                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
955
956                 { TV_SOFT_ARMOR, SV_RHINO_HIDE_ARMOR },
957                 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
958                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
959                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
960
961                 { TV_HARD_ARMOR, SV_DOUBLE_RING_MAIL },
962                 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
963                 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL },
964                 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL },
965
966                 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR },
967                 { TV_HARD_ARMOR, SV_SPLINT_MAIL },
968                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
969                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
970
971                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
972                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
973                 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD },
974                 { TV_SHIELD, SV_SMALL_METAL_SHIELD },
975
976                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
977                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
978                 { TV_HELM, SV_HARD_LEATHER_CAP },
979                 { TV_HELM, SV_HARD_LEATHER_CAP },
980
981                 { TV_SOFT_ARMOR, SV_ROBE },
982                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
983                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
984                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
985
986                 { TV_SOFT_ARMOR, SV_LEATHER_JACK },
987                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
988                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
989                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
990
991                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
992                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
993                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
994                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }
995         },
996
997         {
998                 /* Weaponsmith */
999
1000                 { TV_SWORD, SV_DAGGER },
1001                 { TV_SWORD, SV_MAIN_GAUCHE },
1002                 { TV_SWORD, SV_RAPIER },
1003                 { TV_SWORD, SV_SMALL_SWORD },
1004
1005                 { TV_SWORD, SV_SHORT_SWORD },
1006                 { TV_SWORD, SV_SABRE },
1007                 { TV_SWORD, SV_CUTLASS },
1008                 { TV_SWORD, SV_TULWAR },
1009
1010                 { TV_SWORD, SV_BROAD_SWORD },
1011                 { TV_SWORD, SV_LONG_SWORD },
1012                 { TV_SWORD, SV_SCIMITAR },
1013                 { TV_SWORD, SV_KATANA },
1014
1015                 { TV_SWORD, SV_BASTARD_SWORD },
1016                 { TV_POLEARM, SV_SPEAR },
1017                 { TV_POLEARM, SV_AWL_PIKE },
1018                 { TV_POLEARM, SV_TRIDENT },
1019
1020                 { TV_POLEARM, SV_PIKE },
1021                 { TV_POLEARM, SV_BEAKED_AXE },
1022                 { TV_POLEARM, SV_BROAD_AXE },
1023                 { TV_POLEARM, SV_LANCE },
1024
1025                 { TV_POLEARM, SV_BATTLE_AXE },
1026                 { TV_POLEARM, SV_HATCHET },
1027                 { TV_BOW, SV_SLING },
1028                 { TV_BOW, SV_SHORT_BOW },
1029
1030                 { TV_BOW, SV_LIGHT_XBOW },
1031                 { TV_SHOT, SV_AMMO_NORMAL },
1032                 { TV_SHOT, SV_AMMO_NORMAL },
1033                 { TV_ARROW, SV_AMMO_NORMAL },
1034
1035                 { TV_ARROW, SV_AMMO_NORMAL },
1036                 { TV_BOLT, SV_AMMO_NORMAL },
1037                 { TV_BOLT, SV_AMMO_NORMAL },
1038                 { TV_BOW, SV_LIGHT_XBOW },
1039
1040                 { TV_ARROW, SV_AMMO_NORMAL },
1041                 { TV_BOLT, SV_AMMO_NORMAL },
1042                 { TV_BOW, SV_SHORT_BOW },
1043                 { TV_BOW, SV_LIGHT_XBOW },
1044
1045                 { TV_SWORD, SV_DAGGER },
1046                 { TV_SWORD, SV_TANTO },
1047                 { TV_SWORD, SV_RAPIER },
1048                 { TV_SWORD, SV_SMALL_SWORD },
1049
1050                 { TV_SWORD, SV_SHORT_SWORD },
1051                 { TV_SWORD, SV_LONG_SWORD },
1052                 { TV_SWORD, SV_SCIMITAR },
1053                 { TV_SWORD, SV_BROAD_SWORD },
1054
1055                 { TV_HISSATSU_BOOK, 0 },
1056                 { TV_HISSATSU_BOOK, 0 },
1057                 { TV_HISSATSU_BOOK, 1 },
1058                 { TV_HISSATSU_BOOK, 1 },
1059         },
1060
1061         {
1062                 /* Temple */
1063
1064                 { TV_HAFTED, SV_NUNCHAKU },
1065                 { TV_HAFTED, SV_QUARTERSTAFF },
1066                 { TV_HAFTED, SV_MACE },
1067                 { TV_HAFTED, SV_BO_STAFF },
1068
1069                 { TV_HAFTED, SV_WAR_HAMMER },
1070                 { TV_HAFTED, SV_WAR_HAMMER },
1071                 { TV_HAFTED, SV_MORNING_STAR },
1072                 { TV_HAFTED, SV_FLAIL },
1073
1074                 { TV_HAFTED, SV_LEAD_FILLED_MACE },
1075                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1076                 { TV_SCROLL, SV_SCROLL_BLESSING },
1077                 { TV_SCROLL, SV_SCROLL_HOLY_CHANT },
1078
1079                 { TV_POTION, SV_POTION_HEROISM },
1080                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1081                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1082                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1083
1084                 { TV_POTION, SV_POTION_CURE_LIGHT },
1085                 { TV_POTION, SV_POTION_CURE_SERIOUS },
1086                 { TV_POTION, SV_POTION_CURE_SERIOUS },
1087                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1088
1089                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1090                 { TV_POTION, SV_POTION_RESTORE_EXP },
1091                 { TV_POTION, SV_POTION_RESTORE_EXP },
1092                 { TV_POTION, SV_POTION_RESTORE_EXP },
1093
1094                 { TV_LIFE_BOOK, 0 },
1095                 { TV_LIFE_BOOK, 0 },
1096                 { TV_LIFE_BOOK, 1 },
1097                 { TV_LIFE_BOOK, 1 },
1098
1099                 { TV_CRUSADE_BOOK, 0 },
1100                 { TV_CRUSADE_BOOK, 0 },
1101                 { TV_CRUSADE_BOOK, 1 },
1102                 { TV_CRUSADE_BOOK, 1 },
1103
1104                 { TV_HAFTED, SV_WHIP },
1105                 { TV_HAFTED, SV_MACE },
1106                 { TV_HAFTED, SV_BALL_AND_CHAIN },
1107                 { TV_HAFTED, SV_WAR_HAMMER },
1108
1109                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1110                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1111                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1112                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1113
1114                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1115                 { TV_POTION, SV_POTION_RESTORE_EXP },
1116
1117                 { TV_FIGURINE, 0 },
1118                 { TV_STATUE, SV_ANY },
1119
1120                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1121                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1122                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE },
1123                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE }
1124         },
1125
1126         {
1127                 /* Alchemy shop */
1128
1129                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1130                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1131                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1132                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1133
1134                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1135                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1136                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1137                 { TV_SCROLL, SV_SCROLL_LIGHT },
1138
1139                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1140                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1141                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1142                 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION },
1143
1144                 { TV_SCROLL, SV_SCROLL_MAPPING },
1145                 { TV_SCROLL, SV_SCROLL_DETECT_GOLD },
1146                 { TV_SCROLL, SV_SCROLL_DETECT_ITEM },
1147                 { TV_SCROLL, SV_SCROLL_DETECT_TRAP },
1148
1149                 { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
1150                 { TV_SCROLL, SV_SCROLL_RECHARGING },
1151                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1152                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1153
1154                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1155                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1156                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1157                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1158
1159                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1160                 { TV_POTION, SV_POTION_RES_STR },
1161                 { TV_POTION, SV_POTION_RES_INT },
1162                 { TV_POTION, SV_POTION_RES_WIS },
1163
1164                 { TV_POTION, SV_POTION_RES_DEX },
1165                 { TV_POTION, SV_POTION_RES_CON },
1166                 { TV_POTION, SV_POTION_RES_CHR },
1167                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1168
1169                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1170                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },  /* Yep, occasionally! */
1171                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },
1172                 { TV_SCROLL, SV_SCROLL_LIGHT },
1173
1174                 { TV_POTION, SV_POTION_RES_STR },
1175                 { TV_POTION, SV_POTION_RES_INT },
1176                 { TV_POTION, SV_POTION_RES_WIS },
1177                 { TV_POTION, SV_POTION_RES_DEX },
1178
1179                 { TV_POTION, SV_POTION_RES_CON },
1180                 { TV_POTION, SV_POTION_RES_CHR },
1181                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1182                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1183
1184                 { TV_SCROLL, SV_SCROLL_RECHARGING },
1185                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1186                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1187                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1188
1189         },
1190
1191         {
1192                 /* Magic-User store */
1193
1194                 { TV_RING, SV_RING_PROTECTION },
1195                 { TV_RING, SV_RING_LEVITATION_FALL },
1196                 { TV_RING, SV_RING_PROTECTION },
1197                 { TV_RING, SV_RING_RESIST_FIRE },
1198
1199                 { TV_RING, SV_RING_RESIST_COLD },
1200                 { TV_AMULET, SV_AMULET_CHARISMA },
1201                 { TV_RING, SV_RING_WARNING },
1202                 { TV_AMULET, SV_AMULET_RESIST_ACID },
1203
1204                 { TV_AMULET, SV_AMULET_SEARCHING },
1205                 { TV_WAND, SV_WAND_SLOW_MONSTER },
1206                 { TV_WAND, SV_WAND_CONFUSE_MONSTER },
1207                 { TV_WAND, SV_WAND_SLEEP_MONSTER },
1208
1209                 { TV_WAND, SV_WAND_MAGIC_MISSILE },
1210                 { TV_WAND, SV_WAND_STINKING_CLOUD },
1211                 { TV_WAND, SV_WAND_WONDER },
1212                 { TV_WAND, SV_WAND_DISARMING },
1213
1214                 { TV_STAFF, SV_STAFF_LITE },
1215                 { TV_STAFF, SV_STAFF_MAPPING },
1216                 { TV_STAFF, SV_STAFF_DETECT_TRAP },
1217                 { TV_STAFF, SV_STAFF_DETECT_DOOR },
1218
1219                 { TV_STAFF, SV_STAFF_DETECT_GOLD },
1220                 { TV_STAFF, SV_STAFF_DETECT_ITEM },
1221                 { TV_STAFF, SV_STAFF_DETECT_INVIS },
1222                 { TV_STAFF, SV_STAFF_DETECT_EVIL },
1223
1224                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1225                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1226                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1227                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1228
1229                 { TV_STAFF, SV_STAFF_IDENTIFY },
1230                 { TV_STAFF, SV_STAFF_IDENTIFY },
1231                 { TV_STAFF, SV_STAFF_IDENTIFY },
1232
1233                 { TV_STAFF, SV_STAFF_IDENTIFY },
1234                 { TV_STAFF, SV_STAFF_REMOVE_CURSE },
1235                 { TV_STAFF, SV_STAFF_CURE_LIGHT },
1236                 { TV_STAFF, SV_STAFF_PROBING },
1237
1238                 { TV_FIGURINE, 0 },
1239
1240                 { TV_SORCERY_BOOK, 0 },
1241                 { TV_SORCERY_BOOK, 0 },
1242                 { TV_SORCERY_BOOK, 1 },
1243                 { TV_SORCERY_BOOK, 1 },
1244
1245                 { TV_ARCANE_BOOK, 0 },
1246                 { TV_ARCANE_BOOK, 0 },
1247                 { TV_ARCANE_BOOK, 1 },
1248                 { TV_ARCANE_BOOK, 1 },
1249
1250                 { TV_ARCANE_BOOK, 2 },
1251                 { TV_ARCANE_BOOK, 2 },
1252                 { TV_ARCANE_BOOK, 3 },
1253                 { TV_ARCANE_BOOK, 3 },
1254
1255         },
1256
1257         {
1258                 /* Black Market (unused) */
1259                 { 0, 0 },
1260                 { 0, 0 },
1261                 { 0, 0 },
1262                 { 0, 0 },
1263                 { 0, 0 },
1264                 { 0, 0 },
1265                 { 0, 0 },
1266                 { 0, 0 },
1267                 { 0, 0 },
1268                 { 0, 0 },
1269                 { 0, 0 },
1270                 { 0, 0 },
1271                 { 0, 0 },
1272                 { 0, 0 },
1273                 { 0, 0 },
1274                 { 0, 0 },
1275                 { 0, 0 },
1276                 { 0, 0 },
1277                 { 0, 0 },
1278                 { 0, 0 },
1279                 { 0, 0 },
1280                 { 0, 0 },
1281                 { 0, 0 },
1282                 { 0, 0 },
1283                 { 0, 0 },
1284                 { 0, 0 },
1285                 { 0, 0 },
1286                 { 0, 0 },
1287                 { 0, 0 },
1288                 { 0, 0 },
1289                 { 0, 0 },
1290                 { 0, 0 }
1291         },
1292
1293         {
1294                 /* Home (unused) */
1295                 { 0, 0 },
1296                 { 0, 0 },
1297                 { 0, 0 },
1298                 { 0, 0 },
1299                 { 0, 0 },
1300                 { 0, 0 },
1301                 { 0, 0 },
1302                 { 0, 0 },
1303                 { 0, 0 },
1304                 { 0, 0 },
1305                 { 0, 0 },
1306                 { 0, 0 },
1307                 { 0, 0 },
1308                 { 0, 0 },
1309                 { 0, 0 },
1310                 { 0, 0 },
1311                 { 0, 0 },
1312                 { 0, 0 },
1313                 { 0, 0 },
1314                 { 0, 0 },
1315                 { 0, 0 },
1316                 { 0, 0 },
1317                 { 0, 0 },
1318                 { 0, 0 },
1319                 { 0, 0 },
1320                 { 0, 0 },
1321                 { 0, 0 },
1322                 { 0, 0 },
1323                 { 0, 0 },
1324                 { 0, 0 },
1325                 { 0, 0 },
1326                 { 0, 0 }
1327         },
1328
1329         {
1330                 /* Bookstore */
1331                 { TV_SORCERY_BOOK, 0 },
1332                 { TV_SORCERY_BOOK, 0 },
1333                 { TV_SORCERY_BOOK, 1 },
1334                 { TV_SORCERY_BOOK, 1 },
1335
1336                 { TV_NATURE_BOOK, 0 },
1337                 { TV_NATURE_BOOK, 0 },
1338                 { TV_NATURE_BOOK, 1 },
1339                 { TV_NATURE_BOOK, 1 },
1340
1341                 { TV_CHAOS_BOOK, 0 },
1342                 { TV_CHAOS_BOOK, 0 },
1343                 { TV_CHAOS_BOOK, 1 },
1344                 { TV_CHAOS_BOOK, 1 },
1345
1346                 { TV_DEATH_BOOK, 0 },
1347                 { TV_DEATH_BOOK, 0 },
1348                 { TV_DEATH_BOOK, 1 },
1349                 { TV_DEATH_BOOK, 1 },
1350
1351                 { TV_TRUMP_BOOK, 0 },           /* +16 */
1352                 { TV_TRUMP_BOOK, 0 },
1353                 { TV_TRUMP_BOOK, 1 },
1354                 { TV_TRUMP_BOOK, 1 },
1355
1356                 { TV_ARCANE_BOOK, 0 },
1357                 { TV_ARCANE_BOOK, 1 },
1358                 { TV_ARCANE_BOOK, 2 },
1359                 { TV_ARCANE_BOOK, 3 },
1360
1361                 { TV_CRAFT_BOOK, 0 },
1362                 { TV_CRAFT_BOOK, 0 },
1363                 { TV_CRAFT_BOOK, 1 },
1364                 { TV_CRAFT_BOOK, 1 },
1365
1366                 { TV_DAEMON_BOOK, 0 },
1367                 { TV_DAEMON_BOOK, 0 },
1368                 { TV_DAEMON_BOOK, 1 },
1369                 { TV_DAEMON_BOOK, 1 },
1370
1371                 { TV_MUSIC_BOOK, 0 },
1372                 { TV_MUSIC_BOOK, 0 },
1373                 { TV_MUSIC_BOOK, 1 },
1374                 { TV_MUSIC_BOOK, 1 },
1375
1376                 { TV_HEX_BOOK, 0 },
1377                 { TV_HEX_BOOK, 0 },
1378                 { TV_HEX_BOOK, 1 },
1379                 { TV_HEX_BOOK, 1 },
1380         },
1381
1382         {
1383                 /* Museum (unused) */
1384                 { 0, 0 },
1385                 { 0, 0 },
1386                 { 0, 0 },
1387                 { 0, 0 },
1388                 { 0, 0 },
1389                 { 0, 0 },
1390                 { 0, 0 },
1391                 { 0, 0 },
1392                 { 0, 0 },
1393                 { 0, 0 },
1394                 { 0, 0 },
1395                 { 0, 0 },
1396                 { 0, 0 },
1397                 { 0, 0 },
1398                 { 0, 0 },
1399                 { 0, 0 },
1400                 { 0, 0 },
1401                 { 0, 0 },
1402                 { 0, 0 },
1403                 { 0, 0 },
1404                 { 0, 0 },
1405                 { 0, 0 },
1406                 { 0, 0 },
1407                 { 0, 0 },
1408                 { 0, 0 },
1409                 { 0, 0 },
1410                 { 0, 0 },
1411                 { 0, 0 },
1412                 { 0, 0 },
1413                 { 0, 0 },
1414                 { 0, 0 },
1415                 { 0, 0 }
1416         }
1417 };
1418
1419
1420 /*!
1421  * @brief 基本情報読み込みのメインルーチン /
1422  * Initialize misc. values
1423  * @return エラーコード
1424  */
1425 static errr init_misc(void)
1426 {
1427         /* Initialize the values */
1428         process_dungeon_file("misc.txt", 0, 0, 0, 0);
1429
1430         return 0;
1431 }
1432
1433
1434 /*!
1435  * @brief 町情報読み込みのメインルーチン /
1436  * Initialize town array
1437  * @return エラーコード
1438  */
1439 static errr init_towns(void)
1440 {
1441         int i, j, k;
1442
1443         /*** Prepare the Towns ***/
1444
1445         /* Allocate the towns */
1446         C_MAKE(town, max_towns, town_type);
1447
1448         for (i = 1; i < max_towns; i++)
1449         {
1450                 /*** Prepare the Stores ***/
1451
1452                 /* Allocate the stores */
1453                 C_MAKE(town[i].store, MAX_STORES, store_type);
1454
1455                 /* Fill in each store */
1456                 for (j = 0; j < MAX_STORES; j++)
1457                 {
1458                         /* Access the store */
1459                         store_type *st_ptr = &town[i].store[j];
1460
1461                         if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
1462
1463                         /* Assume full stock */
1464
1465                 /*
1466                  * 我が家が 20 ページまで使える隠し機能のための準備。
1467                  * オプションが有効でもそうでなくても一応スペース
1468                  * を作っておく。
1469                  */
1470                 if (j == STORE_HOME)
1471                 {
1472                         st_ptr->stock_size = (STORE_INVEN_MAX * 10);
1473                 }
1474                 else if (j == STORE_MUSEUM)
1475                 {
1476                         st_ptr->stock_size = (STORE_INVEN_MAX * 50);
1477                 }
1478                 else
1479                 {
1480                         st_ptr->stock_size = STORE_INVEN_MAX;
1481                 }
1482
1483
1484                         /* Allocate the stock */
1485                         C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
1486
1487                         /* No table for the black market or home */
1488                         if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
1489
1490                         /* Assume full table */
1491                         st_ptr->table_size = STORE_CHOICES;
1492
1493                         /* Allocate the stock */
1494                         C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
1495
1496                         /* Scan the choices */
1497                         for (k = 0; k < STORE_CHOICES; k++)
1498                         {
1499                                 KIND_OBJECT_IDX k_idx;
1500
1501                                 /* Extract the tval/sval codes */
1502                                 int tv = store_table[j][k][0];
1503                                 int sv = store_table[j][k][1];
1504
1505                                 /* Look for it */
1506                                 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
1507                                 {
1508                                         object_kind *k_ptr = &k_info[k_idx];
1509
1510                                         /* Found a match */
1511                                         if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
1512                                 }
1513
1514                                 /* Catch errors */
1515                                 if (k_idx == max_k_idx) continue;
1516
1517                                 /* Add that item index to the table */
1518                                 st_ptr->table[st_ptr->table_num++] = k_idx;
1519                         }
1520                 }
1521         }
1522
1523         return 0;
1524 }
1525
1526 /*!
1527  * @brief 店情報初期化のメインルーチン /
1528  * Initialize buildings
1529  * @return エラーコード
1530  */
1531 errr init_buildings(void)
1532 {
1533         int i, j;
1534
1535         for (i = 0; i < MAX_BLDG; i++)
1536         {
1537                 building[i].name[0] = '\0';
1538                 building[i].owner_name[0] = '\0';
1539                 building[i].owner_race[0] = '\0';
1540
1541                 for (j = 0; j < 8; j++)
1542                 {
1543                         building[i].act_names[j][0] = '\0';
1544                         building[i].member_costs[j] = 0;
1545                         building[i].other_costs[j] = 0;
1546                         building[i].letters[j] = 0;
1547                         building[i].actions[j] = 0;
1548                         building[i].action_restr[j] = 0;
1549                 }
1550
1551                 for (j = 0; j < MAX_CLASS; j++)
1552                 {
1553                         building[i].member_class[j] = 0;
1554                 }
1555
1556                 for (j = 0; j < MAX_RACES; j++)
1557                 {
1558                         building[i].member_race[j] = 0;
1559                 }
1560
1561                 for (j = 0; j < MAX_MAGIC+1; j++)
1562                 {
1563                         building[i].member_realm[j] = 0;
1564                 }
1565         }
1566
1567         return (0);
1568 }
1569
1570
1571 /*!
1572  * @brief クエスト情報初期化のメインルーチン /
1573  * Initialize quest array
1574  * @return エラーコード
1575  */
1576 static errr init_quests(void)
1577 {
1578         int i;
1579
1580         /*** Prepare the quests ***/
1581
1582         /* Allocate the quests */
1583         C_MAKE(quest, max_q_idx, quest_type);
1584
1585         /* Set all quest to "untaken" */
1586         for (i = 0; i < max_q_idx; i++)
1587         {
1588                 quest[i].status = QUEST_STATUS_UNTAKEN;
1589         }
1590
1591         return 0;
1592 }
1593
1594 /*! 地形タグ情報から地形IDを得られなかった場合にTRUEを返すグローバル変数 */
1595 static bool feat_tag_is_not_found = FALSE;
1596
1597 /*!
1598  * @brief 地形タグからIDを得る /
1599  * Initialize quest array
1600  * @return 地形ID
1601  */
1602 s16b f_tag_to_index_in_init(cptr str)
1603 {
1604         FEAT_IDX feat = f_tag_to_index(str);
1605
1606         if (feat < 0) feat_tag_is_not_found = TRUE;
1607
1608         return feat;
1609 }
1610
1611
1612 /*!
1613  * @brief 地形の汎用定義をタグを通じて取得する /
1614  * Initialize feature variables
1615  * @return エラーコード
1616  */
1617 static errr init_feat_variables(void)
1618 {
1619         FEAT_IDX i;
1620
1621         /* Nothing */
1622         feat_none = f_tag_to_index_in_init("NONE");
1623
1624         /* Floor */
1625         feat_floor = f_tag_to_index_in_init("FLOOR");
1626
1627         /* Objects */
1628         feat_glyph = f_tag_to_index_in_init("GLYPH");
1629         feat_explosive_rune = f_tag_to_index_in_init("EXPLOSIVE_RUNE");
1630         feat_mirror = f_tag_to_index_in_init("MIRROR");
1631
1632         /* Doors */
1633         feat_door[DOOR_DOOR].open = f_tag_to_index_in_init("OPEN_DOOR");
1634         feat_door[DOOR_DOOR].broken = f_tag_to_index_in_init("BROKEN_DOOR");
1635         feat_door[DOOR_DOOR].closed = f_tag_to_index_in_init("CLOSED_DOOR");
1636
1637         /* Locked doors */
1638         for (i = 1; i < MAX_LJ_DOORS; i++)
1639         {
1640                 s16b door = f_tag_to_index(format("LOCKED_DOOR_%d", i));
1641                 if (door < 0) break;
1642                 feat_door[DOOR_DOOR].locked[i - 1] = door;
1643         }
1644         if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1645         feat_door[DOOR_DOOR].num_locked = i - 1;
1646
1647         /* Jammed doors */
1648         for (i = 0; i < MAX_LJ_DOORS; i++)
1649         {
1650                 s16b door = f_tag_to_index(format("JAMMED_DOOR_%d", i));
1651                 if (door < 0) break;
1652                 feat_door[DOOR_DOOR].jammed[i] = door;
1653         }
1654         if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1655         feat_door[DOOR_DOOR].num_jammed = i;
1656
1657         /* Glass doors */
1658         feat_door[DOOR_GLASS_DOOR].open = f_tag_to_index_in_init("OPEN_GLASS_DOOR");
1659         feat_door[DOOR_GLASS_DOOR].broken = f_tag_to_index_in_init("BROKEN_GLASS_DOOR");
1660         feat_door[DOOR_GLASS_DOOR].closed = f_tag_to_index_in_init("CLOSED_GLASS_DOOR");
1661
1662         /* Locked glass doors */
1663         for (i = 1; i < MAX_LJ_DOORS; i++)
1664         {
1665                 s16b door = f_tag_to_index(format("LOCKED_GLASS_DOOR_%d", i));
1666                 if (door < 0) break;
1667                 feat_door[DOOR_GLASS_DOOR].locked[i - 1] = door;
1668         }
1669         if (i == 1) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1670         feat_door[DOOR_GLASS_DOOR].num_locked = i - 1;
1671
1672         /* Jammed glass doors */
1673         for (i = 0; i < MAX_LJ_DOORS; i++)
1674         {
1675                 s16b door = f_tag_to_index(format("JAMMED_GLASS_DOOR_%d", i));
1676                 if (door < 0) break;
1677                 feat_door[DOOR_GLASS_DOOR].jammed[i] = door;
1678         }
1679         if (!i) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
1680         feat_door[DOOR_GLASS_DOOR].num_jammed = i;
1681
1682         /* Curtains */
1683         feat_door[DOOR_CURTAIN].open = f_tag_to_index_in_init("OPEN_CURTAIN");
1684         feat_door[DOOR_CURTAIN].broken = feat_door[DOOR_CURTAIN].open;
1685         feat_door[DOOR_CURTAIN].closed = f_tag_to_index_in_init("CLOSED_CURTAIN");
1686         feat_door[DOOR_CURTAIN].locked[0] = feat_door[DOOR_CURTAIN].closed;
1687         feat_door[DOOR_CURTAIN].num_locked = 1;
1688         feat_door[DOOR_CURTAIN].jammed[0] = feat_door[DOOR_CURTAIN].closed;
1689         feat_door[DOOR_CURTAIN].num_jammed = 1;
1690
1691         /* Stairs */
1692         feat_up_stair = f_tag_to_index_in_init("UP_STAIR");
1693         feat_down_stair = f_tag_to_index_in_init("DOWN_STAIR");
1694         feat_entrance = f_tag_to_index_in_init("ENTRANCE");
1695
1696         /* Normal traps */
1697         init_normal_traps();
1698
1699         /* Special traps */
1700         feat_trap_open = f_tag_to_index_in_init("TRAP_OPEN");
1701         feat_trap_armageddon = f_tag_to_index_in_init("TRAP_ARMAGEDDON");
1702         feat_trap_piranha = f_tag_to_index_in_init("TRAP_PIRANHA");
1703
1704         /* Rubble */
1705         feat_rubble = f_tag_to_index_in_init("RUBBLE");
1706
1707         /* Seams */
1708         feat_magma_vein = f_tag_to_index_in_init("MAGMA_VEIN");
1709         feat_quartz_vein = f_tag_to_index_in_init("QUARTZ_VEIN");
1710
1711         /* Walls */
1712         feat_granite = f_tag_to_index_in_init("GRANITE");
1713         feat_permanent = f_tag_to_index_in_init("PERMANENT");
1714
1715         /* Glass floor */
1716         feat_glass_floor = f_tag_to_index_in_init("GLASS_FLOOR");
1717
1718         /* Glass walls */
1719         feat_glass_wall = f_tag_to_index_in_init("GLASS_WALL");
1720         feat_permanent_glass_wall = f_tag_to_index_in_init("PERMANENT_GLASS_WALL");
1721
1722         /* Pattern */
1723         feat_pattern_start = f_tag_to_index_in_init("PATTERN_START");
1724         feat_pattern_1 = f_tag_to_index_in_init("PATTERN_1");
1725         feat_pattern_2 = f_tag_to_index_in_init("PATTERN_2");
1726         feat_pattern_3 = f_tag_to_index_in_init("PATTERN_3");
1727         feat_pattern_4 = f_tag_to_index_in_init("PATTERN_4");
1728         feat_pattern_end = f_tag_to_index_in_init("PATTERN_END");
1729         feat_pattern_old = f_tag_to_index_in_init("PATTERN_OLD");
1730         feat_pattern_exit = f_tag_to_index_in_init("PATTERN_EXIT");
1731         feat_pattern_corrupted = f_tag_to_index_in_init("PATTERN_CORRUPTED");
1732
1733         /* Various */
1734         feat_black_market = f_tag_to_index_in_init("BLACK_MARKET");
1735         feat_town = f_tag_to_index_in_init("TOWN");
1736
1737         /* Terrains */
1738         feat_deep_water = f_tag_to_index_in_init("DEEP_WATER");
1739         feat_shallow_water = f_tag_to_index_in_init("SHALLOW_WATER");
1740         feat_deep_lava = f_tag_to_index_in_init("DEEP_LAVA");
1741         feat_shallow_lava = f_tag_to_index_in_init("SHALLOW_LAVA");
1742         feat_dirt = f_tag_to_index_in_init("DIRT");
1743         feat_grass = f_tag_to_index_in_init("GRASS");
1744         feat_flower = f_tag_to_index_in_init("FLOWER");
1745         feat_brake = f_tag_to_index_in_init("BRAKE");
1746         feat_tree = f_tag_to_index_in_init("TREE");
1747         feat_mountain = f_tag_to_index_in_init("MOUNTAIN");
1748         feat_swamp = f_tag_to_index_in_init("SWAMP");
1749
1750         /* Unknown grid (not detected) */
1751         feat_undetected = f_tag_to_index_in_init("UNDETECTED");
1752
1753         /* Wilderness terrains */
1754         init_wilderness_terrains();
1755
1756         return feat_tag_is_not_found ? PARSE_ERROR_UNDEFINED_TERRAIN_TAG : 0;
1757 }
1758
1759
1760 /*!
1761  * @brief その他の初期情報更新 /
1762  * Initialize some other arrays
1763  * @return エラーコード
1764  */
1765 static errr init_other(void)
1766 {
1767         int i, n;
1768
1769
1770         /*** Prepare the "dungeon" information ***/
1771
1772         /* Allocate and Wipe the object list */
1773         C_MAKE(o_list, max_o_idx, object_type);
1774
1775         /* Allocate and Wipe the monster list */
1776         C_MAKE(m_list, max_m_idx, monster_type);
1777
1778         /* Allocate and Wipe the monster process list */
1779         for (i = 0; i < MAX_MTIMED; i++)
1780         {
1781                 C_MAKE(mproc_list[i], max_m_idx, s16b);
1782         }
1783
1784         /* Allocate and Wipe the max dungeon level */
1785         C_MAKE(max_dlv, max_d_idx, DEPTH);
1786
1787         /* Allocate and wipe each line of the cave */
1788         for (i = 0; i < MAX_HGT; i++)
1789         {
1790                 /* Allocate one row of the cave */
1791                 C_MAKE(cave[i], MAX_WID, cave_type);
1792         }
1793
1794
1795         /*** Prepare the various "bizarre" arrays ***/
1796
1797         /* Macro variables */
1798         C_MAKE(macro__pat, MACRO_MAX, cptr);
1799         C_MAKE(macro__act, MACRO_MAX, cptr);
1800         C_MAKE(macro__cmd, MACRO_MAX, bool);
1801
1802         /* Macro action buffer */
1803         C_MAKE(macro__buf, 1024, char);
1804
1805         /* Quark variables */
1806         quark_init();
1807
1808         /* Message variables */
1809         C_MAKE(message__ptr, MESSAGE_MAX, u32b);
1810         C_MAKE(message__buf, MESSAGE_BUF, char);
1811
1812         /* Hack -- No messages yet */
1813         message__tail = MESSAGE_BUF;
1814
1815
1816         /*** Prepare the Player inventory ***/
1817
1818         /* Allocate it */
1819         C_MAKE(inventory, INVEN_TOTAL, object_type);
1820
1821
1822         /*** Prepare the options ***/
1823
1824         /* Scan the options */
1825         for (i = 0; option_info[i].o_desc; i++)
1826         {
1827                 int os = option_info[i].o_set;
1828                 int ob = option_info[i].o_bit;
1829
1830                 /* Set the "default" options */
1831                 if (option_info[i].o_var)
1832                 {
1833                         /* Accept */
1834                         option_mask[os] |= (1L << ob);
1835
1836                         /* Set */
1837                         if (option_info[i].o_norm)
1838                         {
1839                                 /* Set */
1840                                 option_flag[os] |= (1L << ob);
1841                         }
1842
1843                         /* Clear */
1844                         else
1845                         {
1846                                 /* Clear */
1847                                 option_flag[os] &= ~(1L << ob);
1848                         }
1849                 }
1850         }
1851
1852         /* Analyze the windows */
1853         for (n = 0; n < 8; n++)
1854         {
1855                 /* Analyze the options */
1856                 for (i = 0; i < 32; i++)
1857                 {
1858                         /* Accept */
1859                         if (window_flag_desc[i])
1860                         {
1861                                 /* Accept */
1862                                 window_mask[n] |= (1L << i);
1863                         }
1864                 }
1865         }
1866
1867         /*
1868          *  Set the "default" window flags
1869          *  Window 1 : Display messages
1870          *  Window 2 : Display inven/equip
1871          */
1872         window_flag[1] = 1L << 6;
1873         window_flag[2] = 1L << 0;
1874
1875
1876         /*** Pre-allocate space for the "format()" buffer ***/
1877
1878         /* Hack -- Just call the "format()" function */
1879         (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1880
1881
1882         /* Success */
1883         return (0);
1884 }
1885
1886
1887 /*!
1888  * @brief オブジェクト配列を初期化する /
1889  * Initialize some other arrays
1890  * @return エラーコード
1891  */
1892 static errr init_object_alloc(void)
1893 {
1894         int i, j;
1895         object_kind *k_ptr;
1896         alloc_entry *table;
1897         s16b num[MAX_DEPTH];
1898         s16b aux[MAX_DEPTH];
1899
1900
1901         /*** Analyze object allocation info ***/
1902
1903         /* Clear the "aux" array */
1904         (void)C_WIPE(&aux, MAX_DEPTH, s16b);
1905
1906         /* Clear the "num" array */
1907         (void)C_WIPE(&num, MAX_DEPTH, s16b);
1908
1909         /* Free the old "alloc_kind_table" (if it exists) */
1910         if (alloc_kind_table)
1911         {
1912                 C_KILL(alloc_kind_table, alloc_kind_size, alloc_entry);
1913         }
1914
1915         /* Size of "alloc_kind_table" */
1916         alloc_kind_size = 0;
1917
1918         /* Scan the objects */
1919         for (i = 1; i < max_k_idx; i++)
1920         {
1921                 k_ptr = &k_info[i];
1922
1923                 /* Scan allocation pairs */
1924                 for (j = 0; j < 4; j++)
1925                 {
1926                         /* Count the "legal" entries */
1927                         if (k_ptr->chance[j])
1928                         {
1929                                 /* Count the entries */
1930                                 alloc_kind_size++;
1931
1932                                 /* Group by level */
1933                                 num[k_ptr->locale[j]]++;
1934                         }
1935                 }
1936         }
1937
1938         /* Collect the level indexes */
1939         for (i = 1; i < MAX_DEPTH; i++)
1940         {
1941                 /* Group by level */
1942                 num[i] += num[i-1];
1943         }
1944
1945         /* Paranoia */
1946         if (!num[0]) quit(_("町のアイテムがない!", "No town objects!"));
1947
1948         /*** Initialize object allocation info ***/
1949
1950         /* Allocate the alloc_kind_table */
1951         C_MAKE(alloc_kind_table, alloc_kind_size, alloc_entry);
1952
1953         /* Access the table entry */
1954         table = alloc_kind_table;
1955
1956         /* Scan the objects */
1957         for (i = 1; i < max_k_idx; i++)
1958         {
1959                 k_ptr = &k_info[i];
1960
1961                 /* Scan allocation pairs */
1962                 for (j = 0; j < 4; j++)
1963                 {
1964                         /* Count the "legal" entries */
1965                         if (k_ptr->chance[j])
1966                         {
1967                                 int p, x, y, z;
1968
1969                                 /* Extract the base level */
1970                                 x = k_ptr->locale[j];
1971
1972                                 /* Extract the base probability */
1973                                 p = (100 / k_ptr->chance[j]);
1974
1975                                 /* Skip entries preceding our locale */
1976                                 y = (x > 0) ? num[x-1] : 0;
1977
1978                                 /* Skip previous entries at this locale */
1979                                 z = y + aux[x];
1980
1981                                 /* Load the entry */
1982                                 table[z].index = (KIND_OBJECT_IDX)i;
1983                                 table[z].level = (DEPTH)x;
1984                                 table[z].prob1 = (PROB)p;
1985                                 table[z].prob2 = (PROB)p;
1986                                 table[z].prob3 = (PROB)p;
1987
1988                                 /* Another entry complete for this locale */
1989                                 aux[x]++;
1990                         }
1991                 }
1992         }
1993
1994         /* Success */
1995         return (0);
1996 }
1997
1998
1999 /*!
2000  * @brief モンスター配列と生成テーブルを初期化する /
2001  * Initialize some other arrays
2002  * @return エラーコード
2003  */
2004 static errr init_alloc(void)
2005 {
2006         int i;
2007         monster_race *r_ptr;
2008
2009 #ifdef SORT_R_INFO
2010
2011         tag_type *elements;
2012
2013         /* Allocate the "r_info" array */
2014         C_MAKE(elements, max_r_idx, tag_type);
2015
2016         /* Scan the monsters */
2017         for (i = 1; i < max_r_idx; i++)
2018         {
2019                 elements[i].tag = r_info[i].level;
2020                 elements[i].index = i;
2021         }
2022
2023         tag_sort(elements, max_r_idx);
2024
2025         /*** Initialize monster allocation info ***/
2026
2027         /* Size of "alloc_race_table" */
2028         alloc_race_size = max_r_idx;
2029
2030         /* Allocate the alloc_race_table */
2031         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
2032
2033         /* Scan the monsters */
2034         for (i = 1; i < max_r_idx; i++)
2035         {
2036                 /* Get the i'th race */
2037                 r_ptr = &r_info[elements[i].index];
2038
2039                 /* Count valid pairs */
2040                 if (r_ptr->rarity)
2041                 {
2042                         int p, x;
2043
2044                         /* Extract the base level */
2045                         x = r_ptr->level;
2046
2047                         /* Extract the base probability */
2048                         p = (100 / r_ptr->rarity);
2049
2050                         /* Load the entry */
2051                         alloc_race_table[i].index = (KIND_OBJECT_IDX)elements[i].index;
2052                         alloc_race_table[i].level = (DEPTH)x;
2053                         alloc_race_table[i].prob1 = (PROB)p;
2054                         alloc_race_table[i].prob2 = (PROB)p;
2055                         alloc_race_table[i].prob3 = (PROB)p;
2056                 }
2057         }
2058
2059         /* Free the "r_info" array */
2060         C_KILL(elements, max_r_idx, tag_type);
2061
2062 #else /* SORT_R_INFO */
2063
2064         int j;
2065         alloc_entry *table;
2066         s16b num[MAX_DEPTH];
2067         s16b aux[MAX_DEPTH];
2068
2069         /*** Analyze monster allocation info ***/
2070
2071         /* Clear the "aux" array */
2072         C_WIPE(&aux, MAX_DEPTH, s16b);
2073
2074         /* Clear the "num" array */
2075         C_WIPE(&num, MAX_DEPTH, s16b);
2076
2077         /* Size of "alloc_race_table" */
2078         alloc_race_size = 0;
2079
2080         /* Scan the monsters */
2081         for (i = 1; i < max_r_idx; i++)
2082         {
2083                 /* Get the i'th race */
2084                 r_ptr = &r_info[i];
2085
2086                 /* Legal monsters */
2087                 if (r_ptr->rarity)
2088                 {
2089                         /* Count the entries */
2090                         alloc_race_size++;
2091
2092                         /* Group by level */
2093                         num[r_ptr->level]++;
2094                 }
2095         }
2096
2097         /* Collect the level indexes */
2098         for (i = 1; i < MAX_DEPTH; i++)
2099         {
2100                 /* Group by level */
2101                 num[i] += num[i-1];
2102         }
2103
2104         /* Paranoia */
2105         if (!num[0]) quit(_("町のモンスターがない!", "No town monsters!"));
2106
2107         /*** Initialize monster allocation info ***/
2108
2109         /* Allocate the alloc_race_table */
2110         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
2111
2112         /* Access the table entry */
2113         table = alloc_race_table;
2114
2115         /* Scan the monsters */
2116         for (i = 1; i < max_r_idx; i++)
2117         {
2118                 /* Get the i'th race */
2119                 r_ptr = &r_info[i];
2120
2121                 /* Count valid pairs */
2122                 if (r_ptr->rarity)
2123                 {
2124                         int p, x, y, z;
2125
2126                         /* Extract the base level */
2127                         x = r_ptr->level;
2128
2129                         /* Extract the base probability */
2130                         p = (100 / r_ptr->rarity);
2131
2132                         /* Skip entries preceding our locale */
2133                         y = (x > 0) ? num[x-1] : 0;
2134
2135                         /* Skip previous entries at this locale */
2136                         z = y + aux[x];
2137
2138                         /* Load the entry */
2139                         table[z].index = i;
2140                         table[z].level = x;
2141                         table[z].prob1 = p;
2142                         table[z].prob2 = p;
2143                         table[z].prob3 = p;
2144
2145                         /* Another entry complete for this locale */
2146                         aux[x]++;
2147                 }
2148         }
2149
2150 #endif /* SORT_R_INFO */
2151
2152         /* Init the "alloc_kind_table" */
2153         (void)init_object_alloc();
2154
2155         /* Success */
2156         return (0);
2157 }
2158
2159
2160
2161 /*!
2162  * @brief 画面左下にシステムメッセージを表示する /
2163  * Hack -- take notes on line 23
2164  * @return なし
2165  */
2166 static void note(cptr str)
2167 {
2168         Term_erase(0, 23, 255);
2169         Term_putstr(20, 23, -1, TERM_WHITE, str);
2170         Term_fresh();
2171 }
2172
2173
2174
2175 /*!
2176  * @brief 全ゲームデータ読み込みのサブルーチン /
2177  * Hack -- Explain a broken "lib" folder and quit (see below).
2178  * @return なし
2179  * @note
2180  * <pre>
2181  * XXX XXX XXX This function is "messy" because various things
2182  * may or may not be initialized, but the "plog()" and "quit()"
2183  * functions are "supposed" to work under any conditions.
2184  * </pre>
2185  */
2186 static void init_angband_aux(cptr why)
2187 {
2188         /* Why */
2189         plog(why);
2190
2191 #ifdef JP
2192         /* Explain */
2193         plog("'lib'ディレクトリが存在しないか壊れているようです。");
2194
2195         /* More details */
2196         plog("ひょっとするとアーカイブが正しく解凍されていないのかもしれません。");
2197
2198         /* Explain */
2199         plog("該当する'README'ファイルを読んで確認してみて下さい。");
2200
2201         /* Quit with error */
2202         quit("致命的なエラー。");
2203 #else
2204         /* Explain */
2205         plog("The 'lib' directory is probably missing or broken.");
2206
2207         /* More details */
2208         plog("Perhaps the archive was not extracted correctly.");
2209
2210         /* Explain */
2211         plog("See the 'README' file for more information.");
2212
2213         /* Quit with error */
2214         quit("Fatal Error.");
2215 #endif
2216
2217 }
2218
2219
2220 /*!
2221  * @brief 全ゲームデータ読み込みのメインルーチン /
2222  * Hack -- main Angband initialization entry point
2223  * @return なし
2224  * @note
2225  * <pre>
2226  * XXX XXX XXX This function is "messy" because various things
2227  * may or may not be initialized, but the "plog()" and "quit()"
2228  * functions are "supposed" to work under any conditions.
2229  * Verify some files, display the "news.txt" file, create
2230  * the high score file, initialize all internal arrays, and
2231  * load the basic "user pref files".
2232  * Be very careful to keep track of the order in which things
2233  * are initialized, in particular, the only thing *known* to
2234  * be available when this function is called is the "z-term.c"
2235  * package, and that may not be fully initialized until the
2236  * end of this function, when the default "user pref files"
2237  * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
2238  * Note that this function attempts to verify the "news" file,
2239  * and the game aborts (cleanly) on failure, since without the
2240  * "news" file, it is likely that the "lib" folder has not been
2241  * correctly located.  Otherwise, the news file is displayed for
2242  * the user.
2243  * Note that this function attempts to verify (or create) the
2244  * "high score" file, and the game aborts (cleanly) on failure,
2245  * since one of the most common "extraction" failures involves
2246  * failing to extract all sub-directories (even empty ones), such
2247  * as by failing to use the "-d" option of "pkunzip", or failing
2248  * to use the "save empty directories" option with "Compact Pro".
2249  * This error will often be caught by the "high score" creation
2250  * code below, since the "lib/apex" directory, being empty in the
2251  * standard distributions, is most likely to be "lost", making it
2252  * impossible to create the high score file.
2253  * Note that various things are initialized by this function,
2254  * including everything that was once done by "init_some_arrays".
2255  * This initialization involves the parsing of special files
2256  * in the "lib/data" and sometimes the "lib/edit" directories.
2257  * Note that the "template" files are initialized first, since they
2258  * often contain errors.  This means that macros and message recall
2259  * and things like that are not available until after they are done.
2260  * We load the default "user pref files" here in case any "color"
2261  * changes are needed before character creation.
2262  * Note that the "graf-xxx.prf" file must be loaded separately,
2263  * if needed, in the first (?) pass through "TERM_XTRA_REACT".
2264  * </pre>
2265  */
2266 void init_angband(void)
2267 {
2268         int fd = -1;
2269
2270         BIT_FLAGS mode = 0664;
2271
2272         FILE *fp;
2273
2274         char buf[1024];
2275
2276
2277         /*** Verify the "news" file ***/
2278
2279         /* Build the filename */
2280         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2281
2282         /* Attempt to open the file */
2283         fd = fd_open(buf, O_RDONLY);
2284
2285         /* Failure */
2286         if (fd < 0)
2287         {
2288                 char why[1024];
2289
2290                 sprintf(why, _("'%s'ファイルにアクセスできません!", "Cannot access the '%s' file!"), buf);
2291
2292                 /* Crash and burn */
2293                 init_angband_aux(why);
2294         }
2295
2296         /* Close it */
2297         (void)fd_close(fd);
2298
2299
2300         /*** Display the "news" file ***/
2301
2302         /* Clear screen */
2303         Term_clear();
2304
2305         /* Build the filename */
2306         path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
2307
2308         /* Open the News file */
2309         fp = my_fopen(buf, "r");
2310
2311         /* Dump */
2312         if (fp)
2313         {
2314                 int i = 0;
2315
2316                 /* Dump the file to the screen */
2317                 while (0 == my_fgets(fp, buf, sizeof(buf)))
2318                 {
2319                         /* Display and advance */
2320                         Term_putstr(0, i++, -1, TERM_WHITE, buf);
2321                 }
2322
2323                 /* Close */
2324                 my_fclose(fp);
2325         }
2326
2327         /* Flush it */
2328         Term_flush();
2329
2330
2331         /*** Verify (or create) the "high score" file ***/
2332
2333         /* Build the filename */
2334         path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2335
2336         /* Attempt to open the high score file */
2337         fd = fd_open(buf, O_RDONLY);
2338
2339         /* Failure */
2340         if (fd < 0)
2341         {
2342                 /* File type is "DATA" */
2343                 FILE_TYPE(FILE_TYPE_DATA);
2344
2345                 /* Grab permissions */
2346                 safe_setuid_grab();
2347
2348                 /* Create a new high score file */
2349                 fd = fd_make(buf, mode);
2350
2351                 /* Drop permissions */
2352                 safe_setuid_drop();
2353
2354                 /* Failure */
2355                 if (fd < 0)
2356                 {
2357                         char why[1024];
2358
2359                         sprintf(why, _("'%s'ファイルを作成できません!", "Cannot create the '%s' file!"), buf);
2360
2361                         /* Crash and burn */
2362                         init_angband_aux(why);
2363                 }
2364         }
2365
2366         /* Close it */
2367         (void)fd_close(fd);
2368
2369         put_title();
2370
2371         /*** Initialize some arrays ***/
2372
2373         /* Initialize misc. values */
2374         note(_("[変数を初期化しています...(その他)", "[Initializing values... (misc)]"));
2375         if (init_misc()) quit(_("その他の変数を初期化できません", "Cannot initialize misc. values"));
2376
2377         /* Initialize feature info */
2378 #ifdef JP
2379         note("[データの初期化中... (地形)]");
2380         if (init_f_info()) quit("地形初期化不能");
2381         if (init_feat_variables()) quit("地形初期化不能");
2382 #else
2383         note("[Initializing arrays... (features)]");
2384         if (init_f_info()) quit("Cannot initialize features");
2385         if (init_feat_variables()) quit("Cannot initialize features");
2386 #endif
2387
2388
2389         /* Initialize object info */
2390         note(_("[データの初期化中... (アイテム)]", "[Initializing arrays... (objects)]"));
2391         if (init_k_info()) quit(_("アイテム初期化不能", "Cannot initialize objects"));
2392
2393
2394         /* Initialize artifact info */
2395         note(_("[データの初期化中... (伝説のアイテム)]", "[Initializing arrays... (artifacts)]"));
2396         if (init_a_info()) quit(_("伝説のアイテム初期化不能", "Cannot initialize artifacts"));
2397
2398
2399         /* Initialize ego-item info */
2400         note(_("[データの初期化中... (名のあるアイテム)]", "[Initializing arrays... (ego-items)]"));
2401         if (init_e_info()) quit(_("名のあるアイテム初期化不能", "Cannot initialize ego-items"));
2402
2403
2404         /* Initialize monster info */
2405         note(_("[データの初期化中... (モンスター)]", "[Initializing arrays... (monsters)]"));
2406         if (init_r_info()) quit(_("モンスター初期化不能", "Cannot initialize monsters"));
2407
2408
2409         /* Initialize dungeon info */
2410         note(_("[データの初期化中... (ダンジョン)]", "[Initializing arrays... (dungeon)]"));
2411         if (init_d_info()) quit(_("ダンジョン初期化不能", "Cannot initialize dungeon"));
2412         {
2413                 int i;
2414                 for (i = 1; i < max_d_idx; i++)
2415                         if (d_info[i].final_guardian)
2416                                 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
2417         }
2418
2419         /* Initialize magic info */
2420         note(_("[データの初期化中... (魔法)]", "[Initializing arrays... (magic)]"));
2421         if (init_m_info()) quit(_("魔法初期化不能", "Cannot initialize magic"));
2422
2423         /* Initialize weapon_exp info */
2424         note(_("[データの初期化中... (熟練度)]", "[Initializing arrays... (skill)]"));
2425         if (init_s_info()) quit(_("熟練度初期化不能", "Cannot initialize skill"));
2426
2427         /* Initialize wilderness array */
2428         note(_("[配列を初期化しています... (荒野)]", "[Initializing arrays... (wilderness)]"));
2429
2430         if (init_wilderness()) quit(_("荒野を初期化できません", "Cannot initialize wilderness"));
2431
2432
2433         /* Initialize town array */
2434         note(_("[配列を初期化しています... (街)]", "[Initializing arrays... (towns)]"));
2435         if (init_towns()) quit(_("街を初期化できません", "Cannot initialize towns"));
2436
2437
2438         /* Initialize building array */
2439         note(_("[配列を初期化しています... (建物)]", "[Initializing arrays... (buildings)]"));
2440         if (init_buildings()) quit(_("建物を初期化できません", "Cannot initialize buildings"));
2441
2442
2443         /* Initialize quest array */
2444         note(_("[配列を初期化しています... (クエスト)]", "[Initializing arrays... (quests)]"));
2445         if (init_quests()) quit(_("クエストを初期化できません", "Cannot initialize quests"));
2446
2447         /* Initialize vault info */
2448         if (init_v_info()) quit(_("vault 初期化不能", "Cannot initialize vaults"));
2449
2450         /* Initialize some other arrays */
2451         note(_("[データの初期化中... (その他)]", "[Initializing arrays... (other)]"));
2452         if (init_other()) quit(_("その他のデータ初期化不能", "Cannot initialize other stuff"));
2453
2454
2455         /* Initialize some other arrays */
2456         note(_("[データの初期化中... (アロケーション)]", "[Initializing arrays... (alloc)]"));
2457         if (init_alloc()) quit(_("アロケーション・スタッフ初期化不能", "Cannot initialize alloc stuff"));
2458
2459
2460
2461         /*** Load default user pref files ***/
2462
2463         /* Initialize feature info */
2464         note(_("[ユーザー設定ファイルを初期化しています...]", "[Initializing user pref files...]"));
2465
2466         /* Access the "basic" pref file */
2467         strcpy(buf, "pref.prf");
2468
2469         /* Process that file */
2470         process_pref_file(buf);
2471
2472         /* Access the "basic" system pref file */
2473         sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
2474
2475         /* Process that file */
2476         process_pref_file(buf);
2477
2478         /* Done */
2479         note(_("[初期化終了]", "[Initialization complete]"));
2480 }
2481
2482 /*!
2483  * @brief タイトル記述
2484  * @return なし
2485  */
2486 static void put_title(void)
2487 {
2488         char title[120];
2489         int col;
2490 #if H_VER_EXTRA > 0
2491         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,
2492 #else
2493         sprintf(title, _("変愚蛮怒 %d.%d.%d(%s)", "Hengband %d.%d.%d(%s)"), H_VER_MAJOR, H_VER_MINOR, H_VER_PATCH,
2494 #endif
2495         IS_STABLE_VERSION ? _("安定版", "Stable") : _("開発版", "Developing"));
2496         col = (80 - strlen(title)) / 2;
2497         col = col < 0 ? 0 : col;
2498         prt(title, VER_INFO_ROW, col);
2499 }
2500
2501 /*!
2502  * @brief サムチェック情報を出力 / Get check sum in string form
2503  * @return サムチェック情報の文字列
2504  */
2505 cptr get_check_sum(void)
2506 {
2507         return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x", 
2508                       f_head.v_extra, 
2509                       k_head.v_extra, 
2510                       a_head.v_extra, 
2511                       e_head.v_extra, 
2512                       r_head.v_extra, 
2513                       d_head.v_extra, 
2514                       m_head.v_extra, 
2515                       s_head.v_extra, 
2516                       v_head.v_extra);
2517 }
2518