3 * @brief ¥²¡¼¥à¥Ç¡¼¥¿½é´ü²½1 / Initialization (part 1) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
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
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
27 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
28 * in this file is compiled out, and the game will not run unless valid
29 * "binary template files" already exist in "lib/data". Thus, one can
30 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
31 * "*.raw" files in "lib/data", and then quit, and recompile without
32 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
33 * from changing the ascii template files in potentially dangerous ways.
34 * The code could actually be removed and placed into a "stand-alone"
35 * program, but that feels a little silly, especially considering some
36 * of the platforms that we currently support.
44 #ifdef ALLOW_TEMPLATES
49 /*** Helper arrays for parsing ascii template files ***/
52 * ¥â¥ó¥¹¥¿¡¼¤ÎÂÇ·â¼êÃʥȡ¼¥¯¥ó¤ÎÄêµÁ /
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * ¥â¥ó¥¹¥¿¡¼¤ÎÂÇ·â°À¥È¡¼¥¯¥ó¤ÎÄêµÁ /
89 * Monster Blow Effects
91 static cptr r_info_blow_effect[] =
133 * ÃÏ·Á°À¥È¡¼¥¯¥ó¤ÎÄêµÁ /
136 static cptr f_info_flags[] =
258 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ1 /
261 static cptr r_info_flags1[] =
298 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ2 /
301 static cptr r_info_flags2[] =
338 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ3 /
341 static cptr r_info_flags3[] =
378 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ4 /
381 static cptr r_info_flags4[] =
418 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ5 /
421 static cptr r_info_flags5[] =
458 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ6 /
461 static cptr r_info_flags6[] =
478 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
499 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ7 /
502 static cptr r_info_flags7[] =
539 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ8 /
542 static cptr r_info_flags8[] =
574 "WILD_SWAMP", /* ToDo: Implement Swamp */
580 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ9 /
583 static cptr r_info_flags9[] =
622 * ¥â¥ó¥¹¥¿¡¼ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁR(ÂÑÀ) /
625 static cptr r_info_flagsr[] =
663 * ¥ª¥Ö¥¸¥§¥¯¥È´ðËÜÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ /
666 static cptr k_info_flags[] =
763 "XXX3", /* Fake flag for Smith */
764 "XXX4", /* Fake flag for Smith */
814 * ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®ÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ /
817 static cptr k_info_gen_flags[] =
854 * ¥À¥ó¥¸¥ç¥óÆÃÀ¥È¡¼¥¯¥ó¤ÎÄêµÁ /
857 static cptr d_info_flags1[] =
895 * @brief ¥Ç¡¼¥¿¤Î²ÄÊÑʸ»úÎó¾ðÊó¤ò¥Æ¥¥¹¥È¤È¤·¤ÆÊݴɤ¹¤ë /
896 * Add a text to the text-storage and store offset to it.
897 * @param offset ʸ»úÎóÊݴɥݥ¤¥ó¥¿¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È
898 * @param head ¥Æ¥¥¹¥ÈÊݴɥإåÀ¾ðÊó¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
899 * @param buf ÊÝ´Éʸ»úÎó
900 * @param normal_text ¥Æ¥¥¹¥È¤ÎÀµµ¬²½¤ò¹Ô¤¦
902 * ̵»öÊݴɤ¬¤Ç¤¤¿¤éTRUE¤òÊÖ¤¹¡£
903 * Returns FALSE when there isn't enough space available to store
906 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
908 /* Hack -- Verify space */
909 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
915 /* Advance and save the text index */
916 *offset = ++head->text_size;
919 /* Additional text */
920 else if (normal_text)
923 * If neither the end of the last line nor
924 * the beginning of current line is not a space,
925 * fill up a space as a correct separator of two words.
927 if (head->text_size > 0 &&
929 (*(head->text_ptr + head->text_size - 1) != ' ') &&
930 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
931 (buf[0] != ' ') && !iskanji(buf[0])
933 (*(head->text_ptr + head->text_size - 1) != ' ') &&
939 *(head->text_ptr + head->text_size) = ' ';
941 /* Advance the index */
946 /* Append chars to the text */
947 strcpy(head->text_ptr + head->text_size, buf);
949 /* Advance the index */
950 head->text_size += strlen(buf);
958 * @brief ¥Ç¡¼¥¿¤Î²ÄÊÑʸ»úÎó¾ðÊó¤ò̾Á°¤È¤·¤ÆÊݴɤ¹¤ë /
959 * Add a name to the name-storage and return an offset to it.
960 * @param offset ʸ»úÎóÊݴɥݥ¤¥ó¥¿¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È
961 * @param head ¥Æ¥¥¹¥ÈÊݴɥإåÀ¾ðÊó¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
962 * @param buf ÊÝ´Éʸ»úÎó
964 * ̵»öÊݴɤ¬¤Ç¤¤¿¤éTRUE¤òÊÖ¤¹¡£
965 * Returns FALSE when there isn't enough space available to store
968 static bool add_name(u32b *offset, header *head, cptr buf)
970 /* Hack -- Verify space */
971 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
977 /* Advance and save the name index */
978 *offset = ++head->name_size;
981 /* Append chars to the names */
982 strcpy(head->name_ptr + head->name_size, buf);
984 /* Advance the index */
985 head->name_size += strlen(buf);
993 * @brief ¥Ç¡¼¥¿¤Î²ÄÊÑʸ»úÎó¾ðÊó¤ò¥¿¥°¤È¤·¤ÆÊݴɤ¹¤ë /
994 * Add a tag to the tag-storage and return an offset to it.
995 * @param offset ʸ»úÎóÊݴɥݥ¤¥ó¥¿¤«¤é¤Î¥ª¥Õ¥»¥Ã¥È
996 * @param head ¥Æ¥¥¹¥ÈÊݴɥإåÀ¾ðÊó¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
997 * @param buf ÊÝ´Éʸ»úÎó
999 * ̵»öÊݴɤ¬¤Ç¤¤¿¤éTRUE¤òÊÖ¤¹¡£
1000 * Returns FALSE when there isn't enough space available to store
1003 static bool add_tag(s16b *offset, header *head, cptr buf)
1007 /* Search for an existing (fake) tag */
1008 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1011 if (streq(&head->tag_ptr[i], buf)) break;
1014 /* There was no existing tag */
1015 if (i >= head->tag_size)
1017 /* Hack -- Verify space */
1018 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1021 /* Append chars to the tags */
1022 strcpy(head->tag_ptr + head->tag_size, buf);
1024 /* Point the new tag */
1027 /* Advance the index */
1028 head->tag_size += strlen(buf) + 1;
1031 /* Return offset of the tag */
1040 * @brief ¥·¥ó¥Ü¥ë1ʸ»ú¤ò¥«¥é¡¼ID¤ËÊѹ¹¤¹¤ë /
1041 * Convert a "color letter" into an "actual" color
1042 * The colors are: dwsorgbuDWvyRGBU, as shown below
1043 * @param c ¥·¥ó¥Ü¥ëʸ»ú
1046 byte color_char_to_attr(char c)
1050 case 'd': return (TERM_DARK);
1051 case 'w': return (TERM_WHITE);
1052 case 's': return (TERM_SLATE);
1053 case 'o': return (TERM_ORANGE);
1054 case 'r': return (TERM_RED);
1055 case 'g': return (TERM_GREEN);
1056 case 'b': return (TERM_BLUE);
1057 case 'u': return (TERM_UMBER);
1059 case 'D': return (TERM_L_DARK);
1060 case 'W': return (TERM_L_WHITE);
1061 case 'v': return (TERM_VIOLET);
1062 case 'y': return (TERM_YELLOW);
1063 case 'R': return (TERM_L_RED);
1064 case 'G': return (TERM_L_GREEN);
1065 case 'B': return (TERM_L_BLUE);
1066 case 'U': return (TERM_L_UMBER);
1074 /*** Initialize from ascii template files ***/
1078 * @brief ¥Ñ¡¼¥¹´Ø¿ô¤Ë´ð¤Å¤¤¤Æ¥Ç¡¼¥¿¥Õ¥¡¥¤¥ë¤«¤é¥Ç¡¼¥¿¤òÆɤ߼è¤ë /
1079 * Initialize an "*_info" array, by parsing an ascii "template" file
1080 * @param fp Æɤ߼è¤ê¤Ë»È¤¦¥Õ¥¡¥¤¥ë¥Ý¥¤¥ó¥¿
1081 * @param buf Æɤ߼è¤ê¤Ë»È¤¦¥Ð¥Ã¥Õ¥¡Îΰè
1082 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1083 * @param parse_info_txt_line ¥Ñ¡¼¥¹´Ø¿ô
1084 * @return ¥¨¥é¡¼¥³¡¼¥É
1086 errr init_info_txt(FILE *fp, char *buf, header *head,
1087 parse_info_txt_func parse_info_txt_line)
1091 /* Just before the first record */
1094 /* Just before the first line */
1098 /* Prepare the "fake" stuff */
1099 head->name_size = 0;
1100 head->text_size = 0;
1104 while (0 == my_fgets(fp, buf, 1024))
1106 /* Advance the line number */
1109 /* Skip comments and blank lines */
1110 if (!buf[0] || (buf[0] == '#')) continue;
1112 /* Verify correct "colon" format */
1113 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1116 /* Hack -- Process 'V' for "Version" */
1123 /* Mega Hack -- Calculate Check Sum */
1124 if (buf[0] != 'N' && buf[0] != 'D')
1127 for (i = 0; buf[i]; i++)
1129 head->v_extra += (byte)buf[i];
1130 head->v_extra ^= (1 << (i % 8));
1134 /* Parse the line */
1135 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1140 /* Complete the "name" and "text" sizes */
1141 if (head->name_size) head->name_size++;
1142 if (head->text_size) head->text_size++;
1150 * @brief Vault¾ðÊó(v_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
1151 * Initialize the "v_info" array, by parsing an ascii "template" file
1152 * @param buf ¥Æ¥¥¹¥ÈÎó
1153 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1154 * @return ¥¨¥é¡¼¥³¡¼¥É
1156 errr parse_v_info(char *buf, header *head)
1162 static vault_type *v_ptr = NULL;
1164 /* Process 'N' for "New/Number/Name" */
1167 /* Find the colon before the name */
1168 s = my_strchr(buf+2, ':');
1170 /* Verify that colon */
1173 /* Nuke the colon, advance to the name */
1176 /* Paranoia -- require a name */
1177 if (!*s) return (1);
1182 /* Verify information */
1183 if (i <= error_idx) return (4);
1185 /* Verify information */
1186 if (i >= head->info_num) return (2);
1188 /* Save the index */
1191 /* Point at the "info" */
1194 /* Store the name */
1195 if (!add_name(&v_ptr->name, head, s)) return (7);
1198 /* There better be a current v_ptr */
1199 else if (!v_ptr) return (3);
1201 /* Process 'D' for "Description" */
1202 else if (buf[0] == 'D')
1204 /* Acquire the text */
1207 /* Store the text */
1208 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1211 /* Process 'X' for "Extra info" (one line only) */
1212 else if (buf[0] == 'X')
1214 int typ, rat, hgt, wid;
1216 /* Scan for the values */
1217 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1218 &typ, &rat, &hgt, &wid)) return (1);
1220 /* Save the values */
1236 * @brief ¿¦¶Èµ»Ç½¾ðÊó(s_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
1237 * Initialize the "s_info" array, by parsing an ascii "template" file
1238 * @param buf ¥Æ¥¥¹¥ÈÎó
1239 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1240 * @return ¥¨¥é¡¼¥³¡¼¥É
1242 errr parse_s_info(char *buf, header *head)
1247 static skill_table *s_ptr = NULL;
1250 /* Process 'N' for "New/Number/Name" */
1256 /* Verify information */
1257 if (i <= error_idx) return (4);
1259 /* Verify information */
1260 if (i >= head->info_num) return (2);
1262 /* Save the index */
1265 /* Point at the "info" */
1269 /* There better be a current s_ptr */
1270 else if (!s_ptr) return (3);
1272 /* Process 'W' for "Weapon exp" */
1273 else if (buf[0] == 'W')
1275 int tval, sval, start, max;
1276 const s16b exp_conv_table[] =
1278 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1279 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1282 /* Scan for the values */
1283 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1284 &tval, &sval, &start, &max)) return (1);
1286 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1287 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1289 /* Save the values */
1290 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1291 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1294 /* Process 'S' for "Skill exp" */
1295 else if (buf[0] == 'S')
1297 int num, start, max;
1299 /* Scan for the values */
1300 if (3 != sscanf(buf+2, "%d:%d:%d",
1301 &num, &start, &max)) return (1);
1303 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1304 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1306 /* Save the values */
1307 s_ptr->s_start[num] = start;
1308 s_ptr->s_max[num] = max;
1321 * @brief ¿¦¶ÈËâË¡¾ðÊó(m_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
1322 * Initialize the "m_info" array, by parsing an ascii "template" file
1323 * @param buf ¥Æ¥¥¹¥ÈÎó
1324 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1325 * @return ¥¨¥é¡¼¥³¡¼¥É
1327 errr parse_m_info(char *buf, header *head)
1334 static player_magic *m_ptr = NULL;
1337 static int realm, magic_idx = 0, readable = 0;
1340 /* Process 'N' for "New/Number/Name" */
1346 /* Verify information */
1347 if (i <= error_idx) return (4);
1349 /* Verify information */
1350 if (i >= head->info_num) return (2);
1352 /* Save the index */
1355 /* Point at the "info" */
1359 /* There better be a current m_ptr */
1360 else if (!m_ptr) return (3);
1362 /* Process 'I' for "Info" (one line only) */
1363 else if (buf[0] == 'I')
1366 int xtra, type, first, weight;
1368 /* Find the colon before the name */
1369 s = my_strchr(buf+2, ':');
1371 /* Verify that colon */
1374 /* Nuke the colon, advance to the name */
1379 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1380 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1381 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1382 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1383 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1388 /* Find the colon before the name */
1389 s = my_strchr(s, ':');
1391 /* Verify that colon */
1394 /* Nuke the colon, advance to the name */
1397 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1398 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1399 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1400 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1401 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1402 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1406 /* Scan for the values */
1407 if (4 != sscanf(s, "%x:%d:%d:%d",
1408 (uint *)&xtra, &type, &first, &weight)) return (1);
1410 m_ptr->spell_xtra = xtra;
1411 m_ptr->spell_type = type;
1412 m_ptr->spell_first = first;
1413 m_ptr->spell_weight = weight;
1417 /* Process 'R' for "Realm" (one line only) */
1418 else if (buf[0] == 'R')
1420 /* Scan for the values */
1421 if (2 != sscanf(buf+2, "%d:%d",
1422 &realm, &readable)) return (1);
1427 else if (buf[0] == 'T')
1429 int level, mana, fail, exp;
1431 if (!readable) return (1);
1432 /* Scan for the values */
1433 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1434 &level, &mana, &fail, &exp)) return (1);
1436 m_ptr->info[realm][magic_idx].slevel = level;
1437 m_ptr->info[realm][magic_idx].smana = mana;
1438 m_ptr->info[realm][magic_idx].sfail = fail;
1439 m_ptr->info[realm][magic_idx].sexp = exp;
1453 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(ÈÆÍÑ) /
1454 * Grab one flag from a textual string
1455 * @param flgs ¥Ó¥Ã¥È¥Õ¥é¥°¤òÄɲ乤ëÀè¤Î»²¾È¥Ý¥¤¥ó¥¿
1456 * @param names ¥È¡¼¥¯¥óÄêµÁÇÛÎó
1457 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
1458 * @return ¥¨¥é¡¼¥³¡¼¥É
1460 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1465 for (i = 0; i < 32; i++)
1467 if (streq(what, names[i]))
1469 *flags |= (1L << i);
1479 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë¡ÊÃÏ·Á¾ðÊó¸þ¤±¡Ë /
1480 * Grab one flag in an feature_type from a textual string
1481 * @param f_ptr ÃÏ·Á¾ðÊó¤òÊݴɤ¹¤ëÀè¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
1482 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
1483 * @return ¥¨¥é¡¼¥³¡¼¥É
1485 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1490 for (i = 0; i < FF_FLAG_MAX; i++)
1492 if (streq(what, f_info_flags[i]))
1494 add_flag(f_ptr->flags, i);
1501 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1503 msg_format("Unknown feature flag '%s'.", what);
1507 return PARSE_ERROR_GENERIC;
1512 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°(¥¹¥Æ¡¼¥È)¤ò°ì¤ÄÆÀ¤ë¡ÊÃÏ·Á¾ðÊó¸þ¤±2¡Ë /
1513 * Grab an action in an feature_type from a textual string
1514 * @param f_ptr ÃÏ·Á¾ðÊó¤òÊݴɤ¹¤ëÀè¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
1515 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
1516 * @param count ¥¹¥Æ¡¼¥È¤ÎÊݸÀèID
1517 * @return ¥¨¥é¡¼¥³¡¼¥É
1519 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1524 for (i = 0; i < FF_FLAG_MAX; i++)
1526 if (streq(what, f_info_flags[i]))
1528 f_ptr->state[count].action = i;
1535 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1537 msg_format("Unknown feature action '%s'.", what);
1541 return PARSE_ERROR_GENERIC;
1546 * @brief ÃÏ·Á¾ðÊó(f_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
1547 * Initialize the "f_info" array, by parsing an ascii "template" file
1548 * @param buf ¥Æ¥¥¹¥ÈÎó
1549 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1550 * @return ¥¨¥é¡¼¥³¡¼¥É
1552 errr parse_f_info(char *buf, header *head)
1559 static feature_type *f_ptr = NULL;
1562 /* Process 'N' for "New/Number/Name" */
1565 /* Find the colon before the name */
1566 s = my_strchr(buf+2, ':');
1570 /* Nuke the colon, advance to the name */
1577 /* Verify information */
1578 if (i <= error_idx) return (4);
1580 /* Verify information */
1581 if (i >= head->info_num) return (2);
1583 /* Save the index */
1586 /* Point at the "info" */
1589 /* Tag name is given */
1593 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1596 /* Default "mimic" */
1599 /* Default "destroyed state" -- if not specified */
1600 f_ptr->destroyed = i;
1602 /* Default "states" */
1603 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1606 /* There better be a current f_ptr */
1607 else if (!f_ptr) return (3);
1610 else if (buf[0] == 'J')
1612 /* Store the name */
1613 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1616 else if (buf[0] == 'E')
1618 /* Ignore english name */
1621 else if (buf[0] == 'J')
1623 /* Ignore Japanese name */
1626 else if (buf[0] == 'E')
1628 /* Acquire the Text */
1631 /* Store the name */
1632 if (!add_name(&f_ptr->name, head, s)) return (7);
1637 /* Process 'M' for "Mimic" (one line only) */
1638 else if (buf[0] == 'M')
1642 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1644 /* Record a fake tag index */
1645 f_ptr->mimic = -offset;
1649 /* Process 'G' for "Graphics" (one line only) */
1650 else if (buf[0] == 'G')
1654 char char_tmp[F_LIT_MAX];
1657 if (buf[1] != ':') return (1);
1658 if (!buf[2]) return (1);
1659 if (buf[3] != ':') return (1);
1660 if (!buf[4]) return (1);
1662 /* Extract the char */
1663 char_tmp[F_LIT_STANDARD] = buf[2];
1665 /* Extract the color */
1666 s_attr = color_char_to_attr(buf[4]);
1669 if (s_attr > 127) return (1);
1671 /* Save the standard values */
1672 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1673 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1675 /* Is this feature supports lighting? */
1678 /* G:c:a:LIT (default) */
1679 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1681 /* G:c:a:lc:la:dc:da */
1682 if (!streq(buf + 6, "LIT"))
1684 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1686 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1687 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1688 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1689 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1691 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1693 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1696 /* Use default lighting */
1699 /* No lighting support */
1700 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1703 /* Extract the color */
1704 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1705 if (f_ptr->d_attr[j] > 127) return 1;
1708 f_ptr->d_char[j] = char_tmp[j];
1714 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1716 f_ptr->d_attr[j] = s_attr;
1717 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1723 /* Hack -- Process 'F' for flags */
1724 else if (buf[0] == 'F')
1726 /* Parse every entry textually */
1727 for (s = buf + 2; *s; )
1729 /* Find the end of this entry */
1730 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1732 /* Nuke and skip any dividers */
1736 while (*t == ' ' || *t == '|') t++;
1739 /* XXX XXX XXX Hack -- Read feature subtype */
1740 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1742 /* Extract a "subtype" */
1745 /* Start at next entry */
1752 /* XXX XXX XXX Hack -- Read feature power */
1753 if (1 == sscanf(s, "POWER_%d", &i))
1755 /* Extract a "power" */
1758 /* Start at next entry */
1765 /* Parse this entry */
1766 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1768 /* Start the next entry */
1773 /* Process 'W' for "More Info" (one line only) */
1774 else if (buf[0] == 'W')
1778 /* Scan for the value */
1779 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1781 /* Save the value */
1782 f_ptr->priority = priority;
1785 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1786 else if (buf[0] == 'K')
1790 /* Find the next empty state slot (if any) */
1791 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1793 /* Oops, no more slots */
1794 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1796 /* Analyze the first field */
1797 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1799 /* Terminate the field (if necessary) */
1800 if (*t == ':') *t++ = '\0';
1802 /* Is this default entry? */
1803 if (streq(s, "DESTROYED"))
1805 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1807 /* Record a fake tag index */
1808 f_ptr->destroyed = -offset;
1813 f_ptr->state[i].action = 0;
1815 /* Parse this entry */
1816 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1818 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1820 /* Record a fake tag index */
1821 f_ptr->state[i].result = -offset;
1834 * @brief ÃÏ·Á¥¿¥°¤«¤éID¤òÆÀ¤ë /
1835 * Convert a fake tag to a real feat index
1836 * @param str ¥¿¥°Ê¸»úÎó
1839 s16b f_tag_to_index(cptr str)
1843 /* Search for real index corresponding to this fake tag */
1844 for (i = 0; i < f_head.info_num; i++)
1846 if (streq(f_tag + f_info[i].tag, str))
1848 /* Return the index */
1859 * @brief ÃÏ·Á¥¿¥°¤«¤éID¤òÆÀ¤ë /
1860 * Search for real index corresponding to this fake tag
1861 * @param str ¥¿¥°Ê¸»úÎó
1864 static void search_real_feat(s16b *feat)
1868 /* Don't convert non-fake tag */
1869 if (*feat >= 0) return;
1871 /* Search for real index corresponding to this fake tag */
1872 for (i = 0; i < f_head.info_num; i++)
1874 if ((-(*feat)) == f_info[i].tag)
1876 /* Record real index */
1884 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1886 msg_format("%s is undefined.", f_tag + (-(*feat)));
1892 * @brief ÃÏ·Á¾ðÊó¤Î³Æ¼ï¥¿¥°¤«¤éID¤ØÊÑ´¹¤·¤Æ·ë²Ì¤ò¼ý¤á¤ë /
1893 * Retouch fake tags of f_info
1894 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1897 void retouch_f_info(header *head)
1901 /* Convert fake tags to real feat indices */
1902 for (i = 0; i < head->info_num; i++)
1904 feature_type *f_ptr = &f_info[i];
1907 search_real_feat(&f_ptr->mimic);
1909 search_real_feat(&f_ptr->destroyed);
1911 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1917 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(¥Ù¡¼¥¹¥¢¥¤¥Æ¥àÍÑ) /
1918 * Grab one flag in an object_kind from a textual string
1919 * @param k_ptr ÊÝ´ÉÀè¤Î¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
1920 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
1921 * @return ¥¨¥é¡¼¥³¡¼¥É
1923 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1928 for (i = 0; i < TR_FLAG_MAX; i++)
1930 if (streq(what, k_info_flags[i]))
1932 add_flag(k_ptr->flags, i);
1937 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1942 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1944 msg_format("Unknown object flag '%s'.", what);
1953 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(ȯưǽÎÏÍÑ) /
1954 * Grab one activation index flag
1955 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
1956 * @return ȯưǽÎÏID
1958 static byte grab_one_activation_flag(cptr what)
1964 if (activation_info[i].flag == NULL) break;
1966 if (streq(what, activation_info[i].flag))
1968 return activation_info[i].index;
1980 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
1982 msg_format("Unknown activation flag '%s'.", what);
1991 * @brief ¥Ù¡¼¥¹¥¢¥¤¥Æ¥à(k_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
1992 * Initialize the "k_info" array, by parsing an ascii "template" file
1993 * @param buf ¥Æ¥¥¹¥ÈÎó
1994 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
1995 * @return ¥¨¥é¡¼¥³¡¼¥É
1997 errr parse_k_info(char *buf, header *head)
2004 static object_kind *k_ptr = NULL;
2007 /* Process 'N' for "New/Number/Name" */
2014 /* Find the colon before the name */
2015 s = my_strchr(buf+2, ':');
2017 /* Verify that colon */
2020 /* Nuke the colon, advance to the name */
2026 /* Verify information */
2027 if (i <= error_idx) return (4);
2029 /* Verify information */
2030 if (i >= head->info_num) return (2);
2032 /* Save the index */
2035 /* Point at the "info" */
2039 /* Paranoia -- require a name */
2040 if (!*s) return (1);
2042 /* Find the colon before the flavor */
2043 flavor = my_strchr(s, ':');
2045 /* Verify that colon */
2048 /* Nuke the colon, advance to the flavor */
2051 /* Store the flavor */
2052 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2055 /* Store the name */
2056 if (!add_name(&k_ptr->name, head, s)) return (7);
2060 /* There better be a current k_ptr */
2061 else if (!k_ptr) return (3);
2065 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2066 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2067 else if (buf[0] == 'E')
2072 else if (buf[0] == 'E')
2076 /* Acquire the name */
2079 /* Find the colon before the flavor */
2080 flavor = my_strchr(s, ':');
2082 /* Verify that colon */
2085 /* Nuke the colon, advance to the flavor */
2088 /* Store the flavor */
2089 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2092 /* Store the name */
2093 if (!add_name(&k_ptr->name, head, s)) return (7);
2097 /* Process 'D' for "Description" */
2098 else if (buf[0] == 'D')
2103 /* Acquire the text */
2108 /* Acquire the text */
2112 /* Store the text */
2113 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2116 /* Process 'G' for "Graphics" (one line only) */
2117 else if (buf[0] == 'G')
2123 if (buf[1] != ':') return (1);
2124 if (!buf[2]) return (1);
2125 if (buf[3] != ':') return (1);
2126 if (!buf[4]) return (1);
2128 /* Extract the char */
2131 /* Extract the attr */
2132 tmp = color_char_to_attr(buf[4]);
2135 if (tmp > 127) return (1);
2137 /* Save the values */
2138 k_ptr->d_attr = tmp;
2139 k_ptr->d_char = sym;
2142 /* Process 'I' for "Info" (one line only) */
2143 else if (buf[0] == 'I')
2145 int tval, sval, pval;
2147 /* Scan for the values */
2148 if (3 != sscanf(buf+2, "%d:%d:%d",
2149 &tval, &sval, &pval)) return (1);
2151 /* Save the values */
2157 /* Process 'W' for "More Info" (one line only) */
2158 else if (buf[0] == 'W')
2160 int level, extra, wgt;
2163 /* Scan for the values */
2164 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2165 &level, &extra, &wgt, &cost)) return (1);
2167 /* Save the values */
2168 k_ptr->level = level;
2169 k_ptr->extra = extra;
2170 k_ptr->weight = wgt;
2174 /* Process 'A' for "Allocation" (one line only) */
2175 else if (buf[0] == 'A')
2179 /* XXX XXX XXX Simply read each number following a colon */
2180 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2182 /* Default chance */
2183 k_ptr->chance[i] = 1;
2185 /* Store the attack damage index */
2186 k_ptr->locale[i] = atoi(s+1);
2188 /* Find the slash */
2189 t = my_strchr(s+1, '/');
2191 /* Find the next colon */
2192 s = my_strchr(s+1, ':');
2194 /* If the slash is "nearby", use it */
2195 if (t && (!s || t < s))
2197 int chance = atoi(t+1);
2198 if (chance > 0) k_ptr->chance[i] = chance;
2203 /* Hack -- Process 'P' for "power" and such */
2204 else if (buf[0] == 'P')
2206 int ac, hd1, hd2, th, td, ta;
2208 /* Scan for the values */
2209 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2210 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2220 /* Hack -- Process 'U' for activation index */
2221 else if (buf[0] == 'U')
2224 n = grab_one_activation_flag(buf + 2);
2235 /* Hack -- Process 'F' for flags */
2236 else if (buf[0] == 'F')
2238 /* Parse every entry textually */
2239 for (s = buf + 2; *s; )
2241 /* Find the end of this entry */
2242 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2244 /* Nuke and skip any dividers */
2248 while (*t == ' ' || *t == '|') t++;
2251 /* Parse this entry */
2252 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2254 /* Start the next entry */
2269 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥ÈÍÑ) /
2270 * Grab one activation index flag
2271 * @param a_ptr ÊÝ´ÉÀè¤Î¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
2272 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
2273 * @return ¥¨¥é¡¼¤¬¤¢¤Ã¤¿¾ì¹ç1¡¢¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç0¤òÊÖ¤¹
2275 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2280 for (i = 0; i < TR_FLAG_MAX; i++)
2282 if (streq(what, k_info_flags[i]))
2284 add_flag(a_ptr->flags, i);
2289 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2294 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2296 msg_format("Unknown artifact flag '%s'.", what);
2306 * @brief ¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¾ðÊó(a_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
2307 * Initialize the "a_info" array, by parsing an ascii "template" file
2308 * @param buf ¥Æ¥¥¹¥ÈÎó
2309 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
2310 * @return ¥¨¥é¡¼¥³¡¼¥É
2312 errr parse_a_info(char *buf, header *head)
2319 static artifact_type *a_ptr = NULL;
2322 /* Process 'N' for "New/Number/Name" */
2325 /* Find the colon before the name */
2326 s = my_strchr(buf+2, ':');
2328 /* Verify that colon */
2331 /* Nuke the colon, advance to the name */
2334 /* Paranoia -- require a name */
2335 if (!*s) return (1);
2340 /* Verify information */
2341 if (i < error_idx) return (4);
2343 /* Verify information */
2344 if (i >= head->info_num) return (2);
2346 /* Save the index */
2349 /* Point at the "info" */
2352 /* Ignore everything */
2353 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2354 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2355 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2356 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2358 /* Store the name */
2359 if (!add_name(&a_ptr->name, head, s)) return (7);
2363 /* There better be a current a_ptr */
2364 else if (!a_ptr) return (3);
2368 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2369 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2370 else if (buf[0] == 'E')
2375 else if (buf[0] == 'E')
2377 /* Acquire the Text */
2380 /* Store the name */
2381 if (!add_name(&a_ptr->name, head, s)) return (7);
2385 /* Process 'D' for "Description" */
2386 else if (buf[0] == 'D')
2391 /* Acquire the text */
2396 /* Acquire the text */
2400 /* Store the text */
2401 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2405 /* Process 'I' for "Info" (one line only) */
2406 else if (buf[0] == 'I')
2408 int tval, sval, pval;
2410 /* Scan for the values */
2411 if (3 != sscanf(buf+2, "%d:%d:%d",
2412 &tval, &sval, &pval)) return (1);
2414 /* Save the values */
2420 /* Process 'W' for "More Info" (one line only) */
2421 else if (buf[0] == 'W')
2423 int level, rarity, wgt;
2426 /* Scan for the values */
2427 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2428 &level, &rarity, &wgt, &cost)) return (1);
2430 /* Save the values */
2431 a_ptr->level = level;
2432 a_ptr->rarity = rarity;
2433 a_ptr->weight = wgt;
2437 /* Hack -- Process 'P' for "power" and such */
2438 else if (buf[0] == 'P')
2440 int ac, hd1, hd2, th, td, ta;
2442 /* Scan for the values */
2443 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2444 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2454 /* Hack -- Process 'U' for activation index */
2455 else if (buf[0] == 'U')
2458 n = grab_one_activation_flag(buf + 2);
2469 /* Hack -- Process 'F' for flags */
2470 else if (buf[0] == 'F')
2472 /* Parse every entry textually */
2473 for (s = buf + 2; *s; )
2475 /* Find the end of this entry */
2476 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2478 /* Nuke and skip any dividers */
2482 while ((*t == ' ') || (*t == '|')) t++;
2485 /* Parse this entry */
2486 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2488 /* Start the next entry */
2504 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥ÈÍÑ) /
2505 * Grab one flag in a ego-item_type from a textual string
2506 * @param e_ptr ÊÝ´ÉÀè¤Î¥¨¥´¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
2507 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
2508 * @return ¥¨¥é¡¼¤¬¤¢¤Ã¤¿¾ì¹ç1¡¢¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç0¤òÊÖ¤¹
2510 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2515 for (i = 0; i < TR_FLAG_MAX; i++)
2517 if (streq(what, k_info_flags[i]))
2519 add_flag(e_ptr->flags, i);
2524 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2529 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2531 msg_format("Unknown ego-item flag '%s'.", what);
2541 * @brief ¥¢¥¤¥Æ¥à¥¨¥´¾ðÊó(e_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
2542 * Initialize the "e_info" array, by parsing an ascii "template" file
2543 * @param buf ¥Æ¥¥¹¥ÈÎó
2544 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
2545 * @return ¥¨¥é¡¼¥³¡¼¥É
2547 errr parse_e_info(char *buf, header *head)
2554 static ego_item_type *e_ptr = NULL;
2557 /* Just before the first record */
2560 /* Just before the first line */
2564 /* Process 'N' for "New/Number/Name" */
2567 /* Find the colon before the name */
2568 s = my_strchr(buf+2, ':');
2570 /* Verify that colon */
2573 /* Nuke the colon, advance to the name */
2576 /* Paranoia -- require a name */
2577 if (!*s) return (1);
2582 /* Verify information */
2583 if (i < error_idx) return (4);
2585 /* Verify information */
2586 if (i >= head->info_num) return (2);
2588 /* Save the index */
2591 /* Point at the "info" */
2594 /* Store the name */
2595 if (!add_name(&e_ptr->name, head, s)) return (7);
2599 /* There better be a current e_ptr */
2600 else if (!e_ptr) return (3);
2604 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2605 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2606 else if (buf[0] == 'E')
2611 else if (buf[0] == 'E')
2613 /* Acquire the Text */
2616 /* Store the name */
2617 if (!add_name(&e_ptr->name, head, s)) return (7);
2622 /* Process 'D' for "Description" */
2623 else if (buf[0] == 'D')
2625 /* Acquire the text */
2628 /* Store the text */
2629 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2634 /* Process 'X' for "Xtra" (one line only) */
2635 else if (buf[0] == 'X')
2639 /* Scan for the values */
2640 if (2 != sscanf(buf+2, "%d:%d",
2641 &slot, &rating)) return (1);
2643 /* Save the values */
2645 e_ptr->rating = rating;
2648 /* Process 'W' for "More Info" (one line only) */
2649 else if (buf[0] == 'W')
2651 int level, rarity, pad2;
2654 /* Scan for the values */
2655 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2656 &level, &rarity, &pad2, &cost)) return (1);
2658 /* Save the values */
2659 e_ptr->level = level;
2660 e_ptr->rarity = rarity;
2661 /* e_ptr->weight = wgt; */
2665 /* Hack -- Process 'C' for "creation" */
2666 else if (buf[0] == 'C')
2670 /* Scan for the values */
2671 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2672 &th, &td, &ta, &pv)) return (1);
2674 e_ptr->max_to_h = th;
2675 e_ptr->max_to_d = td;
2676 e_ptr->max_to_a = ta;
2677 e_ptr->max_pval = pv;
2680 /* Hack -- Process 'U' for activation index */
2681 else if (buf[0] == 'U')
2684 n = grab_one_activation_flag(buf + 2);
2695 /* Hack -- Process 'F' for flags */
2696 else if (buf[0] == 'F')
2698 /* Parse every entry textually */
2699 for (s = buf + 2; *s; )
2701 /* Find the end of this entry */
2702 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2704 /* Nuke and skip any dividers */
2708 while ((*t == ' ') || (*t == '|')) t++;
2711 /* Parse this entry */
2712 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2714 /* Start the next entry */
2728 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(¥â¥ó¥¹¥¿¡¼ÍÑ1) /
2729 * Grab one (basic) flag in a monster_race from a textual string
2730 * @param e_ptr ÊÝ´ÉÀè¤Î¥â¥ó¥¹¥¿¡¼¼ï²¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
2731 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
2732 * @return ¥¨¥é¡¼¥³¡¼¥É
2734 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2736 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2739 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2742 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2745 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2748 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2751 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2754 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2759 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2761 msg_format("Unknown monster flag '%s'.", what);
2771 * @brief ¥Æ¥¥¹¥È¥È¡¼¥¯¥ó¤òÁöºº¤·¤Æ¥Õ¥é¥°¤ò°ì¤ÄÆÀ¤ë(¥â¥ó¥¹¥¿¡¼ÍÑ2) /
2772 * Grab one (spell) flag in a monster_race from a textual string
2773 * @param e_ptr ÊÝ´ÉÀè¤Î¥â¥ó¥¹¥¿¡¼¼ï²¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
2774 * @param what »²¾È¸µ¤Îʸ»úÎó¥Ý¥¤¥ó¥¿
2775 * @return ¥¨¥é¡¼¥³¡¼¥É
2777 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2779 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2782 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2785 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2790 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2792 msg_format("Unknown monster flag '%s'.", what);
2802 * @brief ¥â¥ó¥¹¥¿¡¼¼ï²¾ðÊó(r_info)¤Î¥Ñ¡¼¥¹´Ø¿ô /
2803 * Initialize the "r_info" array, by parsing an ascii "template" file
2804 * @param buf ¥Æ¥¥¹¥ÈÎó
2805 * @param head ¥Ø¥Ã¥À¹½Â¤ÂÎ
2806 * @return ¥¨¥é¡¼¥³¡¼¥É
2808 errr parse_r_info(char *buf, header *head)
2815 static monster_race *r_ptr = NULL;
2818 /* Process 'N' for "New/Number/Name" */
2821 /* Find the colon before the name */
2822 s = my_strchr(buf+2, ':');
2824 /* Verify that colon */
2827 /* Nuke the colon, advance to the name */
2830 /* Paranoia -- require a name */
2831 if (!*s) return (1);
2836 /* Verify information */
2837 if (i < error_idx) return (4);
2839 /* Verify information */
2840 if (i >= head->info_num) return (2);
2842 /* Save the index */
2845 /* Point at the "info" */
2848 /* Store the name */
2849 if (!add_name(&r_ptr->name, head, s)) return (7);
2853 /* There better be a current r_ptr */
2854 else if (!r_ptr) return (3);
2858 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2859 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2860 else if (buf[0] == 'E')
2862 /* Acquire the Text */
2865 /* Store the name */
2866 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2869 else if (buf[0] == 'E')
2871 /* Acquire the Text */
2874 /* Store the name */
2875 if (!add_name(&r_ptr->name, head, s)) return (7);
2878 /* Process 'D' for "Description" */
2879 else if (buf[0] == 'D')
2884 /* Acquire the text */
2889 /* Acquire the text */
2893 /* Store the text */
2894 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2897 /* Process 'G' for "Graphics" (one line only) */
2898 else if (buf[0] == 'G')
2904 if (buf[1] != ':') return (1);
2905 if (!buf[2]) return (1);
2906 if (buf[3] != ':') return (1);
2907 if (!buf[4]) return (1);
2909 /* Extract the char */
2912 /* Extract the attr */
2913 tmp = color_char_to_attr(buf[4]);
2916 if (tmp > 127) return (1);
2918 /* Save the values */
2919 r_ptr->d_char = sym;
2920 r_ptr->d_attr = tmp;
2923 /* Process 'I' for "Info" (one line only) */
2924 else if (buf[0] == 'I')
2926 int spd, hp1, hp2, aaf, ac, slp;
2928 /* Scan for the other values */
2929 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2930 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2932 /* Save the values */
2934 r_ptr->hdice = MAX(hp1, 1);
2935 r_ptr->hside = MAX(hp2, 1);
2941 /* Process 'W' for "More Info" (one line only) */
2942 else if (buf[0] == 'W')
2949 /* Scan for the values */
2950 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2951 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2953 /* Save the values */
2955 r_ptr->rarity = rar;
2958 r_ptr->next_exp = nextexp;
2959 r_ptr->next_r_idx = nextmon;
2962 /* Process 'R' for "Reinforcement" (up to six lines) */
2963 else if (buf[0] == 'R')
2966 /* Find the next empty blow slot (if any) */
2967 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
2969 /* Oops, no more slots */
2970 if (i == 6) return (1);
2972 /* Scan for the values */
2973 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2974 r_ptr->reinforce_id[i] = id;
2975 r_ptr->reinforce_dd[i] = dd;
2976 r_ptr->reinforce_ds[i] = ds;
2979 /* Process 'B' for "Blows" (up to four lines) */
2980 else if (buf[0] == 'B')
2984 /* Find the next empty blow slot (if any) */
2985 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2987 /* Oops, no more slots */
2988 if (i == 4) return (1);
2990 /* Analyze the first field */
2991 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2993 /* Terminate the field (if necessary) */
2994 if (*t == ':') *t++ = '\0';
2996 /* Analyze the method */
2997 for (n1 = 0; r_info_blow_method[n1]; n1++)
2999 if (streq(s, r_info_blow_method[n1])) break;
3002 /* Invalid method */
3003 if (!r_info_blow_method[n1]) return (1);
3005 /* Analyze the second field */
3006 for (s = t; *t && (*t != ':'); t++) /* loop */;
3008 /* Terminate the field (if necessary) */
3009 if (*t == ':') *t++ = '\0';
3011 /* Analyze effect */
3012 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3014 if (streq(s, r_info_blow_effect[n2])) break;
3017 /* Invalid effect */
3018 if (!r_info_blow_effect[n2]) return (1);
3020 /* Analyze the third field */
3021 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3023 /* Terminate the field (if necessary) */
3024 if (*t == 'd') *t++ = '\0';
3026 /* Save the method */
3027 r_ptr->blow[i].method = n1;
3029 /* Save the effect */
3030 r_ptr->blow[i].effect = n2;
3032 /* Extract the damage dice and sides */
3033 r_ptr->blow[i].d_dice = atoi(s);
3034 r_ptr->blow[i].d_side = atoi(t);
3037 /* Process 'F' for "Basic Flags" (multiple lines) */
3038 else if (buf[0] == 'F')
3040 /* Parse every entry */
3041 for (s = buf + 2; *s; )
3043 /* Find the end of this entry */
3044 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3046 /* Nuke and skip any dividers */
3050 while (*t == ' ' || *t == '|') t++;
3053 /* Parse this entry */
3054 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3056 /* Start the next entry */
3061 /* Process 'S' for "Spell Flags" (multiple lines) */
3062 else if (buf[0] == 'S')
3064 /* Parse every entry */
3065 for (s = buf + 2; *s; )
3067 /* Find the end of this entry */
3068 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3070 /* Nuke and skip any dividers */
3074 while ((*t == ' ') || (*t == '|')) t++;
3077 /* XXX XXX XXX Hack -- Read spell frequency */
3078 if (1 == sscanf(s, "1_IN_%d", &i))
3080 /* Extract a "frequency" */
3081 r_ptr->freq_spell = 100 / i;
3083 /* Start at next entry */
3090 /* Parse this entry */
3091 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3093 /* Start the next entry */
3108 * Grab one flag for a dungeon type from a textual string
3110 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3112 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3117 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3119 msg_format("Unknown dungeon type flag '%s'.", what);
3127 * Grab one (basic) flag in a monster_race from a textual string
3129 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3131 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3134 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3137 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3140 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3143 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3146 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3149 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3154 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3156 msg_format("Unknown monster flag '%s'.", what);
3164 * Grab one (spell) flag in a monster_race from a textual string
3166 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3168 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3171 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3174 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3179 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3181 msg_format("Unknown monster flag '%s'.", what);
3189 * Initialize the "d_info" array, by parsing an ascii "template" file
3191 errr parse_d_info(char *buf, header *head)
3198 static dungeon_info_type *d_ptr = NULL;
3201 /* Process 'N' for "New/Number/Name" */
3204 /* Find the colon before the name */
3205 s = my_strchr(buf+2, ':');
3207 /* Verify that colon */
3210 /* Nuke the colon, advance to the name */
3213 /* Paranoia -- require a name */
3214 if (!*s) return (1);
3219 /* Verify information */
3220 if (i < error_idx) return (4);
3222 /* Verify information */
3223 if (i >= head->info_num) return (2);
3225 /* Save the index */
3228 /* Point at the "info" */
3231 /* Store the name */
3232 if (!add_name(&d_ptr->name, head, s)) return (7);
3237 else if (buf[0] == 'E') return (0);
3239 else if (buf[0] == 'E')
3241 /* Acquire the Text */
3244 /* Store the name */
3245 if (!add_name(&d_ptr->name, head, s)) return (7);
3249 /* Process 'D' for "Description */
3250 else if (buf[0] == 'D')
3255 /* Acquire the text */
3260 /* Acquire the text */
3264 /* Store the text */
3265 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3268 /* Process 'W' for "More Info" (one line only) */
3269 else if (buf[0] == 'W')
3271 int min_lev, max_lev;
3273 int min_alloc, max_chance;
3274 int obj_good, obj_great;
3277 /* Scan for the values */
3278 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3279 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3281 /* Save the values */
3282 d_ptr->mindepth = min_lev;
3283 d_ptr->maxdepth = max_lev;
3284 d_ptr->min_plev = min_plev;
3286 d_ptr->min_m_alloc_level = min_alloc;
3287 d_ptr->max_m_alloc_chance = max_chance;
3288 d_ptr->obj_good = obj_good;
3289 d_ptr->obj_great = obj_great;
3294 /* Process 'P' for "Place Info" */
3295 else if (buf[0] == 'P')
3299 /* Scan for the values */
3300 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3302 /* Save the values */
3307 /* Process 'L' for "fLoor type" (one line only) */
3308 else if (buf[0] == 'L')
3312 /* Scan for the values */
3313 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3315 /* Save the values */
3316 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3318 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3319 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3321 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3323 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3326 /* Process 'A' for "wAll type" (one line only) */
3327 else if (buf[0] == 'A')
3331 /* Scan for the values */
3332 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3334 /* Save the values */
3335 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3337 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3338 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3340 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3343 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3344 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3346 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3347 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3349 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3350 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3352 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3353 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3356 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3357 else if (buf[0] == 'F')
3359 int artif = 0, monst = 0;
3361 /* Parse every entry */
3362 for (s = buf + 2; *s; )
3364 /* Find the end of this entry */
3365 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3367 /* Nuke and skip any dividers */
3371 while (*t == ' ' || *t == '|') t++;
3374 /* XXX XXX XXX Hack -- Read Final Artifact */
3375 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3377 /* Extract a "Final Artifact" */
3378 d_ptr->final_artifact = artif;
3380 /* Start at next entry */
3387 /* XXX XXX XXX Hack -- Read Final Object */
3388 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3390 /* Extract a "Final Artifact" */
3391 d_ptr->final_object = artif;
3393 /* Start at next entry */
3400 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3401 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3403 /* Extract a "Artifact Guardian" */
3404 d_ptr->final_guardian = monst;
3406 /* Start at next entry */
3413 /* XXX XXX XXX Hack -- Read Special Percentage */
3414 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3416 /* Extract a "Special %" */
3417 d_ptr->special_div = monst;
3419 /* Start at next entry */
3426 /* Parse this entry */
3427 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3429 /* Start the next entry */
3434 /* Process 'M' for "Basic Flags" (multiple lines) */
3435 else if (buf[0] == 'M')
3437 /* Parse every entry */
3438 for (s = buf + 2; *s; )
3440 /* Find the end of this entry */
3441 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3443 /* Nuke and skip any dividers */
3447 while (*t == ' ' || *t == '|') t++;
3450 /* Hack -- Read monster symbols */
3451 if (!strncmp(s, "R_CHAR_", 7))
3453 /* Skip "R_CHAR_" */
3457 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3459 /* Start at next entry */
3466 /* Parse this entry */
3467 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3469 /* Start the next entry */
3474 /* Process 'S' for "Spell Flags" (multiple lines) */
3475 else if (buf[0] == 'S')
3477 /* Parse every entry */
3478 for (s = buf + 2; *s; )
3480 /* Find the end of this entry */
3481 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3483 /* Nuke and skip any dividers */
3487 while ((*t == ' ') || (*t == '|')) t++;
3490 /* XXX XXX XXX Hack -- Read spell frequency */
3491 if (1 == sscanf(s, "1_IN_%d", &i))
3493 /* Start at next entry */
3500 /* Parse this entry */
3501 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3503 /* Start the next entry */
3516 #else /* ALLOW_TEMPLATES */
3522 #endif /* ALLOW_TEMPLATES */
3525 /* Random dungeon grid effects */
3526 #define RANDOM_NONE 0x00000000
3527 #define RANDOM_FEATURE 0x00000001
3528 #define RANDOM_MONSTER 0x00000002
3529 #define RANDOM_OBJECT 0x00000004
3530 #define RANDOM_EGO 0x00000008
3531 #define RANDOM_ARTIFACT 0x00000010
3532 #define RANDOM_TRAP 0x00000020
3535 typedef struct dungeon_grid dungeon_grid;
3539 int feature; /* Terrain feature */
3540 int monster; /* Monster */
3541 int object; /* Object */
3542 int ego; /* Ego-Item */
3543 int artifact; /* Artifact */
3544 int trap; /* Trap */
3545 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3546 int special; /* Reserved for special terrain info */
3547 int random; /* Number of the random effect */
3551 static dungeon_grid letter[255];
3555 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3557 static errr parse_line_feature(char *buf)
3563 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3565 /* Tokenize the line */
3566 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3568 /* Letter to assign */
3569 int index = zz[0][0];
3571 /* Reset the info for the letter */
3572 letter[index].feature = feat_none;
3573 letter[index].monster = 0;
3574 letter[index].object = 0;
3575 letter[index].ego = 0;
3576 letter[index].artifact = 0;
3577 letter[index].trap = feat_none;
3578 letter[index].cave_info = 0;
3579 letter[index].special = 0;
3580 letter[index].random = RANDOM_NONE;
3586 letter[index].special = atoi(zz[8]);
3590 if ((zz[7][0] == '*') && !zz[7][1])
3592 letter[index].random |= RANDOM_TRAP;
3596 letter[index].trap = f_tag_to_index(zz[7]);
3597 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3602 if (zz[6][0] == '*')
3604 letter[index].random |= RANDOM_ARTIFACT;
3605 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3607 else if (zz[6][0] == '!')
3609 if (p_ptr->inside_quest)
3611 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3616 letter[index].artifact = atoi(zz[6]);
3621 if (zz[5][0] == '*')
3623 letter[index].random |= RANDOM_EGO;
3624 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3628 letter[index].ego = atoi(zz[5]);
3633 if (zz[4][0] == '*')
3635 letter[index].random |= RANDOM_OBJECT;
3636 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3638 else if (zz[4][0] == '!')
3640 if (p_ptr->inside_quest)
3642 int a_idx = quest[p_ptr->inside_quest].k_idx;
3645 artifact_type *a_ptr = &a_info[a_idx];
3646 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3648 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3655 letter[index].object = atoi(zz[4]);
3660 if (zz[3][0] == '*')
3662 letter[index].random |= RANDOM_MONSTER;
3663 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3665 else if (zz[3][0] == 'c')
3667 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3668 letter[index].monster = - atoi(zz[3] + 1);
3672 letter[index].monster = atoi(zz[3]);
3677 letter[index].cave_info = atoi(zz[2]);
3681 if ((zz[1][0] == '*') && !zz[1][1])
3683 letter[index].random |= RANDOM_FEATURE;
3687 letter[index].feature = f_tag_to_index(zz[1]);
3688 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3701 * Process "B:<Index>:<Command>:..." -- Building definition
3703 static errr parse_line_building(char *buf)
3719 /* Get the building number */
3722 /* Find the colon after the building number */
3723 s = my_strchr(s, ':');
3725 /* Verify that colon */
3728 /* Nuke the colon, advance to the sub-index */
3731 /* Paranoia -- require a sub-index */
3732 if (!*s) return (1);
3734 /* Building definition sub-index */
3737 /* Building name, owner, race */
3740 if (tokenize(s + 2, 3, zz, 0) == 3)
3742 /* Name of the building */
3743 strcpy(building[index].name, zz[0]);
3745 /* Name of the owner */
3746 strcpy(building[index].owner_name, zz[1]);
3748 /* Race of the owner */
3749 strcpy(building[index].owner_race, zz[2]);
3754 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3757 /* Building Action */
3760 if (tokenize(s + 2, 8, zz, 0) >= 7)
3762 /* Index of the action */
3763 int action_index = atoi(zz[0]);
3765 /* Name of the action */
3766 strcpy(building[index].act_names[action_index], zz[1]);
3768 /* Cost of the action for members */
3769 building[index].member_costs[action_index] = atoi(zz[2]);
3771 /* Cost of the action for non-members */
3772 building[index].other_costs[action_index] = atoi(zz[3]);
3774 /* Letter assigned to the action */
3775 building[index].letters[action_index] = zz[4][0];
3778 building[index].actions[action_index] = atoi(zz[5]);
3780 /* Action restriction */
3781 building[index].action_restr[action_index] = atoi(zz[6]);
3786 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3789 /* Building Classes */
3792 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3794 for (i = 0; i < MAX_CLASS; i++)
3796 building[index].member_class[i] = atoi(zz[i]);
3802 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3805 /* Building Races */
3808 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3810 for (i = 0; i < MAX_RACES; i++)
3812 building[index].member_race[i] = atoi(zz[i]);
3818 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3821 /* Building Realms */
3824 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3826 for (i = 0; i < MAX_MAGIC; i++)
3828 building[index].member_realm[i+1] = atoi(zz[i]);
3834 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3839 /* Ignore scripts */
3845 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3854 * Place the object j_ptr to a grid
3856 static void drop_here(object_type *j_ptr, int y, int x)
3858 cave_type *c_ptr = &cave[y][x];
3861 /* Get new object */
3862 s16b o_idx = o_pop();
3864 /* Access new object */
3865 o_ptr = &o_list[o_idx];
3867 /* Structure copy */
3868 object_copy(o_ptr, j_ptr);
3876 o_ptr->held_m_idx = 0;
3879 o_ptr->next_o_idx = c_ptr->o_idx;
3881 /* Place the object */
3882 c_ptr->o_idx = o_idx;
3887 * Parse a sub-file of the "extra info"
3889 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3896 /* Skip "empty" lines */
3897 if (!buf[0]) return (0);
3899 /* Skip "blank" lines */
3900 if (iswspace(buf[0])) return (0);
3903 if (buf[0] == '#') return (0);
3905 /* Require "?:*" format */
3906 if (buf[1] != ':') return (1);
3909 /* Process "%:<fname>" */
3912 /* Attempt to Process the given file */
3913 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3916 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3919 return parse_line_feature(buf);
3922 /* Process "D:<dungeon>" -- info for the cave grids */
3923 else if (buf[0] == 'D')
3925 object_type object_type_body;
3927 /* Acquire the text */
3930 /* Length of the text */
3931 int len = strlen(s);
3933 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3935 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3937 /* Access the grid */
3938 cave_type *c_ptr = &cave[*y][*x];
3942 int object_index = letter[idx].object;
3943 int monster_index = letter[idx].monster;
3944 int random = letter[idx].random;
3945 int artifact_index = letter[idx].artifact;
3947 /* Lay down a floor */
3948 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3950 /* Only the features */
3951 if (init_flags & INIT_ONLY_FEATURES) continue;
3954 c_ptr->info = letter[idx].cave_info;
3956 /* Create a monster */
3957 if (random & RANDOM_MONSTER)
3959 monster_level = base_level + monster_index;
3961 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3963 monster_level = base_level;
3965 else if (monster_index)
3967 int old_cur_num, old_max_num;
3970 if (monster_index < 0)
3972 monster_index = -monster_index;
3975 old_cur_num = r_info[monster_index].cur_num;
3976 old_max_num = r_info[monster_index].max_num;
3978 /* Make alive again */
3979 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3981 r_info[monster_index].cur_num = 0;
3982 r_info[monster_index].max_num = 1;
3985 /* Make alive again */
3986 /* Hack -- Non-unique Nazguls are semi-unique */
3987 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3989 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3991 r_info[monster_index].max_num++;
3996 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4000 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4002 /* Make alive again for real unique monster */
4003 r_info[monster_index].cur_num = old_cur_num;
4004 r_info[monster_index].max_num = old_max_num;
4008 /* Object (and possible trap) */
4009 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4011 object_level = base_level + object_index;
4014 * Random trap and random treasure defined
4015 * 25% chance for trap and 75% chance for object
4017 if (randint0(100) < 75)
4019 place_object(*y, *x, 0L);
4026 object_level = base_level;
4028 else if (random & RANDOM_OBJECT)
4030 object_level = base_level + object_index;
4032 /* Create an out of deep object */
4033 if (randint0(100) < 75)
4034 place_object(*y, *x, 0L);
4035 else if (randint0(100) < 80)
4036 place_object(*y, *x, AM_GOOD);
4038 place_object(*y, *x, AM_GOOD | AM_GREAT);
4040 object_level = base_level;
4043 else if (random & RANDOM_TRAP)
4047 /* Hidden trap (or door) */
4048 else if (letter[idx].trap)
4050 c_ptr->mimic = c_ptr->feat;
4051 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4053 else if (object_index)
4055 /* Get local object */
4056 object_type *o_ptr = &object_type_body;
4058 /* Create the item */
4059 object_prep(o_ptr, object_index);
4061 if (o_ptr->tval == TV_GOLD)
4063 coin_type = object_index - OBJ_GOLD_LIST;
4068 /* Apply magic (no messages, no artifacts) */
4069 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4071 drop_here(o_ptr, *y, *x);
4077 if (a_info[artifact_index].cur_num)
4079 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4081 object_type *q_ptr = &forge;
4083 object_prep(q_ptr, k_idx);
4085 /* Drop it in the dungeon */
4086 drop_here(q_ptr, *y, *x);
4090 /* Create the artifact */
4091 if (create_named_art(artifact_index, *y, *x))
4092 a_info[artifact_index].cur_num = 1;
4096 /* Terrain special */
4097 c_ptr->special = letter[idx].special;
4105 /* Process "Q:<number>:<command>:... -- quest info */
4106 else if (buf[0] == 'Q')
4113 num = tokenize(buf + 2, 33, zz, 0);
4117 num = tokenize(buf + 3, 33, zz, 0);
4120 /* Have we enough parameters? */
4121 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4124 q_ptr = &(quest[atoi(zz[0])]);
4126 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4127 if (zz[1][0] == 'Q')
4129 if (init_flags & INIT_ASSIGN)
4131 monster_race *r_ptr;
4132 artifact_type *a_ptr;
4134 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4136 q_ptr->type = atoi(zz[2]);
4137 q_ptr->num_mon = atoi(zz[3]);
4138 q_ptr->cur_num = atoi(zz[4]);
4139 q_ptr->max_num = atoi(zz[5]);
4140 q_ptr->level = atoi(zz[6]);
4141 q_ptr->r_idx = atoi(zz[7]);
4142 q_ptr->k_idx = atoi(zz[8]);
4143 q_ptr->dungeon = atoi(zz[9]);
4146 q_ptr->flags = atoi(zz[10]);
4148 r_ptr = &r_info[q_ptr->r_idx];
4149 if (r_ptr->flags1 & RF1_UNIQUE)
4150 r_ptr->flags1 |= RF1_QUESTOR;
4152 a_ptr = &a_info[q_ptr->k_idx];
4153 a_ptr->gen_flags |= TRG_QUESTITEM;
4158 else if (zz[1][0] == 'R')
4160 if (init_flags & INIT_ASSIGN)
4165 for (idx = 2; idx < num; idx++)
4167 int a_idx = atoi(zz[idx]);
4168 if (a_idx < 1) continue;
4169 if (a_info[a_idx].cur_num > 0) continue;
4171 if (one_in_(count)) reward_idx = a_idx;
4176 /* Set quest's rewarding artifact */
4177 q_ptr->k_idx = reward_idx;
4178 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4182 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4183 q_ptr->type = QUEST_TYPE_KILL_ALL;
4190 /* Process "Q:<q_index>:N:<name>" -- quest name */
4191 else if (zz[1][0] == 'N')
4193 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4195 strcpy(q_ptr->name, zz[2]);
4201 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4202 else if (zz[1][0] == 'T')
4204 if (init_flags & INIT_SHOW_TEXT)
4206 strcpy(quest_text[quest_text_line], zz[2]);
4214 /* Process "W:<command>: ..." -- info for the wilderness */
4215 else if (buf[0] == 'W')
4217 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4220 /* Process "P:<y>:<x>" -- player position */
4221 else if (buf[0] == 'P')
4223 if (init_flags & INIT_CREATE_DUNGEON)
4225 if (tokenize(buf + 2, 2, zz, 0) == 2)
4227 int panels_x, panels_y;
4229 /* Hack - Set the dungeon size */
4230 panels_y = (*y / SCREEN_HGT);
4231 if (*y % SCREEN_HGT) panels_y++;
4232 cur_hgt = panels_y * SCREEN_HGT;
4234 panels_x = (*x / SCREEN_WID);
4235 if (*x % SCREEN_WID) panels_x++;
4236 cur_wid = panels_x * SCREEN_WID;
4238 /* Assume illegal panel */
4239 panel_row_min = cur_hgt;
4240 panel_col_min = cur_wid;
4242 /* Place player in a quest level */
4243 if (p_ptr->inside_quest)
4247 /* Delete the monster (if any) */
4248 delete_monster(py, px);
4256 /* Place player in the town */
4257 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4259 p_ptr->oldpy = atoi(zz[0]);
4260 p_ptr->oldpx = atoi(zz[1]);
4268 /* Process "B:<Index>:<Command>:..." -- Building definition */
4269 else if (buf[0] == 'B')
4271 return parse_line_building(buf);
4274 /* Process "M:<type>:<maximum>" -- set maximum values */
4275 else if (buf[0] == 'M')
4277 if (tokenize(buf+2, 2, zz, 0) == 2)
4280 if (zz[0][0] == 'T')
4282 max_towns = atoi(zz[1]);
4285 /* Maximum quests */
4286 else if (zz[0][0] == 'Q')
4288 max_quests = atoi(zz[1]);
4292 else if (zz[0][0] == 'R')
4294 max_r_idx = atoi(zz[1]);
4298 else if (zz[0][0] == 'K')
4300 max_k_idx = atoi(zz[1]);
4304 else if (zz[0][0] == 'V')
4306 max_v_idx = atoi(zz[1]);
4310 else if (zz[0][0] == 'F')
4312 max_f_idx = atoi(zz[1]);
4316 else if (zz[0][0] == 'A')
4318 max_a_idx = atoi(zz[1]);
4322 else if (zz[0][0] == 'E')
4324 max_e_idx = atoi(zz[1]);
4328 else if (zz[0][0] == 'D')
4330 max_d_idx = atoi(zz[1]);
4334 else if (zz[0][0] == 'O')
4336 max_o_idx = atoi(zz[1]);
4340 else if (zz[0][0] == 'M')
4342 max_m_idx = atoi(zz[1]);
4345 /* Wilderness size */
4346 else if (zz[0][0] == 'W')
4348 /* Maximum wild_x_size */
4349 if (zz[0][1] == 'X')
4350 max_wild_x = atoi(zz[1]);
4351 /* Maximum wild_y_size */
4352 if (zz[0][1] == 'Y')
4353 max_wild_y = atoi(zz[1]);
4367 static cptr variant = "ZANGBAND";
4371 * Helper function for "process_dungeon_file()"
4373 static cptr process_dungeon_file_expr(char **sp, char *fp)
4389 while (iswspace(*s)) s++;
4407 t = process_dungeon_file_expr(&s, &f);
4416 else if (streq(t, "IOR"))
4419 while (*s && (f != b2))
4421 t = process_dungeon_file_expr(&s, &f);
4422 if (*t && !streq(t, "0")) v = "1";
4427 else if (streq(t, "AND"))
4430 while (*s && (f != b2))
4432 t = process_dungeon_file_expr(&s, &f);
4433 if (*t && streq(t, "0")) v = "0";
4438 else if (streq(t, "NOT"))
4441 while (*s && (f != b2))
4443 t = process_dungeon_file_expr(&s, &f);
4444 if (*t && streq(t, "1")) v = "0";
4449 else if (streq(t, "EQU"))
4452 if (*s && (f != b2))
4454 t = process_dungeon_file_expr(&s, &f);
4456 while (*s && (f != b2))
4458 p = process_dungeon_file_expr(&s, &f);
4459 if (streq(t, p)) v = "1";
4464 else if (streq(t, "LEQ"))
4467 if (*s && (f != b2))
4469 t = process_dungeon_file_expr(&s, &f);
4471 while (*s && (f != b2))
4474 t = process_dungeon_file_expr(&s, &f);
4475 if (*t && atoi(p) > atoi(t)) v = "0";
4480 else if (streq(t, "GEQ"))
4483 if (*s && (f != b2))
4485 t = process_dungeon_file_expr(&s, &f);
4487 while (*s && (f != b2))
4490 t = process_dungeon_file_expr(&s, &f);
4492 /* Compare two numbers instead of string */
4493 if (*t && atoi(p) < atoi(t)) v = "0";
4500 while (*s && (f != b2))
4502 t = process_dungeon_file_expr(&s, &f);
4507 if (f != b2) v = "?x?x?";
4509 /* Extract final and Terminate */
4510 if ((f = *s) != '\0') *s++ = '\0';
4516 /* Accept all printables except spaces and brackets */
4518 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4520 if (iskanji(*s)) s++;
4524 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4527 /* Extract final and Terminate */
4528 if ((f = *s) != '\0') *s++ = '\0';
4534 if (streq(b+1, "SYS"))
4540 else if (streq(b+1, "GRAF"))
4545 else if (streq(b+1, "MONOCHROME"))
4554 else if (streq(b+1, "RACE"))
4557 v = rp_ptr->E_title;
4564 else if (streq(b+1, "CLASS"))
4567 v = cp_ptr->E_title;
4574 else if (streq(b+1, "REALM1"))
4577 v = E_realm_names[p_ptr->realm1];
4579 v = realm_names[p_ptr->realm1];
4584 else if (streq(b+1, "REALM2"))
4587 v = E_realm_names[p_ptr->realm2];
4589 v = realm_names[p_ptr->realm2];
4594 else if (streq(b+1, "PLAYER"))
4596 static char tmp_player_name[32];
4598 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4608 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4611 v = tmp_player_name;
4615 else if (streq(b+1, "TOWN"))
4617 sprintf(tmp, "%d", p_ptr->town_num);
4622 else if (streq(b+1, "LEVEL"))
4624 sprintf(tmp, "%d", p_ptr->lev);
4628 /* Current quest number */
4629 else if (streq(b+1, "QUEST_NUMBER"))
4631 sprintf(tmp, "%d", p_ptr->inside_quest);
4635 /* Number of last quest */
4636 else if (streq(b+1, "LEAVING_QUEST"))
4638 sprintf(tmp, "%d", leaving_quest);
4643 else if (prefix(b+1, "QUEST_TYPE"))
4645 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4646 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4651 else if (prefix(b+1, "QUEST"))
4653 /* "QUEST" uses a special parameter to determine the number of the quest */
4654 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4659 else if (prefix(b+1, "RANDOM"))
4661 /* "RANDOM" uses a special parameter to determine the number of the quest */
4662 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4667 else if (streq(b+1, "VARIANT"))
4673 else if (streq(b+1, "WILDERNESS"))
4676 sprintf(tmp, "NONE");
4678 sprintf(tmp, "LITE");
4680 sprintf(tmp, "NORMAL");
4703 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4713 bool bypass = FALSE;
4715 int x = xmin, y = ymin;
4718 /* Build the filename */
4719 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4722 fp = my_fopen(buf, "r");
4725 if (!fp) return (-1);
4728 /* Process the file */
4729 while (0 == my_fgets(fp, buf, sizeof(buf)))
4735 /* Skip "empty" lines */
4736 if (!buf[0]) continue;
4738 /* Skip "blank" lines */
4739 if (iswspace(buf[0])) continue;
4742 if (buf[0] == '#') continue;
4745 /* Process "?:<expr>" */
4746 if ((buf[0] == '?') && (buf[1] == ':'))
4755 /* Parse the expr */
4756 v = process_dungeon_file_expr(&s, &f);
4759 bypass = (streq(v, "0") ? TRUE : FALSE);
4765 /* Apply conditionals */
4766 if (bypass) continue;
4768 /* Process the line */
4769 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4781 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4784 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4786 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4788 msg_format("Parsing '%s'.", buf);
4795 /* Close the file */
4805 void write_r_info_txt(void)
4807 int i, j, z, fc, bc;
4810 cptr flags[32 * 10];
4815 monster_race *r_ptr;
4817 monster_blow *b_ptr;
4819 FILE *fff = fopen("output.txt", "wt");
4827 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4829 fprintf(fff, "# Version stamp (required)\n\n");
4832 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4835 fprintf(fff, "##### The Player #####\n\n");
4837 for (z = -1; z < alloc_race_size; z++)
4839 /* Output the monsters in order */
4840 i = (z >= 0) ? alloc_race_table[z].index : 0;
4842 /* Acquire the monster */
4845 /* Ignore empty monsters */
4846 if (!strlen(r_name + r_ptr->name)) continue;
4848 /* Ignore useless monsters */
4849 if (i && !r_ptr->speed) continue;
4851 /* Write a note if necessary */
4852 if (i && (!r_ptr->level != !mode))
4857 fprintf(fff, "\n##### Town monsters #####\n\n");
4859 /* Note the dungeon */
4862 fprintf(fff, "\n##### Normal monsters #####\n\n");
4865 /* Record the change */
4866 mode = r_ptr->level;
4869 /* Acquire the flags */
4870 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4871 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4872 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4873 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4874 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4875 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4876 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4877 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4878 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4879 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4881 /* Write New/Number/Name */
4882 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4885 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4887 /* Write Information */
4888 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4889 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4891 /* Write more information */
4892 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4895 for(j = 0; j < 4; j++)
4897 b_ptr = &(r_ptr->blow[j]);
4899 /* Stop when done */
4900 if (!b_ptr->method) break;
4902 /* Write the blows */
4903 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4904 r_info_blow_effect[b_ptr->effect],
4905 b_ptr->d_dice, b_ptr->d_side);
4908 /* Extract the flags */
4909 for (fc = 0, j = 0; j < 32 * 3; j++)
4911 /* Check this flag */
4912 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4915 /* Extract the extra flags */
4916 for (j = 32 * 6; j < 32 * 10; j++)
4918 /* Check this flag */
4919 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4922 /* Write the flags */
4923 for (j = 0; j < fc;)
4927 /* Start the line */
4930 for (bc = 0; (bc < 60) && (j < fc); j++)
4934 /* Format the flag */
4935 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4937 /* Add it to the buffer */
4940 /* Note the length */
4944 /* Done with this line; write it */
4945 fprintf(fff, "%s\n", buf);
4948 /* Write Spells if applicable */
4949 if (r_ptr->freq_spell)
4951 /* Write the frequency */
4952 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4954 /* Extract the spell flags */
4955 for (fc = 0, j = 96; j < 192; j++)
4957 /* Check this flag */
4958 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4961 /* Write the flags */
4962 for (j = 0; j < fc;)
4966 /* Start the line */
4969 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4973 /* Format the flag */
4974 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4978 /* Note the length */
4985 /* Done with this line; write it */
4986 fprintf(fff, "%s\n", buf);
4990 /* Acquire the description */
4991 desc = r_text + r_ptr->text;
4992 dlen = strlen(desc);
4994 /* Write Description */
4995 for (j = 0; j < dlen;)
4999 /* Start the line */
5002 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
5010 /* Done with this line; write it */
5011 fprintf(fff, "%s\n", buf);
5014 /* Space between entries */