OSDN Git Service

branch-habu-tables-improveザ、ヌ、ホハムケケ、エ、ヒ・゙。シ・ク。」
[hengband/hengband.git] / src / init2.c
1 /* File: init2.c */
2
3 /* Purpose: Initialization (part 2) -BEN- */
4
5 #include "angband.h"
6
7 #ifndef MACINTOSH
8 #ifdef CHECK_MODIFICATION_TIME
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #endif /* CHECK_MODIFICATION_TIME */
12 #endif
13
14 /*
15  * This file is used to initialize various variables and arrays for the
16  * Angband game.  Note the use of "fd_read()" and "fd_write()" to bypass
17  * the common limitation of "read()" and "write()" to only 32767 bytes
18  * at a time.
19  *
20  * Several of the arrays for Angband are built from "template" files in
21  * the "lib/file" directory, from which quick-load binary "image" files
22  * are constructed whenever they are not present in the "lib/data"
23  * directory, or if those files become obsolete, if we are allowed.
24  *
25  * Warning -- the "ascii" file parsers use a minor hack to collect the
26  * name and text information in a single pass.  Thus, the game will not
27  * be able to load any template file with more than 20K of names or 60K
28  * of text, even though technically, up to 64K should be legal.
29  *
30  * The "init1.c" file is used only to parse the ascii template files,
31  * to create the binary image files.  If you include the binary image
32  * files instead of the ascii template files, then you can undefine
33  * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c".  Note
34  * that the binary image files are extremely system dependant.
35  */
36
37
38
39 /*
40  * Find the default paths to all of our important sub-directories.
41  *
42  * The purpose of each sub-directory is described in "variable.c".
43  *
44  * All of the sub-directories should, by default, be located inside
45  * the main "lib" directory, whose location is very system dependant.
46  *
47  * This function takes a writable buffer, initially containing the
48  * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
49  * or a system dependant string, for example, ":lib:".  The buffer
50  * must be large enough to contain at least 32 more characters.
51  *
52  * Various command line options may allow some of the important
53  * directories to be changed to user-specified directories, most
54  * importantly, the "info" and "user" and "save" directories,
55  * but this is done after this function, see "main.c".
56  *
57  * In general, the initial path should end in the appropriate "PATH_SEP"
58  * string.  All of the "sub-directory" paths (created below or supplied
59  * by the user) will NOT end in the "PATH_SEP" string, see the special
60  * "path_build()" function in "util.c" for more information.
61  *
62  * Mega-Hack -- support fat raw files under NEXTSTEP, using special
63  * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
64  * requiring the directories to be created by hand by the user.
65  *
66  * Hack -- first we free all the strings, since this is known
67  * to succeed even if the strings have not been allocated yet,
68  * as long as the variables start out as "NULL".  This allows
69  * this function to be called multiple times, for example, to
70  * try several base "path" values until a good one is found.
71  */
72 void init_file_paths(char *path)
73 {
74         char *tail;
75
76 #ifdef PRIVATE_USER_PATH
77         char buf[1024];
78 #endif /* PRIVATE_USER_PATH */
79
80         /*** Free everything ***/
81
82         /* Free the main path */
83         string_free(ANGBAND_DIR);
84
85         /* Free the sub-paths */
86         string_free(ANGBAND_DIR_APEX);
87         string_free(ANGBAND_DIR_BONE);
88         string_free(ANGBAND_DIR_DATA);
89         string_free(ANGBAND_DIR_EDIT);
90         string_free(ANGBAND_DIR_SCRIPT);
91         string_free(ANGBAND_DIR_FILE);
92         string_free(ANGBAND_DIR_HELP);
93         string_free(ANGBAND_DIR_INFO);
94         string_free(ANGBAND_DIR_SAVE);
95         string_free(ANGBAND_DIR_USER);
96         string_free(ANGBAND_DIR_XTRA);
97
98
99         /*** Prepare the "path" ***/
100
101         /* Hack -- save the main directory */
102         ANGBAND_DIR = string_make(path);
103
104         /* Prepare to append to the Base Path */
105         tail = path + strlen(path);
106
107
108 #ifdef VM
109
110         /*** Use "flat" paths with VM/ESA ***/
111
112         /* Use "blank" path names */
113         ANGBAND_DIR_APEX = string_make("");
114         ANGBAND_DIR_BONE = string_make("");
115         ANGBAND_DIR_DATA = string_make("");
116         ANGBAND_DIR_EDIT = string_make("");
117         ANGBAND_DIR_SCRIPT = string_make("");
118         ANGBAND_DIR_FILE = string_make("");
119         ANGBAND_DIR_HELP = string_make("");
120         ANGBAND_DIR_INFO = string_make("");
121         ANGBAND_DIR_SAVE = string_make("");
122         ANGBAND_DIR_USER = string_make("");
123         ANGBAND_DIR_XTRA = string_make("");
124
125
126 #else /* VM */
127
128
129         /*** Build the sub-directory names ***/
130
131         /* Build a path name */
132         strcpy(tail, "apex");
133         ANGBAND_DIR_APEX = string_make(path);
134
135         /* Build a path name */
136         strcpy(tail, "bone");
137         ANGBAND_DIR_BONE = string_make(path);
138
139         /* Build a path name */
140         strcpy(tail, "data");
141         ANGBAND_DIR_DATA = string_make(path);
142
143         /* Build a path name */
144         strcpy(tail, "edit");
145         ANGBAND_DIR_EDIT = string_make(path);
146
147         /* Build a path name */
148         strcpy(tail, "script");
149         ANGBAND_DIR_SCRIPT = string_make(path);
150
151         /* Build a path name */
152         strcpy(tail, "file");
153         ANGBAND_DIR_FILE = string_make(path);
154
155         /* Build a path name */
156         strcpy(tail, "help");
157         ANGBAND_DIR_HELP = string_make(path);
158
159         /* Build a path name */
160         strcpy(tail, "info");
161         ANGBAND_DIR_INFO = string_make(path);
162
163         /* Build a path name */
164         strcpy(tail, "pref");
165         ANGBAND_DIR_PREF = string_make(path);
166
167         /* Build a path name */
168         strcpy(tail, "save");
169         ANGBAND_DIR_SAVE = string_make(path);
170
171 #ifdef PRIVATE_USER_PATH
172
173         /* Build the path to the user specific directory */
174         path_build(buf, 1024, PRIVATE_USER_PATH, VERSION_NAME);
175
176         /* Build a relative path name */
177         ANGBAND_DIR_USER = string_make(buf);
178
179 #else /* PRIVATE_USER_PATH */
180
181         /* Build a path name */
182         strcpy(tail, "user");
183         ANGBAND_DIR_USER = string_make(path);
184
185 #endif /* PRIVATE_USER_PATH */
186
187         /* Build a path name */
188         strcpy(tail, "xtra");
189         ANGBAND_DIR_XTRA = string_make(path);
190
191 #endif /* VM */
192
193
194 #ifdef NeXT
195
196         /* Allow "fat binary" usage with NeXT */
197         if (TRUE)
198         {
199                 cptr next = NULL;
200
201 # if defined(m68k)
202                 next = "m68k";
203 # endif
204
205 # if defined(i386)
206                 next = "i386";
207 # endif
208
209 # if defined(sparc)
210                 next = "sparc";
211 # endif
212
213 # if defined(hppa)
214                 next = "hppa";
215 # endif
216
217                 /* Use special directory */
218                 if (next)
219                 {
220                         /* Forget the old path name */
221                         string_free(ANGBAND_DIR_DATA);
222
223                         /* Build a new path name */
224                         sprintf(tail, "data-%s", next);
225                         ANGBAND_DIR_DATA = string_make(path);
226                 }
227         }
228
229 #endif /* NeXT */
230
231 }
232
233
234
235 #ifdef ALLOW_TEMPLATES
236
237
238 /*
239  * Hack -- help give useful error messages
240  */
241 s16b error_idx;
242 s16b error_line;
243
244
245 /*
246  * Hack -- help initialize the fake "name" and "text" arrays when
247  * parsing an "ascii" template file.
248  */
249 u32b fake_name_size;
250 #ifdef JP
251 u32b E_fake_name_size;
252 #endif
253 u32b fake_text_size;
254
255
256 /*
257  * Standard error message text
258  */
259 cptr err_str[PARSE_ERROR_MAX] =
260 {
261         NULL,
262 #ifdef JP
263         "ʸˡ¥¨¥é¡¼",
264         "¸Å¤¤¥Õ¥¡¥¤¥ë",
265         "µ­Ï¿¥Ø¥Ã¥À¤¬¤Ê¤¤",
266         "ÉÔϢ³¥ì¥³¡¼¥É",
267         "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
268         "̤ÄêµÁÌ¿Îá",
269         "¥á¥â¥êÉÔ­",
270         "ºÂɸÈϰϳ°",
271         "°ú¿ôÉÔ­",
272 #else
273         "parse error",
274         "obsolete file",
275         "missing record header",
276         "non-sequential records",
277         "invalid flag specification",
278         "undefined directive",
279         "out of memory",
280         "coordinates out of bounds",
281         "too few arguments",
282 #endif
283
284 };
285
286
287 #endif /* ALLOW_TEMPLATES */
288
289
290 #ifdef CHECK_MODIFICATION_TIME
291
292 static errr check_modification_date(int fd, cptr template_file)
293 {
294         char buf[1024];
295
296         struct stat txt_stat, raw_stat;
297
298         /* Build the filename */
299         path_build(buf, 1024, ANGBAND_DIR_EDIT, template_file);
300
301         /* Access stats on text file */
302         if (stat(buf, &txt_stat))
303         {
304                 /* No text file - continue */
305         }
306
307         /* Access stats on raw file */
308         else if (fstat(fd, &raw_stat))
309         {
310                 /* Error */
311                 return (-1);
312         }
313
314         /* Ensure text file is not newer than raw file */
315         else if (txt_stat.st_mtime > raw_stat.st_mtime)
316         {
317                 /* Reprocess text file */
318                 return (-1);
319         }
320
321         return (0);
322 }
323
324 #endif /* CHECK_MODIFICATION_TIME */
325
326
327
328 /*** Initialize from binary image files ***/
329
330
331 /*
332  * Initialize the "f_info" array, by parsing a binary "image" file
333  */
334 static errr init_f_info_raw(int fd)
335 {
336         header test;
337
338         /* Read and Verify the header */
339         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
340             (test.v_major != f_head->v_major) ||
341             (test.v_minor != f_head->v_minor) ||
342             (test.v_patch != f_head->v_patch) ||
343             (test.v_extra != f_head->v_extra) ||
344             (test.info_num != f_head->info_num) ||
345             (test.info_len != f_head->info_len) ||
346             (test.head_size != f_head->head_size) ||
347             (test.info_size != f_head->info_size))
348         {
349                 /* Error */
350                 return (-1);
351         }
352
353
354         /* Accept the header */
355         (*f_head) = test;
356
357
358         /* Allocate the "f_info" array */
359         C_MAKE(f_info, f_head->info_num, feature_type);
360
361         /* Read the "f_info" array */
362         fd_read(fd, (char*)(f_info), f_head->info_size);
363
364
365         /* Allocate the "f_name" array */
366         C_MAKE(f_name, f_head->name_size, char);
367
368         /* Read the "f_name" array */
369         fd_read(fd, (char*)(f_name), f_head->name_size);
370
371 #ifdef JP
372         /* ±Ñ¸ì̾ÍÑ */
373         /* Allocate the "E_f_name" array */
374         C_MAKE(E_f_name, f_head->E_name_size, char);
375
376         /* Read the "E_f_name" array */
377         fd_read(fd, (char*)(E_f_name), f_head->E_name_size);
378 #endif
379
380 #ifndef DELAY_LOAD_F_TEXT
381
382         /* Allocate the "f_text" array */
383         C_MAKE(f_text, f_head->text_size, char);
384
385         /* Read the "f_text" array */
386         fd_read(fd, (char*)(f_text), f_head->text_size);
387
388 #endif /* DELAY_LOAD_F_TEXT */
389
390
391         /* Success */
392         return (0);
393 }
394
395
396
397 /*
398  * Initialize the "f_info" array
399  *
400  * Note that we let each entry have a unique "name" and "text" string,
401  * even if the string happens to be empty (everyone has a unique '\0').
402  */
403 static errr init_f_info(void)
404 {
405         int fd;
406
407         int mode = 0644;
408
409         errr err = 0;
410
411         FILE *fp;
412
413         /* General buffer */
414         char buf[1024];
415
416
417         /*** Make the header ***/
418
419         /* Allocate the "header" */
420         MAKE(f_head, header);
421
422         /* Save the "version" */
423         f_head->v_major = FAKE_VER_MAJOR;
424         f_head->v_minor = FAKE_VER_MINOR;
425         f_head->v_patch = FAKE_VER_PATCH;
426         f_head->v_extra = 0;
427
428         /* Save the "record" information */
429         f_head->info_num = max_f_idx;
430         f_head->info_len = sizeof(feature_type);
431
432         /* Save the size of "f_head" and "f_info" */
433         f_head->head_size = sizeof(header);
434         f_head->info_size = f_head->info_num * f_head->info_len;
435
436
437 #ifdef ALLOW_TEMPLATES
438
439         /*** Load the binary image file ***/
440
441         /* Build the filename */
442 #ifdef JP
443         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info_j.raw");
444 #else
445         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
446 #endif
447
448
449         /* Attempt to open the "raw" file */
450         fd = fd_open(buf, O_RDONLY);
451
452         /* Process existing "raw" file */
453         if (fd >= 0)
454         {
455 #ifdef CHECK_MODIFICATION_TIME
456
457                 err = check_modification_date(fd, "f_info_j.txt");
458
459 #endif /* CHECK_MODIFICATION_TIME */
460
461                 /* Attempt to parse the "raw" file */
462                 if (!err)
463                         err = init_f_info_raw(fd);
464
465                 /* Close it */
466                 (void)fd_close(fd);
467
468                 /* Success */
469                 if (!err) return (0);
470         }
471
472
473         /*** Make the fake arrays ***/
474
475         /* Fake the size of "f_name" and "f_text" */
476         fake_name_size = FAKE_NAME_SIZE;
477 #ifdef JP
478         /* ±Ñ¸ì̾ÍÑ */
479         E_fake_name_size = FAKE_NAME_SIZE;
480 #endif
481         fake_text_size = FAKE_TEXT_SIZE;
482
483         /* Allocate the "f_info" array */
484         C_MAKE(f_info, f_head->info_num, feature_type);
485
486         /* Hack -- make "fake" arrays */
487         C_MAKE(f_name, fake_name_size, char);
488 #ifdef JP
489         /* ±Ñ¸ì̾ÍÑ */
490         C_MAKE(E_f_name, E_fake_name_size, char);
491 #endif
492         C_MAKE(f_text, fake_text_size, char);
493
494
495         /*** Load the ascii template file ***/
496
497         /* Build the filename */
498
499         path_build(buf, 1024, ANGBAND_DIR_EDIT, "f_info_j.txt");
500
501         /* Open the file */
502         fp = my_fopen(buf, "r");
503
504         /* Parse it */
505 #ifdef JP
506         if (!fp) quit("'f_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
507 #else
508         if (!fp) quit("Cannot open 'f_info.txt' file.");
509 #endif
510
511
512         /* Parse the file */
513         err = init_f_info_txt(fp, buf);
514
515         /* Close it */
516         my_fclose(fp);
517
518         /* Errors */
519         if (err)
520         {
521                 cptr oops;
522
523 #ifdef JP
524                 /* Error string */
525                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
526
527                 /* Oops */
528                 msg_format("'f_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
529                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
530                 msg_format("¹½Ê¸ '%s'¡£", buf);
531                 msg_print(NULL);
532
533                 /* Quit */
534                 quit("'f_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
535 #else
536                 /* Error string */
537                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
538
539                 /* Oops */
540                 msg_format("Error %d at line %d of 'f_info.txt'.", err, error_line);
541                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
542                 msg_format("Parsing '%s'.", buf);
543                 msg_print(NULL);
544
545                 /* Quit */
546                 quit("Error in 'f_info.txt' file.");
547 #endif
548
549         }
550
551
552         /*** Dump the binary image file ***/
553
554         /* File type is "DATA" */
555         FILE_TYPE(FILE_TYPE_DATA);
556
557         /* Build the filename */
558 #ifdef JP
559         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info_j.raw");
560 #else
561         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
562 #endif
563
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         /* Dump to the file */
572         if (fd >= 0)
573         {
574                 /* Dump it */
575                 fd_write(fd, (char*)(f_head), f_head->head_size);
576
577                 /* Dump the "f_info" array */
578                 fd_write(fd, (char*)(f_info), f_head->info_size);
579
580                 /* Dump the "f_name" array */
581                 fd_write(fd, (char*)(f_name), f_head->name_size);
582 #ifdef JP
583                 /* ±Ñ¸ì̾ÍÑ */
584                 /* Dump the "E_f_name" array */
585                 fd_write(fd, (char*)(E_f_name), f_head->E_name_size);
586 #endif
587
588                 /* Dump the "f_text" array */
589                 fd_write(fd, (char*)(f_text), f_head->text_size);
590
591                 /* Close */
592                 (void)fd_close(fd);
593         }
594
595
596         /*** Kill the fake arrays ***/
597
598         /* Free the "f_info" array */
599         C_KILL(f_info, f_head->info_num, feature_type);
600
601         /* Hack -- Free the "fake" arrays */
602         C_KILL(f_name, fake_name_size, char);
603 #ifdef JP
604         /* ±Ñ¸ì̾ÍÑ */
605         C_KILL(E_f_name, E_fake_name_size, char);
606 #endif
607         C_KILL(f_text, fake_text_size, char);
608
609         /* Forget the array sizes */
610         fake_name_size = 0;
611 #ifdef JP
612         /* ±Ñ¸ì̾ÍÑ */
613         E_fake_name_size = 0;
614 #endif
615         fake_text_size = 0;
616
617 #endif  /* ALLOW_TEMPLATES */
618
619
620         /*** Load the binary image file ***/
621
622         /* Build the filename */
623 #ifdef JP
624         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info_j.raw");
625 #else
626         path_build(buf, 1024, ANGBAND_DIR_DATA, "f_info.raw");
627 #endif
628
629
630         /* Attempt to open the "raw" file */
631         fd = fd_open(buf, O_RDONLY);
632
633         /* Process existing "raw" file */
634 #ifdef JP
635         if (fd < 0) quit("'f_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
636 #else
637         if (fd < 0) quit("Cannot load 'f_info.raw' file.");
638 #endif
639
640
641         /* Attempt to parse the "raw" file */
642         err = init_f_info_raw(fd);
643
644         /* Close it */
645         (void)fd_close(fd);
646
647         /* Error */
648 #ifdef JP
649         if (err) quit("'f_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
650 #else
651         if (err) quit("Cannot parse 'f_info.raw' file.");
652 #endif
653
654
655         /* Success */
656         return (0);
657 }
658
659
660 /*
661  * Initialize the "k_info" array, by parsing a binary "image" file
662  */
663 static errr init_k_info_raw(int fd)
664 {
665         header test;
666
667         /* Read and Verify the header */
668         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
669             (test.v_major != k_head->v_major) ||
670             (test.v_minor != k_head->v_minor) ||
671             (test.v_patch != k_head->v_patch) ||
672             (test.v_extra != k_head->v_extra) ||
673             (test.info_num != k_head->info_num) ||
674             (test.info_len != k_head->info_len) ||
675             (test.head_size != k_head->head_size) ||
676             (test.info_size != k_head->info_size))
677         {
678                 /* Error */
679                 return (-1);
680         }
681
682
683         /* Accept the header */
684         (*k_head) = test;
685
686         /* Allocate the "k_info" array */
687         C_MAKE(k_info, k_head->info_num, object_kind);
688
689         /* Read the "k_info" array */
690         fd_read(fd, (char*)(k_info), k_head->info_size);
691
692
693         /* Allocate the "k_name" array */
694         C_MAKE(k_name, k_head->name_size, char);
695
696         /* Read the "k_name" array */
697         fd_read(fd, (char*)(k_name), k_head->name_size);
698
699
700 #ifdef JP
701         /* ±Ñ¸ì̾ÍÑ */
702         /* Allocate the "E_k_name" array */
703         C_MAKE(E_k_name, k_head->E_name_size, char);
704
705         /* Read the "E_k_name" array */
706         fd_read(fd, (char*)(E_k_name), k_head->E_name_size);
707 #endif
708 #ifndef DELAY_LOAD_K_TEXT
709
710         /* Allocate the "k_text" array */
711         C_MAKE(k_text, k_head->text_size, char);
712
713         /* Read the "k_text" array */
714         fd_read(fd, (char*)(k_text), k_head->text_size);
715
716 #endif /* DELAY_LOAD_K_TEXT */
717
718         /* Success */
719         return (0);
720 }
721
722
723 /*
724  * Initialize the "k_info" array
725  *
726  * Note that we let each entry have a unique "name" and "text" string,
727  * even if the string happens to be empty (everyone has a unique '\0').
728  */
729 static errr init_k_info(void)
730 {
731         int fd;
732
733         int mode = 0644;
734
735         errr err = 0;
736
737         FILE *fp;
738
739         /* General buffer */
740         char buf[1024];
741
742
743         /*** Make the header ***/
744
745         /* Allocate the "header" */
746         MAKE(k_head, header);
747
748         /* Save the "version" */
749         k_head->v_major = FAKE_VER_MAJOR;
750         k_head->v_minor = FAKE_VER_MINOR;
751         k_head->v_patch = FAKE_VER_PATCH;
752         k_head->v_extra = 0;
753
754         /* Save the "record" information */
755         k_head->info_num = max_k_idx;
756         k_head->info_len = sizeof(object_kind);
757
758         /* Save the size of "k_head" and "k_info" */
759         k_head->head_size = sizeof(header);
760         k_head->info_size = k_head->info_num * k_head->info_len;
761
762
763 #ifdef ALLOW_TEMPLATES
764
765         /*** Load the binary image file ***/
766
767         /* Build the filename */
768 #ifdef JP
769         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info_j.raw");
770 #else
771         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
772 #endif
773
774
775         /* Attempt to open the "raw" file */
776         fd = fd_open(buf, O_RDONLY);
777
778         /* Process existing "raw" file */
779         if (fd >= 0)
780         {
781 #ifdef CHECK_MODIFICATION_TIME
782
783                 err = check_modification_date(fd, "k_info_j.txt");
784
785 #endif /* CHECK_MODIFICATION_TIME */
786
787                 /* Attempt to parse the "raw" file */
788                 if (!err)
789                         err = init_k_info_raw(fd);
790
791                 /* Close it */
792                 (void)fd_close(fd);
793
794                 /* Success */
795                 if (!err)
796                 {
797 #ifdef USE_SCRIPT
798                         if (init_object_kind_list_callback()) return (0);
799 #endif /* USE_SCRIPT */
800
801                         return (0);
802                 }
803         }
804
805
806         /*** Make the fake arrays ***/
807
808         /* Fake the size of "k_name" and "k_text" */
809         fake_name_size = FAKE_NAME_SIZE;
810 #ifdef JP
811         /* ±Ñ¸ì̾ÍÑ */
812         E_fake_name_size = FAKE_NAME_SIZE;
813 #endif
814         fake_text_size = FAKE_TEXT_SIZE;
815
816         /* Allocate the "k_info" array */
817         C_MAKE(k_info, k_head->info_num, object_kind);
818
819         /* Hack -- make "fake" arrays */
820         C_MAKE(k_name, fake_name_size, char);
821 #ifdef JP
822         /* ±Ñ¸ì̾ÍÑ */
823         C_MAKE(E_k_name, E_fake_name_size, char);
824 #endif
825         C_MAKE(k_text, fake_text_size, char);
826
827
828         /*** Load the ascii template file ***/
829
830         /* Build the filename */
831
832         path_build(buf, 1024, ANGBAND_DIR_EDIT, "k_info_j.txt");
833
834         /* Open the file */
835         fp = my_fopen(buf, "r");
836
837         /* Parse it */
838 #ifdef JP
839         if (!fp) quit("'k_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
840 #else
841         if (!fp) quit("Cannot open 'k_info.txt' file.");
842 #endif
843
844
845         /* Parse the file */
846         err = init_k_info_txt(fp, buf);
847
848         /* Close it */
849         my_fclose(fp);
850
851         /* Errors */
852         if (err)
853         {
854                 cptr oops;
855
856 #ifdef JP
857                 /* Error string */
858                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
859
860                 /* Oops */
861                 msg_format("'k_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
862                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
863                 msg_format("¹½Ê¸ '%s'¡£", buf);
864                 msg_print(NULL);
865
866                 /* Quit */
867                 quit("'k_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
868 #else
869                 /* Error string */
870                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
871
872                 /* Oops */
873                 msg_format("Error %d at line %d of 'k_info.txt'.", err, error_line);
874                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
875                 msg_format("Parsing '%s'.", buf);
876                 msg_print(NULL);
877
878                 /* Quit */
879                 quit("Error in 'k_info.txt' file.");
880 #endif
881
882         }
883
884
885         /*** Dump the binary image file ***/
886
887         /* File type is "DATA" */
888         FILE_TYPE(FILE_TYPE_DATA);
889
890         /* Build the filename */
891 #ifdef JP
892         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info_j.raw");
893 #else
894         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
895 #endif
896
897
898         /* Kill the old file */
899         (void)fd_kill(buf);
900
901         /* Attempt to create the raw file */
902         fd = fd_make(buf, mode);
903
904         /* Dump to the file */
905         if (fd >= 0)
906         {
907                 /* Dump it */
908                 fd_write(fd, (char*)(k_head), k_head->head_size);
909
910                 /* Dump the "k_info" array */
911                 fd_write(fd, (char*)(k_info), k_head->info_size);
912
913                 /* Dump the "k_name" array */
914                 fd_write(fd, (char*)(k_name), k_head->name_size);
915
916 #ifdef JP
917                 /* ±Ñ¸ì̾ÍÑ */
918                 /* Dump the "E_k_name" array */
919                 fd_write(fd, (char*)(E_k_name), k_head->E_name_size);
920 #endif
921                 /* Dump the "k_text" array */
922                 fd_write(fd, (char*)(k_text), k_head->text_size);
923
924                 /* Close */
925                 (void)fd_close(fd);
926         }
927
928
929         /*** Kill the fake arrays ***/
930
931         /* Free the "k_info" array */
932         C_KILL(k_info, k_head->info_num, object_kind);
933
934         /* Hack -- Free the "fake" arrays */
935         C_KILL(k_name, fake_name_size, char);
936 #ifdef JP
937         /* ±Ñ¸ì̾ÍÑ */
938         C_KILL(E_k_name, E_fake_name_size, char);
939 #endif
940         C_KILL(k_text, fake_text_size, char);
941
942         /* Forget the array sizes */
943         fake_name_size = 0;
944 #ifdef JP
945         /* ±Ñ¸ì̾ÍÑ */
946         E_fake_name_size = 0;
947 #endif
948         fake_text_size = 0;
949
950 #endif  /* ALLOW_TEMPLATES */
951
952
953         /*** Load the binary image file ***/
954
955         /* Build the filename */
956 #ifdef JP
957         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info_j.raw");
958 #else
959         path_build(buf, 1024, ANGBAND_DIR_DATA, "k_info.raw");
960 #endif
961
962
963         /* Attempt to open the "raw" file */
964         fd = fd_open(buf, O_RDONLY);
965
966         /* Process existing "raw" file */
967 #ifdef JP
968         if (fd < 0) quit("'k_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
969 #else
970         if (fd < 0) quit("Cannot load 'k_info.raw' file.");
971 #endif
972
973
974         /* Attempt to parse the "raw" file */
975         err = init_k_info_raw(fd);
976
977         /* Close it */
978         (void)fd_close(fd);
979
980         /* Error */
981 #ifdef JP
982         if (err) quit("'k_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
983 #else
984         if (err) quit("Cannot parse 'k_info.raw' file.");
985 #endif
986
987
988
989 #ifdef USE_SCRIPT
990         if (init_object_kind_list_callback()) return (0);
991 #endif /* USE_SCRIPT */
992
993         /* Success */
994         return (0);
995 }
996
997
998
999 /*
1000  * Initialize the "a_info" array, by parsing a binary "image" file
1001  */
1002 static errr init_a_info_raw(int fd)
1003 {
1004         header test;
1005
1006         /* Read and Verify the header */
1007         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
1008             (test.v_major != a_head->v_major) ||
1009             (test.v_minor != a_head->v_minor) ||
1010             (test.v_patch != a_head->v_patch) ||
1011             (test.v_extra != a_head->v_extra) ||
1012             (test.info_num != a_head->info_num) ||
1013             (test.info_len != a_head->info_len) ||
1014             (test.head_size != a_head->head_size) ||
1015             (test.info_size != a_head->info_size))
1016         {
1017                 /* Error */
1018                 return (-1);
1019         }
1020
1021
1022         /* Accept the header */
1023         (*a_head) = test;
1024
1025
1026         /* Allocate the "a_info" array */
1027         C_MAKE(a_info, a_head->info_num, artifact_type);
1028
1029         /* Read the "a_info" array */
1030         fd_read(fd, (char*)(a_info), a_head->info_size);
1031
1032
1033         /* Allocate the "a_name" array */
1034         C_MAKE(a_name, a_head->name_size, char);
1035
1036         /* Read the "a_name" array */
1037         fd_read(fd, (char*)(a_name), a_head->name_size);
1038
1039
1040 #ifdef JP
1041         /* ±Ñ¸ì̾ÍÑ */
1042         /* Allocate the "E_a_name" array */
1043         C_MAKE(E_a_name, a_head->E_name_size, char);
1044
1045         /* Read the "E_a_name" array */
1046         fd_read(fd, (char*)(E_a_name), a_head->E_name_size);
1047 #endif
1048
1049         /* Allocate the "a_text" array */
1050         C_MAKE(a_text, a_head->text_size, char);
1051
1052         /* Read the "a_text" array */
1053         fd_read(fd, (char*)(a_text), a_head->text_size);
1054
1055         /* Success */
1056         return (0);
1057 }
1058
1059
1060
1061 /*
1062  * Initialize the "a_info" array
1063  *
1064  * Note that we let each entry have a unique "name" and "text" string,
1065  * even if the string happens to be empty (everyone has a unique '\0').
1066  */
1067 static errr init_a_info(void)
1068 {
1069         int fd;
1070
1071         int mode = 0644;
1072
1073         errr err = 0;
1074
1075         FILE *fp;
1076
1077         /* General buffer */
1078         char buf[1024];
1079
1080
1081         /*** Make the "header" ***/
1082
1083         /* Allocate the "header" */
1084         MAKE(a_head, header);
1085
1086         /* Save the "version" */
1087         a_head->v_major = FAKE_VER_MAJOR;
1088         a_head->v_minor = FAKE_VER_MINOR;
1089         a_head->v_patch = FAKE_VER_PATCH;
1090         a_head->v_extra = 0;
1091
1092         /* Save the "record" information */
1093         a_head->info_num = max_a_idx;
1094         a_head->info_len = sizeof(artifact_type);
1095
1096         /* Save the size of "a_head" and "a_info" */
1097         a_head->head_size = sizeof(header);
1098         a_head->info_size = a_head->info_num * a_head->info_len;
1099
1100
1101 #ifdef ALLOW_TEMPLATES
1102
1103         /*** Load the binary image file ***/
1104
1105         /* Build the filename */
1106 #ifdef JP
1107         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info_j.raw");
1108 #else
1109         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
1110 #endif
1111
1112
1113         /* Attempt to open the "raw" file */
1114         fd = fd_open(buf, O_RDONLY);
1115
1116         /* Process existing "raw" file */
1117         if (fd >= 0)
1118         {
1119 #ifdef CHECK_MODIFICATION_TIME
1120
1121                 err = check_modification_date(fd, "a_info_j.txt");
1122
1123 #endif /* CHECK_MODIFICATION_TIME */
1124
1125                 /* Attempt to parse the "raw" file */
1126                 if (!err)
1127                         err = init_a_info_raw(fd);
1128
1129                 /* Close it */
1130                 (void)fd_close(fd);
1131
1132                 /* Success */
1133                 if (!err) return (0);
1134         }
1135
1136
1137         /*** Make the fake arrays ***/
1138
1139         /* Fake the size of "a_name" and "a_text" */
1140         fake_name_size = FAKE_NAME_SIZE;
1141 #ifdef JP
1142         /* ±Ñ¸ì̾ÍÑ */
1143         E_fake_name_size = FAKE_NAME_SIZE;
1144 #endif
1145         fake_text_size = FAKE_TEXT_SIZE;
1146
1147         /* Allocate the "a_info" array */
1148         C_MAKE(a_info, a_head->info_num, artifact_type);
1149
1150         /* Hack -- make "fake" arrays */
1151         C_MAKE(a_name, fake_name_size, char);
1152 #ifdef JP
1153         /* ±Ñ¸ì̾ÍÑ */
1154         C_MAKE(E_a_name, E_fake_name_size, char);
1155 #endif
1156         C_MAKE(a_text, fake_text_size, char);
1157
1158
1159         /*** Load the ascii template file ***/
1160
1161         /* Build the filename */
1162
1163         path_build(buf, 1024, ANGBAND_DIR_EDIT, "a_info_j.txt");
1164
1165         /* Open the file */
1166         fp = my_fopen(buf, "r");
1167
1168         /* Parse it */
1169 #ifdef JP
1170         if (!fp) quit("'a_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
1171 #else
1172         if (!fp) quit("Cannot open 'a_info.txt' file.");
1173 #endif
1174
1175
1176         /* Parse the file */
1177         err = init_a_info_txt(fp, buf);
1178
1179         /* Close it */
1180         my_fclose(fp);
1181
1182         /* Errors */
1183         if (err)
1184         {
1185                 cptr oops;
1186
1187 #ifdef JP
1188                 /* Error string */
1189                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
1190
1191                 /* Oops */
1192                 msg_format("'a_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
1193                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
1194                 msg_format("¹½Ê¸ '%s'¡£", buf);
1195                 msg_print(NULL);
1196
1197                 /* Quit */
1198                 quit("'a_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
1199 #else
1200                 /* Error string */
1201                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
1202
1203                 /* Oops */
1204                 msg_format("Error %d at line %d of 'a_info.txt'.", err, error_line);
1205                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
1206                 msg_format("Parsing '%s'.", buf);
1207                 msg_print(NULL);
1208
1209                 /* Quit */
1210                 quit("Error in 'a_info.txt' file.");
1211 #endif
1212
1213         }
1214
1215
1216         /*** Dump the binary image file ***/
1217
1218         /* File type is "DATA" */
1219         FILE_TYPE(FILE_TYPE_DATA);
1220
1221         /* Build the filename */
1222 #ifdef JP
1223         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info_j.raw");
1224 #else
1225         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
1226 #endif
1227
1228
1229         /* Kill the old file */
1230         (void)fd_kill(buf);
1231
1232         /* Attempt to create the raw file */
1233         fd = fd_make(buf, mode);
1234
1235         /* Dump to the file */
1236         if (fd >= 0)
1237         {
1238                 /* Dump it */
1239                 fd_write(fd, (char*)(a_head), a_head->head_size);
1240
1241                 /* Dump the "a_info" array */
1242                 fd_write(fd, (char*)(a_info), a_head->info_size);
1243
1244                 /* Dump the "a_name" array */
1245                 fd_write(fd, (char*)(a_name), a_head->name_size);
1246
1247 #ifdef JP
1248                 /* ±Ñ¸ì̾ÍÑ */
1249                 /* Dump the "E_a_name" array */
1250                 fd_write(fd, (char*)(E_a_name), a_head->E_name_size);
1251 #endif
1252                 /* Dump the "a_text" array */
1253                 fd_write(fd, (char*)(a_text), a_head->text_size);
1254
1255                 /* Close */
1256                 (void)fd_close(fd);
1257         }
1258
1259
1260         /*** Kill the fake arrays ***/
1261
1262         /* Free the "a_info" array */
1263         C_KILL(a_info, a_head->info_num, artifact_type);
1264
1265         /* Hack -- Free the "fake" arrays */
1266         C_KILL(a_name, fake_name_size, char);
1267 #ifdef JP
1268         /* ±Ñ¸ì̾ÍÑ */
1269         C_KILL(E_a_name, E_fake_name_size, char);
1270 #endif
1271         C_KILL(a_text, fake_text_size, char);
1272
1273         /* Forget the array sizes */
1274         fake_name_size = 0;
1275 #ifdef JP
1276         /* ±Ñ¸ì̾ÍÑ */
1277         E_fake_name_size = 0;
1278 #endif
1279         fake_text_size = 0;
1280
1281 #endif  /* ALLOW_TEMPLATES */
1282
1283
1284         /*** Load the binary image file ***/
1285
1286         /* Build the filename */
1287 #ifdef JP
1288         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info_j.raw");
1289 #else
1290         path_build(buf, 1024, ANGBAND_DIR_DATA, "a_info.raw");
1291 #endif
1292
1293
1294         /* Attempt to open the "raw" file */
1295         fd = fd_open(buf, O_RDONLY);
1296
1297         /* Process existing "raw" file */
1298 #ifdef JP
1299         if (fd < 0) quit("'a_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
1300 #else
1301         if (fd < 0) quit("Cannot open 'a_info.raw' file.");
1302 #endif
1303
1304
1305         /* Attempt to parse the "raw" file */
1306         err = init_a_info_raw(fd);
1307
1308         /* Close it */
1309         (void)fd_close(fd);
1310
1311         /* Error */
1312 #ifdef JP
1313         if (err) quit("'a_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
1314 #else
1315         if (err) quit("Cannot parse 'a_info.raw' file.");
1316 #endif
1317
1318
1319         /* Success */
1320         return (0);
1321 }
1322
1323
1324
1325 /*
1326  * Initialize the "e_info" array, by parsing a binary "image" file
1327  */
1328 static errr init_e_info_raw(int fd)
1329 {
1330         header test;
1331
1332         /* Read and Verify the header */
1333         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
1334             (test.v_major != e_head->v_major) ||
1335             (test.v_minor != e_head->v_minor) ||
1336             (test.v_patch != e_head->v_patch) ||
1337             (test.v_extra != e_head->v_extra) ||
1338             (test.info_num != e_head->info_num) ||
1339             (test.info_len != e_head->info_len) ||
1340             (test.head_size != e_head->head_size) ||
1341             (test.info_size != e_head->info_size))
1342         {
1343                 /* Error */
1344                 return (-1);
1345         }
1346
1347
1348         /* Accept the header */
1349         (*e_head) = test;
1350
1351
1352         /* Allocate the "e_info" array */
1353         C_MAKE(e_info, e_head->info_num, ego_item_type);
1354
1355         /* Read the "e_info" array */
1356         fd_read(fd, (char*)(e_info), e_head->info_size);
1357
1358
1359         /* Allocate the "e_name" array */
1360         C_MAKE(e_name, e_head->name_size, char);
1361
1362         /* Read the "e_name" array */
1363         fd_read(fd, (char*)(e_name), e_head->name_size);
1364
1365
1366 #ifdef JP
1367         /* ±Ñ¸ì̾ÍÑ */
1368         /* Allocate the "E_e_name" array */
1369         C_MAKE(E_e_name, e_head->E_name_size, char);
1370
1371         /* Read the "E_e_name" array */
1372         fd_read(fd, (char*)(E_e_name), e_head->E_name_size);
1373 #endif
1374 #ifndef DELAY_LOAD_E_TEXT
1375
1376         /* Allocate the "e_text" array */
1377         C_MAKE(e_text, e_head->text_size, char);
1378
1379         /* Read the "e_text" array */
1380         fd_read(fd, (char*)(e_text), e_head->text_size);
1381
1382 #endif /* DELAY_LOAD_E_TEXT */
1383
1384
1385         /* Success */
1386         return (0);
1387 }
1388
1389
1390
1391 /*
1392  * Initialize the "e_info" array
1393  *
1394  * Note that we let each entry have a unique "name" and "text" string,
1395  * even if the string happens to be empty (everyone has a unique '\0').
1396  */
1397 static errr init_e_info(void)
1398 {
1399         int fd;
1400
1401         int mode = 0644;
1402
1403         errr err = 0;
1404
1405         FILE *fp;
1406
1407         /* General buffer */
1408         char buf[1024];
1409
1410
1411         /*** Make the "header" ***/
1412
1413         /* Allocate the "header" */
1414         MAKE(e_head, header);
1415
1416         /* Save the "version" */
1417         e_head->v_major = FAKE_VER_MAJOR;
1418         e_head->v_minor = FAKE_VER_MINOR;
1419         e_head->v_patch = FAKE_VER_PATCH;
1420         e_head->v_extra = 0;
1421
1422         /* Save the "record" information */
1423         e_head->info_num = max_e_idx;
1424         e_head->info_len = sizeof(ego_item_type);
1425
1426         /* Save the size of "e_head" and "e_info" */
1427         e_head->head_size = sizeof(header);
1428         e_head->info_size = e_head->info_num * e_head->info_len;
1429
1430
1431 #ifdef ALLOW_TEMPLATES
1432
1433         /*** Load the binary image file ***/
1434
1435         /* Build the filename */
1436 #ifdef JP
1437         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info_j.raw");
1438 #else
1439         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
1440 #endif
1441
1442
1443         /* Attempt to open the "raw" file */
1444         fd = fd_open(buf, O_RDONLY);
1445
1446         /* Process existing "raw" file */
1447         if (fd >= 0)
1448         {
1449
1450 #ifdef CHECK_MODIFICATION_TIME
1451
1452                 err = check_modification_date(fd, "e_info_j.txt");
1453
1454 #endif /* CHECK_MODIFICATION_TIME */
1455
1456
1457                 /* Attempt to parse the "raw" file */
1458                 if (!err)
1459                         err = init_e_info_raw(fd);
1460
1461                 /* Close it */
1462                 (void)fd_close(fd);
1463
1464                 /* Success */
1465                 if (!err) return (0);
1466         }
1467
1468
1469         /*** Make the fake arrays ***/
1470
1471         /* Fake the size of "e_name" and "e_text" */
1472         fake_name_size = FAKE_NAME_SIZE;
1473 #ifdef JP
1474         /* ±Ñ¸ì̾ÍÑ */
1475         E_fake_name_size = FAKE_NAME_SIZE;
1476 #endif
1477         fake_text_size = FAKE_TEXT_SIZE;
1478
1479         /* Allocate the "e_info" array */
1480         C_MAKE(e_info, e_head->info_num, ego_item_type);
1481
1482         /* Hack -- make "fake" arrays */
1483         C_MAKE(e_name, fake_name_size, char);
1484 #ifdef JP
1485         /* ±Ñ¸ì̾ÍÑ */
1486         C_MAKE(E_e_name, E_fake_name_size, char);
1487 #endif
1488         C_MAKE(e_text, fake_text_size, char);
1489
1490
1491         /*** Load the ascii template file ***/
1492
1493         /* Build the filename */
1494
1495         path_build(buf, 1024, ANGBAND_DIR_EDIT, "e_info_j.txt");
1496
1497         /* Open the file */
1498         fp = my_fopen(buf, "r");
1499
1500         /* Parse it */
1501 #ifdef JP
1502         if (!fp) quit("'e_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
1503 #else
1504         if (!fp) quit("Cannot open 'e_info.txt' file.");
1505 #endif
1506
1507
1508         /* Parse the file */
1509         err = init_e_info_txt(fp, buf);
1510
1511         /* Close it */
1512         my_fclose(fp);
1513
1514         /* Errors */
1515         if (err)
1516         {
1517                 cptr oops;
1518
1519 #ifdef JP
1520                 /* Error string */
1521                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
1522
1523                 /* Oops */
1524                 msg_format("'e_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
1525                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
1526                 msg_format("¹½Ê¸ '%s'¡£", buf);
1527                 msg_print(NULL);
1528
1529                 /* Quit */
1530                 quit("'e_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
1531 #else
1532                 /* Error string */
1533                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
1534
1535                 /* Oops */
1536                 msg_format("Error %d at line %d of 'e_info.txt'.", err, error_line);
1537                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
1538                 msg_format("Parsing '%s'.", buf);
1539                 msg_print(NULL);
1540
1541                 /* Quit */
1542                 quit("Error in 'e_info.txt' file.");
1543 #endif
1544
1545         }
1546
1547
1548         /*** Dump the binary image file ***/
1549
1550         /* File type is "DATA" */
1551         FILE_TYPE(FILE_TYPE_DATA);
1552
1553         /* Build the filename */
1554 #ifdef JP
1555         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info_j.raw");
1556 #else
1557         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
1558 #endif
1559
1560
1561         /* Kill the old file */
1562         (void)fd_kill(buf);
1563
1564         /* Attempt to create the raw file */
1565         fd = fd_make(buf, mode);
1566
1567         /* Dump to the file */
1568         if (fd >= 0)
1569         {
1570                 /* Dump it */
1571                 fd_write(fd, (char*)(e_head), e_head->head_size);
1572
1573                 /* Dump the "e_info" array */
1574                 fd_write(fd, (char*)(e_info), e_head->info_size);
1575
1576                 /* Dump the "e_name" array */
1577                 fd_write(fd, (char*)(e_name), e_head->name_size);
1578
1579 #ifdef JP
1580                 /* ±Ñ¸ì̾ÍÑ */
1581                 /* Dump the "E_e_name" array */
1582                 fd_write(fd, (char*)(E_e_name), e_head->E_name_size);
1583 #endif
1584                 /* Dump the "e_text" array */
1585                 fd_write(fd, (char*)(e_text), e_head->text_size);
1586
1587                 /* Close */
1588                 (void)fd_close(fd);
1589         }
1590
1591
1592         /*** Kill the fake arrays ***/
1593
1594         /* Free the "e_info" array */
1595         C_KILL(e_info, e_head->info_num, ego_item_type);
1596
1597         /* Hack -- Free the "fake" arrays */
1598         C_KILL(e_name, fake_name_size, char);
1599 #ifdef JP
1600         /* ±Ñ¸ì̾ÍÑ */
1601         C_KILL(E_e_name, E_fake_name_size, char);
1602 #endif
1603         C_KILL(e_text, fake_text_size, char);
1604
1605         /* Forget the array sizes */
1606         fake_name_size = 0;
1607 #ifdef JP
1608         /* ±Ñ¸ì̾ÍÑ */
1609         E_fake_name_size = 0;
1610 #endif
1611         fake_text_size = 0;
1612
1613 #endif  /* ALLOW_TEMPLATES */
1614
1615
1616         /*** Load the binary image file ***/
1617
1618         /* Build the filename */
1619 #ifdef JP
1620         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info_j.raw");
1621 #else
1622         path_build(buf, 1024, ANGBAND_DIR_DATA, "e_info.raw");
1623 #endif
1624
1625
1626         /* Attempt to open the "raw" file */
1627         fd = fd_open(buf, O_RDONLY);
1628
1629         /* Process existing "raw" file */
1630 #ifdef JP
1631         if (fd < 0) quit("'e_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
1632 #else
1633         if (fd < 0) quit("Cannot load 'e_info.raw' file.");
1634 #endif
1635
1636
1637         /* Attempt to parse the "raw" file */
1638         err = init_e_info_raw(fd);
1639
1640         /* Close it */
1641         (void)fd_close(fd);
1642
1643         /* Error */
1644 #ifdef JP
1645         if (err) quit("'e_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
1646 #else
1647         if (err) quit("Cannot parse 'e_info.raw' file.");
1648 #endif
1649
1650
1651         /* Success */
1652         return (0);
1653 }
1654
1655
1656
1657 /*
1658  * Initialize the "r_info" array, by parsing a binary "image" file
1659  */
1660 static errr init_r_info_raw(int fd)
1661 {
1662         header test;
1663
1664         /* Read and Verify the header */
1665         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
1666             (test.v_major != r_head->v_major) ||
1667             (test.v_minor != r_head->v_minor) ||
1668             (test.v_patch != r_head->v_patch) ||
1669             (test.v_extra != r_head->v_extra) ||
1670             (test.info_num != r_head->info_num) ||
1671             (test.info_len != r_head->info_len) ||
1672             (test.head_size != r_head->head_size) ||
1673             (test.info_size != r_head->info_size))
1674         {
1675                 /* Error */
1676                 return (-1);
1677         }
1678
1679
1680         /* Accept the header */
1681         (*r_head) = test;
1682
1683
1684         /* Allocate the "r_info" array */
1685         C_MAKE(r_info, r_head->info_num, monster_race);
1686
1687         /* Read the "r_info" array */
1688         fd_read(fd, (char*)(r_info), r_head->info_size);
1689
1690
1691         /* Allocate the "r_name" array */
1692         C_MAKE(r_name, r_head->name_size, char);
1693
1694         /* Read the "r_name" array */
1695         fd_read(fd, (char*)(r_name), r_head->name_size);
1696
1697
1698 #ifdef JP
1699         /* ±Ñ¸ì̾ÍÑ */
1700         /* Allocate the "E_r_name" array */
1701         C_MAKE(E_r_name, r_head->E_name_size, char);
1702
1703         /* Read the "E_r_name" array */
1704         fd_read(fd, (char*)(E_r_name), r_head->E_name_size);
1705 #endif
1706 #ifndef DELAY_LOAD_R_TEXT
1707
1708         /* Allocate the "r_text" array */
1709         C_MAKE(r_text, r_head->text_size, char);
1710
1711         /* Read the "r_text" array */
1712         fd_read(fd, (char*)(r_text), r_head->text_size);
1713
1714 #endif /* DELAY_LOAD_R_TEXT */
1715
1716         /* Success */
1717         return (0);
1718 }
1719
1720
1721
1722 /*
1723  * Initialize the "r_info" array
1724  *
1725  * Note that we let each entry have a unique "name" and "text" string,
1726  * even if the string happens to be empty (everyone has a unique '\0').
1727  */
1728 static errr init_r_info(void)
1729 {
1730         int fd;
1731
1732         int mode = 0644;
1733
1734         errr err = 0;
1735
1736         FILE *fp;
1737
1738         /* General buffer */
1739         char buf[1024];
1740
1741
1742         /*** Make the header ***/
1743
1744         /* Allocate the "header" */
1745         MAKE(r_head, header);
1746
1747         /* Save the "version" */
1748         r_head->v_major = FAKE_VER_MAJOR;
1749         r_head->v_minor = FAKE_VER_MINOR;
1750         r_head->v_patch = FAKE_VER_PATCH;
1751         r_head->v_extra = 0;
1752
1753         /* Save the "record" information */
1754         r_head->info_num = max_r_idx;
1755         r_head->info_len = sizeof(monster_race);
1756
1757         /* Save the size of "r_head" and "r_info" */
1758         r_head->head_size = sizeof(header);
1759         r_head->info_size = r_head->info_num * r_head->info_len;
1760
1761
1762 #ifdef ALLOW_TEMPLATES
1763
1764         /*** Load the binary image file ***/
1765
1766         /* Build the filename */
1767 #ifdef JP
1768         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info_j.raw");
1769 #else
1770         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
1771 #endif
1772
1773
1774         /* Attempt to open the "raw" file */
1775         fd = fd_open(buf, O_RDONLY);
1776
1777         /* Process existing "raw" file */
1778         if (fd >= 0)
1779         {
1780 #ifdef CHECK_MODIFICATION_TIME
1781
1782                 err = check_modification_date(fd, "r_info_j.txt");
1783
1784 #endif /* CHECK_MODIFICATION_TIME */
1785
1786                 /* Attempt to parse the "raw" file */
1787                 if (!err)
1788                         err = init_r_info_raw(fd);
1789
1790                 /* Close it */
1791                 (void)fd_close(fd);
1792
1793                 /* Success */
1794                 if (!err) return (0);
1795         }
1796
1797
1798         /*** Make the fake arrays ***/
1799
1800         /* Assume the size of "r_name" and "r_text" */
1801         fake_name_size = FAKE_NAME_SIZE;
1802 #ifdef JP
1803         /* ±Ñ¸ì̾ÍÑ */
1804         E_fake_name_size = FAKE_NAME_SIZE;
1805 #endif
1806         fake_text_size = FAKE_TEXT_SIZE;
1807
1808         /* Allocate the "r_info" array */
1809         C_MAKE(r_info, r_head->info_num, monster_race);
1810
1811         /* Hack -- make "fake" arrays */
1812         C_MAKE(r_name, fake_name_size, char);
1813 #ifdef JP
1814         /* ±Ñ¸ì̾ÍÑ */
1815         C_MAKE(E_r_name, E_fake_name_size, char);
1816 #endif
1817         C_MAKE(r_text, fake_text_size, char);
1818
1819
1820         /*** Load the ascii template file ***/
1821
1822         /* Build the filename */
1823
1824         path_build(buf, 1024, ANGBAND_DIR_EDIT, "r_info_j.txt");
1825
1826         /* Open the file */
1827         fp = my_fopen(buf, "r");
1828
1829         /* Parse it */
1830 #ifdef JP
1831         if (!fp) quit("'r_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
1832 #else
1833         if (!fp) quit("Cannot open 'r_info.txt' file.");
1834 #endif
1835
1836
1837         /* Parse the file */
1838         err = init_r_info_txt(fp, buf);
1839
1840         /* Close it */
1841         my_fclose(fp);
1842
1843         /* Errors */
1844         if (err)
1845         {
1846                 cptr oops;
1847
1848 #ifdef JP
1849                 /* Error string */
1850                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
1851
1852                 /* Oops */
1853                 msg_format("'r_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
1854                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
1855                 msg_format("¹½Ê¸ '%s'¡£", buf);
1856                 msg_print(NULL);
1857
1858                 /* Quit */
1859                 quit("'r_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
1860 #else
1861                 /* Error string */
1862                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
1863
1864                 /* Oops */
1865                 msg_format("Error %d at line %d of 'r_info.txt'.", err, error_line);
1866                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
1867                 msg_format("Parsing '%s'.", buf);
1868                 msg_print(NULL);
1869
1870                 /* Quit */
1871                 quit("Error in 'r_info.txt' file.");
1872 #endif
1873
1874         }
1875
1876
1877         /*** Dump the binary image file ***/
1878
1879         /* File type is "DATA" */
1880         FILE_TYPE(FILE_TYPE_DATA);
1881
1882         /* Build the filename */
1883 #ifdef JP
1884         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info_j.raw");
1885 #else
1886         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
1887 #endif
1888
1889
1890         /* Kill the old file */
1891         (void)fd_kill(buf);
1892
1893         /* Attempt to create the raw file */
1894         fd = fd_make(buf, mode);
1895
1896         /* Dump to the file */
1897         if (fd >= 0)
1898         {
1899                 /* Dump it */
1900                 fd_write(fd, (char*)(r_head), r_head->head_size);
1901
1902                 /* Dump the "r_info" array */
1903                 fd_write(fd, (char*)(r_info), r_head->info_size);
1904
1905                 /* Dump the "r_name" array */
1906                 fd_write(fd, (char*)(r_name), r_head->name_size);
1907
1908 #ifdef JP
1909                 /* ±Ñ¸ì̾ÍÑ */
1910                 /* Dump the "E_r_name" array */
1911                 fd_write(fd, (char*)(E_r_name), r_head->E_name_size);
1912 #endif
1913                 /* Dump the "r_text" array */
1914                 fd_write(fd, (char*)(r_text), r_head->text_size);
1915
1916                 /* Close */
1917                 (void)fd_close(fd);
1918         }
1919
1920
1921         /*** Kill the fake arrays ***/
1922
1923         /* Free the "r_info" array */
1924         C_KILL(r_info, r_head->info_num, monster_race);
1925
1926         /* Hack -- Free the "fake" arrays */
1927         C_KILL(r_name, fake_name_size, char);
1928 #ifdef JP
1929         /* ±Ñ¸ì̾ÍÑ */
1930         C_KILL(E_r_name, E_fake_name_size, char);
1931 #endif
1932         C_KILL(r_text, fake_text_size, char);
1933
1934         /* Forget the array sizes */
1935         fake_name_size = 0;
1936 #ifdef JP
1937         /* ±Ñ¸ì̾ÍÑ */
1938         E_fake_name_size = 0;
1939 #endif
1940         fake_text_size = 0;
1941
1942 #endif  /* ALLOW_TEMPLATES */
1943
1944
1945         /*** Load the binary image file ***/
1946
1947         /* Build the filename */
1948 #ifdef JP
1949         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info_j.raw");
1950 #else
1951         path_build(buf, 1024, ANGBAND_DIR_DATA, "r_info.raw");
1952 #endif
1953
1954
1955         /* Attempt to open the "raw" file */
1956         fd = fd_open(buf, O_RDONLY);
1957
1958         /* Process existing "raw" file */
1959 #ifdef JP
1960         if (fd < 0) quit("'r_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
1961 #else
1962         if (fd < 0) quit("Cannot load 'r_info.raw' file.");
1963 #endif
1964
1965
1966         /* Attempt to parse the "raw" file */
1967         err = init_r_info_raw(fd);
1968
1969         /* Close it */
1970         (void)fd_close(fd);
1971
1972         /* Error */
1973 #ifdef JP
1974         if (err) quit("'r_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
1975 #else
1976         if (err) quit("Cannot parse 'r_info.raw' file.");
1977 #endif
1978
1979
1980         /* Success */
1981         return (0);
1982 }
1983
1984
1985
1986 /*
1987  * Initialize the "d_info" array, by parsing a binary "image" file
1988  */
1989 static errr init_d_info_raw(int fd)
1990 {
1991         header test;
1992
1993         /* Read and Verify the header */
1994         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
1995             (test.v_major != d_head->v_major) ||
1996             (test.v_minor != d_head->v_minor) ||
1997             (test.v_patch != d_head->v_patch) ||
1998             (test.v_extra != d_head->v_extra) ||
1999             (test.info_num != d_head->info_num) ||
2000             (test.info_len != d_head->info_len) ||
2001             (test.head_size != d_head->head_size) ||
2002             (test.info_size != d_head->info_size))
2003         {
2004                 /* Error */
2005                 return (-1);
2006         }
2007
2008
2009         /* Accept the header */
2010         (*d_head) = test;
2011
2012
2013         /* Allocate the "d_info" array */
2014         C_MAKE(d_info, d_head->info_num, dungeon_info_type);
2015
2016         /* Read the "d_info" array */
2017         fd_read(fd, (char*)(d_info), d_head->info_size);
2018
2019
2020         /* Allocate the "d_name" array */
2021         C_MAKE(d_name, d_head->name_size, char);
2022
2023         /* Read the "d_name" array */
2024         fd_read(fd, (char*)(d_name), d_head->name_size);
2025
2026
2027 #ifndef DELAY_LOAD_D_TEXT
2028
2029         /* Allocate the "d_text" array */
2030         C_MAKE(d_text, d_head->text_size, char);
2031
2032         /* Read the "d_text" array */
2033         fd_read(fd, (char*)(d_text), d_head->text_size);
2034
2035 #endif /* DELAY_LOAD_D_TEXT */
2036
2037
2038         /* Success */
2039         return (0);
2040 }
2041
2042
2043
2044 /*
2045  * Initialize the "d_info" array
2046  *
2047  * Note that we let each entry have a unique "name" and "text" string,
2048  * even if the string happens to be empty (everyone has a unique '\0').
2049  */
2050 static errr init_d_info(void)
2051 {
2052         int fd;
2053
2054         int mode = 0644;
2055
2056         errr err = 0;
2057
2058         FILE *fp;
2059
2060         /* General buffer */
2061         char buf[1024];
2062
2063
2064         /*** Make the "header" ***/
2065
2066         /* Allocate the "header" */
2067         MAKE(d_head, header);
2068
2069         /* Save the "version" */
2070         d_head->v_major = FAKE_VER_MAJOR;
2071         d_head->v_minor = FAKE_VER_MINOR;
2072         d_head->v_patch = FAKE_VER_PATCH;
2073         d_head->v_extra = 0;
2074
2075         /* Save the "record" information */
2076         d_head->info_num = max_d_idx;
2077         d_head->info_len = sizeof(dungeon_info_type);
2078
2079         /* Save the size of "d_head" and "d_info" */
2080         d_head->head_size = sizeof(header);
2081         d_head->info_size = d_head->info_num * d_head->info_len;
2082
2083
2084 #ifdef ALLOW_TEMPLATES
2085
2086         /*** Load the binary image file ***/
2087
2088         /* Build the filename */
2089 #ifdef JP
2090         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info_j.raw");
2091 #else
2092         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
2093 #endif
2094
2095
2096         /* Attempt to open the "raw" file */
2097         fd = fd_open(buf, O_RDONLY);
2098
2099         /* Process existing "raw" file */
2100         if (fd >= 0)
2101         {
2102
2103 #ifdef CHECK_MODIFICATION_TIME
2104
2105                 err = check_modification_date(fd, "d_info_j.txt");
2106
2107 #endif /* CHECK_MODIFICATION_TIME */
2108
2109
2110                 /* Attempt to parse the "raw" file */
2111                 if (!err)
2112                         err = init_d_info_raw(fd);
2113
2114                 /* Close it */
2115                 (void)fd_close(fd);
2116
2117                 /* Success */
2118                 if (!err) return (0);
2119         }
2120
2121
2122         /*** Make the fake arrays ***/
2123
2124         /* Fake the size of "d_name" and "d_text" */
2125         fake_name_size = FAKE_NAME_SIZE;
2126         fake_text_size = FAKE_TEXT_SIZE;
2127
2128         /* Allocate the "d_info" array */
2129         C_MAKE(d_info, d_head->info_num, dungeon_info_type);
2130
2131         /* Hack -- make "fake" arrays */
2132         C_MAKE(d_name, fake_name_size, char);
2133         C_MAKE(d_text, fake_text_size, char);
2134
2135
2136         /*** Load the ascii template file ***/
2137
2138         /* Build the filename */
2139
2140         path_build(buf, 1024, ANGBAND_DIR_EDIT, "d_info_j.txt");
2141
2142         /* Open the file */
2143         fp = my_fopen(buf, "r");
2144
2145         /* Parse it */
2146 #ifdef JP
2147         if (!fp) quit("'d_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
2148 #else
2149         if (!fp) quit("Cannot open 'd_info.txt' file.");
2150 #endif
2151
2152
2153         /* Parse the file */
2154         err = init_d_info_txt(fp, buf);
2155
2156         /* Close it */
2157         my_fclose(fp);
2158
2159         /* Errors */
2160         if (err)
2161         {
2162                 cptr oops;
2163
2164 #ifdef JP
2165                 /* Error string */
2166                 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
2167
2168                 /* Oops */
2169                 msg_format("'d_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
2170                 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
2171                 msg_format("¹½Ê¸ '%s'¡£", buf);
2172                 msg_print(NULL);
2173
2174                 /* Quit */
2175                 quit("'d_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
2176 #else
2177                 /* Error string */
2178                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
2179
2180                 /* Oops */
2181                 msg_format("Error %d at line %d of 'd_info.txt'.", err, error_line);
2182                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
2183                 msg_format("Parsing '%s'.", buf);
2184                 msg_print(NULL);
2185
2186                 /* Quit */
2187                 quit("Error in 'd_info.txt' file.");
2188 #endif
2189
2190         }
2191
2192
2193         /*** Dump the binary image file ***/
2194
2195         /* File type is "DATA" */
2196         FILE_TYPE(FILE_TYPE_DATA);
2197
2198         /* Build the filename */
2199 #ifdef JP
2200         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info_j.raw");
2201 #else
2202         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
2203 #endif
2204
2205
2206         /* Kill the old file */
2207         (void)fd_kill(buf);
2208
2209         /* Attempt to create the raw file */
2210         fd = fd_make(buf, mode);
2211
2212         /* Dump to the file */
2213         if (fd >= 0)
2214         {
2215                 /* Dump it */
2216                 fd_write(fd, (char*)(d_head), d_head->head_size);
2217
2218                 /* Dump the "d_info" array */
2219                 fd_write(fd, (char*)(d_info), d_head->info_size);
2220
2221                 /* Dump the "d_name" array */
2222                 fd_write(fd, (char*)(d_name), d_head->name_size);
2223
2224                 /* Dump the "d_text" array */
2225                 fd_write(fd, (char*)(d_text), d_head->text_size);
2226
2227                 /* Close */
2228                 (void)fd_close(fd);
2229         }
2230
2231
2232         /*** Kill the fake arrays ***/
2233
2234         /* Free the "d_info" array */
2235         C_KILL(d_info, d_head->info_num, dungeon_info_type);
2236
2237         /* Hack -- Free the "fake" arrays */
2238         C_KILL(d_name, fake_name_size, char);
2239         C_KILL(d_text, fake_text_size, char);
2240
2241         /* Forget the array sizes */
2242         fake_name_size = 0;
2243         fake_text_size = 0;
2244
2245 #endif  /* ALLOW_TEMPLATES */
2246
2247
2248         /*** Load the binary image file ***/
2249
2250         /* Build the filename */
2251 #ifdef JP
2252         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info_j.raw");
2253 #else
2254         path_build(buf, 1024, ANGBAND_DIR_DATA, "d_info.raw");
2255 #endif
2256
2257
2258         /* Attempt to open the "raw" file */
2259         fd = fd_open(buf, O_RDONLY);
2260
2261         /* Process existing "raw" file */
2262 #ifdef JP
2263         if (fd < 0) quit("'d_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
2264 #else
2265         if (fd < 0) quit("Cannot load 'd_info.raw' file.");
2266 #endif
2267
2268
2269         /* Attempt to parse the "raw" file */
2270         err = init_d_info_raw(fd);
2271
2272         /* Close it */
2273         (void)fd_close(fd);
2274
2275         /* Error */
2276 #ifdef JP
2277         if (err) quit("'d_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
2278 #else
2279         if (err) quit("Cannot parse 'd_info.raw' file.");
2280 #endif
2281
2282
2283         /* Success */
2284         return (0);
2285 }
2286
2287
2288
2289 /*
2290  * Initialize the "v_info" array, by parsing a binary "image" file
2291  */
2292 static errr init_v_info_raw(int fd)
2293 {
2294         header test;
2295
2296         /* Read and Verify the header */
2297         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
2298             (test.v_major != v_head->v_major) ||
2299             (test.v_minor != v_head->v_minor) ||
2300             (test.v_patch != v_head->v_patch) ||
2301             (test.v_extra != v_head->v_extra) ||
2302             (test.info_num != v_head->info_num) ||
2303             (test.info_len != v_head->info_len) ||
2304             (test.head_size != v_head->head_size) ||
2305             (test.info_size != v_head->info_size))
2306         {
2307                 /* Error */
2308                 return (-1);
2309         }
2310
2311
2312         /* Accept the header */
2313         (*v_head) = test;
2314
2315
2316         /* Allocate the "v_info" array */
2317         C_MAKE(v_info, v_head->info_num, vault_type);
2318
2319         /* Read the "v_info" array */
2320         fd_read(fd, (char*)(v_info), v_head->info_size);
2321
2322
2323         /* Allocate the "v_name" array */
2324         C_MAKE(v_name, v_head->name_size, char);
2325
2326         /* Read the "v_name" array */
2327         fd_read(fd, (char*)(v_name), v_head->name_size);
2328
2329
2330 #ifndef DELAY_LOAD_V_TEXT
2331
2332         /* Allocate the "v_text" array */
2333         C_MAKE(v_text, v_head->text_size, char);
2334
2335         /* Read the "v_text" array */
2336         fd_read(fd, (char*)(v_text), v_head->text_size);
2337
2338 #endif /* DELAY_LOAD_V_TEXT */
2339
2340         /* Success */
2341         return (0);
2342 }
2343
2344
2345 /*
2346  * Initialize the "v_info" array
2347  *
2348  * Note that we let each entry have a unique "name" and "text" string,
2349  * even if the string happens to be empty (everyone has a unique '\0').
2350  */
2351 errr init_v_info(void)
2352 {
2353         int fd;
2354
2355         int mode = 0644;
2356
2357         errr err;
2358
2359         FILE *fp;
2360
2361         /* General buffer */
2362         char buf[1024];
2363
2364
2365         /*** Make the header ***/
2366
2367         /* Allocate the "header" */
2368         MAKE(v_head, header);
2369
2370         /* Save the "version" */
2371         v_head->v_major = FAKE_VER_MAJOR;
2372         v_head->v_minor = FAKE_VER_MINOR;
2373         v_head->v_patch = FAKE_VER_PATCH;
2374         v_head->v_extra = 0;
2375
2376         /* Save the "record" information */
2377         v_head->info_num = max_v_idx;
2378         v_head->info_len = sizeof(vault_type);
2379
2380         /* Save the size of "v_head" and "v_info" */
2381         v_head->head_size = sizeof(header);
2382         v_head->info_size = v_head->info_num * v_head->info_len;
2383
2384
2385 #ifdef ALLOW_TEMPLATES
2386
2387         /*** Load the binary image file ***/
2388
2389         /* Build the filename */
2390 #ifdef JP
2391         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info_j.raw");
2392 #else
2393         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
2394 #endif
2395
2396
2397         /* Attempt to open the "raw" file */
2398         fd = fd_open(buf, O_RDONLY);
2399
2400         /* Process existing "raw" file */
2401         if (fd >= 0)
2402         {
2403 #ifdef CHECK_MODIFICATION_TIME
2404
2405                 err = check_modification_date(fd, "v_info_j.txt");
2406
2407 #endif /* CHECK_MODIFICATION_TIME */
2408
2409                 /* Attempt to parse the "raw" file */
2410                 if (!err)
2411                         err = init_v_info_raw(fd);
2412
2413                 /* Close it */
2414                 (void)fd_close(fd);
2415
2416                 /* Success */
2417                 if (!err) return (0);
2418         }
2419
2420
2421         /*** Make the fake arrays ***/
2422
2423         /* Fake the size of "v_name" and "v_text" */
2424         fake_name_size = FAKE_NAME_SIZE;
2425         fake_text_size = FAKE_TEXT_SIZE;
2426
2427         /* Allocate the "k_info" array */
2428         C_MAKE(v_info, v_head->info_num, vault_type);
2429
2430         /* Hack -- make "fake" arrays */
2431         C_MAKE(v_name, fake_name_size, char);
2432         C_MAKE(v_text, fake_text_size, char);
2433
2434
2435         /*** Load the ascii template file ***/
2436
2437         /* Build the filename */
2438
2439         path_build(buf, 1024, ANGBAND_DIR_EDIT, "v_info_j.txt");
2440
2441         /* Open the file */
2442         fp = my_fopen(buf, "r");
2443
2444         /* Parse it */
2445 #ifdef JP
2446         if (!fp) quit("'v_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
2447 #else
2448         if (!fp) quit("Cannot open 'v_info.txt' file.");
2449 #endif
2450
2451
2452         /* Parse the file */
2453         err = init_v_info_txt(fp, buf, TRUE);
2454
2455         /* Close it */
2456         my_fclose(fp);
2457
2458         /* Errors */
2459         if (err)
2460         {
2461                 cptr oops;
2462
2463 #ifdef JP
2464               /* Error string */
2465               oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "̤ÃΤÎ");
2466
2467               /* Oops */
2468               msg_format("'v_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
2469               msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
2470               msg_format("¹½Ê¸ '%s'¡£", buf);
2471               msg_print(NULL);
2472
2473               /* Quit */
2474               quit("'v_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
2475 #else
2476                 /* Error string */
2477                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
2478
2479                 /* Oops */
2480                 msg_format("Error %d at line %d of 'v_info.txt'.", err, error_line);
2481                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
2482                 msg_format("Parsing '%s'.", buf);
2483                 msg_print(NULL);
2484
2485                 /* Quit */
2486                 quit("Error in 'v_info.txt' file.");
2487 #endif
2488
2489         }
2490
2491
2492         /*** Dump the binary image file ***/
2493
2494         /* File type is "DATA" */
2495         FILE_TYPE(FILE_TYPE_DATA);
2496
2497         /* Build the filename */
2498 #ifdef JP
2499         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info_j.raw");
2500 #else
2501         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
2502 #endif
2503
2504
2505         /* Kill the old file */
2506         (void)fd_kill(buf);
2507
2508         /* Attempt to create the raw file */
2509         fd = fd_make(buf, mode);
2510
2511         /* Dump to the file */
2512         if (fd >= 0)
2513         {
2514                 /* Dump it */
2515                 fd_write(fd, (char*)(v_head), v_head->head_size);
2516
2517                 /* Dump the "v_info" array */
2518                 fd_write(fd, (char*)(v_info), v_head->info_size);
2519
2520                 /* Dump the "v_name" array */
2521                 fd_write(fd, (char*)(v_name), v_head->name_size);
2522
2523                 /* Dump the "v_text" array */
2524                 fd_write(fd, (char*)(v_text), v_head->text_size);
2525
2526                 /* Close */
2527                 (void)fd_close(fd);
2528         }
2529
2530
2531         /*** Kill the fake arrays ***/
2532
2533         /* Free the "v_info" array */
2534         C_KILL(v_info, v_head->info_num, vault_type);
2535
2536         /* Hack -- Free the "fake" arrays */
2537         C_KILL(v_name, fake_name_size, char);
2538         C_KILL(v_text, fake_text_size, char);
2539
2540         /* Forget the array sizes */
2541         fake_name_size = 0;
2542         fake_text_size = 0;
2543
2544 #endif /* ALLOW_TEMPLATES */
2545
2546
2547         /*** Load the binary image file ***/
2548
2549         /* Build the filename */
2550 #ifdef JP
2551         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info_j.raw");
2552 #else
2553         path_build(buf, 1024, ANGBAND_DIR_DATA, "v_info.raw");
2554 #endif
2555
2556         /* Attempt to open the "raw" file */
2557         fd = fd_open(buf, O_RDONLY);
2558
2559         /* Process existing "raw" file */
2560 #ifdef JP
2561         if (fd < 0) quit("'v_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
2562 #else
2563         if (fd < 0) quit("Cannot load 'v_info.raw' file.");
2564 #endif
2565
2566
2567         /* Attempt to parse the "raw" file */
2568         err = init_v_info_raw(fd);
2569
2570         /* Close it */
2571         (void)fd_close(fd);
2572
2573         /* Error */
2574 #ifdef JP
2575         if (err) quit("'v_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
2576 #else
2577         if (err) quit("Cannot parse 'v_info.raw' file.");
2578 #endif
2579
2580
2581         /* Success */
2582         return (0);
2583 }
2584
2585
2586 /*
2587  * Initialize the "we_info" array, by parsing a binary "image" file
2588  */
2589 static errr init_we_info_raw(int fd)
2590 {
2591         header test;
2592
2593         /* Read and Verify the header */
2594         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
2595             (test.v_major != we_head->v_major) ||
2596             (test.v_minor != we_head->v_minor) ||
2597             (test.v_patch != we_head->v_patch) ||
2598             (test.v_extra != we_head->v_extra) ||
2599             (test.info_num != we_head->info_num) ||
2600             (test.info_len != we_head->info_len) ||
2601             (test.head_size != we_head->head_size) ||
2602             (test.info_size != we_head->info_size))
2603         {
2604                 /* Error */
2605                 return (-1);
2606         }
2607
2608
2609         /* Accept the header */
2610         (*we_head) = test;
2611
2612
2613         /* Allocate the "we_info" array */
2614         C_MAKE(we_info, we_head->info_num, weapon_exp_table);
2615
2616         /* Read the "we_info" array */
2617         fd_read(fd, (char*)(we_info), we_head->info_size);
2618
2619
2620         /* Allocate the "we_name" array */
2621         C_MAKE(we_name, we_head->name_size, char);
2622
2623         /* Read the "we_name" array */
2624         fd_read(fd, (char*)(we_name), we_head->name_size);
2625
2626
2627         /* Allocate the "we_text" array */
2628         C_MAKE(we_text, we_head->text_size, char);
2629
2630         /* Read the "we_text" array */
2631         fd_read(fd, (char*)(we_text), we_head->text_size);
2632
2633         /* Success */
2634         return (0);
2635 }
2636
2637
2638 /*
2639  * Initialize the "we_info" array
2640  *
2641  * Note that we let each entry have a unique "name" and "text" string,
2642  * even if the string happens to be empty (everyone has a unique '\0').
2643  */
2644 static errr init_we_info(void)
2645 {
2646         int fd;
2647
2648         int mode = 0644;
2649
2650         errr err;
2651
2652         FILE *fp;
2653
2654         /* General buffer */
2655         char buf[1024];
2656
2657
2658         /*** Make the header ***/
2659
2660         /* Allocate the "header" */
2661         MAKE(we_head, header);
2662
2663         /* Save the "version" */
2664         we_head->v_major = FAKE_VER_MAJOR;
2665         we_head->v_minor = FAKE_VER_MINOR;
2666         we_head->v_patch = FAKE_VER_PATCH;
2667         we_head->v_extra = 0;
2668
2669         /* Save the "record" information */
2670         we_head->info_num = MAX_CLASS;
2671         we_head->info_len = sizeof(weapon_exp_table);
2672
2673         /* Save the size of "we_head" and "we_info" */
2674         we_head->head_size = sizeof(header);
2675         we_head->info_size = we_head->info_num * we_head->info_len;
2676
2677
2678 #ifdef ALLOW_TEMPLATES
2679
2680         /*** Load the binary image file ***/
2681
2682         /* Build the filename */
2683 #ifdef JP
2684         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info_j.raw");
2685 #else
2686         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info.raw");
2687 #endif
2688
2689
2690         /* Attempt to open the "raw" file */
2691         fd = fd_open(buf, O_RDONLY);
2692
2693         /* Process existing "raw" file */
2694         if (fd >= 0)
2695         {
2696 #ifdef CHECK_MODIFICATION_TIME
2697
2698                 err = check_modification_date(fd, "we_info_j.txt");
2699
2700 #endif /* CHECK_MODIFICATION_TIME */
2701
2702                 /* Attempt to parse the "raw" file */
2703                 if (!err)
2704                         err = init_we_info_raw(fd);
2705
2706                 /* Close it */
2707                 (void)fd_close(fd);
2708
2709                 /* Success */
2710                 if (!err) return (0);
2711         }
2712
2713
2714         /*** Make the fake arrays ***/
2715
2716         /* Fake the size of "we_name" and "we_text" */
2717         fake_name_size = FAKE_NAME_SIZE;
2718         fake_text_size = FAKE_TEXT_SIZE;
2719
2720         /* Allocate the "we_info" array */
2721         C_MAKE(we_info, we_head->info_num, weapon_exp_table);
2722
2723         /* Hack -- make "fake" arrays */
2724         C_MAKE(we_name, fake_name_size, char);
2725         C_MAKE(we_text, fake_text_size, char);
2726
2727
2728         /*** Load the ascii template file ***/
2729
2730         /* Build the filename */
2731
2732         path_build(buf, 1024, ANGBAND_DIR_EDIT, "we_info_j.txt");
2733
2734         /* Open the file */
2735         fp = my_fopen(buf, "r");
2736
2737         /* Parse it */
2738 #ifdef JP
2739         if (!fp) quit("'we_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
2740 #else
2741         if (!fp) quit("Cannot open 'we_info.txt' file.");
2742 #endif
2743
2744
2745         /* Parse the file */
2746         err = init_we_info_txt(fp, buf);
2747
2748         /* Close it */
2749         my_fclose(fp);
2750
2751         /* Errors */
2752         if (err)
2753         {
2754                 cptr oops;
2755
2756 #ifdef JP
2757               /* Error string */
2758               oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "̤ÃΤÎ");
2759
2760               /* Oops */
2761               msg_format("'we_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
2762               msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
2763               msg_format("¹½Ê¸ '%s'¡£", buf);
2764               msg_print(NULL);
2765
2766               /* Quit */
2767               quit("'we_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
2768 #else
2769                 /* Error string */
2770                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
2771
2772                 /* Oops */
2773                 msg_format("Error %d at line %d of 'we_info.txt'.", err, error_line);
2774                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
2775                 msg_format("Parsing '%s'.", buf);
2776                 msg_print(NULL);
2777
2778                 /* Quit */
2779                 quit("Error in 'we_info.txt' file.");
2780 #endif
2781
2782         }
2783
2784
2785         /*** Dump the binary image file ***/
2786
2787         /* File type is "DATA" */
2788         FILE_TYPE(FILE_TYPE_DATA);
2789
2790         /* Build the filename */
2791 #ifdef JP
2792         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info_j.raw");
2793 #else
2794         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info.raw");
2795 #endif
2796
2797
2798         /* Kill the old file */
2799         (void)fd_kill(buf);
2800
2801         /* Attempt to create the raw file */
2802         fd = fd_make(buf, mode);
2803
2804         /* Dump to the file */
2805         if (fd >= 0)
2806         {
2807                 /* Dump it */
2808                 fd_write(fd, (char*)(we_head), we_head->head_size);
2809
2810                 /* Dump the "we_info" array */
2811                 fd_write(fd, (char*)(we_info), we_head->info_size);
2812
2813                 /* Dump the "we_name" array */
2814                 fd_write(fd, (char*)(we_name), we_head->name_size);
2815
2816                 /* Dump the "we_text" array */
2817                 fd_write(fd, (char*)(we_text), we_head->text_size);
2818
2819                 /* Close */
2820                 (void)fd_close(fd);
2821         }
2822
2823
2824         /*** Kill the fake arrays ***/
2825
2826         /* Free the "we_info" array */
2827         C_KILL(we_info, we_head->info_num, weapon_exp_table);
2828
2829         /* Hack -- Free the "fake" arrays */
2830         C_KILL(we_name, fake_name_size, char);
2831         C_KILL(we_text, fake_text_size, char);
2832
2833         /* Forget the array sizes */
2834         fake_name_size = 0;
2835         fake_text_size = 0;
2836
2837 #endif /* ALLOW_TEMPLATES */
2838
2839
2840         /*** Load the binary image file ***/
2841
2842         /* Build the filename */
2843 #ifdef JP
2844         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info_j.raw");
2845 #else
2846         path_build(buf, 1024, ANGBAND_DIR_DATA, "we_info.raw");
2847 #endif
2848
2849         /* Attempt to open the "raw" file */
2850         fd = fd_open(buf, O_RDONLY);
2851
2852         /* Process existing "raw" file */
2853 #ifdef JP
2854         if (fd < 0) quit("'we_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
2855 #else
2856         if (fd < 0) quit("Cannot load 'we_info.raw' file.");
2857 #endif
2858
2859
2860         /* Attempt to parse the "raw" file */
2861         err = init_we_info_raw(fd);
2862
2863         /* Close it */
2864         (void)fd_close(fd);
2865
2866         /* Error */
2867 #ifdef JP
2868         if (err) quit("'we_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
2869 #else
2870         if (err) quit("Cannot parse 'we_info.raw' file.");
2871 #endif
2872
2873
2874         /* Success */
2875         return (0);
2876 }
2877
2878
2879 /*
2880  * Initialize the "se_info" array, by parsing a binary "image" file
2881  */
2882 static errr init_se_info_raw(int fd)
2883 {
2884         header test;
2885
2886         /* Read and Verify the header */
2887         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
2888             (test.v_major != se_head->v_major) ||
2889             (test.v_minor != se_head->v_minor) ||
2890             (test.v_patch != se_head->v_patch) ||
2891             (test.v_extra != se_head->v_extra) ||
2892             (test.info_num != se_head->info_num) ||
2893             (test.info_len != se_head->info_len) ||
2894             (test.head_size != se_head->head_size) ||
2895             (test.info_size != se_head->info_size))
2896         {
2897                 /* Error */
2898                 return (-1);
2899         }
2900
2901
2902         /* Accept the header */
2903         (*se_head) = test;
2904
2905
2906         /* Allocate the "se_info" array */
2907         C_MAKE(se_info, se_head->info_num, skill_exp_table);
2908
2909         /* Read the "se_info" array */
2910         fd_read(fd, (char*)(se_info), se_head->info_size);
2911
2912
2913         /* Allocate the "se_name" array */
2914         C_MAKE(se_name, se_head->name_size, char);
2915
2916         /* Read the "se_name" array */
2917         fd_read(fd, (char*)(se_name), se_head->name_size);
2918
2919
2920         /* Allocate the "se_text" array */
2921         C_MAKE(se_text, se_head->text_size, char);
2922
2923         /* Read the "se_text" array */
2924         fd_read(fd, (char*)(se_text), se_head->text_size);
2925
2926         /* Success */
2927         return (0);
2928 }
2929
2930
2931 /*
2932  * Initialize the "se_info" array
2933  *
2934  * Note that we let each entry have a unique "name" and "text" string,
2935  * even if the string happens to be empty (everyone has a unique '\0').
2936  */
2937 static errr init_se_info(void)
2938 {
2939         int fd;
2940
2941         int mode = 0644;
2942
2943         errr err;
2944
2945         FILE *fp;
2946
2947         /* General buffer */
2948         char buf[1024];
2949
2950
2951         /*** Make the header ***/
2952
2953         /* Allocate the "header" */
2954         MAKE(se_head, header);
2955
2956         /* Save the "version" */
2957         se_head->v_major = FAKE_VER_MAJOR;
2958         se_head->v_minor = FAKE_VER_MINOR;
2959         se_head->v_patch = FAKE_VER_PATCH;
2960         se_head->v_extra = 0;
2961
2962         /* Save the "record" information */
2963         se_head->info_num = MAX_CLASS;
2964         se_head->info_len = sizeof(skill_exp_table);
2965
2966         /* Save the size of "se_head" and "se_info" */
2967         se_head->head_size = sizeof(header);
2968         se_head->info_size = se_head->info_num * se_head->info_len;
2969
2970
2971 #ifdef ALLOW_TEMPLATES
2972
2973         /*** Load the binary image file ***/
2974
2975         /* Build the filename */
2976 #ifdef JP
2977         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info_j.raw");
2978 #else
2979         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info.raw");
2980 #endif
2981
2982
2983         /* Attempt to open the "raw" file */
2984         fd = fd_open(buf, O_RDONLY);
2985
2986         /* Process existing "raw" file */
2987         if (fd >= 0)
2988         {
2989 #ifdef CHECK_MODIFICATION_TIME
2990
2991                 err = check_modification_date(fd, "se_info_j.txt");
2992
2993 #endif /* CHECK_MODIFICATION_TIME */
2994
2995                 /* Attempt to parse the "raw" file */
2996                 if (!err)
2997                         err = init_se_info_raw(fd);
2998
2999                 /* Close it */
3000                 (void)fd_close(fd);
3001
3002                 /* Success */
3003                 if (!err) return (0);
3004         }
3005
3006
3007         /*** Make the fake arrays ***/
3008
3009         /* Fake the size of "se_name" and "se_text" */
3010         fake_name_size = FAKE_NAME_SIZE;
3011         fake_text_size = FAKE_TEXT_SIZE;
3012
3013         /* Allocate the "se_info" array */
3014         C_MAKE(se_info, se_head->info_num, skill_exp_table);
3015
3016         /* Hack -- make "fake" arrays */
3017         C_MAKE(se_name, fake_name_size, char);
3018         C_MAKE(se_text, fake_text_size, char);
3019
3020
3021         /*** Load the ascii template file ***/
3022
3023         /* Build the filename */
3024
3025         path_build(buf, 1024, ANGBAND_DIR_EDIT, "se_info_j.txt");
3026
3027         /* Open the file */
3028         fp = my_fopen(buf, "r");
3029
3030         /* Parse it */
3031 #ifdef JP
3032         if (!fp) quit("'se_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
3033 #else
3034         if (!fp) quit("Cannot open 'se_info.txt' file.");
3035 #endif
3036
3037
3038         /* Parse the file */
3039         err = init_se_info_txt(fp, buf);
3040
3041         /* Close it */
3042         my_fclose(fp);
3043
3044         /* Errors */
3045         if (err)
3046         {
3047                 cptr oops;
3048
3049 #ifdef JP
3050               /* Error string */
3051               oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "̤ÃΤÎ");
3052
3053               /* Oops */
3054               msg_format("'se_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
3055               msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
3056               msg_format("¹½Ê¸ '%s'¡£", buf);
3057               msg_print(NULL);
3058
3059               /* Quit */
3060               quit("'se_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
3061 #else
3062                 /* Error string */
3063                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
3064
3065                 /* Oops */
3066                 msg_format("Error %d at line %d of 'se_info.txt'.", err, error_line);
3067                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
3068                 msg_format("Parsing '%s'.", buf);
3069                 msg_print(NULL);
3070
3071                 /* Quit */
3072                 quit("Error in 'se_info.txt' file.");
3073 #endif
3074
3075         }
3076
3077
3078         /*** Dump the binary image file ***/
3079
3080         /* File type is "DATA" */
3081         FILE_TYPE(FILE_TYPE_DATA);
3082
3083         /* Build the filename */
3084 #ifdef JP
3085         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info_j.raw");
3086 #else
3087         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info.raw");
3088 #endif
3089
3090
3091         /* Kill the old file */
3092         (void)fd_kill(buf);
3093
3094         /* Attempt to create the raw file */
3095         fd = fd_make(buf, mode);
3096
3097         /* Dump to the file */
3098         if (fd >= 0)
3099         {
3100                 /* Dump it */
3101                 fd_write(fd, (char*)(se_head), se_head->head_size);
3102
3103                 /* Dump the "se_info" array */
3104                 fd_write(fd, (char*)(se_info), se_head->info_size);
3105
3106                 /* Dump the "se_name" array */
3107                 fd_write(fd, (char*)(se_name), se_head->name_size);
3108
3109                 /* Dump the "se_text" array */
3110                 fd_write(fd, (char*)(se_text), se_head->text_size);
3111
3112                 /* Close */
3113                 (void)fd_close(fd);
3114         }
3115
3116
3117         /*** Kill the fake arrays ***/
3118
3119         /* Free the "se_info" array */
3120         C_KILL(se_info, se_head->info_num, skill_exp_table);
3121
3122         /* Hack -- Free the "fake" arrays */
3123         C_KILL(se_name, fake_name_size, char);
3124         C_KILL(se_text, fake_text_size, char);
3125
3126         /* Forget the array sizes */
3127         fake_name_size = 0;
3128         fake_text_size = 0;
3129
3130 #endif /* ALLOW_TEMPLATES */
3131
3132
3133         /*** Load the binary image file ***/
3134
3135         /* Build the filename */
3136 #ifdef JP
3137         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info_j.raw");
3138 #else
3139         path_build(buf, 1024, ANGBAND_DIR_DATA, "se_info.raw");
3140 #endif
3141
3142         /* Attempt to open the "raw" file */
3143         fd = fd_open(buf, O_RDONLY);
3144
3145         /* Process existing "raw" file */
3146 #ifdef JP
3147         if (fd < 0) quit("'se_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
3148 #else
3149         if (fd < 0) quit("Cannot load 'se_info.raw' file.");
3150 #endif
3151
3152
3153         /* Attempt to parse the "raw" file */
3154         err = init_se_info_raw(fd);
3155
3156         /* Close it */
3157         (void)fd_close(fd);
3158
3159         /* Error */
3160 #ifdef JP
3161         if (err) quit("'se_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
3162 #else
3163         if (err) quit("Cannot parse 'se_info.raw' file.");
3164 #endif
3165
3166
3167         /* Success */
3168         return (0);
3169 }
3170
3171
3172 /*
3173  * Initialize the "m_info" array, by parsing a binary "image" file
3174  */
3175 static errr init_m_info_raw(int fd)
3176 {
3177         header test;
3178
3179         /* Read and Verify the header */
3180         if (fd_read(fd, (char*)(&test), sizeof(header)) ||
3181             (test.v_major != m_head->v_major) ||
3182             (test.v_minor != m_head->v_minor) ||
3183             (test.v_patch != m_head->v_patch) ||
3184             (test.v_extra != m_head->v_extra) ||
3185             (test.info_num != m_head->info_num) ||
3186             (test.info_len != m_head->info_len) ||
3187             (test.head_size != m_head->head_size) ||
3188             (test.info_size != m_head->info_size))
3189         {
3190                 /* Error */
3191                 return (-1);
3192         }
3193
3194
3195         /* Accept the header */
3196         (*m_head) = test;
3197
3198
3199         /* Allocate the "m_info" array */
3200         C_MAKE(m_info, m_head->info_num, player_magic);
3201
3202         /* Read the "m_info" array */
3203         fd_read(fd, (char*)(m_info), m_head->info_size);
3204
3205
3206         /* Allocate the "m_name" array */
3207         C_MAKE(m_name, m_head->name_size, char);
3208
3209         /* Read the "m_name" array */
3210         fd_read(fd, (char*)(m_name), m_head->name_size);
3211
3212
3213         /* Allocate the "m_text" array */
3214         C_MAKE(m_text, m_head->text_size, char);
3215
3216         /* Read the "m_text" array */
3217         fd_read(fd, (char*)(m_text), m_head->text_size);
3218
3219         /* Success */
3220         return (0);
3221 }
3222
3223
3224 /*
3225  * Initialize the "m_info" array
3226  *
3227  * Note that we let each entry have a unique "name" and "text" string,
3228  * even if the string happens to be empty (everyone has a unique '\0').
3229  */
3230 static errr init_m_info(void)
3231 {
3232         int fd;
3233
3234         int mode = 0644;
3235
3236         errr err;
3237
3238         FILE *fp;
3239
3240         /* General buffer */
3241         char buf[1024];
3242
3243
3244         /*** Make the header ***/
3245
3246         /* Allocate the "header" */
3247         MAKE(m_head, header);
3248
3249         /* Save the "version" */
3250         m_head->v_major = FAKE_VER_MAJOR;
3251         m_head->v_minor = FAKE_VER_MINOR;
3252         m_head->v_patch = FAKE_VER_PATCH;
3253         m_head->v_extra = 0;
3254
3255         /* Save the "record" information */
3256         m_head->info_num = MAX_CLASS;
3257         m_head->info_len = sizeof(player_magic);
3258
3259         /* Save the size of "m_head" and "m_info" */
3260         m_head->head_size = sizeof(header);
3261         m_head->info_size = m_head->info_num * m_head->info_len;
3262
3263
3264 #ifdef ALLOW_TEMPLATES
3265
3266         /*** Load the binary image file ***/
3267
3268         /* Build the filename */
3269 #ifdef JP
3270         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info_j.raw");
3271 #else
3272         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info.raw");
3273 #endif
3274
3275
3276         /* Attempt to open the "raw" file */
3277         fd = fd_open(buf, O_RDONLY);
3278
3279         /* Process existing "raw" file */
3280         if (fd >= 0)
3281         {
3282 #ifdef CHECK_MODIFICATION_TIME
3283
3284                 err = check_modification_date(fd, "m_info_j.txt");
3285
3286 #endif /* CHECK_MODIFICATION_TIME */
3287
3288                 /* Attempt to parse the "raw" file */
3289                 if (!err)
3290                         err = init_m_info_raw(fd);
3291
3292                 /* Close it */
3293                 (void)fd_close(fd);
3294
3295                 /* Success */
3296                 if (!err) return (0);
3297         }
3298
3299
3300         /*** Make the fake arrays ***/
3301
3302         /* Fake the size of "m_name" and "m_text" */
3303         fake_name_size = FAKE_NAME_SIZE;
3304         fake_text_size = FAKE_TEXT_SIZE;
3305
3306         /* Allocate the "m_info" array */
3307         C_MAKE(m_info, m_head->info_num, player_magic);
3308
3309         /* Hack -- make "fake" arrays */
3310         C_MAKE(m_name, fake_name_size, char);
3311         C_MAKE(m_text, fake_text_size, char);
3312
3313
3314         /*** Load the ascii template file ***/
3315
3316         /* Build the filename */
3317
3318         path_build(buf, 1024, ANGBAND_DIR_EDIT, "m_info_j.txt");
3319
3320         /* Open the file */
3321         fp = my_fopen(buf, "r");
3322
3323         /* Parse it */
3324 #ifdef JP
3325         if (!fp) quit("'m_info_j.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤­¤Þ¤»¤ó¡£");
3326 #else
3327         if (!fp) quit("Cannot open 'm_info.txt' file.");
3328 #endif
3329
3330
3331         /* Parse the file */
3332         err = init_m_info_txt(fp, buf);
3333
3334         /* Close it */
3335         my_fclose(fp);
3336
3337         /* Errors */
3338         if (err)
3339         {
3340                 cptr oops;
3341
3342 #ifdef JP
3343               /* Error string */
3344               oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "̤ÃΤÎ");
3345
3346               /* Oops */
3347               msg_format("'m_info_j.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", error_line);
3348               msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
3349               msg_format("¹½Ê¸ '%s'¡£", buf);
3350               msg_print(NULL);
3351
3352               /* Quit */
3353               quit("'m_info_j.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼");
3354 #else
3355                 /* Error string */
3356                 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
3357
3358                 /* Oops */
3359                 msg_format("Error %d at line %d of 'm_info.txt'.", err, error_line);
3360                 msg_format("Record %d contains a '%s' error.", error_idx, oops);
3361                 msg_format("Parsing '%s'.", buf);
3362                 msg_print(NULL);
3363
3364                 /* Quit */
3365                 quit("Error in 'm_info.txt' file.");
3366 #endif
3367
3368         }
3369
3370
3371         /*** Dump the binary image file ***/
3372
3373         /* File type is "DATA" */
3374         FILE_TYPE(FILE_TYPE_DATA);
3375
3376         /* Build the filename */
3377 #ifdef JP
3378         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info_j.raw");
3379 #else
3380         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info.raw");
3381 #endif
3382
3383
3384         /* Kill the old file */
3385         (void)fd_kill(buf);
3386
3387         /* Attempt to create the raw file */
3388         fd = fd_make(buf, mode);
3389
3390         /* Dump to the file */
3391         if (fd >= 0)
3392         {
3393                 /* Dump it */
3394                 fd_write(fd, (char*)(m_head), m_head->head_size);
3395
3396                 /* Dump the "m_info" array */
3397                 fd_write(fd, (char*)(m_info), m_head->info_size);
3398
3399                 /* Dump the "m_name" array */
3400                 fd_write(fd, (char*)(m_name), m_head->name_size);
3401
3402                 /* Dump the "m_text" array */
3403                 fd_write(fd, (char*)(m_text), m_head->text_size);
3404
3405                 /* Close */
3406                 (void)fd_close(fd);
3407         }
3408
3409
3410         /*** Kill the fake arrays ***/
3411
3412         /* Free the "m_info" array */
3413         C_KILL(m_info, m_head->info_num, player_magic);
3414
3415         /* Hack -- Free the "fake" arrays */
3416         C_KILL(m_name, fake_name_size, char);
3417         C_KILL(m_text, fake_text_size, char);
3418
3419         /* Forget the array sizes */
3420         fake_name_size = 0;
3421         fake_text_size = 0;
3422
3423 #endif /* ALLOW_TEMPLATES */
3424
3425
3426         /*** Load the binary image file ***/
3427
3428         /* Build the filename */
3429 #ifdef JP
3430         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info_j.raw");
3431 #else
3432         path_build(buf, 1024, ANGBAND_DIR_DATA, "m_info.raw");
3433 #endif
3434
3435         /* Attempt to open the "raw" file */
3436         fd = fd_open(buf, O_RDONLY);
3437
3438         /* Process existing "raw" file */
3439 #ifdef JP
3440         if (fd < 0) quit("'m_info_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤­¤Þ¤»¤ó¡£");
3441 #else
3442         if (fd < 0) quit("Cannot load 'm_info.raw' file.");
3443 #endif
3444
3445
3446         /* Attempt to parse the "raw" file */
3447         err = init_m_info_raw(fd);
3448
3449         /* Close it */
3450         (void)fd_close(fd);
3451
3452         /* Error */
3453 #ifdef JP
3454         if (err) quit("'m_info_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ­¤Þ¤»¤ó¡£");
3455 #else
3456         if (err) quit("Cannot parse 'm_info.raw' file.");
3457 #endif
3458
3459
3460         /* Success */
3461         return (0);
3462 }
3463
3464
3465
3466 /*** Initialize others ***/
3467
3468 /*
3469  * Hack -- Objects sold in the stores -- by tval/sval pair.
3470  */
3471 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
3472 {
3473         {
3474                 /* General Store */
3475
3476                 { TV_FOOD, SV_FOOD_RATION },
3477                 { TV_FOOD, SV_FOOD_RATION },
3478                 { TV_FOOD, SV_FOOD_RATION },
3479                 { TV_FOOD, SV_FOOD_RATION },
3480
3481                 { TV_FOOD, SV_FOOD_RATION },
3482                 { TV_FOOD, SV_FOOD_BISCUIT },
3483                 { TV_FOOD, SV_FOOD_JERKY },
3484                 { TV_FOOD, SV_FOOD_JERKY },
3485
3486                 { TV_FOOD, SV_FOOD_PINT_OF_WINE },
3487                 { TV_FOOD, SV_FOOD_PINT_OF_ALE },
3488                 { TV_LITE, SV_LITE_TORCH },
3489                 { TV_LITE, SV_LITE_TORCH },
3490
3491                 { TV_LITE, SV_LITE_TORCH },
3492                 { TV_LITE, SV_LITE_TORCH },
3493                 { TV_LITE, SV_LITE_LANTERN },
3494                 { TV_LITE, SV_LITE_LANTERN },
3495
3496                 { TV_FLASK, 0 },
3497                 { TV_FLASK, 0 },
3498                 { TV_FLASK, 0 },
3499                 { TV_FLASK, 0 },
3500
3501                 { TV_FLASK, 0 },
3502                 { TV_FLASK, 0 },
3503                 { TV_SPIKE, 0 },
3504                 { TV_SPIKE, 0 },
3505
3506                 { TV_SHOT, SV_AMMO_NORMAL },
3507                 { TV_ARROW, SV_AMMO_NORMAL },
3508                 { TV_BOLT, SV_AMMO_NORMAL },
3509                 { TV_DIGGING, SV_SHOVEL },
3510
3511                 { TV_DIGGING, SV_PICK },
3512                 { TV_CLOAK, SV_CLOAK },
3513                 { TV_CLOAK, SV_CLOAK },
3514                 { TV_CLOAK, SV_FUR_CLOAK },
3515
3516                 { TV_FOOD, SV_FOOD_RATION },
3517                 { TV_FOOD, SV_FOOD_RATION },
3518                 { TV_FOOD, SV_FOOD_RATION },
3519                 { TV_FOOD, SV_FOOD_RATION },
3520
3521                 { TV_LITE, SV_LITE_TORCH },
3522                 { TV_LITE, SV_LITE_TORCH },
3523                 { TV_LITE, SV_LITE_LANTERN },
3524                 { TV_LITE, SV_LITE_LANTERN },
3525
3526                 { TV_FLASK, 0 },
3527                 { TV_FLASK, 0 },
3528
3529                 { TV_CAPTURE, 0 },
3530
3531                 { TV_FIGURINE, 0 },
3532
3533                 { TV_SHOT, SV_AMMO_NORMAL },
3534                 { TV_ARROW, SV_AMMO_NORMAL },
3535                 { TV_BOLT, SV_AMMO_NORMAL },
3536                 { TV_DIGGING, SV_SHOVEL }
3537         },
3538
3539         {
3540                 /* Armoury */
3541
3542                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
3543                 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
3544                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
3545                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
3546
3547                 { TV_HELM, SV_HARD_LEATHER_CAP },
3548                 { TV_HELM, SV_HARD_LEATHER_CAP },
3549                 { TV_HELM, SV_METAL_CAP },
3550                 { TV_HELM, SV_IRON_HELM },
3551
3552                 { TV_SOFT_ARMOR, SV_ROBE },
3553                 { TV_SOFT_ARMOR, SV_ROBE },
3554                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
3555                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
3556
3557                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
3558                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
3559                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
3560                 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
3561
3562                 { TV_SOFT_ARMOR, SV_RHINO_HIDE_ARMOR },
3563                 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
3564                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
3565                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
3566
3567                 { TV_HARD_ARMOR, SV_DOUBLE_RING_MAIL },
3568                 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
3569                 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL },
3570                 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL },
3571
3572                 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR },
3573                 { TV_HARD_ARMOR, SV_SPLINT_MAIL },
3574                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
3575                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
3576
3577                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
3578                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
3579                 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD },
3580                 { TV_SHIELD, SV_SMALL_METAL_SHIELD },
3581
3582                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
3583                 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
3584                 { TV_HELM, SV_HARD_LEATHER_CAP },
3585                 { TV_HELM, SV_HARD_LEATHER_CAP },
3586
3587                 { TV_SOFT_ARMOR, SV_ROBE },
3588                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
3589                 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
3590                 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
3591
3592                 { TV_SOFT_ARMOR, SV_LEATHER_JACK },
3593                 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
3594                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
3595                 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
3596
3597                 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
3598                 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
3599                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
3600                 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }
3601         },
3602
3603         {
3604                 /* Weaponsmith */
3605
3606                 { TV_SWORD, SV_DAGGER },
3607                 { TV_SWORD, SV_MAIN_GAUCHE },
3608                 { TV_SWORD, SV_RAPIER },
3609                 { TV_SWORD, SV_SMALL_SWORD },
3610
3611                 { TV_SWORD, SV_SHORT_SWORD },
3612                 { TV_SWORD, SV_SABRE },
3613                 { TV_SWORD, SV_CUTLASS },
3614                 { TV_SWORD, SV_TULWAR },
3615
3616                 { TV_SWORD, SV_BROAD_SWORD },
3617                 { TV_SWORD, SV_LONG_SWORD },
3618                 { TV_SWORD, SV_SCIMITAR },
3619                 { TV_SWORD, SV_KATANA },
3620
3621                 { TV_SWORD, SV_BASTARD_SWORD },
3622                 { TV_POLEARM, SV_SPEAR },
3623                 { TV_POLEARM, SV_AWL_PIKE },
3624                 { TV_POLEARM, SV_TRIDENT },
3625
3626                 { TV_POLEARM, SV_PIKE },
3627                 { TV_POLEARM, SV_BEAKED_AXE },
3628                 { TV_POLEARM, SV_BROAD_AXE },
3629                 { TV_POLEARM, SV_LANCE },
3630
3631                 { TV_POLEARM, SV_BATTLE_AXE },
3632                 { TV_POLEARM, SV_HATCHET },
3633                 { TV_BOW, SV_SLING },
3634                 { TV_BOW, SV_SHORT_BOW },
3635
3636                 { TV_BOW, SV_LONG_BOW },
3637                 { TV_BOW, SV_LIGHT_XBOW },
3638                 { TV_SHOT, SV_AMMO_NORMAL },
3639                 { TV_SHOT, SV_AMMO_NORMAL },
3640
3641                 { TV_ARROW, SV_AMMO_NORMAL },
3642                 { TV_ARROW, SV_AMMO_NORMAL },
3643                 { TV_BOLT, SV_AMMO_NORMAL },
3644                 { TV_BOLT, SV_AMMO_NORMAL },
3645
3646                 { TV_BOW, SV_LONG_BOW },
3647                 { TV_BOW, SV_LIGHT_XBOW },
3648                 { TV_ARROW, SV_AMMO_NORMAL },
3649                 { TV_BOLT, SV_AMMO_NORMAL },
3650
3651                 { TV_BOW, SV_SHORT_BOW },
3652                 { TV_SWORD, SV_DAGGER },
3653                 { TV_SWORD, SV_TANTO },
3654                 { TV_SWORD, SV_RAPIER },
3655
3656                 { TV_SWORD, SV_SMALL_SWORD },
3657                 { TV_SWORD, SV_SHORT_SWORD },
3658                 { TV_SWORD, SV_LONG_SWORD },
3659                 { TV_SWORD, SV_SCIMITAR },
3660
3661                 { TV_HISSATSU_BOOK, 0 },
3662                 { TV_HISSATSU_BOOK, 0 },
3663                 { TV_HISSATSU_BOOK, 1 },
3664                 { TV_HISSATSU_BOOK, 1 },
3665         },
3666
3667         {
3668                 /* Temple */
3669
3670                 { TV_HAFTED, SV_NUNCHAKU },
3671                 { TV_HAFTED, SV_QUARTERSTAFF },
3672                 { TV_HAFTED, SV_MACE },
3673                 { TV_HAFTED, SV_BO_STAFF },
3674
3675                 { TV_HAFTED, SV_WAR_HAMMER },
3676                 { TV_HAFTED, SV_WAR_HAMMER },
3677                 { TV_HAFTED, SV_MORNING_STAR },
3678                 { TV_HAFTED, SV_FLAIL },
3679
3680                 { TV_HAFTED, SV_LEAD_FILLED_MACE },
3681                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
3682                 { TV_SCROLL, SV_SCROLL_BLESSING },
3683                 { TV_SCROLL, SV_SCROLL_HOLY_CHANT },
3684
3685                 { TV_POTION, SV_POTION_HEROISM },
3686                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3687                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3688                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3689
3690                 { TV_POTION, SV_POTION_CURE_LIGHT },
3691                 { TV_POTION, SV_POTION_CURE_SERIOUS },
3692                 { TV_POTION, SV_POTION_CURE_SERIOUS },
3693                 { TV_POTION, SV_POTION_CURE_CRITICAL },
3694
3695                 { TV_POTION, SV_POTION_CURE_CRITICAL },
3696                 { TV_POTION, SV_POTION_RESTORE_EXP },
3697                 { TV_POTION, SV_POTION_RESTORE_EXP },
3698                 { TV_POTION, SV_POTION_RESTORE_EXP },
3699
3700                 { TV_LIFE_BOOK, 0 },
3701                 { TV_LIFE_BOOK, 0 },
3702                 { TV_LIFE_BOOK, 0 },
3703                 { TV_LIFE_BOOK, 0 },
3704
3705                 { TV_LIFE_BOOK, 1 },
3706                 { TV_LIFE_BOOK, 1 },
3707                 { TV_LIFE_BOOK, 1 },
3708                 { TV_LIFE_BOOK, 1 },
3709
3710                 { TV_HAFTED, SV_WHIP },
3711                 { TV_HAFTED, SV_MACE },
3712                 { TV_HAFTED, SV_BALL_AND_CHAIN },
3713                 { TV_HAFTED, SV_WAR_HAMMER },
3714
3715                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3716                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3717                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3718                 { TV_POTION, SV_POTION_CURE_CRITICAL },
3719
3720                 { TV_POTION, SV_POTION_CURE_CRITICAL },
3721                 { TV_POTION, SV_POTION_RESTORE_EXP },
3722
3723                 { TV_FIGURINE, 0 },
3724                 { TV_STATUE, SV_ANY },
3725
3726                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
3727                 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
3728                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE },
3729                 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE }
3730         },
3731
3732         {
3733                 /* Alchemy shop */
3734
3735                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
3736                 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
3737                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
3738                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3739
3740                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3741                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3742                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3743                 { TV_SCROLL, SV_SCROLL_LIGHT },
3744
3745                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
3746                 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
3747                 { TV_SCROLL, SV_SCROLL_TELEPORT },
3748                 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION },
3749
3750                 { TV_SCROLL, SV_SCROLL_MAPPING },
3751                 { TV_SCROLL, SV_SCROLL_DETECT_GOLD },
3752                 { TV_SCROLL, SV_SCROLL_DETECT_ITEM },
3753                 { TV_SCROLL, SV_SCROLL_DETECT_TRAP },
3754
3755                 { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
3756                 { TV_SCROLL, SV_SCROLL_RECHARGING },
3757                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
3758                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3759
3760                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3761                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3762                 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
3763                 { TV_SCROLL, SV_SCROLL_TELEPORT },
3764
3765                 { TV_SCROLL, SV_SCROLL_TELEPORT },
3766                 { TV_POTION, SV_POTION_RES_STR },
3767                 { TV_POTION, SV_POTION_RES_INT },
3768                 { TV_POTION, SV_POTION_RES_WIS },
3769
3770                 { TV_POTION, SV_POTION_RES_DEX },
3771                 { TV_POTION, SV_POTION_RES_CON },
3772                 { TV_POTION, SV_POTION_RES_CHR },
3773                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3774
3775                 { TV_SCROLL, SV_SCROLL_IDENTIFY },
3776                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },  /* Yep, occasionally! */
3777                 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },
3778                 { TV_SCROLL, SV_SCROLL_LIGHT },
3779
3780                 { TV_POTION, SV_POTION_RES_STR },
3781                 { TV_POTION, SV_POTION_RES_INT },
3782                 { TV_POTION, SV_POTION_RES_WIS },
3783                 { TV_POTION, SV_POTION_RES_DEX },
3784
3785                 { TV_POTION, SV_POTION_RES_CON },
3786                 { TV_POTION, SV_POTION_RES_CHR },
3787                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
3788                 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
3789
3790                 { TV_SCROLL, SV_SCROLL_RECHARGING },
3791                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
3792                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER },
3793                 { TV_SCROLL, SV_SCROLL_SATISFY_HUNGER }
3794
3795         },
3796
3797         {
3798                 /* Magic-User store */
3799
3800                 { TV_RING, SV_RING_PROTECTION },
3801                 { TV_RING, SV_RING_FEATHER_FALL },
3802                 { TV_RING, SV_RING_PROTECTION },
3803                 { TV_RING, SV_RING_RESIST_FIRE },
3804
3805                 { TV_RING, SV_RING_RESIST_COLD },
3806                 { TV_AMULET, SV_AMULET_CHARISMA },
3807                 { TV_RING, SV_RING_WARNING },
3808                 { TV_AMULET, SV_AMULET_RESIST_ACID },
3809
3810                 { TV_AMULET, SV_AMULET_SEARCHING },
3811                 { TV_WAND, SV_WAND_SLOW_MONSTER },
3812                 { TV_WAND, SV_WAND_CONFUSE_MONSTER },
3813                 { TV_WAND, SV_WAND_SLEEP_MONSTER },
3814
3815                 { TV_WAND, SV_WAND_MAGIC_MISSILE },
3816                 { TV_WAND, SV_WAND_STINKING_CLOUD },
3817                 { TV_WAND, SV_WAND_WONDER },
3818                 { TV_WAND, SV_WAND_DISARMING },
3819
3820                 { TV_STAFF, SV_STAFF_LITE },
3821                 { TV_STAFF, SV_STAFF_MAPPING },
3822                 { TV_STAFF, SV_STAFF_DETECT_TRAP },
3823                 { TV_STAFF, SV_STAFF_DETECT_DOOR },
3824
3825                 { TV_STAFF, SV_STAFF_DETECT_GOLD },
3826                 { TV_STAFF, SV_STAFF_DETECT_ITEM },
3827                 { TV_STAFF, SV_STAFF_DETECT_INVIS },
3828                 { TV_STAFF, SV_STAFF_DETECT_EVIL },
3829
3830                 { TV_STAFF, SV_STAFF_TELEPORTATION },
3831                 { TV_STAFF, SV_STAFF_TELEPORTATION },
3832                 { TV_STAFF, SV_STAFF_TELEPORTATION },
3833                 { TV_STAFF, SV_STAFF_TELEPORTATION },
3834
3835                 { TV_STAFF, SV_STAFF_IDENTIFY },
3836                 { TV_STAFF, SV_STAFF_IDENTIFY },
3837                 { TV_STAFF, SV_STAFF_IDENTIFY },
3838
3839                 { TV_STAFF, SV_STAFF_IDENTIFY },
3840                 { TV_STAFF, SV_STAFF_REMOVE_CURSE },
3841                 { TV_STAFF, SV_STAFF_CURE_LIGHT },
3842                 { TV_STAFF, SV_STAFF_PROBING },
3843
3844                 { TV_FIGURINE, 0 },
3845
3846                 { TV_SORCERY_BOOK, 0 },
3847                 { TV_SORCERY_BOOK, 0 },
3848                 { TV_SORCERY_BOOK, 1 },
3849                 { TV_SORCERY_BOOK, 1 },
3850
3851                 { TV_ARCANE_BOOK, 0 },
3852                 { TV_ARCANE_BOOK, 0 },
3853                 { TV_ARCANE_BOOK, 1 },
3854                 { TV_ARCANE_BOOK, 1 },
3855
3856                 { TV_ARCANE_BOOK, 2 },
3857                 { TV_ARCANE_BOOK, 2 },
3858                 { TV_ARCANE_BOOK, 3 },
3859                 { TV_ARCANE_BOOK, 3 },
3860
3861         },
3862
3863         {
3864                 /* Black Market (unused) */
3865                 { 0, 0 },
3866                 { 0, 0 },
3867                 { 0, 0 },
3868                 { 0, 0 },
3869                 { 0, 0 },
3870                 { 0, 0 },
3871                 { 0, 0 },
3872                 { 0, 0 },
3873                 { 0, 0 },
3874                 { 0, 0 },
3875                 { 0, 0 },
3876                 { 0, 0 },
3877                 { 0, 0 },
3878                 { 0, 0 },
3879                 { 0, 0 },
3880                 { 0, 0 },
3881                 { 0, 0 },
3882                 { 0, 0 },
3883                 { 0, 0 },
3884                 { 0, 0 },
3885                 { 0, 0 },
3886                 { 0, 0 },
3887                 { 0, 0 },
3888                 { 0, 0 },
3889                 { 0, 0 },
3890                 { 0, 0 },
3891                 { 0, 0 },
3892                 { 0, 0 },
3893                 { 0, 0 },
3894                 { 0, 0 },
3895                 { 0, 0 },
3896                 { 0, 0 }
3897         },
3898
3899         {
3900                 /* Home (unused) */
3901                 { 0, 0 },
3902                 { 0, 0 },
3903                 { 0, 0 },
3904                 { 0, 0 },
3905                 { 0, 0 },
3906                 { 0, 0 },
3907                 { 0, 0 },
3908                 { 0, 0 },
3909                 { 0, 0 },
3910                 { 0, 0 },
3911                 { 0, 0 },
3912                 { 0, 0 },
3913                 { 0, 0 },
3914                 { 0, 0 },
3915                 { 0, 0 },
3916                 { 0, 0 },
3917                 { 0, 0 },
3918                 { 0, 0 },
3919                 { 0, 0 },
3920                 { 0, 0 },
3921                 { 0, 0 },
3922                 { 0, 0 },
3923                 { 0, 0 },
3924                 { 0, 0 },
3925                 { 0, 0 },
3926                 { 0, 0 },
3927                 { 0, 0 },
3928                 { 0, 0 },
3929                 { 0, 0 },
3930                 { 0, 0 },
3931                 { 0, 0 },
3932                 { 0, 0 }
3933         },
3934
3935         {
3936                 /* Bookstore */
3937                 { TV_SORCERY_BOOK, 0 },
3938                 { TV_SORCERY_BOOK, 0 },
3939                 { TV_SORCERY_BOOK, 1 },
3940                 { TV_SORCERY_BOOK, 1 },
3941
3942                 { TV_NATURE_BOOK, 0 },
3943                 { TV_NATURE_BOOK, 0 },
3944                 { TV_NATURE_BOOK, 1 },
3945                 { TV_NATURE_BOOK, 1 },
3946
3947                 { TV_CHAOS_BOOK, 0 },
3948                 { TV_CHAOS_BOOK, 0 },
3949                 { TV_CHAOS_BOOK, 1 },
3950                 { TV_CHAOS_BOOK, 1 },
3951
3952                 { TV_DEATH_BOOK, 0 },
3953                 { TV_DEATH_BOOK, 0 },
3954                 { TV_DEATH_BOOK, 1 },
3955                 { TV_DEATH_BOOK, 1 },
3956
3957                 { TV_TRUMP_BOOK, 0 },           /* +16 */
3958                 { TV_TRUMP_BOOK, 0 },
3959                 { TV_TRUMP_BOOK, 1 },
3960                 { TV_TRUMP_BOOK, 1 },
3961
3962                 { TV_ARCANE_BOOK, 0 },
3963                 { TV_ARCANE_BOOK, 1 },
3964                 { TV_ARCANE_BOOK, 2 },
3965                 { TV_ARCANE_BOOK, 3 },
3966
3967                 { TV_ENCHANT_BOOK, 0 },
3968                 { TV_ENCHANT_BOOK, 0 },
3969                 { TV_ENCHANT_BOOK, 1 },
3970                 { TV_ENCHANT_BOOK, 1 },
3971
3972                 { TV_DAEMON_BOOK, 0 },
3973                 { TV_DAEMON_BOOK, 0 },
3974                 { TV_DAEMON_BOOK, 1 },
3975                 { TV_DAEMON_BOOK, 1 },
3976
3977                 { TV_MUSIC_BOOK, 0 },
3978                 { TV_MUSIC_BOOK, 0 },
3979                 { TV_MUSIC_BOOK, 1 },
3980                 { TV_MUSIC_BOOK, 1 },
3981         },
3982
3983         {
3984                 /* Museum (unused) */
3985                 { 0, 0 },
3986                 { 0, 0 },
3987                 { 0, 0 },
3988                 { 0, 0 },
3989                 { 0, 0 },
3990                 { 0, 0 },
3991                 { 0, 0 },
3992                 { 0, 0 },
3993                 { 0, 0 },
3994                 { 0, 0 },
3995                 { 0, 0 },
3996                 { 0, 0 },
3997                 { 0, 0 },
3998                 { 0, 0 },
3999                 { 0, 0 },
4000                 { 0, 0 },
4001                 { 0, 0 },
4002                 { 0, 0 },
4003                 { 0, 0 },
4004                 { 0, 0 },
4005                 { 0, 0 },
4006                 { 0, 0 },
4007                 { 0, 0 },
4008                 { 0, 0 },
4009                 { 0, 0 },
4010                 { 0, 0 },
4011                 { 0, 0 },
4012                 { 0, 0 },
4013                 { 0, 0 },
4014                 { 0, 0 },
4015                 { 0, 0 },
4016                 { 0, 0 }
4017         }
4018 };
4019
4020
4021 /*
4022  * Initialize misc. values
4023  */
4024 static errr init_misc(void)
4025 {
4026         /* Initialize the values */
4027         process_dungeon_file("misc_j.txt", 0, 0, 0, 0);
4028
4029         return 0;
4030 }
4031
4032
4033 /*
4034  * Initialize town array
4035  */
4036 static errr init_towns(void)
4037 {
4038         int i, j, k;
4039
4040         /*** Prepare the Towns ***/
4041
4042         /* Allocate the towns */
4043         C_MAKE(town, max_towns, town_type);
4044
4045         for (i = 1; i < max_towns; i++)
4046         {
4047                 /*** Prepare the Stores ***/
4048
4049                 /* Allocate the stores */
4050                 C_MAKE(town[i].store, MAX_STORES, store_type);
4051
4052                 /* Fill in each store */
4053                 for (j = 0; j < MAX_STORES; j++)
4054                 {
4055                         /* Access the store */
4056                         store_type *st_ptr = &town[i].store[j];
4057
4058                         if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
4059
4060                         /* Assume full stock */
4061
4062                 /*
4063                  * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë±£¤·µ¡Ç½¤Î¤¿¤á¤Î½àÈ÷¡£
4064                  * ¥ª¥×¥·¥ç¥ó¤¬Í­¸ú¤Ç¤â¤½¤¦¤Ç¤Ê¤¯¤Æ¤â°ì±þ¥¹¥Ú¡¼¥¹
4065                  * ¤òºî¤Ã¤Æ¤ª¤¯¡£
4066                  */
4067                 if (j == STORE_HOME)
4068                 {
4069                         st_ptr->stock_size = (STORE_INVEN_MAX * 10);
4070                 }
4071                 else if (j == STORE_MUSEUM)
4072                 {
4073                         st_ptr->stock_size = (STORE_INVEN_MAX * 50);
4074                 }
4075                 else
4076                 {
4077                         st_ptr->stock_size = STORE_INVEN_MAX;
4078                 }
4079
4080
4081                         /* Allocate the stock */
4082                         C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
4083
4084                         /* No table for the black market or home */
4085                         if ((j == STORE_BLACK) || (j == STORE_HOME)) continue;
4086
4087                         /* Assume full table */
4088                         st_ptr->table_size = STORE_CHOICES;
4089
4090                         /* Allocate the stock */
4091                         C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
4092
4093                         /* Scan the choices */
4094                         for (k = 0; k < STORE_CHOICES; k++)
4095                         {
4096                                 int k_idx;
4097
4098                                 /* Extract the tval/sval codes */
4099                                 int tv = store_table[j][k][0];
4100                                 int sv = store_table[j][k][1];
4101
4102                                 /* Look for it */
4103                                 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
4104                                 {
4105                                         object_kind *k_ptr = &k_info[k_idx];
4106
4107                                         /* Found a match */
4108                                         if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
4109                                 }
4110
4111                                 /* Catch errors */
4112                                 if (k_idx == max_k_idx) continue;
4113
4114                                 /* Add that item index to the table */
4115                                 st_ptr->table[st_ptr->table_num++] = k_idx;
4116                         }
4117                 }
4118         }
4119
4120         return 0;
4121 }
4122
4123 /*
4124  * Initialize buildings
4125  */
4126 errr init_buildings(void)
4127 {
4128         int i, j;
4129
4130         for (i = 0; i < MAX_BLDG; i++)
4131         {
4132                 building[i].name[0] = '\0';
4133                 building[i].owner_name[0] = '\0';
4134                 building[i].owner_race[0] = '\0';
4135
4136                 for (j = 0; j < 8; j++)
4137                 {
4138                         building[i].act_names[j][0] = '\0';
4139                         building[i].member_costs[j] = 0;
4140                         building[i].other_costs[j] = 0;
4141                         building[i].letters[j] = 0;
4142                         building[i].actions[j] = 0;
4143                         building[i].action_restr[j] = 0;
4144                 }
4145
4146                 for (j = 0; j < MAX_CLASS; j++)
4147                 {
4148                         building[i].member_class[j] = 0;
4149                 }
4150
4151                 for (j = 0; j < MAX_RACES; j++)
4152                 {
4153                         building[i].member_race[j] = 0;
4154                 }
4155
4156                 for (j = 0; j < MAX_MAGIC+1; j++)
4157                 {
4158                         building[i].member_realm[j] = 0;
4159                 }
4160         }
4161
4162         return (0);
4163 }
4164
4165
4166 /*
4167  * Initialize quest array
4168  */
4169 static errr init_quests(void)
4170 {
4171         int i;
4172
4173         /*** Prepare the quests ***/
4174
4175         /* Allocate the quests */
4176         C_MAKE(quest, max_quests, quest_type);
4177
4178         /* Set all quest to "untaken" */
4179         for (i = 0; i < max_quests; i++)
4180         {
4181                 quest[i].status = QUEST_STATUS_UNTAKEN;
4182         }
4183
4184         return 0;
4185 }
4186
4187
4188 /*
4189  * Initialize some other arrays
4190  */
4191 static errr init_other(void)
4192 {
4193         int i, n;
4194
4195
4196         /*** Prepare the "dungeon" information ***/
4197
4198         /* Allocate and Wipe the object list */
4199         C_MAKE(o_list, max_o_idx, object_type);
4200
4201         /* Allocate and Wipe the monster list */
4202         C_MAKE(m_list, max_m_idx, monster_type);
4203
4204         /* Allocate and Wipe the max dungeon level */
4205         C_MAKE(max_dlv, max_d_idx, s16b);
4206
4207         /* Allocate and wipe each line of the cave */
4208         for (i = 0; i < MAX_HGT; i++)
4209         {
4210                 /* Allocate one row of the cave */
4211                 C_MAKE(cave[i], MAX_WID, cave_type);
4212         }
4213
4214
4215         /*** Prepare the various "bizarre" arrays ***/
4216
4217         /* Macro variables */
4218         C_MAKE(macro__pat, MACRO_MAX, cptr);
4219         C_MAKE(macro__act, MACRO_MAX, cptr);
4220         C_MAKE(macro__cmd, MACRO_MAX, bool);
4221
4222         /* Macro action buffer */
4223         C_MAKE(macro__buf, 1024, char);
4224
4225         /* Quark variables */
4226         C_MAKE(quark__str, QUARK_MAX, cptr);
4227
4228         /* Message variables */
4229         C_MAKE(message__ptr, MESSAGE_MAX, u16b);
4230         C_MAKE(message__buf, MESSAGE_BUF, char);
4231
4232         /* Hack -- No messages yet */
4233         message__tail = MESSAGE_BUF;
4234
4235
4236         /*** Prepare the Player inventory ***/
4237
4238         /* Allocate it */
4239         C_MAKE(inventory, INVEN_TOTAL, object_type);
4240
4241
4242         /*** Pre-allocate the basic "auto-inscriptions" ***/
4243
4244         /* The "basic" feelings */
4245 #ifdef JP
4246         (void)quark_add("¼ö¤ï¤ì¤Æ¤¤¤ë");
4247         (void)quark_add("²õ¤ì¤Æ¤¤¤ë");
4248         (void)quark_add("ÊÂ");
4249         (void)quark_add("¾å¼Á");
4250 #else
4251         (void)quark_add("cursed");
4252         (void)quark_add("broken");
4253         (void)quark_add("average");
4254         (void)quark_add("good");
4255 #endif
4256
4257
4258         /* The "extra" feelings */
4259 #ifdef JP
4260         (void)quark_add("¹âµéÉÊ");
4261         (void)quark_add("̵²ÁÃÍ");
4262         (void)quark_add("ÆÃÊÌÀ½");
4263         (void)quark_add("¶²¤í¤·¤¤");
4264 #else
4265         (void)quark_add("excellent");
4266         (void)quark_add("worthless");
4267         (void)quark_add("special");
4268         (void)quark_add("terrible");
4269 #endif
4270
4271
4272         /* Some extra strings */
4273 #ifdef JP
4274         (void)quark_add("¼ö¤¤¤Ê¤·");
4275         (void)quark_add("Çä½ÐÃæ");
4276 #else
4277         (void)quark_add("uncursed");
4278         (void)quark_add("on sale");
4279 #endif
4280
4281
4282
4283         /*** Prepare the options ***/
4284
4285         /* Scan the options */
4286         for (i = 0; option_info[i].o_desc; i++)
4287         {
4288                 int os = option_info[i].o_set;
4289                 int ob = option_info[i].o_bit;
4290
4291                 /* Set the "default" options */
4292                 if (option_info[i].o_var)
4293                 {
4294                         /* Accept */
4295                         option_mask[os] |= (1L << ob);
4296
4297                         /* Set */
4298                         if (option_info[i].o_norm)
4299                         {
4300                                 /* Set */
4301                                 option_flag[os] |= (1L << ob);
4302                         }
4303
4304                         /* Clear */
4305                         else
4306                         {
4307                                 /* Clear */
4308                                 option_flag[os] &= ~(1L << ob);
4309                         }
4310                 }
4311         }
4312
4313         /* Analyze the windows */
4314         for (n = 0; n < 8; n++)
4315         {
4316                 /* Analyze the options */
4317                 for (i = 0; i < 32; i++)
4318                 {
4319                         /* Accept */
4320                         if (window_flag_desc[i])
4321                         {
4322                                 /* Accept */
4323                                 window_mask[n] |= (1L << i);
4324                         }
4325                 }
4326         }
4327
4328
4329         /*** Pre-allocate space for the "format()" buffer ***/
4330
4331         /* Hack -- Just call the "format()" function */
4332         (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
4333
4334
4335         /* Success */
4336         return (0);
4337 }
4338
4339
4340
4341 /*
4342  * Initialize some other arrays
4343  */
4344 static errr init_alloc(void)
4345 {
4346         int i;
4347         monster_race *r_ptr;
4348
4349 #ifdef SORT_R_INFO
4350
4351         tag_type *elements;
4352
4353         /* Allocate the "r_info" array */
4354         C_MAKE(elements, max_r_idx, tag_type);
4355
4356         /* Scan the monsters */
4357         for (i = 1; i < max_r_idx; i++)
4358         {
4359                 elements[i].tag = r_info[i].level;
4360                 elements[i].pointer = (void*)i;
4361         }
4362
4363         tag_sort(elements, max_r_idx);
4364
4365         /*** Initialize monster allocation info ***/
4366
4367         /* Size of "alloc_race_table" */
4368         alloc_race_size = max_r_idx;
4369
4370         /* Allocate the alloc_race_table */
4371         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
4372
4373         /* Scan the monsters */
4374         for (i = 1; i < max_r_idx; i++)
4375         {
4376                 /* Get the i'th race */
4377                 r_ptr = &r_info[(int)elements[i].pointer];
4378
4379                 /* Count valid pairs */
4380                 if (r_ptr->rarity)
4381                 {
4382                         int p, x;
4383
4384                         /* Extract the base level */
4385                         x = r_ptr->level;
4386
4387                         /* Extract the base probability */
4388                         p = (100 / r_ptr->rarity);
4389
4390                         /* Load the entry */
4391                         alloc_race_table[i].index = (int)elements[i].pointer;
4392                         alloc_race_table[i].level = x;
4393                         alloc_race_table[i].prob1 = p;
4394                         alloc_race_table[i].prob2 = p;
4395                         alloc_race_table[i].prob3 = p;
4396                 }
4397         }
4398
4399 #else /* SORT_R_INFO */
4400
4401         int j;
4402         alloc_entry *table;
4403         s16b num[MAX_DEPTH];
4404         s16b aux[MAX_DEPTH];
4405
4406         /*** Analyze monster allocation info ***/
4407
4408         /* Clear the "aux" array */
4409         C_WIPE(&aux, MAX_DEPTH, s16b);
4410
4411         /* Clear the "num" array */
4412         C_WIPE(&num, MAX_DEPTH, s16b);
4413
4414         /* Size of "alloc_race_table" */
4415         alloc_race_size = 0;
4416
4417         /* Scan the monsters */
4418         for (i = 1; i < max_r_idx; i++)
4419         {
4420                 /* Get the i'th race */
4421                 r_ptr = &r_info[i];
4422
4423                 /* Legal monsters */
4424                 if (r_ptr->rarity)
4425                 {
4426                         /* Count the entries */
4427                         alloc_race_size++;
4428
4429                         /* Group by level */
4430                         num[r_ptr->level]++;
4431                 }
4432         }
4433
4434         /* Collect the level indexes */
4435         for (i = 1; i < MAX_DEPTH; i++)
4436         {
4437                 /* Group by level */
4438                 num[i] += num[i-1];
4439         }
4440
4441         /* Paranoia */
4442 #ifdef JP
4443         if (!num[0]) quit("Ä®¤Î¥â¥ó¥¹¥¿¡¼¤¬¤Ê¤¤¡ª");
4444 #else
4445         if (!num[0]) quit("No town monsters!");
4446 #endif
4447
4448
4449
4450         /*** Initialize monster allocation info ***/
4451
4452         /* Allocate the alloc_race_table */
4453         C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
4454
4455         /* Access the table entry */
4456         table = alloc_race_table;
4457
4458         /* Scan the monsters */
4459         for (i = 1; i < max_r_idx; i++)
4460         {
4461                 /* Get the i'th race */
4462                 r_ptr = &r_info[i];
4463
4464                 /* Count valid pairs */
4465                 if (r_ptr->rarity)
4466                 {
4467                         int p, x, y, z;
4468
4469                         /* Extract the base level */
4470                         x = r_ptr->level;
4471
4472                         /* Extract the base probability */
4473                         p = (100 / r_ptr->rarity);
4474
4475                         /* Skip entries preceding our locale */
4476                         y = (x > 0) ? num[x-1] : 0;
4477
4478                         /* Skip previous entries at this locale */
4479                         z = y + aux[x];
4480
4481                         /* Load the entry */
4482                         table[z].index = i;
4483                         table[z].level = x;
4484                         table[z].prob1 = p;
4485                         table[z].prob2 = p;
4486                         table[z].prob3 = p;
4487
4488                         /* Another entry complete for this locale */
4489                         aux[x]++;
4490                 }
4491         }
4492
4493 #endif /* SORT_R_INFO */
4494
4495         /* Init the "alloc_kind_table" */
4496         (void)init_object_alloc();
4497
4498         /* Success */
4499         return (0);
4500 }
4501
4502
4503
4504 /*
4505  * Hack -- take notes on line 23
4506  */
4507 static void note(cptr str)
4508 {
4509         Term_erase(0, 23, 255);
4510         Term_putstr(20, 23, -1, TERM_WHITE, str);
4511         Term_fresh();
4512 }
4513
4514
4515
4516 /*
4517  * Hack -- Explain a broken "lib" folder and quit (see below).
4518  *
4519  * XXX XXX XXX This function is "messy" because various things
4520  * may or may not be initialized, but the "plog()" and "quit()"
4521  * functions are "supposed" to work under any conditions.
4522  */
4523 static void init_angband_aux(cptr why)
4524 {
4525         /* Why */
4526         plog(why);
4527
4528 #ifdef JP
4529         /* Explain */
4530         plog("'lib'¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¤«²õ¤ì¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£");
4531
4532         /* More details */
4533         plog("¤Ò¤ç¤Ã¤È¤¹¤ë¤È¥¢¡¼¥«¥¤¥Ö¤¬Àµ¤·¤¯²òÅव¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡£");
4534
4535         /* Explain */
4536         plog("³ºÅö¤¹¤ë'README'¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç³Îǧ¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡£");
4537
4538         /* Quit with error */
4539         quit("Ã×̿Ū¤Ê¥¨¥é¡¼¡£");
4540 #else
4541         /* Explain */
4542         plog("The 'lib' directory is probably missing or broken.");
4543
4544         /* More details */
4545         plog("Perhaps the archive was not extracted correctly.");
4546
4547         /* Explain */
4548         plog("See the 'README' file for more information.");
4549
4550         /* Quit with error */
4551         quit("Fatal Error.");
4552 #endif
4553
4554 }
4555
4556
4557 /*
4558  * Hack -- main Angband initialization entry point
4559  *
4560  * Verify some files, display the "news.txt" file, create
4561  * the high score file, initialize all internal arrays, and
4562  * load the basic "user pref files".
4563  *
4564  * Be very careful to keep track of the order in which things
4565  * are initialized, in particular, the only thing *known* to
4566  * be available when this function is called is the "z-term.c"
4567  * package, and that may not be fully initialized until the
4568  * end of this function, when the default "user pref files"
4569  * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
4570  *
4571  * Note that this function attempts to verify the "news" file,
4572  * and the game aborts (cleanly) on failure, since without the
4573  * "news" file, it is likely that the "lib" folder has not been
4574  * correctly located.  Otherwise, the news file is displayed for
4575  * the user.
4576  *
4577  * Note that this function attempts to verify (or create) the
4578  * "high score" file, and the game aborts (cleanly) on failure,
4579  * since one of the most common "extraction" failures involves
4580  * failing to extract all sub-directories (even empty ones), such
4581  * as by failing to use the "-d" option of "pkunzip", or failing
4582  * to use the "save empty directories" option with "Compact Pro".
4583  * This error will often be caught by the "high score" creation
4584  * code below, since the "lib/apex" directory, being empty in the
4585  * standard distributions, is most likely to be "lost", making it
4586  * impossible to create the high score file.
4587  *
4588  * Note that various things are initialized by this function,
4589  * including everything that was once done by "init_some_arrays".
4590  *
4591  * This initialization involves the parsing of special files
4592  * in the "lib/data" and sometimes the "lib/edit" directories.
4593  *
4594  * Note that the "template" files are initialized first, since they
4595  * often contain errors.  This means that macros and message recall
4596  * and things like that are not available until after they are done.
4597  *
4598  * We load the default "user pref files" here in case any "color"
4599  * changes are needed before character creation.
4600  *
4601  * Note that the "graf-xxx.prf" file must be loaded separately,
4602  * if needed, in the first (?) pass through "TERM_XTRA_REACT".
4603  */
4604 void init_angband(void)
4605 {
4606         int fd = -1;
4607
4608         int mode = 0644;
4609
4610         FILE *fp;
4611
4612         char buf[1024];
4613
4614
4615         /*** Verify the "news" file ***/
4616
4617         /* Build the filename */
4618 #ifdef JP
4619         path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4620 #else
4621         path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
4622 #endif
4623
4624
4625         /* Attempt to open the file */
4626         fd = fd_open(buf, O_RDONLY);
4627
4628         /* Failure */
4629         if (fd < 0)
4630         {
4631                 char why[1024];
4632
4633                 /* Message */
4634 #ifdef JP
4635         sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤Ç¤­¤Þ¤»¤ó!", buf);
4636 #else
4637                 sprintf(why, "Cannot access the '%s' file!", buf);
4638 #endif
4639
4640
4641                 /* Crash and burn */
4642                 init_angband_aux(why);
4643         }
4644
4645         /* Close it */
4646         (void)fd_close(fd);
4647
4648
4649         /*** Display the "news" file ***/
4650
4651         /* Clear screen */
4652         Term_clear();
4653
4654         /* Build the filename */
4655 #ifdef JP
4656         path_build(buf, 1024, ANGBAND_DIR_FILE, "news_j.txt");
4657 #else
4658         path_build(buf, 1024, ANGBAND_DIR_FILE, "news.txt");
4659 #endif
4660
4661
4662         /* Open the News file */
4663         fp = my_fopen(buf, "r");
4664
4665         /* Dump */
4666         if (fp)
4667         {
4668                 int i = 0;
4669
4670                 /* Dump the file to the screen */
4671                 while (0 == my_fgets(fp, buf, 1024))
4672                 {
4673                         /* Display and advance */
4674                         Term_putstr(0, i++, -1, TERM_WHITE, buf);
4675                 }
4676
4677                 /* Close */
4678                 my_fclose(fp);
4679         }
4680
4681         /* Flush it */
4682         Term_fresh();
4683
4684
4685         /*** Verify (or create) the "high score" file ***/
4686
4687         /* Build the filename */
4688         path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
4689
4690         /* Attempt to open the high score file */
4691         fd = fd_open(buf, O_RDONLY);
4692
4693         /* Failure */
4694         if (fd < 0)
4695         {
4696                 /* File type is "DATA" */
4697                 FILE_TYPE(FILE_TYPE_DATA);
4698
4699                 /* Create a new high score file */
4700                 fd = fd_make(buf, mode);
4701
4702                 /* Failure */
4703                 if (fd < 0)
4704                 {
4705                         char why[1024];
4706
4707                         /* Message */
4708 #ifdef JP
4709                         sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤­¤Þ¤»¤ó!", buf);
4710 #else
4711                         sprintf(why, "Cannot create the '%s' file!", buf);
4712 #endif
4713
4714
4715                         /* Crash and burn */
4716                         init_angband_aux(why);
4717                 }
4718         }
4719
4720         /* Close it */
4721         (void)fd_close(fd);
4722
4723
4724         /*** Initialize some arrays ***/
4725
4726         /* Initialize misc. values */
4727 #ifdef JP
4728 note("[ÊÑ¿ô¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...(¤½¤Î¾)");
4729 #else
4730         note("[Initializing values... (misc)]");
4731 #endif
4732
4733 #ifdef JP
4734 if (init_misc()) quit("¤½¤Î¾¤ÎÊÑ¿ô¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4735 #else
4736         if (init_misc()) quit("Cannot initialize misc. values");
4737 #endif
4738
4739
4740 #ifdef USE_SCRIPT
4741 #ifdef JP
4742 note("[¥¹¥¯¥ê¥×¥È¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... ]");
4743 #else
4744         note("[Initializing scripts... ]");
4745 #endif
4746
4747 #ifdef JP
4748 if (init_script()) quit("¥¹¥¯¥ê¥×¥È¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4749 #else
4750         if (init_script()) quit("Cannot initialize scripts");
4751 #endif
4752
4753 #endif /* USE_SCRIPT */
4754
4755         /* Initialize feature info */
4756 #ifdef JP
4757         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÃÏ·Á)]");
4758         if (init_f_info()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
4759 #else
4760         note("[Initializing arrays... (features)]");
4761         if (init_f_info()) quit("Cannot initialize features");
4762 #endif
4763
4764
4765         /* Initialize object info */
4766 #ifdef JP
4767         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥¤¥Æ¥à)]");
4768         if (init_k_info()) quit("¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
4769 #else
4770         note("[Initializing arrays... (objects)]");
4771         if (init_k_info()) quit("Cannot initialize objects");
4772 #endif
4773
4774
4775         /* Initialize artifact info */
4776 #ifdef JP
4777         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÅÁÀâ¤Î¥¢¥¤¥Æ¥à)]");
4778         if (init_a_info()) quit("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
4779 #else
4780         note("[Initializing arrays... (artifacts)]");
4781         if (init_a_info()) quit("Cannot initialize artifacts");
4782 #endif
4783
4784
4785         /* Initialize ego-item info */
4786 #ifdef JP
4787         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à)]");
4788         if (init_e_info()) quit("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
4789 #else
4790         note("[Initializing arrays... (ego-items)]");
4791         if (init_e_info()) quit("Cannot initialize ego-items");
4792 #endif
4793
4794
4795         /* Initialize monster info */
4796 #ifdef JP
4797         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥â¥ó¥¹¥¿¡¼)]");
4798         if (init_r_info()) quit("¥â¥ó¥¹¥¿¡¼½é´ü²½ÉÔǽ");
4799 #else
4800         note("[Initializing arrays... (monsters)]");
4801         if (init_r_info()) quit("Cannot initialize monsters");
4802 #endif
4803
4804
4805         /* Initialize dungeon info */
4806 #ifdef JP
4807         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥À¥ó¥¸¥ç¥ó)]");
4808         if (init_d_info()) quit("¥À¥ó¥¸¥ç¥ó½é´ü²½ÉÔǽ");
4809 #else
4810         note("[Initializing arrays... (dungeon)]");
4811         if (init_d_info()) quit("Cannot initialize dungeon");
4812 #endif
4813         {
4814                 int i;
4815                 for (i = 1; i < max_d_idx; i++)
4816                         if (d_info[i].final_guardian)
4817                                 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
4818         }
4819
4820         /* Initialize magic info */
4821 #ifdef JP
4822         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ËâË¡)]");
4823         if (init_m_info()) quit("ËâË¡½é´ü²½ÉÔǽ");
4824 #else
4825         note("[Initializing arrays... (magic)]");
4826         if (init_m_info()) quit("Cannot initialize magic");
4827 #endif
4828
4829         /* Initialize weapon_exp info */
4830 #ifdef JP
4831         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (Éð´ï½ÏÎýÅÙ)]");
4832         if (init_we_info()) quit("Éð´ï½ÏÎýÅÙ½é´ü²½ÉÔǽ");
4833 #else
4834         note("[Initializing arrays... (weapon exp)]");
4835         if (init_we_info()) quit("Cannot initialize weapon exp");
4836 #endif
4837
4838         /* Initialize weapon_exp info */
4839 #ifdef JP
4840         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (µ»Ç½½ÏÎýÅÙ)]");
4841         if (init_se_info()) quit("µ»Ç½½ÏÎýÅÙ½é´ü²½ÉÔǽ");
4842 #else
4843         note("[Initializing arrays... (skill exp)]");
4844         if (init_se_info()) quit("Cannot initialize skill exp");
4845 #endif
4846
4847         /* Initialize wilderness array */
4848 #ifdef JP
4849 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¹ÓÌî)]");
4850 #else
4851         note("[Initializing arrays... (wilderness)]");
4852 #endif
4853
4854 #ifdef JP
4855 if (init_wilderness()) quit("¹ÓÌî¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4856 #else
4857         if (init_wilderness()) quit("Cannot initialize wilderness");
4858 #endif
4859
4860
4861         /* Initialize town array */
4862 #ifdef JP
4863 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (³¹)]");
4864 #else
4865         note("[Initializing arrays... (towns)]");
4866 #endif
4867
4868 #ifdef JP
4869 if (init_towns()) quit("³¹¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4870 #else
4871         if (init_towns()) quit("Cannot initialize towns");
4872 #endif
4873
4874
4875         /* Initialize building array */
4876 #ifdef JP
4877 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (·úʪ)]");
4878 #else
4879         note("[Initializing arrays... (buildings)]");
4880 #endif
4881
4882 #ifdef JP
4883 if (init_buildings()) quit("·úʪ¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4884 #else
4885         if (init_buildings()) quit("Cannot initialize buildings");
4886 #endif
4887
4888
4889         /* Initialize quest array */
4890 #ifdef JP
4891 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¥¯¥¨¥¹¥È)]");
4892 #else
4893         note("[Initializing arrays... (quests)]");
4894 #endif
4895
4896 #ifdef JP
4897 if (init_quests()) quit("¥¯¥¨¥¹¥È¤ò½é´ü²½¤Ç¤­¤Þ¤»¤ó");
4898 #else
4899         if (init_quests()) quit("Cannot initialize quests");
4900 #endif
4901
4902
4903         /* Initialize some other arrays */
4904 #ifdef JP
4905         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¤½¤Î¾)]");
4906         if (init_other()) quit("¤½¤Î¾¤Î¥Ç¡¼¥¿½é´ü²½ÉÔǽ");
4907 #else
4908         note("[Initializing arrays... (other)]");
4909         if (init_other()) quit("Cannot initialize other stuff");
4910 #endif
4911
4912
4913         /* Initialize some other arrays */
4914 #ifdef JP
4915         /* translation */
4916         note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥í¥±¡¼¥·¥ç¥ó)]");
4917         if (init_alloc()) quit("¥¢¥í¥±¡¼¥·¥ç¥ó¡¦¥¹¥¿¥Ã¥Õ½é´ü²½ÉÔǽ");
4918 #else
4919         note("[Initializing arrays... (alloc)]");
4920         if (init_alloc()) quit("Cannot initialize alloc stuff");
4921 #endif
4922
4923
4924
4925         /*** Load default user pref files ***/
4926
4927         /* Initialize feature info */
4928 #ifdef JP
4929 note("[¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...]");
4930 #else
4931         note("[Initializing user pref files...]");
4932 #endif
4933
4934
4935         /* Access the "basic" pref file */
4936         strcpy(buf, "pref.prf");
4937
4938         /* Process that file */
4939         process_pref_file(buf);
4940
4941         /* Access the "user" pref file */
4942         sprintf(buf, "user.prf");
4943
4944         /* Process that file */
4945         process_pref_file(buf);
4946
4947         /* Access the "basic" system pref file */
4948         sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
4949
4950         /* Process that file */
4951         process_pref_file(buf);
4952
4953         /* Access the "user" system pref file */
4954         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
4955
4956         /* Process that file */
4957         process_pref_file(buf);
4958
4959         /* Done */
4960 #ifdef JP
4961         note("[½é´ü²½½ªÎ»]");
4962 #else
4963         note("[Initialization complete]");
4964 #endif
4965
4966 }