OSDN Git Service

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