3 /* Purpose: Initialization (part 2) -BEN- */
10 #ifdef CHECK_MODIFICATION_TIME
11 #include <sys/types.h>
13 #endif /* CHECK_MODIFICATION_TIME */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * The "init1.c" file is used only to parse the ascii template files,
33 * to create the binary image files. If you include the binary image
34 * files instead of the ascii template files, then you can undefine
35 * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c". Note
36 * that the binary image files are extremely system dependant.
42 * Find the default paths to all of our important sub-directories.
44 * The purpose of each sub-directory is described in "variable.c".
46 * All of the sub-directories should, by default, be located inside
47 * the main "lib" directory, whose location is very system dependant.
49 * This function takes a writable buffer, initially containing the
50 * "path" to the "lib" directory, for example, "/pkg/lib/angband/",
51 * or a system dependant string, for example, ":lib:". The buffer
52 * must be large enough to contain at least 32 more characters.
54 * Various command line options may allow some of the important
55 * directories to be changed to user-specified directories, most
56 * importantly, the "info" and "user" and "save" directories,
57 * but this is done after this function, see "main.c".
59 * In general, the initial path should end in the appropriate "PATH_SEP"
60 * string. All of the "sub-directory" paths (created below or supplied
61 * by the user) will NOT end in the "PATH_SEP" string, see the special
62 * "path_build()" function in "util.c" for more information.
64 * Mega-Hack -- support fat raw files under NEXTSTEP, using special
65 * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
66 * requiring the directories to be created by hand by the user.
68 * Hack -- first we free all the strings, since this is known
69 * to succeed even if the strings have not been allocated yet,
70 * as long as the variables start out as "NULL". This allows
71 * this function to be called multiple times, for example, to
72 * try several base "path" values until a good one is found.
74 void init_file_paths(char *path)
78 #ifdef PRIVATE_USER_PATH
80 #endif /* PRIVATE_USER_PATH */
82 /*** Free everything ***/
84 /* Free the main path */
85 string_free(ANGBAND_DIR);
87 /* Free the sub-paths */
88 string_free(ANGBAND_DIR_APEX);
89 string_free(ANGBAND_DIR_BONE);
90 string_free(ANGBAND_DIR_DATA);
91 string_free(ANGBAND_DIR_EDIT);
92 string_free(ANGBAND_DIR_SCRIPT);
93 string_free(ANGBAND_DIR_FILE);
94 string_free(ANGBAND_DIR_HELP);
95 string_free(ANGBAND_DIR_INFO);
96 string_free(ANGBAND_DIR_SAVE);
97 string_free(ANGBAND_DIR_USER);
98 string_free(ANGBAND_DIR_XTRA);
101 /*** Prepare the "path" ***/
103 /* Hack -- save the main directory */
104 ANGBAND_DIR = string_make(path);
106 /* Prepare to append to the Base Path */
107 tail = path + strlen(path);
112 /*** Use "flat" paths with VM/ESA ***/
114 /* Use "blank" path names */
115 ANGBAND_DIR_APEX = string_make("");
116 ANGBAND_DIR_BONE = string_make("");
117 ANGBAND_DIR_DATA = string_make("");
118 ANGBAND_DIR_EDIT = string_make("");
119 ANGBAND_DIR_SCRIPT = string_make("");
120 ANGBAND_DIR_FILE = string_make("");
121 ANGBAND_DIR_HELP = string_make("");
122 ANGBAND_DIR_INFO = string_make("");
123 ANGBAND_DIR_SAVE = string_make("");
124 ANGBAND_DIR_USER = string_make("");
125 ANGBAND_DIR_XTRA = string_make("");
131 /*** Build the sub-directory names ***/
133 /* Build a path name */
134 strcpy(tail, "apex");
135 ANGBAND_DIR_APEX = string_make(path);
137 /* Build a path name */
138 strcpy(tail, "bone");
139 ANGBAND_DIR_BONE = string_make(path);
141 /* Build a path name */
142 strcpy(tail, "data");
143 ANGBAND_DIR_DATA = string_make(path);
145 /* Build a path name */
146 strcpy(tail, "edit");
147 ANGBAND_DIR_EDIT = string_make(path);
149 /* Build a path name */
150 strcpy(tail, "script");
151 ANGBAND_DIR_SCRIPT = string_make(path);
153 /* Build a path name */
154 strcpy(tail, "file");
155 ANGBAND_DIR_FILE = string_make(path);
157 /* Build a path name */
158 strcpy(tail, "help");
159 ANGBAND_DIR_HELP = string_make(path);
161 /* Build a path name */
162 strcpy(tail, "info");
163 ANGBAND_DIR_INFO = string_make(path);
165 /* Build a path name */
166 strcpy(tail, "pref");
167 ANGBAND_DIR_PREF = string_make(path);
169 /* Build a path name */
170 strcpy(tail, "save");
171 ANGBAND_DIR_SAVE = string_make(path);
173 #ifdef PRIVATE_USER_PATH
175 /* Build the path to the user specific directory */
176 path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
178 /* Build a relative path name */
179 ANGBAND_DIR_USER = string_make(buf);
181 #else /* PRIVATE_USER_PATH */
183 /* Build a path name */
184 strcpy(tail, "user");
185 ANGBAND_DIR_USER = string_make(path);
187 #endif /* PRIVATE_USER_PATH */
189 /* Build a path name */
190 strcpy(tail, "xtra");
191 ANGBAND_DIR_XTRA = string_make(path);
198 /* Allow "fat binary" usage with NeXT */
219 /* Use special directory */
222 /* Forget the old path name */
223 string_free(ANGBAND_DIR_DATA);
225 /* Build a new path name */
226 sprintf(tail, "data-%s", next);
227 ANGBAND_DIR_DATA = string_make(path);
237 #ifdef ALLOW_TEMPLATES
241 * Hack -- help give useful error messages
248 * Standard error message text
250 cptr err_str[PARSE_ERROR_MAX] =
258 "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
266 "missing record header",
267 "non-sequential records",
268 "invalid flag specification",
269 "undefined directive",
271 "coordinates out of bounds",
278 #endif /* ALLOW_TEMPLATES */
294 #ifdef CHECK_MODIFICATION_TIME
296 static errr check_modification_date(int fd, cptr template_file)
300 struct stat txt_stat, raw_stat;
302 /* Build the filename */
303 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
305 /* Access stats on text file */
306 if (stat(buf, &txt_stat))
308 /* No text file - continue */
311 /* Access stats on raw file */
312 else if (fstat(fd, &raw_stat))
318 /* Ensure text file is not newer than raw file */
319 else if (txt_stat.st_mtime > raw_stat.st_mtime)
321 /* Reprocess text file */
328 #endif /* CHECK_MODIFICATION_TIME */
332 /*** Initialize from binary image files ***/
336 * Initialize the "*_info" array, by parsing a binary "image" file
338 static errr init_info_raw(int fd, header *head)
342 /* Read and Verify the header */
343 if (fd_read(fd, (char*)(&test), sizeof(header)) ||
344 (test.v_major != head->v_major) ||
345 (test.v_minor != head->v_minor) ||
346 (test.v_patch != head->v_patch) ||
347 (test.info_num != head->info_num) ||
348 (test.info_len != head->info_len) ||
349 (test.head_size != head->head_size) ||
350 (test.info_size != head->info_size))
357 /* Accept the header */
361 /* Allocate the "*_info" array */
362 C_MAKE(head->info_ptr, head->info_size, char);
364 /* Read the "*_info" array */
365 fd_read(fd, head->info_ptr, head->info_size);
370 /* Allocate the "*_name" array */
371 C_MAKE(head->name_ptr, head->name_size, char);
373 /* Read the "*_name" array */
374 fd_read(fd, head->name_ptr, head->name_size);
380 /* Allocate the "*_text" array */
381 C_MAKE(head->text_ptr, head->text_size, char);
383 /* Read the "*_text" array */
384 fd_read(fd, head->text_ptr, head->text_size);
394 * Initialize the header of an *_info.raw file.
396 static void init_header(header *head, int num, int len)
398 /* Save the "version" */
399 head->v_major = FAKE_VER_MAJOR;
400 head->v_minor = FAKE_VER_MINOR;
401 head->v_patch = FAKE_VER_PATCH;
404 /* Save the "record" information */
405 head->info_num = num;
406 head->info_len = len;
408 /* Save the size of "*_head" and "*_info" */
409 head->head_size = sizeof(header);
410 head->info_size = head->info_num * head->info_len;
415 * Initialize the "*_info" array
417 * Note that we let each entry have a unique "name" and "text" string,
418 * even if the string happens to be empty (everyone has a unique '\0').
420 static errr init_info(cptr filename, header *head,
421 void **info, char **name, char **text)
435 #ifdef ALLOW_TEMPLATES
437 /*** Load the binary image file ***/
439 /* Build the filename */
441 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
443 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
447 /* Attempt to open the "raw" file */
448 fd = fd_open(buf, O_RDONLY);
450 /* Process existing "raw" file */
453 #ifdef CHECK_MODIFICATION_TIME
455 err = check_modification_date(fd, format("%s.txt", filename));
457 #endif /* CHECK_MODIFICATION_TIME */
459 /* Attempt to parse the "raw" file */
461 err = init_info_raw(fd, head);
468 /* Do we have to parse the *.txt file? */
471 /*** Make the fake arrays ***/
473 /* Allocate the "*_info" array */
474 C_MAKE(head->info_ptr, head->info_size, char);
476 /* Hack -- make "fake" arrays */
477 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
478 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
480 if (info) (*info) = head->info_ptr;
481 if (name) (*name) = head->name_ptr;
482 if (text) (*text) = head->text_ptr;
484 /*** Load the ascii template file ***/
486 /* Build the filename */
488 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
491 fp = my_fopen(buf, "r");
495 if (!fp) quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤¤Þ¤»¤ó¡£", filename));
497 if (!fp) quit(format("Cannot open '%s.txt' file.", filename));
502 err = init_info_txt(fp, buf, head, head->parse_info_txt);
514 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
517 msg_format("'%s.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", filename, error_line);
518 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
519 msg_format("¹½Ê¸ '%s'¡£", buf);
523 quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼", filename));
526 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
529 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
530 msg_format("Record %d contains a '%s' error.", error_idx, oops);
531 msg_format("Parsing '%s'.", buf);
535 quit(format("Error in '%s.txt' file.", filename));
541 /*** Dump the binary image file ***/
543 /* File type is "DATA" */
544 FILE_TYPE(FILE_TYPE_DATA);
546 /* Build the filename */
548 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
550 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
554 /* Kill the old file */
557 /* Attempt to create the raw file */
558 fd = fd_make(buf, mode);
560 /* Dump to the file */
564 fd_write(fd, (cptr)(head), head->head_size);
566 /* Dump the "*_info" array */
567 fd_write(fd, head->info_ptr, head->info_size);
569 /* Dump the "*_name" array */
570 fd_write(fd, head->name_ptr, head->name_size);
572 /* Dump the "*_text" array */
573 fd_write(fd, head->text_ptr, head->text_size);
580 /*** Kill the fake arrays ***/
582 /* Free the "*_info" array */
583 C_KILL(head->info_ptr, head->info_size, char);
585 /* Hack -- Free the "fake" arrays */
586 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
587 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
589 #endif /* ALLOW_TEMPLATES */
592 /*** Load the binary image file ***/
594 /* Build the filename */
596 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
598 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
602 /* Attempt to open the "raw" file */
603 fd = fd_open(buf, O_RDONLY);
605 /* Process existing "raw" file */
607 if (fd < 0) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤¤Þ¤»¤ó¡£", filename));
609 if (fd < 0) quit(format("Cannot load '%s.raw' file.", filename));
613 /* Attempt to parse the "raw" file */
614 err = init_info_raw(fd, head);
621 if (err) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ¤Þ¤»¤ó¡£", filename));
623 if (err) quit(format("Cannot parse '%s.raw' file.", filename));
626 #ifdef ALLOW_TEMPLATES
630 if (info) (*info) = head->info_ptr;
631 if (name) (*name) = head->name_ptr;
632 if (text) (*text) = head->text_ptr;
640 * Initialize the "f_info" array
642 static errr init_f_info(void)
644 /* Init the header */
645 init_header(&f_head, max_f_idx, sizeof(feature_type));
647 #ifdef ALLOW_TEMPLATES
649 /* Save a pointer to the parsing function */
650 f_head.parse_info_txt = parse_f_info;
652 #endif /* ALLOW_TEMPLATES */
654 return init_info("f_info", &f_head,
655 (void*)&f_info, (void*)&f_name, NULL);
660 * Initialize the "k_info" array
662 static errr init_k_info(void)
664 /* Init the header */
665 init_header(&k_head, max_k_idx, sizeof(object_kind));
667 #ifdef ALLOW_TEMPLATES
669 /* Save a pointer to the parsing function */
670 k_head.parse_info_txt = parse_k_info;
672 #endif /* ALLOW_TEMPLATES */
674 return init_info("k_info", &k_head,
675 (void*)&k_info, (void*)&k_name, (void*)&k_text);
681 * Initialize the "a_info" array
683 static errr init_a_info(void)
685 /* Init the header */
686 init_header(&a_head, max_a_idx, sizeof(artifact_type));
688 #ifdef ALLOW_TEMPLATES
690 /* Save a pointer to the parsing function */
691 a_head.parse_info_txt = parse_a_info;
693 #endif /* ALLOW_TEMPLATES */
695 return init_info("a_info", &a_head,
696 (void*)&a_info, (void*)&a_name, (void*)&a_text);
702 * Initialize the "e_info" array
704 static errr init_e_info(void)
706 /* Init the header */
707 init_header(&e_head, max_e_idx, sizeof(ego_item_type));
709 #ifdef ALLOW_TEMPLATES
711 /* Save a pointer to the parsing function */
712 e_head.parse_info_txt = parse_e_info;
714 #endif /* ALLOW_TEMPLATES */
716 return init_info("e_info", &e_head,
717 (void*)&e_info, (void*)&e_name, (void*)&e_text);
723 * Initialize the "r_info" array
725 static errr init_r_info(void)
727 /* Init the header */
728 init_header(&r_head, max_r_idx, sizeof(monster_race));
730 #ifdef ALLOW_TEMPLATES
732 /* Save a pointer to the parsing function */
733 r_head.parse_info_txt = parse_r_info;
735 #endif /* ALLOW_TEMPLATES */
737 return init_info("r_info", &r_head,
738 (void*)&r_info, (void*)&r_name, (void*)&r_text);
744 * Initialize the "d_info" array
746 static errr init_d_info(void)
748 /* Init the header */
749 init_header(&d_head, max_d_idx, sizeof(dungeon_info_type));
751 #ifdef ALLOW_TEMPLATES
753 /* Save a pointer to the parsing function */
754 d_head.parse_info_txt = parse_d_info;
756 #endif /* ALLOW_TEMPLATES */
758 return init_info("d_info", &d_head,
759 (void*)&d_info, (void*)&d_name, (void*)&d_text);
764 * Initialize the "v_info" array
766 * Note that we let each entry have a unique "name" and "text" string,
767 * even if the string happens to be empty (everyone has a unique '\0').
769 errr init_v_info(void)
771 /* Init the header */
772 init_header(&v_head, max_v_idx, sizeof(vault_type));
774 #ifdef ALLOW_TEMPLATES
776 /* Save a pointer to the parsing function */
777 v_head.parse_info_txt = parse_v_info;
779 #endif /* ALLOW_TEMPLATES */
781 return init_info("v_info", &v_head,
782 (void*)&v_info, (void*)&v_name, (void*)&v_text);
787 * Initialize the "s_info" array
789 static errr init_s_info(void)
791 /* Init the header */
792 init_header(&s_head, MAX_CLASS, sizeof(skill_table));
794 #ifdef ALLOW_TEMPLATES
796 /* Save a pointer to the parsing function */
797 s_head.parse_info_txt = parse_s_info;
799 #endif /* ALLOW_TEMPLATES */
801 return init_info("s_info", &s_head,
802 (void*)&s_info, NULL, NULL);
807 * Initialize the "m_info" array
809 static errr init_m_info(void)
811 /* Init the header */
812 init_header(&m_head, MAX_CLASS, sizeof(player_magic));
814 #ifdef ALLOW_TEMPLATES
816 /* Save a pointer to the parsing function */
817 m_head.parse_info_txt = parse_m_info;
819 #endif /* ALLOW_TEMPLATES */
821 return init_info("m_info", &m_head,
822 (void*)&m_info, NULL, NULL);
827 /*** Initialize others ***/
830 * Hack -- Objects sold in the stores -- by tval/sval pair.
832 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
837 { TV_FOOD, SV_FOOD_RATION },
838 { TV_FOOD, SV_FOOD_RATION },
839 { TV_FOOD, SV_FOOD_RATION },
840 { TV_FOOD, SV_FOOD_RATION },
842 { TV_FOOD, SV_FOOD_RATION },
843 { TV_FOOD, SV_FOOD_BISCUIT },
844 { TV_FOOD, SV_FOOD_JERKY },
845 { TV_FOOD, SV_FOOD_JERKY },
847 { TV_FOOD, SV_FOOD_PINT_OF_WINE },
848 { TV_FOOD, SV_FOOD_PINT_OF_ALE },
849 { TV_LITE, SV_LITE_TORCH },
850 { TV_LITE, SV_LITE_TORCH },
852 { TV_LITE, SV_LITE_TORCH },
853 { TV_LITE, SV_LITE_TORCH },
854 { TV_LITE, SV_LITE_LANTERN },
855 { TV_LITE, SV_LITE_LANTERN },
867 { TV_SHOT, SV_AMMO_NORMAL },
868 { TV_ARROW, SV_AMMO_NORMAL },
869 { TV_BOLT, SV_AMMO_NORMAL },
870 { TV_DIGGING, SV_SHOVEL },
872 { TV_DIGGING, SV_PICK },
873 { TV_CLOAK, SV_CLOAK },
874 { TV_CLOAK, SV_CLOAK },
875 { TV_CLOAK, SV_FUR_CLOAK },
877 { TV_FOOD, SV_FOOD_RATION },
878 { TV_FOOD, SV_FOOD_RATION },
879 { TV_FOOD, SV_FOOD_RATION },
880 { TV_FOOD, SV_FOOD_RATION },
882 { TV_POTION, SV_POTION_WATER },
883 { TV_POTION, SV_POTION_WATER },
884 { TV_LITE, SV_LITE_LANTERN },
885 { TV_LITE, SV_LITE_LANTERN },
892 { TV_SHOT, SV_AMMO_NORMAL },
893 { TV_ARROW, SV_AMMO_NORMAL },
894 { TV_BOLT, SV_AMMO_NORMAL },
895 { TV_DIGGING, SV_SHOVEL }
901 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
902 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
903 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
904 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
906 { TV_HELM, SV_HARD_LEATHER_CAP },
907 { TV_HELM, SV_HARD_LEATHER_CAP },
908 { TV_HELM, SV_METAL_CAP },
909 { TV_HELM, SV_IRON_HELM },
911 { TV_SOFT_ARMOR, SV_ROBE },
912 { TV_SOFT_ARMOR, SV_ROBE },
913 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
914 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
916 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
917 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
918 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
919 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
921 { TV_SOFT_ARMOR, SV_RHINO_HIDE_ARMOR },
922 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
923 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
924 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
926 { TV_HARD_ARMOR, SV_DOUBLE_RING_MAIL },
927 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
928 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL },
929 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL },
931 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR },
932 { TV_HARD_ARMOR, SV_SPLINT_MAIL },
933 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
934 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
936 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
937 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
938 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD },
939 { TV_SHIELD, SV_SMALL_METAL_SHIELD },
941 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
942 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
943 { TV_HELM, SV_HARD_LEATHER_CAP },
944 { TV_HELM, SV_HARD_LEATHER_CAP },
946 { TV_SOFT_ARMOR, SV_ROBE },
947 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
948 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
949 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
951 { TV_SOFT_ARMOR, SV_LEATHER_JACK },
952 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
953 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
954 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
956 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
957 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
958 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
959 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }
965 { TV_SWORD, SV_DAGGER },
966 { TV_SWORD, SV_MAIN_GAUCHE },
967 { TV_SWORD, SV_RAPIER },
968 { TV_SWORD, SV_SMALL_SWORD },
970 { TV_SWORD, SV_SHORT_SWORD },
971 { TV_SWORD, SV_SABRE },
972 { TV_SWORD, SV_CUTLASS },
973 { TV_SWORD, SV_TULWAR },
975 { TV_SWORD, SV_BROAD_SWORD },
976 { TV_SWORD, SV_LONG_SWORD },
977 { TV_SWORD, SV_SCIMITAR },
978 { TV_SWORD, SV_KATANA },
980 { TV_SWORD, SV_BASTARD_SWORD },
981 { TV_POLEARM, SV_SPEAR },
982 { TV_POLEARM, SV_AWL_PIKE },
983 { TV_POLEARM, SV_TRIDENT },
985 { TV_POLEARM, SV_PIKE },
986 { TV_POLEARM, SV_BEAKED_AXE },
987 { TV_POLEARM, SV_BROAD_AXE },
988 { TV_POLEARM, SV_LANCE },
990 { TV_POLEARM, SV_BATTLE_AXE },
991 { TV_POLEARM, SV_HATCHET },
992 { TV_BOW, SV_SLING },
993 { TV_BOW, SV_SHORT_BOW },
995 { TV_BOW, SV_LIGHT_XBOW },
996 { TV_SHOT, SV_AMMO_NORMAL },
997 { TV_SHOT, SV_AMMO_NORMAL },
998 { TV_ARROW, SV_AMMO_NORMAL },
1000 { TV_ARROW, SV_AMMO_NORMAL },
1001 { TV_BOLT, SV_AMMO_NORMAL },
1002 { TV_BOLT, SV_AMMO_NORMAL },
1003 { TV_BOW, SV_LIGHT_XBOW },
1005 { TV_ARROW, SV_AMMO_NORMAL },
1006 { TV_BOLT, SV_AMMO_NORMAL },
1007 { TV_BOW, SV_SHORT_BOW },
1008 { TV_BOW, SV_LIGHT_XBOW },
1010 { TV_SWORD, SV_DAGGER },
1011 { TV_SWORD, SV_TANTO },
1012 { TV_SWORD, SV_RAPIER },
1013 { TV_SWORD, SV_SMALL_SWORD },
1015 { TV_SWORD, SV_SHORT_SWORD },
1016 { TV_SWORD, SV_LONG_SWORD },
1017 { TV_SWORD, SV_SCIMITAR },
1018 { TV_SWORD, SV_BROAD_SWORD },
1020 { TV_HISSATSU_BOOK, 0 },
1021 { TV_HISSATSU_BOOK, 0 },
1022 { TV_HISSATSU_BOOK, 1 },
1023 { TV_HISSATSU_BOOK, 1 },
1029 { TV_HAFTED, SV_NUNCHAKU },
1030 { TV_HAFTED, SV_QUARTERSTAFF },
1031 { TV_HAFTED, SV_MACE },
1032 { TV_HAFTED, SV_BO_STAFF },
1034 { TV_HAFTED, SV_WAR_HAMMER },
1035 { TV_HAFTED, SV_WAR_HAMMER },
1036 { TV_HAFTED, SV_MORNING_STAR },
1037 { TV_HAFTED, SV_FLAIL },
1039 { TV_HAFTED, SV_LEAD_FILLED_MACE },
1040 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1041 { TV_SCROLL, SV_SCROLL_BLESSING },
1042 { TV_SCROLL, SV_SCROLL_HOLY_CHANT },
1044 { TV_POTION, SV_POTION_HEROISM },
1045 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1046 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1047 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1049 { TV_POTION, SV_POTION_CURE_LIGHT },
1050 { TV_POTION, SV_POTION_CURE_SERIOUS },
1051 { TV_POTION, SV_POTION_CURE_SERIOUS },
1052 { TV_POTION, SV_POTION_CURE_CRITICAL },
1054 { TV_POTION, SV_POTION_CURE_CRITICAL },
1055 { TV_POTION, SV_POTION_RESTORE_EXP },
1056 { TV_POTION, SV_POTION_RESTORE_EXP },
1057 { TV_POTION, SV_POTION_RESTORE_EXP },
1059 { TV_LIFE_BOOK, 0 },
1060 { TV_LIFE_BOOK, 0 },
1061 { TV_LIFE_BOOK, 1 },
1062 { TV_LIFE_BOOK, 1 },
1064 { TV_CRUSADE_BOOK, 0 },
1065 { TV_CRUSADE_BOOK, 0 },
1066 { TV_CRUSADE_BOOK, 1 },
1067 { TV_CRUSADE_BOOK, 1 },
1069 { TV_HAFTED, SV_WHIP },
1070 { TV_HAFTED, SV_MACE },
1071 { TV_HAFTED, SV_BALL_AND_CHAIN },
1072 { TV_HAFTED, SV_WAR_HAMMER },
1074 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1075 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1076 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1077 { TV_POTION, SV_POTION_CURE_CRITICAL },
1079 { TV_POTION, SV_POTION_CURE_CRITICAL },
1080 { TV_POTION, SV_POTION_RESTORE_EXP },
1083 { TV_STATUE, SV_ANY },
1085 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1086 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1087 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE },
1088 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE }
1094 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1095 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1096 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1097 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1099 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1100 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1101 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1102 { TV_SCROLL, SV_SCROLL_LIGHT },
1104 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1105 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1106 { TV_SCROLL, SV_SCROLL_TELEPORT },
1107 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION },
1109 { TV_SCROLL, SV_SCROLL_MAPPING },
1110 { TV_SCROLL, SV_SCROLL_DETECT_GOLD },
1111 { TV_SCROLL, SV_SCROLL_DETECT_ITEM },
1112 { TV_SCROLL, SV_SCROLL_DETECT_TRAP },
1114 { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
1115 { TV_SCROLL, SV_SCROLL_RECHARGING },
1116 { TV_SCROLL, SV_SCROLL_TELEPORT },
1117 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1119 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1120 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1121 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1122 { TV_SCROLL, SV_SCROLL_TELEPORT },
1124 { TV_SCROLL, SV_SCROLL_TELEPORT },
1125 { TV_POTION, SV_POTION_RES_STR },
1126 { TV_POTION, SV_POTION_RES_INT },
1127 { TV_POTION, SV_POTION_RES_WIS },
1129 { TV_POTION, SV_POTION_RES_DEX },
1130 { TV_POTION, SV_POTION_RES_CON },
1131 { TV_POTION, SV_POTION_RES_CHR },
1132 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1134 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1135 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY }, /* Yep, occasionally! */
1136 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },
1137 { TV_SCROLL, SV_SCROLL_LIGHT },
1139 { TV_POTION, SV_POTION_RES_STR },
1140 { TV_POTION, SV_POTION_RES_INT },
1141 { TV_POTION, SV_POTION_RES_WIS },
1142 { TV_POTION, SV_POTION_RES_DEX },
1144 { TV_POTION, SV_POTION_RES_CON },
1145 { TV_POTION, SV_POTION_RES_CHR },
1146 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1147 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1149 { TV_SCROLL, SV_SCROLL_RECHARGING },
1150 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1151 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1152 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1157 /* Magic-User store */
1159 { TV_RING, SV_RING_PROTECTION },
1160 { TV_RING, SV_RING_FEATHER_FALL },
1161 { TV_RING, SV_RING_PROTECTION },
1162 { TV_RING, SV_RING_RESIST_FIRE },
1164 { TV_RING, SV_RING_RESIST_COLD },
1165 { TV_AMULET, SV_AMULET_CHARISMA },
1166 { TV_RING, SV_RING_WARNING },
1167 { TV_AMULET, SV_AMULET_RESIST_ACID },
1169 { TV_AMULET, SV_AMULET_SEARCHING },
1170 { TV_WAND, SV_WAND_SLOW_MONSTER },
1171 { TV_WAND, SV_WAND_CONFUSE_MONSTER },
1172 { TV_WAND, SV_WAND_SLEEP_MONSTER },
1174 { TV_WAND, SV_WAND_MAGIC_MISSILE },
1175 { TV_WAND, SV_WAND_STINKING_CLOUD },
1176 { TV_WAND, SV_WAND_WONDER },
1177 { TV_WAND, SV_WAND_DISARMING },
1179 { TV_STAFF, SV_STAFF_LITE },
1180 { TV_STAFF, SV_STAFF_MAPPING },
1181 { TV_STAFF, SV_STAFF_DETECT_TRAP },
1182 { TV_STAFF, SV_STAFF_DETECT_DOOR },
1184 { TV_STAFF, SV_STAFF_DETECT_GOLD },
1185 { TV_STAFF, SV_STAFF_DETECT_ITEM },
1186 { TV_STAFF, SV_STAFF_DETECT_INVIS },
1187 { TV_STAFF, SV_STAFF_DETECT_EVIL },
1189 { TV_STAFF, SV_STAFF_TELEPORTATION },
1190 { TV_STAFF, SV_STAFF_TELEPORTATION },
1191 { TV_STAFF, SV_STAFF_TELEPORTATION },
1192 { TV_STAFF, SV_STAFF_TELEPORTATION },
1194 { TV_STAFF, SV_STAFF_IDENTIFY },
1195 { TV_STAFF, SV_STAFF_IDENTIFY },
1196 { TV_STAFF, SV_STAFF_IDENTIFY },
1198 { TV_STAFF, SV_STAFF_IDENTIFY },
1199 { TV_STAFF, SV_STAFF_REMOVE_CURSE },
1200 { TV_STAFF, SV_STAFF_CURE_LIGHT },
1201 { TV_STAFF, SV_STAFF_PROBING },
1205 { TV_SORCERY_BOOK, 0 },
1206 { TV_SORCERY_BOOK, 0 },
1207 { TV_SORCERY_BOOK, 1 },
1208 { TV_SORCERY_BOOK, 1 },
1210 { TV_ARCANE_BOOK, 0 },
1211 { TV_ARCANE_BOOK, 0 },
1212 { TV_ARCANE_BOOK, 1 },
1213 { TV_ARCANE_BOOK, 1 },
1215 { TV_ARCANE_BOOK, 2 },
1216 { TV_ARCANE_BOOK, 2 },
1217 { TV_ARCANE_BOOK, 3 },
1218 { TV_ARCANE_BOOK, 3 },
1223 /* Black Market (unused) */
1296 { TV_SORCERY_BOOK, 0 },
1297 { TV_SORCERY_BOOK, 0 },
1298 { TV_SORCERY_BOOK, 1 },
1299 { TV_SORCERY_BOOK, 1 },
1301 { TV_NATURE_BOOK, 0 },
1302 { TV_NATURE_BOOK, 0 },
1303 { TV_NATURE_BOOK, 1 },
1304 { TV_NATURE_BOOK, 1 },
1306 { TV_CHAOS_BOOK, 0 },
1307 { TV_CHAOS_BOOK, 0 },
1308 { TV_CHAOS_BOOK, 1 },
1309 { TV_CHAOS_BOOK, 1 },
1311 { TV_DEATH_BOOK, 0 },
1312 { TV_DEATH_BOOK, 0 },
1313 { TV_DEATH_BOOK, 1 },
1314 { TV_DEATH_BOOK, 1 },
1316 { TV_TRUMP_BOOK, 0 }, /* +16 */
1317 { TV_TRUMP_BOOK, 0 },
1318 { TV_TRUMP_BOOK, 1 },
1319 { TV_TRUMP_BOOK, 1 },
1321 { TV_ARCANE_BOOK, 0 },
1322 { TV_ARCANE_BOOK, 1 },
1323 { TV_ARCANE_BOOK, 2 },
1324 { TV_ARCANE_BOOK, 3 },
1326 { TV_ENCHANT_BOOK, 0 },
1327 { TV_ENCHANT_BOOK, 0 },
1328 { TV_ENCHANT_BOOK, 1 },
1329 { TV_ENCHANT_BOOK, 1 },
1331 { TV_DAEMON_BOOK, 0 },
1332 { TV_DAEMON_BOOK, 0 },
1333 { TV_DAEMON_BOOK, 1 },
1334 { TV_DAEMON_BOOK, 1 },
1336 { TV_MUSIC_BOOK, 0 },
1337 { TV_MUSIC_BOOK, 0 },
1338 { TV_MUSIC_BOOK, 1 },
1339 { TV_MUSIC_BOOK, 1 },
1343 /* Museum (unused) */
1381 * Initialize misc. values
1383 static errr init_misc(void)
1385 /* Initialize the values */
1386 process_dungeon_file("misc.txt", 0, 0, 0, 0);
1393 * Initialize town array
1395 static errr init_towns(void)
1399 /*** Prepare the Towns ***/
1401 /* Allocate the towns */
1402 C_MAKE(town, max_towns, town_type);
1404 for (i = 1; i < max_towns; i++)
1406 /*** Prepare the Stores ***/
1408 /* Allocate the stores */
1409 C_MAKE(town[i].store, MAX_STORES, store_type);
1411 /* Fill in each store */
1412 for (j = 0; j < MAX_STORES; j++)
1414 /* Access the store */
1415 store_type *st_ptr = &town[i].store[j];
1417 if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
1419 /* Assume full stock */
1422 * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë±£¤·µ¡Ç½¤Î¤¿¤á¤Î½àÈ÷¡£
1423 * ¥ª¥×¥·¥ç¥ó¤¬Í¸ú¤Ç¤â¤½¤¦¤Ç¤Ê¤¯¤Æ¤â°ì±þ¥¹¥Ú¡¼¥¹
1426 if (j == STORE_HOME)
1428 st_ptr->stock_size = (STORE_INVEN_MAX * 10);
1430 else if (j == STORE_MUSEUM)
1432 st_ptr->stock_size = (STORE_INVEN_MAX * 50);
1436 st_ptr->stock_size = STORE_INVEN_MAX;
1440 /* Allocate the stock */
1441 C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
1443 /* No table for the black market or home */
1444 if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
1446 /* Assume full table */
1447 st_ptr->table_size = STORE_CHOICES;
1449 /* Allocate the stock */
1450 C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
1452 /* Scan the choices */
1453 for (k = 0; k < STORE_CHOICES; k++)
1457 /* Extract the tval/sval codes */
1458 int tv = store_table[j][k][0];
1459 int sv = store_table[j][k][1];
1462 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
1464 object_kind *k_ptr = &k_info[k_idx];
1467 if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
1471 if (k_idx == max_k_idx) continue;
1473 /* Add that item index to the table */
1474 st_ptr->table[st_ptr->table_num++] = k_idx;
1483 * Initialize buildings
1485 errr init_buildings(void)
1489 for (i = 0; i < MAX_BLDG; i++)
1491 building[i].name[0] = '\0';
1492 building[i].owner_name[0] = '\0';
1493 building[i].owner_race[0] = '\0';
1495 for (j = 0; j < 8; j++)
1497 building[i].act_names[j][0] = '\0';
1498 building[i].member_costs[j] = 0;
1499 building[i].other_costs[j] = 0;
1500 building[i].letters[j] = 0;
1501 building[i].actions[j] = 0;
1502 building[i].action_restr[j] = 0;
1505 for (j = 0; j < MAX_CLASS; j++)
1507 building[i].member_class[j] = 0;
1510 for (j = 0; j < MAX_RACES; j++)
1512 building[i].member_race[j] = 0;
1515 for (j = 0; j < MAX_MAGIC+1; j++)
1517 building[i].member_realm[j] = 0;
1526 * Initialize quest array
1528 static errr init_quests(void)
1532 /*** Prepare the quests ***/
1534 /* Allocate the quests */
1535 C_MAKE(quest, max_quests, quest_type);
1537 /* Set all quest to "untaken" */
1538 for (i = 0; i < max_quests; i++)
1540 quest[i].status = QUEST_STATUS_UNTAKEN;
1548 * Initialize some other arrays
1550 static errr init_other(void)
1555 /*** Prepare the "dungeon" information ***/
1557 /* Allocate and Wipe the object list */
1558 C_MAKE(o_list, max_o_idx, object_type);
1560 /* Allocate and Wipe the monster list */
1561 C_MAKE(m_list, max_m_idx, monster_type);
1563 /* Allocate and Wipe the max dungeon level */
1564 C_MAKE(max_dlv, max_d_idx, s16b);
1566 /* Allocate and wipe each line of the cave */
1567 for (i = 0; i < MAX_HGT; i++)
1569 /* Allocate one row of the cave */
1570 C_MAKE(cave[i], MAX_WID, cave_type);
1574 /*** Prepare the various "bizarre" arrays ***/
1576 /* Macro variables */
1577 C_MAKE(macro__pat, MACRO_MAX, cptr);
1578 C_MAKE(macro__act, MACRO_MAX, cptr);
1579 C_MAKE(macro__cmd, MACRO_MAX, bool);
1581 /* Macro action buffer */
1582 C_MAKE(macro__buf, 1024, char);
1584 /* Quark variables */
1585 C_MAKE(quark__str, QUARK_MAX, cptr);
1587 /* Message variables */
1588 C_MAKE(message__ptr, MESSAGE_MAX, u16b);
1589 C_MAKE(message__buf, MESSAGE_BUF, char);
1591 /* Hack -- No messages yet */
1592 message__tail = MESSAGE_BUF;
1595 /*** Prepare the Player inventory ***/
1598 C_MAKE(inventory, INVEN_TOTAL, object_type);
1601 /*** Pre-allocate the basic "auto-inscriptions" ***/
1603 /* The "basic" feelings */
1605 (void)quark_add("¼ö¤ï¤ì¤Æ¤¤¤ë");
1606 (void)quark_add("²õ¤ì¤Æ¤¤¤ë");
1607 (void)quark_add("ÊÂ");
1608 (void)quark_add("¾å¼Á");
1610 (void)quark_add("cursed");
1611 (void)quark_add("broken");
1612 (void)quark_add("average");
1613 (void)quark_add("good");
1617 /* The "extra" feelings */
1619 (void)quark_add("¹âµéÉÊ");
1620 (void)quark_add("̵²ÁÃÍ");
1621 (void)quark_add("ÆÃÊÌÀ½");
1622 (void)quark_add("¶²¤í¤·¤¤");
1624 (void)quark_add("excellent");
1625 (void)quark_add("worthless");
1626 (void)quark_add("special");
1627 (void)quark_add("terrible");
1631 /* Some extra strings */
1633 (void)quark_add("¼ö¤¤¤Ê¤·");
1634 (void)quark_add("Çä½ÐÃæ");
1636 (void)quark_add("uncursed");
1637 (void)quark_add("on sale");
1642 /*** Prepare the options ***/
1644 /* Scan the options */
1645 for (i = 0; option_info[i].o_desc; i++)
1647 int os = option_info[i].o_set;
1648 int ob = option_info[i].o_bit;
1650 /* Set the "default" options */
1651 if (option_info[i].o_var)
1654 option_mask[os] |= (1L << ob);
1657 if (option_info[i].o_norm)
1660 option_flag[os] |= (1L << ob);
1667 option_flag[os] &= ~(1L << ob);
1672 /* Analyze the windows */
1673 for (n = 0; n < 8; n++)
1675 /* Analyze the options */
1676 for (i = 0; i < 32; i++)
1679 if (window_flag_desc[i])
1682 window_mask[n] |= (1L << i);
1688 * Set the "default" window flags
1689 * Window 1 : Display messages
1690 * Window 2 : Display inven/equip
1692 window_flag[1] = 1L << 6;
1693 window_flag[2] = 1L << 0;
1696 /*** Pre-allocate space for the "format()" buffer ***/
1698 /* Hack -- Just call the "format()" function */
1699 (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1709 * Initialize some other arrays
1711 static errr init_alloc(void)
1714 monster_race *r_ptr;
1720 /* Allocate the "r_info" array */
1721 C_MAKE(elements, max_r_idx, tag_type);
1723 /* Scan the monsters */
1724 for (i = 1; i < max_r_idx; i++)
1726 elements[i].tag = r_info[i].level;
1727 elements[i].pointer = (void*)i;
1730 tag_sort(elements, max_r_idx);
1732 /*** Initialize monster allocation info ***/
1734 /* Size of "alloc_race_table" */
1735 alloc_race_size = max_r_idx;
1737 /* Allocate the alloc_race_table */
1738 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1740 /* Scan the monsters */
1741 for (i = 1; i < max_r_idx; i++)
1743 /* Get the i'th race */
1744 r_ptr = &r_info[(int)elements[i].pointer];
1746 /* Count valid pairs */
1751 /* Extract the base level */
1754 /* Extract the base probability */
1755 p = (100 / r_ptr->rarity);
1757 /* Load the entry */
1758 alloc_race_table[i].index = (int)elements[i].pointer;
1759 alloc_race_table[i].level = x;
1760 alloc_race_table[i].prob1 = p;
1761 alloc_race_table[i].prob2 = p;
1762 alloc_race_table[i].prob3 = p;
1766 /* Free the "r_info" array */
1767 C_KILL(elements, max_r_idx, tag_type);
1769 #else /* SORT_R_INFO */
1773 s16b num[MAX_DEPTH];
1774 s16b aux[MAX_DEPTH];
1776 /*** Analyze monster allocation info ***/
1778 /* Clear the "aux" array */
1779 C_WIPE(&aux, MAX_DEPTH, s16b);
1781 /* Clear the "num" array */
1782 C_WIPE(&num, MAX_DEPTH, s16b);
1784 /* Size of "alloc_race_table" */
1785 alloc_race_size = 0;
1787 /* Scan the monsters */
1788 for (i = 1; i < max_r_idx; i++)
1790 /* Get the i'th race */
1793 /* Legal monsters */
1796 /* Count the entries */
1799 /* Group by level */
1800 num[r_ptr->level]++;
1804 /* Collect the level indexes */
1805 for (i = 1; i < MAX_DEPTH; i++)
1807 /* Group by level */
1813 if (!num[0]) quit("Ä®¤Î¥â¥ó¥¹¥¿¡¼¤¬¤Ê¤¤¡ª");
1815 if (!num[0]) quit("No town monsters!");
1820 /*** Initialize monster allocation info ***/
1822 /* Allocate the alloc_race_table */
1823 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1825 /* Access the table entry */
1826 table = alloc_race_table;
1828 /* Scan the monsters */
1829 for (i = 1; i < max_r_idx; i++)
1831 /* Get the i'th race */
1834 /* Count valid pairs */
1839 /* Extract the base level */
1842 /* Extract the base probability */
1843 p = (100 / r_ptr->rarity);
1845 /* Skip entries preceding our locale */
1846 y = (x > 0) ? num[x-1] : 0;
1848 /* Skip previous entries at this locale */
1851 /* Load the entry */
1858 /* Another entry complete for this locale */
1863 #endif /* SORT_R_INFO */
1865 /* Init the "alloc_kind_table" */
1866 (void)init_object_alloc();
1875 * Hack -- take notes on line 23
1877 static void note(cptr str)
1879 Term_erase(0, 23, 255);
1880 Term_putstr(20, 23, -1, TERM_WHITE, str);
1887 * Hack -- Explain a broken "lib" folder and quit (see below).
1889 * XXX XXX XXX This function is "messy" because various things
1890 * may or may not be initialized, but the "plog()" and "quit()"
1891 * functions are "supposed" to work under any conditions.
1893 static void init_angband_aux(cptr why)
1900 plog("'lib'¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¤«²õ¤ì¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£");
1903 plog("¤Ò¤ç¤Ã¤È¤¹¤ë¤È¥¢¡¼¥«¥¤¥Ö¤¬Àµ¤·¤¯²òÅव¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡£");
1906 plog("³ºÅö¤¹¤ë'README'¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç³Îǧ¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡£");
1908 /* Quit with error */
1909 quit("Ã×̿Ū¤Ê¥¨¥é¡¼¡£");
1912 plog("The 'lib' directory is probably missing or broken.");
1915 plog("Perhaps the archive was not extracted correctly.");
1918 plog("See the 'README' file for more information.");
1920 /* Quit with error */
1921 quit("Fatal Error.");
1928 * Hack -- main Angband initialization entry point
1930 * Verify some files, display the "news.txt" file, create
1931 * the high score file, initialize all internal arrays, and
1932 * load the basic "user pref files".
1934 * Be very careful to keep track of the order in which things
1935 * are initialized, in particular, the only thing *known* to
1936 * be available when this function is called is the "z-term.c"
1937 * package, and that may not be fully initialized until the
1938 * end of this function, when the default "user pref files"
1939 * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1941 * Note that this function attempts to verify the "news" file,
1942 * and the game aborts (cleanly) on failure, since without the
1943 * "news" file, it is likely that the "lib" folder has not been
1944 * correctly located. Otherwise, the news file is displayed for
1947 * Note that this function attempts to verify (or create) the
1948 * "high score" file, and the game aborts (cleanly) on failure,
1949 * since one of the most common "extraction" failures involves
1950 * failing to extract all sub-directories (even empty ones), such
1951 * as by failing to use the "-d" option of "pkunzip", or failing
1952 * to use the "save empty directories" option with "Compact Pro".
1953 * This error will often be caught by the "high score" creation
1954 * code below, since the "lib/apex" directory, being empty in the
1955 * standard distributions, is most likely to be "lost", making it
1956 * impossible to create the high score file.
1958 * Note that various things are initialized by this function,
1959 * including everything that was once done by "init_some_arrays".
1961 * This initialization involves the parsing of special files
1962 * in the "lib/data" and sometimes the "lib/edit" directories.
1964 * Note that the "template" files are initialized first, since they
1965 * often contain errors. This means that macros and message recall
1966 * and things like that are not available until after they are done.
1968 * We load the default "user pref files" here in case any "color"
1969 * changes are needed before character creation.
1971 * Note that the "graf-xxx.prf" file must be loaded separately,
1972 * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1974 void init_angband(void)
1985 /*** Verify the "news" file ***/
1987 /* Build the filename */
1989 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
1991 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
1995 /* Attempt to open the file */
1996 fd = fd_open(buf, O_RDONLY);
2005 sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤Ç¤¤Þ¤»¤ó!", buf);
2007 sprintf(why, "Cannot access the '%s' file!", buf);
2011 /* Crash and burn */
2012 init_angband_aux(why);
2019 /*** Display the "news" file ***/
2024 /* Build the filename */
2026 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
2028 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
2032 /* Open the News file */
2033 fp = my_fopen(buf, "r");
2040 /* Dump the file to the screen */
2041 while (0 == my_fgets(fp, buf, sizeof(buf)))
2043 /* Display and advance */
2044 Term_putstr(0, i++, -1, TERM_WHITE, buf);
2055 /*** Verify (or create) the "high score" file ***/
2057 /* Build the filename */
2058 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2060 /* Attempt to open the high score file */
2061 fd = fd_open(buf, O_RDONLY);
2066 /* File type is "DATA" */
2067 FILE_TYPE(FILE_TYPE_DATA);
2069 /* Create a new high score file */
2070 fd = fd_make(buf, mode);
2079 sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó!", buf);
2081 sprintf(why, "Cannot create the '%s' file!", buf);
2085 /* Crash and burn */
2086 init_angband_aux(why);
2094 /*** Initialize some arrays ***/
2096 /* Initialize misc. values */
2098 note("[ÊÑ¿ô¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...(¤½¤Î¾)");
2100 note("[Initializing values... (misc)]");
2104 if (init_misc()) quit("¤½¤Î¾¤ÎÊÑ¿ô¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2106 if (init_misc()) quit("Cannot initialize misc. values");
2110 /* Initialize feature info */
2112 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÃÏ·Á)]");
2113 if (init_f_info()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
2115 note("[Initializing arrays... (features)]");
2116 if (init_f_info()) quit("Cannot initialize features");
2120 /* Initialize object info */
2122 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥¤¥Æ¥à)]");
2123 if (init_k_info()) quit("¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2125 note("[Initializing arrays... (objects)]");
2126 if (init_k_info()) quit("Cannot initialize objects");
2130 /* Initialize artifact info */
2132 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÅÁÀâ¤Î¥¢¥¤¥Æ¥à)]");
2133 if (init_a_info()) quit("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2135 note("[Initializing arrays... (artifacts)]");
2136 if (init_a_info()) quit("Cannot initialize artifacts");
2140 /* Initialize ego-item info */
2142 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à)]");
2143 if (init_e_info()) quit("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2145 note("[Initializing arrays... (ego-items)]");
2146 if (init_e_info()) quit("Cannot initialize ego-items");
2150 /* Initialize monster info */
2152 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥â¥ó¥¹¥¿¡¼)]");
2153 if (init_r_info()) quit("¥â¥ó¥¹¥¿¡¼½é´ü²½ÉÔǽ");
2155 note("[Initializing arrays... (monsters)]");
2156 if (init_r_info()) quit("Cannot initialize monsters");
2160 /* Initialize dungeon info */
2162 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥À¥ó¥¸¥ç¥ó)]");
2163 if (init_d_info()) quit("¥À¥ó¥¸¥ç¥ó½é´ü²½ÉÔǽ");
2165 note("[Initializing arrays... (dungeon)]");
2166 if (init_d_info()) quit("Cannot initialize dungeon");
2170 for (i = 1; i < max_d_idx; i++)
2171 if (d_info[i].final_guardian)
2172 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
2175 /* Initialize magic info */
2177 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ËâË¡)]");
2178 if (init_m_info()) quit("ËâË¡½é´ü²½ÉÔǽ");
2180 note("[Initializing arrays... (magic)]");
2181 if (init_m_info()) quit("Cannot initialize magic");
2184 /* Initialize weapon_exp info */
2186 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (½ÏÎýÅÙ)]");
2187 if (init_s_info()) quit("½ÏÎýÅÙ½é´ü²½ÉÔǽ");
2189 note("[Initializing arrays... (skill)]");
2190 if (init_s_info()) quit("Cannot initialize skill");
2193 /* Initialize wilderness array */
2195 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¹ÓÌî)]");
2197 note("[Initializing arrays... (wilderness)]");
2201 if (init_wilderness()) quit("¹ÓÌî¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2203 if (init_wilderness()) quit("Cannot initialize wilderness");
2207 /* Initialize town array */
2209 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (³¹)]");
2211 note("[Initializing arrays... (towns)]");
2215 if (init_towns()) quit("³¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2217 if (init_towns()) quit("Cannot initialize towns");
2221 /* Initialize building array */
2223 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (·úʪ)]");
2225 note("[Initializing arrays... (buildings)]");
2229 if (init_buildings()) quit("·úʪ¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2231 if (init_buildings()) quit("Cannot initialize buildings");
2235 /* Initialize quest array */
2237 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¥¯¥¨¥¹¥È)]");
2239 note("[Initializing arrays... (quests)]");
2243 if (init_quests()) quit("¥¯¥¨¥¹¥È¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2245 if (init_quests()) quit("Cannot initialize quests");
2249 /* Initialize some other arrays */
2251 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¤½¤Î¾)]");
2252 if (init_other()) quit("¤½¤Î¾¤Î¥Ç¡¼¥¿½é´ü²½ÉÔǽ");
2254 note("[Initializing arrays... (other)]");
2255 if (init_other()) quit("Cannot initialize other stuff");
2259 /* Initialize some other arrays */
2262 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥í¥±¡¼¥·¥ç¥ó)]");
2263 if (init_alloc()) quit("¥¢¥í¥±¡¼¥·¥ç¥ó¡¦¥¹¥¿¥Ã¥Õ½é´ü²½ÉÔǽ");
2265 note("[Initializing arrays... (alloc)]");
2266 if (init_alloc()) quit("Cannot initialize alloc stuff");
2271 /*** Load default user pref files ***/
2273 /* Initialize feature info */
2275 note("[¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...]");
2277 note("[Initializing user pref files...]");
2281 /* Access the "basic" pref file */
2282 strcpy(buf, "pref.prf");
2284 /* Process that file */
2285 process_pref_file(buf);
2287 /* Access the "basic" system pref file */
2288 sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
2290 /* Process that file */
2291 process_pref_file(buf);
2295 note("[½é´ü²½½ªÎ»]");
2297 note("[Initialization complete]");
2303 * Get check sum in string form
2305 cptr get_check_sum(void)
2307 return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",