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[] =
135 static cptr f_info_flags[] =
259 static cptr r_info_flags1[] =
298 static cptr r_info_flags2[] =
337 static cptr r_info_flags3[] =
376 static cptr r_info_flags4[] =
415 static cptr r_info_flags5[] =
454 static cptr r_info_flags6[] =
471 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
494 static cptr r_info_flags7[] =
533 static cptr r_info_flags8[] =
565 "WILD_SWAMP", /* ToDo: Implement Swamp */
571 * Monster race flags - Drops
573 static cptr r_info_flags9[] =
612 * Monster race flags - Resistances
614 static cptr r_info_flagsr[] =
654 static cptr k_info_flags[] =
751 "XXX3", /* Fake flag for Smith */
752 "XXX4", /* Fake flag for Smith */
801 static cptr k_info_gen_flags[] =
840 static cptr d_info_flags1[] =
878 * Add a text to the text-storage and store offset to it.
880 * Returns FALSE when there isn't enough space available to store
883 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
885 /* Hack -- Verify space */
886 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
892 /* Advance and save the text index */
893 *offset = ++head->text_size;
896 /* Additional text */
897 else if (normal_text)
900 * If neither the end of the last line nor
901 * the beginning of current line is not a space,
902 * fill up a space as a correct separator of two words.
904 if (head->text_size > 0 &&
906 (*(head->text_ptr + head->text_size - 1) != ' ') &&
907 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
908 (buf[0] != ' ') && !iskanji(buf[0])
910 (*(head->text_ptr + head->text_size - 1) != ' ') &&
916 *(head->text_ptr + head->text_size) = ' ';
918 /* Advance the index */
923 /* Append chars to the text */
924 strcpy(head->text_ptr + head->text_size, buf);
926 /* Advance the index */
927 head->text_size += strlen(buf);
935 * Add a name to the name-storage and return an offset to it.
937 * Returns FALSE when there isn't enough space available to store
940 static bool add_name(u32b *offset, header *head, cptr buf)
942 /* Hack -- Verify space */
943 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
949 /* Advance and save the name index */
950 *offset = ++head->name_size;
953 /* Append chars to the names */
954 strcpy(head->name_ptr + head->name_size, buf);
956 /* Advance the index */
957 head->name_size += strlen(buf);
965 * Add a tag to the tag-storage and return an offset to it.
967 * Returns FALSE when there isn't enough space available to store
970 static bool add_tag(s16b *offset, header *head, cptr buf)
974 /* Search for an existing (fake) tag */
975 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
978 if (streq(&head->tag_ptr[i], buf)) break;
981 /* There was no existing tag */
982 if (i >= head->tag_size)
984 /* Hack -- Verify space */
985 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
988 /* Append chars to the tags */
989 strcpy(head->tag_ptr + head->tag_size, buf);
991 /* Point the new tag */
994 /* Advance the index */
995 head->tag_size += strlen(buf) + 1;
998 /* Return offset of the tag */
1007 * Convert a "color letter" into an "actual" color
1008 * The colors are: dwsorgbuDWvyRGBU, as shown below
1010 byte color_char_to_attr(char c)
1014 case 'd': return (TERM_DARK);
1015 case 'w': return (TERM_WHITE);
1016 case 's': return (TERM_SLATE);
1017 case 'o': return (TERM_ORANGE);
1018 case 'r': return (TERM_RED);
1019 case 'g': return (TERM_GREEN);
1020 case 'b': return (TERM_BLUE);
1021 case 'u': return (TERM_UMBER);
1023 case 'D': return (TERM_L_DARK);
1024 case 'W': return (TERM_L_WHITE);
1025 case 'v': return (TERM_VIOLET);
1026 case 'y': return (TERM_YELLOW);
1027 case 'R': return (TERM_L_RED);
1028 case 'G': return (TERM_L_GREEN);
1029 case 'B': return (TERM_L_BLUE);
1030 case 'U': return (TERM_L_UMBER);
1038 /*** Initialize from ascii template files ***/
1042 * Initialize an "*_info" array, by parsing an ascii "template" file
1044 errr init_info_txt(FILE *fp, char *buf, header *head,
1045 parse_info_txt_func parse_info_txt_line)
1049 /* Just before the first record */
1052 /* Just before the first line */
1056 /* Prepare the "fake" stuff */
1057 head->name_size = 0;
1058 head->text_size = 0;
1062 while (0 == my_fgets(fp, buf, 1024))
1064 /* Advance the line number */
1067 /* Skip comments and blank lines */
1068 if (!buf[0] || (buf[0] == '#')) continue;
1070 /* Verify correct "colon" format */
1071 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1074 /* Hack -- Process 'V' for "Version" */
1081 /* Mega Hack -- Calculate Check Sum */
1082 if (buf[0] != 'N' && buf[0] != 'D')
1085 for (i = 0; buf[i]; i++)
1087 head->v_extra += (byte)buf[i];
1088 head->v_extra ^= (1 << (i % 8));
1092 /* Parse the line */
1093 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1098 /* Complete the "name" and "text" sizes */
1099 if (head->name_size) head->name_size++;
1100 if (head->text_size) head->text_size++;
1108 * Initialize the "v_info" array, by parsing an ascii "template" file
1110 errr parse_v_info(char *buf, header *head)
1116 static vault_type *v_ptr = NULL;
1118 /* Process 'N' for "New/Number/Name" */
1121 /* Find the colon before the name */
1122 s = my_strchr(buf+2, ':');
1124 /* Verify that colon */
1127 /* Nuke the colon, advance to the name */
1130 /* Paranoia -- require a name */
1131 if (!*s) return (1);
1136 /* Verify information */
1137 if (i <= error_idx) return (4);
1139 /* Verify information */
1140 if (i >= head->info_num) return (2);
1142 /* Save the index */
1145 /* Point at the "info" */
1148 /* Store the name */
1149 if (!add_name(&v_ptr->name, head, s)) return (7);
1152 /* There better be a current v_ptr */
1153 else if (!v_ptr) return (3);
1155 /* Process 'D' for "Description" */
1156 else if (buf[0] == 'D')
1158 /* Acquire the text */
1161 /* Store the text */
1162 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1165 /* Process 'X' for "Extra info" (one line only) */
1166 else if (buf[0] == 'X')
1168 int typ, rat, hgt, wid;
1170 /* Scan for the values */
1171 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1172 &typ, &rat, &hgt, &wid)) return (1);
1174 /* Save the values */
1191 * Initialize the "s_info" array, by parsing an ascii "template" file
1193 errr parse_s_info(char *buf, header *head)
1198 static skill_table *s_ptr = NULL;
1201 /* Process 'N' for "New/Number/Name" */
1207 /* Verify information */
1208 if (i <= error_idx) return (4);
1210 /* Verify information */
1211 if (i >= head->info_num) return (2);
1213 /* Save the index */
1216 /* Point at the "info" */
1220 /* There better be a current s_ptr */
1221 else if (!s_ptr) return (3);
1223 /* Process 'W' for "Weapon exp" */
1224 else if (buf[0] == 'W')
1226 int tval, sval, start, max;
1227 const s16b exp_conv_table[] =
1229 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1230 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1233 /* Scan for the values */
1234 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1235 &tval, &sval, &start, &max)) return (1);
1237 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1238 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1240 /* Save the values */
1241 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1242 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1245 /* Process 'S' for "Skill exp" */
1246 else if (buf[0] == 'S')
1248 int num, start, max;
1250 /* Scan for the values */
1251 if (3 != sscanf(buf+2, "%d:%d:%d",
1252 &num, &start, &max)) return (1);
1254 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1255 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1257 /* Save the values */
1258 s_ptr->s_start[num] = start;
1259 s_ptr->s_max[num] = max;
1272 * Initialize the "m_info" array, by parsing an ascii "template" file
1274 errr parse_m_info(char *buf, header *head)
1281 static player_magic *m_ptr = NULL;
1284 static int realm, magic_idx = 0, readable = 0;
1287 /* Process 'N' for "New/Number/Name" */
1293 /* Verify information */
1294 if (i <= error_idx) return (4);
1296 /* Verify information */
1297 if (i >= head->info_num) return (2);
1299 /* Save the index */
1302 /* Point at the "info" */
1306 /* There better be a current m_ptr */
1307 else if (!m_ptr) return (3);
1309 /* Process 'I' for "Info" (one line only) */
1310 else if (buf[0] == 'I')
1313 int xtra, type, first, weight;
1315 /* Find the colon before the name */
1316 s = my_strchr(buf+2, ':');
1318 /* Verify that colon */
1321 /* Nuke the colon, advance to the name */
1326 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1327 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1328 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1329 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1330 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1335 /* Find the colon before the name */
1336 s = my_strchr(s, ':');
1338 /* Verify that colon */
1341 /* Nuke the colon, advance to the name */
1344 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1345 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1346 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1347 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1348 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1349 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1353 /* Scan for the values */
1354 if (4 != sscanf(s, "%x:%d:%d:%d",
1355 (uint *)&xtra, &type, &first, &weight)) return (1);
1357 m_ptr->spell_xtra = xtra;
1358 m_ptr->spell_type = type;
1359 m_ptr->spell_first = first;
1360 m_ptr->spell_weight = weight;
1364 /* Process 'R' for "Realm" (one line only) */
1365 else if (buf[0] == 'R')
1367 /* Scan for the values */
1368 if (2 != sscanf(buf+2, "%d:%d",
1369 &realm, &readable)) return (1);
1374 else if (buf[0] == 'T')
1376 int level, mana, fail, exp;
1378 if (!readable) return (1);
1379 /* Scan for the values */
1380 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1381 &level, &mana, &fail, &exp)) return (1);
1383 m_ptr->info[realm][magic_idx].slevel = level;
1384 m_ptr->info[realm][magic_idx].smana = mana;
1385 m_ptr->info[realm][magic_idx].sfail = fail;
1386 m_ptr->info[realm][magic_idx].sexp = exp;
1400 * Grab one flag from a textual string
1402 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1407 for (i = 0; i < 32; i++)
1409 if (streq(what, names[i]))
1411 *flags |= (1L << i);
1421 * Grab one flag in an feature_type from a textual string
1423 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1428 for (i = 0; i < FF_FLAG_MAX; i++)
1430 if (streq(what, f_info_flags[i]))
1432 add_flag(f_ptr->flags, i);
1439 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1441 msg_format("Unknown feature flag '%s'.", what);
1445 return PARSE_ERROR_GENERIC;
1450 * Grab an action in an feature_type from a textual string
1452 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1457 for (i = 0; i < FF_FLAG_MAX; i++)
1459 if (streq(what, f_info_flags[i]))
1461 f_ptr->state[count].action = i;
1468 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1470 msg_format("Unknown feature action '%s'.", what);
1474 return PARSE_ERROR_GENERIC;
1479 * Initialize the "f_info" array, by parsing an ascii "template" file
1481 errr parse_f_info(char *buf, header *head)
1488 static feature_type *f_ptr = NULL;
1491 /* Process 'N' for "New/Number/Name" */
1494 /* Find the colon before the name */
1495 s = my_strchr(buf+2, ':');
1499 /* Nuke the colon, advance to the name */
1506 /* Verify information */
1507 if (i <= error_idx) return (4);
1509 /* Verify information */
1510 if (i >= head->info_num) return (2);
1512 /* Save the index */
1515 /* Point at the "info" */
1518 /* Tag name is given */
1522 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1525 /* Default "mimic" */
1528 /* Default "destroyed state" -- if not specified */
1529 f_ptr->destroyed = i;
1531 /* Default "states" */
1532 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1535 /* There better be a current f_ptr */
1536 else if (!f_ptr) return (3);
1539 else if (buf[0] == 'J')
1541 /* Store the name */
1542 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1545 else if (buf[0] == 'E')
1547 /* Ignore english name */
1550 else if (buf[0] == 'J')
1552 /* Ignore Japanese name */
1555 else if (buf[0] == 'E')
1557 /* Acquire the Text */
1560 /* Store the name */
1561 if (!add_name(&f_ptr->name, head, s)) return (7);
1566 /* Process 'M' for "Mimic" (one line only) */
1567 else if (buf[0] == 'M')
1571 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1573 /* Record a fake tag index */
1574 f_ptr->mimic = -offset;
1578 /* Process 'G' for "Graphics" (one line only) */
1579 else if (buf[0] == 'G')
1583 char char_tmp[F_LIT_MAX];
1586 if (buf[1] != ':') return (1);
1587 if (!buf[2]) return (1);
1588 if (buf[3] != ':') return (1);
1589 if (!buf[4]) return (1);
1591 /* Extract the char */
1592 char_tmp[F_LIT_STANDARD] = buf[2];
1594 /* Extract the color */
1595 s_attr = color_char_to_attr(buf[4]);
1598 if (s_attr > 127) return (1);
1600 /* Save the standard values */
1601 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1602 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1604 /* Is this feature supports lighting? */
1607 /* G:c:a:LIT (default) */
1608 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1610 /* G:c:a:lc:la:dc:da */
1611 if (!streq(buf + 6, "LIT"))
1613 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1615 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1616 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1617 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1618 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1620 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1622 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1625 /* Use default lighting */
1628 /* No lighting support */
1629 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1632 /* Extract the color */
1633 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1634 if (f_ptr->d_attr[j] > 127) return 1;
1637 f_ptr->d_char[j] = char_tmp[j];
1643 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1645 f_ptr->d_attr[j] = s_attr;
1646 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1652 /* Hack -- Process 'F' for flags */
1653 else if (buf[0] == 'F')
1655 /* Parse every entry textually */
1656 for (s = buf + 2; *s; )
1658 /* Find the end of this entry */
1659 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1661 /* Nuke and skip any dividers */
1665 while (*t == ' ' || *t == '|') t++;
1668 /* XXX XXX XXX Hack -- Read feature subtype */
1669 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1671 /* Extract a "subtype" */
1674 /* Start at next entry */
1681 /* XXX XXX XXX Hack -- Read feature power */
1682 if (1 == sscanf(s, "POWER_%d", &i))
1684 /* Extract a "power" */
1687 /* Start at next entry */
1694 /* Parse this entry */
1695 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1697 /* Start the next entry */
1702 /* Process 'W' for "More Info" (one line only) */
1703 else if (buf[0] == 'W')
1707 /* Scan for the value */
1708 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1710 /* Save the value */
1711 f_ptr->priority = priority;
1714 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1715 else if (buf[0] == 'K')
1719 /* Find the next empty state slot (if any) */
1720 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1722 /* Oops, no more slots */
1723 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1725 /* Analyze the first field */
1726 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1728 /* Terminate the field (if necessary) */
1729 if (*t == ':') *t++ = '\0';
1731 /* Is this default entry? */
1732 if (streq(s, "DESTROYED"))
1734 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1736 /* Record a fake tag index */
1737 f_ptr->destroyed = -offset;
1742 f_ptr->state[i].action = 0;
1744 /* Parse this entry */
1745 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1747 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1749 /* Record a fake tag index */
1750 f_ptr->state[i].result = -offset;
1763 * Convert a fake tag to a real feat index
1765 s16b f_tag_to_index(cptr str)
1769 /* Search for real index corresponding to this fake tag */
1770 for (i = 0; i < f_head.info_num; i++)
1772 if (streq(f_tag + f_info[i].tag, str))
1774 /* Return the index */
1785 * Search for real index corresponding to this fake tag
1787 static void search_real_feat(s16b *feat)
1791 /* Don't convert non-fake tag */
1792 if (*feat >= 0) return;
1794 /* Search for real index corresponding to this fake tag */
1795 for (i = 0; i < f_head.info_num; i++)
1797 if ((-(*feat)) == f_info[i].tag)
1799 /* Record real index */
1807 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1809 msg_format("%s is undefined.", f_tag + (-(*feat)));
1815 * Retouch fake tags of f_info
1817 void retouch_f_info(header *head)
1821 /* Convert fake tags to real feat indices */
1822 for (i = 0; i < head->info_num; i++)
1824 feature_type *f_ptr = &f_info[i];
1827 search_real_feat(&f_ptr->mimic);
1829 search_real_feat(&f_ptr->destroyed);
1831 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1837 * Grab one flag in an object_kind from a textual string
1839 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1844 for (i = 0; i < TR_FLAG_MAX; i++)
1846 if (streq(what, k_info_flags[i]))
1848 add_flag(k_ptr->flags, i);
1853 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1858 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1860 msg_format("Unknown object flag '%s'.", what);
1869 * Grab one activation index flag
1871 static byte grab_one_activation_flag(cptr what)
1877 if (activation_info[i].flag == NULL) break;
1879 if (streq(what, activation_info[i].flag))
1881 return activation_info[i].index;
1893 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
1895 msg_format("Unknown activation flag '%s'.", what);
1904 * Initialize the "k_info" array, by parsing an ascii "template" file
1906 errr parse_k_info(char *buf, header *head)
1913 static object_kind *k_ptr = NULL;
1916 /* Process 'N' for "New/Number/Name" */
1923 /* Find the colon before the name */
1924 s = my_strchr(buf+2, ':');
1926 /* Verify that colon */
1929 /* Nuke the colon, advance to the name */
1935 /* Verify information */
1936 if (i <= error_idx) return (4);
1938 /* Verify information */
1939 if (i >= head->info_num) return (2);
1941 /* Save the index */
1944 /* Point at the "info" */
1948 /* Paranoia -- require a name */
1949 if (!*s) return (1);
1951 /* Find the colon before the flavor */
1952 flavor = my_strchr(s, ':');
1954 /* Verify that colon */
1957 /* Nuke the colon, advance to the flavor */
1960 /* Store the flavor */
1961 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1964 /* Store the name */
1965 if (!add_name(&k_ptr->name, head, s)) return (7);
1969 /* There better be a current k_ptr */
1970 else if (!k_ptr) return (3);
1974 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1975 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1976 else if (buf[0] == 'E')
1981 else if (buf[0] == 'E')
1985 /* Acquire the name */
1988 /* Find the colon before the flavor */
1989 flavor = my_strchr(s, ':');
1991 /* Verify that colon */
1994 /* Nuke the colon, advance to the flavor */
1997 /* Store the flavor */
1998 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2001 /* Store the name */
2002 if (!add_name(&k_ptr->name, head, s)) return (7);
2006 /* Process 'D' for "Description" */
2007 else if (buf[0] == 'D')
2012 /* Acquire the text */
2017 /* Acquire the text */
2021 /* Store the text */
2022 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2025 /* Process 'G' for "Graphics" (one line only) */
2026 else if (buf[0] == 'G')
2032 if (buf[1] != ':') return (1);
2033 if (!buf[2]) return (1);
2034 if (buf[3] != ':') return (1);
2035 if (!buf[4]) return (1);
2037 /* Extract the char */
2040 /* Extract the attr */
2041 tmp = color_char_to_attr(buf[4]);
2044 if (tmp > 127) return (1);
2046 /* Save the values */
2047 k_ptr->d_attr = tmp;
2048 k_ptr->d_char = sym;
2051 /* Process 'I' for "Info" (one line only) */
2052 else if (buf[0] == 'I')
2054 int tval, sval, pval;
2056 /* Scan for the values */
2057 if (3 != sscanf(buf+2, "%d:%d:%d",
2058 &tval, &sval, &pval)) return (1);
2060 /* Save the values */
2066 /* Process 'W' for "More Info" (one line only) */
2067 else if (buf[0] == 'W')
2069 int level, extra, wgt;
2072 /* Scan for the values */
2073 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2074 &level, &extra, &wgt, &cost)) return (1);
2076 /* Save the values */
2077 k_ptr->level = level;
2078 k_ptr->extra = extra;
2079 k_ptr->weight = wgt;
2083 /* Process 'A' for "Allocation" (one line only) */
2084 else if (buf[0] == 'A')
2088 /* XXX XXX XXX Simply read each number following a colon */
2089 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2091 /* Default chance */
2092 k_ptr->chance[i] = 1;
2094 /* Store the attack damage index */
2095 k_ptr->locale[i] = atoi(s+1);
2097 /* Find the slash */
2098 t = my_strchr(s+1, '/');
2100 /* Find the next colon */
2101 s = my_strchr(s+1, ':');
2103 /* If the slash is "nearby", use it */
2104 if (t && (!s || t < s))
2106 int chance = atoi(t+1);
2107 if (chance > 0) k_ptr->chance[i] = chance;
2112 /* Hack -- Process 'P' for "power" and such */
2113 else if (buf[0] == 'P')
2115 int ac, hd1, hd2, th, td, ta;
2117 /* Scan for the values */
2118 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2119 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2129 /* Hack -- Process 'U' for activation index */
2130 else if (buf[0] == 'U')
2133 n = grab_one_activation_flag(buf + 2);
2144 /* Hack -- Process 'F' for flags */
2145 else if (buf[0] == 'F')
2147 /* Parse every entry textually */
2148 for (s = buf + 2; *s; )
2150 /* Find the end of this entry */
2151 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2153 /* Nuke and skip any dividers */
2157 while (*t == ' ' || *t == '|') t++;
2160 /* Parse this entry */
2161 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2163 /* Start the next entry */
2179 * Grab one flag in an artifact_type from a textual string
2181 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2186 for (i = 0; i < TR_FLAG_MAX; i++)
2188 if (streq(what, k_info_flags[i]))
2190 add_flag(a_ptr->flags, i);
2195 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2200 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2202 msg_format("Unknown artifact flag '%s'.", what);
2212 * Initialize the "a_info" array, by parsing an ascii "template" file
2214 errr parse_a_info(char *buf, header *head)
2221 static artifact_type *a_ptr = NULL;
2224 /* Process 'N' for "New/Number/Name" */
2227 /* Find the colon before the name */
2228 s = my_strchr(buf+2, ':');
2230 /* Verify that colon */
2233 /* Nuke the colon, advance to the name */
2236 /* Paranoia -- require a name */
2237 if (!*s) return (1);
2242 /* Verify information */
2243 if (i < error_idx) return (4);
2245 /* Verify information */
2246 if (i >= head->info_num) return (2);
2248 /* Save the index */
2251 /* Point at the "info" */
2254 /* Ignore everything */
2255 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2256 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2257 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2258 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2260 /* Store the name */
2261 if (!add_name(&a_ptr->name, head, s)) return (7);
2265 /* There better be a current a_ptr */
2266 else if (!a_ptr) return (3);
2270 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2271 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2272 else if (buf[0] == 'E')
2277 else if (buf[0] == 'E')
2279 /* Acquire the Text */
2282 /* Store the name */
2283 if (!add_name(&a_ptr->name, head, s)) return (7);
2287 /* Process 'D' for "Description" */
2288 else if (buf[0] == 'D')
2293 /* Acquire the text */
2298 /* Acquire the text */
2302 /* Store the text */
2303 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2307 /* Process 'I' for "Info" (one line only) */
2308 else if (buf[0] == 'I')
2310 int tval, sval, pval;
2312 /* Scan for the values */
2313 if (3 != sscanf(buf+2, "%d:%d:%d",
2314 &tval, &sval, &pval)) return (1);
2316 /* Save the values */
2322 /* Process 'W' for "More Info" (one line only) */
2323 else if (buf[0] == 'W')
2325 int level, rarity, wgt;
2328 /* Scan for the values */
2329 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2330 &level, &rarity, &wgt, &cost)) return (1);
2332 /* Save the values */
2333 a_ptr->level = level;
2334 a_ptr->rarity = rarity;
2335 a_ptr->weight = wgt;
2339 /* Hack -- Process 'P' for "power" and such */
2340 else if (buf[0] == 'P')
2342 int ac, hd1, hd2, th, td, ta;
2344 /* Scan for the values */
2345 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2346 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2356 /* Hack -- Process 'U' for activation index */
2357 else if (buf[0] == 'U')
2360 n = grab_one_activation_flag(buf + 2);
2371 /* Hack -- Process 'F' for flags */
2372 else if (buf[0] == 'F')
2374 /* Parse every entry textually */
2375 for (s = buf + 2; *s; )
2377 /* Find the end of this entry */
2378 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2380 /* Nuke and skip any dividers */
2384 while ((*t == ' ') || (*t == '|')) t++;
2387 /* Parse this entry */
2388 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2390 /* Start the next entry */
2406 * Grab one flag in a ego-item_type from a textual string
2408 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2413 for (i = 0; i < TR_FLAG_MAX; i++)
2415 if (streq(what, k_info_flags[i]))
2417 add_flag(e_ptr->flags, i);
2422 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2427 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2429 msg_format("Unknown ego-item flag '%s'.", what);
2441 * Initialize the "e_info" array, by parsing an ascii "template" file
2443 errr parse_e_info(char *buf, header *head)
2450 static ego_item_type *e_ptr = NULL;
2453 /* Just before the first record */
2456 /* Just before the first line */
2460 /* Process 'N' for "New/Number/Name" */
2463 /* Find the colon before the name */
2464 s = my_strchr(buf+2, ':');
2466 /* Verify that colon */
2469 /* Nuke the colon, advance to the name */
2472 /* Paranoia -- require a name */
2473 if (!*s) return (1);
2478 /* Verify information */
2479 if (i < error_idx) return (4);
2481 /* Verify information */
2482 if (i >= head->info_num) return (2);
2484 /* Save the index */
2487 /* Point at the "info" */
2490 /* Store the name */
2491 if (!add_name(&e_ptr->name, head, s)) return (7);
2495 /* There better be a current e_ptr */
2496 else if (!e_ptr) return (3);
2500 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2501 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2502 else if (buf[0] == 'E')
2507 else if (buf[0] == 'E')
2509 /* Acquire the Text */
2512 /* Store the name */
2513 if (!add_name(&e_ptr->name, head, s)) return (7);
2518 /* Process 'D' for "Description" */
2519 else if (buf[0] == 'D')
2521 /* Acquire the text */
2524 /* Store the text */
2525 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2530 /* Process 'X' for "Xtra" (one line only) */
2531 else if (buf[0] == 'X')
2535 /* Scan for the values */
2536 if (2 != sscanf(buf+2, "%d:%d",
2537 &slot, &rating)) return (1);
2539 /* Save the values */
2541 e_ptr->rating = rating;
2544 /* Process 'W' for "More Info" (one line only) */
2545 else if (buf[0] == 'W')
2547 int level, rarity, pad2;
2550 /* Scan for the values */
2551 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2552 &level, &rarity, &pad2, &cost)) return (1);
2554 /* Save the values */
2555 e_ptr->level = level;
2556 e_ptr->rarity = rarity;
2557 /* e_ptr->weight = wgt; */
2561 /* Hack -- Process 'C' for "creation" */
2562 else if (buf[0] == 'C')
2566 /* Scan for the values */
2567 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2568 &th, &td, &ta, &pv)) return (1);
2570 e_ptr->max_to_h = th;
2571 e_ptr->max_to_d = td;
2572 e_ptr->max_to_a = ta;
2573 e_ptr->max_pval = pv;
2576 /* Hack -- Process 'U' for activation index */
2577 else if (buf[0] == 'U')
2580 n = grab_one_activation_flag(buf + 2);
2591 /* Hack -- Process 'F' for flags */
2592 else if (buf[0] == 'F')
2594 /* Parse every entry textually */
2595 for (s = buf + 2; *s; )
2597 /* Find the end of this entry */
2598 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2600 /* Nuke and skip any dividers */
2604 while ((*t == ' ') || (*t == '|')) t++;
2607 /* Parse this entry */
2608 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2610 /* Start the next entry */
2624 * Grab one (basic) flag in a monster_race from a textual string
2626 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2628 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2631 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2634 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2637 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2640 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2643 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2646 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2651 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2653 msg_format("Unknown monster flag '%s'.", what);
2663 * Grab one (spell) flag in a monster_race from a textual string
2665 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2667 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2670 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2673 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2678 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2680 msg_format("Unknown monster flag '%s'.", what);
2692 * Initialize the "r_info" array, by parsing an ascii "template" file
2694 errr parse_r_info(char *buf, header *head)
2701 static monster_race *r_ptr = NULL;
2704 /* Process 'N' for "New/Number/Name" */
2707 /* Find the colon before the name */
2708 s = my_strchr(buf+2, ':');
2710 /* Verify that colon */
2713 /* Nuke the colon, advance to the name */
2716 /* Paranoia -- require a name */
2717 if (!*s) return (1);
2722 /* Verify information */
2723 if (i < error_idx) return (4);
2725 /* Verify information */
2726 if (i >= head->info_num) return (2);
2728 /* Save the index */
2731 /* Point at the "info" */
2734 /* Store the name */
2735 if (!add_name(&r_ptr->name, head, s)) return (7);
2739 /* There better be a current r_ptr */
2740 else if (!r_ptr) return (3);
2744 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2745 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2746 else if (buf[0] == 'E')
2748 /* Acquire the Text */
2751 /* Store the name */
2752 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2755 else if (buf[0] == 'E')
2757 /* Acquire the Text */
2760 /* Store the name */
2761 if (!add_name(&r_ptr->name, head, s)) return (7);
2764 /* Process 'D' for "Description" */
2765 else if (buf[0] == 'D')
2770 /* Acquire the text */
2775 /* Acquire the text */
2779 /* Store the text */
2780 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2783 /* Process 'G' for "Graphics" (one line only) */
2784 else if (buf[0] == 'G')
2790 if (buf[1] != ':') return (1);
2791 if (!buf[2]) return (1);
2792 if (buf[3] != ':') return (1);
2793 if (!buf[4]) return (1);
2795 /* Extract the char */
2798 /* Extract the attr */
2799 tmp = color_char_to_attr(buf[4]);
2802 if (tmp > 127) return (1);
2804 /* Save the values */
2805 r_ptr->d_char = sym;
2806 r_ptr->d_attr = tmp;
2809 /* Process 'I' for "Info" (one line only) */
2810 else if (buf[0] == 'I')
2812 int spd, hp1, hp2, aaf, ac, slp;
2814 /* Scan for the other values */
2815 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2816 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2818 /* Save the values */
2820 r_ptr->hdice = MAX(hp1, 1);
2821 r_ptr->hside = MAX(hp2, 1);
2827 /* Process 'W' for "More Info" (one line only) */
2828 else if (buf[0] == 'W')
2835 /* Scan for the values */
2836 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2837 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2839 /* Save the values */
2841 r_ptr->rarity = rar;
2844 r_ptr->next_exp = nextexp;
2845 r_ptr->next_r_idx = nextmon;
2848 /* Process 'R' for "Reinforcement" (up to six lines) */
2849 else if (buf[0] == 'R')
2852 /* Find the next empty blow slot (if any) */
2853 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
2855 /* Oops, no more slots */
2856 if (i == 6) return (1);
2858 /* Scan for the values */
2859 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2860 r_ptr->reinforce_id[i] = id;
2861 r_ptr->reinforce_dd[i] = dd;
2862 r_ptr->reinforce_ds[i] = ds;
2865 /* Process 'B' for "Blows" (up to four lines) */
2866 else if (buf[0] == 'B')
2870 /* Find the next empty blow slot (if any) */
2871 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2873 /* Oops, no more slots */
2874 if (i == 4) return (1);
2876 /* Analyze the first field */
2877 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2879 /* Terminate the field (if necessary) */
2880 if (*t == ':') *t++ = '\0';
2882 /* Analyze the method */
2883 for (n1 = 0; r_info_blow_method[n1]; n1++)
2885 if (streq(s, r_info_blow_method[n1])) break;
2888 /* Invalid method */
2889 if (!r_info_blow_method[n1]) return (1);
2891 /* Analyze the second field */
2892 for (s = t; *t && (*t != ':'); t++) /* loop */;
2894 /* Terminate the field (if necessary) */
2895 if (*t == ':') *t++ = '\0';
2897 /* Analyze effect */
2898 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2900 if (streq(s, r_info_blow_effect[n2])) break;
2903 /* Invalid effect */
2904 if (!r_info_blow_effect[n2]) return (1);
2906 /* Analyze the third field */
2907 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2909 /* Terminate the field (if necessary) */
2910 if (*t == 'd') *t++ = '\0';
2912 /* Save the method */
2913 r_ptr->blow[i].method = n1;
2915 /* Save the effect */
2916 r_ptr->blow[i].effect = n2;
2918 /* Extract the damage dice and sides */
2919 r_ptr->blow[i].d_dice = atoi(s);
2920 r_ptr->blow[i].d_side = atoi(t);
2923 /* Process 'F' for "Basic Flags" (multiple lines) */
2924 else if (buf[0] == 'F')
2926 /* Parse every entry */
2927 for (s = buf + 2; *s; )
2929 /* Find the end of this entry */
2930 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2932 /* Nuke and skip any dividers */
2936 while (*t == ' ' || *t == '|') t++;
2939 /* Parse this entry */
2940 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2942 /* Start the next entry */
2947 /* Process 'S' for "Spell Flags" (multiple lines) */
2948 else if (buf[0] == 'S')
2950 /* Parse every entry */
2951 for (s = buf + 2; *s; )
2953 /* Find the end of this entry */
2954 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2956 /* Nuke and skip any dividers */
2960 while ((*t == ' ') || (*t == '|')) t++;
2963 /* XXX XXX XXX Hack -- Read spell frequency */
2964 if (1 == sscanf(s, "1_IN_%d", &i))
2966 /* Extract a "frequency" */
2967 r_ptr->freq_spell = 100 / i;
2969 /* Start at next entry */
2976 /* Parse this entry */
2977 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2979 /* Start the next entry */
2994 * Grab one flag for a dungeon type from a textual string
2996 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2998 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3003 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3005 msg_format("Unknown dungeon type flag '%s'.", what);
3013 * Grab one (basic) flag in a monster_race from a textual string
3015 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3017 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3020 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3023 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3026 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3029 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3032 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3035 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3040 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3042 msg_format("Unknown monster flag '%s'.", what);
3050 * Grab one (spell) flag in a monster_race from a textual string
3052 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3054 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3057 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3060 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3065 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3067 msg_format("Unknown monster flag '%s'.", what);
3075 * Initialize the "d_info" array, by parsing an ascii "template" file
3077 errr parse_d_info(char *buf, header *head)
3084 static dungeon_info_type *d_ptr = NULL;
3087 /* Process 'N' for "New/Number/Name" */
3090 /* Find the colon before the name */
3091 s = my_strchr(buf+2, ':');
3093 /* Verify that colon */
3096 /* Nuke the colon, advance to the name */
3099 /* Paranoia -- require a name */
3100 if (!*s) return (1);
3105 /* Verify information */
3106 if (i < error_idx) return (4);
3108 /* Verify information */
3109 if (i >= head->info_num) return (2);
3111 /* Save the index */
3114 /* Point at the "info" */
3117 /* Store the name */
3118 if (!add_name(&d_ptr->name, head, s)) return (7);
3123 else if (buf[0] == 'E') return (0);
3125 else if (buf[0] == 'E')
3127 /* Acquire the Text */
3130 /* Store the name */
3131 if (!add_name(&d_ptr->name, head, s)) return (7);
3135 /* Process 'D' for "Description */
3136 else if (buf[0] == 'D')
3141 /* Acquire the text */
3146 /* Acquire the text */
3150 /* Store the text */
3151 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3154 /* Process 'W' for "More Info" (one line only) */
3155 else if (buf[0] == 'W')
3157 int min_lev, max_lev;
3159 int min_alloc, max_chance;
3160 int obj_good, obj_great;
3163 /* Scan for the values */
3164 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3165 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3167 /* Save the values */
3168 d_ptr->mindepth = min_lev;
3169 d_ptr->maxdepth = max_lev;
3170 d_ptr->min_plev = min_plev;
3172 d_ptr->min_m_alloc_level = min_alloc;
3173 d_ptr->max_m_alloc_chance = max_chance;
3174 d_ptr->obj_good = obj_good;
3175 d_ptr->obj_great = obj_great;
3180 /* Process 'P' for "Place Info" */
3181 else if (buf[0] == 'P')
3185 /* Scan for the values */
3186 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3188 /* Save the values */
3193 /* Process 'L' for "fLoor type" (one line only) */
3194 else if (buf[0] == 'L')
3198 /* Scan for the values */
3199 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3201 /* Save the values */
3202 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3204 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3205 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3207 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3209 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3212 /* Process 'A' for "wAll type" (one line only) */
3213 else if (buf[0] == 'A')
3217 /* Scan for the values */
3218 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3220 /* Save the values */
3221 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3223 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3224 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3226 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3229 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3230 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3232 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3233 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3235 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3236 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3238 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3239 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3242 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3243 else if (buf[0] == 'F')
3245 int artif = 0, monst = 0;
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 Final Artifact */
3261 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3263 /* Extract a "Final Artifact" */
3264 d_ptr->final_artifact = artif;
3266 /* Start at next entry */
3273 /* XXX XXX XXX Hack -- Read Final Object */
3274 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3276 /* Extract a "Final Artifact" */
3277 d_ptr->final_object = artif;
3279 /* Start at next entry */
3286 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3287 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3289 /* Extract a "Artifact Guardian" */
3290 d_ptr->final_guardian = monst;
3292 /* Start at next entry */
3299 /* XXX XXX XXX Hack -- Read Special Percentage */
3300 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3302 /* Extract a "Special %" */
3303 d_ptr->special_div = monst;
3305 /* Start at next entry */
3312 /* Parse this entry */
3313 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3315 /* Start the next entry */
3320 /* Process 'M' for "Basic Flags" (multiple lines) */
3321 else if (buf[0] == 'M')
3323 /* Parse every entry */
3324 for (s = buf + 2; *s; )
3326 /* Find the end of this entry */
3327 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3329 /* Nuke and skip any dividers */
3333 while (*t == ' ' || *t == '|') t++;
3336 /* Hack -- Read monster symbols */
3337 if (!strncmp(s, "R_CHAR_", 7))
3339 /* Skip "R_CHAR_" */
3343 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3345 /* Start at next entry */
3352 /* Parse this entry */
3353 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3355 /* Start the next entry */
3360 /* Process 'S' for "Spell Flags" (multiple lines) */
3361 else if (buf[0] == 'S')
3363 /* Parse every entry */
3364 for (s = buf + 2; *s; )
3366 /* Find the end of this entry */
3367 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3369 /* Nuke and skip any dividers */
3373 while ((*t == ' ') || (*t == '|')) t++;
3376 /* XXX XXX XXX Hack -- Read spell frequency */
3377 if (1 == sscanf(s, "1_IN_%d", &i))
3379 /* Start at next entry */
3386 /* Parse this entry */
3387 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3389 /* Start the next entry */
3402 #else /* ALLOW_TEMPLATES */
3408 #endif /* ALLOW_TEMPLATES */
3411 /* Random dungeon grid effects */
3412 #define RANDOM_NONE 0x00000000
3413 #define RANDOM_FEATURE 0x00000001
3414 #define RANDOM_MONSTER 0x00000002
3415 #define RANDOM_OBJECT 0x00000004
3416 #define RANDOM_EGO 0x00000008
3417 #define RANDOM_ARTIFACT 0x00000010
3418 #define RANDOM_TRAP 0x00000020
3421 typedef struct dungeon_grid dungeon_grid;
3425 int feature; /* Terrain feature */
3426 int monster; /* Monster */
3427 int object; /* Object */
3428 int ego; /* Ego-Item */
3429 int artifact; /* Artifact */
3430 int trap; /* Trap */
3431 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3432 int special; /* Reserved for special terrain info */
3433 int random; /* Number of the random effect */
3437 static dungeon_grid letter[255];
3441 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3443 static errr parse_line_feature(char *buf)
3449 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3451 /* Tokenize the line */
3452 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3454 /* Letter to assign */
3455 int index = zz[0][0];
3457 /* Reset the info for the letter */
3458 letter[index].feature = feat_none;
3459 letter[index].monster = 0;
3460 letter[index].object = 0;
3461 letter[index].ego = 0;
3462 letter[index].artifact = 0;
3463 letter[index].trap = feat_none;
3464 letter[index].cave_info = 0;
3465 letter[index].special = 0;
3466 letter[index].random = RANDOM_NONE;
3472 letter[index].special = atoi(zz[8]);
3476 if ((zz[7][0] == '*') && !zz[7][1])
3478 letter[index].random |= RANDOM_TRAP;
3482 letter[index].trap = f_tag_to_index(zz[7]);
3483 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3488 if (zz[6][0] == '*')
3490 letter[index].random |= RANDOM_ARTIFACT;
3491 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3493 else if (zz[6][0] == '!')
3495 if (p_ptr->inside_quest)
3497 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3502 letter[index].artifact = atoi(zz[6]);
3507 if (zz[5][0] == '*')
3509 letter[index].random |= RANDOM_EGO;
3510 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3514 letter[index].ego = atoi(zz[5]);
3519 if (zz[4][0] == '*')
3521 letter[index].random |= RANDOM_OBJECT;
3522 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3524 else if (zz[4][0] == '!')
3526 if (p_ptr->inside_quest)
3528 int a_idx = quest[p_ptr->inside_quest].k_idx;
3531 artifact_type *a_ptr = &a_info[a_idx];
3532 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3534 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3541 letter[index].object = atoi(zz[4]);
3546 if (zz[3][0] == '*')
3548 letter[index].random |= RANDOM_MONSTER;
3549 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3551 else if (zz[3][0] == 'c')
3553 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3554 letter[index].monster = - atoi(zz[3] + 1);
3558 letter[index].monster = atoi(zz[3]);
3563 letter[index].cave_info = atoi(zz[2]);
3567 if ((zz[1][0] == '*') && !zz[1][1])
3569 letter[index].random |= RANDOM_FEATURE;
3573 letter[index].feature = f_tag_to_index(zz[1]);
3574 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3587 * Process "B:<Index>:<Command>:..." -- Building definition
3589 static errr parse_line_building(char *buf)
3605 /* Get the building number */
3608 /* Find the colon after the building number */
3609 s = my_strchr(s, ':');
3611 /* Verify that colon */
3614 /* Nuke the colon, advance to the sub-index */
3617 /* Paranoia -- require a sub-index */
3618 if (!*s) return (1);
3620 /* Building definition sub-index */
3623 /* Building name, owner, race */
3626 if (tokenize(s + 2, 3, zz, 0) == 3)
3628 /* Name of the building */
3629 strcpy(building[index].name, zz[0]);
3631 /* Name of the owner */
3632 strcpy(building[index].owner_name, zz[1]);
3634 /* Race of the owner */
3635 strcpy(building[index].owner_race, zz[2]);
3640 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3643 /* Building Action */
3646 if (tokenize(s + 2, 8, zz, 0) >= 7)
3648 /* Index of the action */
3649 int action_index = atoi(zz[0]);
3651 /* Name of the action */
3652 strcpy(building[index].act_names[action_index], zz[1]);
3654 /* Cost of the action for members */
3655 building[index].member_costs[action_index] = atoi(zz[2]);
3657 /* Cost of the action for non-members */
3658 building[index].other_costs[action_index] = atoi(zz[3]);
3660 /* Letter assigned to the action */
3661 building[index].letters[action_index] = zz[4][0];
3664 building[index].actions[action_index] = atoi(zz[5]);
3666 /* Action restriction */
3667 building[index].action_restr[action_index] = atoi(zz[6]);
3672 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3675 /* Building Classes */
3678 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3680 for (i = 0; i < MAX_CLASS; i++)
3682 building[index].member_class[i] = atoi(zz[i]);
3688 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3691 /* Building Races */
3694 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3696 for (i = 0; i < MAX_RACES; i++)
3698 building[index].member_race[i] = atoi(zz[i]);
3704 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3707 /* Building Realms */
3710 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3712 for (i = 0; i < MAX_MAGIC; i++)
3714 building[index].member_realm[i+1] = atoi(zz[i]);
3720 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3725 /* Ignore scripts */
3731 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3740 * Place the object j_ptr to a grid
3742 static void drop_here(object_type *j_ptr, int y, int x)
3744 cave_type *c_ptr = &cave[y][x];
3747 /* Get new object */
3748 s16b o_idx = o_pop();
3750 /* Access new object */
3751 o_ptr = &o_list[o_idx];
3753 /* Structure copy */
3754 object_copy(o_ptr, j_ptr);
3762 o_ptr->held_m_idx = 0;
3765 o_ptr->next_o_idx = c_ptr->o_idx;
3767 /* Place the object */
3768 c_ptr->o_idx = o_idx;
3773 * Parse a sub-file of the "extra info"
3775 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3782 /* Skip "empty" lines */
3783 if (!buf[0]) return (0);
3785 /* Skip "blank" lines */
3786 if (isspace(buf[0])) return (0);
3789 if (buf[0] == '#') return (0);
3791 /* Require "?:*" format */
3792 if (buf[1] != ':') return (1);
3795 /* Process "%:<fname>" */
3798 /* Attempt to Process the given file */
3799 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3802 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3805 return parse_line_feature(buf);
3808 /* Process "D:<dungeon>" -- info for the cave grids */
3809 else if (buf[0] == 'D')
3811 object_type object_type_body;
3813 /* Acquire the text */
3816 /* Length of the text */
3817 int len = strlen(s);
3819 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3821 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3823 /* Access the grid */
3824 cave_type *c_ptr = &cave[*y][*x];
3828 int object_index = letter[idx].object;
3829 int monster_index = letter[idx].monster;
3830 int random = letter[idx].random;
3831 int artifact_index = letter[idx].artifact;
3833 /* Lay down a floor */
3834 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3836 /* Only the features */
3837 if (init_flags & INIT_ONLY_FEATURES) continue;
3840 c_ptr->info = letter[idx].cave_info;
3842 /* Create a monster */
3843 if (random & RANDOM_MONSTER)
3845 monster_level = base_level + monster_index;
3847 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3849 monster_level = base_level;
3851 else if (monster_index)
3853 int old_cur_num, old_max_num;
3856 if (monster_index < 0)
3858 monster_index = -monster_index;
3861 old_cur_num = r_info[monster_index].cur_num;
3862 old_max_num = r_info[monster_index].max_num;
3864 /* Make alive again */
3865 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3867 r_info[monster_index].cur_num = 0;
3868 r_info[monster_index].max_num = 1;
3871 /* Make alive again */
3872 /* Hack -- Non-unique Nazguls are semi-unique */
3873 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3875 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3877 r_info[monster_index].max_num++;
3882 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3886 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3888 /* Make alive again for real unique monster */
3889 r_info[monster_index].cur_num = old_cur_num;
3890 r_info[monster_index].max_num = old_max_num;
3894 /* Object (and possible trap) */
3895 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3897 object_level = base_level + object_index;
3900 * Random trap and random treasure defined
3901 * 25% chance for trap and 75% chance for object
3903 if (randint0(100) < 75)
3905 place_object(*y, *x, 0L);
3912 object_level = base_level;
3914 else if (random & RANDOM_OBJECT)
3916 object_level = base_level + object_index;
3918 /* Create an out of deep object */
3919 if (randint0(100) < 75)
3920 place_object(*y, *x, 0L);
3921 else if (randint0(100) < 80)
3922 place_object(*y, *x, AM_GOOD);
3924 place_object(*y, *x, AM_GOOD | AM_GREAT);
3926 object_level = base_level;
3929 else if (random & RANDOM_TRAP)
3933 /* Hidden trap (or door) */
3934 else if (letter[idx].trap)
3936 c_ptr->mimic = c_ptr->feat;
3937 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3939 else if (object_index)
3941 /* Get local object */
3942 object_type *o_ptr = &object_type_body;
3944 /* Create the item */
3945 object_prep(o_ptr, object_index);
3947 if (o_ptr->tval == TV_GOLD)
3949 coin_type = object_index - OBJ_GOLD_LIST;
3954 /* Apply magic (no messages, no artifacts) */
3955 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3957 drop_here(o_ptr, *y, *x);
3963 if (a_info[artifact_index].cur_num)
3965 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3967 object_type *q_ptr = &forge;
3969 object_prep(q_ptr, k_idx);
3971 /* Drop it in the dungeon */
3972 drop_here(q_ptr, *y, *x);
3976 /* Create the artifact */
3977 if (create_named_art(artifact_index, *y, *x))
3978 a_info[artifact_index].cur_num = 1;
3982 /* Terrain special */
3983 c_ptr->special = letter[idx].special;
3991 /* Process "Q:<number>:<command>:... -- quest info */
3992 else if (buf[0] == 'Q')
3999 num = tokenize(buf + 2, 33, zz, 0);
4003 num = tokenize(buf + 3, 33, zz, 0);
4006 /* Have we enough parameters? */
4007 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4010 q_ptr = &(quest[atoi(zz[0])]);
4012 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4013 if (zz[1][0] == 'Q')
4015 if (init_flags & INIT_ASSIGN)
4017 monster_race *r_ptr;
4018 artifact_type *a_ptr;
4020 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4022 q_ptr->type = atoi(zz[2]);
4023 q_ptr->num_mon = atoi(zz[3]);
4024 q_ptr->cur_num = atoi(zz[4]);
4025 q_ptr->max_num = atoi(zz[5]);
4026 q_ptr->level = atoi(zz[6]);
4027 q_ptr->r_idx = atoi(zz[7]);
4028 q_ptr->k_idx = atoi(zz[8]);
4029 q_ptr->dungeon = atoi(zz[9]);
4032 q_ptr->flags = atoi(zz[10]);
4034 r_ptr = &r_info[q_ptr->r_idx];
4035 if (r_ptr->flags1 & RF1_UNIQUE)
4036 r_ptr->flags1 |= RF1_QUESTOR;
4038 a_ptr = &a_info[q_ptr->k_idx];
4039 a_ptr->gen_flags |= TRG_QUESTITEM;
4044 else if (zz[1][0] == 'R')
4046 if (init_flags & INIT_ASSIGN)
4051 for (idx = 2; idx < num; idx++)
4053 int a_idx = atoi(zz[idx]);
4054 if (a_idx < 1) continue;
4055 if (a_info[a_idx].cur_num > 0) continue;
4057 if (one_in_(count)) reward_idx = a_idx;
4062 /* Set quest's rewarding artifact */
4063 q_ptr->k_idx = reward_idx;
4064 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4068 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4069 q_ptr->type = QUEST_TYPE_KILL_ALL;
4076 /* Process "Q:<q_index>:N:<name>" -- quest name */
4077 else if (zz[1][0] == 'N')
4079 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4081 strcpy(q_ptr->name, zz[2]);
4087 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4088 else if (zz[1][0] == 'T')
4090 if (init_flags & INIT_SHOW_TEXT)
4092 strcpy(quest_text[quest_text_line], zz[2]);
4100 /* Process "W:<command>: ..." -- info for the wilderness */
4101 else if (buf[0] == 'W')
4103 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4106 /* Process "P:<y>:<x>" -- player position */
4107 else if (buf[0] == 'P')
4109 if (init_flags & INIT_CREATE_DUNGEON)
4111 if (tokenize(buf + 2, 2, zz, 0) == 2)
4113 int panels_x, panels_y;
4115 /* Hack - Set the dungeon size */
4116 panels_y = (*y / SCREEN_HGT);
4117 if (*y % SCREEN_HGT) panels_y++;
4118 cur_hgt = panels_y * SCREEN_HGT;
4120 panels_x = (*x / SCREEN_WID);
4121 if (*x % SCREEN_WID) panels_x++;
4122 cur_wid = panels_x * SCREEN_WID;
4124 /* Assume illegal panel */
4125 panel_row_min = cur_hgt;
4126 panel_col_min = cur_wid;
4128 /* Place player in a quest level */
4129 if (p_ptr->inside_quest)
4133 /* Delete the monster (if any) */
4134 delete_monster(py, px);
4142 /* Place player in the town */
4143 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4145 p_ptr->oldpy = atoi(zz[0]);
4146 p_ptr->oldpx = atoi(zz[1]);
4154 /* Process "B:<Index>:<Command>:..." -- Building definition */
4155 else if (buf[0] == 'B')
4157 return parse_line_building(buf);
4160 /* Process "M:<type>:<maximum>" -- set maximum values */
4161 else if (buf[0] == 'M')
4163 if (tokenize(buf+2, 2, zz, 0) == 2)
4166 if (zz[0][0] == 'T')
4168 max_towns = atoi(zz[1]);
4171 /* Maximum quests */
4172 else if (zz[0][0] == 'Q')
4174 max_quests = atoi(zz[1]);
4178 else if (zz[0][0] == 'R')
4180 max_r_idx = atoi(zz[1]);
4184 else if (zz[0][0] == 'K')
4186 max_k_idx = atoi(zz[1]);
4190 else if (zz[0][0] == 'V')
4192 max_v_idx = atoi(zz[1]);
4196 else if (zz[0][0] == 'F')
4198 max_f_idx = atoi(zz[1]);
4202 else if (zz[0][0] == 'A')
4204 max_a_idx = atoi(zz[1]);
4208 else if (zz[0][0] == 'E')
4210 max_e_idx = atoi(zz[1]);
4214 else if (zz[0][0] == 'D')
4216 max_d_idx = atoi(zz[1]);
4220 else if (zz[0][0] == 'O')
4222 max_o_idx = atoi(zz[1]);
4226 else if (zz[0][0] == 'M')
4228 max_m_idx = atoi(zz[1]);
4231 /* Wilderness size */
4232 else if (zz[0][0] == 'W')
4234 /* Maximum wild_x_size */
4235 if (zz[0][1] == 'X')
4236 max_wild_x = atoi(zz[1]);
4237 /* Maximum wild_y_size */
4238 if (zz[0][1] == 'Y')
4239 max_wild_y = atoi(zz[1]);
4253 static cptr variant = "ZANGBAND";
4257 * Helper function for "process_dungeon_file()"
4259 static cptr process_dungeon_file_expr(char **sp, char *fp)
4275 while (isspace(*s)) s++;
4293 t = process_dungeon_file_expr(&s, &f);
4302 else if (streq(t, "IOR"))
4305 while (*s && (f != b2))
4307 t = process_dungeon_file_expr(&s, &f);
4308 if (*t && !streq(t, "0")) v = "1";
4313 else if (streq(t, "AND"))
4316 while (*s && (f != b2))
4318 t = process_dungeon_file_expr(&s, &f);
4319 if (*t && streq(t, "0")) v = "0";
4324 else if (streq(t, "NOT"))
4327 while (*s && (f != b2))
4329 t = process_dungeon_file_expr(&s, &f);
4330 if (*t && streq(t, "1")) v = "0";
4335 else if (streq(t, "EQU"))
4338 if (*s && (f != b2))
4340 t = process_dungeon_file_expr(&s, &f);
4342 while (*s && (f != b2))
4344 p = process_dungeon_file_expr(&s, &f);
4345 if (streq(t, p)) v = "1";
4350 else if (streq(t, "LEQ"))
4353 if (*s && (f != b2))
4355 t = process_dungeon_file_expr(&s, &f);
4357 while (*s && (f != b2))
4360 t = process_dungeon_file_expr(&s, &f);
4361 if (*t && atoi(p) > atoi(t)) v = "0";
4366 else if (streq(t, "GEQ"))
4369 if (*s && (f != b2))
4371 t = process_dungeon_file_expr(&s, &f);
4373 while (*s && (f != b2))
4376 t = process_dungeon_file_expr(&s, &f);
4378 /* Compare two numbers instead of string */
4379 if (*t && atoi(p) < atoi(t)) v = "0";
4386 while (*s && (f != b2))
4388 t = process_dungeon_file_expr(&s, &f);
4393 if (f != b2) v = "?x?x?";
4395 /* Extract final and Terminate */
4396 if ((f = *s) != '\0') *s++ = '\0';
4402 /* Accept all printables except spaces and brackets */
4404 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4406 if (iskanji(*s)) s++;
4410 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4413 /* Extract final and Terminate */
4414 if ((f = *s) != '\0') *s++ = '\0';
4420 if (streq(b+1, "SYS"))
4426 else if (streq(b+1, "GRAF"))
4431 else if (streq(b+1, "MONOCHROME"))
4440 else if (streq(b+1, "RACE"))
4443 v = rp_ptr->E_title;
4450 else if (streq(b+1, "CLASS"))
4453 v = cp_ptr->E_title;
4460 else if (streq(b+1, "REALM1"))
4463 v = E_realm_names[p_ptr->realm1];
4465 v = realm_names[p_ptr->realm1];
4470 else if (streq(b+1, "REALM2"))
4473 v = E_realm_names[p_ptr->realm2];
4475 v = realm_names[p_ptr->realm2];
4480 else if (streq(b+1, "PLAYER"))
4482 static char tmp_player_name[32];
4484 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4494 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4497 v = tmp_player_name;
4501 else if (streq(b+1, "TOWN"))
4503 sprintf(tmp, "%d", p_ptr->town_num);
4508 else if (streq(b+1, "LEVEL"))
4510 sprintf(tmp, "%d", p_ptr->lev);
4514 /* Current quest number */
4515 else if (streq(b+1, "QUEST_NUMBER"))
4517 sprintf(tmp, "%d", p_ptr->inside_quest);
4521 /* Number of last quest */
4522 else if (streq(b+1, "LEAVING_QUEST"))
4524 sprintf(tmp, "%d", leaving_quest);
4529 else if (prefix(b+1, "QUEST_TYPE"))
4531 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4532 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4537 else if (prefix(b+1, "QUEST"))
4539 /* "QUEST" uses a special parameter to determine the number of the quest */
4540 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4545 else if (prefix(b+1, "RANDOM"))
4547 /* "RANDOM" uses a special parameter to determine the number of the quest */
4548 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4553 else if (streq(b+1, "VARIANT"))
4559 else if (streq(b+1, "WILDERNESS"))
4562 sprintf(tmp, "NONE");
4564 sprintf(tmp, "LITE");
4566 sprintf(tmp, "NORMAL");
4589 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4599 bool bypass = FALSE;
4601 int x = xmin, y = ymin;
4604 /* Build the filename */
4605 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4608 fp = my_fopen(buf, "r");
4611 if (!fp) return (-1);
4614 /* Process the file */
4615 while (0 == my_fgets(fp, buf, sizeof(buf)))
4621 /* Skip "empty" lines */
4622 if (!buf[0]) continue;
4624 /* Skip "blank" lines */
4625 if (isspace(buf[0])) continue;
4628 if (buf[0] == '#') continue;
4631 /* Process "?:<expr>" */
4632 if ((buf[0] == '?') && (buf[1] == ':'))
4641 /* Parse the expr */
4642 v = process_dungeon_file_expr(&s, &f);
4645 bypass = (streq(v, "0") ? TRUE : FALSE);
4651 /* Apply conditionals */
4652 if (bypass) continue;
4654 /* Process the line */
4655 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4667 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4670 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4672 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4674 msg_format("Parsing '%s'.", buf);
4681 /* Close the file */
4691 void write_r_info_txt(void)
4693 int i, j, z, fc, bc;
4696 cptr flags[32 * 10];
4701 monster_race *r_ptr;
4703 monster_blow *b_ptr;
4705 FILE *fff = fopen("output.txt", "wt");
4713 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4715 fprintf(fff, "# Version stamp (required)\n\n");
4718 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4721 fprintf(fff, "##### The Player #####\n\n");
4723 for (z = -1; z < alloc_race_size; z++)
4725 /* Output the monsters in order */
4726 i = (z >= 0) ? alloc_race_table[z].index : 0;
4728 /* Acquire the monster */
4731 /* Ignore empty monsters */
4732 if (!strlen(r_name + r_ptr->name)) continue;
4734 /* Ignore useless monsters */
4735 if (i && !r_ptr->speed) continue;
4737 /* Write a note if necessary */
4738 if (i && (!r_ptr->level != !mode))
4743 fprintf(fff, "\n##### Town monsters #####\n\n");
4745 /* Note the dungeon */
4748 fprintf(fff, "\n##### Normal monsters #####\n\n");
4751 /* Record the change */
4752 mode = r_ptr->level;
4755 /* Acquire the flags */
4756 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4757 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4758 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4759 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4760 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4761 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4762 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4763 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4764 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4765 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4767 /* Write New/Number/Name */
4768 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4771 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4773 /* Write Information */
4774 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4775 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4777 /* Write more information */
4778 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4781 for(j = 0; j < 4; j++)
4783 b_ptr = &(r_ptr->blow[j]);
4785 /* Stop when done */
4786 if (!b_ptr->method) break;
4788 /* Write the blows */
4789 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4790 r_info_blow_effect[b_ptr->effect],
4791 b_ptr->d_dice, b_ptr->d_side);
4794 /* Extract the flags */
4795 for (fc = 0, j = 0; j < 32 * 3; j++)
4797 /* Check this flag */
4798 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4801 /* Extract the extra flags */
4802 for (j = 32 * 6; j < 32 * 10; j++)
4804 /* Check this flag */
4805 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4808 /* Write the flags */
4809 for (j = 0; j < fc;)
4813 /* Start the line */
4816 for (bc = 0; (bc < 60) && (j < fc); j++)
4820 /* Format the flag */
4821 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4823 /* Add it to the buffer */
4826 /* Note the length */
4830 /* Done with this line; write it */
4831 fprintf(fff, "%s\n", buf);
4834 /* Write Spells if applicable */
4835 if (r_ptr->freq_spell)
4837 /* Write the frequency */
4838 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4840 /* Extract the spell flags */
4841 for (fc = 0, j = 96; j < 192; j++)
4843 /* Check this flag */
4844 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4847 /* Write the flags */
4848 for (j = 0; j < fc;)
4852 /* Start the line */
4855 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4859 /* Format the flag */
4860 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4864 /* Note the length */
4871 /* Done with this line; write it */
4872 fprintf(fff, "%s\n", buf);
4876 /* Acquire the description */
4877 desc = r_text + r_ptr->text;
4878 dlen = strlen(desc);
4880 /* Write Description */
4881 for (j = 0; j < dlen;)
4885 /* Start the line */
4888 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4896 /* Done with this line; write it */
4897 fprintf(fff, "%s\n", buf);
4900 /* Space between entries */