OSDN Git Service

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