OSDN Git Service

*_infoの初期化コードを大幅に書き変えてある程度まとめた。(最新版VやZを参考に)
[hengband/hengband.git] / src / init2.c
1 /* File: init2.c */
2
3 /* Purpose: Initialization (part 2) -BEN- */
4
5 #include "angband.h"
6
7 #include "init.h"
8
9 #ifndef MACINTOSH
10 #ifdef CHECK_MODIFICATION_TIME
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #endif /* CHECK_MODIFICATION_TIME */
14 #endif
15
16 /*
17  * This file is used to initialize various variables and arrays for the
18  * Angband game.  Note the use of "fd_read()" and "fd_write()" to bypass
19  * the common limitation of "read()" and "write()" to only 32767 bytes
20  * at a time.
21  *
22  * Several of the arrays for Angband are built from "template" files in
23  * the "lib/file" directory, from which quick-load binary "image" files
24  * are constructed whenever they are not present in the "lib/data"
25  * directory, or if those files become obsolete, if we are allowed.
26  *
27  * Warning -- the "ascii" file parsers use a minor hack to collect the
28  * name and text information in a single pass.  Thus, the game will not
29  * be able to load any template file with more than 20K of names or 60K
30  * of text, even though technically, up to 64K should be legal.
31  *
32  * The "init1.c" file is used only to parse the ascii template files,
33  * to create the binary image files.  If you include the binary image
34  * files instead of the ascii template files, then you can undefine
35  * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c".  Note
36  * that the binary image files are extremely system dependant.
37  */
38
39
40
41 /*
42  * Find the default paths to all of our important sub-directories.
43  *
44  * The purpose of each sub-directory is described in "variable.c".
45  *
46  * All of the sub-directories should, by default, be located inside
47  * the main "lib" directory, whose location is very system dependant.
48  *
49  * This function takes a writable buffer, initially containing the
50  * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
51  * or a system dependant string, for example, ":lib:".  The buffer
52  * must be large enough to contain at least 32 more characters.
53  *
54  * Various command line options may allow some of the important
55  * directories to be changed to user-specified directories, most
56  * importantly, the "info" and "user" and "save" directories,
57  * but this is done after this function, see "main.c".
58  *
59  * In general, the initial path should end in the appropriate "PATH_SEP"
60  * string.  All of the "sub-directory" paths (created below or supplied
61  * by the user) will NOT end in the "PATH_SEP" string, see the special
62  * "path_build()" function in "util.c" for more information.
63  *
64  * Mega-Hack -- support fat raw files under NEXTSTEP, using special
65  * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
66  * requiring the directories to be created by hand by the user.
67  *
68  * Hack -- first we free all the strings, since this is known
69  * to succeed even if the strings have not been allocated yet,
70  * as long as the variables start out as "NULL".  This allows
71  * this function to be called multiple times, for example, to
72  * try several base "path" values until a good one is found.
73  */
74 void init_file_paths(char *path)
75 {
76         char *tail;
77
78 #ifdef PRIVATE_USER_PATH
79         char buf[1024];
80 #endif /* PRIVATE_USER_PATH */
81
82         /*** Free everything ***/
83
84         /* Free the main path */
85         string_free(ANGBAND_DIR);
86
87         /* Free the sub-paths */
88         string_free(ANGBAND_DIR_APEX);
89         string_free(ANGBAND_DIR_BONE);
90         string_free(ANGBAND_DIR_DATA);
91         string_free(ANGBAND_DIR_EDIT);
92         string_free(ANGBAND_DIR_SCRIPT);
93         string_free(ANGBAND_DIR_FILE);
94         string_free(ANGBAND_DIR_HELP);
95         string_free(ANGBAND_DIR_INFO);
96         string_free(ANGBAND_DIR_SAVE);
97         string_free(ANGBAND_DIR_USER);
98         string_free(ANGBAND_DIR_XTRA);
99
100
101         /*** Prepare the "path" ***/
102
103         /* Hack -- save the main directory */
104         ANGBAND_DIR = string_make(path);
105
106         /* Prepare to append to the Base Path */
107         tail = path + strlen(path);
108
109
110 #ifdef VM
111
112         /*** Use "flat" paths with VM/ESA ***/
113
114         /* Use "blank" path names */
115         ANGBAND_DIR_APEX = string_make("");
116         ANGBAND_DIR_BONE = string_make("");
117         ANGBAND_DIR_DATA = string_make("");
118         ANGBAND_DIR_EDIT = string_make("");
119         ANGBAND_DIR_SCRIPT = string_make("");
120         ANGBAND_DIR_FILE = string_make("");
121         ANGBAND_DIR_HELP = string_make("");
122         ANGBAND_DIR_INFO = string_make("");
123         ANGBAND_DIR_SAVE = string_make("");
124         ANGBAND_DIR_USER = string_make("");
125         ANGBAND_DIR_XTRA = string_make("");
126
127
128 #else /* VM */
129
130
131         /*** Build the sub-directory names ***/
132
133         /* Build a path name */
134         strcpy(tail, "apex");
135         ANGBAND_DIR_APEX = string_make(path);
136
137         /* Build a path name */
138         strcpy(tail, "bone");
139         ANGBAND_DIR_BONE = string_make(path);
140
141         /* Build a path name */
142         strcpy(tail, "data");
143         ANGBAND_DIR_DATA = string_make(path);
144
145         /* Build a path name */
146         strcpy(tail, "edit");
147         ANGBAND_DIR_EDIT = string_make(path);
148
149         /* Build a path name */
150         strcpy(tail, "script");
151         ANGBAND_DIR_SCRIPT = string_make(path);
152
153         /* Build a path name */
154         strcpy(tail, "file");
155         ANGBAND_DIR_FILE = string_make(path);
156
157         /* Build a path name */
158         strcpy(tail, "help");
159         ANGBAND_DIR_HELP = string_make(path);
160
161         /* Build a path name */
162         strcpy(tail, "info");
163         ANGBAND_DIR_INFO = string_make(path);
164
165         /* Build a path name */
166         strcpy(tail, "pref");
167         ANGBAND_DIR_PREF = string_make(path);
168
169         /* Build a path name */
170         strcpy(tail, "save");
171         ANGBAND_DIR_SAVE = string_make(path);
172
173 #ifdef PRIVATE_USER_PATH
174
175         /* Build the path to the user specific directory */
176         path_build(buf, 1024, PRIVATE_USER_PATH, VERSION_NAME);
177
178         /* Build a relative path name */
179         ANGBAND_DIR_USER = string_make(buf);
180
181 #else /* PRIVATE_USER_PATH */
182
183         /* Build a path name */
184         strcpy(tail, "user");
185         ANGBAND_DIR_USER = string_make(path);
186
187 #endif /* PRIVATE_USER_PATH */
188
189         /* Build a path name */
190         strcpy(tail, "xtra");
191         ANGBAND_DIR_XTRA = string_make(path);
192
193 #endif /* VM */
194
195
196 #ifdef NeXT
197
198         /* Allow "fat binary" usage with NeXT */
199         if (TRUE)
200         {
201                 cptr next = NULL;
202
203 # if defined(m68k)
204                 next = "m68k";
205 # endif
206
207 # if defined(i386)
208                 next = "i386";
209 # endif
210
211 # if defined(sparc)
212                 next = "sparc";
213 # endif
214
215 # if defined(hppa)
216                 next = "hppa";
217 # endif
218
219                 /* Use special directory */
220                 if (next)
221                 {
222                         /* Forget the old path name */
223                         string_free(ANGBAND_DIR_DATA);
224
225                         /* Build a new path name */
226                         sprintf(tail, "data-%s", next);
227                         ANGBAND_DIR_DATA = string_make(path);
228                 }
229         }
230
231 #endif /* NeXT */
232
233 }
234
235
236
237 #ifdef ALLOW_TEMPLATES
238
239
240 /*
241  * Hack -- help give useful error messages
242  */
243 int error_idx;
244 int error_line;
245
246
247 /*
248  * Hack -- help initialize the fake "name" and "text" arrays when
249  * parsing an "ascii" template file.
250  */
251 u32b fake_name_size;
252 u32b fake_text_size;
253
254
255 /*
256  * Standard error message text
257  */
258 cptr err_str[PARSE_ERROR_MAX] =
259 {
260         NULL,
261 #ifdef JP
262         "ʸˡ¥¨¥é¡¼",
263         "¸Å¤¤¥Õ¥¡¥¤¥ë",
264         "µ­Ï¿¥Ø¥Ã¥À¤¬¤Ê¤¤",
265         "ÉÔϢ³¥ì¥³¡¼¥É",
266         "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
267         "̤ÄêµÁÌ¿Îá",
268         "¥á¥â¥êÉÔ­",
269         "ºÂɸÈϰϳ°",
270         "°ú¿ôÉÔ­",
271 #else
272         "parse error",
273         "obsolete file",
274         "missing record header",
275         "non-sequential records",
276         "invalid flag specification",
277         "undefined directive",
278         "out of memory",
279         "coordinates out of bounds",
280         "too few arguments",
281 #endif
282
283 };
284
285
286 #endif /* ALLOW_TEMPLATES */
287
288
289 /*
290  * File headers
291  */
292 header v_head;
293 header f_head;
294 header k_head;
295 header a_head;
296 header e_head;
297 header r_head;
298 header d_head;
299 header s_head;
300 header m_head;
301
302 #ifdef CHECK_MODIFICATION_TIME
303
304 static errr check_modification_date(int fd, cptr template_file)
305 {
306         char buf[1024];
307
308         struct stat txt_stat, raw_stat;
309
310         /* Build the filename */
311         path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
312
313         /* Access stats on text file */
314         if (stat(buf, &txt_stat))
315         {
316                 /* No text file - continue */
317         }
318
319         /* Access stats on raw file */
320         else if (fstat(fd, &raw_stat))
321         {
322                 /* Error */
323                 return (-1);
324         }
325
326         /* Ensure text file is not newer than raw file */
327         else if (txt_stat.st_mtime > raw_stat.st_mtime)
328         {
329                 /* Reprocess text file */
330                 return (-1);
331         }
332
333         return (0);
334 }
335
336 #endif /* CHECK_MODIFICATION_TIME */
337
338
339
340 /*** Initialize from binary image files ***/
341
342
343 /*
344  * Initialize the "*_info" array, by parsing a binary "image" file
345  */
346 static errr init_info_raw(int fd, header *head)
347 {
348         header test;
349
350         /* Read and Verify the header */
351         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
352             (test.v_major != head->v_major) ||
353             (test.v_minor != head->v_minor) ||
354             (test.v_patch != head->v_patch) ||
355             (test.v_extra != head->v_extra) ||
356             (test.info_num != head->info_num) ||
357             (test.info_len != head->info_len) ||
358             (test.head_size != head->head_size) ||
359             (test.info_size != head->info_size))
360         {
361                 /* Error */
362                 return (-1);
363         }
364
365
366         /* Accept the header */
367         (*head) = test;
368
369
370         /* Allocate the "*_info" array */
371         C_MAKE(head->info_ptr, head->info_size, char);
372
373         /* Read the "*_info" array */
374         fd_read(fd, head->info_ptr, head->info_size);
375
376
377         if (head->name_size)
378         {
379                 /* Allocate the "*_name" array */
380                 C_MAKE(head->name_ptr, head->name_size, char);
381
382                 /* Read the "*_name" array */
383                 fd_read(fd, head->name_ptr, head->name_size);
384         }
385
386
387         if (head->text_size)
388         {
389                 /* Allocate the "*_text" array */
390                 C_MAKE(head->text_ptr, head->text_size, char);
391
392                 /* Read the "*_text" array */
393                 fd_read(fd, head->text_ptr, head->text_size);
394         }
395
396         /* Success */
397         return (0);
398 }
399
400
401
402 /*
403  * Initialize the header of an *_info.raw file.
404  */
405 static void init_header(header *head, int num, int len)
406 {
407         /* Save the "version" */
408         head->v_major = FAKE_VER_MAJOR;
409         head->v_minor = FAKE_VER_MINOR;
410         head->v_patch = FAKE_VER_PATCH;
411         head->v_extra = 0;
412
413         /* Save the "record" information */
414         head->info_num = num;
415         head->info_len = len;
416
417         /* Save the size of "*_head" and "*_info" */
418         head->head_size = sizeof(header);
419         head->info_size = head->info_num * head->info_len;
420 }
421
422
423 /*
424  * Initialize the "*_info" array
425  *
426  * Note that we let each entry have a unique "name" and "text" string,
427  * even if the string happens to be empty (everyone has a unique '\0').
428  */
429 static errr init_info(cptr filename, header *head,
430                         void **info, char **name, char **text)
431 {
432         int fd;
433
434         int mode = 0644;
435
436         errr err = 1;
437
438         FILE *fp;
439
440         /* General buffer */
441         char buf[1024];
442
443
444 #ifdef ALLOW_TEMPLATES
445
446         /*** Load the binary image file ***/
447
448         /* Build the filename */
449 #ifdef JP
450         path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
451 #else
452         path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
453 #endif
454
455
456         /* Attempt to open the "raw" file */
457         fd = fd_open(buf, O_RDONLY);
458
459         /* Process existing "raw" file */
460         if (fd >= 0)
461         {
462 #ifdef CHECK_MODIFICATION_TIME
463
464                 err = check_modification_date(fd, format("%s_j.txt", filename));
465
466 #endif /* CHECK_MODIFICATION_TIME */
467
468                 /* Attempt to parse the "raw" file */
469                 if (!err)
470                         err = init_info_raw(fd, head);
471
472                 /* Close it */
473                 (void)fd_close(fd);
474         }
475
476
477         /* Do we have to parse the *.txt file? */
478         if (err)
479         {
480                 /*** Make the fake arrays ***/
481
482                 /* Assume the size of "*_name" and "*_text" */
483                 fake_name_size = FAKE_NAME_SIZE;
484                 fake_text_size = FAKE_TEXT_SIZE;
485
486                 /* Allocate the "*_info" array */
487                 C_MAKE(head->info_ptr, head->info_size, char);
488
489                 /* Hack -- make "fake" arrays */
490                 if (name) C_MAKE(head->name_ptr, fake_name_size, char);
491                 if (text) C_MAKE(head->text_ptr, fake_text_size, char);
492
493                 if (info) (*info) = head->info_ptr;
494                 if (name) (*name) = head->name_ptr;
495                 if (text) (*text) = head->text_ptr;
496
497                 /*** Load the ascii template file ***/
498
499                 /* Build the filename */
500
501                 path_build(buf, 1024, ANGBAND_DIR_EDIT, format("%s_j.txt", filename));
502
503                 /* Open the file */
504                 fp = my_fopen(buf, "r");
505
506                 /* Parse it */
507 #ifdef JP
508                 if (!fp) quit(format("'%s_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£", filename));
509 #else
510                 if (!fp) quit(format("Cannot open '%s.txt' file.", filename));
511 #endif
512
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_str[err] : "̤ÃΤÎ");
528
529                         /* Oops */
530                         msg_format("'%s_j.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_j.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                 /*** Dump the binary image file ***/
555
556                 /* File type is "DATA" */
557                 FILE_TYPE(FILE_TYPE_DATA);
558
559                 /* Build the filename */
560 #ifdef JP
561                 path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
562 #else
563                 path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
564 #endif
565
566
567                 /* Kill the old file */
568                 (void)fd_kill(buf);
569
570                 /* Attempt to create the raw file */
571                 fd = fd_make(buf, mode);
572
573                 /* Dump to the file */
574                 if (fd >= 0)
575                 {
576                         /* Dump it */
577                         fd_write(fd, (cptr)(head), head->head_size);
578
579                 /* Dump the "*_info" array */
580                         fd_write(fd, head->info_ptr, head->info_size);
581
582                         /* Dump the "*_name" array */
583                         fd_write(fd, head->name_ptr, head->name_size);
584
585                         /* Dump the "*_text" array */
586                         fd_write(fd, head->text_ptr, head->text_size);
587
588                         /* Close */
589                         (void)fd_close(fd);
590                 }
591
592
593                 /*** Kill the fake arrays ***/
594
595                 /* Free the "*_info" array */
596                 C_KILL(head->info_ptr, head->info_size, char);
597
598                 /* Hack -- Free the "fake" arrays */
599                 if (name) C_KILL(head->name_ptr, fake_name_size, char);
600                 if (text) C_KILL(head->text_ptr, fake_text_size, char);
601
602                 /* Forget the array sizes */
603                 fake_name_size = 0;
604                 fake_text_size = 0;
605
606 #endif  /* ALLOW_TEMPLATES */
607
608
609                 /*** Load the binary image file ***/
610
611                 /* Build the filename */
612 #ifdef JP
613                 path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s_j.raw", filename));
614 #else
615                 path_build(buf, 1024, ANGBAND_DIR_DATA, format("%s.raw", filename));
616 #endif
617
618
619                 /* Attempt to open the "raw" file */
620                 fd = fd_open(buf, O_RDONLY);
621
622                 /* Process existing "raw" file */
623 #ifdef JP
624                 if (fd < 0) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£", filename));
625 #else
626                 if (fd < 0) quit(format("Cannot load '%s.raw' file.", filename));
627 #endif
628
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 #ifdef JP
638                 if (err) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£", filename));
639 #else
640                 if (err) quit(format("Cannot parse '%s.raw' file.", filename));
641 #endif
642
643 #ifdef ALLOW_TEMPLATES
644         }
645 #endif
646
647         if (info) (*info) = head->info_ptr;
648         if (name) (*name) = head->name_ptr;
649         if (text) (*text) = head->text_ptr;
650
651         /* Success */
652         return (0);
653 }
654
655
656 /*
657  * Initialize the "f_info" array
658  */
659 static errr init_f_info(void)
660 {
661         /* Init the header */
662         init_header(&f_head, max_f_idx, sizeof(feature_type));
663
664 #ifdef ALLOW_TEMPLATES
665
666         /* Save a pointer to the parsing function */
667         f_head.parse_info_txt = parse_f_info;
668
669 #endif /* ALLOW_TEMPLATES */
670
671         return init_info("f_info", &f_head,
672                          (void*)&f_info, (void*)&f_name, (void*)&f_text);
673 }
674
675
676 /*
677  * Initialize the "k_info" array
678  */
679 static errr init_k_info(void)
680 {
681         /* Init the header */
682         init_header(&k_head, max_k_idx, sizeof(object_kind));
683
684 #ifdef ALLOW_TEMPLATES
685
686         /* Save a pointer to the parsing function */
687         k_head.parse_info_txt = parse_k_info;
688
689 #endif /* ALLOW_TEMPLATES */
690
691         return init_info("k_info", &k_head,
692                          (void*)&k_info, (void*)&k_name, (void*)&k_text);
693 }
694
695
696
697 /*
698  * Initialize the "a_info" array
699  */
700 static errr init_a_info(void)
701 {
702         /* Init the header */
703         init_header(&a_head, max_a_idx, sizeof(artifact_type));
704
705 #ifdef ALLOW_TEMPLATES
706
707         /* Save a pointer to the parsing function */
708         a_head.parse_info_txt = parse_a_info;
709
710 #endif /* ALLOW_TEMPLATES */
711
712         return init_info("a_info", &a_head,
713                          (void*)&a_info, (void*)&a_name, (void*)&a_text);
714 }
715
716
717
718 /*
719  * Initialize the "e_info" array
720  */
721 static errr init_e_info(void)
722 {
723         /* Init the header */
724         init_header(&e_head, max_e_idx, sizeof(ego_item_type));
725
726 #ifdef ALLOW_TEMPLATES
727
728         /* Save a pointer to the parsing function */
729         e_head.parse_info_txt = parse_e_info;
730
731 #endif /* ALLOW_TEMPLATES */
732
733         return init_info("e_info", &e_head,
734                          (void*)&e_info, (void*)&e_name, (void*)&e_text);
735 }
736
737
738
739 /*
740  * Initialize the "r_info" array
741  */
742 static errr init_r_info(void)
743 {
744         /* Init the header */
745         init_header(&r_head, max_r_idx, sizeof(monster_race));
746
747 #ifdef ALLOW_TEMPLATES
748
749         /* Save a pointer to the parsing function */
750         r_head.parse_info_txt = parse_r_info;
751
752 #endif /* ALLOW_TEMPLATES */
753
754         return init_info("r_info", &r_head,
755                          (void*)&r_info, (void*)&r_name, (void*)&r_text);
756 }
757
758
759
760 /*
761  * Initialize the "d_info" array
762  */
763 static errr init_d_info(void)
764 {
765         /* Init the header */
766         init_header(&d_head, max_d_idx, sizeof(dungeon_info_type));
767
768 #ifdef ALLOW_TEMPLATES
769
770         /* Save a pointer to the parsing function */
771         d_head.parse_info_txt = parse_d_info;
772
773 #endif /* ALLOW_TEMPLATES */
774
775         return init_info("d_info", &d_head,
776                          (void*)&d_info, (void*)&d_name, (void*)&d_text);
777 }
778
779
780 /*
781  * Initialize the "v_info" array
782  *
783  * Note that we let each entry have a unique "name" and "text" string,
784  * even if the string happens to be empty (everyone has a unique '\0').
785  */
786 errr init_v_info(void)
787 {
788         /* Init the header */
789         init_header(&v_head, max_v_idx, sizeof(vault_type));
790
791 #ifdef ALLOW_TEMPLATES
792
793         /* Save a pointer to the parsing function */
794         v_head.parse_info_txt = parse_v_info;
795
796 #endif /* ALLOW_TEMPLATES */
797
798         return init_info("v_info", &v_head,
799                          (void*)&v_info, (void*)&v_name, (void*)&v_text);
800 }
801
802
803 /*
804  * Initialize the "s_info" array
805  */
806 static errr init_s_info(void)
807 {
808         /* Init the header */
809         init_header(&s_head, MAX_CLASS, sizeof(skill_table));
810
811 #ifdef ALLOW_TEMPLATES
812
813         /* Save a pointer to the parsing function */
814         s_head.parse_info_txt = parse_s_info;
815
816 #endif /* ALLOW_TEMPLATES */
817
818         return init_info("s_info", &s_head,
819                          (void*)&s_info, (void*)&s_name, (void*)&s_text);
820 }
821
822
823 /*
824  * Initialize the "m_info" array
825  */
826 static errr init_m_info(void)
827 {
828         /* Init the header */
829         init_header(&m_head, MAX_CLASS, sizeof(player_magic));
830
831 #ifdef ALLOW_TEMPLATES
832
833         /* Save a pointer to the parsing function */
834         m_head.parse_info_txt = parse_m_info;
835
836 #endif /* ALLOW_TEMPLATES */
837
838         return init_info("m_info", &m_head,
839                          (void*)&m_info, (void*)&m_name, (void*)&m_text);
840 }
841
842
843
844 /*** Initialize others ***/
845
846 /*
847  * Hack -- Objects sold in the stores -- by tval/sval pair.
848  */
849 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
850 {
851         {
852                 /* General Store */
853
854                 { TV_FOOD, SV_FOOD_RATION },
855                 { TV_FOOD, SV_FOOD_RATION },
856                 { TV_FOOD, SV_FOOD_RATION },
857                 { TV_FOOD, SV_FOOD_RATION },
858
859                 { TV_FOOD, SV_FOOD_RATION },
860                 { TV_FOOD, SV_FOOD_BISCUIT },
861                 { TV_FOOD, SV_FOOD_JERKY },
862                 { TV_FOOD, SV_FOOD_JERKY },
863
864                 { TV_FOOD, SV_FOOD_PINT_OF_WINE },
865                 { TV_FOOD, SV_FOOD_PINT_OF_ALE },
866                 { TV_LITE, SV_LITE_TORCH },
867                 { TV_LITE, SV_LITE_TORCH },
868
869                 { TV_LITE, SV_LITE_TORCH },
870                 { TV_LITE, SV_LITE_TORCH },
871                 { TV_LITE, SV_LITE_LANTERN },
872                 { TV_LITE, SV_LITE_LANTERN },
873
874                 { TV_FLASK, 0 },
875                 { TV_FLASK, 0 },
876                 { TV_FLASK, 0 },
877                 { TV_FLASK, 0 },
878
879                 { TV_FLASK, 0 },
880                 { TV_FLASK, 0 },
881                 { TV_SPIKE, 0 },
882                 { TV_SPIKE, 0 },
883
884                 { TV_SHOT, SV_AMMO_NORMAL },
885                 { TV_ARROW, SV_AMMO_NORMAL },
886                 { TV_BOLT, SV_AMMO_NORMAL },
887                 { TV_DIGGING, SV_SHOVEL },
888
889                 { TV_DIGGING, SV_PICK },
890                 { TV_CLOAK, SV_CLOAK },
891                 { TV_CLOAK, SV_CLOAK },
892                 { TV_CLOAK, SV_FUR_CLOAK },
893
894                 { TV_FOOD, SV_FOOD_RATION },
895                 { TV_FOOD, SV_FOOD_RATION },
896                 { TV_FOOD, SV_FOOD_RATION },
897                 { TV_FOOD, SV_FOOD_RATION },
898
899                 { TV_LITE, SV_LITE_TORCH },
900                 { TV_LITE, SV_LITE_TORCH },
901                 { TV_LITE, SV_LITE_LANTERN },
902                 { TV_LITE, SV_LITE_LANTERN },
903
904                 { TV_FLASK, 0 },
905                 { TV_FLASK, 0 },
906
907                 { TV_CAPTURE, 0 },
908
909                 { TV_FIGURINE, 0 },
910
911                 { TV_SHOT, SV_AMMO_NORMAL },
912                 { TV_ARROW, SV_AMMO_NORMAL },
913                 { TV_BOLT, SV_AMMO_NORMAL },
914                 { TV_DIGGING, SV_SHOVEL }
915         },
916
917         {
918                 /* Armoury */
919
920                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
921                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
922                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
923                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
924
925                 { TV_HELM, SV_HARD_LEATHER_CAP },
926                 { TV_HELM, SV_HARD_LEATHER_CAP },
927                 { TV_HELM, SV_METAL_CAP },
928                 { TV_HELM, SV_IRON_HELM },
929
930                 { TV_SOFT_ARMOR, SV_ROBE },
931                 { TV_SOFT_ARMOR, SV_ROBE },
932                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
933                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
934
935                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
936                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
937                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
938                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
939
940                 { TV_SOFT_ARMOR, SV_RHINO_HIDE_ARMOR },
941                 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
942                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
943                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
944
945                 { TV_HARD_ARMOR, SV_DOUBLE_RING_MAIL },
946                 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
947                 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL },
948                 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL },
949
950                 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR },
951                 { TV_HARD_ARMOR, SV_SPLINT_MAIL },
952                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
953                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
954
955                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
956                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
957                 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD },
958                 { TV_SHIELD, SV_SMALL_METAL_SHIELD },
959
960                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
961                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
962                 { TV_HELM, SV_HARD_LEATHER_CAP },
963                 { TV_HELM, SV_HARD_LEATHER_CAP },
964
965                 { TV_SOFT_ARMOR, SV_ROBE },
966                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
967                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
968                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
969
970                 { TV_SOFT_ARMOR, SV_LEATHER_JACK },
971                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
972                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
973                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
974
975                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
976                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
977                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
978                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }
979         },
980
981         {
982                 /* Weaponsmith */
983
984                 { TV_SWORD, SV_DAGGER },
985                 { TV_SWORD, SV_MAIN_GAUCHE },
986                 { TV_SWORD, SV_RAPIER },
987                 { TV_SWORD, SV_SMALL_SWORD },
988
989                 { TV_SWORD, SV_SHORT_SWORD },
990                 { TV_SWORD, SV_SABRE },
991                 { TV_SWORD, SV_CUTLASS },
992                 { TV_SWORD, SV_TULWAR },
993
994                 { TV_SWORD, SV_BROAD_SWORD },
995                 { TV_SWORD, SV_LONG_SWORD },
996                 { TV_SWORD, SV_SCIMITAR },
997                 { TV_SWORD, SV_KATANA },
998
999                 { TV_SWORD, SV_BASTARD_SWORD },
1000                 { TV_POLEARM, SV_SPEAR },
1001                 { TV_POLEARM, SV_AWL_PIKE },
1002                 { TV_POLEARM, SV_TRIDENT },
1003
1004                 { TV_POLEARM, SV_PIKE },
1005                 { TV_POLEARM, SV_BEAKED_AXE },
1006                 { TV_POLEARM, SV_BROAD_AXE },
1007                 { TV_POLEARM, SV_LANCE },
1008
1009                 { TV_POLEARM, SV_BATTLE_AXE },
1010                 { TV_POLEARM, SV_HATCHET },
1011                 { TV_BOW, SV_SLING },
1012                 { TV_BOW, SV_SHORT_BOW },
1013
1014                 { TV_BOW, SV_LONG_BOW },
1015                 { TV_BOW, SV_LIGHT_XBOW },
1016                 { TV_SHOT, SV_AMMO_NORMAL },
1017                 { TV_SHOT, SV_AMMO_NORMAL },
1018
1019                 { TV_ARROW, SV_AMMO_NORMAL },
1020                 { TV_ARROW, SV_AMMO_NORMAL },
1021                 { TV_BOLT, SV_AMMO_NORMAL },
1022                 { TV_BOLT, SV_AMMO_NORMAL },
1023
1024                 { TV_BOW, SV_LONG_BOW },
1025                 { TV_BOW, SV_LIGHT_XBOW },
1026                 { TV_ARROW, SV_AMMO_NORMAL },
1027                 { TV_BOLT, SV_AMMO_NORMAL },
1028
1029                 { TV_BOW, SV_SHORT_BOW },
1030                 { TV_SWORD, SV_DAGGER },
1031                 { TV_SWORD, SV_TANTO },
1032                 { TV_SWORD, SV_RAPIER },
1033
1034                 { TV_SWORD, SV_SMALL_SWORD },
1035                 { TV_SWORD, SV_SHORT_SWORD },
1036                 { TV_SWORD, SV_LONG_SWORD },
1037                 { TV_SWORD, SV_SCIMITAR },
1038
1039                 { TV_HISSATSU_BOOK, 0 },
1040                 { TV_HISSATSU_BOOK, 0 },
1041                 { TV_HISSATSU_BOOK, 1 },
1042                 { TV_HISSATSU_BOOK, 1 },
1043         },
1044
1045         {
1046                 /* Temple */
1047
1048                 { TV_HAFTED, SV_NUNCHAKU },
1049                 { TV_HAFTED, SV_QUARTERSTAFF },
1050                 { TV_HAFTED, SV_MACE },
1051                 { TV_HAFTED, SV_BO_STAFF },
1052
1053                 { TV_HAFTED, SV_WAR_HAMMER },
1054                 { TV_HAFTED, SV_WAR_HAMMER },
1055                 { TV_HAFTED, SV_MORNING_STAR },
1056                 { TV_HAFTED, SV_FLAIL },
1057
1058                 { TV_HAFTED, SV_LEAD_FILLED_MACE },
1059                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1060                 { TV_SCROLL, SV_SCROLL_BLESSING },
1061                 { TV_SCROLL, SV_SCROLL_HOLY_CHANT },
1062
1063                 { TV_POTION, SV_POTION_HEROISM },
1064                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1065                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1066                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1067
1068                 { TV_POTION, SV_POTION_CURE_LIGHT },
1069                 { TV_POTION, SV_POTION_CURE_SERIOUS },
1070                 { TV_POTION, SV_POTION_CURE_SERIOUS },
1071                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1072
1073                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1074                 { TV_POTION, SV_POTION_RESTORE_EXP },
1075                 { TV_POTION, SV_POTION_RESTORE_EXP },
1076                 { TV_POTION, SV_POTION_RESTORE_EXP },
1077
1078                 { TV_LIFE_BOOK, 0 },
1079                 { TV_LIFE_BOOK, 0 },
1080                 { TV_LIFE_BOOK, 0 },
1081                 { TV_LIFE_BOOK, 0 },
1082
1083                 { TV_LIFE_BOOK, 1 },
1084                 { TV_LIFE_BOOK, 1 },
1085                 { TV_LIFE_BOOK, 1 },
1086                 { TV_LIFE_BOOK, 1 },
1087
1088                 { TV_HAFTED, SV_WHIP },
1089                 { TV_HAFTED, SV_MACE },
1090                 { TV_HAFTED, SV_BALL_AND_CHAIN },
1091                 { TV_HAFTED, SV_WAR_HAMMER },
1092
1093                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1094                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1095                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1096                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1097
1098                 { TV_POTION, SV_POTION_CURE_CRITICAL },
1099                 { TV_POTION, SV_POTION_RESTORE_EXP },
1100
1101                 { TV_FIGURINE, 0 },
1102                 { TV_STATUE, SV_ANY },
1103
1104                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1105                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1106                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE },
1107                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE }
1108         },
1109
1110         {
1111                 /* Alchemy shop */
1112
1113                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1114                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1115                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1116                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1117
1118                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1119                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1120                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1121                 { TV_SCROLL, SV_SCROLL_LIGHT },
1122
1123                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1124                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1125                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1126                 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION },
1127
1128                 { TV_SCROLL, SV_SCROLL_MAPPING },
1129                 { TV_SCROLL, SV_SCROLL_DETECT_GOLD },
1130                 { TV_SCROLL, SV_SCROLL_DETECT_ITEM },
1131                 { TV_SCROLL, SV_SCROLL_DETECT_TRAP },
1132
1133                 { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
1134                 { TV_SCROLL, SV_SCROLL_RECHARGING },
1135                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
1136                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1137
1138                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1139                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1140                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1141                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1142
1143                 { TV_SCROLL, SV_SCROLL_TELEPORT },
1144                 { TV_POTION, SV_POTION_RES_STR },
1145                 { TV_POTION, SV_POTION_RES_INT },
1146                 { TV_POTION, SV_POTION_RES_WIS },
1147
1148                 { TV_POTION, SV_POTION_RES_DEX },
1149                 { TV_POTION, SV_POTION_RES_CON },
1150                 { TV_POTION, SV_POTION_RES_CHR },
1151                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1152
1153                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1154                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },  /* Yep, occasionally! */
1155                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },
1156                 { TV_SCROLL, SV_SCROLL_LIGHT },
1157
1158                 { TV_POTION, SV_POTION_RES_STR },
1159                 { TV_POTION, SV_POTION_RES_INT },
1160                 { TV_POTION, SV_POTION_RES_WIS },
1161                 { TV_POTION, SV_POTION_RES_DEX },
1162
1163                 { TV_POTION, SV_POTION_RES_CON },
1164                 { TV_POTION, SV_POTION_RES_CHR },
1165                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1166                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1167
1168                 { TV_SCROLL, SV_SCROLL_RECHARGING },
1169                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
1170                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
1171                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER }
1172
1173         },
1174
1175         {
1176                 /* Magic-User store */
1177
1178                 { TV_RING, SV_RING_PROTECTION },
1179                 { TV_RING, SV_RING_FEATHER_FALL },
1180                 { TV_RING, SV_RING_PROTECTION },
1181                 { TV_RING, SV_RING_RESIST_FIRE },
1182
1183                 { TV_RING, SV_RING_RESIST_COLD },
1184                 { TV_AMULET, SV_AMULET_CHARISMA },
1185                 { TV_RING, SV_RING_WARNING },
1186                 { TV_AMULET, SV_AMULET_RESIST_ACID },
1187
1188                 { TV_AMULET, SV_AMULET_SEARCHING },
1189                 { TV_WAND, SV_WAND_SLOW_MONSTER },
1190                 { TV_WAND, SV_WAND_CONFUSE_MONSTER },
1191                 { TV_WAND, SV_WAND_SLEEP_MONSTER },
1192
1193                 { TV_WAND, SV_WAND_MAGIC_MISSILE },
1194                 { TV_WAND, SV_WAND_STINKING_CLOUD },
1195                 { TV_WAND, SV_WAND_WONDER },
1196                 { TV_WAND, SV_WAND_DISARMING },
1197
1198                 { TV_STAFF, SV_STAFF_LITE },
1199                 { TV_STAFF, SV_STAFF_MAPPING },
1200                 { TV_STAFF, SV_STAFF_DETECT_TRAP },
1201                 { TV_STAFF, SV_STAFF_DETECT_DOOR },
1202
1203                 { TV_STAFF, SV_STAFF_DETECT_GOLD },
1204                 { TV_STAFF, SV_STAFF_DETECT_ITEM },
1205                 { TV_STAFF, SV_STAFF_DETECT_INVIS },
1206                 { TV_STAFF, SV_STAFF_DETECT_EVIL },
1207
1208                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1209                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1210                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1211                 { TV_STAFF, SV_STAFF_TELEPORTATION },
1212
1213                 { TV_STAFF, SV_STAFF_IDENTIFY },
1214                 { TV_STAFF, SV_STAFF_IDENTIFY },
1215                 { TV_STAFF, SV_STAFF_IDENTIFY },
1216
1217                 { TV_STAFF, SV_STAFF_IDENTIFY },
1218                 { TV_STAFF, SV_STAFF_REMOVE_CURSE },
1219                 { TV_STAFF, SV_STAFF_CURE_LIGHT },
1220                 { TV_STAFF, SV_STAFF_PROBING },
1221
1222                 { TV_FIGURINE, 0 },
1223
1224                 { TV_SORCERY_BOOK, 0 },
1225                 { TV_SORCERY_BOOK, 0 },
1226                 { TV_SORCERY_BOOK, 1 },
1227                 { TV_SORCERY_BOOK, 1 },
1228
1229                 { TV_ARCANE_BOOK, 0 },
1230                 { TV_ARCANE_BOOK, 0 },
1231                 { TV_ARCANE_BOOK, 1 },
1232                 { TV_ARCANE_BOOK, 1 },
1233
1234                 { TV_ARCANE_BOOK, 2 },
1235                 { TV_ARCANE_BOOK, 2 },
1236                 { TV_ARCANE_BOOK, 3 },
1237                 { TV_ARCANE_BOOK, 3 },
1238
1239         },
1240
1241         {
1242                 /* Black Market (unused) */
1243                 { 0, 0 },
1244                 { 0, 0 },
1245                 { 0, 0 },
1246                 { 0, 0 },
1247                 { 0, 0 },
1248                 { 0, 0 },
1249                 { 0, 0 },
1250                 { 0, 0 },
1251                 { 0, 0 },
1252                 { 0, 0 },
1253                 { 0, 0 },
1254                 { 0, 0 },
1255                 { 0, 0 },
1256                 { 0, 0 },
1257                 { 0, 0 },
1258                 { 0, 0 },
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         },
1276
1277         {
1278                 /* Home (unused) */
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                 { 0, 0 },
1292                 { 0, 0 },
1293                 { 0, 0 },
1294                 { 0, 0 },
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         },
1312
1313         {
1314                 /* Bookstore */
1315                 { TV_SORCERY_BOOK, 0 },
1316                 { TV_SORCERY_BOOK, 0 },
1317                 { TV_SORCERY_BOOK, 1 },
1318                 { TV_SORCERY_BOOK, 1 },
1319
1320                 { TV_NATURE_BOOK, 0 },
1321                 { TV_NATURE_BOOK, 0 },
1322                 { TV_NATURE_BOOK, 1 },
1323                 { TV_NATURE_BOOK, 1 },
1324
1325                 { TV_CHAOS_BOOK, 0 },
1326                 { TV_CHAOS_BOOK, 0 },
1327                 { TV_CHAOS_BOOK, 1 },
1328                 { TV_CHAOS_BOOK, 1 },
1329
1330                 { TV_DEATH_BOOK, 0 },
1331                 { TV_DEATH_BOOK, 0 },
1332                 { TV_DEATH_BOOK, 1 },
1333                 { TV_DEATH_BOOK, 1 },
1334
1335                 { TV_TRUMP_BOOK, 0 },           /* +16 */
1336                 { TV_TRUMP_BOOK, 0 },
1337                 { TV_TRUMP_BOOK, 1 },
1338                 { TV_TRUMP_BOOK, 1 },
1339
1340                 { TV_ARCANE_BOOK, 0 },
1341                 { TV_ARCANE_BOOK, 1 },
1342                 { TV_ARCANE_BOOK, 2 },
1343                 { TV_ARCANE_BOOK, 3 },
1344
1345                 { TV_ENCHANT_BOOK, 0 },
1346                 { TV_ENCHANT_BOOK, 0 },
1347                 { TV_ENCHANT_BOOK, 1 },
1348                 { TV_ENCHANT_BOOK, 1 },
1349
1350                 { TV_DAEMON_BOOK, 0 },
1351                 { TV_DAEMON_BOOK, 0 },
1352                 { TV_DAEMON_BOOK, 1 },
1353                 { TV_DAEMON_BOOK, 1 },
1354
1355                 { TV_MUSIC_BOOK, 0 },
1356                 { TV_MUSIC_BOOK, 0 },
1357                 { TV_MUSIC_BOOK, 1 },
1358                 { TV_MUSIC_BOOK, 1 },
1359         },
1360
1361         {
1362                 /* Museum (unused) */
1363                 { 0, 0 },
1364                 { 0, 0 },
1365                 { 0, 0 },
1366                 { 0, 0 },
1367                 { 0, 0 },
1368                 { 0, 0 },
1369                 { 0, 0 },
1370                 { 0, 0 },
1371                 { 0, 0 },
1372                 { 0, 0 },
1373                 { 0, 0 },
1374                 { 0, 0 },
1375                 { 0, 0 },
1376                 { 0, 0 },
1377                 { 0, 0 },
1378                 { 0, 0 },
1379                 { 0, 0 },
1380                 { 0, 0 },
1381                 { 0, 0 },
1382                 { 0, 0 },
1383                 { 0, 0 },
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         }
1396 };
1397
1398
1399 /*
1400  * Initialize misc. values
1401  */
1402 static errr init_misc(void)
1403 {
1404         /* Initialize the values */
1405         process_dungeon_file("misc_j.txt", 0, 0, 0, 0);
1406
1407         return 0;
1408 }
1409
1410
1411 /*
1412  * Initialize town array
1413  */
1414 static errr init_towns(void)
1415 {
1416         int i, j, k;
1417
1418         /*** Prepare the Towns ***/
1419
1420         /* Allocate the towns */
1421         C_MAKE(town, max_towns, town_type);
1422
1423         for (i = 1; i < max_towns; i++)
1424         {
1425                 /*** Prepare the Stores ***/
1426
1427                 /* Allocate the stores */
1428                 C_MAKE(town[i].store, MAX_STORES, store_type);
1429
1430                 /* Fill in each store */
1431                 for (j = 0; j < MAX_STORES; j++)
1432                 {
1433                         /* Access the store */
1434                         store_type *st_ptr = &town[i].store[j];
1435
1436                         if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
1437
1438                         /* Assume full stock */
1439
1440                 /*
1441                  * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë±£¤·µ¡Ç½¤Î¤¿¤á¤Î½àÈ÷¡£
1442                  * ¥ª¥×¥·¥ç¥ó¤¬Í­¸ú¤Ç¤â¤½¤¦¤Ç¤Ê¤¯¤Æ¤â°ì±þ¥¹¥Ú¡¼¥¹
1443                  * ¤òºî¤Ã¤Æ¤ª¤¯¡£
1444                  */
1445                 if (j == STORE_HOME)
1446                 {
1447                         st_ptr->stock_size = (STORE_INVEN_MAX * 10);
1448                 }
1449                 else if (j == STORE_MUSEUM)
1450                 {
1451                         st_ptr->stock_size = (STORE_INVEN_MAX * 50);
1452                 }
1453                 else
1454                 {
1455                         st_ptr->stock_size = STORE_INVEN_MAX;
1456                 }
1457
1458
1459                         /* Allocate the stock */
1460                         C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
1461
1462                         /* No table for the black market or home */
1463                         if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
1464
1465                         /* Assume full table */
1466                         st_ptr->table_size = STORE_CHOICES;
1467
1468                         /* Allocate the stock */
1469                         C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
1470
1471                         /* Scan the choices */
1472                         for (k = 0; k < STORE_CHOICES; k++)
1473                         {
1474                                 int k_idx;
1475
1476                                 /* Extract the tval/sval codes */
1477                                 int tv = store_table[j][k][0];
1478                                 int sv = store_table[j][k][1];
1479
1480                                 /* Look for it */
1481                                 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
1482                                 {
1483                                         object_kind *k_ptr = &k_info[k_idx];
1484
1485                                         /* Found a match */
1486                                         if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
1487                                 }
1488
1489                                 /* Catch errors */
1490                                 if (k_idx == max_k_idx) continue;
1491
1492                                 /* Add that item index to the table */
1493                                 st_ptr->table[st_ptr->table_num++] = k_idx;
1494                         }
1495                 }
1496         }
1497
1498         return 0;
1499 }
1500
1501 /*
1502  * Initialize buildings
1503  */
1504 errr init_buildings(void)
1505 {
1506         int i, j;
1507
1508         for (i = 0; i < MAX_BLDG; i++)
1509         {
1510                 building[i].name[0] = '\0';
1511                 building[i].owner_name[0] = '\0';
1512                 building[i].owner_race[0] = '\0';
1513
1514                 for (j = 0; j < 8; j++)
1515                 {
1516                         building[i].act_names[j][0] = '\0';
1517                         building[i].member_costs[j] = 0;
1518                         building[i].other_costs[j] = 0;
1519                         building[i].letters[j] = 0;
1520                         building[i].actions[j] = 0;
1521                         building[i].action_restr[j] = 0;
1522                 }
1523
1524                 for (j = 0; j < MAX_CLASS; j++)
1525                 {
1526                         building[i].member_class[j] = 0;
1527                 }
1528
1529                 for (j = 0; j < MAX_RACES; j++)
1530                 {
1531                         building[i].member_race[j] = 0;
1532                 }
1533
1534                 for (j = 0; j < MAX_MAGIC+1; j++)
1535                 {
1536                         building[i].member_realm[j] = 0;
1537                 }
1538         }
1539
1540         return (0);
1541 }
1542
1543
1544 /*
1545  * Initialize quest array
1546  */
1547 static errr init_quests(void)
1548 {
1549         int i;
1550
1551         /*** Prepare the quests ***/
1552
1553         /* Allocate the quests */
1554         C_MAKE(quest, max_quests, quest_type);
1555
1556         /* Set all quest to "untaken" */
1557         for (i = 0; i < max_quests; i++)
1558         {
1559                 quest[i].status = QUEST_STATUS_UNTAKEN;
1560         }
1561
1562         return 0;
1563 }
1564
1565
1566 /*
1567  * Initialize some other arrays
1568  */
1569 static errr init_other(void)
1570 {
1571         int i, n;
1572
1573
1574         /*** Prepare the "dungeon" information ***/
1575
1576         /* Allocate and Wipe the object list */
1577         C_MAKE(o_list, max_o_idx, object_type);
1578
1579         /* Allocate and Wipe the monster list */
1580         C_MAKE(m_list, max_m_idx, monster_type);
1581
1582         /* Allocate and Wipe the max dungeon level */
1583         C_MAKE(max_dlv, max_d_idx, s16b);
1584
1585         /* Allocate and wipe each line of the cave */
1586         for (i = 0; i < MAX_HGT; i++)
1587         {
1588                 /* Allocate one row of the cave */
1589                 C_MAKE(cave[i], MAX_WID, cave_type);
1590         }
1591
1592
1593         /*** Prepare the various "bizarre" arrays ***/
1594
1595         /* Macro variables */
1596         C_MAKE(macro__pat, MACRO_MAX, cptr);
1597         C_MAKE(macro__act, MACRO_MAX, cptr);
1598         C_MAKE(macro__cmd, MACRO_MAX, bool);
1599
1600         /* Macro action buffer */
1601         C_MAKE(macro__buf, 1024, char);
1602
1603         /* Quark variables */
1604         C_MAKE(quark__str, QUARK_MAX, cptr);
1605
1606         /* Message variables */
1607         C_MAKE(message__ptr, MESSAGE_MAX, u16b);
1608         C_MAKE(message__buf, MESSAGE_BUF, char);
1609
1610         /* Hack -- No messages yet */
1611         message__tail = MESSAGE_BUF;
1612
1613
1614         /*** Prepare the Player inventory ***/
1615
1616         /* Allocate it */
1617         C_MAKE(inventory, INVEN_TOTAL, object_type);
1618
1619
1620         /*** Pre-allocate the basic "auto-inscriptions" ***/
1621
1622         /* The "basic" feelings */
1623 #ifdef JP
1624         (void)quark_add("¼ö¤ï¤ì¤Æ¤¤¤ë");
1625         (void)quark_add("²õ¤ì¤Æ¤¤¤ë");
1626         (void)quark_add("ÊÂ");
1627         (void)quark_add("¾å¼Á");
1628 #else
1629         (void)quark_add("cursed");
1630         (void)quark_add("broken");
1631         (void)quark_add("average");
1632         (void)quark_add("good");
1633 #endif
1634
1635
1636         /* The "extra" feelings */
1637 #ifdef JP
1638         (void)quark_add("¹âµéÉÊ");
1639         (void)quark_add("̵²ÁÃÍ");
1640         (void)quark_add("ÆÃÊÌÀ½");
1641         (void)quark_add("¶²¤í¤·¤¤");
1642 #else
1643         (void)quark_add("excellent");
1644         (void)quark_add("worthless");
1645         (void)quark_add("special");
1646         (void)quark_add("terrible");
1647 #endif
1648
1649
1650         /* Some extra strings */
1651 #ifdef JP
1652         (void)quark_add("¼ö¤¤¤Ê¤·");
1653         (void)quark_add("Çä½ÐÃæ");
1654 #else
1655         (void)quark_add("uncursed");
1656         (void)quark_add("on sale");
1657 #endif
1658
1659
1660
1661         /*** Prepare the options ***/
1662
1663         /* Scan the options */
1664         for (i = 0; option_info[i].o_desc; i++)
1665         {
1666                 int os = option_info[i].o_set;
1667                 int ob = option_info[i].o_bit;
1668
1669                 /* Set the "default" options */
1670                 if (option_info[i].o_var)
1671                 {
1672                         /* Accept */
1673                         option_mask[os] |= (1L << ob);
1674
1675                         /* Set */
1676                         if (option_info[i].o_norm)
1677                         {
1678                                 /* Set */
1679                                 option_flag[os] |= (1L << ob);
1680                         }
1681
1682                         /* Clear */
1683                         else
1684                         {
1685                                 /* Clear */
1686                                 option_flag[os] &= ~(1L << ob);
1687                         }
1688                 }
1689         }
1690
1691         /* Analyze the windows */
1692         for (n = 0; n < 8; n++)
1693         {
1694                 /* Analyze the options */
1695                 for (i = 0; i < 32; i++)
1696                 {
1697                         /* Accept */
1698                         if (window_flag_desc[i])
1699                         {
1700                                 /* Accept */
1701                                 window_mask[n] |= (1L << i);
1702                         }
1703                 }
1704         }
1705
1706
1707         /*** Pre-allocate space for the "format()" buffer ***/
1708
1709         /* Hack -- Just call the "format()" function */
1710         (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1711
1712
1713         /* Success */
1714         return (0);
1715 }
1716
1717
1718
1719 /*
1720  * Initialize some other arrays
1721  */
1722 static errr init_alloc(void)
1723 {
1724         int i;
1725         monster_race *r_ptr;
1726
1727 #ifdef SORT_R_INFO
1728
1729         tag_type *elements;
1730
1731         /* Allocate the "r_info" array */
1732         C_MAKE(elements, max_r_idx, tag_type);
1733
1734         /* Scan the monsters */
1735         for (i = 1; i < max_r_idx; i++)
1736         {
1737                 elements[i].tag = r_info[i].level;
1738                 elements[i].pointer = (void*)i;
1739         }
1740
1741         tag_sort(elements, max_r_idx);
1742
1743         /*** Initialize monster allocation info ***/
1744
1745         /* Size of "alloc_race_table" */
1746         alloc_race_size = max_r_idx;
1747
1748         /* Allocate the alloc_race_table */
1749         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1750
1751         /* Scan the monsters */
1752         for (i = 1; i < max_r_idx; i++)
1753         {
1754                 /* Get the i'th race */
1755                 r_ptr = &r_info[(int)elements[i].pointer];
1756
1757                 /* Count valid pairs */
1758                 if (r_ptr->rarity)
1759                 {
1760                         int p, x;
1761
1762                         /* Extract the base level */
1763                         x = r_ptr->level;
1764
1765                         /* Extract the base probability */
1766                         p = (100 / r_ptr->rarity);
1767
1768                         /* Load the entry */
1769                         alloc_race_table[i].index = (int)elements[i].pointer;
1770                         alloc_race_table[i].level = x;
1771                         alloc_race_table[i].prob1 = p;
1772                         alloc_race_table[i].prob2 = p;
1773                         alloc_race_table[i].prob3 = p;
1774                 }
1775         }
1776
1777 #else /* SORT_R_INFO */
1778
1779         int j;
1780         alloc_entry *table;
1781         s16b num[MAX_DEPTH];
1782         s16b aux[MAX_DEPTH];
1783
1784         /*** Analyze monster allocation info ***/
1785
1786         /* Clear the "aux" array */
1787         C_WIPE(&aux, MAX_DEPTH, s16b);
1788
1789         /* Clear the "num" array */
1790         C_WIPE(&num, MAX_DEPTH, s16b);
1791
1792         /* Size of "alloc_race_table" */
1793         alloc_race_size = 0;
1794
1795         /* Scan the monsters */
1796         for (i = 1; i < max_r_idx; i++)
1797         {
1798                 /* Get the i'th race */
1799                 r_ptr = &r_info[i];
1800
1801                 /* Legal monsters */
1802                 if (r_ptr->rarity)
1803                 {
1804                         /* Count the entries */
1805                         alloc_race_size++;
1806
1807                         /* Group by level */
1808                         num[r_ptr->level]++;
1809                 }
1810         }
1811
1812         /* Collect the level indexes */
1813         for (i = 1; i < MAX_DEPTH; i++)
1814         {
1815                 /* Group by level */
1816                 num[i] += num[i-1];
1817         }
1818
1819         /* Paranoia */
1820 #ifdef JP
1821         if (!num[0]) quit("Ä®¤Î¥â¥ó¥¹¥¿¡¼¤¬¤Ê¤¤¡ª");
1822 #else
1823         if (!num[0]) quit("No town monsters!");
1824 #endif
1825
1826
1827
1828         /*** Initialize monster allocation info ***/
1829
1830         /* Allocate the alloc_race_table */
1831         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1832
1833         /* Access the table entry */
1834         table = alloc_race_table;
1835
1836         /* Scan the monsters */
1837         for (i = 1; i < max_r_idx; i++)
1838         {
1839                 /* Get the i'th race */
1840                 r_ptr = &r_info[i];
1841
1842                 /* Count valid pairs */
1843                 if (r_ptr->rarity)
1844                 {
1845                         int p, x, y, z;
1846
1847                         /* Extract the base level */
1848                         x = r_ptr->level;
1849
1850                         /* Extract the base probability */
1851                         p = (100 / r_ptr->rarity);
1852
1853                         /* Skip entries preceding our locale */
1854                         y = (x > 0) ? num[x-1] : 0;
1855
1856                         /* Skip previous entries at this locale */
1857                         z = y + aux[x];
1858
1859                         /* Load the entry */
1860                         table[z].index = i;
1861                         table[z].level = x;
1862                         table[z].prob1 = p;
1863                         table[z].prob2 = p;
1864                         table[z].prob3 = p;
1865
1866                         /* Another entry complete for this locale */
1867                         aux[x]++;
1868                 }
1869         }
1870
1871 #endif /* SORT_R_INFO */
1872
1873         /* Init the "alloc_kind_table" */
1874         (void)init_object_alloc();
1875
1876         /* Success */
1877         return (0);
1878 }
1879
1880
1881
1882 /*
1883  * Hack -- take notes on line 23
1884  */
1885 static void note(cptr str)
1886 {
1887         Term_erase(0, 23, 255);
1888         Term_putstr(20, 23, -1, TERM_WHITE, str);
1889         Term_fresh();
1890 }
1891
1892
1893
1894 /*
1895  * Hack -- Explain a broken "lib" folder and quit (see below).
1896  *
1897  * XXX XXX XXX This function is "messy" because various things
1898  * may or may not be initialized, but the "plog()" and "quit()"
1899  * functions are "supposed" to work under any conditions.
1900  */
1901 static void init_angband_aux(cptr why)
1902 {
1903         /* Why */
1904         plog(why);
1905
1906 #ifdef JP
1907         /* Explain */
1908         plog("'lib'¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¤«²õ¤ì¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£");
1909
1910         /* More details */
1911         plog("¤Ò¤ç¤Ã¤È¤¹¤ë¤È¥¢¡¼¥«¥¤¥Ö¤¬Àµ¤·¤¯²òÅव¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡£");
1912
1913         /* Explain */
1914         plog("³ºÅö¤¹¤ë'README'¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç³Îǧ¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡£");
1915
1916         /* Quit with error */
1917         quit("Ã×̿Ū¤Ê¥¨¥é¡¼¡£");
1918 #else
1919         /* Explain */
1920         plog("The 'lib' directory is probably missing or broken.");
1921
1922         /* More details */
1923         plog("Perhaps the archive was not extracted correctly.");
1924
1925         /* Explain */
1926         plog("See the 'README' file for more information.");
1927
1928         /* Quit with error */
1929         quit("Fatal Error.");
1930 #endif
1931
1932 }
1933
1934
1935 /*
1936  * Hack -- main Angband initialization entry point
1937  *
1938  * Verify some files, display the "news.txt" file, create
1939  * the high score file, initialize all internal arrays, and
1940  * load the basic "user pref files".
1941  *
1942  * Be very careful to keep track of the order in which things
1943  * are initialized, in particular, the only thing *known* to
1944  * be available when this function is called is the "z-term.c"
1945  * package, and that may not be fully initialized until the
1946  * end of this function, when the default "user pref files"
1947  * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1948  *
1949  * Note that this function attempts to verify the "news" file,
1950  * and the game aborts (cleanly) on failure, since without the
1951  * "news" file, it is likely that the "lib" folder has not been
1952  * correctly located.  Otherwise, the news file is displayed for
1953  * the user.
1954  *
1955  * Note that this function attempts to verify (or create) the
1956  * "high score" file, and the game aborts (cleanly) on failure,
1957  * since one of the most common "extraction" failures involves
1958  * failing to extract all sub-directories (even empty ones), such
1959  * as by failing to use the "-d" option of "pkunzip", or failing
1960  * to use the "save empty directories" option with "Compact Pro".
1961  * This error will often be caught by the "high score" creation
1962  * code below, since the "lib/apex" directory, being empty in the
1963  * standard distributions, is most likely to be "lost", making it
1964  * impossible to create the high score file.
1965  *
1966  * Note that various things are initialized by this function,
1967  * including everything that was once done by "init_some_arrays".
1968  *
1969  * This initialization involves the parsing of special files
1970  * in the "lib/data" and sometimes the "lib/edit" directories.
1971  *
1972  * Note that the "template" files are initialized first, since they
1973  * often contain errors.  This means that macros and message recall
1974  * and things like that are not available until after they are done.
1975  *
1976  * We load the default "user pref files" here in case any "color"
1977  * changes are needed before character creation.
1978  *
1979  * Note that the "graf-xxx.prf" file must be loaded separately,
1980  * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1981  */
1982 void init_angband(void)
1983 {
1984         int fd = -1;
1985
1986         int mode = 0644;
1987
1988         FILE *fp;
1989
1990         char buf[1024];
1991
1992
1993         /*** Verify the "news" file ***/
1994
1995         /* Build the filename */
1996 #ifdef JP
1997         path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
1998 #else
1999         path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
2000 #endif
2001
2002
2003         /* Attempt to open the file */
2004         fd = fd_open(buf, O_RDONLY);
2005
2006         /* Failure */
2007         if (fd < 0)
2008         {
2009                 char why[1024];
2010
2011                 /* Message */
2012 #ifdef JP
2013         sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤Ç¤­¤Þ¤»¤ó!", buf);
2014 #else
2015                 sprintf(why, "Cannot access the '%s' file!", buf);
2016 #endif
2017
2018
2019                 /* Crash and burn */
2020                 init_angband_aux(why);
2021         }
2022
2023         /* Close it */
2024         (void)fd_close(fd);
2025
2026
2027         /*** Display the "news" file ***/
2028
2029         /* Clear screen */
2030         Term_clear();
2031
2032         /* Build the filename */
2033 #ifdef JP
2034         path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
2035 #else
2036         path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
2037 #endif
2038
2039
2040         /* Open the News file */
2041         fp = my_fopen(buf, "r");
2042
2043         /* Dump */
2044         if (fp)
2045         {
2046                 int i = 0;
2047
2048                 /* Dump the file to the screen */
2049                 while (0 == my_fgets(fp, buf, 1024))
2050                 {
2051                         /* Display and advance */
2052                         Term_putstr(0, i++, -1, TERM_WHITE, buf);
2053                 }
2054
2055                 /* Close */
2056                 my_fclose(fp);
2057         }
2058
2059         /* Flush it */
2060         Term_fresh();
2061
2062
2063         /*** Verify (or create) the "high score" file ***/
2064
2065         /* Build the filename */
2066         path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
2067
2068         /* Attempt to open the high score file */
2069         fd = fd_open(buf, O_RDONLY);
2070
2071         /* Failure */
2072         if (fd < 0)
2073         {
2074                 /* File type is "DATA" */
2075                 FILE_TYPE(FILE_TYPE_DATA);
2076
2077                 /* Create a new high score file */
2078                 fd = fd_make(buf, mode);
2079
2080                 /* Failure */
2081                 if (fd < 0)
2082                 {
2083                         char why[1024];
2084
2085                         /* Message */
2086 #ifdef JP
2087                         sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤­¤Þ¤»¤ó!", buf);
2088 #else
2089                         sprintf(why, "Cannot create the '%s' file!", buf);
2090 #endif
2091
2092
2093                         /* Crash and burn */
2094                         init_angband_aux(why);
2095                 }
2096         }
2097
2098         /* Close it */
2099         (void)fd_close(fd);
2100
2101
2102         /*** Initialize some arrays ***/
2103
2104         /* Initialize misc. values */
2105 #ifdef JP
2106 note("[ÊÑ¿ô¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...(¤½¤Î¾)");
2107 #else
2108         note("[Initializing values... (misc)]");
2109 #endif
2110
2111 #ifdef JP
2112 if (init_misc()) quit("¤½¤Î¾¤ÎÊÑ¿ô¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2113 #else
2114         if (init_misc()) quit("Cannot initialize misc. values");
2115 #endif
2116
2117
2118 #ifdef USE_SCRIPT
2119 #ifdef JP
2120 note("[¥¹¥¯¥ê¥×¥È¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... ]");
2121 #else
2122         note("[Initializing scripts... ]");
2123 #endif
2124
2125 #ifdef JP
2126 if (init_script()) quit("¥¹¥¯¥ê¥×¥È¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2127 #else
2128         if (init_script()) quit("Cannot initialize scripts");
2129 #endif
2130
2131 #endif /* USE_SCRIPT */
2132
2133         /* Initialize feature info */
2134 #ifdef JP
2135         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÃÏ·Á)]");
2136         if (init_f_info()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
2137 #else
2138         note("[Initializing arrays... (features)]");
2139         if (init_f_info()) quit("Cannot initialize features");
2140 #endif
2141
2142
2143         /* Initialize object info */
2144 #ifdef JP
2145         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥¤¥Æ¥à)]");
2146         if (init_k_info()) quit("¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2147 #else
2148         note("[Initializing arrays... (objects)]");
2149         if (init_k_info()) quit("Cannot initialize objects");
2150 #endif
2151
2152
2153         /* Initialize artifact info */
2154 #ifdef JP
2155         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÅÁÀâ¤Î¥¢¥¤¥Æ¥à)]");
2156         if (init_a_info()) quit("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2157 #else
2158         note("[Initializing arrays... (artifacts)]");
2159         if (init_a_info()) quit("Cannot initialize artifacts");
2160 #endif
2161
2162
2163         /* Initialize ego-item info */
2164 #ifdef JP
2165         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à)]");
2166         if (init_e_info()) quit("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2167 #else
2168         note("[Initializing arrays... (ego-items)]");
2169         if (init_e_info()) quit("Cannot initialize ego-items");
2170 #endif
2171
2172
2173         /* Initialize monster info */
2174 #ifdef JP
2175         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥â¥ó¥¹¥¿¡¼)]");
2176         if (init_r_info()) quit("¥â¥ó¥¹¥¿¡¼½é´ü²½ÉÔǽ");
2177 #else
2178         note("[Initializing arrays... (monsters)]");
2179         if (init_r_info()) quit("Cannot initialize monsters");
2180 #endif
2181
2182
2183         /* Initialize dungeon info */
2184 #ifdef JP
2185         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥À¥ó¥¸¥ç¥ó)]");
2186         if (init_d_info()) quit("¥À¥ó¥¸¥ç¥ó½é´ü²½ÉÔǽ");
2187 #else
2188         note("[Initializing arrays... (dungeon)]");
2189         if (init_d_info()) quit("Cannot initialize dungeon");
2190 #endif
2191         {
2192                 int i;
2193                 for (i = 1; i < max_d_idx; i++)
2194                         if (d_info[i].final_guardian)
2195                                 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
2196         }
2197
2198         /* Initialize magic info */
2199 #ifdef JP
2200         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ËâË¡)]");
2201         if (init_m_info()) quit("ËâË¡½é´ü²½ÉÔǽ");
2202 #else
2203         note("[Initializing arrays... (magic)]");
2204         if (init_m_info()) quit("Cannot initialize magic");
2205 #endif
2206
2207         /* Initialize weapon_exp info */
2208 #ifdef JP
2209         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (½ÏÎýÅÙ)]");
2210         if (init_s_info()) quit("½ÏÎýÅÙ½é´ü²½ÉÔǽ");
2211 #else
2212         note("[Initializing arrays... (skill)]");
2213         if (init_s_info()) quit("Cannot initialize skill");
2214 #endif
2215
2216         /* Initialize wilderness array */
2217 #ifdef JP
2218 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¹ÓÌî)]");
2219 #else
2220         note("[Initializing arrays... (wilderness)]");
2221 #endif
2222
2223 #ifdef JP
2224 if (init_wilderness()) quit("¹ÓÌî¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2225 #else
2226         if (init_wilderness()) quit("Cannot initialize wilderness");
2227 #endif
2228
2229
2230         /* Initialize town array */
2231 #ifdef JP
2232 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (³¹)]");
2233 #else
2234         note("[Initializing arrays... (towns)]");
2235 #endif
2236
2237 #ifdef JP
2238 if (init_towns()) quit("³¹¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2239 #else
2240         if (init_towns()) quit("Cannot initialize towns");
2241 #endif
2242
2243
2244         /* Initialize building array */
2245 #ifdef JP
2246 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (·úʪ)]");
2247 #else
2248         note("[Initializing arrays... (buildings)]");
2249 #endif
2250
2251 #ifdef JP
2252 if (init_buildings()) quit("·úʪ¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2253 #else
2254         if (init_buildings()) quit("Cannot initialize buildings");
2255 #endif
2256
2257
2258         /* Initialize quest array */
2259 #ifdef JP
2260 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¥¯¥¨¥¹¥È)]");
2261 #else
2262         note("[Initializing arrays... (quests)]");
2263 #endif
2264
2265 #ifdef JP
2266 if (init_quests()) quit("¥¯¥¨¥¹¥È¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
2267 #else
2268         if (init_quests()) quit("Cannot initialize quests");
2269 #endif
2270
2271
2272         /* Initialize some other arrays */
2273 #ifdef JP
2274         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¤½¤Î¾)]");
2275         if (init_other()) quit("¤½¤Î¾¤Î¥Ç¡¼¥¿½é´ü²½ÉÔǽ");
2276 #else
2277         note("[Initializing arrays... (other)]");
2278         if (init_other()) quit("Cannot initialize other stuff");
2279 #endif
2280
2281
2282         /* Initialize some other arrays */
2283 #ifdef JP
2284         /* translation */
2285         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥í¥±¡¼¥·¥ç¥ó)]");
2286         if (init_alloc()) quit("¥¢¥í¥±¡¼¥·¥ç¥ó¡¦¥¹¥¿¥Ã¥Õ½é´ü²½ÉÔǽ");
2287 #else
2288         note("[Initializing arrays... (alloc)]");
2289         if (init_alloc()) quit("Cannot initialize alloc stuff");
2290 #endif
2291
2292
2293
2294         /*** Load default user pref files ***/
2295
2296         /* Initialize feature info */
2297 #ifdef JP
2298 note("[¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...]");
2299 #else
2300         note("[Initializing user pref files...]");
2301 #endif
2302
2303
2304         /* Access the "basic" pref file */
2305         strcpy(buf, "pref.prf");
2306
2307         /* Process that file */
2308         process_pref_file(buf);
2309
2310         /* Access the "user" pref file */
2311         sprintf(buf, "user.prf");
2312
2313         /* Process that file */
2314         process_pref_file(buf);
2315
2316         /* Access the "basic" system pref file */
2317         sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
2318
2319         /* Process that file */
2320         process_pref_file(buf);
2321
2322         /* Access the "user" system pref file */
2323         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
2324
2325         /* Process that file */
2326         process_pref_file(buf);
2327
2328         /* Done */
2329 #ifdef JP
2330         note("[½é´ü²½½ªÎ»]");
2331 #else
2332         note("[Initialization complete]");
2333 #endif
2334
2335 }