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[] =
257 static cptr r_info_flags1[] =
296 static cptr r_info_flags2[] =
335 static cptr r_info_flags3[] =
374 static cptr r_info_flags4[] =
413 static cptr r_info_flags5[] =
452 static cptr r_info_flags6[] =
469 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
492 static cptr r_info_flags7[] =
531 static cptr r_info_flags8[] =
563 "WILD_SWAMP", /* ToDo: Implement Swamp */
569 * Monster race flags - Drops
571 static cptr r_info_flags9[] =
610 * Monster race flags - Resistances
612 static cptr r_info_flagsr[] =
652 static cptr k_info_flags[] =
778 static cptr k_info_gen_flags[] =
818 static cptr d_info_flags1[] =
856 * Add a text to the text-storage and store offset to it.
858 * Returns FALSE when there isn't enough space available to store
861 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
863 /* Hack -- Verify space */
864 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
870 /* Advance and save the text index */
871 *offset = ++head->text_size;
874 /* Additional text */
875 else if (normal_text)
878 * If neither the end of the last line nor
879 * the beginning of current line is not a space,
880 * fill up a space as a correct separator of two words.
882 if (head->text_size > 0 &&
884 (*(head->text_ptr + head->text_size - 1) != ' ') &&
885 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
886 (buf[0] != ' ') && !iskanji(buf[0])
888 (*(head->text_ptr + head->text_size - 1) != ' ') &&
894 *(head->text_ptr + head->text_size) = ' ';
896 /* Advance the index */
901 /* Append chars to the text */
902 strcpy(head->text_ptr + head->text_size, buf);
904 /* Advance the index */
905 head->text_size += strlen(buf);
913 * Add a name to the name-storage and return an offset to it.
915 * Returns FALSE when there isn't enough space available to store
918 static bool add_name(u32b *offset, header *head, cptr buf)
920 /* Hack -- Verify space */
921 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
927 /* Advance and save the name index */
928 *offset = ++head->name_size;
931 /* Append chars to the names */
932 strcpy(head->name_ptr + head->name_size, buf);
934 /* Advance the index */
935 head->name_size += strlen(buf);
943 * Add a tag to the tag-storage and return an offset to it.
945 * Returns FALSE when there isn't enough space available to store
948 static bool add_tag(s16b *offset, header *head, cptr buf)
952 /* Search for an existing (fake) tag */
953 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
956 if (streq(&head->tag_ptr[i], buf)) break;
959 /* There was no existing tag */
960 if (i >= head->tag_size)
962 /* Hack -- Verify space */
963 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
966 /* Append chars to the tags */
967 strcpy(head->tag_ptr + head->tag_size, buf);
969 /* Point the new tag */
972 /* Advance the index */
973 head->tag_size += strlen(buf) + 1;
976 /* Return offset of the tag */
985 * Convert a "color letter" into an "actual" color
986 * The colors are: dwsorgbuDWvyRGBU, as shown below
988 byte color_char_to_attr(char c)
992 case 'd': return (TERM_DARK);
993 case 'w': return (TERM_WHITE);
994 case 's': return (TERM_SLATE);
995 case 'o': return (TERM_ORANGE);
996 case 'r': return (TERM_RED);
997 case 'g': return (TERM_GREEN);
998 case 'b': return (TERM_BLUE);
999 case 'u': return (TERM_UMBER);
1001 case 'D': return (TERM_L_DARK);
1002 case 'W': return (TERM_L_WHITE);
1003 case 'v': return (TERM_VIOLET);
1004 case 'y': return (TERM_YELLOW);
1005 case 'R': return (TERM_L_RED);
1006 case 'G': return (TERM_L_GREEN);
1007 case 'B': return (TERM_L_BLUE);
1008 case 'U': return (TERM_L_UMBER);
1016 /*** Initialize from ascii template files ***/
1020 * Initialize an "*_info" array, by parsing an ascii "template" file
1022 errr init_info_txt(FILE *fp, char *buf, header *head,
1023 parse_info_txt_func parse_info_txt_line)
1027 /* Just before the first record */
1030 /* Just before the first line */
1034 /* Prepare the "fake" stuff */
1035 head->name_size = 0;
1036 head->text_size = 0;
1040 while (0 == my_fgets(fp, buf, 1024))
1042 /* Advance the line number */
1045 /* Skip comments and blank lines */
1046 if (!buf[0] || (buf[0] == '#')) continue;
1048 /* Verify correct "colon" format */
1049 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1052 /* Hack -- Process 'V' for "Version" */
1059 /* Mega Hack -- Calculate Check Sum */
1060 if (buf[0] != 'N' && buf[0] != 'D')
1063 for (i = 0; buf[i]; i++)
1065 head->v_extra += (byte)buf[i];
1066 head->v_extra ^= (1 << (i % 8));
1070 /* Parse the line */
1071 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1076 /* Complete the "name" and "text" sizes */
1077 if (head->name_size) head->name_size++;
1078 if (head->text_size) head->text_size++;
1086 * Initialize the "v_info" array, by parsing an ascii "template" file
1088 errr parse_v_info(char *buf, header *head)
1094 static vault_type *v_ptr = NULL;
1096 /* Process 'N' for "New/Number/Name" */
1099 /* Find the colon before the name */
1100 s = my_strchr(buf+2, ':');
1102 /* Verify that colon */
1105 /* Nuke the colon, advance to the name */
1108 /* Paranoia -- require a name */
1109 if (!*s) return (1);
1114 /* Verify information */
1115 if (i <= error_idx) return (4);
1117 /* Verify information */
1118 if (i >= head->info_num) return (2);
1120 /* Save the index */
1123 /* Point at the "info" */
1126 /* Store the name */
1127 if (!add_name(&v_ptr->name, head, s)) return (7);
1130 /* There better be a current v_ptr */
1131 else if (!v_ptr) return (3);
1133 /* Process 'D' for "Description" */
1134 else if (buf[0] == 'D')
1136 /* Acquire the text */
1139 /* Store the text */
1140 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1143 /* Process 'X' for "Extra info" (one line only) */
1144 else if (buf[0] == 'X')
1146 int typ, rat, hgt, wid;
1148 /* Scan for the values */
1149 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1150 &typ, &rat, &hgt, &wid)) return (1);
1152 /* Save the values */
1169 * Initialize the "s_info" array, by parsing an ascii "template" file
1171 errr parse_s_info(char *buf, header *head)
1176 static skill_table *s_ptr = NULL;
1179 /* Process 'N' for "New/Number/Name" */
1185 /* Verify information */
1186 if (i <= error_idx) return (4);
1188 /* Verify information */
1189 if (i >= head->info_num) return (2);
1191 /* Save the index */
1194 /* Point at the "info" */
1198 /* There better be a current s_ptr */
1199 else if (!s_ptr) return (3);
1201 /* Process 'W' for "Weapon exp" */
1202 else if (buf[0] == 'W')
1204 int tval, sval, start, max;
1205 const s16b exp_conv_table[] =
1207 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1208 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1211 /* Scan for the values */
1212 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1213 &tval, &sval, &start, &max)) return (1);
1215 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1216 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1218 /* Save the values */
1219 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1220 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1223 /* Process 'S' for "Skill exp" */
1224 else if (buf[0] == 'S')
1226 int num, start, max;
1228 /* Scan for the values */
1229 if (3 != sscanf(buf+2, "%d:%d:%d",
1230 &num, &start, &max)) return (1);
1232 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1233 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1235 /* Save the values */
1236 s_ptr->s_start[num] = start;
1237 s_ptr->s_max[num] = max;
1250 * Initialize the "m_info" array, by parsing an ascii "template" file
1252 errr parse_m_info(char *buf, header *head)
1259 static player_magic *m_ptr = NULL;
1262 static int realm, magic_idx = 0, readable = 0;
1265 /* Process 'N' for "New/Number/Name" */
1271 /* Verify information */
1272 if (i <= error_idx) return (4);
1274 /* Verify information */
1275 if (i >= head->info_num) return (2);
1277 /* Save the index */
1280 /* Point at the "info" */
1284 /* There better be a current m_ptr */
1285 else if (!m_ptr) return (3);
1287 /* Process 'I' for "Info" (one line only) */
1288 else if (buf[0] == 'I')
1291 int xtra, type, first, weight;
1293 /* Find the colon before the name */
1294 s = my_strchr(buf+2, ':');
1296 /* Verify that colon */
1299 /* Nuke the colon, advance to the name */
1304 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1305 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1306 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1307 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1308 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1313 /* Find the colon before the name */
1314 s = my_strchr(s, ':');
1316 /* Verify that colon */
1319 /* Nuke the colon, advance to the name */
1322 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1323 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1324 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1325 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1326 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1327 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1331 /* Scan for the values */
1332 if (4 != sscanf(s, "%x:%d:%d:%d",
1333 (uint *)&xtra, &type, &first, &weight)) return (1);
1335 m_ptr->spell_xtra = xtra;
1336 m_ptr->spell_type = type;
1337 m_ptr->spell_first = first;
1338 m_ptr->spell_weight = weight;
1342 /* Process 'R' for "Realm" (one line only) */
1343 else if (buf[0] == 'R')
1345 /* Scan for the values */
1346 if (2 != sscanf(buf+2, "%d:%d",
1347 &realm, &readable)) return (1);
1352 else if (buf[0] == 'T')
1354 int level, mana, fail, exp;
1356 if (!readable) return (1);
1357 /* Scan for the values */
1358 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1359 &level, &mana, &fail, &exp)) return (1);
1361 m_ptr->info[realm][magic_idx].slevel = level;
1362 m_ptr->info[realm][magic_idx].smana = mana;
1363 m_ptr->info[realm][magic_idx].sfail = fail;
1364 m_ptr->info[realm][magic_idx].sexp = exp;
1378 * Grab one flag from a textual string
1380 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1385 for (i = 0; i < 32; i++)
1387 if (streq(what, names[i]))
1389 *flags |= (1L << i);
1399 * Grab one flag in an feature_type from a textual string
1401 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1406 for (i = 0; i < FF_FLAG_MAX; i++)
1408 if (streq(what, f_info_flags[i]))
1410 add_flag(f_ptr->flags, i);
1417 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1419 msg_format("Unknown feature flag '%s'.", what);
1423 return PARSE_ERROR_GENERIC;
1428 * Grab an action in an feature_type from a textual string
1430 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1435 for (i = 0; i < FF_FLAG_MAX; i++)
1437 if (streq(what, f_info_flags[i]))
1439 f_ptr->state[count].action = i;
1446 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1448 msg_format("Unknown feature action '%s'.", what);
1452 return PARSE_ERROR_GENERIC;
1457 * Initialize the "f_info" array, by parsing an ascii "template" file
1459 errr parse_f_info(char *buf, header *head)
1466 static feature_type *f_ptr = NULL;
1469 /* Process 'N' for "New/Number/Name" */
1472 /* Find the colon before the name */
1473 s = my_strchr(buf+2, ':');
1477 /* Nuke the colon, advance to the name */
1484 /* Verify information */
1485 if (i <= error_idx) return (4);
1487 /* Verify information */
1488 if (i >= head->info_num) return (2);
1490 /* Save the index */
1493 /* Point at the "info" */
1496 /* Tag name is given */
1500 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1503 /* Default "mimic" */
1506 /* Default "destroyed state" -- if not specified */
1507 f_ptr->destroyed = i;
1509 /* Default "states" */
1510 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1513 /* There better be a current f_ptr */
1514 else if (!f_ptr) return (3);
1517 else if (buf[0] == 'J')
1519 /* Store the name */
1520 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1523 else if (buf[0] == 'E')
1525 /* Ignore english name */
1528 else if (buf[0] == 'J')
1530 /* Ignore Japanese name */
1533 else if (buf[0] == 'E')
1535 /* Acquire the Text */
1538 /* Store the name */
1539 if (!add_name(&f_ptr->name, head, s)) return (7);
1544 /* Process 'M' for "Mimic" (one line only) */
1545 else if (buf[0] == 'M')
1549 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1551 /* Record a fake tag index */
1552 f_ptr->mimic = -offset;
1556 /* Process 'G' for "Graphics" (one line only) */
1557 else if (buf[0] == 'G')
1561 char char_tmp[F_LIT_MAX];
1564 if (buf[1] != ':') return (1);
1565 if (!buf[2]) return (1);
1566 if (buf[3] != ':') return (1);
1567 if (!buf[4]) return (1);
1569 /* Extract the char */
1570 char_tmp[F_LIT_STANDARD] = buf[2];
1572 /* Extract the color */
1573 s_attr = color_char_to_attr(buf[4]);
1576 if (s_attr > 127) return (1);
1578 /* Save the standard values */
1579 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1580 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1582 /* Is this feature supports lighting? */
1585 /* G:c:a:LIT (default) */
1586 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1588 /* G:c:a:lc:la:dc:da */
1589 if (!streq(buf + 6, "LIT"))
1591 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1593 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1594 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1595 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1596 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1598 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1600 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1603 /* Use default lighting */
1606 /* No lighting support */
1607 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1610 /* Extract the color */
1611 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1612 if (f_ptr->d_attr[j] > 127) return 1;
1615 f_ptr->d_char[j] = char_tmp[j];
1621 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1623 f_ptr->d_attr[j] = s_attr;
1624 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1630 /* Hack -- Process 'F' for flags */
1631 else if (buf[0] == 'F')
1633 /* Parse every entry textually */
1634 for (s = buf + 2; *s; )
1636 /* Find the end of this entry */
1637 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1639 /* Nuke and skip any dividers */
1643 while (*t == ' ' || *t == '|') t++;
1646 /* XXX XXX XXX Hack -- Read feature subtype */
1647 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1649 /* Extract a "subtype" */
1652 /* Start at next entry */
1659 /* XXX XXX XXX Hack -- Read feature power */
1660 if (1 == sscanf(s, "POWER_%d", &i))
1662 /* Extract a "power" */
1665 /* Start at next entry */
1672 /* Parse this entry */
1673 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1675 /* Start the next entry */
1680 /* Process 'W' for "More Info" (one line only) */
1681 else if (buf[0] == 'W')
1685 /* Scan for the value */
1686 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1688 /* Save the value */
1689 f_ptr->priority = priority;
1692 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1693 else if (buf[0] == 'K')
1697 /* Find the next empty state slot (if any) */
1698 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1700 /* Oops, no more slots */
1701 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1703 /* Analyze the first field */
1704 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1706 /* Terminate the field (if necessary) */
1707 if (*t == ':') *t++ = '\0';
1709 /* Is this default entry? */
1710 if (streq(s, "DESTROYED"))
1712 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1714 /* Record a fake tag index */
1715 f_ptr->destroyed = -offset;
1720 f_ptr->state[i].action = 0;
1722 /* Parse this entry */
1723 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1725 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1727 /* Record a fake tag index */
1728 f_ptr->state[i].result = -offset;
1741 * Convert a fake tag to a real feat index
1743 s16b f_tag_to_index(cptr str)
1747 /* Search for real index corresponding to this fake tag */
1748 for (i = 0; i < f_head.info_num; i++)
1750 if (streq(f_tag + f_info[i].tag, str))
1752 /* Return the index */
1763 * Search for real index corresponding to this fake tag
1765 static void search_real_feat(s16b *feat)
1769 /* Don't convert non-fake tag */
1770 if (*feat >= 0) return;
1772 /* Search for real index corresponding to this fake tag */
1773 for (i = 0; i < f_head.info_num; i++)
1775 if ((-(*feat)) == f_info[i].tag)
1777 /* Record real index */
1785 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1787 msg_format("%s is undefined.", f_tag + (-(*feat)));
1793 * Retouch fake tags of f_info
1795 void retouch_f_info(header *head)
1799 /* Convert fake tags to real feat indices */
1800 for (i = 0; i < head->info_num; i++)
1802 feature_type *f_ptr = &f_info[i];
1805 search_real_feat(&f_ptr->mimic);
1807 search_real_feat(&f_ptr->destroyed);
1809 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1815 * Grab one flag in an object_kind from a textual string
1817 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1822 for (i = 0; i < TR_FLAG_MAX; i++)
1824 if (streq(what, k_info_flags[i]))
1826 add_flag(k_ptr->flags, i);
1831 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1836 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1838 msg_format("Unknown object flag '%s'.", what);
1848 * Initialize the "k_info" array, by parsing an ascii "template" file
1850 errr parse_k_info(char *buf, header *head)
1857 static object_kind *k_ptr = NULL;
1860 /* Process 'N' for "New/Number/Name" */
1867 /* Find the colon before the name */
1868 s = my_strchr(buf+2, ':');
1870 /* Verify that colon */
1873 /* Nuke the colon, advance to the name */
1879 /* Verify information */
1880 if (i <= error_idx) return (4);
1882 /* Verify information */
1883 if (i >= head->info_num) return (2);
1885 /* Save the index */
1888 /* Point at the "info" */
1892 /* Paranoia -- require a name */
1893 if (!*s) return (1);
1895 /* Find the colon before the flavor */
1896 flavor = my_strchr(s, ':');
1898 /* Verify that colon */
1901 /* Nuke the colon, advance to the flavor */
1904 /* Store the flavor */
1905 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1908 /* Store the name */
1909 if (!add_name(&k_ptr->name, head, s)) return (7);
1913 /* There better be a current k_ptr */
1914 else if (!k_ptr) return (3);
1918 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1919 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1920 else if (buf[0] == 'E')
1925 else if (buf[0] == 'E')
1929 /* Acquire the name */
1932 /* Find the colon before the flavor */
1933 flavor = my_strchr(s, ':');
1935 /* Verify that colon */
1938 /* Nuke the colon, advance to the flavor */
1941 /* Store the flavor */
1942 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1945 /* Store the name */
1946 if (!add_name(&k_ptr->name, head, s)) return (7);
1950 /* Process 'D' for "Description" */
1951 else if (buf[0] == 'D')
1956 /* Acquire the text */
1961 /* Acquire the text */
1965 /* Store the text */
1966 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
1969 /* Process 'G' for "Graphics" (one line only) */
1970 else if (buf[0] == 'G')
1976 if (buf[1] != ':') return (1);
1977 if (!buf[2]) return (1);
1978 if (buf[3] != ':') return (1);
1979 if (!buf[4]) return (1);
1981 /* Extract the char */
1984 /* Extract the attr */
1985 tmp = color_char_to_attr(buf[4]);
1988 if (tmp > 127) return (1);
1990 /* Save the values */
1991 k_ptr->d_attr = tmp;
1992 k_ptr->d_char = sym;
1995 /* Process 'I' for "Info" (one line only) */
1996 else if (buf[0] == 'I')
1998 int tval, sval, pval;
2000 /* Scan for the values */
2001 if (3 != sscanf(buf+2, "%d:%d:%d",
2002 &tval, &sval, &pval)) return (1);
2004 /* Save the values */
2010 /* Process 'W' for "More Info" (one line only) */
2011 else if (buf[0] == 'W')
2013 int level, extra, wgt;
2016 /* Scan for the values */
2017 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2018 &level, &extra, &wgt, &cost)) return (1);
2020 /* Save the values */
2021 k_ptr->level = level;
2022 k_ptr->extra = extra;
2023 k_ptr->weight = wgt;
2027 /* Process 'A' for "Allocation" (one line only) */
2028 else if (buf[0] == 'A')
2032 /* XXX XXX XXX Simply read each number following a colon */
2033 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2035 /* Default chance */
2036 k_ptr->chance[i] = 1;
2038 /* Store the attack damage index */
2039 k_ptr->locale[i] = atoi(s+1);
2041 /* Find the slash */
2042 t = my_strchr(s+1, '/');
2044 /* Find the next colon */
2045 s = my_strchr(s+1, ':');
2047 /* If the slash is "nearby", use it */
2048 if (t && (!s || t < s))
2050 int chance = atoi(t+1);
2051 if (chance > 0) k_ptr->chance[i] = chance;
2056 /* Hack -- Process 'P' for "power" and such */
2057 else if (buf[0] == 'P')
2059 int ac, hd1, hd2, th, td, ta;
2061 /* Scan for the values */
2062 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2063 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2073 /* Hack -- Process 'F' for flags */
2074 else if (buf[0] == 'F')
2076 /* Parse every entry textually */
2077 for (s = buf + 2; *s; )
2079 /* Find the end of this entry */
2080 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2082 /* Nuke and skip any dividers */
2086 while (*t == ' ' || *t == '|') t++;
2089 /* Parse this entry */
2090 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2092 /* Start the next entry */
2108 * Grab one flag in an artifact_type from a textual string
2110 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2115 for (i = 0; i < TR_FLAG_MAX; i++)
2117 if (streq(what, k_info_flags[i]))
2119 add_flag(a_ptr->flags, i);
2124 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2129 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2131 msg_format("Unknown artifact flag '%s'.", what);
2143 * Initialize the "a_info" array, by parsing an ascii "template" file
2145 errr parse_a_info(char *buf, header *head)
2152 static artifact_type *a_ptr = NULL;
2155 /* Process 'N' for "New/Number/Name" */
2158 /* Find the colon before the name */
2159 s = my_strchr(buf+2, ':');
2161 /* Verify that colon */
2164 /* Nuke the colon, advance to the name */
2167 /* Paranoia -- require a name */
2168 if (!*s) return (1);
2173 /* Verify information */
2174 if (i < error_idx) return (4);
2176 /* Verify information */
2177 if (i >= head->info_num) return (2);
2179 /* Save the index */
2182 /* Point at the "info" */
2185 /* Ignore everything */
2186 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2187 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2188 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2189 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2191 /* Store the name */
2192 if (!add_name(&a_ptr->name, head, s)) return (7);
2196 /* There better be a current a_ptr */
2197 else if (!a_ptr) return (3);
2201 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2202 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2203 else if (buf[0] == 'E')
2208 else if (buf[0] == 'E')
2210 /* Acquire the Text */
2213 /* Store the name */
2214 if (!add_name(&a_ptr->name, head, s)) return (7);
2218 /* Process 'D' for "Description" */
2219 else if (buf[0] == 'D')
2224 /* Acquire the text */
2229 /* Acquire the text */
2233 /* Store the text */
2234 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2238 /* Process 'I' for "Info" (one line only) */
2239 else if (buf[0] == 'I')
2241 int tval, sval, pval;
2243 /* Scan for the values */
2244 if (3 != sscanf(buf+2, "%d:%d:%d",
2245 &tval, &sval, &pval)) return (1);
2247 /* Save the values */
2253 /* Process 'W' for "More Info" (one line only) */
2254 else if (buf[0] == 'W')
2256 int level, rarity, wgt;
2259 /* Scan for the values */
2260 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2261 &level, &rarity, &wgt, &cost)) return (1);
2263 /* Save the values */
2264 a_ptr->level = level;
2265 a_ptr->rarity = rarity;
2266 a_ptr->weight = wgt;
2270 /* Hack -- Process 'P' for "power" and such */
2271 else if (buf[0] == 'P')
2273 int ac, hd1, hd2, th, td, ta;
2275 /* Scan for the values */
2276 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2277 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2287 /* Hack -- Process 'F' for flags */
2288 else if (buf[0] == 'F')
2290 /* Parse every entry textually */
2291 for (s = buf + 2; *s; )
2293 /* Find the end of this entry */
2294 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2296 /* Nuke and skip any dividers */
2300 while ((*t == ' ') || (*t == '|')) t++;
2303 /* Parse this entry */
2304 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2306 /* Start the next entry */
2322 * Grab one flag in a ego-item_type from a textual string
2324 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2329 for (i = 0; i < TR_FLAG_MAX; i++)
2331 if (streq(what, k_info_flags[i]))
2333 add_flag(e_ptr->flags, i);
2338 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2343 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2345 msg_format("Unknown ego-item flag '%s'.", what);
2357 * Initialize the "e_info" array, by parsing an ascii "template" file
2359 errr parse_e_info(char *buf, header *head)
2366 static ego_item_type *e_ptr = NULL;
2369 /* Just before the first record */
2372 /* Just before the first line */
2376 /* Process 'N' for "New/Number/Name" */
2379 /* Find the colon before the name */
2380 s = my_strchr(buf+2, ':');
2382 /* Verify that colon */
2385 /* Nuke the colon, advance to the name */
2388 /* Paranoia -- require a name */
2389 if (!*s) return (1);
2394 /* Verify information */
2395 if (i < error_idx) return (4);
2397 /* Verify information */
2398 if (i >= head->info_num) return (2);
2400 /* Save the index */
2403 /* Point at the "info" */
2406 /* Store the name */
2407 if (!add_name(&e_ptr->name, head, s)) return (7);
2411 /* There better be a current e_ptr */
2412 else if (!e_ptr) return (3);
2416 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2417 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2418 else if (buf[0] == 'E')
2423 else if (buf[0] == 'E')
2425 /* Acquire the Text */
2428 /* Store the name */
2429 if (!add_name(&e_ptr->name, head, s)) return (7);
2434 /* Process 'D' for "Description" */
2435 else if (buf[0] == 'D')
2437 /* Acquire the text */
2440 /* Store the text */
2441 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2446 /* Process 'X' for "Xtra" (one line only) */
2447 else if (buf[0] == 'X')
2451 /* Scan for the values */
2452 if (2 != sscanf(buf+2, "%d:%d",
2453 &slot, &rating)) return (1);
2455 /* Save the values */
2457 e_ptr->rating = rating;
2460 /* Process 'W' for "More Info" (one line only) */
2461 else if (buf[0] == 'W')
2463 int level, rarity, pad2;
2466 /* Scan for the values */
2467 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2468 &level, &rarity, &pad2, &cost)) return (1);
2470 /* Save the values */
2471 e_ptr->level = level;
2472 e_ptr->rarity = rarity;
2473 /* e_ptr->weight = wgt; */
2477 /* Hack -- Process 'C' for "creation" */
2478 else if (buf[0] == 'C')
2482 /* Scan for the values */
2483 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2484 &th, &td, &ta, &pv)) return (1);
2486 e_ptr->max_to_h = th;
2487 e_ptr->max_to_d = td;
2488 e_ptr->max_to_a = ta;
2489 e_ptr->max_pval = pv;
2492 /* Hack -- Process 'F' for flags */
2493 else if (buf[0] == 'F')
2495 /* Parse every entry textually */
2496 for (s = buf + 2; *s; )
2498 /* Find the end of this entry */
2499 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2501 /* Nuke and skip any dividers */
2505 while ((*t == ' ') || (*t == '|')) t++;
2508 /* Parse this entry */
2509 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2511 /* Start the next entry */
2525 * Grab one (basic) flag in a monster_race from a textual string
2527 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2529 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2532 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2535 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2538 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2541 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2544 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2547 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2552 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2554 msg_format("Unknown monster flag '%s'.", what);
2564 * Grab one (spell) flag in a monster_race from a textual string
2566 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2568 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2571 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2574 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2579 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2581 msg_format("Unknown monster flag '%s'.", what);
2593 * Initialize the "r_info" array, by parsing an ascii "template" file
2595 errr parse_r_info(char *buf, header *head)
2602 static monster_race *r_ptr = NULL;
2605 /* Process 'N' for "New/Number/Name" */
2608 /* Find the colon before the name */
2609 s = my_strchr(buf+2, ':');
2611 /* Verify that colon */
2614 /* Nuke the colon, advance to the name */
2617 /* Paranoia -- require a name */
2618 if (!*s) return (1);
2623 /* Verify information */
2624 if (i < error_idx) return (4);
2626 /* Verify information */
2627 if (i >= head->info_num) return (2);
2629 /* Save the index */
2632 /* Point at the "info" */
2635 /* Store the name */
2636 if (!add_name(&r_ptr->name, head, s)) return (7);
2640 /* There better be a current r_ptr */
2641 else if (!r_ptr) return (3);
2645 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2646 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2647 else if (buf[0] == 'E')
2649 /* Acquire the Text */
2652 /* Store the name */
2653 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2656 else if (buf[0] == 'E')
2658 /* Acquire the Text */
2661 /* Store the name */
2662 if (!add_name(&r_ptr->name, head, s)) return (7);
2665 /* Process 'D' for "Description" */
2666 else if (buf[0] == 'D')
2671 /* Acquire the text */
2676 /* Acquire the text */
2680 /* Store the text */
2681 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2684 /* Process 'G' for "Graphics" (one line only) */
2685 else if (buf[0] == 'G')
2691 if (buf[1] != ':') return (1);
2692 if (!buf[2]) return (1);
2693 if (buf[3] != ':') return (1);
2694 if (!buf[4]) return (1);
2696 /* Extract the char */
2699 /* Extract the attr */
2700 tmp = color_char_to_attr(buf[4]);
2703 if (tmp > 127) return (1);
2705 /* Save the values */
2706 r_ptr->d_char = sym;
2707 r_ptr->d_attr = tmp;
2710 /* Process 'I' for "Info" (one line only) */
2711 else if (buf[0] == 'I')
2713 int spd, hp1, hp2, aaf, ac, slp;
2715 /* Scan for the other values */
2716 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2717 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2719 /* Save the values */
2721 r_ptr->hdice = MAX(hp1, 1);
2722 r_ptr->hside = MAX(hp2, 1);
2728 /* Process 'W' for "More Info" (one line only) */
2729 else if (buf[0] == 'W')
2736 /* Scan for the values */
2737 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2738 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2740 /* Save the values */
2742 r_ptr->rarity = rar;
2745 r_ptr->next_exp = nextexp;
2746 r_ptr->next_r_idx = nextmon;
2749 /* Process 'B' for "Blows" (up to four lines) */
2750 else if (buf[0] == 'B')
2754 /* Find the next empty blow slot (if any) */
2755 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2757 /* Oops, no more slots */
2758 if (i == 4) return (1);
2760 /* Analyze the first field */
2761 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2763 /* Terminate the field (if necessary) */
2764 if (*t == ':') *t++ = '\0';
2766 /* Analyze the method */
2767 for (n1 = 0; r_info_blow_method[n1]; n1++)
2769 if (streq(s, r_info_blow_method[n1])) break;
2772 /* Invalid method */
2773 if (!r_info_blow_method[n1]) return (1);
2775 /* Analyze the second field */
2776 for (s = t; *t && (*t != ':'); t++) /* loop */;
2778 /* Terminate the field (if necessary) */
2779 if (*t == ':') *t++ = '\0';
2781 /* Analyze effect */
2782 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2784 if (streq(s, r_info_blow_effect[n2])) break;
2787 /* Invalid effect */
2788 if (!r_info_blow_effect[n2]) return (1);
2790 /* Analyze the third field */
2791 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2793 /* Terminate the field (if necessary) */
2794 if (*t == 'd') *t++ = '\0';
2796 /* Save the method */
2797 r_ptr->blow[i].method = n1;
2799 /* Save the effect */
2800 r_ptr->blow[i].effect = n2;
2802 /* Extract the damage dice and sides */
2803 r_ptr->blow[i].d_dice = atoi(s);
2804 r_ptr->blow[i].d_side = atoi(t);
2807 /* Process 'F' for "Basic Flags" (multiple lines) */
2808 else if (buf[0] == 'F')
2810 /* Parse every entry */
2811 for (s = buf + 2; *s; )
2813 /* Find the end of this entry */
2814 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2816 /* Nuke and skip any dividers */
2820 while (*t == ' ' || *t == '|') t++;
2823 /* Parse this entry */
2824 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2826 /* Start the next entry */
2831 /* Process 'S' for "Spell Flags" (multiple lines) */
2832 else if (buf[0] == 'S')
2834 /* Parse every entry */
2835 for (s = buf + 2; *s; )
2837 /* Find the end of this entry */
2838 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2840 /* Nuke and skip any dividers */
2844 while ((*t == ' ') || (*t == '|')) t++;
2847 /* XXX XXX XXX Hack -- Read spell frequency */
2848 if (1 == sscanf(s, "1_IN_%d", &i))
2850 /* Extract a "frequency" */
2851 r_ptr->freq_spell = 100 / i;
2853 /* Start at next entry */
2860 /* Parse this entry */
2861 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2863 /* Start the next entry */
2878 * Grab one flag for a dungeon type from a textual string
2880 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2882 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2887 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2889 msg_format("Unknown dungeon type flag '%s'.", what);
2897 * Grab one (basic) flag in a monster_race from a textual string
2899 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2901 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2904 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2907 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2910 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2913 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2916 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2919 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2924 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2926 msg_format("Unknown monster flag '%s'.", what);
2934 * Grab one (spell) flag in a monster_race from a textual string
2936 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2938 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2941 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2944 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2949 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2951 msg_format("Unknown monster flag '%s'.", what);
2959 * Initialize the "d_info" array, by parsing an ascii "template" file
2961 errr parse_d_info(char *buf, header *head)
2968 static dungeon_info_type *d_ptr = NULL;
2971 /* Process 'N' for "New/Number/Name" */
2974 /* Find the colon before the name */
2975 s = my_strchr(buf+2, ':');
2977 /* Verify that colon */
2980 /* Nuke the colon, advance to the name */
2983 /* Paranoia -- require a name */
2984 if (!*s) return (1);
2989 /* Verify information */
2990 if (i < error_idx) return (4);
2992 /* Verify information */
2993 if (i >= head->info_num) return (2);
2995 /* Save the index */
2998 /* Point at the "info" */
3001 /* Store the name */
3002 if (!add_name(&d_ptr->name, head, s)) return (7);
3007 else if (buf[0] == 'E') return (0);
3009 else if (buf[0] == 'E')
3011 /* Acquire the Text */
3014 /* Store the name */
3015 if (!add_name(&d_ptr->name, head, s)) return (7);
3019 /* Process 'D' for "Description */
3020 else if (buf[0] == 'D')
3025 /* Acquire the text */
3030 /* Acquire the text */
3034 /* Store the text */
3035 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3038 /* Process 'W' for "More Info" (one line only) */
3039 else if (buf[0] == 'W')
3041 int min_lev, max_lev;
3043 int min_alloc, max_chance;
3044 int obj_good, obj_great;
3047 /* Scan for the values */
3048 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3049 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3051 /* Save the values */
3052 d_ptr->mindepth = min_lev;
3053 d_ptr->maxdepth = max_lev;
3054 d_ptr->min_plev = min_plev;
3056 d_ptr->min_m_alloc_level = min_alloc;
3057 d_ptr->max_m_alloc_chance = max_chance;
3058 d_ptr->obj_good = obj_good;
3059 d_ptr->obj_great = obj_great;
3064 /* Process 'P' for "Place Info" */
3065 else if (buf[0] == 'P')
3069 /* Scan for the values */
3070 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3072 /* Save the values */
3077 /* Process 'L' for "fLoor type" (one line only) */
3078 else if (buf[0] == 'L')
3082 /* Scan for the values */
3083 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3085 /* Save the values */
3086 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3088 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3089 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3091 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3093 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3096 /* Process 'A' for "wAll type" (one line only) */
3097 else if (buf[0] == 'A')
3101 /* Scan for the values */
3102 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3104 /* Save the values */
3105 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3107 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3108 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3110 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3113 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3114 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3116 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3117 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3119 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3120 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3122 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3123 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3126 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3127 else if (buf[0] == 'F')
3129 int artif = 0, monst = 0;
3131 /* Parse every entry */
3132 for (s = buf + 2; *s; )
3134 /* Find the end of this entry */
3135 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3137 /* Nuke and skip any dividers */
3141 while (*t == ' ' || *t == '|') t++;
3144 /* XXX XXX XXX Hack -- Read Final Artifact */
3145 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3147 /* Extract a "Final Artifact" */
3148 d_ptr->final_artifact = artif;
3150 /* Start at next entry */
3157 /* XXX XXX XXX Hack -- Read Final Object */
3158 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3160 /* Extract a "Final Artifact" */
3161 d_ptr->final_object = artif;
3163 /* Start at next entry */
3170 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3171 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3173 /* Extract a "Artifact Guardian" */
3174 d_ptr->final_guardian = monst;
3176 /* Start at next entry */
3183 /* XXX XXX XXX Hack -- Read Special Percentage */
3184 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3186 /* Extract a "Special %" */
3187 d_ptr->special_div = monst;
3189 /* Start at next entry */
3196 /* Parse this entry */
3197 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3199 /* Start the next entry */
3204 /* Process 'M' for "Basic Flags" (multiple lines) */
3205 else if (buf[0] == 'M')
3207 /* Parse every entry */
3208 for (s = buf + 2; *s; )
3210 /* Find the end of this entry */
3211 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3213 /* Nuke and skip any dividers */
3217 while (*t == ' ' || *t == '|') t++;
3220 /* Hack -- Read monster symbols */
3221 if (!strncmp(s, "R_CHAR_", 7))
3223 /* Skip "R_CHAR_" */
3227 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3229 /* Start at next entry */
3236 /* Parse this entry */
3237 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3239 /* Start the next entry */
3244 /* Process 'S' for "Spell Flags" (multiple lines) */
3245 else if (buf[0] == 'S')
3247 /* Parse every entry */
3248 for (s = buf + 2; *s; )
3250 /* Find the end of this entry */
3251 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3253 /* Nuke and skip any dividers */
3257 while ((*t == ' ') || (*t == '|')) t++;
3260 /* XXX XXX XXX Hack -- Read spell frequency */
3261 if (1 == sscanf(s, "1_IN_%d", &i))
3263 /* Start at next entry */
3270 /* Parse this entry */
3271 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3273 /* Start the next entry */
3286 #else /* ALLOW_TEMPLATES */
3292 #endif /* ALLOW_TEMPLATES */
3295 /* Random dungeon grid effects */
3296 #define RANDOM_NONE 0x00000000
3297 #define RANDOM_FEATURE 0x00000001
3298 #define RANDOM_MONSTER 0x00000002
3299 #define RANDOM_OBJECT 0x00000004
3300 #define RANDOM_EGO 0x00000008
3301 #define RANDOM_ARTIFACT 0x00000010
3302 #define RANDOM_TRAP 0x00000020
3305 typedef struct dungeon_grid dungeon_grid;
3309 int feature; /* Terrain feature */
3310 int monster; /* Monster */
3311 int object; /* Object */
3312 int ego; /* Ego-Item */
3313 int artifact; /* Artifact */
3314 int trap; /* Trap */
3315 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3316 int special; /* Reserved for special terrain info */
3317 int random; /* Number of the random effect */
3321 static dungeon_grid letter[255];
3325 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3327 static errr parse_line_feature(char *buf)
3333 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3335 /* Tokenize the line */
3336 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3338 /* Letter to assign */
3339 int index = zz[0][0];
3341 /* Reset the info for the letter */
3342 letter[index].feature = feat_none;
3343 letter[index].monster = 0;
3344 letter[index].object = 0;
3345 letter[index].ego = 0;
3346 letter[index].artifact = 0;
3347 letter[index].trap = feat_none;
3348 letter[index].cave_info = 0;
3349 letter[index].special = 0;
3350 letter[index].random = RANDOM_NONE;
3356 letter[index].special = atoi(zz[8]);
3360 if ((zz[7][0] == '*') && !zz[7][1])
3362 letter[index].random |= RANDOM_TRAP;
3366 letter[index].trap = f_tag_to_index(zz[7]);
3367 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3372 if (zz[6][0] == '*')
3374 letter[index].random |= RANDOM_ARTIFACT;
3375 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3379 letter[index].artifact = atoi(zz[6]);
3384 if (zz[5][0] == '*')
3386 letter[index].random |= RANDOM_EGO;
3387 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3391 letter[index].ego = atoi(zz[5]);
3396 if (zz[4][0] == '*')
3398 letter[index].random |= RANDOM_OBJECT;
3399 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3403 letter[index].object = atoi(zz[4]);
3408 if (zz[3][0] == '*')
3410 letter[index].random |= RANDOM_MONSTER;
3411 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3413 else if (zz[3][0] == 'c')
3415 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3416 letter[index].monster = - atoi(zz[3] + 1);
3420 letter[index].monster = atoi(zz[3]);
3425 letter[index].cave_info = atoi(zz[2]);
3429 if ((zz[1][0] == '*') && !zz[1][1])
3431 letter[index].random |= RANDOM_FEATURE;
3435 letter[index].feature = f_tag_to_index(zz[1]);
3436 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3449 * Process "B:<Index>:<Command>:..." -- Building definition
3451 static errr parse_line_building(char *buf)
3467 /* Get the building number */
3470 /* Find the colon after the building number */
3471 s = my_strchr(s, ':');
3473 /* Verify that colon */
3476 /* Nuke the colon, advance to the sub-index */
3479 /* Paranoia -- require a sub-index */
3480 if (!*s) return (1);
3482 /* Building definition sub-index */
3485 /* Building name, owner, race */
3488 if (tokenize(s + 2, 3, zz, 0) == 3)
3490 /* Name of the building */
3491 strcpy(building[index].name, zz[0]);
3493 /* Name of the owner */
3494 strcpy(building[index].owner_name, zz[1]);
3496 /* Race of the owner */
3497 strcpy(building[index].owner_race, zz[2]);
3502 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3505 /* Building Action */
3508 if (tokenize(s + 2, 8, zz, 0) >= 7)
3510 /* Index of the action */
3511 int action_index = atoi(zz[0]);
3513 /* Name of the action */
3514 strcpy(building[index].act_names[action_index], zz[1]);
3516 /* Cost of the action for members */
3517 building[index].member_costs[action_index] = atoi(zz[2]);
3519 /* Cost of the action for non-members */
3520 building[index].other_costs[action_index] = atoi(zz[3]);
3522 /* Letter assigned to the action */
3523 building[index].letters[action_index] = zz[4][0];
3526 building[index].actions[action_index] = atoi(zz[5]);
3528 /* Action restriction */
3529 building[index].action_restr[action_index] = atoi(zz[6]);
3534 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3537 /* Building Classes */
3540 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3542 for (i = 0; i < MAX_CLASS; i++)
3544 building[index].member_class[i] = atoi(zz[i]);
3550 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3553 /* Building Races */
3556 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3558 for (i = 0; i < MAX_RACES; i++)
3560 building[index].member_race[i] = atoi(zz[i]);
3566 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3569 /* Building Realms */
3572 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3574 for (i = 0; i < MAX_MAGIC; i++)
3576 building[index].member_realm[i+1] = atoi(zz[i]);
3582 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3587 /* Ignore scripts */
3593 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3602 * Place the object j_ptr to a grid
3604 static void drop_here(object_type *j_ptr, int y, int x)
3606 cave_type *c_ptr = &cave[y][x];
3609 /* Get new object */
3610 s16b o_idx = o_pop();
3612 /* Access new object */
3613 o_ptr = &o_list[o_idx];
3615 /* Structure copy */
3616 object_copy(o_ptr, j_ptr);
3624 o_ptr->held_m_idx = 0;
3627 o_ptr->next_o_idx = c_ptr->o_idx;
3629 /* Place the object */
3630 c_ptr->o_idx = o_idx;
3635 * Parse a sub-file of the "extra info"
3637 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3644 /* Skip "empty" lines */
3645 if (!buf[0]) return (0);
3647 /* Skip "blank" lines */
3648 if (isspace(buf[0])) return (0);
3651 if (buf[0] == '#') return (0);
3653 /* Require "?:*" format */
3654 if (buf[1] != ':') return (1);
3657 /* Process "%:<fname>" */
3660 /* Attempt to Process the given file */
3661 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3664 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3667 return parse_line_feature(buf);
3670 /* Process "D:<dungeon>" -- info for the cave grids */
3671 else if (buf[0] == 'D')
3673 object_type object_type_body;
3675 /* Acquire the text */
3678 /* Length of the text */
3679 int len = strlen(s);
3681 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3683 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3685 /* Access the grid */
3686 cave_type *c_ptr = &cave[*y][*x];
3690 int object_index = letter[idx].object;
3691 int monster_index = letter[idx].monster;
3692 int random = letter[idx].random;
3693 int artifact_index = letter[idx].artifact;
3695 /* Lay down a floor */
3696 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3698 /* Only the features */
3699 if (init_flags & INIT_ONLY_FEATURES) continue;
3702 c_ptr->info = letter[idx].cave_info;
3704 /* Create a monster */
3705 if (random & RANDOM_MONSTER)
3707 monster_level = base_level + monster_index;
3709 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3711 monster_level = base_level;
3713 else if (monster_index)
3715 int old_cur_num, old_max_num;
3718 if (monster_index < 0)
3720 monster_index = -monster_index;
3723 old_cur_num = r_info[monster_index].cur_num;
3724 old_max_num = r_info[monster_index].max_num;
3726 /* Make alive again */
3727 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3729 r_info[monster_index].cur_num = 0;
3730 r_info[monster_index].max_num = 1;
3733 /* Make alive again */
3734 /* Hack -- Non-unique Nazguls are semi-unique */
3735 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3737 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3739 r_info[monster_index].max_num++;
3744 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3748 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3750 /* Make alive again for real unique monster */
3751 r_info[monster_index].cur_num = old_cur_num;
3752 r_info[monster_index].max_num = old_max_num;
3756 /* Object (and possible trap) */
3757 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3759 object_level = base_level + object_index;
3762 * Random trap and random treasure defined
3763 * 25% chance for trap and 75% chance for object
3765 if (randint0(100) < 75)
3767 place_object(*y, *x, 0L);
3774 object_level = base_level;
3776 else if (random & RANDOM_OBJECT)
3778 object_level = base_level + object_index;
3780 /* Create an out of deep object */
3781 if (randint0(100) < 75)
3782 place_object(*y, *x, 0L);
3783 else if (randint0(100) < 80)
3784 place_object(*y, *x, AM_GOOD);
3786 place_object(*y, *x, AM_GOOD | AM_GREAT);
3788 object_level = base_level;
3791 else if (random & RANDOM_TRAP)
3795 /* Hidden trap (or door) */
3796 else if (letter[idx].trap)
3798 c_ptr->mimic = c_ptr->feat;
3799 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3801 else if (object_index)
3803 /* Get local object */
3804 object_type *o_ptr = &object_type_body;
3806 /* Create the item */
3807 object_prep(o_ptr, object_index);
3809 if (o_ptr->tval == TV_GOLD)
3811 coin_type = object_index - OBJ_GOLD_LIST;
3816 /* Apply magic (no messages, no artifacts) */
3817 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3819 drop_here(o_ptr, *y, *x);
3825 if (a_info[artifact_index].cur_num)
3827 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3829 object_type *q_ptr = &forge;
3831 object_prep(q_ptr, k_idx);
3833 /* Drop it in the dungeon */
3834 drop_here(q_ptr, *y, *x);
3838 /* Create the artifact */
3839 if (create_named_art(artifact_index, *y, *x))
3840 a_info[artifact_index].cur_num = 1;
3844 /* Terrain special */
3845 c_ptr->special = letter[idx].special;
3853 /* Process "Q:<number>:<command>:... -- quest info */
3854 else if (buf[0] == 'Q')
3861 num = tokenize(buf + 2, 33, zz, 0);
3865 num = tokenize(buf + 3, 33, zz, 0);
3868 /* Have we enough parameters? */
3869 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3872 q_ptr = &(quest[atoi(zz[0])]);
3874 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3875 if (zz[1][0] == 'Q')
3877 if (init_flags & INIT_ASSIGN)
3879 monster_race *r_ptr;
3880 artifact_type *a_ptr;
3882 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3884 q_ptr->type = atoi(zz[2]);
3885 q_ptr->num_mon = atoi(zz[3]);
3886 q_ptr->cur_num = atoi(zz[4]);
3887 q_ptr->max_num = atoi(zz[5]);
3888 q_ptr->level = atoi(zz[6]);
3889 q_ptr->r_idx = atoi(zz[7]);
3890 q_ptr->k_idx = atoi(zz[8]);
3891 q_ptr->dungeon = atoi(zz[9]);
3894 q_ptr->flags = atoi(zz[10]);
3896 r_ptr = &r_info[q_ptr->r_idx];
3897 if (r_ptr->flags1 & RF1_UNIQUE)
3898 r_ptr->flags1 |= RF1_QUESTOR;
3900 a_ptr = &a_info[q_ptr->k_idx];
3901 a_ptr->gen_flags |= TRG_QUESTITEM;
3906 /* Process "Q:<q_index>:N:<name>" -- quest name */
3907 else if (zz[1][0] == 'N')
3909 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3911 strcpy(q_ptr->name, zz[2]);
3917 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3918 else if (zz[1][0] == 'T')
3920 if (init_flags & INIT_SHOW_TEXT)
3922 strcpy(quest_text[quest_text_line], zz[2]);
3930 /* Process "W:<command>: ..." -- info for the wilderness */
3931 else if (buf[0] == 'W')
3933 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3936 /* Process "P:<y>:<x>" -- player position */
3937 else if (buf[0] == 'P')
3939 if (init_flags & INIT_CREATE_DUNGEON)
3941 if (tokenize(buf + 2, 2, zz, 0) == 2)
3943 int panels_x, panels_y;
3945 /* Hack - Set the dungeon size */
3946 panels_y = (*y / SCREEN_HGT);
3947 if (*y % SCREEN_HGT) panels_y++;
3948 cur_hgt = panels_y * SCREEN_HGT;
3950 panels_x = (*x / SCREEN_WID);
3951 if (*x % SCREEN_WID) panels_x++;
3952 cur_wid = panels_x * SCREEN_WID;
3954 /* Assume illegal panel */
3955 panel_row_min = cur_hgt;
3956 panel_col_min = cur_wid;
3958 /* Place player in a quest level */
3959 if (p_ptr->inside_quest)
3963 /* Delete the monster (if any) */
3964 delete_monster(py, px);
3972 /* Place player in the town */
3973 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3975 p_ptr->oldpy = atoi(zz[0]);
3976 p_ptr->oldpx = atoi(zz[1]);
3984 /* Process "B:<Index>:<Command>:..." -- Building definition */
3985 else if (buf[0] == 'B')
3987 return parse_line_building(buf);
3990 /* Process "M:<type>:<maximum>" -- set maximum values */
3991 else if (buf[0] == 'M')
3993 if (tokenize(buf+2, 2, zz, 0) == 2)
3996 if (zz[0][0] == 'T')
3998 max_towns = atoi(zz[1]);
4001 /* Maximum quests */
4002 else if (zz[0][0] == 'Q')
4004 max_quests = atoi(zz[1]);
4008 else if (zz[0][0] == 'R')
4010 max_r_idx = atoi(zz[1]);
4014 else if (zz[0][0] == 'K')
4016 max_k_idx = atoi(zz[1]);
4020 else if (zz[0][0] == 'V')
4022 max_v_idx = atoi(zz[1]);
4026 else if (zz[0][0] == 'F')
4028 max_f_idx = atoi(zz[1]);
4032 else if (zz[0][0] == 'A')
4034 max_a_idx = atoi(zz[1]);
4038 else if (zz[0][0] == 'E')
4040 max_e_idx = atoi(zz[1]);
4044 else if (zz[0][0] == 'D')
4046 max_d_idx = atoi(zz[1]);
4050 else if (zz[0][0] == 'O')
4052 max_o_idx = atoi(zz[1]);
4056 else if (zz[0][0] == 'M')
4058 max_m_idx = atoi(zz[1]);
4061 /* Wilderness size */
4062 else if (zz[0][0] == 'W')
4064 /* Maximum wild_x_size */
4065 if (zz[0][1] == 'X')
4066 max_wild_x = atoi(zz[1]);
4067 /* Maximum wild_y_size */
4068 if (zz[0][1] == 'Y')
4069 max_wild_y = atoi(zz[1]);
4083 static cptr variant = "ZANGBAND";
4087 * Helper function for "process_dungeon_file()"
4089 static cptr process_dungeon_file_expr(char **sp, char *fp)
4105 while (isspace(*s)) s++;
4123 t = process_dungeon_file_expr(&s, &f);
4132 else if (streq(t, "IOR"))
4135 while (*s && (f != b2))
4137 t = process_dungeon_file_expr(&s, &f);
4138 if (*t && !streq(t, "0")) v = "1";
4143 else if (streq(t, "AND"))
4146 while (*s && (f != b2))
4148 t = process_dungeon_file_expr(&s, &f);
4149 if (*t && streq(t, "0")) v = "0";
4154 else if (streq(t, "NOT"))
4157 while (*s && (f != b2))
4159 t = process_dungeon_file_expr(&s, &f);
4160 if (*t && streq(t, "1")) v = "0";
4165 else if (streq(t, "EQU"))
4168 if (*s && (f != b2))
4170 t = process_dungeon_file_expr(&s, &f);
4172 while (*s && (f != b2))
4174 p = process_dungeon_file_expr(&s, &f);
4175 if (streq(t, p)) v = "1";
4180 else if (streq(t, "LEQ"))
4183 if (*s && (f != b2))
4185 t = process_dungeon_file_expr(&s, &f);
4187 while (*s && (f != b2))
4190 t = process_dungeon_file_expr(&s, &f);
4191 if (*t && atoi(p) > atoi(t)) v = "0";
4196 else if (streq(t, "GEQ"))
4199 if (*s && (f != b2))
4201 t = process_dungeon_file_expr(&s, &f);
4203 while (*s && (f != b2))
4206 t = process_dungeon_file_expr(&s, &f);
4208 /* Compare two numbers instead of string */
4209 if (*t && atoi(p) < atoi(t)) v = "0";
4216 while (*s && (f != b2))
4218 t = process_dungeon_file_expr(&s, &f);
4223 if (f != b2) v = "?x?x?";
4225 /* Extract final and Terminate */
4226 if ((f = *s) != '\0') *s++ = '\0';
4232 /* Accept all printables except spaces and brackets */
4234 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4236 if (iskanji(*s)) s++;
4240 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4243 /* Extract final and Terminate */
4244 if ((f = *s) != '\0') *s++ = '\0';
4250 if (streq(b+1, "SYS"))
4256 else if (streq(b+1, "GRAF"))
4261 else if (streq(b+1, "MONOCHROME"))
4270 else if (streq(b+1, "RACE"))
4273 v = rp_ptr->E_title;
4280 else if (streq(b+1, "CLASS"))
4283 v = cp_ptr->E_title;
4290 else if (streq(b+1, "REALM1"))
4293 v = E_realm_names[p_ptr->realm1];
4295 v = realm_names[p_ptr->realm1];
4300 else if (streq(b+1, "REALM2"))
4303 v = E_realm_names[p_ptr->realm2];
4305 v = realm_names[p_ptr->realm2];
4310 else if (streq(b+1, "PLAYER"))
4312 static char tmp_player_name[32];
4314 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4324 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4327 v = tmp_player_name;
4331 else if (streq(b+1, "TOWN"))
4333 sprintf(tmp, "%d", p_ptr->town_num);
4338 else if (streq(b+1, "LEVEL"))
4340 sprintf(tmp, "%d", p_ptr->lev);
4344 /* Current quest number */
4345 else if (streq(b+1, "QUEST_NUMBER"))
4347 sprintf(tmp, "%d", p_ptr->inside_quest);
4351 /* Number of last quest */
4352 else if (streq(b+1, "LEAVING_QUEST"))
4354 sprintf(tmp, "%d", leaving_quest);
4359 else if (prefix(b+1, "QUEST"))
4361 /* "QUEST" uses a special parameter to determine the number of the quest */
4362 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4367 else if (prefix(b+1, "RANDOM"))
4369 /* "RANDOM" uses a special parameter to determine the number of the quest */
4370 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4375 else if (streq(b+1, "VARIANT"))
4381 else if (streq(b+1, "WILDERNESS"))
4384 sprintf(tmp, "NONE");
4386 sprintf(tmp, "LITE");
4388 sprintf(tmp, "NORMAL");
4411 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4421 bool bypass = FALSE;
4423 int x = xmin, y = ymin;
4426 /* Build the filename */
4427 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4430 fp = my_fopen(buf, "r");
4433 if (!fp) return (-1);
4436 /* Process the file */
4437 while (0 == my_fgets(fp, buf, sizeof(buf)))
4443 /* Skip "empty" lines */
4444 if (!buf[0]) continue;
4446 /* Skip "blank" lines */
4447 if (isspace(buf[0])) continue;
4450 if (buf[0] == '#') continue;
4453 /* Process "?:<expr>" */
4454 if ((buf[0] == '?') && (buf[1] == ':'))
4463 /* Parse the expr */
4464 v = process_dungeon_file_expr(&s, &f);
4467 bypass = (streq(v, "0") ? TRUE : FALSE);
4473 /* Apply conditionals */
4474 if (bypass) continue;
4476 /* Process the line */
4477 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4489 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4492 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4494 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4496 msg_format("Parsing '%s'.", buf);
4503 /* Close the file */
4513 void write_r_info_txt(void)
4515 int i, j, z, fc, bc;
4518 cptr flags[32 * 10];
4523 monster_race *r_ptr;
4525 monster_blow *b_ptr;
4527 FILE *fff = fopen("output.txt", "wt");
4535 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4537 fprintf(fff, "# Version stamp (required)\n\n");
4540 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4543 fprintf(fff, "##### The Player #####\n\n");
4545 for (z = -1; z < alloc_race_size; z++)
4547 /* Output the monsters in order */
4548 i = (z >= 0) ? alloc_race_table[z].index : 0;
4550 /* Acquire the monster */
4553 /* Ignore empty monsters */
4554 if (!strlen(r_name + r_ptr->name)) continue;
4556 /* Ignore useless monsters */
4557 if (i && !r_ptr->speed) continue;
4559 /* Write a note if necessary */
4560 if (i && (!r_ptr->level != !mode))
4565 fprintf(fff, "\n##### Town monsters #####\n\n");
4567 /* Note the dungeon */
4570 fprintf(fff, "\n##### Normal monsters #####\n\n");
4573 /* Record the change */
4574 mode = r_ptr->level;
4577 /* Acquire the flags */
4578 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4579 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4580 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4581 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4582 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4583 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4584 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4585 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4586 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4587 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4589 /* Write New/Number/Name */
4590 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4593 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4595 /* Write Information */
4596 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4597 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4599 /* Write more information */
4600 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4603 for(j = 0; j < 4; j++)
4605 b_ptr = &(r_ptr->blow[j]);
4607 /* Stop when done */
4608 if (!b_ptr->method) break;
4610 /* Write the blows */
4611 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4612 r_info_blow_effect[b_ptr->effect],
4613 b_ptr->d_dice, b_ptr->d_side);
4616 /* Extract the flags */
4617 for (fc = 0, j = 0; j < 32 * 3; j++)
4619 /* Check this flag */
4620 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4623 /* Extract the extra flags */
4624 for (j = 32 * 6; j < 32 * 10; j++)
4626 /* Check this flag */
4627 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4630 /* Write the flags */
4631 for (j = 0; j < fc;)
4635 /* Start the line */
4638 for (bc = 0; (bc < 60) && (j < fc); j++)
4642 /* Format the flag */
4643 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4645 /* Add it to the buffer */
4648 /* Note the length */
4652 /* Done with this line; write it */
4653 fprintf(fff, "%s\n", buf);
4656 /* Write Spells if applicable */
4657 if (r_ptr->freq_spell)
4659 /* Write the frequency */
4660 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4662 /* Extract the spell flags */
4663 for (fc = 0, j = 96; j < 192; j++)
4665 /* Check this flag */
4666 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4669 /* Write the flags */
4670 for (j = 0; j < fc;)
4674 /* Start the line */
4677 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4681 /* Format the flag */
4682 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4686 /* Note the length */
4693 /* Done with this line; write it */
4694 fprintf(fff, "%s\n", buf);
4698 /* Acquire the description */
4699 desc = r_text + r_ptr->text;
4700 dlen = strlen(desc);
4702 /* Write Description */
4703 for (j = 0; j < dlen;)
4707 /* Start the line */
4710 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4718 /* Done with this line; write it */
4719 fprintf(fff, "%s\n", buf);
4722 /* Space between entries */