OSDN Git Service

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