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[] =
256 static cptr r_info_flags1[] =
295 static cptr r_info_flags2[] =
334 static cptr r_info_flags3[] =
373 static cptr r_info_flags4[] =
412 static cptr r_info_flags5[] =
451 static cptr r_info_flags6[] =
468 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
491 static cptr r_info_flags7[] =
530 static cptr r_info_flags8[] =
562 "WILD_SWAMP", /* ToDo: Implement Swamp */
568 * Monster race flags - Drops
570 static cptr r_info_flags9[] =
609 * Monster race flags - Resistances
611 static cptr r_info_flagsr[] =
651 static cptr k_info_flags[] =
776 static cptr k_info_gen_flags[] =
816 static cptr d_info_flags1[] =
854 * Add a text to the text-storage and store offset to it.
856 * Returns FALSE when there isn't enough space available to store
859 static bool add_text(u32b *offset, header *head, cptr buf)
861 /* Hack -- Verify space */
862 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
868 /* Advance and save the text index */
869 *offset = ++head->text_size;
872 /* Append chars to the text */
873 strcpy(head->text_ptr + head->text_size, buf);
875 /* Advance the index */
876 head->text_size += strlen(buf);
884 * Add a name to the name-storage and return an offset to it.
886 * Returns FALSE when there isn't enough space available to store
889 static bool add_name(u32b *offset, header *head, cptr buf)
891 /* Hack -- Verify space */
892 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
898 /* Advance and save the name index */
899 *offset = ++head->name_size;
902 /* Append chars to the names */
903 strcpy(head->name_ptr + head->name_size, buf);
905 /* Advance the index */
906 head->name_size += strlen(buf);
914 * Add a tag to the tag-storage and return an offset to it.
916 * Returns FALSE when there isn't enough space available to store
919 static bool add_tag(s16b *offset, header *head, cptr buf)
923 /* Search for an existing (fake) tag */
924 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
927 if (streq(&head->tag_ptr[i], buf)) break;
930 /* There was no existing tag */
931 if (i >= head->tag_size)
933 /* Hack -- Verify space */
934 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
937 /* Append chars to the tags */
938 strcpy(head->tag_ptr + head->tag_size, buf);
940 /* Point the new tag */
943 /* Advance the index */
944 head->tag_size += strlen(buf) + 1;
947 /* Return offset of the tag */
956 * Convert a "color letter" into an "actual" color
957 * The colors are: dwsorgbuDWvyRGBU, as shown below
959 byte color_char_to_attr(char c)
963 case 'd': return (TERM_DARK);
964 case 'w': return (TERM_WHITE);
965 case 's': return (TERM_SLATE);
966 case 'o': return (TERM_ORANGE);
967 case 'r': return (TERM_RED);
968 case 'g': return (TERM_GREEN);
969 case 'b': return (TERM_BLUE);
970 case 'u': return (TERM_UMBER);
972 case 'D': return (TERM_L_DARK);
973 case 'W': return (TERM_L_WHITE);
974 case 'v': return (TERM_VIOLET);
975 case 'y': return (TERM_YELLOW);
976 case 'R': return (TERM_L_RED);
977 case 'G': return (TERM_L_GREEN);
978 case 'B': return (TERM_L_BLUE);
979 case 'U': return (TERM_L_UMBER);
987 /*** Initialize from ascii template files ***/
991 * Initialize an "*_info" array, by parsing an ascii "template" file
993 errr init_info_txt(FILE *fp, char *buf, header *head,
994 parse_info_txt_func parse_info_txt_line)
998 /* Just before the first record */
1001 /* Just before the first line */
1005 /* Prepare the "fake" stuff */
1006 head->name_size = 0;
1007 head->text_size = 0;
1011 while (0 == my_fgets(fp, buf, 1024))
1013 /* Advance the line number */
1016 /* Skip comments and blank lines */
1017 if (!buf[0] || (buf[0] == '#')) continue;
1019 /* Verify correct "colon" format */
1020 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1023 /* Hack -- Process 'V' for "Version" */
1030 /* Mega Hack -- Calculate Check Sum */
1031 if (buf[0] != 'N' && buf[0] != 'D')
1034 for (i = 0; buf[i]; i++)
1036 head->v_extra += (byte)buf[i];
1037 head->v_extra ^= (1 << (i % 8));
1041 /* Parse the line */
1042 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1047 /* Complete the "name" and "text" sizes */
1048 if (head->name_size) head->name_size++;
1049 if (head->text_size) head->text_size++;
1057 * Initialize the "v_info" array, by parsing an ascii "template" file
1059 errr parse_v_info(char *buf, header *head)
1065 static vault_type *v_ptr = NULL;
1067 /* Process 'N' for "New/Number/Name" */
1070 /* Find the colon before the name */
1071 s = my_strchr(buf+2, ':');
1073 /* Verify that colon */
1076 /* Nuke the colon, advance to the name */
1079 /* Paranoia -- require a name */
1080 if (!*s) return (1);
1085 /* Verify information */
1086 if (i <= error_idx) return (4);
1088 /* Verify information */
1089 if (i >= head->info_num) return (2);
1091 /* Save the index */
1094 /* Point at the "info" */
1097 /* Store the name */
1098 if (!add_name(&v_ptr->name, head, s)) return (7);
1101 /* There better be a current v_ptr */
1102 else if (!v_ptr) return (3);
1104 /* Process 'D' for "Description" */
1105 else if (buf[0] == 'D')
1107 /* Acquire the text */
1110 /* Store the text */
1111 if (!add_text(&v_ptr->text, head, s)) return (7);
1114 /* Process 'X' for "Extra info" (one line only) */
1115 else if (buf[0] == 'X')
1117 int typ, rat, hgt, wid;
1119 /* Scan for the values */
1120 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1121 &typ, &rat, &hgt, &wid)) return (1);
1123 /* Save the values */
1140 * Initialize the "s_info" array, by parsing an ascii "template" file
1142 errr parse_s_info(char *buf, header *head)
1147 static skill_table *s_ptr = NULL;
1150 /* Process 'N' for "New/Number/Name" */
1156 /* Verify information */
1157 if (i <= error_idx) return (4);
1159 /* Verify information */
1160 if (i >= head->info_num) return (2);
1162 /* Save the index */
1165 /* Point at the "info" */
1169 /* There better be a current s_ptr */
1170 else if (!s_ptr) return (3);
1172 /* Process 'W' for "Weapon exp" */
1173 else if (buf[0] == 'W')
1175 int tval, sval, start, max;
1176 const s16b exp_conv_table[] =
1178 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1179 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1182 /* Scan for the values */
1183 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1184 &tval, &sval, &start, &max)) return (1);
1186 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1187 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1189 /* Save the values */
1190 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1191 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1194 /* Process 'S' for "Skill exp" */
1195 else if (buf[0] == 'S')
1197 int num, start, max;
1199 /* Scan for the values */
1200 if (3 != sscanf(buf+2, "%d:%d:%d",
1201 &num, &start, &max)) return (1);
1203 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1204 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1206 /* Save the values */
1207 s_ptr->s_start[num] = start;
1208 s_ptr->s_max[num] = max;
1221 * Initialize the "m_info" array, by parsing an ascii "template" file
1223 errr parse_m_info(char *buf, header *head)
1230 static player_magic *m_ptr = NULL;
1233 static int realm, magic_idx = 0, readable = 0;
1236 /* Process 'N' for "New/Number/Name" */
1242 /* Verify information */
1243 if (i <= error_idx) return (4);
1245 /* Verify information */
1246 if (i >= head->info_num) return (2);
1248 /* Save the index */
1251 /* Point at the "info" */
1255 /* There better be a current m_ptr */
1256 else if (!m_ptr) return (3);
1258 /* Process 'I' for "Info" (one line only) */
1259 else if (buf[0] == 'I')
1262 int xtra, type, first, weight;
1264 /* Find the colon before the name */
1265 s = my_strchr(buf+2, ':');
1267 /* Verify that colon */
1270 /* Nuke the colon, advance to the name */
1275 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1276 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1277 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1278 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1279 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1284 /* Find the colon before the name */
1285 s = my_strchr(s, ':');
1287 /* Verify that colon */
1290 /* Nuke the colon, advance to the name */
1293 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1294 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1295 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1296 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1297 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1298 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1302 /* Scan for the values */
1303 if (4 != sscanf(s, "%x:%d:%d:%d",
1304 (uint *)&xtra, &type, &first, &weight)) return (1);
1306 m_ptr->spell_xtra = xtra;
1307 m_ptr->spell_type = type;
1308 m_ptr->spell_first = first;
1309 m_ptr->spell_weight = weight;
1313 /* Process 'R' for "Realm" (one line only) */
1314 else if (buf[0] == 'R')
1316 /* Scan for the values */
1317 if (2 != sscanf(buf+2, "%d:%d",
1318 &realm, &readable)) return (1);
1323 else if (buf[0] == 'T')
1325 int level, mana, fail, exp;
1327 if (!readable) return (1);
1328 /* Scan for the values */
1329 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1330 &level, &mana, &fail, &exp)) return (1);
1332 m_ptr->info[realm][magic_idx].slevel = level;
1333 m_ptr->info[realm][magic_idx].smana = mana;
1334 m_ptr->info[realm][magic_idx].sfail = fail;
1335 m_ptr->info[realm][magic_idx].sexp = exp;
1349 * Grab one flag from a textual string
1351 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1356 for (i = 0; i < 32; i++)
1358 if (streq(what, names[i]))
1360 *flags |= (1L << i);
1370 * Grab one flag in an feature_type from a textual string
1372 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1377 for (i = 0; i < FF_FLAG_MAX; i++)
1379 if (streq(what, f_info_flags[i]))
1381 add_flag(f_ptr->flags, i);
1388 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1390 msg_format("Unknown feature flag '%s'.", what);
1394 return PARSE_ERROR_GENERIC;
1399 * Grab an action in an feature_type from a textual string
1401 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1406 for (i = 0; i < FF_FLAG_MAX; i++)
1408 if (streq(what, f_info_flags[i]))
1410 f_ptr->state[count].action = i;
1417 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1419 msg_format("Unknown feature action '%s'.", what);
1423 return PARSE_ERROR_GENERIC;
1428 * Initialize the "f_info" array, by parsing an ascii "template" file
1430 errr parse_f_info(char *buf, header *head)
1437 static feature_type *f_ptr = NULL;
1440 /* Process 'N' for "New/Number/Name" */
1443 /* Find the colon before the name */
1444 s = my_strchr(buf+2, ':');
1448 /* Nuke the colon, advance to the name */
1455 /* Verify information */
1456 if (i <= error_idx) return (4);
1458 /* Verify information */
1459 if (i >= head->info_num) return (2);
1461 /* Save the index */
1464 /* Point at the "info" */
1467 /* Tag name is given */
1471 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1474 /* Default "mimic" */
1477 /* Default "destroyed state" -- if not specified */
1478 f_ptr->destroyed = i;
1480 /* Default "states" */
1481 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1484 /* There better be a current f_ptr */
1485 else if (!f_ptr) return (3);
1488 else if (buf[0] == 'J')
1490 /* Store the name */
1491 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1494 else if (buf[0] == 'E')
1496 /* Ignore english name */
1499 else if (buf[0] == 'J')
1501 /* Ignore Japanese name */
1504 else if (buf[0] == 'E')
1506 /* Acquire the Text */
1509 /* Store the name */
1510 if (!add_name(&f_ptr->name, head, s)) return (7);
1515 /* Process 'M' for "Mimic" (one line only) */
1516 else if (buf[0] == 'M')
1520 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1522 /* Record a fake tag index */
1523 f_ptr->mimic = -offset;
1527 /* Process 'G' for "Graphics" (one line only) */
1528 else if (buf[0] == 'G')
1531 byte def_attr[F_LIT_MAX];
1532 char char_tmp[F_LIT_MAX];
1535 if (buf[1] != ':') return (1);
1536 if (!buf[2]) return (1);
1537 if (buf[3] != ':') return (1);
1538 if (!buf[4]) return (1);
1540 /* Extract the char */
1541 char_tmp[F_LIT_STANDARD] = buf[2];
1543 /* Extract the color */
1544 def_attr[F_LIT_STANDARD] = color_char_to_attr(buf[4]);
1547 if (def_attr[F_LIT_STANDARD] > 127) return (1);
1549 /* Save the default values for lighting */
1550 for (j = 0; j < F_LIT_MAX; j++)
1552 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1553 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1556 /* Is this feature supports lighting? */
1559 def_attr[F_LIT_LITE] = lighting_colours[def_attr[F_LIT_STANDARD]][0];
1560 def_attr[F_LIT_DARK] = lighting_colours[def_attr[F_LIT_STANDARD]][1];
1561 def_attr[F_LIT_DARKDARK] = lighting_colours[lighting_colours[def_attr[F_LIT_STANDARD]][1]][1];
1563 /* G:c:a:LIT (default) */
1564 if (streq(buf + 6, "LIT"))
1566 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1568 f_ptr->d_attr[j] = def_attr[j];
1572 /* G:c:a:lc:la:dc:da:Dc:Da */
1575 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1577 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c:%c:%c",
1578 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1579 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN],
1580 &char_tmp[F_LIT_DARKDARK], &attr_lite_tmp[F_LIT_DARKDARK - F_LIT_NS_BEGIN])) return 1;
1581 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1583 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1585 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1588 /* Use default lighting */
1589 f_ptr->d_attr[j] = def_attr[j];
1592 /* No lighting support */
1593 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1596 /* Extract the color */
1597 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1598 if (f_ptr->d_attr[j] > 127) return 1;
1601 f_ptr->d_char[j] = char_tmp[j];
1605 else if (buf[5]) return 1;
1608 /* Hack -- Process 'F' for flags */
1609 else if (buf[0] == 'F')
1611 /* Parse every entry textually */
1612 for (s = buf + 2; *s; )
1614 /* Find the end of this entry */
1615 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1617 /* Nuke and skip any dividers */
1621 while (*t == ' ' || *t == '|') t++;
1624 /* XXX XXX XXX Hack -- Read feature power */
1625 if (1 == sscanf(s, "POWER_%d", &i))
1627 /* Extract a "power" */
1630 /* Start at next entry */
1637 /* Parse this entry */
1638 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1640 /* Start the next entry */
1645 /* Process 'W' for "More Info" (one line only) */
1646 else if (buf[0] == 'W')
1650 /* Scan for the value */
1651 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1653 /* Save the value */
1654 f_ptr->priority = priority;
1657 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1658 else if (buf[0] == 'K')
1662 /* Find the next empty state slot (if any) */
1663 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1665 /* Oops, no more slots */
1666 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1668 /* Analyze the first field */
1669 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1671 /* Terminate the field (if necessary) */
1672 if (*t == ':') *t++ = '\0';
1674 /* Is this default entry? */
1675 if (streq(s, "DESTROYED"))
1677 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1679 /* Record a fake tag index */
1680 f_ptr->destroyed = -offset;
1685 f_ptr->state[i].action = 0;
1687 /* Parse this entry */
1688 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1690 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1692 /* Record a fake tag index */
1693 f_ptr->state[i].result = -offset;
1706 * Convert a fake tag to a real feat index
1708 s16b f_tag_to_index(cptr str)
1712 /* Search for real index corresponding to this fake tag */
1713 for (i = 0; i < f_head.info_num; i++)
1715 if (streq(f_tag + f_info[i].tag, str))
1717 /* Return the index */
1728 * Search for real index corresponding to this fake tag
1730 static void search_real_feat(s16b *feat)
1734 /* Don't convert non-fake tag */
1735 if (*feat >= 0) return;
1737 /* Search for real index corresponding to this fake tag */
1738 for (i = 0; i < f_head.info_num; i++)
1740 if ((-(*feat)) == f_info[i].tag)
1742 /* Record real index */
1750 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1752 msg_format("%s is undefined.", f_tag + (-(*feat)));
1758 * Retouch fake tags of f_info
1760 void retouch_f_info(header *head)
1764 /* Convert fake tags to real feat indices */
1765 for (i = 0; i < head->info_num; i++)
1767 feature_type *f_ptr = &f_info[i];
1770 search_real_feat(&f_ptr->mimic);
1772 search_real_feat(&f_ptr->destroyed);
1774 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1780 * Grab one flag in an object_kind from a textual string
1782 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1787 for (i = 0; i < TR_FLAG_MAX; i++)
1789 if (streq(what, k_info_flags[i]))
1791 add_flag(k_ptr->flags, i);
1796 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1801 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1803 msg_format("Unknown object flag '%s'.", what);
1813 * Initialize the "k_info" array, by parsing an ascii "template" file
1815 errr parse_k_info(char *buf, header *head)
1822 static object_kind *k_ptr = NULL;
1825 /* Process 'N' for "New/Number/Name" */
1828 /* Find the colon before the name */
1829 s = my_strchr(buf+2, ':');
1831 /* Verify that colon */
1834 /* Nuke the colon, advance to the name */
1838 /* Paranoia -- require a name */
1839 if (!*s) return (1);
1844 /* Verify information */
1845 if (i <= error_idx) return (4);
1847 /* Verify information */
1848 if (i >= head->info_num) return (2);
1850 /* Save the index */
1853 /* Point at the "info" */
1857 /* Store the name */
1858 if (!add_name(&k_ptr->name, head, s)) return (7);
1862 /* There better be a current k_ptr */
1863 else if (!k_ptr) return (3);
1867 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1868 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1869 else if (buf[0] == 'E')
1874 else if (buf[0] == 'E')
1876 /* Acquire the Text */
1879 /* Store the name */
1880 if (!add_name(&k_ptr->name, head, s)) return (7);
1884 /* Process 'D' for "Description" */
1885 else if (buf[0] == 'D')
1890 /* Acquire the text */
1895 /* Acquire the text */
1899 /* Store the text */
1900 if (!add_text(&k_ptr->text, head, s)) return (7);
1903 /* Process 'G' for "Graphics" (one line only) */
1904 else if (buf[0] == 'G')
1910 if (buf[1] != ':') return (1);
1911 if (!buf[2]) return (1);
1912 if (buf[3] != ':') return (1);
1913 if (!buf[4]) return (1);
1915 /* Extract the char */
1918 /* Extract the attr */
1919 tmp = color_char_to_attr(buf[4]);
1922 if (tmp > 127) return (1);
1924 /* Save the values */
1925 k_ptr->d_attr = tmp;
1926 k_ptr->d_char = sym;
1929 /* Process 'I' for "Info" (one line only) */
1930 else if (buf[0] == 'I')
1932 int tval, sval, pval;
1934 /* Scan for the values */
1935 if (3 != sscanf(buf+2, "%d:%d:%d",
1936 &tval, &sval, &pval)) return (1);
1938 /* Save the values */
1944 /* Process 'W' for "More Info" (one line only) */
1945 else if (buf[0] == 'W')
1947 int level, extra, wgt;
1950 /* Scan for the values */
1951 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1952 &level, &extra, &wgt, &cost)) return (1);
1954 /* Save the values */
1955 k_ptr->level = level;
1956 k_ptr->extra = extra;
1957 k_ptr->weight = wgt;
1961 /* Process 'A' for "Allocation" (one line only) */
1962 else if (buf[0] == 'A')
1966 /* XXX XXX XXX Simply read each number following a colon */
1967 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1969 /* Default chance */
1970 k_ptr->chance[i] = 1;
1972 /* Store the attack damage index */
1973 k_ptr->locale[i] = atoi(s+1);
1975 /* Find the slash */
1976 t = my_strchr(s+1, '/');
1978 /* Find the next colon */
1979 s = my_strchr(s+1, ':');
1981 /* If the slash is "nearby", use it */
1982 if (t && (!s || t < s))
1984 int chance = atoi(t+1);
1985 if (chance > 0) k_ptr->chance[i] = chance;
1990 /* Hack -- Process 'P' for "power" and such */
1991 else if (buf[0] == 'P')
1993 int ac, hd1, hd2, th, td, ta;
1995 /* Scan for the values */
1996 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1997 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2007 /* Hack -- Process 'F' for flags */
2008 else if (buf[0] == 'F')
2010 /* Parse every entry textually */
2011 for (s = buf + 2; *s; )
2013 /* Find the end of this entry */
2014 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2016 /* Nuke and skip any dividers */
2020 while (*t == ' ' || *t == '|') t++;
2023 /* Parse this entry */
2024 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2026 /* Start the next entry */
2042 * Grab one flag in an artifact_type from a textual string
2044 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2049 for (i = 0; i < TR_FLAG_MAX; i++)
2051 if (streq(what, k_info_flags[i]))
2053 add_flag(a_ptr->flags, i);
2058 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2063 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2065 msg_format("Unknown artifact flag '%s'.", what);
2077 * Initialize the "a_info" array, by parsing an ascii "template" file
2079 errr parse_a_info(char *buf, header *head)
2086 static artifact_type *a_ptr = NULL;
2089 /* Process 'N' for "New/Number/Name" */
2092 /* Find the colon before the name */
2093 s = my_strchr(buf+2, ':');
2095 /* Verify that colon */
2098 /* Nuke the colon, advance to the name */
2101 /* Paranoia -- require a name */
2102 if (!*s) return (1);
2107 /* Verify information */
2108 if (i < error_idx) return (4);
2110 /* Verify information */
2111 if (i >= head->info_num) return (2);
2113 /* Save the index */
2116 /* Point at the "info" */
2119 /* Ignore everything */
2120 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2121 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2122 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2123 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2125 /* Store the name */
2126 if (!add_name(&a_ptr->name, head, s)) return (7);
2130 /* There better be a current a_ptr */
2131 else if (!a_ptr) return (3);
2135 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2136 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2137 else if (buf[0] == 'E')
2142 else if (buf[0] == 'E')
2144 /* Acquire the Text */
2147 /* Store the name */
2148 if (!add_name(&a_ptr->name, head, s)) return (7);
2152 /* Process 'D' for "Description" */
2153 else if (buf[0] == 'D')
2158 /* Acquire the text */
2163 /* Acquire the text */
2167 /* Store the text */
2168 if (!add_text(&a_ptr->text, head, s)) return (7);
2172 /* Process 'I' for "Info" (one line only) */
2173 else if (buf[0] == 'I')
2175 int tval, sval, pval;
2177 /* Scan for the values */
2178 if (3 != sscanf(buf+2, "%d:%d:%d",
2179 &tval, &sval, &pval)) return (1);
2181 /* Save the values */
2187 /* Process 'W' for "More Info" (one line only) */
2188 else if (buf[0] == 'W')
2190 int level, rarity, wgt;
2193 /* Scan for the values */
2194 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2195 &level, &rarity, &wgt, &cost)) return (1);
2197 /* Save the values */
2198 a_ptr->level = level;
2199 a_ptr->rarity = rarity;
2200 a_ptr->weight = wgt;
2204 /* Hack -- Process 'P' for "power" and such */
2205 else if (buf[0] == 'P')
2207 int ac, hd1, hd2, th, td, ta;
2209 /* Scan for the values */
2210 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2211 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2221 /* Hack -- Process 'F' for flags */
2222 else if (buf[0] == 'F')
2224 /* Parse every entry textually */
2225 for (s = buf + 2; *s; )
2227 /* Find the end of this entry */
2228 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2230 /* Nuke and skip any dividers */
2234 while ((*t == ' ') || (*t == '|')) t++;
2237 /* Parse this entry */
2238 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2240 /* Start the next entry */
2256 * Grab one flag in a ego-item_type from a textual string
2258 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2263 for (i = 0; i < TR_FLAG_MAX; i++)
2265 if (streq(what, k_info_flags[i]))
2267 add_flag(e_ptr->flags, i);
2272 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2277 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2279 msg_format("Unknown ego-item flag '%s'.", what);
2291 * Initialize the "e_info" array, by parsing an ascii "template" file
2293 errr parse_e_info(char *buf, header *head)
2300 static ego_item_type *e_ptr = NULL;
2303 /* Just before the first record */
2306 /* Just before the first line */
2310 /* Process 'N' for "New/Number/Name" */
2313 /* Find the colon before the name */
2314 s = my_strchr(buf+2, ':');
2316 /* Verify that colon */
2319 /* Nuke the colon, advance to the name */
2322 /* Paranoia -- require a name */
2323 if (!*s) return (1);
2328 /* Verify information */
2329 if (i < error_idx) return (4);
2331 /* Verify information */
2332 if (i >= head->info_num) return (2);
2334 /* Save the index */
2337 /* Point at the "info" */
2340 /* Store the name */
2341 if (!add_name(&e_ptr->name, head, s)) return (7);
2345 /* There better be a current e_ptr */
2346 else if (!e_ptr) return (3);
2350 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2351 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2352 else if (buf[0] == 'E')
2357 else if (buf[0] == 'E')
2359 /* Acquire the Text */
2362 /* Store the name */
2363 if (!add_name(&e_ptr->name, head, s)) return (7);
2368 /* Process 'D' for "Description" */
2369 else if (buf[0] == 'D')
2371 /* Acquire the text */
2374 /* Store the text */
2375 if (!add_text(&e_ptr->text, head, s)) return (7);
2380 /* Process 'X' for "Xtra" (one line only) */
2381 else if (buf[0] == 'X')
2385 /* Scan for the values */
2386 if (2 != sscanf(buf+2, "%d:%d",
2387 &slot, &rating)) return (1);
2389 /* Save the values */
2391 e_ptr->rating = rating;
2394 /* Process 'W' for "More Info" (one line only) */
2395 else if (buf[0] == 'W')
2397 int level, rarity, pad2;
2400 /* Scan for the values */
2401 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2402 &level, &rarity, &pad2, &cost)) return (1);
2404 /* Save the values */
2405 e_ptr->level = level;
2406 e_ptr->rarity = rarity;
2407 /* e_ptr->weight = wgt; */
2411 /* Hack -- Process 'C' for "creation" */
2412 else if (buf[0] == 'C')
2416 /* Scan for the values */
2417 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2418 &th, &td, &ta, &pv)) return (1);
2420 e_ptr->max_to_h = th;
2421 e_ptr->max_to_d = td;
2422 e_ptr->max_to_a = ta;
2423 e_ptr->max_pval = pv;
2426 /* Hack -- Process 'F' for flags */
2427 else if (buf[0] == 'F')
2429 /* Parse every entry textually */
2430 for (s = buf + 2; *s; )
2432 /* Find the end of this entry */
2433 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2435 /* Nuke and skip any dividers */
2439 while ((*t == ' ') || (*t == '|')) t++;
2442 /* Parse this entry */
2443 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2445 /* Start the next entry */
2459 * Grab one (basic) flag in a monster_race from a textual string
2461 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2463 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2466 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2469 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2472 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2475 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2478 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2481 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2486 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2488 msg_format("Unknown monster flag '%s'.", what);
2498 * Grab one (spell) flag in a monster_race from a textual string
2500 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2502 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2505 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2508 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2513 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2515 msg_format("Unknown monster flag '%s'.", what);
2527 * Initialize the "r_info" array, by parsing an ascii "template" file
2529 errr parse_r_info(char *buf, header *head)
2536 static monster_race *r_ptr = NULL;
2539 /* Process 'N' for "New/Number/Name" */
2542 /* Find the colon before the name */
2543 s = my_strchr(buf+2, ':');
2545 /* Verify that colon */
2548 /* Nuke the colon, advance to the name */
2551 /* Paranoia -- require a name */
2552 if (!*s) return (1);
2557 /* Verify information */
2558 if (i < error_idx) return (4);
2560 /* Verify information */
2561 if (i >= head->info_num) return (2);
2563 /* Save the index */
2566 /* Point at the "info" */
2569 /* Store the name */
2570 if (!add_name(&r_ptr->name, head, s)) return (7);
2574 /* There better be a current r_ptr */
2575 else if (!r_ptr) return (3);
2579 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2580 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2581 else if (buf[0] == 'E')
2583 /* Acquire the Text */
2586 /* Store the name */
2587 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2590 else if (buf[0] == 'E')
2592 /* Acquire the Text */
2595 /* Store the name */
2596 if (!add_name(&r_ptr->name, head, s)) return (7);
2599 /* Process 'D' for "Description" */
2600 else if (buf[0] == 'D')
2605 /* Acquire the text */
2610 /* Acquire the text */
2614 /* Store the text */
2615 if (!add_text(&r_ptr->text, head, s)) return (7);
2618 /* Process 'G' for "Graphics" (one line only) */
2619 else if (buf[0] == 'G')
2625 if (buf[1] != ':') return (1);
2626 if (!buf[2]) return (1);
2627 if (buf[3] != ':') return (1);
2628 if (!buf[4]) return (1);
2630 /* Extract the char */
2633 /* Extract the attr */
2634 tmp = color_char_to_attr(buf[4]);
2637 if (tmp > 127) return (1);
2639 /* Save the values */
2640 r_ptr->d_char = sym;
2641 r_ptr->d_attr = tmp;
2644 /* Process 'I' for "Info" (one line only) */
2645 else if (buf[0] == 'I')
2647 int spd, hp1, hp2, aaf, ac, slp;
2649 /* Scan for the other values */
2650 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2651 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2653 /* Save the values */
2662 /* Process 'W' for "More Info" (one line only) */
2663 else if (buf[0] == 'W')
2670 /* Scan for the values */
2671 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2672 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2674 /* Save the values */
2676 r_ptr->rarity = rar;
2679 r_ptr->next_exp = nextexp;
2680 r_ptr->next_r_idx = nextmon;
2683 /* Process 'B' for "Blows" (up to four lines) */
2684 else if (buf[0] == 'B')
2688 /* Find the next empty blow slot (if any) */
2689 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2691 /* Oops, no more slots */
2692 if (i == 4) return (1);
2694 /* Analyze the first field */
2695 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2697 /* Terminate the field (if necessary) */
2698 if (*t == ':') *t++ = '\0';
2700 /* Analyze the method */
2701 for (n1 = 0; r_info_blow_method[n1]; n1++)
2703 if (streq(s, r_info_blow_method[n1])) break;
2706 /* Invalid method */
2707 if (!r_info_blow_method[n1]) return (1);
2709 /* Analyze the second field */
2710 for (s = t; *t && (*t != ':'); t++) /* loop */;
2712 /* Terminate the field (if necessary) */
2713 if (*t == ':') *t++ = '\0';
2715 /* Analyze effect */
2716 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2718 if (streq(s, r_info_blow_effect[n2])) break;
2721 /* Invalid effect */
2722 if (!r_info_blow_effect[n2]) return (1);
2724 /* Analyze the third field */
2725 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2727 /* Terminate the field (if necessary) */
2728 if (*t == 'd') *t++ = '\0';
2730 /* Save the method */
2731 r_ptr->blow[i].method = n1;
2733 /* Save the effect */
2734 r_ptr->blow[i].effect = n2;
2736 /* Extract the damage dice and sides */
2737 r_ptr->blow[i].d_dice = atoi(s);
2738 r_ptr->blow[i].d_side = atoi(t);
2741 /* Process 'F' for "Basic Flags" (multiple lines) */
2742 else if (buf[0] == 'F')
2744 /* Parse every entry */
2745 for (s = buf + 2; *s; )
2747 /* Find the end of this entry */
2748 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2750 /* Nuke and skip any dividers */
2754 while (*t == ' ' || *t == '|') t++;
2757 /* Parse this entry */
2758 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2760 /* Start the next entry */
2765 /* Process 'S' for "Spell Flags" (multiple lines) */
2766 else if (buf[0] == 'S')
2768 /* Parse every entry */
2769 for (s = buf + 2; *s; )
2771 /* Find the end of this entry */
2772 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2774 /* Nuke and skip any dividers */
2778 while ((*t == ' ') || (*t == '|')) t++;
2781 /* XXX XXX XXX Hack -- Read spell frequency */
2782 if (1 == sscanf(s, "1_IN_%d", &i))
2784 /* Extract a "frequency" */
2785 r_ptr->freq_spell = 100 / i;
2787 /* Start at next entry */
2794 /* Parse this entry */
2795 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2797 /* Start the next entry */
2812 * Grab one flag for a dungeon type from a textual string
2814 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2816 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2821 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2823 msg_format("Unknown dungeon type flag '%s'.", what);
2831 * Grab one (basic) flag in a monster_race from a textual string
2833 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2835 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2838 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2841 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2844 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2847 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2850 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2853 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2858 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2860 msg_format("Unknown monster flag '%s'.", what);
2868 * Grab one (spell) flag in a monster_race from a textual string
2870 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2872 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2875 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2878 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2883 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2885 msg_format("Unknown monster flag '%s'.", what);
2893 * Initialize the "d_info" array, by parsing an ascii "template" file
2895 errr parse_d_info(char *buf, header *head)
2902 static dungeon_info_type *d_ptr = NULL;
2905 /* Process 'N' for "New/Number/Name" */
2908 /* Find the colon before the name */
2909 s = my_strchr(buf+2, ':');
2911 /* Verify that colon */
2914 /* Nuke the colon, advance to the name */
2917 /* Paranoia -- require a name */
2918 if (!*s) return (1);
2923 /* Verify information */
2924 if (i < error_idx) return (4);
2926 /* Verify information */
2927 if (i >= head->info_num) return (2);
2929 /* Save the index */
2932 /* Point at the "info" */
2935 /* Store the name */
2936 if (!add_name(&d_ptr->name, head, s)) return (7);
2941 else if (buf[0] == 'E') return (0);
2943 else if (buf[0] == 'E')
2945 /* Acquire the Text */
2948 /* Store the name */
2949 if (!add_name(&d_ptr->name, head, s)) return (7);
2953 /* Process 'D' for "Description */
2954 else if (buf[0] == 'D')
2959 /* Acquire the text */
2964 /* Acquire the text */
2968 /* Store the text */
2969 if (!add_text(&d_ptr->text, head, s)) return (7);
2972 /* Process 'W' for "More Info" (one line only) */
2973 else if (buf[0] == 'W')
2975 int min_lev, max_lev;
2977 int min_alloc, max_chance;
2978 int obj_good, obj_great;
2981 /* Scan for the values */
2982 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2983 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2985 /* Save the values */
2986 d_ptr->mindepth = min_lev;
2987 d_ptr->maxdepth = max_lev;
2988 d_ptr->min_plev = min_plev;
2990 d_ptr->min_m_alloc_level = min_alloc;
2991 d_ptr->max_m_alloc_chance = max_chance;
2992 d_ptr->obj_good = obj_good;
2993 d_ptr->obj_great = obj_great;
2998 /* Process 'P' for "Place Info" */
2999 else if (buf[0] == 'P')
3003 /* Scan for the values */
3004 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3006 /* Save the values */
3011 /* Process 'L' for "fLoor type" (one line only) */
3012 else if (buf[0] == 'L')
3016 /* Scan for the values */
3017 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3019 /* Save the values */
3020 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3022 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3023 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3025 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3027 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3030 /* Process 'A' for "wAll type" (one line only) */
3031 else if (buf[0] == 'A')
3035 /* Scan for the values */
3036 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3038 /* Save the values */
3039 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3041 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3042 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3044 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3047 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3048 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3050 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3051 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3053 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3054 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3056 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3057 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3060 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3061 else if (buf[0] == 'F')
3063 int artif = 0, monst = 0;
3065 /* Parse every entry */
3066 for (s = buf + 2; *s; )
3068 /* Find the end of this entry */
3069 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3071 /* Nuke and skip any dividers */
3075 while (*t == ' ' || *t == '|') t++;
3078 /* XXX XXX XXX Hack -- Read Final Artifact */
3079 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3081 /* Extract a "Final Artifact" */
3082 d_ptr->final_artifact = artif;
3084 /* Start at next entry */
3091 /* XXX XXX XXX Hack -- Read Final Object */
3092 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3094 /* Extract a "Final Artifact" */
3095 d_ptr->final_object = artif;
3097 /* Start at next entry */
3104 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3105 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3107 /* Extract a "Artifact Guardian" */
3108 d_ptr->final_guardian = monst;
3110 /* Start at next entry */
3117 /* XXX XXX XXX Hack -- Read Special Percentage */
3118 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3120 /* Extract a "Special %" */
3121 d_ptr->special_div = monst;
3123 /* Start at next entry */
3130 /* Parse this entry */
3131 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3133 /* Start the next entry */
3138 /* Process 'M' for "Basic Flags" (multiple lines) */
3139 else if (buf[0] == 'M')
3141 /* Parse every entry */
3142 for (s = buf + 2; *s; )
3144 /* Find the end of this entry */
3145 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3147 /* Nuke and skip any dividers */
3151 while (*t == ' ' || *t == '|') t++;
3154 /* Hack -- Read monster symbols */
3155 if (!strncmp(s, "R_CHAR_", 7))
3157 /* Skip "R_CHAR_" */
3161 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3163 /* Start at next entry */
3170 /* Parse this entry */
3171 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3173 /* Start the next entry */
3178 /* Process 'S' for "Spell Flags" (multiple lines) */
3179 else if (buf[0] == 'S')
3181 /* Parse every entry */
3182 for (s = buf + 2; *s; )
3184 /* Find the end of this entry */
3185 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3187 /* Nuke and skip any dividers */
3191 while ((*t == ' ') || (*t == '|')) t++;
3194 /* XXX XXX XXX Hack -- Read spell frequency */
3195 if (1 == sscanf(s, "1_IN_%d", &i))
3197 /* Start at next entry */
3204 /* Parse this entry */
3205 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3207 /* Start the next entry */
3220 #else /* ALLOW_TEMPLATES */
3226 #endif /* ALLOW_TEMPLATES */
3229 /* Random dungeon grid effects */
3230 #define RANDOM_NONE 0x00000000
3231 #define RANDOM_FEATURE 0x00000001
3232 #define RANDOM_MONSTER 0x00000002
3233 #define RANDOM_OBJECT 0x00000004
3234 #define RANDOM_EGO 0x00000008
3235 #define RANDOM_ARTIFACT 0x00000010
3236 #define RANDOM_TRAP 0x00000020
3237 #define RANDOM_FEAT_MIMIC 0x00000040
3240 typedef struct dungeon_grid dungeon_grid;
3244 int feature; /* Terrain feature */
3245 int monster; /* Monster */
3246 int object; /* Object */
3247 int ego; /* Ego-Item */
3248 int artifact; /* Artifact */
3249 int trap; /* Trap */
3250 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3251 int special; /* Reserved for special terrain info */
3252 int feat_mimic; /* Reserved for terrain mimic info */
3253 int random; /* Number of the random effect */
3257 static dungeon_grid letter[255];
3261 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3263 static errr parse_line_feature(char *buf)
3269 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3271 /* Tokenize the line */
3272 if ((num = tokenize(buf+2, 10, zz, 0)) > 1)
3274 /* Letter to assign */
3275 int index = zz[0][0];
3277 /* Reset the info for the letter */
3278 letter[index].feature = FEAT_NONE;
3279 letter[index].monster = 0;
3280 letter[index].object = 0;
3281 letter[index].ego = 0;
3282 letter[index].artifact = 0;
3283 letter[index].trap = FEAT_NONE;
3284 letter[index].cave_info = 0;
3285 letter[index].special = 0;
3286 letter[index].feat_mimic = FEAT_NONE;
3287 letter[index].random = RANDOM_NONE;
3293 if ((zz[9][0] == '*') && !zz[9][1])
3295 letter[index].random |= RANDOM_FEAT_MIMIC;
3299 letter[index].feat_mimic = f_tag_to_index(zz[9]);
3300 if (letter[index].feat_mimic < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3305 letter[index].special = atoi(zz[8]);
3309 if ((zz[7][0] == '*') && !zz[7][1])
3311 letter[index].random |= RANDOM_TRAP;
3315 letter[index].trap = f_tag_to_index(zz[7]);
3316 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3321 if (zz[6][0] == '*')
3323 letter[index].random |= RANDOM_ARTIFACT;
3324 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3328 letter[index].artifact = atoi(zz[6]);
3333 if (zz[5][0] == '*')
3335 letter[index].random |= RANDOM_EGO;
3336 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3340 letter[index].ego = atoi(zz[5]);
3345 if (zz[4][0] == '*')
3347 letter[index].random |= RANDOM_OBJECT;
3348 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3352 letter[index].object = atoi(zz[4]);
3357 if (zz[3][0] == '*')
3359 letter[index].random |= RANDOM_MONSTER;
3360 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3362 else if (zz[3][0] == 'c')
3364 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3365 letter[index].monster = - atoi(zz[3] + 1);
3369 letter[index].monster = atoi(zz[3]);
3374 letter[index].cave_info = atoi(zz[2]);
3378 if ((zz[1][0] == '*') && !zz[1][1])
3380 letter[index].random |= RANDOM_FEATURE;
3384 letter[index].feature = f_tag_to_index(zz[1]);
3385 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3398 * Process "B:<Index>:<Command>:..." -- Building definition
3400 static errr parse_line_building(char *buf)
3416 /* Get the building number */
3419 /* Find the colon after the building number */
3420 s = my_strchr(s, ':');
3422 /* Verify that colon */
3425 /* Nuke the colon, advance to the sub-index */
3428 /* Paranoia -- require a sub-index */
3429 if (!*s) return (1);
3431 /* Building definition sub-index */
3434 /* Building name, owner, race */
3437 if (tokenize(s + 2, 3, zz, 0) == 3)
3439 /* Name of the building */
3440 strcpy(building[index].name, zz[0]);
3442 /* Name of the owner */
3443 strcpy(building[index].owner_name, zz[1]);
3445 /* Race of the owner */
3446 strcpy(building[index].owner_race, zz[2]);
3451 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3454 /* Building Action */
3457 if (tokenize(s + 2, 8, zz, 0) >= 7)
3459 /* Index of the action */
3460 int action_index = atoi(zz[0]);
3462 /* Name of the action */
3463 strcpy(building[index].act_names[action_index], zz[1]);
3465 /* Cost of the action for members */
3466 building[index].member_costs[action_index] = atoi(zz[2]);
3468 /* Cost of the action for non-members */
3469 building[index].other_costs[action_index] = atoi(zz[3]);
3471 /* Letter assigned to the action */
3472 building[index].letters[action_index] = zz[4][0];
3475 building[index].actions[action_index] = atoi(zz[5]);
3477 /* Action restriction */
3478 building[index].action_restr[action_index] = atoi(zz[6]);
3483 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3486 /* Building Classes */
3489 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3491 for (i = 0; i < MAX_CLASS; i++)
3493 building[index].member_class[i] = atoi(zz[i]);
3499 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3502 /* Building Races */
3505 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3507 for (i = 0; i < MAX_RACES; i++)
3509 building[index].member_race[i] = atoi(zz[i]);
3515 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3518 /* Building Realms */
3521 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3523 for (i = 0; i < MAX_MAGIC; i++)
3525 building[index].member_realm[i+1] = atoi(zz[i]);
3531 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3536 /* Ignore scripts */
3542 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3551 * Place the object j_ptr to a grid
3553 static void drop_here(object_type *j_ptr, int y, int x)
3555 cave_type *c_ptr = &cave[y][x];
3558 /* Get new object */
3559 s16b o_idx = o_pop();
3561 /* Access new object */
3562 o_ptr = &o_list[o_idx];
3564 /* Structure copy */
3565 object_copy(o_ptr, j_ptr);
3573 o_ptr->held_m_idx = 0;
3576 o_ptr->next_o_idx = c_ptr->o_idx;
3578 /* Place the object */
3579 c_ptr->o_idx = o_idx;
3584 * Parse a sub-file of the "extra info"
3586 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3593 /* Skip "empty" lines */
3594 if (!buf[0]) return (0);
3596 /* Skip "blank" lines */
3597 if (isspace(buf[0])) return (0);
3600 if (buf[0] == '#') return (0);
3602 /* Require "?:*" format */
3603 if (buf[1] != ':') return (1);
3606 /* Process "%:<fname>" */
3609 /* Attempt to Process the given file */
3610 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3613 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3616 return parse_line_feature(buf);
3619 /* Process "D:<dungeon>" -- info for the cave grids */
3620 else if (buf[0] == 'D')
3622 object_type object_type_body;
3624 /* Acquire the text */
3627 /* Length of the text */
3628 int len = strlen(s);
3630 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3632 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3634 /* Access the grid */
3635 cave_type *c_ptr = &cave[*y][*x];
3639 int object_index = letter[idx].object;
3640 int monster_index = letter[idx].monster;
3641 int random = letter[idx].random;
3642 int artifact_index = letter[idx].artifact;
3644 /* Lay down a floor */
3645 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3646 c_ptr->mimic = conv_dungeon_feat(letter[idx].feat_mimic);
3648 /* Only the features */
3649 if (init_flags & INIT_ONLY_FEATURES) continue;
3652 c_ptr->info = letter[idx].cave_info;
3654 /* Create a monster */
3655 if (random & RANDOM_MONSTER)
3657 monster_level = base_level + monster_index;
3659 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3661 monster_level = base_level;
3663 else if (monster_index)
3665 int old_cur_num, old_max_num;
3668 if (monster_index < 0)
3670 monster_index = -monster_index;
3673 old_cur_num = r_info[monster_index].cur_num;
3674 old_max_num = r_info[monster_index].max_num;
3676 /* Make alive again */
3677 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3679 r_info[monster_index].cur_num = 0;
3680 r_info[monster_index].max_num = 1;
3683 /* Make alive again */
3684 /* Hack -- Non-unique Nazguls are semi-unique */
3685 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3687 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3689 r_info[monster_index].max_num++;
3694 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3698 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3700 /* Make alive again for real unique monster */
3701 r_info[monster_index].cur_num = old_cur_num;
3702 r_info[monster_index].max_num = old_max_num;
3706 /* Object (and possible trap) */
3707 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3709 object_level = base_level + object_index;
3712 * Random trap and random treasure defined
3713 * 25% chance for trap and 75% chance for object
3715 if (randint0(100) < 75)
3717 place_object(*y, *x, 0L);
3721 if (c_ptr->mimic) c_ptr->feat = c_ptr->mimic;
3725 object_level = base_level;
3727 else if (random & RANDOM_OBJECT)
3729 object_level = base_level + object_index;
3731 /* Create an out of deep object */
3732 if (randint0(100) < 75)
3733 place_object(*y, *x, 0L);
3734 else if (randint0(100) < 80)
3735 place_object(*y, *x, AM_GOOD);
3737 place_object(*y, *x, AM_GOOD | AM_GREAT);
3739 object_level = base_level;
3742 else if (random & RANDOM_TRAP)
3744 if (c_ptr->mimic) c_ptr->feat = c_ptr->mimic;
3747 /* Hidden trap (or door) */
3748 else if (letter[idx].trap)
3750 if (!c_ptr->mimic) c_ptr->mimic = c_ptr->feat;
3751 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3753 else if (object_index)
3755 /* Get local object */
3756 object_type *o_ptr = &object_type_body;
3758 /* Create the item */
3759 object_prep(o_ptr, object_index);
3761 if (o_ptr->tval == TV_GOLD)
3763 coin_type = object_index - OBJ_GOLD_LIST;
3768 /* Apply magic (no messages, no artifacts) */
3769 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3771 drop_here(o_ptr, *y, *x);
3777 if (a_info[artifact_index].cur_num)
3779 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3781 object_type *q_ptr = &forge;
3783 object_prep(q_ptr, k_idx);
3785 /* Drop it in the dungeon */
3786 drop_here(q_ptr, *y, *x);
3790 /* Create the artifact */
3791 create_named_art(artifact_index, *y, *x);
3793 a_info[artifact_index].cur_num = 1;
3797 /* Terrain special */
3798 c_ptr->special = letter[idx].special;
3806 /* Process "Q:<number>:<command>:... -- quest info */
3807 else if (buf[0] == 'Q')
3814 num = tokenize(buf + 2, 33, zz, 0);
3818 num = tokenize(buf + 3, 33, zz, 0);
3821 /* Have we enough parameters? */
3822 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3825 q_ptr = &(quest[atoi(zz[0])]);
3827 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3828 if (zz[1][0] == 'Q')
3830 if (init_flags & INIT_ASSIGN)
3832 monster_race *r_ptr;
3833 artifact_type *a_ptr;
3835 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3837 q_ptr->type = atoi(zz[2]);
3838 q_ptr->num_mon = atoi(zz[3]);
3839 q_ptr->cur_num = atoi(zz[4]);
3840 q_ptr->max_num = atoi(zz[5]);
3841 q_ptr->level = atoi(zz[6]);
3842 q_ptr->r_idx = atoi(zz[7]);
3843 q_ptr->k_idx = atoi(zz[8]);
3844 q_ptr->dungeon = atoi(zz[9]);
3847 q_ptr->flags = atoi(zz[10]);
3849 r_ptr = &r_info[q_ptr->r_idx];
3850 if (r_ptr->flags1 & RF1_UNIQUE)
3851 r_ptr->flags1 |= RF1_QUESTOR;
3853 a_ptr = &a_info[q_ptr->k_idx];
3854 a_ptr->gen_flags |= TRG_QUESTITEM;
3859 /* Process "Q:<q_index>:N:<name>" -- quest name */
3860 else if (zz[1][0] == 'N')
3862 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3864 strcpy(q_ptr->name, zz[2]);
3870 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3871 else if (zz[1][0] == 'T')
3873 if (init_flags & INIT_SHOW_TEXT)
3875 strcpy(quest_text[quest_text_line], zz[2]);
3883 /* Process "W:<command>: ..." -- info for the wilderness */
3884 else if (buf[0] == 'W')
3886 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3889 /* Process "P:<y>:<x>" -- player position */
3890 else if (buf[0] == 'P')
3892 if (init_flags & INIT_CREATE_DUNGEON)
3894 if (tokenize(buf + 2, 2, zz, 0) == 2)
3896 int panels_x, panels_y;
3898 /* Hack - Set the dungeon size */
3899 panels_y = (*y / SCREEN_HGT);
3900 if (*y % SCREEN_HGT) panels_y++;
3901 cur_hgt = panels_y * SCREEN_HGT;
3903 panels_x = (*x / SCREEN_WID);
3904 if (*x % SCREEN_WID) panels_x++;
3905 cur_wid = panels_x * SCREEN_WID;
3907 /* Assume illegal panel */
3908 panel_row_min = cur_hgt;
3909 panel_col_min = cur_wid;
3911 /* Place player in a quest level */
3912 if (p_ptr->inside_quest)
3916 /* Delete the monster (if any) */
3917 delete_monster(py, px);
3925 /* Place player in the town */
3926 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3928 p_ptr->oldpy = atoi(zz[0]);
3929 p_ptr->oldpx = atoi(zz[1]);
3937 /* Process "B:<Index>:<Command>:..." -- Building definition */
3938 else if (buf[0] == 'B')
3940 return parse_line_building(buf);
3943 /* Process "M:<type>:<maximum>" -- set maximum values */
3944 else if (buf[0] == 'M')
3946 if (tokenize(buf+2, 2, zz, 0) == 2)
3949 if (zz[0][0] == 'T')
3951 max_towns = atoi(zz[1]);
3954 /* Maximum quests */
3955 else if (zz[0][0] == 'Q')
3957 max_quests = atoi(zz[1]);
3961 else if (zz[0][0] == 'R')
3963 max_r_idx = atoi(zz[1]);
3967 else if (zz[0][0] == 'K')
3969 max_k_idx = atoi(zz[1]);
3973 else if (zz[0][0] == 'V')
3975 max_v_idx = atoi(zz[1]);
3979 else if (zz[0][0] == 'F')
3981 max_f_idx = atoi(zz[1]);
3985 else if (zz[0][0] == 'A')
3987 max_a_idx = atoi(zz[1]);
3991 else if (zz[0][0] == 'E')
3993 max_e_idx = atoi(zz[1]);
3997 else if (zz[0][0] == 'D')
3999 max_d_idx = atoi(zz[1]);
4003 else if (zz[0][0] == 'O')
4005 max_o_idx = atoi(zz[1]);
4009 else if (zz[0][0] == 'M')
4011 max_m_idx = atoi(zz[1]);
4014 /* Wilderness size */
4015 else if (zz[0][0] == 'W')
4017 /* Maximum wild_x_size */
4018 if (zz[0][1] == 'X')
4019 max_wild_x = atoi(zz[1]);
4020 /* Maximum wild_y_size */
4021 if (zz[0][1] == 'Y')
4022 max_wild_y = atoi(zz[1]);
4036 static cptr variant = "ZANGBAND";
4040 * Helper function for "process_dungeon_file()"
4042 static cptr process_dungeon_file_expr(char **sp, char *fp)
4058 while (isspace(*s)) s++;
4076 t = process_dungeon_file_expr(&s, &f);
4085 else if (streq(t, "IOR"))
4088 while (*s && (f != b2))
4090 t = process_dungeon_file_expr(&s, &f);
4091 if (*t && !streq(t, "0")) v = "1";
4096 else if (streq(t, "AND"))
4099 while (*s && (f != b2))
4101 t = process_dungeon_file_expr(&s, &f);
4102 if (*t && streq(t, "0")) v = "0";
4107 else if (streq(t, "NOT"))
4110 while (*s && (f != b2))
4112 t = process_dungeon_file_expr(&s, &f);
4113 if (*t && streq(t, "1")) v = "0";
4118 else if (streq(t, "EQU"))
4121 if (*s && (f != b2))
4123 t = process_dungeon_file_expr(&s, &f);
4125 while (*s && (f != b2))
4127 p = process_dungeon_file_expr(&s, &f);
4128 if (streq(t, p)) v = "1";
4133 else if (streq(t, "LEQ"))
4136 if (*s && (f != b2))
4138 t = process_dungeon_file_expr(&s, &f);
4140 while (*s && (f != b2))
4143 t = process_dungeon_file_expr(&s, &f);
4144 if (*t && atoi(p) > atoi(t)) v = "0";
4149 else if (streq(t, "GEQ"))
4152 if (*s && (f != b2))
4154 t = process_dungeon_file_expr(&s, &f);
4156 while (*s && (f != b2))
4159 t = process_dungeon_file_expr(&s, &f);
4161 /* Compare two numbers instead of string */
4162 if (*t && atoi(p) < atoi(t)) v = "0";
4169 while (*s && (f != b2))
4171 t = process_dungeon_file_expr(&s, &f);
4176 if (f != b2) v = "?x?x?";
4178 /* Extract final and Terminate */
4179 if ((f = *s) != '\0') *s++ = '\0';
4185 /* Accept all printables except spaces and brackets */
4186 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4188 /* Extract final and Terminate */
4189 if ((f = *s) != '\0') *s++ = '\0';
4195 if (streq(b+1, "SYS"))
4201 else if (streq(b+1, "GRAF"))
4206 else if (streq(b+1, "MONOCHROME"))
4215 else if (streq(b+1, "RACE"))
4218 v = rp_ptr->E_title;
4225 else if (streq(b+1, "CLASS"))
4228 v = cp_ptr->E_title;
4235 else if (streq(b+1, "REALM1"))
4238 v = E_realm_names[p_ptr->realm1];
4240 v = realm_names[p_ptr->realm1];
4245 else if (streq(b+1, "REALM2"))
4248 v = E_realm_names[p_ptr->realm2];
4250 v = realm_names[p_ptr->realm2];
4255 else if (streq(b+1, "PLAYER"))
4261 else if (streq(b+1, "TOWN"))
4263 sprintf(tmp, "%d", p_ptr->town_num);
4268 else if (streq(b+1, "LEVEL"))
4270 sprintf(tmp, "%d", p_ptr->lev);
4274 /* Current quest number */
4275 else if (streq(b+1, "QUEST_NUMBER"))
4277 sprintf(tmp, "%d", p_ptr->inside_quest);
4281 /* Number of last quest */
4282 else if (streq(b+1, "LEAVING_QUEST"))
4284 sprintf(tmp, "%d", leaving_quest);
4289 else if (prefix(b+1, "QUEST"))
4291 /* "QUEST" uses a special parameter to determine the number of the quest */
4292 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4297 else if (prefix(b+1, "RANDOM"))
4299 /* "RANDOM" uses a special parameter to determine the number of the quest */
4300 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4305 else if (streq(b+1, "VARIANT"))
4311 else if (streq(b+1, "WILDERNESS"))
4314 sprintf(tmp, "NONE");
4316 sprintf(tmp, "LITE");
4318 sprintf(tmp, "NORMAL");
4341 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4351 bool bypass = FALSE;
4353 int x = xmin, y = ymin;
4356 /* Build the filename */
4357 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4360 fp = my_fopen(buf, "r");
4363 if (!fp) return (-1);
4366 /* Process the file */
4367 while (0 == my_fgets(fp, buf, sizeof(buf)))
4373 /* Skip "empty" lines */
4374 if (!buf[0]) continue;
4376 /* Skip "blank" lines */
4377 if (isspace(buf[0])) continue;
4380 if (buf[0] == '#') continue;
4383 /* Process "?:<expr>" */
4384 if ((buf[0] == '?') && (buf[1] == ':'))
4393 /* Parse the expr */
4394 v = process_dungeon_file_expr(&s, &f);
4397 bypass = (streq(v, "0") ? TRUE : FALSE);
4403 /* Apply conditionals */
4404 if (bypass) continue;
4406 /* Process the line */
4407 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4419 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4422 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4424 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4426 msg_format("Parsing '%s'.", buf);
4433 /* Close the file */
4443 void write_r_info_txt(void)
4445 int i, j, z, fc, bc;
4448 cptr flags[32 * 10];
4453 monster_race *r_ptr;
4455 monster_blow *b_ptr;
4457 FILE *fff = fopen("output.txt", "wt");
4465 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4467 fprintf(fff, "# Version stamp (required)\n\n");
4470 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4473 fprintf(fff, "##### The Player #####\n\n");
4475 for (z = -1; z < alloc_race_size; z++)
4477 /* Output the monsters in order */
4478 i = (z >= 0) ? alloc_race_table[z].index : 0;
4480 /* Acquire the monster */
4483 /* Ignore empty monsters */
4484 if (!strlen(r_name + r_ptr->name)) continue;
4486 /* Ignore useless monsters */
4487 if (i && !r_ptr->speed) continue;
4489 /* Write a note if necessary */
4490 if (i && (!r_ptr->level != !mode))
4495 fprintf(fff, "\n##### Town monsters #####\n\n");
4497 /* Note the dungeon */
4500 fprintf(fff, "\n##### Normal monsters #####\n\n");
4503 /* Record the change */
4504 mode = r_ptr->level;
4507 /* Acquire the flags */
4508 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4509 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4510 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4511 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4512 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4513 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4514 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4515 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4516 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4517 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4519 /* Write New/Number/Name */
4520 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4523 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4525 /* Write Information */
4526 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4527 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4529 /* Write more information */
4530 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4533 for(j = 0; j < 4; j++)
4535 b_ptr = &(r_ptr->blow[j]);
4537 /* Stop when done */
4538 if (!b_ptr->method) break;
4540 /* Write the blows */
4541 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4542 r_info_blow_effect[b_ptr->effect],
4543 b_ptr->d_dice, b_ptr->d_side);
4546 /* Extract the flags */
4547 for (fc = 0, j = 0; j < 32 * 3; j++)
4549 /* Check this flag */
4550 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4553 /* Extract the extra flags */
4554 for (j = 32 * 6; j < 32 * 10; j++)
4556 /* Check this flag */
4557 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4560 /* Write the flags */
4561 for (j = 0; j < fc;)
4565 /* Start the line */
4568 for (bc = 0; (bc < 60) && (j < fc); j++)
4572 /* Format the flag */
4573 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4575 /* Add it to the buffer */
4578 /* Note the length */
4582 /* Done with this line; write it */
4583 fprintf(fff, "%s\n", buf);
4586 /* Write Spells if applicable */
4587 if (r_ptr->freq_spell)
4589 /* Write the frequency */
4590 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4592 /* Extract the spell flags */
4593 for (fc = 0, j = 96; j < 192; j++)
4595 /* Check this flag */
4596 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4599 /* Write the flags */
4600 for (j = 0; j < fc;)
4604 /* Start the line */
4607 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4611 /* Format the flag */
4612 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4616 /* Note the length */
4623 /* Done with this line; write it */
4624 fprintf(fff, "%s\n", buf);
4628 /* Acquire the description */
4629 desc = r_text + r_ptr->text;
4630 dlen = strlen(desc);
4632 /* Write Description */
4633 for (j = 0; j < dlen;)
4637 /* Start the line */
4640 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4648 /* Done with this line; write it */
4649 fprintf(fff, "%s\n", buf);
4652 /* Space between entries */