4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 1) -BEN- */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
33 * in this file is compiled out, and the game will not run unless valid
34 * "binary template files" already exist in "lib/data". Thus, one can
35 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
36 * "*.raw" files in "lib/data", and then quit, and recompile without
37 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
38 * from changing the ascii template files in potentially dangerous ways.
40 * The code could actually be removed and placed into a "stand-alone"
41 * program, but that feels a little silly, especially considering some
42 * of the platforms that we currently support.
45 #ifdef ALLOW_TEMPLATES
50 /*** Helper arrays for parsing ascii template files ***/
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * Monster Blow Effects
90 static cptr r_info_blow_effect[] =
133 static cptr f_info_flags[] =
253 * Special feature info tags
255 static cptr f_info_special_tags[] =
271 static cptr r_info_flags1[] =
310 static cptr r_info_flags2[] =
349 static cptr r_info_flags3[] =
388 static cptr r_info_flags4[] =
427 static cptr r_info_flags5[] =
466 static cptr r_info_flags6[] =
483 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
506 static cptr r_info_flags7[] =
545 static cptr r_info_flags8[] =
577 "WILD_SWAMP", /* ToDo: Implement Swamp */
583 * Monster race flags - Drops
585 static cptr r_info_flags9[] =
624 * Monster race flags - Resistances
626 static cptr r_info_flagsr[] =
666 static cptr k_info_flags[] =
791 static cptr k_info_gen_flags[] =
831 static cptr d_info_flags1[] =
869 * Add a text to the text-storage and store offset to it.
871 * Returns FALSE when there isn't enough space available to store
874 static bool add_text(u32b *offset, header *head, cptr buf)
876 /* Hack -- Verify space */
877 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
883 /* Advance and save the text index */
884 *offset = ++head->text_size;
887 /* Append chars to the text */
888 strcpy(head->text_ptr + head->text_size, buf);
890 /* Advance the index */
891 head->text_size += strlen(buf);
899 * Add a name to the name-storage and return an offset to it.
901 * Returns FALSE when there isn't enough space available to store
904 static bool add_name(u32b *offset, header *head, cptr buf)
906 /* Hack -- Verify space */
907 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
913 /* Advance and save the name index */
914 *offset = ++head->name_size;
917 /* Append chars to the names */
918 strcpy(head->name_ptr + head->name_size, buf);
920 /* Advance the index */
921 head->name_size += strlen(buf);
929 * Add a tag to the tag-storage and return an offset to it.
931 * Returns FALSE when there isn't enough space available to store
934 static bool add_tag(s16b *offset, header *head, cptr buf)
938 /* Search for an existing (fake) tag */
939 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
942 if (streq(&head->tag_ptr[i], buf)) break;
945 /* There was no existing tag */
946 if (i >= head->tag_size)
948 /* Hack -- Verify space */
949 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
952 /* Append chars to the tags */
953 strcpy(head->tag_ptr + head->tag_size, buf);
955 /* Point the new tag */
958 /* Advance the index */
959 head->tag_size += strlen(buf) + 1;
962 /* Return offset of the tag */
971 * Convert a "color letter" into an "actual" color
972 * The colors are: dwsorgbuDWvyRGBU, as shown below
974 byte color_char_to_attr(char c)
978 case 'd': return (TERM_DARK);
979 case 'w': return (TERM_WHITE);
980 case 's': return (TERM_SLATE);
981 case 'o': return (TERM_ORANGE);
982 case 'r': return (TERM_RED);
983 case 'g': return (TERM_GREEN);
984 case 'b': return (TERM_BLUE);
985 case 'u': return (TERM_UMBER);
987 case 'D': return (TERM_L_DARK);
988 case 'W': return (TERM_L_WHITE);
989 case 'v': return (TERM_VIOLET);
990 case 'y': return (TERM_YELLOW);
991 case 'R': return (TERM_L_RED);
992 case 'G': return (TERM_L_GREEN);
993 case 'B': return (TERM_L_BLUE);
994 case 'U': return (TERM_L_UMBER);
1002 /*** Initialize from ascii template files ***/
1006 * Initialize an "*_info" array, by parsing an ascii "template" file
1008 errr init_info_txt(FILE *fp, char *buf, header *head,
1009 parse_info_txt_func parse_info_txt_line)
1013 /* Just before the first record */
1016 /* Just before the first line */
1020 /* Prepare the "fake" stuff */
1021 head->name_size = 0;
1022 head->text_size = 0;
1026 while (0 == my_fgets(fp, buf, 1024))
1028 /* Advance the line number */
1031 /* Skip comments and blank lines */
1032 if (!buf[0] || (buf[0] == '#')) continue;
1034 /* Verify correct "colon" format */
1035 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1038 /* Hack -- Process 'V' for "Version" */
1045 /* Mega Hack -- Calculate Check Sum */
1046 if (buf[0] != 'N' && buf[0] != 'D')
1049 for (i = 0; buf[i]; i++)
1051 head->v_extra += (byte)buf[i];
1052 head->v_extra ^= (1 << (i % 8));
1056 /* Parse the line */
1057 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1062 /* Complete the "name" and "text" sizes */
1063 if (head->name_size) head->name_size++;
1064 if (head->text_size) head->text_size++;
1072 * Initialize the "v_info" array, by parsing an ascii "template" file
1074 errr parse_v_info(char *buf, header *head)
1080 static vault_type *v_ptr = NULL;
1082 /* Process 'N' for "New/Number/Name" */
1085 /* Find the colon before the name */
1086 s = my_strchr(buf+2, ':');
1088 /* Verify that colon */
1091 /* Nuke the colon, advance to the name */
1094 /* Paranoia -- require a name */
1095 if (!*s) return (1);
1100 /* Verify information */
1101 if (i <= error_idx) return (4);
1103 /* Verify information */
1104 if (i >= head->info_num) return (2);
1106 /* Save the index */
1109 /* Point at the "info" */
1112 /* Store the name */
1113 if (!add_name(&v_ptr->name, head, s)) return (7);
1116 /* There better be a current v_ptr */
1117 else if (!v_ptr) return (3);
1119 /* Process 'D' for "Description" */
1120 else if (buf[0] == 'D')
1122 /* Acquire the text */
1125 /* Store the text */
1126 if (!add_text(&v_ptr->text, head, s)) return (7);
1129 /* Process 'X' for "Extra info" (one line only) */
1130 else if (buf[0] == 'X')
1132 int typ, rat, hgt, wid;
1134 /* Scan for the values */
1135 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1136 &typ, &rat, &hgt, &wid)) return (1);
1138 /* Save the values */
1155 * Initialize the "s_info" array, by parsing an ascii "template" file
1157 errr parse_s_info(char *buf, header *head)
1162 static skill_table *s_ptr = NULL;
1165 /* Process 'N' for "New/Number/Name" */
1171 /* Verify information */
1172 if (i <= error_idx) return (4);
1174 /* Verify information */
1175 if (i >= head->info_num) return (2);
1177 /* Save the index */
1180 /* Point at the "info" */
1184 /* There better be a current s_ptr */
1185 else if (!s_ptr) return (3);
1187 /* Process 'W' for "Weapon exp" */
1188 else if (buf[0] == 'W')
1190 int tval, sval, start, max;
1191 const s16b exp_conv_table[] =
1193 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1194 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1197 /* Scan for the values */
1198 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1199 &tval, &sval, &start, &max)) return (1);
1201 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1202 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1204 /* Save the values */
1205 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1206 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1209 /* Process 'S' for "Skill exp" */
1210 else if (buf[0] == 'S')
1212 int num, start, max;
1214 /* Scan for the values */
1215 if (3 != sscanf(buf+2, "%d:%d:%d",
1216 &num, &start, &max)) return (1);
1218 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1219 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1221 /* Save the values */
1222 s_ptr->s_start[num] = start;
1223 s_ptr->s_max[num] = max;
1236 * Initialize the "m_info" array, by parsing an ascii "template" file
1238 errr parse_m_info(char *buf, header *head)
1245 static player_magic *m_ptr = NULL;
1248 static int realm, magic_idx = 0, readable = 0;
1251 /* Process 'N' for "New/Number/Name" */
1257 /* Verify information */
1258 if (i <= error_idx) return (4);
1260 /* Verify information */
1261 if (i >= head->info_num) return (2);
1263 /* Save the index */
1266 /* Point at the "info" */
1270 /* There better be a current m_ptr */
1271 else if (!m_ptr) return (3);
1273 /* Process 'I' for "Info" (one line only) */
1274 else if (buf[0] == 'I')
1277 int xtra, type, first, weight;
1279 /* Find the colon before the name */
1280 s = my_strchr(buf+2, ':');
1282 /* Verify that colon */
1285 /* Nuke the colon, advance to the name */
1290 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1291 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1292 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1293 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1294 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1299 /* Find the colon before the name */
1300 s = my_strchr(s, ':');
1302 /* Verify that colon */
1305 /* Nuke the colon, advance to the name */
1308 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1309 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1310 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1311 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1312 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1313 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1317 /* Scan for the values */
1318 if (4 != sscanf(s, "%x:%d:%d:%d",
1319 (uint *)&xtra, &type, &first, &weight)) return (1);
1321 m_ptr->spell_xtra = xtra;
1322 m_ptr->spell_type = type;
1323 m_ptr->spell_first = first;
1324 m_ptr->spell_weight = weight;
1328 /* Process 'R' for "Realm" (one line only) */
1329 else if (buf[0] == 'R')
1331 /* Scan for the values */
1332 if (2 != sscanf(buf+2, "%d:%d",
1333 &realm, &readable)) return (1);
1338 else if (buf[0] == 'T')
1340 int level, mana, fail, exp;
1342 if (!readable) return (1);
1343 /* Scan for the values */
1344 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1345 &level, &mana, &fail, &exp)) return (1);
1347 m_ptr->info[realm][magic_idx].slevel = level;
1348 m_ptr->info[realm][magic_idx].smana = mana;
1349 m_ptr->info[realm][magic_idx].sfail = fail;
1350 m_ptr->info[realm][magic_idx].sexp = exp;
1364 * Grab one flag from a textual string
1366 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1371 for (i = 0; i < 32; i++)
1373 if (streq(what, names[i]))
1375 *flags |= (1L << i);
1385 * Grab one flag in an feature_type from a textual string
1387 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1392 for (i = 0; i < FF_FLAG_MAX; i++)
1394 if (streq(what, f_info_flags[i]))
1396 add_flag(f_ptr->flags, i);
1403 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1405 msg_format("Unknown feature flag '%s'.", what);
1409 return PARSE_ERROR_GENERIC;
1414 * Grab an action in an feature_type from a textual string
1416 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1421 for (i = 0; i < FF_FLAG_MAX; i++)
1423 if (streq(what, f_info_flags[i]))
1425 f_ptr->state[count].action = i;
1432 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1434 msg_format("Unknown feature action '%s'.", what);
1438 return PARSE_ERROR_GENERIC;
1443 * Initialize the "f_info" array, by parsing an ascii "template" file
1445 errr parse_f_info(char *buf, header *head)
1452 static feature_type *f_ptr = NULL;
1455 /* Process 'N' for "New/Number/Name" */
1458 /* Find the colon before the name */
1459 s = my_strchr(buf+2, ':');
1463 /* Nuke the colon, advance to the name */
1470 /* Verify information */
1471 if (i <= error_idx) return (4);
1473 /* Verify information */
1474 if (i >= head->info_num) return (2);
1476 /* Save the index */
1479 /* Point at the "info" */
1482 /* Tag name is given */
1486 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1489 /* Default "mimic" */
1492 /* Default "destroyed state" -- if not specified */
1493 f_ptr->destroyed = i;
1495 /* Default "states" */
1496 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1499 /* There better be a current f_ptr */
1500 else if (!f_ptr) return (3);
1503 else if (buf[0] == 'J')
1505 /* Store the name */
1506 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1509 else if (buf[0] == 'E')
1511 /* Ignore english name */
1514 else if (buf[0] == 'J')
1516 /* Ignore Japanese name */
1519 else if (buf[0] == 'E')
1521 /* Acquire the Text */
1524 /* Store the name */
1525 if (!add_name(&f_ptr->name, head, s)) return (7);
1530 /* Process 'M' for "Mimic" (one line only) */
1531 else if (buf[0] == 'M')
1535 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1537 /* Record a fake tag index */
1538 f_ptr->mimic = -offset;
1542 /* Process 'G' for "Graphics" (one line only) */
1543 else if (buf[0] == 'G')
1546 byte def_attr[F_LIT_MAX];
1547 char char_tmp[F_LIT_MAX];
1550 if (buf[1] != ':') return (1);
1551 if (!buf[2]) return (1);
1552 if (buf[3] != ':') return (1);
1553 if (!buf[4]) return (1);
1555 /* Extract the char */
1556 char_tmp[F_LIT_STANDARD] = buf[2];
1558 /* Extract the color */
1559 def_attr[F_LIT_STANDARD] = color_char_to_attr(buf[4]);
1562 if (def_attr[F_LIT_STANDARD] > 127) return (1);
1564 /* Save the default values for lighting */
1565 for (j = 0; j < F_LIT_MAX; j++)
1567 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1568 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1571 /* Is this feature supports lighting? */
1574 def_attr[F_LIT_LITE] = lighting_colours[def_attr[F_LIT_STANDARD]][0];
1575 def_attr[F_LIT_DARK] = lighting_colours[def_attr[F_LIT_STANDARD]][1];
1576 def_attr[F_LIT_DARKDARK] = lighting_colours[lighting_colours[def_attr[F_LIT_STANDARD]][1]][1];
1578 /* G:c:a:LIT (default) */
1579 if (streq(buf + 6, "LIT"))
1581 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1583 f_ptr->d_attr[j] = def_attr[j];
1587 /* G:c:a:lc:la:dc:da:Dc:Da */
1590 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1592 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c:%c:%c",
1593 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1594 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN],
1595 &char_tmp[F_LIT_DARKDARK], &attr_lite_tmp[F_LIT_DARKDARK - F_LIT_NS_BEGIN])) return 1;
1596 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1598 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1600 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1603 /* Use default lighting */
1604 f_ptr->d_attr[j] = def_attr[j];
1607 /* No lighting support */
1608 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1611 /* Extract the color */
1612 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1613 if (f_ptr->d_attr[j] > 127) return 1;
1616 f_ptr->d_char[j] = char_tmp[j];
1620 else if (buf[5]) return 1;
1623 /* Hack -- Process 'F' for flags */
1624 else if (buf[0] == 'F')
1626 /* Parse every entry textually */
1627 for (s = buf + 2; *s; )
1629 /* Find the end of this entry */
1630 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1632 /* Nuke and skip any dividers */
1636 while (*t == ' ' || *t == '|') t++;
1639 /* XXX XXX XXX Hack -- Read feature power */
1640 if (1 == sscanf(s, "POWER_%d", &i))
1642 /* Extract a "power" */
1645 /* Start at next entry */
1652 /* Parse this entry */
1653 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1655 /* Start the next entry */
1660 /* Process 'W' for "More Info" (one line only) */
1661 else if (buf[0] == 'W')
1665 /* Scan for the value */
1666 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1668 /* Save the value */
1669 f_ptr->priority = priority;
1672 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1673 else if (buf[0] == 'K')
1677 /* Find the next empty state slot (if any) */
1678 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1680 /* Oops, no more slots */
1681 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1683 /* Analyze the first field */
1684 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1686 /* Terminate the field (if necessary) */
1687 if (*t == ':') *t++ = '\0';
1689 /* Is this default entry? */
1690 if (streq(s, "DESTROYED"))
1692 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1694 /* Record a fake tag index */
1695 f_ptr->destroyed = -offset;
1700 f_ptr->state[i].action = 0;
1702 /* Parse this entry */
1703 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1705 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1707 /* Record a fake tag index */
1708 f_ptr->state[i].result = -offset;
1721 * Convert a fake tag to a real feat index
1723 s16b f_tag_to_index(cptr str)
1727 /* Search for real index corresponding to this fake tag */
1728 for (i = 0; i < f_head.info_num; i++)
1730 if (streq(f_tag + f_info[i].tag, str))
1732 /* Return the index */
1737 /* Search for special index corresponding to this fake tag */
1738 for (i = 0; f_info_special_tags[i]; i++)
1740 if (streq(f_info_special_tags[i], str))
1742 /* Return the special index */
1743 return (s16b)(FEAT_DUNGEON_FLOOR - i);
1753 * Search for real index corresponding to this fake tag
1755 static void search_real_feat(s16b *feat)
1759 /* Don't convert non-fake tag */
1760 if (*feat >= 0) return;
1762 /* Search for real index corresponding to this fake tag */
1763 for (i = 0; i < f_head.info_num; i++)
1765 if ((-(*feat)) == f_info[i].tag)
1767 /* Record real index */
1773 /* Search for special index corresponding to this fake tag */
1774 for (i = 0; f_info_special_tags[i]; i++)
1776 if (streq(f_info_special_tags[i], f_tag + (-(*feat))))
1778 /* Record special index */
1779 *feat = (s16b)(FEAT_DUNGEON_FLOOR - i);
1786 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1788 msg_format("%s is undefined.", f_tag + (-(*feat)));
1794 * Retouch fake tags of f_info
1796 void retouch_f_info(header *head)
1800 /* Convert fake tags to real feat indices */
1801 for (i = 0; i < head->info_num; i++)
1803 feature_type *f_ptr = &f_info[i];
1806 search_real_feat(&f_ptr->mimic);
1808 search_real_feat(&f_ptr->destroyed);
1810 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1816 * Grab one flag in an object_kind from a textual string
1818 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1823 for (i = 0; i < TR_FLAG_MAX; i++)
1825 if (streq(what, k_info_flags[i]))
1827 add_flag(k_ptr->flags, i);
1832 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1837 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1839 msg_format("Unknown object flag '%s'.", what);
1849 * Initialize the "k_info" array, by parsing an ascii "template" file
1851 errr parse_k_info(char *buf, header *head)
1858 static object_kind *k_ptr = NULL;
1861 /* Process 'N' for "New/Number/Name" */
1864 /* Find the colon before the name */
1865 s = my_strchr(buf+2, ':');
1867 /* Verify that colon */
1870 /* Nuke the colon, advance to the name */
1874 /* Paranoia -- require a name */
1875 if (!*s) return (1);
1880 /* Verify information */
1881 if (i <= error_idx) return (4);
1883 /* Verify information */
1884 if (i >= head->info_num) return (2);
1886 /* Save the index */
1889 /* Point at the "info" */
1893 /* Store the name */
1894 if (!add_name(&k_ptr->name, head, s)) return (7);
1898 /* There better be a current k_ptr */
1899 else if (!k_ptr) return (3);
1903 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1904 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1905 else if (buf[0] == 'E')
1910 else if (buf[0] == 'E')
1912 /* Acquire the Text */
1915 /* Store the name */
1916 if (!add_name(&k_ptr->name, head, s)) return (7);
1920 /* Process 'D' for "Description" */
1921 else if (buf[0] == 'D')
1926 /* Acquire the text */
1931 /* Acquire the text */
1935 /* Store the text */
1936 if (!add_text(&k_ptr->text, head, s)) return (7);
1939 /* Process 'G' for "Graphics" (one line only) */
1940 else if (buf[0] == 'G')
1946 if (buf[1] != ':') return (1);
1947 if (!buf[2]) return (1);
1948 if (buf[3] != ':') return (1);
1949 if (!buf[4]) return (1);
1951 /* Extract the char */
1954 /* Extract the attr */
1955 tmp = color_char_to_attr(buf[4]);
1958 if (tmp > 127) return (1);
1960 /* Save the values */
1961 k_ptr->d_attr = tmp;
1962 k_ptr->d_char = sym;
1965 /* Process 'I' for "Info" (one line only) */
1966 else if (buf[0] == 'I')
1968 int tval, sval, pval;
1970 /* Scan for the values */
1971 if (3 != sscanf(buf+2, "%d:%d:%d",
1972 &tval, &sval, &pval)) return (1);
1974 /* Save the values */
1980 /* Process 'W' for "More Info" (one line only) */
1981 else if (buf[0] == 'W')
1983 int level, extra, wgt;
1986 /* Scan for the values */
1987 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1988 &level, &extra, &wgt, &cost)) return (1);
1990 /* Save the values */
1991 k_ptr->level = level;
1992 k_ptr->extra = extra;
1993 k_ptr->weight = wgt;
1997 /* Process 'A' for "Allocation" (one line only) */
1998 else if (buf[0] == 'A')
2002 /* XXX XXX XXX Simply read each number following a colon */
2003 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2005 /* Default chance */
2006 k_ptr->chance[i] = 1;
2008 /* Store the attack damage index */
2009 k_ptr->locale[i] = atoi(s+1);
2011 /* Find the slash */
2012 t = my_strchr(s+1, '/');
2014 /* Find the next colon */
2015 s = my_strchr(s+1, ':');
2017 /* If the slash is "nearby", use it */
2018 if (t && (!s || t < s))
2020 int chance = atoi(t+1);
2021 if (chance > 0) k_ptr->chance[i] = chance;
2026 /* Hack -- Process 'P' for "power" and such */
2027 else if (buf[0] == 'P')
2029 int ac, hd1, hd2, th, td, ta;
2031 /* Scan for the values */
2032 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2033 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2043 /* Hack -- Process 'F' for flags */
2044 else if (buf[0] == 'F')
2046 /* Parse every entry textually */
2047 for (s = buf + 2; *s; )
2049 /* Find the end of this entry */
2050 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2052 /* Nuke and skip any dividers */
2056 while (*t == ' ' || *t == '|') t++;
2059 /* Parse this entry */
2060 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2062 /* Start the next entry */
2078 * Grab one flag in an artifact_type from a textual string
2080 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2085 for (i = 0; i < TR_FLAG_MAX; i++)
2087 if (streq(what, k_info_flags[i]))
2089 add_flag(a_ptr->flags, i);
2094 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2099 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2101 msg_format("Unknown artifact flag '%s'.", what);
2113 * Initialize the "a_info" array, by parsing an ascii "template" file
2115 errr parse_a_info(char *buf, header *head)
2122 static artifact_type *a_ptr = NULL;
2125 /* Process 'N' for "New/Number/Name" */
2128 /* Find the colon before the name */
2129 s = my_strchr(buf+2, ':');
2131 /* Verify that colon */
2134 /* Nuke the colon, advance to the name */
2137 /* Paranoia -- require a name */
2138 if (!*s) return (1);
2143 /* Verify information */
2144 if (i < error_idx) return (4);
2146 /* Verify information */
2147 if (i >= head->info_num) return (2);
2149 /* Save the index */
2152 /* Point at the "info" */
2155 /* Ignore everything */
2156 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2157 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2158 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2159 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2161 /* Store the name */
2162 if (!add_name(&a_ptr->name, head, s)) return (7);
2166 /* There better be a current a_ptr */
2167 else if (!a_ptr) return (3);
2171 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2172 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2173 else if (buf[0] == 'E')
2178 else if (buf[0] == 'E')
2180 /* Acquire the Text */
2183 /* Store the name */
2184 if (!add_name(&a_ptr->name, head, s)) return (7);
2188 /* Process 'D' for "Description" */
2189 else if (buf[0] == 'D')
2194 /* Acquire the text */
2199 /* Acquire the text */
2203 /* Store the text */
2204 if (!add_text(&a_ptr->text, head, s)) return (7);
2208 /* Process 'I' for "Info" (one line only) */
2209 else if (buf[0] == 'I')
2211 int tval, sval, pval;
2213 /* Scan for the values */
2214 if (3 != sscanf(buf+2, "%d:%d:%d",
2215 &tval, &sval, &pval)) return (1);
2217 /* Save the values */
2223 /* Process 'W' for "More Info" (one line only) */
2224 else if (buf[0] == 'W')
2226 int level, rarity, wgt;
2229 /* Scan for the values */
2230 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2231 &level, &rarity, &wgt, &cost)) return (1);
2233 /* Save the values */
2234 a_ptr->level = level;
2235 a_ptr->rarity = rarity;
2236 a_ptr->weight = wgt;
2240 /* Hack -- Process 'P' for "power" and such */
2241 else if (buf[0] == 'P')
2243 int ac, hd1, hd2, th, td, ta;
2245 /* Scan for the values */
2246 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2247 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2257 /* Hack -- Process 'F' for flags */
2258 else if (buf[0] == 'F')
2260 /* Parse every entry textually */
2261 for (s = buf + 2; *s; )
2263 /* Find the end of this entry */
2264 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2266 /* Nuke and skip any dividers */
2270 while ((*t == ' ') || (*t == '|')) t++;
2273 /* Parse this entry */
2274 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2276 /* Start the next entry */
2292 * Grab one flag in a ego-item_type from a textual string
2294 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2299 for (i = 0; i < TR_FLAG_MAX; i++)
2301 if (streq(what, k_info_flags[i]))
2303 add_flag(e_ptr->flags, i);
2308 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2313 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2315 msg_format("Unknown ego-item flag '%s'.", what);
2327 * Initialize the "e_info" array, by parsing an ascii "template" file
2329 errr parse_e_info(char *buf, header *head)
2336 static ego_item_type *e_ptr = NULL;
2339 /* Just before the first record */
2342 /* Just before the first line */
2346 /* Process 'N' for "New/Number/Name" */
2349 /* Find the colon before the name */
2350 s = my_strchr(buf+2, ':');
2352 /* Verify that colon */
2355 /* Nuke the colon, advance to the name */
2358 /* Paranoia -- require a name */
2359 if (!*s) return (1);
2364 /* Verify information */
2365 if (i < error_idx) return (4);
2367 /* Verify information */
2368 if (i >= head->info_num) return (2);
2370 /* Save the index */
2373 /* Point at the "info" */
2376 /* Store the name */
2377 if (!add_name(&e_ptr->name, head, s)) return (7);
2381 /* There better be a current e_ptr */
2382 else if (!e_ptr) return (3);
2386 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2387 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2388 else if (buf[0] == 'E')
2393 else if (buf[0] == 'E')
2395 /* Acquire the Text */
2398 /* Store the name */
2399 if (!add_name(&e_ptr->name, head, s)) return (7);
2404 /* Process 'D' for "Description" */
2405 else if (buf[0] == 'D')
2407 /* Acquire the text */
2410 /* Store the text */
2411 if (!add_text(&e_ptr->text, head, s)) return (7);
2416 /* Process 'X' for "Xtra" (one line only) */
2417 else if (buf[0] == 'X')
2421 /* Scan for the values */
2422 if (2 != sscanf(buf+2, "%d:%d",
2423 &slot, &rating)) return (1);
2425 /* Save the values */
2427 e_ptr->rating = rating;
2430 /* Process 'W' for "More Info" (one line only) */
2431 else if (buf[0] == 'W')
2433 int level, rarity, pad2;
2436 /* Scan for the values */
2437 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2438 &level, &rarity, &pad2, &cost)) return (1);
2440 /* Save the values */
2441 e_ptr->level = level;
2442 e_ptr->rarity = rarity;
2443 /* e_ptr->weight = wgt; */
2447 /* Hack -- Process 'C' for "creation" */
2448 else if (buf[0] == 'C')
2452 /* Scan for the values */
2453 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2454 &th, &td, &ta, &pv)) return (1);
2456 e_ptr->max_to_h = th;
2457 e_ptr->max_to_d = td;
2458 e_ptr->max_to_a = ta;
2459 e_ptr->max_pval = pv;
2462 /* Hack -- Process 'F' for flags */
2463 else if (buf[0] == 'F')
2465 /* Parse every entry textually */
2466 for (s = buf + 2; *s; )
2468 /* Find the end of this entry */
2469 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2471 /* Nuke and skip any dividers */
2475 while ((*t == ' ') || (*t == '|')) t++;
2478 /* Parse this entry */
2479 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2481 /* Start the next entry */
2495 * Grab one (basic) flag in a monster_race from a textual string
2497 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2499 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2502 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2505 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2508 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2511 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2514 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2517 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2522 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2524 msg_format("Unknown monster flag '%s'.", what);
2534 * Grab one (spell) flag in a monster_race from a textual string
2536 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2538 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2541 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2544 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2549 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2551 msg_format("Unknown monster flag '%s'.", what);
2563 * Initialize the "r_info" array, by parsing an ascii "template" file
2565 errr parse_r_info(char *buf, header *head)
2572 static monster_race *r_ptr = NULL;
2575 /* Process 'N' for "New/Number/Name" */
2578 /* Find the colon before the name */
2579 s = my_strchr(buf+2, ':');
2581 /* Verify that colon */
2584 /* Nuke the colon, advance to the name */
2587 /* Paranoia -- require a name */
2588 if (!*s) return (1);
2593 /* Verify information */
2594 if (i < error_idx) return (4);
2596 /* Verify information */
2597 if (i >= head->info_num) return (2);
2599 /* Save the index */
2602 /* Point at the "info" */
2605 /* Store the name */
2606 if (!add_name(&r_ptr->name, head, s)) return (7);
2610 /* There better be a current r_ptr */
2611 else if (!r_ptr) return (3);
2615 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2616 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2617 else if (buf[0] == 'E')
2619 /* Acquire the Text */
2622 /* Store the name */
2623 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2626 else if (buf[0] == 'E')
2628 /* Acquire the Text */
2631 /* Store the name */
2632 if (!add_name(&r_ptr->name, head, s)) return (7);
2635 /* Process 'D' for "Description" */
2636 else if (buf[0] == 'D')
2641 /* Acquire the text */
2646 /* Acquire the text */
2650 /* Store the text */
2651 if (!add_text(&r_ptr->text, head, s)) return (7);
2654 /* Process 'G' for "Graphics" (one line only) */
2655 else if (buf[0] == 'G')
2661 if (buf[1] != ':') return (1);
2662 if (!buf[2]) return (1);
2663 if (buf[3] != ':') return (1);
2664 if (!buf[4]) return (1);
2666 /* Extract the char */
2669 /* Extract the attr */
2670 tmp = color_char_to_attr(buf[4]);
2673 if (tmp > 127) return (1);
2675 /* Save the values */
2676 r_ptr->d_char = sym;
2677 r_ptr->d_attr = tmp;
2680 /* Process 'I' for "Info" (one line only) */
2681 else if (buf[0] == 'I')
2683 int spd, hp1, hp2, aaf, ac, slp;
2685 /* Scan for the other values */
2686 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2687 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2689 /* Save the values */
2698 /* Process 'W' for "More Info" (one line only) */
2699 else if (buf[0] == 'W')
2706 /* Scan for the values */
2707 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2708 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2710 /* Save the values */
2712 r_ptr->rarity = rar;
2715 r_ptr->next_exp = nextexp;
2716 r_ptr->next_r_idx = nextmon;
2719 /* Process 'B' for "Blows" (up to four lines) */
2720 else if (buf[0] == 'B')
2724 /* Find the next empty blow slot (if any) */
2725 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2727 /* Oops, no more slots */
2728 if (i == 4) return (1);
2730 /* Analyze the first field */
2731 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2733 /* Terminate the field (if necessary) */
2734 if (*t == ':') *t++ = '\0';
2736 /* Analyze the method */
2737 for (n1 = 0; r_info_blow_method[n1]; n1++)
2739 if (streq(s, r_info_blow_method[n1])) break;
2742 /* Invalid method */
2743 if (!r_info_blow_method[n1]) return (1);
2745 /* Analyze the second field */
2746 for (s = t; *t && (*t != ':'); t++) /* loop */;
2748 /* Terminate the field (if necessary) */
2749 if (*t == ':') *t++ = '\0';
2751 /* Analyze effect */
2752 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2754 if (streq(s, r_info_blow_effect[n2])) break;
2757 /* Invalid effect */
2758 if (!r_info_blow_effect[n2]) return (1);
2760 /* Analyze the third field */
2761 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2763 /* Terminate the field (if necessary) */
2764 if (*t == 'd') *t++ = '\0';
2766 /* Save the method */
2767 r_ptr->blow[i].method = n1;
2769 /* Save the effect */
2770 r_ptr->blow[i].effect = n2;
2772 /* Extract the damage dice and sides */
2773 r_ptr->blow[i].d_dice = atoi(s);
2774 r_ptr->blow[i].d_side = atoi(t);
2777 /* Process 'F' for "Basic Flags" (multiple lines) */
2778 else if (buf[0] == 'F')
2780 /* Parse every entry */
2781 for (s = buf + 2; *s; )
2783 /* Find the end of this entry */
2784 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2786 /* Nuke and skip any dividers */
2790 while (*t == ' ' || *t == '|') t++;
2793 /* Parse this entry */
2794 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2796 /* Start the next entry */
2801 /* Process 'S' for "Spell Flags" (multiple lines) */
2802 else if (buf[0] == 'S')
2804 /* Parse every entry */
2805 for (s = buf + 2; *s; )
2807 /* Find the end of this entry */
2808 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2810 /* Nuke and skip any dividers */
2814 while ((*t == ' ') || (*t == '|')) t++;
2817 /* XXX XXX XXX Hack -- Read spell frequency */
2818 if (1 == sscanf(s, "1_IN_%d", &i))
2820 /* Extract a "frequency" */
2821 r_ptr->freq_spell = 100 / i;
2823 /* Start at next entry */
2830 /* Parse this entry */
2831 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2833 /* Start the next entry */
2848 * Grab one flag for a dungeon type from a textual string
2850 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2852 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2857 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2859 msg_format("Unknown dungeon type flag '%s'.", what);
2867 * Grab one (basic) flag in a monster_race from a textual string
2869 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2871 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2874 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2877 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2880 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2883 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2886 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2889 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2894 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2896 msg_format("Unknown monster flag '%s'.", what);
2904 * Grab one (spell) flag in a monster_race from a textual string
2906 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2908 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2911 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2914 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2919 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2921 msg_format("Unknown monster flag '%s'.", what);
2929 * Initialize the "d_info" array, by parsing an ascii "template" file
2931 errr parse_d_info(char *buf, header *head)
2938 static dungeon_info_type *d_ptr = NULL;
2941 /* Process 'N' for "New/Number/Name" */
2944 /* Find the colon before the name */
2945 s = my_strchr(buf+2, ':');
2947 /* Verify that colon */
2950 /* Nuke the colon, advance to the name */
2953 /* Paranoia -- require a name */
2954 if (!*s) return (1);
2959 /* Verify information */
2960 if (i < error_idx) return (4);
2962 /* Verify information */
2963 if (i >= head->info_num) return (2);
2965 /* Save the index */
2968 /* Point at the "info" */
2971 /* Store the name */
2972 if (!add_name(&d_ptr->name, head, s)) return (7);
2977 else if (buf[0] == 'E') return (0);
2979 else if (buf[0] == 'E')
2981 /* Acquire the Text */
2984 /* Store the name */
2985 if (!add_name(&d_ptr->name, head, s)) return (7);
2989 /* Process 'D' for "Description */
2990 else if (buf[0] == 'D')
2995 /* Acquire the text */
3000 /* Acquire the text */
3004 /* Store the text */
3005 if (!add_text(&d_ptr->text, head, s)) return (7);
3008 /* Process 'W' for "More Info" (one line only) */
3009 else if (buf[0] == 'W')
3011 int min_lev, max_lev;
3013 int min_alloc, max_chance;
3014 int obj_good, obj_great;
3017 /* Scan for the values */
3018 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3019 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3021 /* Save the values */
3022 d_ptr->mindepth = min_lev;
3023 d_ptr->maxdepth = max_lev;
3024 d_ptr->min_plev = min_plev;
3026 d_ptr->min_m_alloc_level = min_alloc;
3027 d_ptr->max_m_alloc_chance = max_chance;
3028 d_ptr->obj_good = obj_good;
3029 d_ptr->obj_great = obj_great;
3034 /* Process 'P' for "Place Info" */
3035 else if (buf[0] == 'P')
3039 /* Scan for the values */
3040 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3042 /* Save the values */
3047 /* Process 'L' for "fLoor type" (one line only) */
3048 else if (buf[0] == 'L')
3052 /* Scan for the values */
3053 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3055 /* Save the values */
3056 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3058 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3059 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3061 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3064 /* Process 'A' for "wAll type" (one line only) */
3065 else if (buf[0] == 'A')
3069 /* Scan for the values */
3070 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3072 /* Save the values */
3073 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3075 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3076 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3078 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3079 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3080 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3081 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3084 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3085 else if (buf[0] == 'F')
3087 int artif = 0, monst = 0;
3089 /* Parse every entry */
3090 for (s = buf + 2; *s; )
3092 /* Find the end of this entry */
3093 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3095 /* Nuke and skip any dividers */
3099 while (*t == ' ' || *t == '|') t++;
3102 /* XXX XXX XXX Hack -- Read Final Artifact */
3103 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3105 /* Extract a "Final Artifact" */
3106 d_ptr->final_artifact = artif;
3108 /* Start at next entry */
3115 /* XXX XXX XXX Hack -- Read Final Object */
3116 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3118 /* Extract a "Final Artifact" */
3119 d_ptr->final_object = artif;
3121 /* Start at next entry */
3128 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3129 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3131 /* Extract a "Artifact Guardian" */
3132 d_ptr->final_guardian = monst;
3134 /* Start at next entry */
3141 /* XXX XXX XXX Hack -- Read Special Percentage */
3142 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3144 /* Extract a "Special %" */
3145 d_ptr->special_div = monst;
3147 /* Start at next entry */
3154 /* Parse this entry */
3155 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3157 /* Start the next entry */
3162 /* Process 'M' for "Basic Flags" (multiple lines) */
3163 else if (buf[0] == 'M')
3165 /* Parse every entry */
3166 for (s = buf + 2; *s; )
3168 /* Find the end of this entry */
3169 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3171 /* Nuke and skip any dividers */
3175 while (*t == ' ' || *t == '|') t++;
3178 /* Hack -- Read monster symbols */
3179 if (!strncmp(s, "R_CHAR_", 7))
3181 /* Skip "R_CHAR_" */
3185 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3187 /* Start at next entry */
3194 /* Parse this entry */
3195 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3197 /* Start the next entry */
3202 /* Process 'S' for "Spell Flags" (multiple lines) */
3203 else if (buf[0] == 'S')
3205 /* Parse every entry */
3206 for (s = buf + 2; *s; )
3208 /* Find the end of this entry */
3209 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3211 /* Nuke and skip any dividers */
3215 while ((*t == ' ') || (*t == '|')) t++;
3218 /* XXX XXX XXX Hack -- Read spell frequency */
3219 if (1 == sscanf(s, "1_IN_%d", &i))
3221 /* Start at next entry */
3228 /* Parse this entry */
3229 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3231 /* Start the next entry */
3244 #else /* ALLOW_TEMPLATES */
3250 #endif /* ALLOW_TEMPLATES */
3253 /* Random dungeon grid effects */
3254 #define RANDOM_NONE 0x00
3255 #define RANDOM_FEATURE 0x01
3256 #define RANDOM_MONSTER 0x02
3257 #define RANDOM_OBJECT 0x04
3258 #define RANDOM_EGO 0x08
3259 #define RANDOM_ARTIFACT 0x10
3260 #define RANDOM_TRAP 0x20
3263 typedef struct dungeon_grid dungeon_grid;
3267 int feature; /* Terrain feature */
3268 int monster; /* Monster */
3269 int object; /* Object */
3270 int ego; /* Ego-Item */
3271 int artifact; /* Artifact */
3272 int trap; /* Trap */
3273 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3274 int special; /* Reserved for special terrain info */
3275 int random; /* Number of the random effect */
3279 static dungeon_grid letter[255];
3283 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3285 static errr parse_line_feature(char *buf)
3291 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3293 /* Tokenize the line */
3294 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3296 /* Letter to assign */
3297 int index = zz[0][0];
3299 /* Reset the info for the letter */
3300 letter[index].feature = 0;
3301 letter[index].monster = 0;
3302 letter[index].object = 0;
3303 letter[index].ego = 0;
3304 letter[index].artifact = 0;
3305 letter[index].trap = 0;
3306 letter[index].cave_info = 0;
3307 letter[index].special = 0;
3308 letter[index].random = 0;
3314 letter[index].special = atoi(zz[8]);
3318 if (zz[7][0] == '*')
3320 letter[index].random |= RANDOM_TRAP;
3325 letter[index].trap = atoi(zz[7]);
3330 letter[index].trap = atoi(zz[7]);
3335 if (zz[6][0] == '*')
3337 letter[index].random |= RANDOM_ARTIFACT;
3342 letter[index].artifact = atoi(zz[6]);
3347 letter[index].artifact = atoi(zz[6]);
3352 if (zz[5][0] == '*')
3354 letter[index].random |= RANDOM_EGO;
3359 letter[index].ego = atoi(zz[5]);
3364 letter[index].ego = atoi(zz[5]);
3369 if (zz[4][0] == '*')
3371 letter[index].random |= RANDOM_OBJECT;
3376 letter[index].object = atoi(zz[4]);
3381 letter[index].object = atoi(zz[4]);
3386 if (zz[3][0] == '*')
3388 letter[index].random |= RANDOM_MONSTER;
3392 letter[index].monster = atoi(zz[3]);
3395 else if (zz[3][0] == 'c')
3397 letter[index].monster = - atoi(zz[3]+1);
3401 letter[index].monster = atoi(zz[3]);
3406 letter[index].cave_info = atoi(zz[2]);
3410 if (zz[1][0] == '*')
3412 letter[index].random |= RANDOM_FEATURE;
3416 letter[index].feature = atoi(zz[1]);
3421 letter[index].feature = atoi(zz[1]);
3434 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3436 static errr parse_line_building(char *buf)
3452 /* Get the building number */
3455 /* Find the colon after the building number */
3456 s = my_strchr(s, ':');
3458 /* Verify that colon */
3461 /* Nuke the colon, advance to the sub-index */
3464 /* Paranoia -- require a sub-index */
3465 if (!*s) return (1);
3467 /* Building definition sub-index */
3470 /* Building name, owner, race */
3473 if (tokenize(s + 2, 3, zz, 0) == 3)
3475 /* Name of the building */
3476 strcpy(building[index].name, zz[0]);
3478 /* Name of the owner */
3479 strcpy(building[index].owner_name, zz[1]);
3481 /* Race of the owner */
3482 strcpy(building[index].owner_race, zz[2]);
3487 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3490 /* Building Action */
3493 if (tokenize(s + 2, 8, zz, 0) >= 7)
3495 /* Index of the action */
3496 int action_index = atoi(zz[0]);
3498 /* Name of the action */
3499 strcpy(building[index].act_names[action_index], zz[1]);
3501 /* Cost of the action for members */
3502 building[index].member_costs[action_index] = atoi(zz[2]);
3504 /* Cost of the action for non-members */
3505 building[index].other_costs[action_index] = atoi(zz[3]);
3507 /* Letter assigned to the action */
3508 building[index].letters[action_index] = zz[4][0];
3511 building[index].actions[action_index] = atoi(zz[5]);
3513 /* Action restriction */
3514 building[index].action_restr[action_index] = atoi(zz[6]);
3519 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3522 /* Building Classes */
3525 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3527 for (i = 0; i < MAX_CLASS; i++)
3529 building[index].member_class[i] = atoi(zz[i]);
3535 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3538 /* Building Races */
3541 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3543 for (i = 0; i < MAX_RACES; i++)
3545 building[index].member_race[i] = atoi(zz[i]);
3551 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3554 /* Building Realms */
3557 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3559 for (i = 0; i < MAX_MAGIC; i++)
3561 building[index].member_realm[i+1] = atoi(zz[i]);
3567 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3572 /* Ignore scripts */
3578 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3586 static void drop_here(object_type *j_ptr, int by, int bx)
3592 s16b this_o_idx, next_o_idx = 0;
3596 cave_type *c_ptr = &cave[by][bx];
3598 /* Scan objects in that grid for combination */
3599 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
3603 /* Acquire object */
3604 o_ptr = &o_list[this_o_idx];
3606 /* Acquire next object */
3607 next_o_idx = o_ptr->next_o_idx;
3609 /* Check for combination */
3610 if (object_similar(o_ptr, j_ptr))
3612 /* Combine the items */
3613 object_absorb(o_ptr, j_ptr);
3623 /* Get new object */
3624 if (!done) o_idx = o_pop();
3630 /* Structure copy */
3631 object_copy(&o_list[o_idx], j_ptr);
3633 /* Access new object */
3634 j_ptr = &o_list[o_idx];
3641 j_ptr->held_m_idx = 0;
3644 j_ptr->next_o_idx = c_ptr->o_idx;
3646 /* Place the object */
3647 c_ptr->o_idx = o_idx;
3658 * Parse a sub-file of the "extra info"
3660 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3667 /* Skip "empty" lines */
3668 if (!buf[0]) return (0);
3670 /* Skip "blank" lines */
3671 if (isspace(buf[0])) return (0);
3674 if (buf[0] == '#') return (0);
3676 /* Require "?:*" format */
3677 if (buf[1] != ':') return (1);
3680 /* Process "%:<fname>" */
3683 /* Attempt to Process the given file */
3684 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3687 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3690 return parse_line_feature(buf);
3693 /* Process "D:<dungeon>" -- info for the cave grids */
3694 else if (buf[0] == 'D')
3696 object_type object_type_body;
3698 /* Acquire the text */
3701 /* Length of the text */
3702 int len = strlen(s);
3704 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3706 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3708 /* Access the grid */
3709 cave_type *c_ptr = &cave[*y][*x];
3713 int object_index = letter[idx].object;
3714 int monster_index = letter[idx].monster;
3715 int random = letter[idx].random;
3716 int artifact_index = letter[idx].artifact;
3718 /* Lay down a floor */
3719 c_ptr->feat = letter[idx].feature;
3721 /* Only the features */
3722 if (init_flags & INIT_ONLY_FEATURES) continue;
3725 c_ptr->info = letter[idx].cave_info;
3727 /* Create a monster */
3728 if (random & RANDOM_MONSTER)
3730 monster_level = base_level + monster_index;
3732 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3734 monster_level = base_level;
3736 else if (monster_index)
3738 int old_cur_num, old_max_num;
3741 if (monster_index < 0)
3743 monster_index = -monster_index;
3746 old_cur_num = r_info[monster_index].cur_num;
3747 old_max_num = r_info[monster_index].max_num;
3749 /* Make alive again */
3750 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3752 r_info[monster_index].cur_num = 0;
3753 r_info[monster_index].max_num = 1;
3756 /* Make alive again */
3757 /* Hack -- Non-unique Nazguls are semi-unique */
3758 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3760 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3762 r_info[monster_index].max_num++;
3767 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3771 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3773 /* Make alive again for real unique monster */
3774 r_info[monster_index].cur_num = old_cur_num;
3775 r_info[monster_index].max_num = old_max_num;
3779 /* Object (and possible trap) */
3780 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3782 object_level = base_level + object_index;
3785 * Random trap and random treasure defined
3786 * 25% chance for trap and 75% chance for object
3788 if (randint0(100) < 75)
3790 place_object(*y, *x, 0L);
3797 object_level = base_level;
3799 else if (random & RANDOM_OBJECT)
3801 object_level = base_level + object_index;
3803 /* Create an out of deep object */
3804 if (randint0(100) < 75)
3805 place_object(*y, *x, 0L);
3806 else if (randint0(100) < 80)
3807 place_object(*y, *x, AM_GOOD);
3809 place_object(*y, *x, AM_GOOD | AM_GREAT);
3811 object_level = base_level;
3814 else if (random & RANDOM_TRAP)
3818 /* Hidden trap (or door) */
3819 else if (letter[idx].trap)
3821 c_ptr->mimic = c_ptr->feat;
3822 c_ptr->feat = letter[idx].trap;
3824 else if (object_index)
3826 /* Get local object */
3827 object_type *o_ptr = &object_type_body;
3829 /* Create the item */
3830 object_prep(o_ptr, object_index);
3832 if (o_ptr->tval == TV_GOLD)
3834 coin_type = object_index - OBJ_GOLD_LIST;
3839 /* Apply magic (no messages, no artifacts) */
3840 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3842 drop_here(o_ptr, *y, *x);
3848 if (a_info[artifact_index].cur_num)
3850 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3852 object_type *q_ptr = &forge;
3854 object_prep(q_ptr, k_idx);
3856 /* Drop it in the dungeon */
3857 drop_here(q_ptr, *y, *x);
3861 /* Create the artifact */
3862 create_named_art(artifact_index, *y, *x);
3864 a_info[artifact_index].cur_num = 1;
3868 /* Terrain special */
3869 c_ptr->special = letter[idx].special;
3877 /* Process "Q:<number>:<command>:... -- quest info */
3878 else if (buf[0] == 'Q')
3885 num = tokenize(buf + 2, 33, zz, 0);
3889 num = tokenize(buf + 3, 33, zz, 0);
3892 /* Have we enough parameters? */
3893 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3896 q_ptr = &(quest[atoi(zz[0])]);
3898 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3899 if (zz[1][0] == 'Q')
3901 if (init_flags & INIT_ASSIGN)
3903 monster_race *r_ptr;
3904 artifact_type *a_ptr;
3906 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3908 q_ptr->type = atoi(zz[2]);
3909 q_ptr->num_mon = atoi(zz[3]);
3910 q_ptr->cur_num = atoi(zz[4]);
3911 q_ptr->max_num = atoi(zz[5]);
3912 q_ptr->level = atoi(zz[6]);
3913 q_ptr->r_idx = atoi(zz[7]);
3914 q_ptr->k_idx = atoi(zz[8]);
3915 q_ptr->dungeon = atoi(zz[9]);
3918 q_ptr->flags = atoi(zz[10]);
3920 r_ptr = &r_info[q_ptr->r_idx];
3921 if (r_ptr->flags1 & RF1_UNIQUE)
3922 r_ptr->flags1 |= RF1_QUESTOR;
3924 a_ptr = &a_info[q_ptr->k_idx];
3925 a_ptr->gen_flags |= TRG_QUESTITEM;
3930 /* Process "Q:<q_index>:N:<name>" -- quest name */
3931 else if (zz[1][0] == 'N')
3933 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3935 strcpy(q_ptr->name, zz[2]);
3941 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3942 else if (zz[1][0] == 'T')
3944 if (init_flags & INIT_SHOW_TEXT)
3946 strcpy(quest_text[quest_text_line], zz[2]);
3954 /* Process "W:<command>: ..." -- info for the wilderness */
3955 else if (buf[0] == 'W')
3957 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3960 /* Process "P:<y>:<x>" -- player position */
3961 else if (buf[0] == 'P')
3963 if (init_flags & INIT_CREATE_DUNGEON)
3965 if (tokenize(buf + 2, 2, zz, 0) == 2)
3967 int panels_x, panels_y;
3969 /* Hack - Set the dungeon size */
3970 panels_y = (*y / SCREEN_HGT);
3971 if (*y % SCREEN_HGT) panels_y++;
3972 cur_hgt = panels_y * SCREEN_HGT;
3974 panels_x = (*x / SCREEN_WID);
3975 if (*x % SCREEN_WID) panels_x++;
3976 cur_wid = panels_x * SCREEN_WID;
3978 /* Assume illegal panel */
3979 panel_row_min = cur_hgt;
3980 panel_col_min = cur_wid;
3982 /* Place player in a quest level */
3983 if (p_ptr->inside_quest)
3987 /* Delete the monster (if any) */
3988 delete_monster(py, px);
3996 /* Place player in the town */
3997 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3999 p_ptr->oldpy = atoi(zz[0]);
4000 p_ptr->oldpx = atoi(zz[1]);
4008 /* Process "B:<Index>:<Command>:..." -- Building definition */
4009 else if (buf[0] == 'B')
4011 return parse_line_building(buf);
4014 /* Process "M:<type>:<maximum>" -- set maximum values */
4015 else if (buf[0] == 'M')
4017 if (tokenize(buf+2, 2, zz, 0) == 2)
4020 if (zz[0][0] == 'T')
4022 max_towns = atoi(zz[1]);
4025 /* Maximum quests */
4026 else if (zz[0][0] == 'Q')
4028 max_quests = atoi(zz[1]);
4032 else if (zz[0][0] == 'R')
4034 max_r_idx = atoi(zz[1]);
4038 else if (zz[0][0] == 'K')
4040 max_k_idx = atoi(zz[1]);
4044 else if (zz[0][0] == 'V')
4046 max_v_idx = atoi(zz[1]);
4050 else if (zz[0][0] == 'F')
4052 max_f_idx = atoi(zz[1]);
4056 else if (zz[0][0] == 'A')
4058 max_a_idx = atoi(zz[1]);
4062 else if (zz[0][0] == 'E')
4064 max_e_idx = atoi(zz[1]);
4068 else if (zz[0][0] == 'D')
4070 max_d_idx = atoi(zz[1]);
4074 else if (zz[0][0] == 'O')
4076 max_o_idx = atoi(zz[1]);
4080 else if (zz[0][0] == 'M')
4082 max_m_idx = atoi(zz[1]);
4085 /* Wilderness size */
4086 else if (zz[0][0] == 'W')
4088 /* Maximum wild_x_size */
4089 if (zz[0][1] == 'X')
4090 max_wild_x = atoi(zz[1]);
4091 /* Maximum wild_y_size */
4092 if (zz[0][1] == 'Y')
4093 max_wild_y = atoi(zz[1]);
4107 static cptr variant = "ZANGBAND";
4111 * Helper function for "process_dungeon_file()"
4113 static cptr process_dungeon_file_expr(char **sp, char *fp)
4129 while (isspace(*s)) s++;
4147 t = process_dungeon_file_expr(&s, &f);
4156 else if (streq(t, "IOR"))
4159 while (*s && (f != b2))
4161 t = process_dungeon_file_expr(&s, &f);
4162 if (*t && !streq(t, "0")) v = "1";
4167 else if (streq(t, "AND"))
4170 while (*s && (f != b2))
4172 t = process_dungeon_file_expr(&s, &f);
4173 if (*t && streq(t, "0")) v = "0";
4178 else if (streq(t, "NOT"))
4181 while (*s && (f != b2))
4183 t = process_dungeon_file_expr(&s, &f);
4184 if (*t && streq(t, "1")) v = "0";
4189 else if (streq(t, "EQU"))
4192 if (*s && (f != b2))
4194 t = process_dungeon_file_expr(&s, &f);
4196 while (*s && (f != b2))
4198 p = process_dungeon_file_expr(&s, &f);
4199 if (streq(t, p)) v = "1";
4204 else if (streq(t, "LEQ"))
4207 if (*s && (f != b2))
4209 t = process_dungeon_file_expr(&s, &f);
4211 while (*s && (f != b2))
4214 t = process_dungeon_file_expr(&s, &f);
4215 if (*t && atoi(p) > atoi(t)) v = "0";
4220 else if (streq(t, "GEQ"))
4223 if (*s && (f != b2))
4225 t = process_dungeon_file_expr(&s, &f);
4227 while (*s && (f != b2))
4230 t = process_dungeon_file_expr(&s, &f);
4232 /* Compare two numbers instead of string */
4233 if (*t && atoi(p) < atoi(t)) v = "0";
4240 while (*s && (f != b2))
4242 t = process_dungeon_file_expr(&s, &f);
4247 if (f != b2) v = "?x?x?";
4249 /* Extract final and Terminate */
4250 if ((f = *s) != '\0') *s++ = '\0';
4256 /* Accept all printables except spaces and brackets */
4257 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4259 /* Extract final and Terminate */
4260 if ((f = *s) != '\0') *s++ = '\0';
4266 if (streq(b+1, "SYS"))
4272 else if (streq(b+1, "GRAF"))
4277 else if (streq(b+1, "MONOCHROME"))
4286 else if (streq(b+1, "RACE"))
4289 v = rp_ptr->E_title;
4296 else if (streq(b+1, "CLASS"))
4299 v = cp_ptr->E_title;
4306 else if (streq(b+1, "REALM1"))
4309 v = E_realm_names[p_ptr->realm1];
4311 v = realm_names[p_ptr->realm1];
4316 else if (streq(b+1, "REALM2"))
4319 v = E_realm_names[p_ptr->realm2];
4321 v = realm_names[p_ptr->realm2];
4326 else if (streq(b+1, "PLAYER"))
4332 else if (streq(b+1, "TOWN"))
4334 sprintf(tmp, "%d", p_ptr->town_num);
4339 else if (streq(b+1, "LEVEL"))
4341 sprintf(tmp, "%d", p_ptr->lev);
4345 /* Current quest number */
4346 else if (streq(b+1, "QUEST_NUMBER"))
4348 sprintf(tmp, "%d", p_ptr->inside_quest);
4352 /* Number of last quest */
4353 else if (streq(b+1, "LEAVING_QUEST"))
4355 sprintf(tmp, "%d", leaving_quest);
4360 else if (prefix(b+1, "QUEST"))
4362 /* "QUEST" uses a special parameter to determine the number of the quest */
4363 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4368 else if (prefix(b+1, "RANDOM"))
4370 /* "RANDOM" uses a special parameter to determine the number of the quest */
4371 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4376 else if (streq(b+1, "VARIANT"))
4382 else if (streq(b+1, "WILDERNESS"))
4385 sprintf(tmp, "NONE");
4387 sprintf(tmp, "LITE");
4389 sprintf(tmp, "NORMAL");
4412 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4422 bool bypass = FALSE;
4424 int x = xmin, y = ymin;
4427 /* Build the filename */
4428 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4431 fp = my_fopen(buf, "r");
4434 if (!fp) return (-1);
4437 /* Process the file */
4438 while (0 == my_fgets(fp, buf, sizeof(buf)))
4444 /* Skip "empty" lines */
4445 if (!buf[0]) continue;
4447 /* Skip "blank" lines */
4448 if (isspace(buf[0])) continue;
4451 if (buf[0] == '#') continue;
4454 /* Process "?:<expr>" */
4455 if ((buf[0] == '?') && (buf[1] == ':'))
4464 /* Parse the expr */
4465 v = process_dungeon_file_expr(&s, &f);
4468 bypass = (streq(v, "0") ? TRUE : FALSE);
4474 /* Apply conditionals */
4475 if (bypass) continue;
4477 /* Process the line */
4478 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4490 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4493 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4495 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4497 msg_format("Parsing '%s'.", buf);
4504 /* Close the file */
4514 void write_r_info_txt(void)
4516 int i, j, z, fc, bc;
4519 cptr flags[32 * 10];
4524 monster_race *r_ptr;
4526 monster_blow *b_ptr;
4528 FILE *fff = fopen("output.txt", "wt");
4536 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4538 fprintf(fff, "# Version stamp (required)\n\n");
4541 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4544 fprintf(fff, "##### The Player #####\n\n");
4546 for (z = -1; z < alloc_race_size; z++)
4548 /* Output the monsters in order */
4549 i = (z >= 0) ? alloc_race_table[z].index : 0;
4551 /* Acquire the monster */
4554 /* Ignore empty monsters */
4555 if (!strlen(r_name + r_ptr->name)) continue;
4557 /* Ignore useless monsters */
4558 if (i && !r_ptr->speed) continue;
4560 /* Write a note if necessary */
4561 if (i && (!r_ptr->level != !mode))
4566 fprintf(fff, "\n##### Town monsters #####\n\n");
4568 /* Note the dungeon */
4571 fprintf(fff, "\n##### Normal monsters #####\n\n");
4574 /* Record the change */
4575 mode = r_ptr->level;
4578 /* Acquire the flags */
4579 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4580 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4581 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4582 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4583 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4584 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4585 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4586 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4587 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4588 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4590 /* Write New/Number/Name */
4591 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4594 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4596 /* Write Information */
4597 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4598 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4600 /* Write more information */
4601 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4604 for(j = 0; j < 4; j++)
4606 b_ptr = &(r_ptr->blow[j]);
4608 /* Stop when done */
4609 if (!b_ptr->method) break;
4611 /* Write the blows */
4612 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4613 r_info_blow_effect[b_ptr->effect],
4614 b_ptr->d_dice, b_ptr->d_side);
4617 /* Extract the flags */
4618 for (fc = 0, j = 0; j < 32 * 3; j++)
4620 /* Check this flag */
4621 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4624 /* Extract the extra flags */
4625 for (j = 32 * 6; j < 32 * 10; j++)
4627 /* Check this flag */
4628 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4631 /* Write the flags */
4632 for (j = 0; j < fc;)
4636 /* Start the line */
4639 for (bc = 0; (bc < 60) && (j < fc); j++)
4643 /* Format the flag */
4644 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4646 /* Add it to the buffer */
4649 /* Note the length */
4653 /* Done with this line; write it */
4654 fprintf(fff, "%s\n", buf);
4657 /* Write Spells if applicable */
4658 if (r_ptr->freq_spell)
4660 /* Write the frequency */
4661 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4663 /* Extract the spell flags */
4664 for (fc = 0, j = 96; j < 192; j++)
4666 /* Check this flag */
4667 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4670 /* Write the flags */
4671 for (j = 0; j < fc;)
4675 /* Start the line */
4678 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4682 /* Format the flag */
4683 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4687 /* Note the length */
4694 /* Done with this line; write it */
4695 fprintf(fff, "%s\n", buf);
4699 /* Acquire the description */
4700 desc = r_text + r_ptr->text;
4701 dlen = strlen(desc);
4703 /* Write Description */
4704 for (j = 0; j < dlen;)
4708 /* Start the line */
4711 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4719 /* Done with this line; write it */
4720 fprintf(fff, "%s\n", buf);
4723 /* Space between entries */