OSDN Git Service

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