OSDN Git Service

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