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[] =
856 static cptr d_info_flags1[] =
894 * Add a text to the text-storage and store offset to it.
896 * Returns FALSE when there isn't enough space available to store
899 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
901 /* Hack -- Verify space */
902 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
908 /* Advance and save the text index */
909 *offset = ++head->text_size;
912 /* Additional text */
913 else if (normal_text)
916 * If neither the end of the last line nor
917 * the beginning of current line is not a space,
918 * fill up a space as a correct separator of two words.
920 if (head->text_size > 0 &&
922 (*(head->text_ptr + head->text_size - 1) != ' ') &&
923 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
924 (buf[0] != ' ') && !iskanji(buf[0])
926 (*(head->text_ptr + head->text_size - 1) != ' ') &&
932 *(head->text_ptr + head->text_size) = ' ';
934 /* Advance the index */
939 /* Append chars to the text */
940 strcpy(head->text_ptr + head->text_size, buf);
942 /* Advance the index */
943 head->text_size += strlen(buf);
951 * Add a name to the name-storage and return an offset to it.
953 * Returns FALSE when there isn't enough space available to store
956 static bool add_name(u32b *offset, header *head, cptr buf)
958 /* Hack -- Verify space */
959 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
965 /* Advance and save the name index */
966 *offset = ++head->name_size;
969 /* Append chars to the names */
970 strcpy(head->name_ptr + head->name_size, buf);
972 /* Advance the index */
973 head->name_size += strlen(buf);
981 * Add a tag to the tag-storage and return an offset to it.
983 * Returns FALSE when there isn't enough space available to store
986 static bool add_tag(s16b *offset, header *head, cptr buf)
990 /* Search for an existing (fake) tag */
991 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
994 if (streq(&head->tag_ptr[i], buf)) break;
997 /* There was no existing tag */
998 if (i >= head->tag_size)
1000 /* Hack -- Verify space */
1001 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1004 /* Append chars to the tags */
1005 strcpy(head->tag_ptr + head->tag_size, buf);
1007 /* Point the new tag */
1010 /* Advance the index */
1011 head->tag_size += strlen(buf) + 1;
1014 /* Return offset of the tag */
1023 * Convert a "color letter" into an "actual" color
1024 * The colors are: dwsorgbuDWvyRGBU, as shown below
1026 byte color_char_to_attr(char c)
1030 case 'd': return (TERM_DARK);
1031 case 'w': return (TERM_WHITE);
1032 case 's': return (TERM_SLATE);
1033 case 'o': return (TERM_ORANGE);
1034 case 'r': return (TERM_RED);
1035 case 'g': return (TERM_GREEN);
1036 case 'b': return (TERM_BLUE);
1037 case 'u': return (TERM_UMBER);
1039 case 'D': return (TERM_L_DARK);
1040 case 'W': return (TERM_L_WHITE);
1041 case 'v': return (TERM_VIOLET);
1042 case 'y': return (TERM_YELLOW);
1043 case 'R': return (TERM_L_RED);
1044 case 'G': return (TERM_L_GREEN);
1045 case 'B': return (TERM_L_BLUE);
1046 case 'U': return (TERM_L_UMBER);
1054 /*** Initialize from ascii template files ***/
1058 * Initialize an "*_info" array, by parsing an ascii "template" file
1060 errr init_info_txt(FILE *fp, char *buf, header *head,
1061 parse_info_txt_func parse_info_txt_line)
1065 /* Just before the first record */
1068 /* Just before the first line */
1072 /* Prepare the "fake" stuff */
1073 head->name_size = 0;
1074 head->text_size = 0;
1078 while (0 == my_fgets(fp, buf, 1024))
1080 /* Advance the line number */
1083 /* Skip comments and blank lines */
1084 if (!buf[0] || (buf[0] == '#')) continue;
1086 /* Verify correct "colon" format */
1087 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1090 /* Hack -- Process 'V' for "Version" */
1097 /* Mega Hack -- Calculate Check Sum */
1098 if (buf[0] != 'N' && buf[0] != 'D')
1101 for (i = 0; buf[i]; i++)
1103 head->v_extra += (byte)buf[i];
1104 head->v_extra ^= (1 << (i % 8));
1108 /* Parse the line */
1109 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1114 /* Complete the "name" and "text" sizes */
1115 if (head->name_size) head->name_size++;
1116 if (head->text_size) head->text_size++;
1124 * Initialize the "v_info" array, by parsing an ascii "template" file
1126 errr parse_v_info(char *buf, header *head)
1132 static vault_type *v_ptr = NULL;
1134 /* Process 'N' for "New/Number/Name" */
1137 /* Find the colon before the name */
1138 s = my_strchr(buf+2, ':');
1140 /* Verify that colon */
1143 /* Nuke the colon, advance to the name */
1146 /* Paranoia -- require a name */
1147 if (!*s) return (1);
1152 /* Verify information */
1153 if (i <= error_idx) return (4);
1155 /* Verify information */
1156 if (i >= head->info_num) return (2);
1158 /* Save the index */
1161 /* Point at the "info" */
1164 /* Store the name */
1165 if (!add_name(&v_ptr->name, head, s)) return (7);
1168 /* There better be a current v_ptr */
1169 else if (!v_ptr) return (3);
1171 /* Process 'D' for "Description" */
1172 else if (buf[0] == 'D')
1174 /* Acquire the text */
1177 /* Store the text */
1178 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1181 /* Process 'X' for "Extra info" (one line only) */
1182 else if (buf[0] == 'X')
1184 int typ, rat, hgt, wid;
1186 /* Scan for the values */
1187 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1188 &typ, &rat, &hgt, &wid)) return (1);
1190 /* Save the values */
1207 * Initialize the "s_info" array, by parsing an ascii "template" file
1209 errr parse_s_info(char *buf, header *head)
1214 static skill_table *s_ptr = NULL;
1217 /* Process 'N' for "New/Number/Name" */
1223 /* Verify information */
1224 if (i <= error_idx) return (4);
1226 /* Verify information */
1227 if (i >= head->info_num) return (2);
1229 /* Save the index */
1232 /* Point at the "info" */
1236 /* There better be a current s_ptr */
1237 else if (!s_ptr) return (3);
1239 /* Process 'W' for "Weapon exp" */
1240 else if (buf[0] == 'W')
1242 int tval, sval, start, max;
1243 const s16b exp_conv_table[] =
1245 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1246 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1249 /* Scan for the values */
1250 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1251 &tval, &sval, &start, &max)) return (1);
1253 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1254 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1256 /* Save the values */
1257 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1258 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1261 /* Process 'S' for "Skill exp" */
1262 else if (buf[0] == 'S')
1264 int num, start, max;
1266 /* Scan for the values */
1267 if (3 != sscanf(buf+2, "%d:%d:%d",
1268 &num, &start, &max)) return (1);
1270 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1271 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1273 /* Save the values */
1274 s_ptr->s_start[num] = start;
1275 s_ptr->s_max[num] = max;
1288 * Initialize the "m_info" array, by parsing an ascii "template" file
1290 errr parse_m_info(char *buf, header *head)
1297 static player_magic *m_ptr = NULL;
1300 static int realm, magic_idx = 0, readable = 0;
1303 /* Process 'N' for "New/Number/Name" */
1309 /* Verify information */
1310 if (i <= error_idx) return (4);
1312 /* Verify information */
1313 if (i >= head->info_num) return (2);
1315 /* Save the index */
1318 /* Point at the "info" */
1322 /* There better be a current m_ptr */
1323 else if (!m_ptr) return (3);
1325 /* Process 'I' for "Info" (one line only) */
1326 else if (buf[0] == 'I')
1329 int xtra, type, first, weight;
1331 /* Find the colon before the name */
1332 s = my_strchr(buf+2, ':');
1334 /* Verify that colon */
1337 /* Nuke the colon, advance to the name */
1342 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1343 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1344 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1345 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1346 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1351 /* Find the colon before the name */
1352 s = my_strchr(s, ':');
1354 /* Verify that colon */
1357 /* Nuke the colon, advance to the name */
1360 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1361 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1362 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1363 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1364 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1365 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1369 /* Scan for the values */
1370 if (4 != sscanf(s, "%x:%d:%d:%d",
1371 (uint *)&xtra, &type, &first, &weight)) return (1);
1373 m_ptr->spell_xtra = xtra;
1374 m_ptr->spell_type = type;
1375 m_ptr->spell_first = first;
1376 m_ptr->spell_weight = weight;
1380 /* Process 'R' for "Realm" (one line only) */
1381 else if (buf[0] == 'R')
1383 /* Scan for the values */
1384 if (2 != sscanf(buf+2, "%d:%d",
1385 &realm, &readable)) return (1);
1390 else if (buf[0] == 'T')
1392 int level, mana, fail, exp;
1394 if (!readable) return (1);
1395 /* Scan for the values */
1396 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1397 &level, &mana, &fail, &exp)) return (1);
1399 m_ptr->info[realm][magic_idx].slevel = level;
1400 m_ptr->info[realm][magic_idx].smana = mana;
1401 m_ptr->info[realm][magic_idx].sfail = fail;
1402 m_ptr->info[realm][magic_idx].sexp = exp;
1416 * Grab one flag from a textual string
1418 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1423 for (i = 0; i < 32; i++)
1425 if (streq(what, names[i]))
1427 *flags |= (1L << i);
1437 * Grab one flag in an feature_type from a textual string
1439 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1444 for (i = 0; i < FF_FLAG_MAX; i++)
1446 if (streq(what, f_info_flags[i]))
1448 add_flag(f_ptr->flags, i);
1455 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1457 msg_format("Unknown feature flag '%s'.", what);
1461 return PARSE_ERROR_GENERIC;
1466 * Grab an action in an feature_type from a textual string
1468 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1473 for (i = 0; i < FF_FLAG_MAX; i++)
1475 if (streq(what, f_info_flags[i]))
1477 f_ptr->state[count].action = i;
1484 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1486 msg_format("Unknown feature action '%s'.", what);
1490 return PARSE_ERROR_GENERIC;
1495 * Initialize the "f_info" array, by parsing an ascii "template" file
1497 errr parse_f_info(char *buf, header *head)
1504 static feature_type *f_ptr = NULL;
1507 /* Process 'N' for "New/Number/Name" */
1510 /* Find the colon before the name */
1511 s = my_strchr(buf+2, ':');
1515 /* Nuke the colon, advance to the name */
1522 /* Verify information */
1523 if (i <= error_idx) return (4);
1525 /* Verify information */
1526 if (i >= head->info_num) return (2);
1528 /* Save the index */
1531 /* Point at the "info" */
1534 /* Tag name is given */
1538 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1541 /* Default "mimic" */
1544 /* Default "destroyed state" -- if not specified */
1545 f_ptr->destroyed = i;
1547 /* Default "states" */
1548 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1551 /* There better be a current f_ptr */
1552 else if (!f_ptr) return (3);
1555 else if (buf[0] == 'J')
1557 /* Store the name */
1558 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1561 else if (buf[0] == 'E')
1563 /* Ignore english name */
1566 else if (buf[0] == 'J')
1568 /* Ignore Japanese name */
1571 else if (buf[0] == 'E')
1573 /* Acquire the Text */
1576 /* Store the name */
1577 if (!add_name(&f_ptr->name, head, s)) return (7);
1582 /* Process 'M' for "Mimic" (one line only) */
1583 else if (buf[0] == 'M')
1587 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1589 /* Record a fake tag index */
1590 f_ptr->mimic = -offset;
1594 /* Process 'G' for "Graphics" (one line only) */
1595 else if (buf[0] == 'G')
1599 char char_tmp[F_LIT_MAX];
1602 if (buf[1] != ':') return (1);
1603 if (!buf[2]) return (1);
1604 if (buf[3] != ':') return (1);
1605 if (!buf[4]) return (1);
1607 /* Extract the char */
1608 char_tmp[F_LIT_STANDARD] = buf[2];
1610 /* Extract the color */
1611 s_attr = color_char_to_attr(buf[4]);
1614 if (s_attr > 127) return (1);
1616 /* Save the standard values */
1617 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1618 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1620 /* Is this feature supports lighting? */
1623 /* G:c:a:LIT (default) */
1624 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1626 /* G:c:a:lc:la:dc:da */
1627 if (!streq(buf + 6, "LIT"))
1629 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1631 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1632 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1633 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1634 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1636 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1638 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1641 /* Use default lighting */
1644 /* No lighting support */
1645 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1648 /* Extract the color */
1649 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1650 if (f_ptr->d_attr[j] > 127) return 1;
1653 f_ptr->d_char[j] = char_tmp[j];
1659 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1661 f_ptr->d_attr[j] = s_attr;
1662 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1668 /* Hack -- Process 'F' for flags */
1669 else if (buf[0] == 'F')
1671 /* Parse every entry textually */
1672 for (s = buf + 2; *s; )
1674 /* Find the end of this entry */
1675 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1677 /* Nuke and skip any dividers */
1681 while (*t == ' ' || *t == '|') t++;
1684 /* XXX XXX XXX Hack -- Read feature subtype */
1685 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1687 /* Extract a "subtype" */
1690 /* Start at next entry */
1697 /* XXX XXX XXX Hack -- Read feature power */
1698 if (1 == sscanf(s, "POWER_%d", &i))
1700 /* Extract a "power" */
1703 /* Start at next entry */
1710 /* Parse this entry */
1711 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1713 /* Start the next entry */
1718 /* Process 'W' for "More Info" (one line only) */
1719 else if (buf[0] == 'W')
1723 /* Scan for the value */
1724 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1726 /* Save the value */
1727 f_ptr->priority = priority;
1730 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1731 else if (buf[0] == 'K')
1735 /* Find the next empty state slot (if any) */
1736 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1738 /* Oops, no more slots */
1739 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1741 /* Analyze the first field */
1742 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1744 /* Terminate the field (if necessary) */
1745 if (*t == ':') *t++ = '\0';
1747 /* Is this default entry? */
1748 if (streq(s, "DESTROYED"))
1750 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1752 /* Record a fake tag index */
1753 f_ptr->destroyed = -offset;
1758 f_ptr->state[i].action = 0;
1760 /* Parse this entry */
1761 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1763 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1765 /* Record a fake tag index */
1766 f_ptr->state[i].result = -offset;
1779 * Convert a fake tag to a real feat index
1781 s16b f_tag_to_index(cptr str)
1785 /* Search for real index corresponding to this fake tag */
1786 for (i = 0; i < f_head.info_num; i++)
1788 if (streq(f_tag + f_info[i].tag, str))
1790 /* Return the index */
1801 * Search for real index corresponding to this fake tag
1803 static void search_real_feat(s16b *feat)
1807 /* Don't convert non-fake tag */
1808 if (*feat >= 0) return;
1810 /* Search for real index corresponding to this fake tag */
1811 for (i = 0; i < f_head.info_num; i++)
1813 if ((-(*feat)) == f_info[i].tag)
1815 /* Record real index */
1823 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1825 msg_format("%s is undefined.", f_tag + (-(*feat)));
1831 * Retouch fake tags of f_info
1833 void retouch_f_info(header *head)
1837 /* Convert fake tags to real feat indices */
1838 for (i = 0; i < head->info_num; i++)
1840 feature_type *f_ptr = &f_info[i];
1843 search_real_feat(&f_ptr->mimic);
1845 search_real_feat(&f_ptr->destroyed);
1847 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1853 * Grab one flag in an object_kind from a textual string
1855 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1860 for (i = 0; i < TR_FLAG_MAX; i++)
1862 if (streq(what, k_info_flags[i]))
1864 add_flag(k_ptr->flags, i);
1869 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1874 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1876 msg_format("Unknown object flag '%s'.", what);
1885 * Grab one activation index flag
1887 static byte grab_one_activation_flag(cptr what)
1893 if (activation_info[i].flag == NULL) break;
1895 if (streq(what, activation_info[i].flag))
1897 return activation_info[i].index;
1909 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
1911 msg_format("Unknown activation flag '%s'.", what);
1920 * Initialize the "k_info" array, by parsing an ascii "template" file
1922 errr parse_k_info(char *buf, header *head)
1929 static object_kind *k_ptr = NULL;
1932 /* Process 'N' for "New/Number/Name" */
1939 /* Find the colon before the name */
1940 s = my_strchr(buf+2, ':');
1942 /* Verify that colon */
1945 /* Nuke the colon, advance to the name */
1951 /* Verify information */
1952 if (i <= error_idx) return (4);
1954 /* Verify information */
1955 if (i >= head->info_num) return (2);
1957 /* Save the index */
1960 /* Point at the "info" */
1964 /* Paranoia -- require a name */
1965 if (!*s) return (1);
1967 /* Find the colon before the flavor */
1968 flavor = my_strchr(s, ':');
1970 /* Verify that colon */
1973 /* Nuke the colon, advance to the flavor */
1976 /* Store the flavor */
1977 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1980 /* Store the name */
1981 if (!add_name(&k_ptr->name, head, s)) return (7);
1985 /* There better be a current k_ptr */
1986 else if (!k_ptr) return (3);
1990 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1991 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1992 else if (buf[0] == 'E')
1997 else if (buf[0] == 'E')
2001 /* Acquire the name */
2004 /* Find the colon before the flavor */
2005 flavor = my_strchr(s, ':');
2007 /* Verify that colon */
2010 /* Nuke the colon, advance to the flavor */
2013 /* Store the flavor */
2014 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2017 /* Store the name */
2018 if (!add_name(&k_ptr->name, head, s)) return (7);
2022 /* Process 'D' for "Description" */
2023 else if (buf[0] == 'D')
2028 /* Acquire the text */
2033 /* Acquire the text */
2037 /* Store the text */
2038 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2041 /* Process 'G' for "Graphics" (one line only) */
2042 else if (buf[0] == 'G')
2048 if (buf[1] != ':') return (1);
2049 if (!buf[2]) return (1);
2050 if (buf[3] != ':') return (1);
2051 if (!buf[4]) return (1);
2053 /* Extract the char */
2056 /* Extract the attr */
2057 tmp = color_char_to_attr(buf[4]);
2060 if (tmp > 127) return (1);
2062 /* Save the values */
2063 k_ptr->d_attr = tmp;
2064 k_ptr->d_char = sym;
2067 /* Process 'I' for "Info" (one line only) */
2068 else if (buf[0] == 'I')
2070 int tval, sval, pval;
2072 /* Scan for the values */
2073 if (3 != sscanf(buf+2, "%d:%d:%d",
2074 &tval, &sval, &pval)) return (1);
2076 /* Save the values */
2082 /* Process 'W' for "More Info" (one line only) */
2083 else if (buf[0] == 'W')
2085 int level, extra, wgt;
2088 /* Scan for the values */
2089 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2090 &level, &extra, &wgt, &cost)) return (1);
2092 /* Save the values */
2093 k_ptr->level = level;
2094 k_ptr->extra = extra;
2095 k_ptr->weight = wgt;
2099 /* Process 'A' for "Allocation" (one line only) */
2100 else if (buf[0] == 'A')
2104 /* XXX XXX XXX Simply read each number following a colon */
2105 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2107 /* Default chance */
2108 k_ptr->chance[i] = 1;
2110 /* Store the attack damage index */
2111 k_ptr->locale[i] = atoi(s+1);
2113 /* Find the slash */
2114 t = my_strchr(s+1, '/');
2116 /* Find the next colon */
2117 s = my_strchr(s+1, ':');
2119 /* If the slash is "nearby", use it */
2120 if (t && (!s || t < s))
2122 int chance = atoi(t+1);
2123 if (chance > 0) k_ptr->chance[i] = chance;
2128 /* Hack -- Process 'P' for "power" and such */
2129 else if (buf[0] == 'P')
2131 int ac, hd1, hd2, th, td, ta;
2133 /* Scan for the values */
2134 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2135 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2145 /* Hack -- Process 'U' for activation index */
2146 else if (buf[0] == 'U')
2149 n = grab_one_activation_flag(buf + 2);
2160 /* Hack -- Process 'F' for flags */
2161 else if (buf[0] == 'F')
2163 /* Parse every entry textually */
2164 for (s = buf + 2; *s; )
2166 /* Find the end of this entry */
2167 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2169 /* Nuke and skip any dividers */
2173 while (*t == ' ' || *t == '|') t++;
2176 /* Parse this entry */
2177 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2179 /* Start the next entry */
2195 * Grab one flag in an artifact_type from a textual string
2197 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2202 for (i = 0; i < TR_FLAG_MAX; i++)
2204 if (streq(what, k_info_flags[i]))
2206 add_flag(a_ptr->flags, i);
2211 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2216 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2218 msg_format("Unknown artifact flag '%s'.", what);
2228 * Initialize the "a_info" array, by parsing an ascii "template" file
2230 errr parse_a_info(char *buf, header *head)
2237 static artifact_type *a_ptr = NULL;
2240 /* Process 'N' for "New/Number/Name" */
2243 /* Find the colon before the name */
2244 s = my_strchr(buf+2, ':');
2246 /* Verify that colon */
2249 /* Nuke the colon, advance to the name */
2252 /* Paranoia -- require a name */
2253 if (!*s) return (1);
2258 /* Verify information */
2259 if (i < error_idx) return (4);
2261 /* Verify information */
2262 if (i >= head->info_num) return (2);
2264 /* Save the index */
2267 /* Point at the "info" */
2270 /* Ignore everything */
2271 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2272 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2273 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2274 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2276 /* Store the name */
2277 if (!add_name(&a_ptr->name, head, s)) return (7);
2281 /* There better be a current a_ptr */
2282 else if (!a_ptr) return (3);
2286 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2287 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2288 else if (buf[0] == 'E')
2293 else if (buf[0] == 'E')
2295 /* Acquire the Text */
2298 /* Store the name */
2299 if (!add_name(&a_ptr->name, head, s)) return (7);
2303 /* Process 'D' for "Description" */
2304 else if (buf[0] == 'D')
2309 /* Acquire the text */
2314 /* Acquire the text */
2318 /* Store the text */
2319 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2323 /* Process 'I' for "Info" (one line only) */
2324 else if (buf[0] == 'I')
2326 int tval, sval, pval;
2328 /* Scan for the values */
2329 if (3 != sscanf(buf+2, "%d:%d:%d",
2330 &tval, &sval, &pval)) return (1);
2332 /* Save the values */
2338 /* Process 'W' for "More Info" (one line only) */
2339 else if (buf[0] == 'W')
2341 int level, rarity, wgt;
2344 /* Scan for the values */
2345 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2346 &level, &rarity, &wgt, &cost)) return (1);
2348 /* Save the values */
2349 a_ptr->level = level;
2350 a_ptr->rarity = rarity;
2351 a_ptr->weight = wgt;
2355 /* Hack -- Process 'P' for "power" and such */
2356 else if (buf[0] == 'P')
2358 int ac, hd1, hd2, th, td, ta;
2360 /* Scan for the values */
2361 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2362 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2372 /* Hack -- Process 'U' for activation index */
2373 else if (buf[0] == 'U')
2376 n = grab_one_activation_flag(buf + 2);
2387 /* Hack -- Process 'F' for flags */
2388 else if (buf[0] == 'F')
2390 /* Parse every entry textually */
2391 for (s = buf + 2; *s; )
2393 /* Find the end of this entry */
2394 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2396 /* Nuke and skip any dividers */
2400 while ((*t == ' ') || (*t == '|')) t++;
2403 /* Parse this entry */
2404 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2406 /* Start the next entry */
2422 * Grab one flag in a ego-item_type from a textual string
2424 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2429 for (i = 0; i < TR_FLAG_MAX; i++)
2431 if (streq(what, k_info_flags[i]))
2433 add_flag(e_ptr->flags, i);
2438 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2443 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2445 msg_format("Unknown ego-item flag '%s'.", what);
2457 * Initialize the "e_info" array, by parsing an ascii "template" file
2459 errr parse_e_info(char *buf, header *head)
2466 static ego_item_type *e_ptr = NULL;
2469 /* Just before the first record */
2472 /* Just before the first line */
2476 /* Process 'N' for "New/Number/Name" */
2479 /* Find the colon before the name */
2480 s = my_strchr(buf+2, ':');
2482 /* Verify that colon */
2485 /* Nuke the colon, advance to the name */
2488 /* Paranoia -- require a name */
2489 if (!*s) return (1);
2494 /* Verify information */
2495 if (i < error_idx) return (4);
2497 /* Verify information */
2498 if (i >= head->info_num) return (2);
2500 /* Save the index */
2503 /* Point at the "info" */
2506 /* Store the name */
2507 if (!add_name(&e_ptr->name, head, s)) return (7);
2511 /* There better be a current e_ptr */
2512 else if (!e_ptr) return (3);
2516 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2517 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2518 else if (buf[0] == 'E')
2523 else if (buf[0] == 'E')
2525 /* Acquire the Text */
2528 /* Store the name */
2529 if (!add_name(&e_ptr->name, head, s)) return (7);
2534 /* Process 'D' for "Description" */
2535 else if (buf[0] == 'D')
2537 /* Acquire the text */
2540 /* Store the text */
2541 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2546 /* Process 'X' for "Xtra" (one line only) */
2547 else if (buf[0] == 'X')
2551 /* Scan for the values */
2552 if (2 != sscanf(buf+2, "%d:%d",
2553 &slot, &rating)) return (1);
2555 /* Save the values */
2557 e_ptr->rating = rating;
2560 /* Process 'W' for "More Info" (one line only) */
2561 else if (buf[0] == 'W')
2563 int level, rarity, pad2;
2566 /* Scan for the values */
2567 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2568 &level, &rarity, &pad2, &cost)) return (1);
2570 /* Save the values */
2571 e_ptr->level = level;
2572 e_ptr->rarity = rarity;
2573 /* e_ptr->weight = wgt; */
2577 /* Hack -- Process 'C' for "creation" */
2578 else if (buf[0] == 'C')
2582 /* Scan for the values */
2583 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2584 &th, &td, &ta, &pv)) return (1);
2586 e_ptr->max_to_h = th;
2587 e_ptr->max_to_d = td;
2588 e_ptr->max_to_a = ta;
2589 e_ptr->max_pval = pv;
2592 /* Hack -- Process 'U' for activation index */
2593 else if (buf[0] == 'U')
2596 n = grab_one_activation_flag(buf + 2);
2607 /* Hack -- Process 'F' for flags */
2608 else if (buf[0] == 'F')
2610 /* Parse every entry textually */
2611 for (s = buf + 2; *s; )
2613 /* Find the end of this entry */
2614 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2616 /* Nuke and skip any dividers */
2620 while ((*t == ' ') || (*t == '|')) t++;
2623 /* Parse this entry */
2624 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2626 /* Start the next entry */
2640 * Grab one (basic) flag in a monster_race from a textual string
2642 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2644 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2647 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2650 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2653 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2656 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2659 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2662 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2667 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2669 msg_format("Unknown monster flag '%s'.", what);
2679 * Grab one (spell) flag in a monster_race from a textual string
2681 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2683 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2686 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2689 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2694 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2696 msg_format("Unknown monster flag '%s'.", what);
2708 * Initialize the "r_info" array, by parsing an ascii "template" file
2710 errr parse_r_info(char *buf, header *head)
2717 static monster_race *r_ptr = NULL;
2720 /* Process 'N' for "New/Number/Name" */
2723 /* Find the colon before the name */
2724 s = my_strchr(buf+2, ':');
2726 /* Verify that colon */
2729 /* Nuke the colon, advance to the name */
2732 /* Paranoia -- require a name */
2733 if (!*s) return (1);
2738 /* Verify information */
2739 if (i < error_idx) return (4);
2741 /* Verify information */
2742 if (i >= head->info_num) return (2);
2744 /* Save the index */
2747 /* Point at the "info" */
2750 /* Store the name */
2751 if (!add_name(&r_ptr->name, head, s)) return (7);
2755 /* There better be a current r_ptr */
2756 else if (!r_ptr) return (3);
2760 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2761 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2762 else if (buf[0] == 'E')
2764 /* Acquire the Text */
2767 /* Store the name */
2768 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2771 else if (buf[0] == 'E')
2773 /* Acquire the Text */
2776 /* Store the name */
2777 if (!add_name(&r_ptr->name, head, s)) return (7);
2780 /* Process 'D' for "Description" */
2781 else if (buf[0] == 'D')
2786 /* Acquire the text */
2791 /* Acquire the text */
2795 /* Store the text */
2796 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2799 /* Process 'G' for "Graphics" (one line only) */
2800 else if (buf[0] == 'G')
2806 if (buf[1] != ':') return (1);
2807 if (!buf[2]) return (1);
2808 if (buf[3] != ':') return (1);
2809 if (!buf[4]) return (1);
2811 /* Extract the char */
2814 /* Extract the attr */
2815 tmp = color_char_to_attr(buf[4]);
2818 if (tmp > 127) return (1);
2820 /* Save the values */
2821 r_ptr->d_char = sym;
2822 r_ptr->d_attr = tmp;
2825 /* Process 'I' for "Info" (one line only) */
2826 else if (buf[0] == 'I')
2828 int spd, hp1, hp2, aaf, ac, slp;
2830 /* Scan for the other values */
2831 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2832 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2834 /* Save the values */
2836 r_ptr->hdice = MAX(hp1, 1);
2837 r_ptr->hside = MAX(hp2, 1);
2843 /* Process 'W' for "More Info" (one line only) */
2844 else if (buf[0] == 'W')
2851 /* Scan for the values */
2852 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2853 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2855 /* Save the values */
2857 r_ptr->rarity = rar;
2860 r_ptr->next_exp = nextexp;
2861 r_ptr->next_r_idx = nextmon;
2864 /* Process 'R' for "Reinforcement" (up to six lines) */
2865 else if (buf[0] == 'R')
2868 /* Find the next empty blow slot (if any) */
2869 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
2871 /* Oops, no more slots */
2872 if (i == 6) return (1);
2874 /* Scan for the values */
2875 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2876 r_ptr->reinforce_id[i] = id;
2877 r_ptr->reinforce_dd[i] = dd;
2878 r_ptr->reinforce_ds[i] = ds;
2881 /* Process 'B' for "Blows" (up to four lines) */
2882 else if (buf[0] == 'B')
2886 /* Find the next empty blow slot (if any) */
2887 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2889 /* Oops, no more slots */
2890 if (i == 4) return (1);
2892 /* Analyze the first field */
2893 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2895 /* Terminate the field (if necessary) */
2896 if (*t == ':') *t++ = '\0';
2898 /* Analyze the method */
2899 for (n1 = 0; r_info_blow_method[n1]; n1++)
2901 if (streq(s, r_info_blow_method[n1])) break;
2904 /* Invalid method */
2905 if (!r_info_blow_method[n1]) return (1);
2907 /* Analyze the second field */
2908 for (s = t; *t && (*t != ':'); t++) /* loop */;
2910 /* Terminate the field (if necessary) */
2911 if (*t == ':') *t++ = '\0';
2913 /* Analyze effect */
2914 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2916 if (streq(s, r_info_blow_effect[n2])) break;
2919 /* Invalid effect */
2920 if (!r_info_blow_effect[n2]) return (1);
2922 /* Analyze the third field */
2923 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2925 /* Terminate the field (if necessary) */
2926 if (*t == 'd') *t++ = '\0';
2928 /* Save the method */
2929 r_ptr->blow[i].method = n1;
2931 /* Save the effect */
2932 r_ptr->blow[i].effect = n2;
2934 /* Extract the damage dice and sides */
2935 r_ptr->blow[i].d_dice = atoi(s);
2936 r_ptr->blow[i].d_side = atoi(t);
2939 /* Process 'F' for "Basic Flags" (multiple lines) */
2940 else if (buf[0] == 'F')
2942 /* Parse every entry */
2943 for (s = buf + 2; *s; )
2945 /* Find the end of this entry */
2946 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2948 /* Nuke and skip any dividers */
2952 while (*t == ' ' || *t == '|') t++;
2955 /* Parse this entry */
2956 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2958 /* Start the next entry */
2963 /* Process 'S' for "Spell Flags" (multiple lines) */
2964 else if (buf[0] == 'S')
2966 /* Parse every entry */
2967 for (s = buf + 2; *s; )
2969 /* Find the end of this entry */
2970 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2972 /* Nuke and skip any dividers */
2976 while ((*t == ' ') || (*t == '|')) t++;
2979 /* XXX XXX XXX Hack -- Read spell frequency */
2980 if (1 == sscanf(s, "1_IN_%d", &i))
2982 /* Extract a "frequency" */
2983 r_ptr->freq_spell = 100 / i;
2985 /* Start at next entry */
2992 /* Parse this entry */
2993 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2995 /* Start the next entry */
3010 * Grab one flag for a dungeon type from a textual string
3012 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3014 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3019 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3021 msg_format("Unknown dungeon type flag '%s'.", what);
3029 * Grab one (basic) flag in a monster_race from a textual string
3031 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3033 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3036 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3039 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3042 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3045 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3048 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3051 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3056 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3058 msg_format("Unknown monster flag '%s'.", what);
3066 * Grab one (spell) flag in a monster_race from a textual string
3068 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3070 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3073 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3076 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3081 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3083 msg_format("Unknown monster flag '%s'.", what);
3091 * Initialize the "d_info" array, by parsing an ascii "template" file
3093 errr parse_d_info(char *buf, header *head)
3100 static dungeon_info_type *d_ptr = NULL;
3103 /* Process 'N' for "New/Number/Name" */
3106 /* Find the colon before the name */
3107 s = my_strchr(buf+2, ':');
3109 /* Verify that colon */
3112 /* Nuke the colon, advance to the name */
3115 /* Paranoia -- require a name */
3116 if (!*s) return (1);
3121 /* Verify information */
3122 if (i < error_idx) return (4);
3124 /* Verify information */
3125 if (i >= head->info_num) return (2);
3127 /* Save the index */
3130 /* Point at the "info" */
3133 /* Store the name */
3134 if (!add_name(&d_ptr->name, head, s)) return (7);
3139 else if (buf[0] == 'E') return (0);
3141 else if (buf[0] == 'E')
3143 /* Acquire the Text */
3146 /* Store the name */
3147 if (!add_name(&d_ptr->name, head, s)) return (7);
3151 /* Process 'D' for "Description */
3152 else if (buf[0] == 'D')
3157 /* Acquire the text */
3162 /* Acquire the text */
3166 /* Store the text */
3167 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3170 /* Process 'W' for "More Info" (one line only) */
3171 else if (buf[0] == 'W')
3173 int min_lev, max_lev;
3175 int min_alloc, max_chance;
3176 int obj_good, obj_great;
3179 /* Scan for the values */
3180 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3181 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3183 /* Save the values */
3184 d_ptr->mindepth = min_lev;
3185 d_ptr->maxdepth = max_lev;
3186 d_ptr->min_plev = min_plev;
3188 d_ptr->min_m_alloc_level = min_alloc;
3189 d_ptr->max_m_alloc_chance = max_chance;
3190 d_ptr->obj_good = obj_good;
3191 d_ptr->obj_great = obj_great;
3196 /* Process 'P' for "Place Info" */
3197 else if (buf[0] == 'P')
3201 /* Scan for the values */
3202 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3204 /* Save the values */
3209 /* Process 'L' for "fLoor type" (one line only) */
3210 else if (buf[0] == 'L')
3214 /* Scan for the values */
3215 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3217 /* Save the values */
3218 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3220 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3221 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3223 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3225 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3228 /* Process 'A' for "wAll type" (one line only) */
3229 else if (buf[0] == 'A')
3233 /* Scan for the values */
3234 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3236 /* Save the values */
3237 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3239 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3240 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3242 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3245 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3246 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3248 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3249 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3251 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3252 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3254 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3255 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3258 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3259 else if (buf[0] == 'F')
3261 int artif = 0, monst = 0;
3263 /* Parse every entry */
3264 for (s = buf + 2; *s; )
3266 /* Find the end of this entry */
3267 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3269 /* Nuke and skip any dividers */
3273 while (*t == ' ' || *t == '|') t++;
3276 /* XXX XXX XXX Hack -- Read Final Artifact */
3277 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3279 /* Extract a "Final Artifact" */
3280 d_ptr->final_artifact = artif;
3282 /* Start at next entry */
3289 /* XXX XXX XXX Hack -- Read Final Object */
3290 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3292 /* Extract a "Final Artifact" */
3293 d_ptr->final_object = artif;
3295 /* Start at next entry */
3302 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3303 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3305 /* Extract a "Artifact Guardian" */
3306 d_ptr->final_guardian = monst;
3308 /* Start at next entry */
3315 /* XXX XXX XXX Hack -- Read Special Percentage */
3316 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3318 /* Extract a "Special %" */
3319 d_ptr->special_div = monst;
3321 /* Start at next entry */
3328 /* Parse this entry */
3329 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3331 /* Start the next entry */
3336 /* Process 'M' for "Basic Flags" (multiple lines) */
3337 else if (buf[0] == 'M')
3339 /* Parse every entry */
3340 for (s = buf + 2; *s; )
3342 /* Find the end of this entry */
3343 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3345 /* Nuke and skip any dividers */
3349 while (*t == ' ' || *t == '|') t++;
3352 /* Hack -- Read monster symbols */
3353 if (!strncmp(s, "R_CHAR_", 7))
3355 /* Skip "R_CHAR_" */
3359 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3361 /* Start at next entry */
3368 /* Parse this entry */
3369 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3371 /* Start the next entry */
3376 /* Process 'S' for "Spell Flags" (multiple lines) */
3377 else if (buf[0] == 'S')
3379 /* Parse every entry */
3380 for (s = buf + 2; *s; )
3382 /* Find the end of this entry */
3383 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3385 /* Nuke and skip any dividers */
3389 while ((*t == ' ') || (*t == '|')) t++;
3392 /* XXX XXX XXX Hack -- Read spell frequency */
3393 if (1 == sscanf(s, "1_IN_%d", &i))
3395 /* Start at next entry */
3402 /* Parse this entry */
3403 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3405 /* Start the next entry */
3418 #else /* ALLOW_TEMPLATES */
3424 #endif /* ALLOW_TEMPLATES */
3427 /* Random dungeon grid effects */
3428 #define RANDOM_NONE 0x00000000
3429 #define RANDOM_FEATURE 0x00000001
3430 #define RANDOM_MONSTER 0x00000002
3431 #define RANDOM_OBJECT 0x00000004
3432 #define RANDOM_EGO 0x00000008
3433 #define RANDOM_ARTIFACT 0x00000010
3434 #define RANDOM_TRAP 0x00000020
3437 typedef struct dungeon_grid dungeon_grid;
3441 int feature; /* Terrain feature */
3442 int monster; /* Monster */
3443 int object; /* Object */
3444 int ego; /* Ego-Item */
3445 int artifact; /* Artifact */
3446 int trap; /* Trap */
3447 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3448 int special; /* Reserved for special terrain info */
3449 int random; /* Number of the random effect */
3453 static dungeon_grid letter[255];
3457 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3459 static errr parse_line_feature(char *buf)
3465 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3467 /* Tokenize the line */
3468 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3470 /* Letter to assign */
3471 int index = zz[0][0];
3473 /* Reset the info for the letter */
3474 letter[index].feature = feat_none;
3475 letter[index].monster = 0;
3476 letter[index].object = 0;
3477 letter[index].ego = 0;
3478 letter[index].artifact = 0;
3479 letter[index].trap = feat_none;
3480 letter[index].cave_info = 0;
3481 letter[index].special = 0;
3482 letter[index].random = RANDOM_NONE;
3488 letter[index].special = atoi(zz[8]);
3492 if ((zz[7][0] == '*') && !zz[7][1])
3494 letter[index].random |= RANDOM_TRAP;
3498 letter[index].trap = f_tag_to_index(zz[7]);
3499 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3504 if (zz[6][0] == '*')
3506 letter[index].random |= RANDOM_ARTIFACT;
3507 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3509 else if (zz[6][0] == '!')
3511 if (p_ptr->inside_quest)
3513 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3518 letter[index].artifact = atoi(zz[6]);
3523 if (zz[5][0] == '*')
3525 letter[index].random |= RANDOM_EGO;
3526 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3530 letter[index].ego = atoi(zz[5]);
3535 if (zz[4][0] == '*')
3537 letter[index].random |= RANDOM_OBJECT;
3538 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3540 else if (zz[4][0] == '!')
3542 if (p_ptr->inside_quest)
3544 int a_idx = quest[p_ptr->inside_quest].k_idx;
3547 artifact_type *a_ptr = &a_info[a_idx];
3548 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3550 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3557 letter[index].object = atoi(zz[4]);
3562 if (zz[3][0] == '*')
3564 letter[index].random |= RANDOM_MONSTER;
3565 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3567 else if (zz[3][0] == 'c')
3569 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3570 letter[index].monster = - atoi(zz[3] + 1);
3574 letter[index].monster = atoi(zz[3]);
3579 letter[index].cave_info = atoi(zz[2]);
3583 if ((zz[1][0] == '*') && !zz[1][1])
3585 letter[index].random |= RANDOM_FEATURE;
3589 letter[index].feature = f_tag_to_index(zz[1]);
3590 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3603 * Process "B:<Index>:<Command>:..." -- Building definition
3605 static errr parse_line_building(char *buf)
3621 /* Get the building number */
3624 /* Find the colon after the building number */
3625 s = my_strchr(s, ':');
3627 /* Verify that colon */
3630 /* Nuke the colon, advance to the sub-index */
3633 /* Paranoia -- require a sub-index */
3634 if (!*s) return (1);
3636 /* Building definition sub-index */
3639 /* Building name, owner, race */
3642 if (tokenize(s + 2, 3, zz, 0) == 3)
3644 /* Name of the building */
3645 strcpy(building[index].name, zz[0]);
3647 /* Name of the owner */
3648 strcpy(building[index].owner_name, zz[1]);
3650 /* Race of the owner */
3651 strcpy(building[index].owner_race, zz[2]);
3656 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3659 /* Building Action */
3662 if (tokenize(s + 2, 8, zz, 0) >= 7)
3664 /* Index of the action */
3665 int action_index = atoi(zz[0]);
3667 /* Name of the action */
3668 strcpy(building[index].act_names[action_index], zz[1]);
3670 /* Cost of the action for members */
3671 building[index].member_costs[action_index] = atoi(zz[2]);
3673 /* Cost of the action for non-members */
3674 building[index].other_costs[action_index] = atoi(zz[3]);
3676 /* Letter assigned to the action */
3677 building[index].letters[action_index] = zz[4][0];
3680 building[index].actions[action_index] = atoi(zz[5]);
3682 /* Action restriction */
3683 building[index].action_restr[action_index] = atoi(zz[6]);
3688 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3691 /* Building Classes */
3694 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3696 for (i = 0; i < MAX_CLASS; i++)
3698 building[index].member_class[i] = atoi(zz[i]);
3704 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3707 /* Building Races */
3710 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3712 for (i = 0; i < MAX_RACES; i++)
3714 building[index].member_race[i] = atoi(zz[i]);
3720 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3723 /* Building Realms */
3726 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3728 for (i = 0; i < MAX_MAGIC; i++)
3730 building[index].member_realm[i+1] = atoi(zz[i]);
3736 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3741 /* Ignore scripts */
3747 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3756 * Place the object j_ptr to a grid
3758 static void drop_here(object_type *j_ptr, int y, int x)
3760 cave_type *c_ptr = &cave[y][x];
3763 /* Get new object */
3764 s16b o_idx = o_pop();
3766 /* Access new object */
3767 o_ptr = &o_list[o_idx];
3769 /* Structure copy */
3770 object_copy(o_ptr, j_ptr);
3778 o_ptr->held_m_idx = 0;
3781 o_ptr->next_o_idx = c_ptr->o_idx;
3783 /* Place the object */
3784 c_ptr->o_idx = o_idx;
3789 * Parse a sub-file of the "extra info"
3791 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3798 /* Skip "empty" lines */
3799 if (!buf[0]) return (0);
3801 /* Skip "blank" lines */
3802 if (iswspace(buf[0])) return (0);
3805 if (buf[0] == '#') return (0);
3807 /* Require "?:*" format */
3808 if (buf[1] != ':') return (1);
3811 /* Process "%:<fname>" */
3814 /* Attempt to Process the given file */
3815 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3818 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3821 return parse_line_feature(buf);
3824 /* Process "D:<dungeon>" -- info for the cave grids */
3825 else if (buf[0] == 'D')
3827 object_type object_type_body;
3829 /* Acquire the text */
3832 /* Length of the text */
3833 int len = strlen(s);
3835 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3837 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3839 /* Access the grid */
3840 cave_type *c_ptr = &cave[*y][*x];
3844 int object_index = letter[idx].object;
3845 int monster_index = letter[idx].monster;
3846 int random = letter[idx].random;
3847 int artifact_index = letter[idx].artifact;
3849 /* Lay down a floor */
3850 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3852 /* Only the features */
3853 if (init_flags & INIT_ONLY_FEATURES) continue;
3856 c_ptr->info = letter[idx].cave_info;
3858 /* Create a monster */
3859 if (random & RANDOM_MONSTER)
3861 monster_level = base_level + monster_index;
3863 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3865 monster_level = base_level;
3867 else if (monster_index)
3869 int old_cur_num, old_max_num;
3872 if (monster_index < 0)
3874 monster_index = -monster_index;
3877 old_cur_num = r_info[monster_index].cur_num;
3878 old_max_num = r_info[monster_index].max_num;
3880 /* Make alive again */
3881 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3883 r_info[monster_index].cur_num = 0;
3884 r_info[monster_index].max_num = 1;
3887 /* Make alive again */
3888 /* Hack -- Non-unique Nazguls are semi-unique */
3889 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3891 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3893 r_info[monster_index].max_num++;
3898 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3902 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3904 /* Make alive again for real unique monster */
3905 r_info[monster_index].cur_num = old_cur_num;
3906 r_info[monster_index].max_num = old_max_num;
3910 /* Object (and possible trap) */
3911 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3913 object_level = base_level + object_index;
3916 * Random trap and random treasure defined
3917 * 25% chance for trap and 75% chance for object
3919 if (randint0(100) < 75)
3921 place_object(*y, *x, 0L);
3928 object_level = base_level;
3930 else if (random & RANDOM_OBJECT)
3932 object_level = base_level + object_index;
3934 /* Create an out of deep object */
3935 if (randint0(100) < 75)
3936 place_object(*y, *x, 0L);
3937 else if (randint0(100) < 80)
3938 place_object(*y, *x, AM_GOOD);
3940 place_object(*y, *x, AM_GOOD | AM_GREAT);
3942 object_level = base_level;
3945 else if (random & RANDOM_TRAP)
3949 /* Hidden trap (or door) */
3950 else if (letter[idx].trap)
3952 c_ptr->mimic = c_ptr->feat;
3953 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3955 else if (object_index)
3957 /* Get local object */
3958 object_type *o_ptr = &object_type_body;
3960 /* Create the item */
3961 object_prep(o_ptr, object_index);
3963 if (o_ptr->tval == TV_GOLD)
3965 coin_type = object_index - OBJ_GOLD_LIST;
3970 /* Apply magic (no messages, no artifacts) */
3971 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3973 drop_here(o_ptr, *y, *x);
3979 if (a_info[artifact_index].cur_num)
3981 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3983 object_type *q_ptr = &forge;
3985 object_prep(q_ptr, k_idx);
3987 /* Drop it in the dungeon */
3988 drop_here(q_ptr, *y, *x);
3992 /* Create the artifact */
3993 if (create_named_art(artifact_index, *y, *x))
3994 a_info[artifact_index].cur_num = 1;
3998 /* Terrain special */
3999 c_ptr->special = letter[idx].special;
4007 /* Process "Q:<number>:<command>:... -- quest info */
4008 else if (buf[0] == 'Q')
4015 num = tokenize(buf + 2, 33, zz, 0);
4019 num = tokenize(buf + 3, 33, zz, 0);
4022 /* Have we enough parameters? */
4023 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4026 q_ptr = &(quest[atoi(zz[0])]);
4028 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4029 if (zz[1][0] == 'Q')
4031 if (init_flags & INIT_ASSIGN)
4033 monster_race *r_ptr;
4034 artifact_type *a_ptr;
4036 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4038 q_ptr->type = atoi(zz[2]);
4039 q_ptr->num_mon = atoi(zz[3]);
4040 q_ptr->cur_num = atoi(zz[4]);
4041 q_ptr->max_num = atoi(zz[5]);
4042 q_ptr->level = atoi(zz[6]);
4043 q_ptr->r_idx = atoi(zz[7]);
4044 q_ptr->k_idx = atoi(zz[8]);
4045 q_ptr->dungeon = atoi(zz[9]);
4048 q_ptr->flags = atoi(zz[10]);
4050 r_ptr = &r_info[q_ptr->r_idx];
4051 if (r_ptr->flags1 & RF1_UNIQUE)
4052 r_ptr->flags1 |= RF1_QUESTOR;
4054 a_ptr = &a_info[q_ptr->k_idx];
4055 a_ptr->gen_flags |= TRG_QUESTITEM;
4060 else if (zz[1][0] == 'R')
4062 if (init_flags & INIT_ASSIGN)
4067 for (idx = 2; idx < num; idx++)
4069 int a_idx = atoi(zz[idx]);
4070 if (a_idx < 1) continue;
4071 if (a_info[a_idx].cur_num > 0) continue;
4073 if (one_in_(count)) reward_idx = a_idx;
4078 /* Set quest's rewarding artifact */
4079 q_ptr->k_idx = reward_idx;
4080 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4084 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4085 q_ptr->type = QUEST_TYPE_KILL_ALL;
4092 /* Process "Q:<q_index>:N:<name>" -- quest name */
4093 else if (zz[1][0] == 'N')
4095 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4097 strcpy(q_ptr->name, zz[2]);
4103 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4104 else if (zz[1][0] == 'T')
4106 if (init_flags & INIT_SHOW_TEXT)
4108 strcpy(quest_text[quest_text_line], zz[2]);
4116 /* Process "W:<command>: ..." -- info for the wilderness */
4117 else if (buf[0] == 'W')
4119 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4122 /* Process "P:<y>:<x>" -- player position */
4123 else if (buf[0] == 'P')
4125 if (init_flags & INIT_CREATE_DUNGEON)
4127 if (tokenize(buf + 2, 2, zz, 0) == 2)
4129 int panels_x, panels_y;
4131 /* Hack - Set the dungeon size */
4132 panels_y = (*y / SCREEN_HGT);
4133 if (*y % SCREEN_HGT) panels_y++;
4134 cur_hgt = panels_y * SCREEN_HGT;
4136 panels_x = (*x / SCREEN_WID);
4137 if (*x % SCREEN_WID) panels_x++;
4138 cur_wid = panels_x * SCREEN_WID;
4140 /* Assume illegal panel */
4141 panel_row_min = cur_hgt;
4142 panel_col_min = cur_wid;
4144 /* Place player in a quest level */
4145 if (p_ptr->inside_quest)
4149 /* Delete the monster (if any) */
4150 delete_monster(py, px);
4158 /* Place player in the town */
4159 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4161 p_ptr->oldpy = atoi(zz[0]);
4162 p_ptr->oldpx = atoi(zz[1]);
4170 /* Process "B:<Index>:<Command>:..." -- Building definition */
4171 else if (buf[0] == 'B')
4173 return parse_line_building(buf);
4176 /* Process "M:<type>:<maximum>" -- set maximum values */
4177 else if (buf[0] == 'M')
4179 if (tokenize(buf+2, 2, zz, 0) == 2)
4182 if (zz[0][0] == 'T')
4184 max_towns = atoi(zz[1]);
4187 /* Maximum quests */
4188 else if (zz[0][0] == 'Q')
4190 max_quests = atoi(zz[1]);
4194 else if (zz[0][0] == 'R')
4196 max_r_idx = atoi(zz[1]);
4200 else if (zz[0][0] == 'K')
4202 max_k_idx = atoi(zz[1]);
4206 else if (zz[0][0] == 'V')
4208 max_v_idx = atoi(zz[1]);
4212 else if (zz[0][0] == 'F')
4214 max_f_idx = atoi(zz[1]);
4218 else if (zz[0][0] == 'A')
4220 max_a_idx = atoi(zz[1]);
4224 else if (zz[0][0] == 'E')
4226 max_e_idx = atoi(zz[1]);
4230 else if (zz[0][0] == 'D')
4232 max_d_idx = atoi(zz[1]);
4236 else if (zz[0][0] == 'O')
4238 max_o_idx = atoi(zz[1]);
4242 else if (zz[0][0] == 'M')
4244 max_m_idx = atoi(zz[1]);
4247 /* Wilderness size */
4248 else if (zz[0][0] == 'W')
4250 /* Maximum wild_x_size */
4251 if (zz[0][1] == 'X')
4252 max_wild_x = atoi(zz[1]);
4253 /* Maximum wild_y_size */
4254 if (zz[0][1] == 'Y')
4255 max_wild_y = atoi(zz[1]);
4269 static cptr variant = "ZANGBAND";
4273 * Helper function for "process_dungeon_file()"
4275 static cptr process_dungeon_file_expr(char **sp, char *fp)
4291 while (iswspace(*s)) s++;
4309 t = process_dungeon_file_expr(&s, &f);
4318 else if (streq(t, "IOR"))
4321 while (*s && (f != b2))
4323 t = process_dungeon_file_expr(&s, &f);
4324 if (*t && !streq(t, "0")) v = "1";
4329 else if (streq(t, "AND"))
4332 while (*s && (f != b2))
4334 t = process_dungeon_file_expr(&s, &f);
4335 if (*t && streq(t, "0")) v = "0";
4340 else if (streq(t, "NOT"))
4343 while (*s && (f != b2))
4345 t = process_dungeon_file_expr(&s, &f);
4346 if (*t && streq(t, "1")) v = "0";
4351 else if (streq(t, "EQU"))
4354 if (*s && (f != b2))
4356 t = process_dungeon_file_expr(&s, &f);
4358 while (*s && (f != b2))
4360 p = process_dungeon_file_expr(&s, &f);
4361 if (streq(t, p)) v = "1";
4366 else if (streq(t, "LEQ"))
4369 if (*s && (f != b2))
4371 t = process_dungeon_file_expr(&s, &f);
4373 while (*s && (f != b2))
4376 t = process_dungeon_file_expr(&s, &f);
4377 if (*t && atoi(p) > atoi(t)) v = "0";
4382 else if (streq(t, "GEQ"))
4385 if (*s && (f != b2))
4387 t = process_dungeon_file_expr(&s, &f);
4389 while (*s && (f != b2))
4392 t = process_dungeon_file_expr(&s, &f);
4394 /* Compare two numbers instead of string */
4395 if (*t && atoi(p) < atoi(t)) v = "0";
4402 while (*s && (f != b2))
4404 t = process_dungeon_file_expr(&s, &f);
4409 if (f != b2) v = "?x?x?";
4411 /* Extract final and Terminate */
4412 if ((f = *s) != '\0') *s++ = '\0';
4418 /* Accept all printables except spaces and brackets */
4420 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4422 if (iskanji(*s)) s++;
4426 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4429 /* Extract final and Terminate */
4430 if ((f = *s) != '\0') *s++ = '\0';
4436 if (streq(b+1, "SYS"))
4442 else if (streq(b+1, "GRAF"))
4447 else if (streq(b+1, "MONOCHROME"))
4456 else if (streq(b+1, "RACE"))
4459 v = rp_ptr->E_title;
4466 else if (streq(b+1, "CLASS"))
4469 v = cp_ptr->E_title;
4476 else if (streq(b+1, "REALM1"))
4479 v = E_realm_names[p_ptr->realm1];
4481 v = realm_names[p_ptr->realm1];
4486 else if (streq(b+1, "REALM2"))
4489 v = E_realm_names[p_ptr->realm2];
4491 v = realm_names[p_ptr->realm2];
4496 else if (streq(b+1, "PLAYER"))
4498 static char tmp_player_name[32];
4500 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4510 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4513 v = tmp_player_name;
4517 else if (streq(b+1, "TOWN"))
4519 sprintf(tmp, "%d", p_ptr->town_num);
4524 else if (streq(b+1, "LEVEL"))
4526 sprintf(tmp, "%d", p_ptr->lev);
4530 /* Current quest number */
4531 else if (streq(b+1, "QUEST_NUMBER"))
4533 sprintf(tmp, "%d", p_ptr->inside_quest);
4537 /* Number of last quest */
4538 else if (streq(b+1, "LEAVING_QUEST"))
4540 sprintf(tmp, "%d", leaving_quest);
4545 else if (prefix(b+1, "QUEST_TYPE"))
4547 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4548 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4553 else if (prefix(b+1, "QUEST"))
4555 /* "QUEST" uses a special parameter to determine the number of the quest */
4556 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4561 else if (prefix(b+1, "RANDOM"))
4563 /* "RANDOM" uses a special parameter to determine the number of the quest */
4564 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4569 else if (streq(b+1, "VARIANT"))
4575 else if (streq(b+1, "WILDERNESS"))
4578 sprintf(tmp, "NONE");
4580 sprintf(tmp, "LITE");
4582 sprintf(tmp, "NORMAL");
4605 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4615 bool bypass = FALSE;
4617 int x = xmin, y = ymin;
4620 /* Build the filename */
4621 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4624 fp = my_fopen(buf, "r");
4627 if (!fp) return (-1);
4630 /* Process the file */
4631 while (0 == my_fgets(fp, buf, sizeof(buf)))
4637 /* Skip "empty" lines */
4638 if (!buf[0]) continue;
4640 /* Skip "blank" lines */
4641 if (iswspace(buf[0])) continue;
4644 if (buf[0] == '#') continue;
4647 /* Process "?:<expr>" */
4648 if ((buf[0] == '?') && (buf[1] == ':'))
4657 /* Parse the expr */
4658 v = process_dungeon_file_expr(&s, &f);
4661 bypass = (streq(v, "0") ? TRUE : FALSE);
4667 /* Apply conditionals */
4668 if (bypass) continue;
4670 /* Process the line */
4671 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4683 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4686 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4688 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4690 msg_format("Parsing '%s'.", buf);
4697 /* Close the file */
4707 void write_r_info_txt(void)
4709 int i, j, z, fc, bc;
4712 cptr flags[32 * 10];
4717 monster_race *r_ptr;
4719 monster_blow *b_ptr;
4721 FILE *fff = fopen("output.txt", "wt");
4729 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4731 fprintf(fff, "# Version stamp (required)\n\n");
4734 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4737 fprintf(fff, "##### The Player #####\n\n");
4739 for (z = -1; z < alloc_race_size; z++)
4741 /* Output the monsters in order */
4742 i = (z >= 0) ? alloc_race_table[z].index : 0;
4744 /* Acquire the monster */
4747 /* Ignore empty monsters */
4748 if (!strlen(r_name + r_ptr->name)) continue;
4750 /* Ignore useless monsters */
4751 if (i && !r_ptr->speed) continue;
4753 /* Write a note if necessary */
4754 if (i && (!r_ptr->level != !mode))
4759 fprintf(fff, "\n##### Town monsters #####\n\n");
4761 /* Note the dungeon */
4764 fprintf(fff, "\n##### Normal monsters #####\n\n");
4767 /* Record the change */
4768 mode = r_ptr->level;
4771 /* Acquire the flags */
4772 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4773 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4774 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4775 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4776 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4777 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4778 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4779 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4780 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4781 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4783 /* Write New/Number/Name */
4784 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4787 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4789 /* Write Information */
4790 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4791 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4793 /* Write more information */
4794 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4797 for(j = 0; j < 4; j++)
4799 b_ptr = &(r_ptr->blow[j]);
4801 /* Stop when done */
4802 if (!b_ptr->method) break;
4804 /* Write the blows */
4805 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4806 r_info_blow_effect[b_ptr->effect],
4807 b_ptr->d_dice, b_ptr->d_side);
4810 /* Extract the flags */
4811 for (fc = 0, j = 0; j < 32 * 3; j++)
4813 /* Check this flag */
4814 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4817 /* Extract the extra flags */
4818 for (j = 32 * 6; j < 32 * 10; j++)
4820 /* Check this flag */
4821 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4824 /* Write the flags */
4825 for (j = 0; j < fc;)
4829 /* Start the line */
4832 for (bc = 0; (bc < 60) && (j < fc); j++)
4836 /* Format the flag */
4837 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4839 /* Add it to the buffer */
4842 /* Note the length */
4846 /* Done with this line; write it */
4847 fprintf(fff, "%s\n", buf);
4850 /* Write Spells if applicable */
4851 if (r_ptr->freq_spell)
4853 /* Write the frequency */
4854 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4856 /* Extract the spell flags */
4857 for (fc = 0, j = 96; j < 192; j++)
4859 /* Check this flag */
4860 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4863 /* Write the flags */
4864 for (j = 0; j < fc;)
4868 /* Start the line */
4871 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4875 /* Format the flag */
4876 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4880 /* Note the length */
4887 /* Done with this line; write it */
4888 fprintf(fff, "%s\n", buf);
4892 /* Acquire the description */
4893 desc = r_text + r_ptr->text;
4894 dlen = strlen(desc);
4896 /* Write Description */
4897 for (j = 0; j < dlen;)
4901 /* Start the line */
4904 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4912 /* Done with this line; write it */
4913 fprintf(fff, "%s\n", buf);
4916 /* Space between entries */