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')
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 s_attr = color_char_to_attr(buf[4]);
1547 if (s_attr > 127) return (1);
1549 /* Save the standard values */
1550 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1551 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1553 /* Is this feature supports lighting? */
1556 /* G:c:a:LIT (default) */
1557 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1559 /* G:c:a:lc:la:dc:da */
1560 if (!streq(buf + 6, "LIT"))
1562 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1564 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1565 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1566 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1567 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1569 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1571 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1574 /* Use default lighting */
1577 /* No lighting support */
1578 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1581 /* Extract the color */
1582 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1583 if (f_ptr->d_attr[j] > 127) return 1;
1586 f_ptr->d_char[j] = char_tmp[j];
1592 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1594 f_ptr->d_attr[j] = s_attr;
1595 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1601 /* Hack -- Process 'F' for flags */
1602 else if (buf[0] == 'F')
1604 /* Parse every entry textually */
1605 for (s = buf + 2; *s; )
1607 /* Find the end of this entry */
1608 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1610 /* Nuke and skip any dividers */
1614 while (*t == ' ' || *t == '|') t++;
1617 /* XXX XXX XXX Hack -- Read feature power */
1618 if (1 == sscanf(s, "POWER_%d", &i))
1620 /* Extract a "power" */
1623 /* Start at next entry */
1630 /* Parse this entry */
1631 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1633 /* Start the next entry */
1638 /* Process 'W' for "More Info" (one line only) */
1639 else if (buf[0] == 'W')
1643 /* Scan for the value */
1644 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1646 /* Save the value */
1647 f_ptr->priority = priority;
1650 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1651 else if (buf[0] == 'K')
1655 /* Find the next empty state slot (if any) */
1656 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1658 /* Oops, no more slots */
1659 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1661 /* Analyze the first field */
1662 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1664 /* Terminate the field (if necessary) */
1665 if (*t == ':') *t++ = '\0';
1667 /* Is this default entry? */
1668 if (streq(s, "DESTROYED"))
1670 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1672 /* Record a fake tag index */
1673 f_ptr->destroyed = -offset;
1678 f_ptr->state[i].action = 0;
1680 /* Parse this entry */
1681 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1683 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1685 /* Record a fake tag index */
1686 f_ptr->state[i].result = -offset;
1699 * Convert a fake tag to a real feat index
1701 s16b f_tag_to_index(cptr str)
1705 /* Search for real index corresponding to this fake tag */
1706 for (i = 0; i < f_head.info_num; i++)
1708 if (streq(f_tag + f_info[i].tag, str))
1710 /* Return the index */
1721 * Search for real index corresponding to this fake tag
1723 static void search_real_feat(s16b *feat)
1727 /* Don't convert non-fake tag */
1728 if (*feat >= 0) return;
1730 /* Search for real index corresponding to this fake tag */
1731 for (i = 0; i < f_head.info_num; i++)
1733 if ((-(*feat)) == f_info[i].tag)
1735 /* Record real index */
1743 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1745 msg_format("%s is undefined.", f_tag + (-(*feat)));
1751 * Retouch fake tags of f_info
1753 void retouch_f_info(header *head)
1757 /* Convert fake tags to real feat indices */
1758 for (i = 0; i < head->info_num; i++)
1760 feature_type *f_ptr = &f_info[i];
1763 search_real_feat(&f_ptr->mimic);
1765 search_real_feat(&f_ptr->destroyed);
1767 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1773 * Grab one flag in an object_kind from a textual string
1775 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1780 for (i = 0; i < TR_FLAG_MAX; i++)
1782 if (streq(what, k_info_flags[i]))
1784 add_flag(k_ptr->flags, i);
1789 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1794 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1796 msg_format("Unknown object flag '%s'.", what);
1806 * Initialize the "k_info" array, by parsing an ascii "template" file
1808 errr parse_k_info(char *buf, header *head)
1815 static object_kind *k_ptr = NULL;
1818 /* Process 'N' for "New/Number/Name" */
1821 /* Find the colon before the name */
1822 s = my_strchr(buf+2, ':');
1824 /* Verify that colon */
1827 /* Nuke the colon, advance to the name */
1831 /* Paranoia -- require a name */
1832 if (!*s) return (1);
1837 /* Verify information */
1838 if (i <= error_idx) return (4);
1840 /* Verify information */
1841 if (i >= head->info_num) return (2);
1843 /* Save the index */
1846 /* Point at the "info" */
1850 /* Store the name */
1851 if (!add_name(&k_ptr->name, head, s)) return (7);
1855 /* There better be a current k_ptr */
1856 else if (!k_ptr) return (3);
1860 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1861 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1862 else if (buf[0] == 'E')
1867 else if (buf[0] == 'E')
1869 /* Acquire the Text */
1872 /* Store the name */
1873 if (!add_name(&k_ptr->name, head, s)) return (7);
1877 /* Process 'D' for "Description" */
1878 else if (buf[0] == 'D')
1883 /* Acquire the text */
1888 /* Acquire the text */
1892 /* Store the text */
1893 if (!add_text(&k_ptr->text, head, s)) return (7);
1896 /* Process 'G' for "Graphics" (one line only) */
1897 else if (buf[0] == 'G')
1903 if (buf[1] != ':') return (1);
1904 if (!buf[2]) return (1);
1905 if (buf[3] != ':') return (1);
1906 if (!buf[4]) return (1);
1908 /* Extract the char */
1911 /* Extract the attr */
1912 tmp = color_char_to_attr(buf[4]);
1915 if (tmp > 127) return (1);
1917 /* Save the values */
1918 k_ptr->d_attr = tmp;
1919 k_ptr->d_char = sym;
1922 /* Process 'I' for "Info" (one line only) */
1923 else if (buf[0] == 'I')
1925 int tval, sval, pval;
1927 /* Scan for the values */
1928 if (3 != sscanf(buf+2, "%d:%d:%d",
1929 &tval, &sval, &pval)) return (1);
1931 /* Save the values */
1937 /* Process 'W' for "More Info" (one line only) */
1938 else if (buf[0] == 'W')
1940 int level, extra, wgt;
1943 /* Scan for the values */
1944 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1945 &level, &extra, &wgt, &cost)) return (1);
1947 /* Save the values */
1948 k_ptr->level = level;
1949 k_ptr->extra = extra;
1950 k_ptr->weight = wgt;
1954 /* Process 'A' for "Allocation" (one line only) */
1955 else if (buf[0] == 'A')
1959 /* XXX XXX XXX Simply read each number following a colon */
1960 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1962 /* Default chance */
1963 k_ptr->chance[i] = 1;
1965 /* Store the attack damage index */
1966 k_ptr->locale[i] = atoi(s+1);
1968 /* Find the slash */
1969 t = my_strchr(s+1, '/');
1971 /* Find the next colon */
1972 s = my_strchr(s+1, ':');
1974 /* If the slash is "nearby", use it */
1975 if (t && (!s || t < s))
1977 int chance = atoi(t+1);
1978 if (chance > 0) k_ptr->chance[i] = chance;
1983 /* Hack -- Process 'P' for "power" and such */
1984 else if (buf[0] == 'P')
1986 int ac, hd1, hd2, th, td, ta;
1988 /* Scan for the values */
1989 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1990 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2000 /* Hack -- Process 'F' for flags */
2001 else if (buf[0] == 'F')
2003 /* Parse every entry textually */
2004 for (s = buf + 2; *s; )
2006 /* Find the end of this entry */
2007 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2009 /* Nuke and skip any dividers */
2013 while (*t == ' ' || *t == '|') t++;
2016 /* Parse this entry */
2017 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2019 /* Start the next entry */
2035 * Grab one flag in an artifact_type from a textual string
2037 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2042 for (i = 0; i < TR_FLAG_MAX; i++)
2044 if (streq(what, k_info_flags[i]))
2046 add_flag(a_ptr->flags, i);
2051 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2056 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2058 msg_format("Unknown artifact flag '%s'.", what);
2070 * Initialize the "a_info" array, by parsing an ascii "template" file
2072 errr parse_a_info(char *buf, header *head)
2079 static artifact_type *a_ptr = NULL;
2082 /* Process 'N' for "New/Number/Name" */
2085 /* Find the colon before the name */
2086 s = my_strchr(buf+2, ':');
2088 /* Verify that colon */
2091 /* Nuke the colon, advance to the name */
2094 /* Paranoia -- require a name */
2095 if (!*s) return (1);
2100 /* Verify information */
2101 if (i < error_idx) return (4);
2103 /* Verify information */
2104 if (i >= head->info_num) return (2);
2106 /* Save the index */
2109 /* Point at the "info" */
2112 /* Ignore everything */
2113 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2114 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2115 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2116 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2118 /* Store the name */
2119 if (!add_name(&a_ptr->name, head, s)) return (7);
2123 /* There better be a current a_ptr */
2124 else if (!a_ptr) return (3);
2128 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2129 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2130 else if (buf[0] == 'E')
2135 else if (buf[0] == 'E')
2137 /* Acquire the Text */
2140 /* Store the name */
2141 if (!add_name(&a_ptr->name, head, s)) return (7);
2145 /* Process 'D' for "Description" */
2146 else if (buf[0] == 'D')
2151 /* Acquire the text */
2156 /* Acquire the text */
2160 /* Store the text */
2161 if (!add_text(&a_ptr->text, head, s)) return (7);
2165 /* Process 'I' for "Info" (one line only) */
2166 else if (buf[0] == 'I')
2168 int tval, sval, pval;
2170 /* Scan for the values */
2171 if (3 != sscanf(buf+2, "%d:%d:%d",
2172 &tval, &sval, &pval)) return (1);
2174 /* Save the values */
2180 /* Process 'W' for "More Info" (one line only) */
2181 else if (buf[0] == 'W')
2183 int level, rarity, wgt;
2186 /* Scan for the values */
2187 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2188 &level, &rarity, &wgt, &cost)) return (1);
2190 /* Save the values */
2191 a_ptr->level = level;
2192 a_ptr->rarity = rarity;
2193 a_ptr->weight = wgt;
2197 /* Hack -- Process 'P' for "power" and such */
2198 else if (buf[0] == 'P')
2200 int ac, hd1, hd2, th, td, ta;
2202 /* Scan for the values */
2203 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2204 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2214 /* Hack -- Process 'F' for flags */
2215 else if (buf[0] == 'F')
2217 /* Parse every entry textually */
2218 for (s = buf + 2; *s; )
2220 /* Find the end of this entry */
2221 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2223 /* Nuke and skip any dividers */
2227 while ((*t == ' ') || (*t == '|')) t++;
2230 /* Parse this entry */
2231 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2233 /* Start the next entry */
2249 * Grab one flag in a ego-item_type from a textual string
2251 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2256 for (i = 0; i < TR_FLAG_MAX; i++)
2258 if (streq(what, k_info_flags[i]))
2260 add_flag(e_ptr->flags, i);
2265 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2270 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2272 msg_format("Unknown ego-item flag '%s'.", what);
2284 * Initialize the "e_info" array, by parsing an ascii "template" file
2286 errr parse_e_info(char *buf, header *head)
2293 static ego_item_type *e_ptr = NULL;
2296 /* Just before the first record */
2299 /* Just before the first line */
2303 /* Process 'N' for "New/Number/Name" */
2306 /* Find the colon before the name */
2307 s = my_strchr(buf+2, ':');
2309 /* Verify that colon */
2312 /* Nuke the colon, advance to the name */
2315 /* Paranoia -- require a name */
2316 if (!*s) return (1);
2321 /* Verify information */
2322 if (i < error_idx) return (4);
2324 /* Verify information */
2325 if (i >= head->info_num) return (2);
2327 /* Save the index */
2330 /* Point at the "info" */
2333 /* Store the name */
2334 if (!add_name(&e_ptr->name, head, s)) return (7);
2338 /* There better be a current e_ptr */
2339 else if (!e_ptr) return (3);
2343 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2344 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2345 else if (buf[0] == 'E')
2350 else if (buf[0] == 'E')
2352 /* Acquire the Text */
2355 /* Store the name */
2356 if (!add_name(&e_ptr->name, head, s)) return (7);
2361 /* Process 'D' for "Description" */
2362 else if (buf[0] == 'D')
2364 /* Acquire the text */
2367 /* Store the text */
2368 if (!add_text(&e_ptr->text, head, s)) return (7);
2373 /* Process 'X' for "Xtra" (one line only) */
2374 else if (buf[0] == 'X')
2378 /* Scan for the values */
2379 if (2 != sscanf(buf+2, "%d:%d",
2380 &slot, &rating)) return (1);
2382 /* Save the values */
2384 e_ptr->rating = rating;
2387 /* Process 'W' for "More Info" (one line only) */
2388 else if (buf[0] == 'W')
2390 int level, rarity, pad2;
2393 /* Scan for the values */
2394 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2395 &level, &rarity, &pad2, &cost)) return (1);
2397 /* Save the values */
2398 e_ptr->level = level;
2399 e_ptr->rarity = rarity;
2400 /* e_ptr->weight = wgt; */
2404 /* Hack -- Process 'C' for "creation" */
2405 else if (buf[0] == 'C')
2409 /* Scan for the values */
2410 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2411 &th, &td, &ta, &pv)) return (1);
2413 e_ptr->max_to_h = th;
2414 e_ptr->max_to_d = td;
2415 e_ptr->max_to_a = ta;
2416 e_ptr->max_pval = pv;
2419 /* Hack -- Process 'F' for flags */
2420 else if (buf[0] == 'F')
2422 /* Parse every entry textually */
2423 for (s = buf + 2; *s; )
2425 /* Find the end of this entry */
2426 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2428 /* Nuke and skip any dividers */
2432 while ((*t == ' ') || (*t == '|')) t++;
2435 /* Parse this entry */
2436 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2438 /* Start the next entry */
2452 * Grab one (basic) flag in a monster_race from a textual string
2454 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2456 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2459 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2462 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2465 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2468 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2471 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2474 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2479 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2481 msg_format("Unknown monster flag '%s'.", what);
2491 * Grab one (spell) flag in a monster_race from a textual string
2493 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2495 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2498 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2501 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2506 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2508 msg_format("Unknown monster flag '%s'.", what);
2520 * Initialize the "r_info" array, by parsing an ascii "template" file
2522 errr parse_r_info(char *buf, header *head)
2529 static monster_race *r_ptr = NULL;
2532 /* Process 'N' for "New/Number/Name" */
2535 /* Find the colon before the name */
2536 s = my_strchr(buf+2, ':');
2538 /* Verify that colon */
2541 /* Nuke the colon, advance to the name */
2544 /* Paranoia -- require a name */
2545 if (!*s) return (1);
2550 /* Verify information */
2551 if (i < error_idx) return (4);
2553 /* Verify information */
2554 if (i >= head->info_num) return (2);
2556 /* Save the index */
2559 /* Point at the "info" */
2562 /* Store the name */
2563 if (!add_name(&r_ptr->name, head, s)) return (7);
2567 /* There better be a current r_ptr */
2568 else if (!r_ptr) return (3);
2572 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2573 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2574 else if (buf[0] == 'E')
2576 /* Acquire the Text */
2579 /* Store the name */
2580 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2583 else if (buf[0] == 'E')
2585 /* Acquire the Text */
2588 /* Store the name */
2589 if (!add_name(&r_ptr->name, head, s)) return (7);
2592 /* Process 'D' for "Description" */
2593 else if (buf[0] == 'D')
2598 /* Acquire the text */
2603 /* Acquire the text */
2607 /* Store the text */
2608 if (!add_text(&r_ptr->text, head, s)) return (7);
2611 /* Process 'G' for "Graphics" (one line only) */
2612 else if (buf[0] == 'G')
2618 if (buf[1] != ':') return (1);
2619 if (!buf[2]) return (1);
2620 if (buf[3] != ':') return (1);
2621 if (!buf[4]) return (1);
2623 /* Extract the char */
2626 /* Extract the attr */
2627 tmp = color_char_to_attr(buf[4]);
2630 if (tmp > 127) return (1);
2632 /* Save the values */
2633 r_ptr->d_char = sym;
2634 r_ptr->d_attr = tmp;
2637 /* Process 'I' for "Info" (one line only) */
2638 else if (buf[0] == 'I')
2640 int spd, hp1, hp2, aaf, ac, slp;
2642 /* Scan for the other values */
2643 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2644 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2646 /* Save the values */
2655 /* Process 'W' for "More Info" (one line only) */
2656 else if (buf[0] == 'W')
2663 /* Scan for the values */
2664 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2665 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2667 /* Save the values */
2669 r_ptr->rarity = rar;
2672 r_ptr->next_exp = nextexp;
2673 r_ptr->next_r_idx = nextmon;
2676 /* Process 'B' for "Blows" (up to four lines) */
2677 else if (buf[0] == 'B')
2681 /* Find the next empty blow slot (if any) */
2682 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2684 /* Oops, no more slots */
2685 if (i == 4) return (1);
2687 /* Analyze the first field */
2688 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2690 /* Terminate the field (if necessary) */
2691 if (*t == ':') *t++ = '\0';
2693 /* Analyze the method */
2694 for (n1 = 0; r_info_blow_method[n1]; n1++)
2696 if (streq(s, r_info_blow_method[n1])) break;
2699 /* Invalid method */
2700 if (!r_info_blow_method[n1]) return (1);
2702 /* Analyze the second field */
2703 for (s = t; *t && (*t != ':'); t++) /* loop */;
2705 /* Terminate the field (if necessary) */
2706 if (*t == ':') *t++ = '\0';
2708 /* Analyze effect */
2709 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2711 if (streq(s, r_info_blow_effect[n2])) break;
2714 /* Invalid effect */
2715 if (!r_info_blow_effect[n2]) return (1);
2717 /* Analyze the third field */
2718 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2720 /* Terminate the field (if necessary) */
2721 if (*t == 'd') *t++ = '\0';
2723 /* Save the method */
2724 r_ptr->blow[i].method = n1;
2726 /* Save the effect */
2727 r_ptr->blow[i].effect = n2;
2729 /* Extract the damage dice and sides */
2730 r_ptr->blow[i].d_dice = atoi(s);
2731 r_ptr->blow[i].d_side = atoi(t);
2734 /* Process 'F' for "Basic Flags" (multiple lines) */
2735 else if (buf[0] == 'F')
2737 /* Parse every entry */
2738 for (s = buf + 2; *s; )
2740 /* Find the end of this entry */
2741 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2743 /* Nuke and skip any dividers */
2747 while (*t == ' ' || *t == '|') t++;
2750 /* Parse this entry */
2751 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2753 /* Start the next entry */
2758 /* Process 'S' for "Spell Flags" (multiple lines) */
2759 else if (buf[0] == 'S')
2761 /* Parse every entry */
2762 for (s = buf + 2; *s; )
2764 /* Find the end of this entry */
2765 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2767 /* Nuke and skip any dividers */
2771 while ((*t == ' ') || (*t == '|')) t++;
2774 /* XXX XXX XXX Hack -- Read spell frequency */
2775 if (1 == sscanf(s, "1_IN_%d", &i))
2777 /* Extract a "frequency" */
2778 r_ptr->freq_spell = 100 / i;
2780 /* Start at next entry */
2787 /* Parse this entry */
2788 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2790 /* Start the next entry */
2805 * Grab one flag for a dungeon type from a textual string
2807 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2809 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2814 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2816 msg_format("Unknown dungeon type flag '%s'.", what);
2824 * Grab one (basic) flag in a monster_race from a textual string
2826 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2828 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2831 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2834 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2837 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2840 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2843 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2846 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2851 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2853 msg_format("Unknown monster flag '%s'.", what);
2861 * Grab one (spell) flag in a monster_race from a textual string
2863 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2865 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2868 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2871 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2876 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2878 msg_format("Unknown monster flag '%s'.", what);
2886 * Initialize the "d_info" array, by parsing an ascii "template" file
2888 errr parse_d_info(char *buf, header *head)
2895 static dungeon_info_type *d_ptr = NULL;
2898 /* Process 'N' for "New/Number/Name" */
2901 /* Find the colon before the name */
2902 s = my_strchr(buf+2, ':');
2904 /* Verify that colon */
2907 /* Nuke the colon, advance to the name */
2910 /* Paranoia -- require a name */
2911 if (!*s) return (1);
2916 /* Verify information */
2917 if (i < error_idx) return (4);
2919 /* Verify information */
2920 if (i >= head->info_num) return (2);
2922 /* Save the index */
2925 /* Point at the "info" */
2928 /* Store the name */
2929 if (!add_name(&d_ptr->name, head, s)) return (7);
2934 else if (buf[0] == 'E') return (0);
2936 else if (buf[0] == 'E')
2938 /* Acquire the Text */
2941 /* Store the name */
2942 if (!add_name(&d_ptr->name, head, s)) return (7);
2946 /* Process 'D' for "Description */
2947 else if (buf[0] == 'D')
2952 /* Acquire the text */
2957 /* Acquire the text */
2961 /* Store the text */
2962 if (!add_text(&d_ptr->text, head, s)) return (7);
2965 /* Process 'W' for "More Info" (one line only) */
2966 else if (buf[0] == 'W')
2968 int min_lev, max_lev;
2970 int min_alloc, max_chance;
2971 int obj_good, obj_great;
2974 /* Scan for the values */
2975 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2976 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2978 /* Save the values */
2979 d_ptr->mindepth = min_lev;
2980 d_ptr->maxdepth = max_lev;
2981 d_ptr->min_plev = min_plev;
2983 d_ptr->min_m_alloc_level = min_alloc;
2984 d_ptr->max_m_alloc_chance = max_chance;
2985 d_ptr->obj_good = obj_good;
2986 d_ptr->obj_great = obj_great;
2991 /* Process 'P' for "Place Info" */
2992 else if (buf[0] == 'P')
2996 /* Scan for the values */
2997 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
2999 /* Save the values */
3004 /* Process 'L' for "fLoor type" (one line only) */
3005 else if (buf[0] == 'L')
3009 /* Scan for the values */
3010 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3012 /* Save the values */
3013 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3015 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3016 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3018 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3020 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3023 /* Process 'A' for "wAll type" (one line only) */
3024 else if (buf[0] == 'A')
3028 /* Scan for the values */
3029 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3031 /* Save the values */
3032 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3034 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3035 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3037 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3040 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3041 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3043 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3044 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3046 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3047 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3049 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3050 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3053 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3054 else if (buf[0] == 'F')
3056 int artif = 0, monst = 0;
3058 /* Parse every entry */
3059 for (s = buf + 2; *s; )
3061 /* Find the end of this entry */
3062 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3064 /* Nuke and skip any dividers */
3068 while (*t == ' ' || *t == '|') t++;
3071 /* XXX XXX XXX Hack -- Read Final Artifact */
3072 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3074 /* Extract a "Final Artifact" */
3075 d_ptr->final_artifact = artif;
3077 /* Start at next entry */
3084 /* XXX XXX XXX Hack -- Read Final Object */
3085 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3087 /* Extract a "Final Artifact" */
3088 d_ptr->final_object = artif;
3090 /* Start at next entry */
3097 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3098 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3100 /* Extract a "Artifact Guardian" */
3101 d_ptr->final_guardian = monst;
3103 /* Start at next entry */
3110 /* XXX XXX XXX Hack -- Read Special Percentage */
3111 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3113 /* Extract a "Special %" */
3114 d_ptr->special_div = monst;
3116 /* Start at next entry */
3123 /* Parse this entry */
3124 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3126 /* Start the next entry */
3131 /* Process 'M' for "Basic Flags" (multiple lines) */
3132 else if (buf[0] == 'M')
3134 /* Parse every entry */
3135 for (s = buf + 2; *s; )
3137 /* Find the end of this entry */
3138 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3140 /* Nuke and skip any dividers */
3144 while (*t == ' ' || *t == '|') t++;
3147 /* Hack -- Read monster symbols */
3148 if (!strncmp(s, "R_CHAR_", 7))
3150 /* Skip "R_CHAR_" */
3154 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3156 /* Start at next entry */
3163 /* Parse this entry */
3164 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3166 /* Start the next entry */
3171 /* Process 'S' for "Spell Flags" (multiple lines) */
3172 else if (buf[0] == 'S')
3174 /* Parse every entry */
3175 for (s = buf + 2; *s; )
3177 /* Find the end of this entry */
3178 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3180 /* Nuke and skip any dividers */
3184 while ((*t == ' ') || (*t == '|')) t++;
3187 /* XXX XXX XXX Hack -- Read spell frequency */
3188 if (1 == sscanf(s, "1_IN_%d", &i))
3190 /* Start at next entry */
3197 /* Parse this entry */
3198 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3200 /* Start the next entry */
3213 #else /* ALLOW_TEMPLATES */
3219 #endif /* ALLOW_TEMPLATES */
3222 /* Random dungeon grid effects */
3223 #define RANDOM_NONE 0x00000000
3224 #define RANDOM_FEATURE 0x00000001
3225 #define RANDOM_MONSTER 0x00000002
3226 #define RANDOM_OBJECT 0x00000004
3227 #define RANDOM_EGO 0x00000008
3228 #define RANDOM_ARTIFACT 0x00000010
3229 #define RANDOM_TRAP 0x00000020
3232 typedef struct dungeon_grid dungeon_grid;
3236 int feature; /* Terrain feature */
3237 int monster; /* Monster */
3238 int object; /* Object */
3239 int ego; /* Ego-Item */
3240 int artifact; /* Artifact */
3241 int trap; /* Trap */
3242 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3243 int special; /* Reserved for special terrain info */
3244 int random; /* Number of the random effect */
3248 static dungeon_grid letter[255];
3252 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3254 static errr parse_line_feature(char *buf)
3260 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3262 /* Tokenize the line */
3263 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3265 /* Letter to assign */
3266 int index = zz[0][0];
3268 /* Reset the info for the letter */
3269 letter[index].feature = FEAT_NONE;
3270 letter[index].monster = 0;
3271 letter[index].object = 0;
3272 letter[index].ego = 0;
3273 letter[index].artifact = 0;
3274 letter[index].trap = FEAT_NONE;
3275 letter[index].cave_info = 0;
3276 letter[index].special = 0;
3277 letter[index].random = RANDOM_NONE;
3283 letter[index].special = atoi(zz[8]);
3287 if ((zz[7][0] == '*') && !zz[7][1])
3289 letter[index].random |= RANDOM_TRAP;
3293 letter[index].trap = f_tag_to_index(zz[7]);
3294 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3299 if (zz[6][0] == '*')
3301 letter[index].random |= RANDOM_ARTIFACT;
3302 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3306 letter[index].artifact = atoi(zz[6]);
3311 if (zz[5][0] == '*')
3313 letter[index].random |= RANDOM_EGO;
3314 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3318 letter[index].ego = atoi(zz[5]);
3323 if (zz[4][0] == '*')
3325 letter[index].random |= RANDOM_OBJECT;
3326 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3330 letter[index].object = atoi(zz[4]);
3335 if (zz[3][0] == '*')
3337 letter[index].random |= RANDOM_MONSTER;
3338 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3340 else if (zz[3][0] == 'c')
3342 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3343 letter[index].monster = - atoi(zz[3] + 1);
3347 letter[index].monster = atoi(zz[3]);
3352 letter[index].cave_info = atoi(zz[2]);
3356 if ((zz[1][0] == '*') && !zz[1][1])
3358 letter[index].random |= RANDOM_FEATURE;
3362 letter[index].feature = f_tag_to_index(zz[1]);
3363 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3376 * Process "B:<Index>:<Command>:..." -- Building definition
3378 static errr parse_line_building(char *buf)
3394 /* Get the building number */
3397 /* Find the colon after the building number */
3398 s = my_strchr(s, ':');
3400 /* Verify that colon */
3403 /* Nuke the colon, advance to the sub-index */
3406 /* Paranoia -- require a sub-index */
3407 if (!*s) return (1);
3409 /* Building definition sub-index */
3412 /* Building name, owner, race */
3415 if (tokenize(s + 2, 3, zz, 0) == 3)
3417 /* Name of the building */
3418 strcpy(building[index].name, zz[0]);
3420 /* Name of the owner */
3421 strcpy(building[index].owner_name, zz[1]);
3423 /* Race of the owner */
3424 strcpy(building[index].owner_race, zz[2]);
3429 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3432 /* Building Action */
3435 if (tokenize(s + 2, 8, zz, 0) >= 7)
3437 /* Index of the action */
3438 int action_index = atoi(zz[0]);
3440 /* Name of the action */
3441 strcpy(building[index].act_names[action_index], zz[1]);
3443 /* Cost of the action for members */
3444 building[index].member_costs[action_index] = atoi(zz[2]);
3446 /* Cost of the action for non-members */
3447 building[index].other_costs[action_index] = atoi(zz[3]);
3449 /* Letter assigned to the action */
3450 building[index].letters[action_index] = zz[4][0];
3453 building[index].actions[action_index] = atoi(zz[5]);
3455 /* Action restriction */
3456 building[index].action_restr[action_index] = atoi(zz[6]);
3461 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3464 /* Building Classes */
3467 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3469 for (i = 0; i < MAX_CLASS; i++)
3471 building[index].member_class[i] = atoi(zz[i]);
3477 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3480 /* Building Races */
3483 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3485 for (i = 0; i < MAX_RACES; i++)
3487 building[index].member_race[i] = atoi(zz[i]);
3493 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3496 /* Building Realms */
3499 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3501 for (i = 0; i < MAX_MAGIC; i++)
3503 building[index].member_realm[i+1] = atoi(zz[i]);
3509 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3514 /* Ignore scripts */
3520 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3529 * Place the object j_ptr to a grid
3531 static void drop_here(object_type *j_ptr, int y, int x)
3533 cave_type *c_ptr = &cave[y][x];
3536 /* Get new object */
3537 s16b o_idx = o_pop();
3539 /* Access new object */
3540 o_ptr = &o_list[o_idx];
3542 /* Structure copy */
3543 object_copy(o_ptr, j_ptr);
3551 o_ptr->held_m_idx = 0;
3554 o_ptr->next_o_idx = c_ptr->o_idx;
3556 /* Place the object */
3557 c_ptr->o_idx = o_idx;
3562 * Parse a sub-file of the "extra info"
3564 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3571 /* Skip "empty" lines */
3572 if (!buf[0]) return (0);
3574 /* Skip "blank" lines */
3575 if (isspace(buf[0])) return (0);
3578 if (buf[0] == '#') return (0);
3580 /* Require "?:*" format */
3581 if (buf[1] != ':') return (1);
3584 /* Process "%:<fname>" */
3587 /* Attempt to Process the given file */
3588 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3591 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3594 return parse_line_feature(buf);
3597 /* Process "D:<dungeon>" -- info for the cave grids */
3598 else if (buf[0] == 'D')
3600 object_type object_type_body;
3602 /* Acquire the text */
3605 /* Length of the text */
3606 int len = strlen(s);
3608 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3610 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3612 /* Access the grid */
3613 cave_type *c_ptr = &cave[*y][*x];
3617 int object_index = letter[idx].object;
3618 int monster_index = letter[idx].monster;
3619 int random = letter[idx].random;
3620 int artifact_index = letter[idx].artifact;
3622 /* Lay down a floor */
3623 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3625 /* Only the features */
3626 if (init_flags & INIT_ONLY_FEATURES) continue;
3629 c_ptr->info = letter[idx].cave_info;
3631 /* Create a monster */
3632 if (random & RANDOM_MONSTER)
3634 monster_level = base_level + monster_index;
3636 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3638 monster_level = base_level;
3640 else if (monster_index)
3642 int old_cur_num, old_max_num;
3645 if (monster_index < 0)
3647 monster_index = -monster_index;
3650 old_cur_num = r_info[monster_index].cur_num;
3651 old_max_num = r_info[monster_index].max_num;
3653 /* Make alive again */
3654 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3656 r_info[monster_index].cur_num = 0;
3657 r_info[monster_index].max_num = 1;
3660 /* Make alive again */
3661 /* Hack -- Non-unique Nazguls are semi-unique */
3662 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3664 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3666 r_info[monster_index].max_num++;
3671 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3675 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3677 /* Make alive again for real unique monster */
3678 r_info[monster_index].cur_num = old_cur_num;
3679 r_info[monster_index].max_num = old_max_num;
3683 /* Object (and possible trap) */
3684 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3686 object_level = base_level + object_index;
3689 * Random trap and random treasure defined
3690 * 25% chance for trap and 75% chance for object
3692 if (randint0(100) < 75)
3694 place_object(*y, *x, 0L);
3701 object_level = base_level;
3703 else if (random & RANDOM_OBJECT)
3705 object_level = base_level + object_index;
3707 /* Create an out of deep object */
3708 if (randint0(100) < 75)
3709 place_object(*y, *x, 0L);
3710 else if (randint0(100) < 80)
3711 place_object(*y, *x, AM_GOOD);
3713 place_object(*y, *x, AM_GOOD | AM_GREAT);
3715 object_level = base_level;
3718 else if (random & RANDOM_TRAP)
3722 /* Hidden trap (or door) */
3723 else if (letter[idx].trap)
3725 c_ptr->mimic = c_ptr->feat;
3726 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3728 else if (object_index)
3730 /* Get local object */
3731 object_type *o_ptr = &object_type_body;
3733 /* Create the item */
3734 object_prep(o_ptr, object_index);
3736 if (o_ptr->tval == TV_GOLD)
3738 coin_type = object_index - OBJ_GOLD_LIST;
3743 /* Apply magic (no messages, no artifacts) */
3744 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3746 drop_here(o_ptr, *y, *x);
3752 if (a_info[artifact_index].cur_num)
3754 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3756 object_type *q_ptr = &forge;
3758 object_prep(q_ptr, k_idx);
3760 /* Drop it in the dungeon */
3761 drop_here(q_ptr, *y, *x);
3765 /* Create the artifact */
3766 create_named_art(artifact_index, *y, *x);
3768 a_info[artifact_index].cur_num = 1;
3772 /* Terrain special */
3773 c_ptr->special = letter[idx].special;
3781 /* Process "Q:<number>:<command>:... -- quest info */
3782 else if (buf[0] == 'Q')
3789 num = tokenize(buf + 2, 33, zz, 0);
3793 num = tokenize(buf + 3, 33, zz, 0);
3796 /* Have we enough parameters? */
3797 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3800 q_ptr = &(quest[atoi(zz[0])]);
3802 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3803 if (zz[1][0] == 'Q')
3805 if (init_flags & INIT_ASSIGN)
3807 monster_race *r_ptr;
3808 artifact_type *a_ptr;
3810 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3812 q_ptr->type = atoi(zz[2]);
3813 q_ptr->num_mon = atoi(zz[3]);
3814 q_ptr->cur_num = atoi(zz[4]);
3815 q_ptr->max_num = atoi(zz[5]);
3816 q_ptr->level = atoi(zz[6]);
3817 q_ptr->r_idx = atoi(zz[7]);
3818 q_ptr->k_idx = atoi(zz[8]);
3819 q_ptr->dungeon = atoi(zz[9]);
3822 q_ptr->flags = atoi(zz[10]);
3824 r_ptr = &r_info[q_ptr->r_idx];
3825 if (r_ptr->flags1 & RF1_UNIQUE)
3826 r_ptr->flags1 |= RF1_QUESTOR;
3828 a_ptr = &a_info[q_ptr->k_idx];
3829 a_ptr->gen_flags |= TRG_QUESTITEM;
3834 /* Process "Q:<q_index>:N:<name>" -- quest name */
3835 else if (zz[1][0] == 'N')
3837 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3839 strcpy(q_ptr->name, zz[2]);
3845 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3846 else if (zz[1][0] == 'T')
3848 if (init_flags & INIT_SHOW_TEXT)
3850 strcpy(quest_text[quest_text_line], zz[2]);
3858 /* Process "W:<command>: ..." -- info for the wilderness */
3859 else if (buf[0] == 'W')
3861 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3864 /* Process "P:<y>:<x>" -- player position */
3865 else if (buf[0] == 'P')
3867 if (init_flags & INIT_CREATE_DUNGEON)
3869 if (tokenize(buf + 2, 2, zz, 0) == 2)
3871 int panels_x, panels_y;
3873 /* Hack - Set the dungeon size */
3874 panels_y = (*y / SCREEN_HGT);
3875 if (*y % SCREEN_HGT) panels_y++;
3876 cur_hgt = panels_y * SCREEN_HGT;
3878 panels_x = (*x / SCREEN_WID);
3879 if (*x % SCREEN_WID) panels_x++;
3880 cur_wid = panels_x * SCREEN_WID;
3882 /* Assume illegal panel */
3883 panel_row_min = cur_hgt;
3884 panel_col_min = cur_wid;
3886 /* Place player in a quest level */
3887 if (p_ptr->inside_quest)
3891 /* Delete the monster (if any) */
3892 delete_monster(py, px);
3900 /* Place player in the town */
3901 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3903 p_ptr->oldpy = atoi(zz[0]);
3904 p_ptr->oldpx = atoi(zz[1]);
3912 /* Process "B:<Index>:<Command>:..." -- Building definition */
3913 else if (buf[0] == 'B')
3915 return parse_line_building(buf);
3918 /* Process "M:<type>:<maximum>" -- set maximum values */
3919 else if (buf[0] == 'M')
3921 if (tokenize(buf+2, 2, zz, 0) == 2)
3924 if (zz[0][0] == 'T')
3926 max_towns = atoi(zz[1]);
3929 /* Maximum quests */
3930 else if (zz[0][0] == 'Q')
3932 max_quests = atoi(zz[1]);
3936 else if (zz[0][0] == 'R')
3938 max_r_idx = atoi(zz[1]);
3942 else if (zz[0][0] == 'K')
3944 max_k_idx = atoi(zz[1]);
3948 else if (zz[0][0] == 'V')
3950 max_v_idx = atoi(zz[1]);
3954 else if (zz[0][0] == 'F')
3956 max_f_idx = atoi(zz[1]);
3960 else if (zz[0][0] == 'A')
3962 max_a_idx = atoi(zz[1]);
3966 else if (zz[0][0] == 'E')
3968 max_e_idx = atoi(zz[1]);
3972 else if (zz[0][0] == 'D')
3974 max_d_idx = atoi(zz[1]);
3978 else if (zz[0][0] == 'O')
3980 max_o_idx = atoi(zz[1]);
3984 else if (zz[0][0] == 'M')
3986 max_m_idx = atoi(zz[1]);
3989 /* Wilderness size */
3990 else if (zz[0][0] == 'W')
3992 /* Maximum wild_x_size */
3993 if (zz[0][1] == 'X')
3994 max_wild_x = atoi(zz[1]);
3995 /* Maximum wild_y_size */
3996 if (zz[0][1] == 'Y')
3997 max_wild_y = atoi(zz[1]);
4011 static cptr variant = "ZANGBAND";
4015 * Helper function for "process_dungeon_file()"
4017 static cptr process_dungeon_file_expr(char **sp, char *fp)
4033 while (isspace(*s)) s++;
4051 t = process_dungeon_file_expr(&s, &f);
4060 else if (streq(t, "IOR"))
4063 while (*s && (f != b2))
4065 t = process_dungeon_file_expr(&s, &f);
4066 if (*t && !streq(t, "0")) v = "1";
4071 else if (streq(t, "AND"))
4074 while (*s && (f != b2))
4076 t = process_dungeon_file_expr(&s, &f);
4077 if (*t && streq(t, "0")) v = "0";
4082 else if (streq(t, "NOT"))
4085 while (*s && (f != b2))
4087 t = process_dungeon_file_expr(&s, &f);
4088 if (*t && streq(t, "1")) v = "0";
4093 else if (streq(t, "EQU"))
4096 if (*s && (f != b2))
4098 t = process_dungeon_file_expr(&s, &f);
4100 while (*s && (f != b2))
4102 p = process_dungeon_file_expr(&s, &f);
4103 if (streq(t, p)) v = "1";
4108 else if (streq(t, "LEQ"))
4111 if (*s && (f != b2))
4113 t = process_dungeon_file_expr(&s, &f);
4115 while (*s && (f != b2))
4118 t = process_dungeon_file_expr(&s, &f);
4119 if (*t && atoi(p) > atoi(t)) v = "0";
4124 else if (streq(t, "GEQ"))
4127 if (*s && (f != b2))
4129 t = process_dungeon_file_expr(&s, &f);
4131 while (*s && (f != b2))
4134 t = process_dungeon_file_expr(&s, &f);
4136 /* Compare two numbers instead of string */
4137 if (*t && atoi(p) < atoi(t)) v = "0";
4144 while (*s && (f != b2))
4146 t = process_dungeon_file_expr(&s, &f);
4151 if (f != b2) v = "?x?x?";
4153 /* Extract final and Terminate */
4154 if ((f = *s) != '\0') *s++ = '\0';
4160 /* Accept all printables except spaces and brackets */
4161 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4163 /* Extract final and Terminate */
4164 if ((f = *s) != '\0') *s++ = '\0';
4170 if (streq(b+1, "SYS"))
4176 else if (streq(b+1, "GRAF"))
4181 else if (streq(b+1, "MONOCHROME"))
4190 else if (streq(b+1, "RACE"))
4193 v = rp_ptr->E_title;
4200 else if (streq(b+1, "CLASS"))
4203 v = cp_ptr->E_title;
4210 else if (streq(b+1, "REALM1"))
4213 v = E_realm_names[p_ptr->realm1];
4215 v = realm_names[p_ptr->realm1];
4220 else if (streq(b+1, "REALM2"))
4223 v = E_realm_names[p_ptr->realm2];
4225 v = realm_names[p_ptr->realm2];
4230 else if (streq(b+1, "PLAYER"))
4236 else if (streq(b+1, "TOWN"))
4238 sprintf(tmp, "%d", p_ptr->town_num);
4243 else if (streq(b+1, "LEVEL"))
4245 sprintf(tmp, "%d", p_ptr->lev);
4249 /* Current quest number */
4250 else if (streq(b+1, "QUEST_NUMBER"))
4252 sprintf(tmp, "%d", p_ptr->inside_quest);
4256 /* Number of last quest */
4257 else if (streq(b+1, "LEAVING_QUEST"))
4259 sprintf(tmp, "%d", leaving_quest);
4264 else if (prefix(b+1, "QUEST"))
4266 /* "QUEST" uses a special parameter to determine the number of the quest */
4267 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4272 else if (prefix(b+1, "RANDOM"))
4274 /* "RANDOM" uses a special parameter to determine the number of the quest */
4275 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4280 else if (streq(b+1, "VARIANT"))
4286 else if (streq(b+1, "WILDERNESS"))
4289 sprintf(tmp, "NONE");
4291 sprintf(tmp, "LITE");
4293 sprintf(tmp, "NORMAL");
4316 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4326 bool bypass = FALSE;
4328 int x = xmin, y = ymin;
4331 /* Build the filename */
4332 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4335 fp = my_fopen(buf, "r");
4338 if (!fp) return (-1);
4341 /* Process the file */
4342 while (0 == my_fgets(fp, buf, sizeof(buf)))
4348 /* Skip "empty" lines */
4349 if (!buf[0]) continue;
4351 /* Skip "blank" lines */
4352 if (isspace(buf[0])) continue;
4355 if (buf[0] == '#') continue;
4358 /* Process "?:<expr>" */
4359 if ((buf[0] == '?') && (buf[1] == ':'))
4368 /* Parse the expr */
4369 v = process_dungeon_file_expr(&s, &f);
4372 bypass = (streq(v, "0") ? TRUE : FALSE);
4378 /* Apply conditionals */
4379 if (bypass) continue;
4381 /* Process the line */
4382 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4394 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4397 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4399 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4401 msg_format("Parsing '%s'.", buf);
4408 /* Close the file */
4418 void write_r_info_txt(void)
4420 int i, j, z, fc, bc;
4423 cptr flags[32 * 10];
4428 monster_race *r_ptr;
4430 monster_blow *b_ptr;
4432 FILE *fff = fopen("output.txt", "wt");
4440 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4442 fprintf(fff, "# Version stamp (required)\n\n");
4445 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4448 fprintf(fff, "##### The Player #####\n\n");
4450 for (z = -1; z < alloc_race_size; z++)
4452 /* Output the monsters in order */
4453 i = (z >= 0) ? alloc_race_table[z].index : 0;
4455 /* Acquire the monster */
4458 /* Ignore empty monsters */
4459 if (!strlen(r_name + r_ptr->name)) continue;
4461 /* Ignore useless monsters */
4462 if (i && !r_ptr->speed) continue;
4464 /* Write a note if necessary */
4465 if (i && (!r_ptr->level != !mode))
4470 fprintf(fff, "\n##### Town monsters #####\n\n");
4472 /* Note the dungeon */
4475 fprintf(fff, "\n##### Normal monsters #####\n\n");
4478 /* Record the change */
4479 mode = r_ptr->level;
4482 /* Acquire the flags */
4483 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4484 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4485 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4486 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4487 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4488 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4489 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4490 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4491 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4492 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4494 /* Write New/Number/Name */
4495 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4498 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4500 /* Write Information */
4501 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4502 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4504 /* Write more information */
4505 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4508 for(j = 0; j < 4; j++)
4510 b_ptr = &(r_ptr->blow[j]);
4512 /* Stop when done */
4513 if (!b_ptr->method) break;
4515 /* Write the blows */
4516 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4517 r_info_blow_effect[b_ptr->effect],
4518 b_ptr->d_dice, b_ptr->d_side);
4521 /* Extract the flags */
4522 for (fc = 0, j = 0; j < 32 * 3; j++)
4524 /* Check this flag */
4525 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4528 /* Extract the extra flags */
4529 for (j = 32 * 6; j < 32 * 10; j++)
4531 /* Check this flag */
4532 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4535 /* Write the flags */
4536 for (j = 0; j < fc;)
4540 /* Start the line */
4543 for (bc = 0; (bc < 60) && (j < fc); j++)
4547 /* Format the flag */
4548 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4550 /* Add it to the buffer */
4553 /* Note the length */
4557 /* Done with this line; write it */
4558 fprintf(fff, "%s\n", buf);
4561 /* Write Spells if applicable */
4562 if (r_ptr->freq_spell)
4564 /* Write the frequency */
4565 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4567 /* Extract the spell flags */
4568 for (fc = 0, j = 96; j < 192; j++)
4570 /* Check this flag */
4571 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4574 /* Write the flags */
4575 for (j = 0; j < fc;)
4579 /* Start the line */
4582 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4586 /* Format the flag */
4587 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4591 /* Note the length */
4598 /* Done with this line; write it */
4599 fprintf(fff, "%s\n", buf);
4603 /* Acquire the description */
4604 desc = r_text + r_ptr->text;
4605 dlen = strlen(desc);
4607 /* Write Description */
4608 for (j = 0; j < dlen;)
4612 /* Start the line */
4615 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4623 /* Done with this line; write it */
4624 fprintf(fff, "%s\n", buf);
4627 /* Space between entries */