4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 2) -BEN- */
18 #ifdef CHECK_MODIFICATION_TIME
19 #include <sys/types.h>
21 #endif /* CHECK_MODIFICATION_TIME */
25 * This file is used to initialize various variables and arrays for the
26 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
27 * the common limitation of "read()" and "write()" to only 32767 bytes
30 * Several of the arrays for Angband are built from "template" files in
31 * the "lib/file" directory, from which quick-load binary "image" files
32 * are constructed whenever they are not present in the "lib/data"
33 * directory, or if those files become obsolete, if we are allowed.
35 * Warning -- the "ascii" file parsers use a minor hack to collect the
36 * name and text information in a single pass. Thus, the game will not
37 * be able to load any template file with more than 20K of names or 60K
38 * of text, even though technically, up to 64K should be legal.
40 * The "init1.c" file is used only to parse the ascii template files,
41 * to create the binary image files. If you include the binary image
42 * files instead of the ascii template files, then you can undefine
43 * "ALLOW_TEMPLATES", saving about 20K by removing "init1.c". Note
44 * that the binary image files are extremely system dependant.
50 * Set the default paths to all of our important sub-directories.
54 * varpath Is the base path for directories that have files which
55 * are not read-only: ANGBAND_DIR_APEX, ANGBAND_DIR_BONE, ANGBAND_DIR_DATA,
56 * and ANGBAND_DIR_SAVE. If the PRIVATE_USER_PATH preprocessor macro has not
57 * been set, it is also used as the base path for ANGBAND_DIR_USER.
59 * The purpose of each sub-directory is described in "variable.c".
60 * The traditional behavior was to put all of the sub-directories within
61 * one directory, "lib". To get that behavior, pass the same string for
62 * libpath and varpath. Further customization may be done later in response
63 * to command line options (most importantly for the "info", "user", and
64 * "save" directories), but that is done after this function: see
65 * "change_path()" in "main.c". libpath and varpath should end in the
66 * appropriate "PATH_SEP" string. All of the "sub-directory" paths
67 * (created below or supplied by the user) will NOT end in the "PATH_SEP"
68 * string, see the special "path_build()" function in "util.c" for more
71 * Mega-Hack -- support fat raw files under NEXTSTEP, using special
72 * "suffixed" directories for the "ANGBAND_DIR_DATA" directory, but
73 * requiring the directories to be created by hand by the user.
74 * Hack -- first we free all the strings, since this is known
75 * to succeed even if the strings have not been allocated yet,
76 * as long as the variables start out as "NULL". This allows
77 * this function to be called multiple times, for example, to
78 * try several base "path" values until a good one is found.
80 void init_file_paths(char *libpath, char *varpath)
82 char *libtail, *vartail;
84 #ifdef PRIVATE_USER_PATH
86 #endif /* PRIVATE_USER_PATH */
88 /*** Free everything ***/
90 /* Free the main path */
91 string_free(ANGBAND_DIR);
93 /* Free the sub-paths */
94 string_free(ANGBAND_DIR_APEX);
95 string_free(ANGBAND_DIR_BONE);
96 string_free(ANGBAND_DIR_DATA);
97 string_free(ANGBAND_DIR_EDIT);
98 string_free(ANGBAND_DIR_SCRIPT);
99 string_free(ANGBAND_DIR_FILE);
100 string_free(ANGBAND_DIR_HELP);
101 string_free(ANGBAND_DIR_INFO);
102 string_free(ANGBAND_DIR_SAVE);
103 string_free(ANGBAND_DIR_USER);
104 string_free(ANGBAND_DIR_XTRA);
107 /*** Prepare the "path" ***/
109 /* Hack -- save the main directory */
110 ANGBAND_DIR = string_make(libpath);
112 /* Prepare to append to the Base Paths */
113 libtail = libpath + strlen(libpath);
114 vartail = varpath + strlen(varpath);
118 /*** Use "flat" paths with VM/ESA ***/
120 /* Use "blank" path names */
121 ANGBAND_DIR_APEX = string_make("");
122 ANGBAND_DIR_BONE = string_make("");
123 ANGBAND_DIR_DATA = string_make("");
124 ANGBAND_DIR_EDIT = string_make("");
125 ANGBAND_DIR_SCRIPT = string_make("");
126 ANGBAND_DIR_FILE = string_make("");
127 ANGBAND_DIR_HELP = string_make("");
128 ANGBAND_DIR_INFO = string_make("");
129 ANGBAND_DIR_SAVE = string_make("");
130 ANGBAND_DIR_USER = string_make("");
131 ANGBAND_DIR_XTRA = string_make("");
137 /*** Build the sub-directory names ***/
139 /* Build a path name */
140 strcpy(vartail, "apex");
141 ANGBAND_DIR_APEX = string_make(varpath);
143 /* Build a path name */
144 strcpy(vartail, "bone");
145 ANGBAND_DIR_BONE = string_make(varpath);
147 /* Build a path name */
148 strcpy(vartail, "data");
149 ANGBAND_DIR_DATA = string_make(varpath);
151 /* Build a path name */
152 strcpy(libtail, "edit");
153 ANGBAND_DIR_EDIT = string_make(libpath);
155 /* Build a path name */
156 strcpy(libtail, "script");
157 ANGBAND_DIR_SCRIPT = string_make(libpath);
159 /* Build a path name */
160 strcpy(libtail, "file");
161 ANGBAND_DIR_FILE = string_make(libpath);
163 /* Build a path name */
164 strcpy(libtail, "help");
165 ANGBAND_DIR_HELP = string_make(libpath);
167 /* Build a path name */
168 strcpy(libtail, "info");
169 ANGBAND_DIR_INFO = string_make(libpath);
171 /* Build a path name */
172 strcpy(libtail, "pref");
173 ANGBAND_DIR_PREF = string_make(libpath);
175 /* Build a path name */
176 strcpy(vartail, "save");
177 ANGBAND_DIR_SAVE = string_make(varpath);
179 #ifdef PRIVATE_USER_PATH
181 /* Build the path to the user specific directory */
182 path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
184 /* Build a relative path name */
185 ANGBAND_DIR_USER = string_make(buf);
187 #else /* PRIVATE_USER_PATH */
189 /* Build a path name */
190 strcpy(vartail, "user");
191 ANGBAND_DIR_USER = string_make(varpath);
193 #endif /* PRIVATE_USER_PATH */
195 /* Build a path name */
196 strcpy(libtail, "xtra");
197 ANGBAND_DIR_XTRA = string_make(libpath);
204 /* Allow "fat binary" usage with NeXT */
225 /* Use special directory */
228 /* Forget the old path name */
229 string_free(ANGBAND_DIR_DATA);
231 /* Build a new path name */
232 sprintf(vartail, "data-%s", next);
233 ANGBAND_DIR_DATA = string_make(varpath);
243 #ifdef ALLOW_TEMPLATES
247 * Hack -- help give useful error messages
254 * Standard error message text
256 cptr err_str[PARSE_ERROR_MAX] =
264 "¤ª¤«¤·¤Ê¥Õ¥é¥°Â¸ºß",
272 "missing record header",
273 "non-sequential records",
274 "invalid flag specification",
275 "undefined directive",
277 "coordinates out of bounds",
284 #endif /* ALLOW_TEMPLATES */
300 #ifdef CHECK_MODIFICATION_TIME
302 static errr check_modification_date(int fd, cptr template_file)
306 struct stat txt_stat, raw_stat;
308 /* Build the filename */
309 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, template_file);
311 /* Access stats on text file */
312 if (stat(buf, &txt_stat))
314 /* No text file - continue */
317 /* Access stats on raw file */
318 else if (fstat(fd, &raw_stat))
324 /* Ensure text file is not newer than raw file */
325 else if (txt_stat.st_mtime > raw_stat.st_mtime)
327 /* Reprocess text file */
334 #endif /* CHECK_MODIFICATION_TIME */
338 /*** Initialize from binary image files ***/
342 * Initialize the "*_info" array, by parsing a binary "image" file
344 static errr init_info_raw(int fd, header *head)
348 /* Read and Verify the header */
349 if (fd_read(fd, (char*)(&test), sizeof(header)) ||
350 (test.v_major != head->v_major) ||
351 (test.v_minor != head->v_minor) ||
352 (test.v_patch != head->v_patch) ||
353 (test.info_num != head->info_num) ||
354 (test.info_len != head->info_len) ||
355 (test.head_size != head->head_size) ||
356 (test.info_size != head->info_size))
363 /* Accept the header */
367 /* Allocate the "*_info" array */
368 C_MAKE(head->info_ptr, head->info_size, char);
370 /* Read the "*_info" array */
371 fd_read(fd, head->info_ptr, head->info_size);
376 /* Allocate the "*_name" array */
377 C_MAKE(head->name_ptr, head->name_size, char);
379 /* Read the "*_name" array */
380 fd_read(fd, head->name_ptr, head->name_size);
386 /* Allocate the "*_text" array */
387 C_MAKE(head->text_ptr, head->text_size, char);
389 /* Read the "*_text" array */
390 fd_read(fd, head->text_ptr, head->text_size);
400 * Initialize the header of an *_info.raw file.
402 static void init_header(header *head, int num, int len)
404 /* Save the "version" */
405 head->v_major = FAKE_VER_MAJOR;
406 head->v_minor = FAKE_VER_MINOR;
407 head->v_patch = FAKE_VER_PATCH;
410 /* Save the "record" information */
411 head->info_num = num;
412 head->info_len = len;
414 /* Save the size of "*_head" and "*_info" */
415 head->head_size = sizeof(header);
416 head->info_size = head->info_num * head->info_len;
421 * Initialize the "*_info" array
423 * Note that we let each entry have a unique "name" and "text" string,
424 * even if the string happens to be empty (everyone has a unique '\0').
426 static errr init_info(cptr filename, header *head,
427 void **info, char **name, char **text)
441 #ifdef ALLOW_TEMPLATES
443 /*** Load the binary image file ***/
445 /* Build the filename */
447 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
449 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
453 /* Attempt to open the "raw" file */
454 fd = fd_open(buf, O_RDONLY);
456 /* Process existing "raw" file */
459 #ifdef CHECK_MODIFICATION_TIME
461 err = check_modification_date(fd, format("%s.txt", filename));
463 #endif /* CHECK_MODIFICATION_TIME */
465 /* Attempt to parse the "raw" file */
467 err = init_info_raw(fd, head);
474 /* Do we have to parse the *.txt file? */
477 /*** Make the fake arrays ***/
479 /* Allocate the "*_info" array */
480 C_MAKE(head->info_ptr, head->info_size, char);
482 /* Hack -- make "fake" arrays */
483 if (name) C_MAKE(head->name_ptr, FAKE_NAME_SIZE, char);
484 if (text) C_MAKE(head->text_ptr, FAKE_TEXT_SIZE, char);
486 if (info) (*info) = head->info_ptr;
487 if (name) (*name) = head->name_ptr;
488 if (text) (*text) = head->text_ptr;
490 /*** Load the ascii template file ***/
492 /* Build the filename */
494 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, format("%s.txt", filename));
497 fp = my_fopen(buf, "r");
501 if (!fp) quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤ò¥ª¡¼¥×¥ó¤Ç¤¤Þ¤»¤ó¡£", filename));
503 if (!fp) quit(format("Cannot open '%s.txt' file.", filename));
508 err = init_info_txt(fp, buf, head, head->parse_info_txt);
520 oops = ((err > 0) ? err_str[err] : "̤ÃΤÎ");
523 msg_format("'%s.txt'¥Õ¥¡¥¤¥ë¤Î %d ¹ÔÌܤ˥¨¥é¡¼¡£", filename, error_line);
524 msg_format("¥ì¥³¡¼¥É %d ¤Ï '%s' ¥¨¥é¡¼¤¬¤¢¤ê¤Þ¤¹¡£", error_idx, oops);
525 msg_format("¹½Ê¸ '%s'¡£", buf);
529 quit(format("'%s.txt'¥Õ¥¡¥¤¥ë¤Ë¥¨¥é¡¼", filename));
532 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
535 msg_format("Error %d at line %d of '%s.txt'.", err, error_line, filename);
536 msg_format("Record %d contains a '%s' error.", error_idx, oops);
537 msg_format("Parsing '%s'.", buf);
541 quit(format("Error in '%s.txt' file.", filename));
547 /*** Dump the binary image file ***/
549 /* File type is "DATA" */
550 FILE_TYPE(FILE_TYPE_DATA);
552 /* Build the filename */
554 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
556 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
560 /* Grab permissions */
563 /* Kill the old file */
566 /* Attempt to create the raw file */
567 fd = fd_make(buf, mode);
569 /* Drop permissions */
572 /* Dump to the file */
576 fd_write(fd, (cptr)(head), head->head_size);
578 /* Dump the "*_info" array */
579 fd_write(fd, head->info_ptr, head->info_size);
581 /* Dump the "*_name" array */
582 fd_write(fd, head->name_ptr, head->name_size);
584 /* Dump the "*_text" array */
585 fd_write(fd, head->text_ptr, head->text_size);
592 /*** Kill the fake arrays ***/
594 /* Free the "*_info" array */
595 C_KILL(head->info_ptr, head->info_size, char);
597 /* Hack -- Free the "fake" arrays */
598 if (name) C_KILL(head->name_ptr, FAKE_NAME_SIZE, char);
599 if (text) C_KILL(head->text_ptr, FAKE_TEXT_SIZE, char);
601 #endif /* ALLOW_TEMPLATES */
604 /*** Load the binary image file ***/
606 /* Build the filename */
608 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s_j.raw", filename));
610 path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, format("%s.raw", filename));
614 /* Attempt to open the "raw" file */
615 fd = fd_open(buf, O_RDONLY);
617 /* Process existing "raw" file */
619 if (fd < 0) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò¥í¡¼¥É¤Ç¤¤Þ¤»¤ó¡£", filename));
621 if (fd < 0) quit(format("Cannot load '%s.raw' file.", filename));
625 /* Attempt to parse the "raw" file */
626 err = init_info_raw(fd, head);
633 if (err) quit(format("'%s_j.raw'¥Õ¥¡¥¤¥ë¤ò²òÀϤǤ¤Þ¤»¤ó¡£", filename));
635 if (err) quit(format("Cannot parse '%s.raw' file.", filename));
638 #ifdef ALLOW_TEMPLATES
642 if (info) (*info) = head->info_ptr;
643 if (name) (*name) = head->name_ptr;
644 if (text) (*text) = head->text_ptr;
652 * Initialize the "f_info" array
654 static errr init_f_info(void)
656 /* Init the header */
657 init_header(&f_head, max_f_idx, sizeof(feature_type));
659 #ifdef ALLOW_TEMPLATES
661 /* Save a pointer to the parsing function */
662 f_head.parse_info_txt = parse_f_info;
664 #endif /* ALLOW_TEMPLATES */
666 return init_info("f_info", &f_head,
667 (void*)&f_info, (void*)&f_name, NULL);
672 * Initialize the "k_info" array
674 static errr init_k_info(void)
676 /* Init the header */
677 init_header(&k_head, max_k_idx, sizeof(object_kind));
679 #ifdef ALLOW_TEMPLATES
681 /* Save a pointer to the parsing function */
682 k_head.parse_info_txt = parse_k_info;
684 #endif /* ALLOW_TEMPLATES */
686 return init_info("k_info", &k_head,
687 (void*)&k_info, (void*)&k_name, (void*)&k_text);
693 * Initialize the "a_info" array
695 static errr init_a_info(void)
697 /* Init the header */
698 init_header(&a_head, max_a_idx, sizeof(artifact_type));
700 #ifdef ALLOW_TEMPLATES
702 /* Save a pointer to the parsing function */
703 a_head.parse_info_txt = parse_a_info;
705 #endif /* ALLOW_TEMPLATES */
707 return init_info("a_info", &a_head,
708 (void*)&a_info, (void*)&a_name, (void*)&a_text);
714 * Initialize the "e_info" array
716 static errr init_e_info(void)
718 /* Init the header */
719 init_header(&e_head, max_e_idx, sizeof(ego_item_type));
721 #ifdef ALLOW_TEMPLATES
723 /* Save a pointer to the parsing function */
724 e_head.parse_info_txt = parse_e_info;
726 #endif /* ALLOW_TEMPLATES */
728 return init_info("e_info", &e_head,
729 (void*)&e_info, (void*)&e_name, (void*)&e_text);
735 * Initialize the "r_info" array
737 static errr init_r_info(void)
739 /* Init the header */
740 init_header(&r_head, max_r_idx, sizeof(monster_race));
742 #ifdef ALLOW_TEMPLATES
744 /* Save a pointer to the parsing function */
745 r_head.parse_info_txt = parse_r_info;
747 #endif /* ALLOW_TEMPLATES */
749 return init_info("r_info", &r_head,
750 (void*)&r_info, (void*)&r_name, (void*)&r_text);
756 * Initialize the "d_info" array
758 static errr init_d_info(void)
760 /* Init the header */
761 init_header(&d_head, max_d_idx, sizeof(dungeon_info_type));
763 #ifdef ALLOW_TEMPLATES
765 /* Save a pointer to the parsing function */
766 d_head.parse_info_txt = parse_d_info;
768 #endif /* ALLOW_TEMPLATES */
770 return init_info("d_info", &d_head,
771 (void*)&d_info, (void*)&d_name, (void*)&d_text);
776 * Initialize the "v_info" array
778 * Note that we let each entry have a unique "name" and "text" string,
779 * even if the string happens to be empty (everyone has a unique '\0').
781 errr init_v_info(void)
783 /* Init the header */
784 init_header(&v_head, max_v_idx, sizeof(vault_type));
786 #ifdef ALLOW_TEMPLATES
788 /* Save a pointer to the parsing function */
789 v_head.parse_info_txt = parse_v_info;
791 #endif /* ALLOW_TEMPLATES */
793 return init_info("v_info", &v_head,
794 (void*)&v_info, (void*)&v_name, (void*)&v_text);
799 * Initialize the "s_info" array
801 static errr init_s_info(void)
803 /* Init the header */
804 init_header(&s_head, MAX_CLASS, sizeof(skill_table));
806 #ifdef ALLOW_TEMPLATES
808 /* Save a pointer to the parsing function */
809 s_head.parse_info_txt = parse_s_info;
811 #endif /* ALLOW_TEMPLATES */
813 return init_info("s_info", &s_head,
814 (void*)&s_info, NULL, NULL);
819 * Initialize the "m_info" array
821 static errr init_m_info(void)
823 /* Init the header */
824 init_header(&m_head, MAX_CLASS, sizeof(player_magic));
826 #ifdef ALLOW_TEMPLATES
828 /* Save a pointer to the parsing function */
829 m_head.parse_info_txt = parse_m_info;
831 #endif /* ALLOW_TEMPLATES */
833 return init_info("m_info", &m_head,
834 (void*)&m_info, NULL, NULL);
839 /*** Initialize others ***/
842 * Hack -- Objects sold in the stores -- by tval/sval pair.
844 static byte store_table[MAX_STORES][STORE_CHOICES][2] =
849 { TV_FOOD, SV_FOOD_RATION },
850 { TV_FOOD, SV_FOOD_RATION },
851 { TV_FOOD, SV_FOOD_RATION },
852 { TV_FOOD, SV_FOOD_RATION },
854 { TV_FOOD, SV_FOOD_RATION },
855 { TV_FOOD, SV_FOOD_BISCUIT },
856 { TV_FOOD, SV_FOOD_JERKY },
857 { TV_FOOD, SV_FOOD_JERKY },
859 { TV_FOOD, SV_FOOD_PINT_OF_WINE },
860 { TV_FOOD, SV_FOOD_PINT_OF_ALE },
861 { TV_LITE, SV_LITE_TORCH },
862 { TV_LITE, SV_LITE_TORCH },
864 { TV_LITE, SV_LITE_TORCH },
865 { TV_LITE, SV_LITE_TORCH },
866 { TV_LITE, SV_LITE_LANTERN },
867 { TV_LITE, SV_LITE_LANTERN },
879 { TV_SHOT, SV_AMMO_NORMAL },
880 { TV_ARROW, SV_AMMO_NORMAL },
881 { TV_BOLT, SV_AMMO_NORMAL },
882 { TV_DIGGING, SV_SHOVEL },
884 { TV_DIGGING, SV_PICK },
885 { TV_CLOAK, SV_CLOAK },
886 { TV_CLOAK, SV_CLOAK },
887 { TV_CLOAK, SV_FUR_CLOAK },
889 { TV_FOOD, SV_FOOD_RATION },
890 { TV_FOOD, SV_FOOD_RATION },
891 { TV_FOOD, SV_FOOD_RATION },
892 { TV_FOOD, SV_FOOD_RATION },
894 { TV_POTION, SV_POTION_WATER },
895 { TV_POTION, SV_POTION_WATER },
896 { TV_LITE, SV_LITE_LANTERN },
897 { TV_LITE, SV_LITE_LANTERN },
899 { TV_FOOD, SV_FOOD_WAYBREAD },
900 { TV_FOOD, SV_FOOD_WAYBREAD },
904 { TV_SHOT, SV_AMMO_NORMAL },
905 { TV_ARROW, SV_AMMO_NORMAL },
906 { TV_BOLT, SV_AMMO_NORMAL },
907 { TV_DIGGING, SV_SHOVEL }
913 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
914 { TV_BOOTS, SV_PAIR_OF_SOFT_LEATHER_BOOTS },
915 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
916 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
918 { TV_HELM, SV_HARD_LEATHER_CAP },
919 { TV_HELM, SV_HARD_LEATHER_CAP },
920 { TV_HELM, SV_METAL_CAP },
921 { TV_HELM, SV_IRON_HELM },
923 { TV_SOFT_ARMOR, SV_ROBE },
924 { TV_SOFT_ARMOR, SV_ROBE },
925 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
926 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
928 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
929 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
930 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
931 { TV_SOFT_ARMOR, SV_HARD_STUDDED_LEATHER },
933 { TV_SOFT_ARMOR, SV_RHINO_HIDE_ARMOR },
934 { TV_SOFT_ARMOR, SV_LEATHER_SCALE_MAIL },
935 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
936 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
938 { TV_HARD_ARMOR, SV_DOUBLE_RING_MAIL },
939 { TV_HARD_ARMOR, SV_AUGMENTED_CHAIN_MAIL },
940 { TV_HARD_ARMOR, SV_BAR_CHAIN_MAIL },
941 { TV_HARD_ARMOR, SV_DOUBLE_CHAIN_MAIL },
943 { TV_HARD_ARMOR, SV_METAL_BRIGANDINE_ARMOUR },
944 { TV_HARD_ARMOR, SV_SPLINT_MAIL },
945 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
946 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
948 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
949 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
950 { TV_SHIELD, SV_LARGE_LEATHER_SHIELD },
951 { TV_SHIELD, SV_SMALL_METAL_SHIELD },
953 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
954 { TV_BOOTS, SV_PAIR_OF_HARD_LEATHER_BOOTS },
955 { TV_HELM, SV_HARD_LEATHER_CAP },
956 { TV_HELM, SV_HARD_LEATHER_CAP },
958 { TV_SOFT_ARMOR, SV_ROBE },
959 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
960 { TV_SOFT_ARMOR, SV_SOFT_LEATHER_ARMOR },
961 { TV_SOFT_ARMOR, SV_HARD_LEATHER_ARMOR },
963 { TV_SOFT_ARMOR, SV_LEATHER_JACK },
964 { TV_HARD_ARMOR, SV_METAL_SCALE_MAIL },
965 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
966 { TV_HARD_ARMOR, SV_CHAIN_MAIL },
968 { TV_GLOVES, SV_SET_OF_LEATHER_GLOVES },
969 { TV_GLOVES, SV_SET_OF_GAUNTLETS },
970 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD },
971 { TV_SHIELD, SV_SMALL_LEATHER_SHIELD }
977 { TV_SWORD, SV_DAGGER },
978 { TV_SWORD, SV_MAIN_GAUCHE },
979 { TV_SWORD, SV_RAPIER },
980 { TV_SWORD, SV_SMALL_SWORD },
982 { TV_SWORD, SV_SHORT_SWORD },
983 { TV_SWORD, SV_SABRE },
984 { TV_SWORD, SV_CUTLASS },
985 { TV_SWORD, SV_TULWAR },
987 { TV_SWORD, SV_BROAD_SWORD },
988 { TV_SWORD, SV_LONG_SWORD },
989 { TV_SWORD, SV_SCIMITAR },
990 { TV_SWORD, SV_KATANA },
992 { TV_SWORD, SV_BASTARD_SWORD },
993 { TV_POLEARM, SV_SPEAR },
994 { TV_POLEARM, SV_AWL_PIKE },
995 { TV_POLEARM, SV_TRIDENT },
997 { TV_POLEARM, SV_PIKE },
998 { TV_POLEARM, SV_BEAKED_AXE },
999 { TV_POLEARM, SV_BROAD_AXE },
1000 { TV_POLEARM, SV_LANCE },
1002 { TV_POLEARM, SV_BATTLE_AXE },
1003 { TV_POLEARM, SV_HATCHET },
1004 { TV_BOW, SV_SLING },
1005 { TV_BOW, SV_SHORT_BOW },
1007 { TV_BOW, SV_LIGHT_XBOW },
1008 { TV_SHOT, SV_AMMO_NORMAL },
1009 { TV_SHOT, SV_AMMO_NORMAL },
1010 { TV_ARROW, SV_AMMO_NORMAL },
1012 { TV_ARROW, SV_AMMO_NORMAL },
1013 { TV_BOLT, SV_AMMO_NORMAL },
1014 { TV_BOLT, SV_AMMO_NORMAL },
1015 { TV_BOW, SV_LIGHT_XBOW },
1017 { TV_ARROW, SV_AMMO_NORMAL },
1018 { TV_BOLT, SV_AMMO_NORMAL },
1019 { TV_BOW, SV_SHORT_BOW },
1020 { TV_BOW, SV_LIGHT_XBOW },
1022 { TV_SWORD, SV_DAGGER },
1023 { TV_SWORD, SV_TANTO },
1024 { TV_SWORD, SV_RAPIER },
1025 { TV_SWORD, SV_SMALL_SWORD },
1027 { TV_SWORD, SV_SHORT_SWORD },
1028 { TV_SWORD, SV_LONG_SWORD },
1029 { TV_SWORD, SV_SCIMITAR },
1030 { TV_SWORD, SV_BROAD_SWORD },
1032 { TV_HISSATSU_BOOK, 0 },
1033 { TV_HISSATSU_BOOK, 0 },
1034 { TV_HISSATSU_BOOK, 1 },
1035 { TV_HISSATSU_BOOK, 1 },
1041 { TV_HAFTED, SV_NUNCHAKU },
1042 { TV_HAFTED, SV_QUARTERSTAFF },
1043 { TV_HAFTED, SV_MACE },
1044 { TV_HAFTED, SV_BO_STAFF },
1046 { TV_HAFTED, SV_WAR_HAMMER },
1047 { TV_HAFTED, SV_WAR_HAMMER },
1048 { TV_HAFTED, SV_MORNING_STAR },
1049 { TV_HAFTED, SV_FLAIL },
1051 { TV_HAFTED, SV_LEAD_FILLED_MACE },
1052 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1053 { TV_SCROLL, SV_SCROLL_BLESSING },
1054 { TV_SCROLL, SV_SCROLL_HOLY_CHANT },
1056 { TV_POTION, SV_POTION_HEROISM },
1057 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1058 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1059 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1061 { TV_POTION, SV_POTION_CURE_LIGHT },
1062 { TV_POTION, SV_POTION_CURE_SERIOUS },
1063 { TV_POTION, SV_POTION_CURE_SERIOUS },
1064 { TV_POTION, SV_POTION_CURE_CRITICAL },
1066 { TV_POTION, SV_POTION_CURE_CRITICAL },
1067 { TV_POTION, SV_POTION_RESTORE_EXP },
1068 { TV_POTION, SV_POTION_RESTORE_EXP },
1069 { TV_POTION, SV_POTION_RESTORE_EXP },
1071 { TV_LIFE_BOOK, 0 },
1072 { TV_LIFE_BOOK, 0 },
1073 { TV_LIFE_BOOK, 1 },
1074 { TV_LIFE_BOOK, 1 },
1076 { TV_CRUSADE_BOOK, 0 },
1077 { TV_CRUSADE_BOOK, 0 },
1078 { TV_CRUSADE_BOOK, 1 },
1079 { TV_CRUSADE_BOOK, 1 },
1081 { TV_HAFTED, SV_WHIP },
1082 { TV_HAFTED, SV_MACE },
1083 { TV_HAFTED, SV_BALL_AND_CHAIN },
1084 { TV_HAFTED, SV_WAR_HAMMER },
1086 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1087 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1088 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1089 { TV_POTION, SV_POTION_CURE_CRITICAL },
1091 { TV_POTION, SV_POTION_CURE_CRITICAL },
1092 { TV_POTION, SV_POTION_RESTORE_EXP },
1095 { TV_STATUE, SV_ANY },
1097 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1098 { TV_SCROLL, SV_SCROLL_REMOVE_CURSE },
1099 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE },
1100 { TV_SCROLL, SV_SCROLL_STAR_REMOVE_CURSE }
1106 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1107 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1108 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1109 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1111 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1112 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1113 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1114 { TV_SCROLL, SV_SCROLL_LIGHT },
1116 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1117 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1118 { TV_SCROLL, SV_SCROLL_TELEPORT },
1119 { TV_SCROLL, SV_SCROLL_MONSTER_CONFUSION },
1121 { TV_SCROLL, SV_SCROLL_MAPPING },
1122 { TV_SCROLL, SV_SCROLL_DETECT_GOLD },
1123 { TV_SCROLL, SV_SCROLL_DETECT_ITEM },
1124 { TV_SCROLL, SV_SCROLL_DETECT_TRAP },
1126 { TV_SCROLL, SV_SCROLL_DETECT_INVIS },
1127 { TV_SCROLL, SV_SCROLL_RECHARGING },
1128 { TV_SCROLL, SV_SCROLL_TELEPORT },
1129 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1131 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1132 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1133 { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL },
1134 { TV_SCROLL, SV_SCROLL_TELEPORT },
1136 { TV_SCROLL, SV_SCROLL_TELEPORT },
1137 { TV_POTION, SV_POTION_RES_STR },
1138 { TV_POTION, SV_POTION_RES_INT },
1139 { TV_POTION, SV_POTION_RES_WIS },
1141 { TV_POTION, SV_POTION_RES_DEX },
1142 { TV_POTION, SV_POTION_RES_CON },
1143 { TV_POTION, SV_POTION_RES_CHR },
1144 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1146 { TV_SCROLL, SV_SCROLL_IDENTIFY },
1147 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY }, /* Yep, occasionally! */
1148 { TV_SCROLL, SV_SCROLL_STAR_IDENTIFY },
1149 { TV_SCROLL, SV_SCROLL_LIGHT },
1151 { TV_POTION, SV_POTION_RES_STR },
1152 { TV_POTION, SV_POTION_RES_INT },
1153 { TV_POTION, SV_POTION_RES_WIS },
1154 { TV_POTION, SV_POTION_RES_DEX },
1156 { TV_POTION, SV_POTION_RES_CON },
1157 { TV_POTION, SV_POTION_RES_CHR },
1158 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1159 { TV_SCROLL, SV_SCROLL_ENCHANT_ARMOR },
1161 { TV_SCROLL, SV_SCROLL_RECHARGING },
1162 { TV_SCROLL, SV_SCROLL_PHASE_DOOR },
1163 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_HIT },
1164 { TV_SCROLL, SV_SCROLL_ENCHANT_WEAPON_TO_DAM },
1169 /* Magic-User store */
1171 { TV_RING, SV_RING_PROTECTION },
1172 { TV_RING, SV_RING_FEATHER_FALL },
1173 { TV_RING, SV_RING_PROTECTION },
1174 { TV_RING, SV_RING_RESIST_FIRE },
1176 { TV_RING, SV_RING_RESIST_COLD },
1177 { TV_AMULET, SV_AMULET_CHARISMA },
1178 { TV_RING, SV_RING_WARNING },
1179 { TV_AMULET, SV_AMULET_RESIST_ACID },
1181 { TV_AMULET, SV_AMULET_SEARCHING },
1182 { TV_WAND, SV_WAND_SLOW_MONSTER },
1183 { TV_WAND, SV_WAND_CONFUSE_MONSTER },
1184 { TV_WAND, SV_WAND_SLEEP_MONSTER },
1186 { TV_WAND, SV_WAND_MAGIC_MISSILE },
1187 { TV_WAND, SV_WAND_STINKING_CLOUD },
1188 { TV_WAND, SV_WAND_WONDER },
1189 { TV_WAND, SV_WAND_DISARMING },
1191 { TV_STAFF, SV_STAFF_LITE },
1192 { TV_STAFF, SV_STAFF_MAPPING },
1193 { TV_STAFF, SV_STAFF_DETECT_TRAP },
1194 { TV_STAFF, SV_STAFF_DETECT_DOOR },
1196 { TV_STAFF, SV_STAFF_DETECT_GOLD },
1197 { TV_STAFF, SV_STAFF_DETECT_ITEM },
1198 { TV_STAFF, SV_STAFF_DETECT_INVIS },
1199 { TV_STAFF, SV_STAFF_DETECT_EVIL },
1201 { TV_STAFF, SV_STAFF_TELEPORTATION },
1202 { TV_STAFF, SV_STAFF_TELEPORTATION },
1203 { TV_STAFF, SV_STAFF_TELEPORTATION },
1204 { TV_STAFF, SV_STAFF_TELEPORTATION },
1206 { TV_STAFF, SV_STAFF_IDENTIFY },
1207 { TV_STAFF, SV_STAFF_IDENTIFY },
1208 { TV_STAFF, SV_STAFF_IDENTIFY },
1210 { TV_STAFF, SV_STAFF_IDENTIFY },
1211 { TV_STAFF, SV_STAFF_REMOVE_CURSE },
1212 { TV_STAFF, SV_STAFF_CURE_LIGHT },
1213 { TV_STAFF, SV_STAFF_PROBING },
1217 { TV_SORCERY_BOOK, 0 },
1218 { TV_SORCERY_BOOK, 0 },
1219 { TV_SORCERY_BOOK, 1 },
1220 { TV_SORCERY_BOOK, 1 },
1222 { TV_ARCANE_BOOK, 0 },
1223 { TV_ARCANE_BOOK, 0 },
1224 { TV_ARCANE_BOOK, 1 },
1225 { TV_ARCANE_BOOK, 1 },
1227 { TV_ARCANE_BOOK, 2 },
1228 { TV_ARCANE_BOOK, 2 },
1229 { TV_ARCANE_BOOK, 3 },
1230 { TV_ARCANE_BOOK, 3 },
1235 /* Black Market (unused) */
1308 { TV_SORCERY_BOOK, 0 },
1309 { TV_SORCERY_BOOK, 0 },
1310 { TV_SORCERY_BOOK, 1 },
1311 { TV_SORCERY_BOOK, 1 },
1313 { TV_NATURE_BOOK, 0 },
1314 { TV_NATURE_BOOK, 0 },
1315 { TV_NATURE_BOOK, 1 },
1316 { TV_NATURE_BOOK, 1 },
1318 { TV_CHAOS_BOOK, 0 },
1319 { TV_CHAOS_BOOK, 0 },
1320 { TV_CHAOS_BOOK, 1 },
1321 { TV_CHAOS_BOOK, 1 },
1323 { TV_DEATH_BOOK, 0 },
1324 { TV_DEATH_BOOK, 0 },
1325 { TV_DEATH_BOOK, 1 },
1326 { TV_DEATH_BOOK, 1 },
1328 { TV_TRUMP_BOOK, 0 }, /* +16 */
1329 { TV_TRUMP_BOOK, 0 },
1330 { TV_TRUMP_BOOK, 1 },
1331 { TV_TRUMP_BOOK, 1 },
1333 { TV_ARCANE_BOOK, 0 },
1334 { TV_ARCANE_BOOK, 1 },
1335 { TV_ARCANE_BOOK, 2 },
1336 { TV_ARCANE_BOOK, 3 },
1338 { TV_ENCHANT_BOOK, 0 },
1339 { TV_ENCHANT_BOOK, 0 },
1340 { TV_ENCHANT_BOOK, 1 },
1341 { TV_ENCHANT_BOOK, 1 },
1343 { TV_DAEMON_BOOK, 0 },
1344 { TV_DAEMON_BOOK, 0 },
1345 { TV_DAEMON_BOOK, 1 },
1346 { TV_DAEMON_BOOK, 1 },
1348 { TV_MUSIC_BOOK, 0 },
1349 { TV_MUSIC_BOOK, 0 },
1350 { TV_MUSIC_BOOK, 1 },
1351 { TV_MUSIC_BOOK, 1 },
1355 /* Museum (unused) */
1393 * Initialize misc. values
1395 static errr init_misc(void)
1397 /* Initialize the values */
1398 process_dungeon_file("misc.txt", 0, 0, 0, 0);
1405 * Initialize town array
1407 static errr init_towns(void)
1411 /*** Prepare the Towns ***/
1413 /* Allocate the towns */
1414 C_MAKE(town, max_towns, town_type);
1416 for (i = 1; i < max_towns; i++)
1418 /*** Prepare the Stores ***/
1420 /* Allocate the stores */
1421 C_MAKE(town[i].store, MAX_STORES, store_type);
1423 /* Fill in each store */
1424 for (j = 0; j < MAX_STORES; j++)
1426 /* Access the store */
1427 store_type *st_ptr = &town[i].store[j];
1429 if ((i > 1) && (j == STORE_MUSEUM || j == STORE_HOME)) continue;
1431 /* Assume full stock */
1434 * ²æ¤¬²È¤¬ 20 ¥Ú¡¼¥¸¤Þ¤Ç»È¤¨¤ë±£¤·µ¡Ç½¤Î¤¿¤á¤Î½àÈ÷¡£
1435 * ¥ª¥×¥·¥ç¥ó¤¬Í¸ú¤Ç¤â¤½¤¦¤Ç¤Ê¤¯¤Æ¤â°ì±þ¥¹¥Ú¡¼¥¹
1438 if (j == STORE_HOME)
1440 st_ptr->stock_size = (STORE_INVEN_MAX * 10);
1442 else if (j == STORE_MUSEUM)
1444 st_ptr->stock_size = (STORE_INVEN_MAX * 50);
1448 st_ptr->stock_size = STORE_INVEN_MAX;
1452 /* Allocate the stock */
1453 C_MAKE(st_ptr->stock, st_ptr->stock_size, object_type);
1455 /* No table for the black market or home */
1456 if ((j == STORE_BLACK) || (j == STORE_HOME) || (j == STORE_MUSEUM)) continue;
1458 /* Assume full table */
1459 st_ptr->table_size = STORE_CHOICES;
1461 /* Allocate the stock */
1462 C_MAKE(st_ptr->table, st_ptr->table_size, s16b);
1464 /* Scan the choices */
1465 for (k = 0; k < STORE_CHOICES; k++)
1469 /* Extract the tval/sval codes */
1470 int tv = store_table[j][k][0];
1471 int sv = store_table[j][k][1];
1474 for (k_idx = 1; k_idx < max_k_idx; k_idx++)
1476 object_kind *k_ptr = &k_info[k_idx];
1479 if ((k_ptr->tval == tv) && (k_ptr->sval == sv)) break;
1483 if (k_idx == max_k_idx) continue;
1485 /* Add that item index to the table */
1486 st_ptr->table[st_ptr->table_num++] = k_idx;
1495 * Initialize buildings
1497 errr init_buildings(void)
1501 for (i = 0; i < MAX_BLDG; i++)
1503 building[i].name[0] = '\0';
1504 building[i].owner_name[0] = '\0';
1505 building[i].owner_race[0] = '\0';
1507 for (j = 0; j < 8; j++)
1509 building[i].act_names[j][0] = '\0';
1510 building[i].member_costs[j] = 0;
1511 building[i].other_costs[j] = 0;
1512 building[i].letters[j] = 0;
1513 building[i].actions[j] = 0;
1514 building[i].action_restr[j] = 0;
1517 for (j = 0; j < MAX_CLASS; j++)
1519 building[i].member_class[j] = 0;
1522 for (j = 0; j < MAX_RACES; j++)
1524 building[i].member_race[j] = 0;
1527 for (j = 0; j < MAX_MAGIC+1; j++)
1529 building[i].member_realm[j] = 0;
1538 * Initialize quest array
1540 static errr init_quests(void)
1544 /*** Prepare the quests ***/
1546 /* Allocate the quests */
1547 C_MAKE(quest, max_quests, quest_type);
1549 /* Set all quest to "untaken" */
1550 for (i = 0; i < max_quests; i++)
1552 quest[i].status = QUEST_STATUS_UNTAKEN;
1560 * Initialize some other arrays
1562 static errr init_other(void)
1567 /*** Prepare the "dungeon" information ***/
1569 /* Allocate and Wipe the object list */
1570 C_MAKE(o_list, max_o_idx, object_type);
1572 /* Allocate and Wipe the monster list */
1573 C_MAKE(m_list, max_m_idx, monster_type);
1575 /* Allocate and Wipe the max dungeon level */
1576 C_MAKE(max_dlv, max_d_idx, s16b);
1578 /* Allocate and wipe each line of the cave */
1579 for (i = 0; i < MAX_HGT; i++)
1581 /* Allocate one row of the cave */
1582 C_MAKE(cave[i], MAX_WID, cave_type);
1586 /*** Prepare the various "bizarre" arrays ***/
1588 /* Macro variables */
1589 C_MAKE(macro__pat, MACRO_MAX, cptr);
1590 C_MAKE(macro__act, MACRO_MAX, cptr);
1591 C_MAKE(macro__cmd, MACRO_MAX, bool);
1593 /* Macro action buffer */
1594 C_MAKE(macro__buf, 1024, char);
1596 /* Quark variables */
1599 /* Message variables */
1600 C_MAKE(message__ptr, MESSAGE_MAX, u16b);
1601 C_MAKE(message__buf, MESSAGE_BUF, char);
1603 /* Hack -- No messages yet */
1604 message__tail = MESSAGE_BUF;
1607 /*** Prepare the Player inventory ***/
1610 C_MAKE(inventory, INVEN_TOTAL, object_type);
1613 /*** Prepare the options ***/
1615 /* Scan the options */
1616 for (i = 0; option_info[i].o_desc; i++)
1618 int os = option_info[i].o_set;
1619 int ob = option_info[i].o_bit;
1621 /* Set the "default" options */
1622 if (option_info[i].o_var)
1625 option_mask[os] |= (1L << ob);
1628 if (option_info[i].o_norm)
1631 option_flag[os] |= (1L << ob);
1638 option_flag[os] &= ~(1L << ob);
1643 /* Analyze the windows */
1644 for (n = 0; n < 8; n++)
1646 /* Analyze the options */
1647 for (i = 0; i < 32; i++)
1650 if (window_flag_desc[i])
1653 window_mask[n] |= (1L << i);
1659 * Set the "default" window flags
1660 * Window 1 : Display messages
1661 * Window 2 : Display inven/equip
1663 window_flag[1] = 1L << 6;
1664 window_flag[2] = 1L << 0;
1667 /*** Pre-allocate space for the "format()" buffer ***/
1669 /* Hack -- Just call the "format()" function */
1670 (void)format("%s (%s).", "Mr.Hoge", MAINTAINER);
1680 * Initialize some other arrays
1682 static errr init_alloc(void)
1685 monster_race *r_ptr;
1691 /* Allocate the "r_info" array */
1692 C_MAKE(elements, max_r_idx, tag_type);
1694 /* Scan the monsters */
1695 for (i = 1; i < max_r_idx; i++)
1697 elements[i].tag = r_info[i].level;
1698 elements[i].pointer = (void*)i;
1701 tag_sort(elements, max_r_idx);
1703 /*** Initialize monster allocation info ***/
1705 /* Size of "alloc_race_table" */
1706 alloc_race_size = max_r_idx;
1708 /* Allocate the alloc_race_table */
1709 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1711 /* Scan the monsters */
1712 for (i = 1; i < max_r_idx; i++)
1714 /* Get the i'th race */
1715 r_ptr = &r_info[(int)elements[i].pointer];
1717 /* Count valid pairs */
1722 /* Extract the base level */
1725 /* Extract the base probability */
1726 p = (100 / r_ptr->rarity);
1728 /* Load the entry */
1729 alloc_race_table[i].index = (int)elements[i].pointer;
1730 alloc_race_table[i].level = x;
1731 alloc_race_table[i].prob1 = p;
1732 alloc_race_table[i].prob2 = p;
1733 alloc_race_table[i].prob3 = p;
1737 /* Free the "r_info" array */
1738 C_KILL(elements, max_r_idx, tag_type);
1740 #else /* SORT_R_INFO */
1744 s16b num[MAX_DEPTH];
1745 s16b aux[MAX_DEPTH];
1747 /*** Analyze monster allocation info ***/
1749 /* Clear the "aux" array */
1750 C_WIPE(&aux, MAX_DEPTH, s16b);
1752 /* Clear the "num" array */
1753 C_WIPE(&num, MAX_DEPTH, s16b);
1755 /* Size of "alloc_race_table" */
1756 alloc_race_size = 0;
1758 /* Scan the monsters */
1759 for (i = 1; i < max_r_idx; i++)
1761 /* Get the i'th race */
1764 /* Legal monsters */
1767 /* Count the entries */
1770 /* Group by level */
1771 num[r_ptr->level]++;
1775 /* Collect the level indexes */
1776 for (i = 1; i < MAX_DEPTH; i++)
1778 /* Group by level */
1784 if (!num[0]) quit("Ä®¤Î¥â¥ó¥¹¥¿¡¼¤¬¤Ê¤¤¡ª");
1786 if (!num[0]) quit("No town monsters!");
1791 /*** Initialize monster allocation info ***/
1793 /* Allocate the alloc_race_table */
1794 C_MAKE(alloc_race_table, alloc_race_size, alloc_entry);
1796 /* Access the table entry */
1797 table = alloc_race_table;
1799 /* Scan the monsters */
1800 for (i = 1; i < max_r_idx; i++)
1802 /* Get the i'th race */
1805 /* Count valid pairs */
1810 /* Extract the base level */
1813 /* Extract the base probability */
1814 p = (100 / r_ptr->rarity);
1816 /* Skip entries preceding our locale */
1817 y = (x > 0) ? num[x-1] : 0;
1819 /* Skip previous entries at this locale */
1822 /* Load the entry */
1829 /* Another entry complete for this locale */
1834 #endif /* SORT_R_INFO */
1836 /* Init the "alloc_kind_table" */
1837 (void)init_object_alloc();
1846 * Hack -- take notes on line 23
1848 static void note(cptr str)
1850 Term_erase(0, 23, 255);
1851 Term_putstr(20, 23, -1, TERM_WHITE, str);
1858 * Hack -- Explain a broken "lib" folder and quit (see below).
1860 * XXX XXX XXX This function is "messy" because various things
1861 * may or may not be initialized, but the "plog()" and "quit()"
1862 * functions are "supposed" to work under any conditions.
1864 static void init_angband_aux(cptr why)
1871 plog("'lib'¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤¤¤«²õ¤ì¤Æ¤¤¤ë¤è¤¦¤Ç¤¹¡£");
1874 plog("¤Ò¤ç¤Ã¤È¤¹¤ë¤È¥¢¡¼¥«¥¤¥Ö¤¬Àµ¤·¤¯²òÅव¤ì¤Æ¤¤¤Ê¤¤¤Î¤«¤â¤·¤ì¤Þ¤»¤ó¡£");
1877 plog("³ºÅö¤¹¤ë'README'¥Õ¥¡¥¤¥ë¤òÆɤó¤Ç³Îǧ¤·¤Æ¤ß¤Æ²¼¤µ¤¤¡£");
1879 /* Quit with error */
1880 quit("Ã×̿Ū¤Ê¥¨¥é¡¼¡£");
1883 plog("The 'lib' directory is probably missing or broken.");
1886 plog("Perhaps the archive was not extracted correctly.");
1889 plog("See the 'README' file for more information.");
1891 /* Quit with error */
1892 quit("Fatal Error.");
1899 * Hack -- main Angband initialization entry point
1901 * Verify some files, display the "news.txt" file, create
1902 * the high score file, initialize all internal arrays, and
1903 * load the basic "user pref files".
1905 * Be very careful to keep track of the order in which things
1906 * are initialized, in particular, the only thing *known* to
1907 * be available when this function is called is the "z-term.c"
1908 * package, and that may not be fully initialized until the
1909 * end of this function, when the default "user pref files"
1910 * are loaded and "Term_xtra(TERM_XTRA_REACT,0)" is called.
1912 * Note that this function attempts to verify the "news" file,
1913 * and the game aborts (cleanly) on failure, since without the
1914 * "news" file, it is likely that the "lib" folder has not been
1915 * correctly located. Otherwise, the news file is displayed for
1918 * Note that this function attempts to verify (or create) the
1919 * "high score" file, and the game aborts (cleanly) on failure,
1920 * since one of the most common "extraction" failures involves
1921 * failing to extract all sub-directories (even empty ones), such
1922 * as by failing to use the "-d" option of "pkunzip", or failing
1923 * to use the "save empty directories" option with "Compact Pro".
1924 * This error will often be caught by the "high score" creation
1925 * code below, since the "lib/apex" directory, being empty in the
1926 * standard distributions, is most likely to be "lost", making it
1927 * impossible to create the high score file.
1929 * Note that various things are initialized by this function,
1930 * including everything that was once done by "init_some_arrays".
1932 * This initialization involves the parsing of special files
1933 * in the "lib/data" and sometimes the "lib/edit" directories.
1935 * Note that the "template" files are initialized first, since they
1936 * often contain errors. This means that macros and message recall
1937 * and things like that are not available until after they are done.
1939 * We load the default "user pref files" here in case any "color"
1940 * changes are needed before character creation.
1942 * Note that the "graf-xxx.prf" file must be loaded separately,
1943 * if needed, in the first (?) pass through "TERM_XTRA_REACT".
1945 void init_angband(void)
1956 /*** Verify the "news" file ***/
1958 /* Build the filename */
1960 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
1962 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
1966 /* Attempt to open the file */
1967 fd = fd_open(buf, O_RDONLY);
1976 sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤Ç¤¤Þ¤»¤ó!", buf);
1978 sprintf(why, "Cannot access the '%s' file!", buf);
1982 /* Crash and burn */
1983 init_angband_aux(why);
1990 /*** Display the "news" file ***/
1995 /* Build the filename */
1997 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news_j.txt");
1999 path_build(buf, sizeof(buf), ANGBAND_DIR_FILE, "news.txt");
2003 /* Open the News file */
2004 fp = my_fopen(buf, "r");
2011 /* Dump the file to the screen */
2012 while (0 == my_fgets(fp, buf, sizeof(buf)))
2014 /* Display and advance */
2015 Term_putstr(0, i++, -1, TERM_WHITE, buf);
2026 /*** Verify (or create) the "high score" file ***/
2028 /* Build the filename */
2029 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
2031 /* Attempt to open the high score file */
2032 fd = fd_open(buf, O_RDONLY);
2037 /* File type is "DATA" */
2038 FILE_TYPE(FILE_TYPE_DATA);
2040 /* Grab permissions */
2043 /* Create a new high score file */
2044 fd = fd_make(buf, mode);
2046 /* Drop permissions */
2056 sprintf(why, "'%s'¥Õ¥¡¥¤¥ë¤òºîÀ®¤Ç¤¤Þ¤»¤ó!", buf);
2058 sprintf(why, "Cannot create the '%s' file!", buf);
2062 /* Crash and burn */
2063 init_angband_aux(why);
2071 /*** Initialize some arrays ***/
2073 /* Initialize misc. values */
2075 note("[ÊÑ¿ô¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...(¤½¤Î¾)");
2077 note("[Initializing values... (misc)]");
2081 if (init_misc()) quit("¤½¤Î¾¤ÎÊÑ¿ô¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2083 if (init_misc()) quit("Cannot initialize misc. values");
2087 /* Initialize feature info */
2089 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÃÏ·Á)]");
2090 if (init_f_info()) quit("ÃÏ·Á½é´ü²½ÉÔǽ");
2092 note("[Initializing arrays... (features)]");
2093 if (init_f_info()) quit("Cannot initialize features");
2097 /* Initialize object info */
2099 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥¤¥Æ¥à)]");
2100 if (init_k_info()) quit("¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2102 note("[Initializing arrays... (objects)]");
2103 if (init_k_info()) quit("Cannot initialize objects");
2107 /* Initialize artifact info */
2109 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ÅÁÀâ¤Î¥¢¥¤¥Æ¥à)]");
2110 if (init_a_info()) quit("ÅÁÀâ¤Î¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2112 note("[Initializing arrays... (artifacts)]");
2113 if (init_a_info()) quit("Cannot initialize artifacts");
2117 /* Initialize ego-item info */
2119 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à)]");
2120 if (init_e_info()) quit("̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à½é´ü²½ÉÔǽ");
2122 note("[Initializing arrays... (ego-items)]");
2123 if (init_e_info()) quit("Cannot initialize ego-items");
2127 /* Initialize monster info */
2129 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥â¥ó¥¹¥¿¡¼)]");
2130 if (init_r_info()) quit("¥â¥ó¥¹¥¿¡¼½é´ü²½ÉÔǽ");
2132 note("[Initializing arrays... (monsters)]");
2133 if (init_r_info()) quit("Cannot initialize monsters");
2137 /* Initialize dungeon info */
2139 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥À¥ó¥¸¥ç¥ó)]");
2140 if (init_d_info()) quit("¥À¥ó¥¸¥ç¥ó½é´ü²½ÉÔǽ");
2142 note("[Initializing arrays... (dungeon)]");
2143 if (init_d_info()) quit("Cannot initialize dungeon");
2147 for (i = 1; i < max_d_idx; i++)
2148 if (d_info[i].final_guardian)
2149 r_info[d_info[i].final_guardian].flags7 |= RF7_GUARDIAN;
2152 /* Initialize magic info */
2154 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (ËâË¡)]");
2155 if (init_m_info()) quit("ËâË¡½é´ü²½ÉÔǽ");
2157 note("[Initializing arrays... (magic)]");
2158 if (init_m_info()) quit("Cannot initialize magic");
2161 /* Initialize weapon_exp info */
2163 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (½ÏÎýÅÙ)]");
2164 if (init_s_info()) quit("½ÏÎýÅÙ½é´ü²½ÉÔǽ");
2166 note("[Initializing arrays... (skill)]");
2167 if (init_s_info()) quit("Cannot initialize skill");
2170 /* Initialize wilderness array */
2172 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¹ÓÌî)]");
2174 note("[Initializing arrays... (wilderness)]");
2178 if (init_wilderness()) quit("¹ÓÌî¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2180 if (init_wilderness()) quit("Cannot initialize wilderness");
2184 /* Initialize town array */
2186 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (³¹)]");
2188 note("[Initializing arrays... (towns)]");
2192 if (init_towns()) quit("³¹¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2194 if (init_towns()) quit("Cannot initialize towns");
2198 /* Initialize building array */
2200 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (·úʪ)]");
2202 note("[Initializing arrays... (buildings)]");
2206 if (init_buildings()) quit("·úʪ¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2208 if (init_buildings()) quit("Cannot initialize buildings");
2212 /* Initialize quest array */
2214 note("[ÇÛÎó¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹... (¥¯¥¨¥¹¥È)]");
2216 note("[Initializing arrays... (quests)]");
2220 if (init_quests()) quit("¥¯¥¨¥¹¥È¤ò½é´ü²½¤Ç¤¤Þ¤»¤ó");
2222 if (init_quests()) quit("Cannot initialize quests");
2226 /* Initialize vault info */
2228 if (init_v_info()) quit("vault ½é´ü²½ÉÔǽ");
2230 if (init_v_info()) quit("Cannot initialize vaults");
2234 /* Initialize some other arrays */
2236 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¤½¤Î¾)]");
2237 if (init_other()) quit("¤½¤Î¾¤Î¥Ç¡¼¥¿½é´ü²½ÉÔǽ");
2239 note("[Initializing arrays... (other)]");
2240 if (init_other()) quit("Cannot initialize other stuff");
2244 /* Initialize some other arrays */
2247 note("[¥Ç¡¼¥¿¤Î½é´ü²½Ãæ... (¥¢¥í¥±¡¼¥·¥ç¥ó)]");
2248 if (init_alloc()) quit("¥¢¥í¥±¡¼¥·¥ç¥ó¡¦¥¹¥¿¥Ã¥Õ½é´ü²½ÉÔǽ");
2250 note("[Initializing arrays... (alloc)]");
2251 if (init_alloc()) quit("Cannot initialize alloc stuff");
2256 /*** Load default user pref files ***/
2258 /* Initialize feature info */
2260 note("[¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤ò½é´ü²½¤·¤Æ¤¤¤Þ¤¹...]");
2262 note("[Initializing user pref files...]");
2266 /* Access the "basic" pref file */
2267 strcpy(buf, "pref.prf");
2269 /* Process that file */
2270 process_pref_file(buf);
2272 /* Access the "basic" system pref file */
2273 sprintf(buf, "pref-%s.prf", ANGBAND_SYS);
2275 /* Process that file */
2276 process_pref_file(buf);
2280 note("[½é´ü²½½ªÎ»]");
2282 note("[Initialization complete]");
2288 * Get check sum in string form
2290 cptr get_check_sum(void)
2292 return format("%02x%02x%02x%02x%02x%02x%02x%02x%02x",