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 */
782 static cptr k_info_gen_flags[] =
821 static cptr d_info_flags1[] =
859 * Add a text to the text-storage and store offset to it.
861 * Returns FALSE when there isn't enough space available to store
864 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
866 /* Hack -- Verify space */
867 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
873 /* Advance and save the text index */
874 *offset = ++head->text_size;
877 /* Additional text */
878 else if (normal_text)
881 * If neither the end of the last line nor
882 * the beginning of current line is not a space,
883 * fill up a space as a correct separator of two words.
885 if (head->text_size > 0 &&
887 (*(head->text_ptr + head->text_size - 1) != ' ') &&
888 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
889 (buf[0] != ' ') && !iskanji(buf[0])
891 (*(head->text_ptr + head->text_size - 1) != ' ') &&
897 *(head->text_ptr + head->text_size) = ' ';
899 /* Advance the index */
904 /* Append chars to the text */
905 strcpy(head->text_ptr + head->text_size, buf);
907 /* Advance the index */
908 head->text_size += strlen(buf);
916 * Add a name to the name-storage and return an offset to it.
918 * Returns FALSE when there isn't enough space available to store
921 static bool add_name(u32b *offset, header *head, cptr buf)
923 /* Hack -- Verify space */
924 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
930 /* Advance and save the name index */
931 *offset = ++head->name_size;
934 /* Append chars to the names */
935 strcpy(head->name_ptr + head->name_size, buf);
937 /* Advance the index */
938 head->name_size += strlen(buf);
946 * Add a tag to the tag-storage and return an offset to it.
948 * Returns FALSE when there isn't enough space available to store
951 static bool add_tag(s16b *offset, header *head, cptr buf)
955 /* Search for an existing (fake) tag */
956 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
959 if (streq(&head->tag_ptr[i], buf)) break;
962 /* There was no existing tag */
963 if (i >= head->tag_size)
965 /* Hack -- Verify space */
966 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
969 /* Append chars to the tags */
970 strcpy(head->tag_ptr + head->tag_size, buf);
972 /* Point the new tag */
975 /* Advance the index */
976 head->tag_size += strlen(buf) + 1;
979 /* Return offset of the tag */
988 * Convert a "color letter" into an "actual" color
989 * The colors are: dwsorgbuDWvyRGBU, as shown below
991 byte color_char_to_attr(char c)
995 case 'd': return (TERM_DARK);
996 case 'w': return (TERM_WHITE);
997 case 's': return (TERM_SLATE);
998 case 'o': return (TERM_ORANGE);
999 case 'r': return (TERM_RED);
1000 case 'g': return (TERM_GREEN);
1001 case 'b': return (TERM_BLUE);
1002 case 'u': return (TERM_UMBER);
1004 case 'D': return (TERM_L_DARK);
1005 case 'W': return (TERM_L_WHITE);
1006 case 'v': return (TERM_VIOLET);
1007 case 'y': return (TERM_YELLOW);
1008 case 'R': return (TERM_L_RED);
1009 case 'G': return (TERM_L_GREEN);
1010 case 'B': return (TERM_L_BLUE);
1011 case 'U': return (TERM_L_UMBER);
1019 /*** Initialize from ascii template files ***/
1023 * Initialize an "*_info" array, by parsing an ascii "template" file
1025 errr init_info_txt(FILE *fp, char *buf, header *head,
1026 parse_info_txt_func parse_info_txt_line)
1030 /* Just before the first record */
1033 /* Just before the first line */
1037 /* Prepare the "fake" stuff */
1038 head->name_size = 0;
1039 head->text_size = 0;
1043 while (0 == my_fgets(fp, buf, 1024))
1045 /* Advance the line number */
1048 /* Skip comments and blank lines */
1049 if (!buf[0] || (buf[0] == '#')) continue;
1051 /* Verify correct "colon" format */
1052 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1055 /* Hack -- Process 'V' for "Version" */
1062 /* Mega Hack -- Calculate Check Sum */
1063 if (buf[0] != 'N' && buf[0] != 'D')
1066 for (i = 0; buf[i]; i++)
1068 head->v_extra += (byte)buf[i];
1069 head->v_extra ^= (1 << (i % 8));
1073 /* Parse the line */
1074 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1079 /* Complete the "name" and "text" sizes */
1080 if (head->name_size) head->name_size++;
1081 if (head->text_size) head->text_size++;
1089 * Initialize the "v_info" array, by parsing an ascii "template" file
1091 errr parse_v_info(char *buf, header *head)
1097 static vault_type *v_ptr = NULL;
1099 /* Process 'N' for "New/Number/Name" */
1102 /* Find the colon before the name */
1103 s = my_strchr(buf+2, ':');
1105 /* Verify that colon */
1108 /* Nuke the colon, advance to the name */
1111 /* Paranoia -- require a name */
1112 if (!*s) return (1);
1117 /* Verify information */
1118 if (i <= error_idx) return (4);
1120 /* Verify information */
1121 if (i >= head->info_num) return (2);
1123 /* Save the index */
1126 /* Point at the "info" */
1129 /* Store the name */
1130 if (!add_name(&v_ptr->name, head, s)) return (7);
1133 /* There better be a current v_ptr */
1134 else if (!v_ptr) return (3);
1136 /* Process 'D' for "Description" */
1137 else if (buf[0] == 'D')
1139 /* Acquire the text */
1142 /* Store the text */
1143 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1146 /* Process 'X' for "Extra info" (one line only) */
1147 else if (buf[0] == 'X')
1149 int typ, rat, hgt, wid;
1151 /* Scan for the values */
1152 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1153 &typ, &rat, &hgt, &wid)) return (1);
1155 /* Save the values */
1172 * Initialize the "s_info" array, by parsing an ascii "template" file
1174 errr parse_s_info(char *buf, header *head)
1179 static skill_table *s_ptr = NULL;
1182 /* Process 'N' for "New/Number/Name" */
1188 /* Verify information */
1189 if (i <= error_idx) return (4);
1191 /* Verify information */
1192 if (i >= head->info_num) return (2);
1194 /* Save the index */
1197 /* Point at the "info" */
1201 /* There better be a current s_ptr */
1202 else if (!s_ptr) return (3);
1204 /* Process 'W' for "Weapon exp" */
1205 else if (buf[0] == 'W')
1207 int tval, sval, start, max;
1208 const s16b exp_conv_table[] =
1210 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1211 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1214 /* Scan for the values */
1215 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1216 &tval, &sval, &start, &max)) return (1);
1218 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1219 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1221 /* Save the values */
1222 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1223 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1226 /* Process 'S' for "Skill exp" */
1227 else if (buf[0] == 'S')
1229 int num, start, max;
1231 /* Scan for the values */
1232 if (3 != sscanf(buf+2, "%d:%d:%d",
1233 &num, &start, &max)) return (1);
1235 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1236 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1238 /* Save the values */
1239 s_ptr->s_start[num] = start;
1240 s_ptr->s_max[num] = max;
1253 * Initialize the "m_info" array, by parsing an ascii "template" file
1255 errr parse_m_info(char *buf, header *head)
1262 static player_magic *m_ptr = NULL;
1265 static int realm, magic_idx = 0, readable = 0;
1268 /* Process 'N' for "New/Number/Name" */
1274 /* Verify information */
1275 if (i <= error_idx) return (4);
1277 /* Verify information */
1278 if (i >= head->info_num) return (2);
1280 /* Save the index */
1283 /* Point at the "info" */
1287 /* There better be a current m_ptr */
1288 else if (!m_ptr) return (3);
1290 /* Process 'I' for "Info" (one line only) */
1291 else if (buf[0] == 'I')
1294 int xtra, type, first, weight;
1296 /* Find the colon before the name */
1297 s = my_strchr(buf+2, ':');
1299 /* Verify that colon */
1302 /* Nuke the colon, advance to the name */
1307 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1308 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1309 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1310 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1311 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1316 /* Find the colon before the name */
1317 s = my_strchr(s, ':');
1319 /* Verify that colon */
1322 /* Nuke the colon, advance to the name */
1325 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1326 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1327 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1328 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1329 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1330 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1334 /* Scan for the values */
1335 if (4 != sscanf(s, "%x:%d:%d:%d",
1336 (uint *)&xtra, &type, &first, &weight)) return (1);
1338 m_ptr->spell_xtra = xtra;
1339 m_ptr->spell_type = type;
1340 m_ptr->spell_first = first;
1341 m_ptr->spell_weight = weight;
1345 /* Process 'R' for "Realm" (one line only) */
1346 else if (buf[0] == 'R')
1348 /* Scan for the values */
1349 if (2 != sscanf(buf+2, "%d:%d",
1350 &realm, &readable)) return (1);
1355 else if (buf[0] == 'T')
1357 int level, mana, fail, exp;
1359 if (!readable) return (1);
1360 /* Scan for the values */
1361 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1362 &level, &mana, &fail, &exp)) return (1);
1364 m_ptr->info[realm][magic_idx].slevel = level;
1365 m_ptr->info[realm][magic_idx].smana = mana;
1366 m_ptr->info[realm][magic_idx].sfail = fail;
1367 m_ptr->info[realm][magic_idx].sexp = exp;
1381 * Grab one flag from a textual string
1383 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1388 for (i = 0; i < 32; i++)
1390 if (streq(what, names[i]))
1392 *flags |= (1L << i);
1402 * Grab one flag in an feature_type from a textual string
1404 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1409 for (i = 0; i < FF_FLAG_MAX; i++)
1411 if (streq(what, f_info_flags[i]))
1413 add_flag(f_ptr->flags, i);
1420 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1422 msg_format("Unknown feature flag '%s'.", what);
1426 return PARSE_ERROR_GENERIC;
1431 * Grab an action in an feature_type from a textual string
1433 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1438 for (i = 0; i < FF_FLAG_MAX; i++)
1440 if (streq(what, f_info_flags[i]))
1442 f_ptr->state[count].action = i;
1449 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1451 msg_format("Unknown feature action '%s'.", what);
1455 return PARSE_ERROR_GENERIC;
1460 * Initialize the "f_info" array, by parsing an ascii "template" file
1462 errr parse_f_info(char *buf, header *head)
1469 static feature_type *f_ptr = NULL;
1472 /* Process 'N' for "New/Number/Name" */
1475 /* Find the colon before the name */
1476 s = my_strchr(buf+2, ':');
1480 /* Nuke the colon, advance to the name */
1487 /* Verify information */
1488 if (i <= error_idx) return (4);
1490 /* Verify information */
1491 if (i >= head->info_num) return (2);
1493 /* Save the index */
1496 /* Point at the "info" */
1499 /* Tag name is given */
1503 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1506 /* Default "mimic" */
1509 /* Default "destroyed state" -- if not specified */
1510 f_ptr->destroyed = i;
1512 /* Default "states" */
1513 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1516 /* There better be a current f_ptr */
1517 else if (!f_ptr) return (3);
1520 else if (buf[0] == 'J')
1522 /* Store the name */
1523 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1526 else if (buf[0] == 'E')
1528 /* Ignore english name */
1531 else if (buf[0] == 'J')
1533 /* Ignore Japanese name */
1536 else if (buf[0] == 'E')
1538 /* Acquire the Text */
1541 /* Store the name */
1542 if (!add_name(&f_ptr->name, head, s)) return (7);
1547 /* Process 'M' for "Mimic" (one line only) */
1548 else if (buf[0] == 'M')
1552 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1554 /* Record a fake tag index */
1555 f_ptr->mimic = -offset;
1559 /* Process 'G' for "Graphics" (one line only) */
1560 else if (buf[0] == 'G')
1564 char char_tmp[F_LIT_MAX];
1567 if (buf[1] != ':') return (1);
1568 if (!buf[2]) return (1);
1569 if (buf[3] != ':') return (1);
1570 if (!buf[4]) return (1);
1572 /* Extract the char */
1573 char_tmp[F_LIT_STANDARD] = buf[2];
1575 /* Extract the color */
1576 s_attr = color_char_to_attr(buf[4]);
1579 if (s_attr > 127) return (1);
1581 /* Save the standard values */
1582 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1583 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1585 /* Is this feature supports lighting? */
1588 /* G:c:a:LIT (default) */
1589 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1591 /* G:c:a:lc:la:dc:da */
1592 if (!streq(buf + 6, "LIT"))
1594 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1596 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1597 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1598 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1599 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1601 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1603 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1606 /* Use default lighting */
1609 /* No lighting support */
1610 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1613 /* Extract the color */
1614 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1615 if (f_ptr->d_attr[j] > 127) return 1;
1618 f_ptr->d_char[j] = char_tmp[j];
1624 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1626 f_ptr->d_attr[j] = s_attr;
1627 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1633 /* Hack -- Process 'F' for flags */
1634 else if (buf[0] == 'F')
1636 /* Parse every entry textually */
1637 for (s = buf + 2; *s; )
1639 /* Find the end of this entry */
1640 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1642 /* Nuke and skip any dividers */
1646 while (*t == ' ' || *t == '|') t++;
1649 /* XXX XXX XXX Hack -- Read feature subtype */
1650 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1652 /* Extract a "subtype" */
1655 /* Start at next entry */
1662 /* XXX XXX XXX Hack -- Read feature power */
1663 if (1 == sscanf(s, "POWER_%d", &i))
1665 /* Extract a "power" */
1668 /* Start at next entry */
1675 /* Parse this entry */
1676 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1678 /* Start the next entry */
1683 /* Process 'W' for "More Info" (one line only) */
1684 else if (buf[0] == 'W')
1688 /* Scan for the value */
1689 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1691 /* Save the value */
1692 f_ptr->priority = priority;
1695 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1696 else if (buf[0] == 'K')
1700 /* Find the next empty state slot (if any) */
1701 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1703 /* Oops, no more slots */
1704 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1706 /* Analyze the first field */
1707 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1709 /* Terminate the field (if necessary) */
1710 if (*t == ':') *t++ = '\0';
1712 /* Is this default entry? */
1713 if (streq(s, "DESTROYED"))
1715 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1717 /* Record a fake tag index */
1718 f_ptr->destroyed = -offset;
1723 f_ptr->state[i].action = 0;
1725 /* Parse this entry */
1726 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1728 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1730 /* Record a fake tag index */
1731 f_ptr->state[i].result = -offset;
1744 * Convert a fake tag to a real feat index
1746 s16b f_tag_to_index(cptr str)
1750 /* Search for real index corresponding to this fake tag */
1751 for (i = 0; i < f_head.info_num; i++)
1753 if (streq(f_tag + f_info[i].tag, str))
1755 /* Return the index */
1766 * Search for real index corresponding to this fake tag
1768 static void search_real_feat(s16b *feat)
1772 /* Don't convert non-fake tag */
1773 if (*feat >= 0) return;
1775 /* Search for real index corresponding to this fake tag */
1776 for (i = 0; i < f_head.info_num; i++)
1778 if ((-(*feat)) == f_info[i].tag)
1780 /* Record real index */
1788 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1790 msg_format("%s is undefined.", f_tag + (-(*feat)));
1796 * Retouch fake tags of f_info
1798 void retouch_f_info(header *head)
1802 /* Convert fake tags to real feat indices */
1803 for (i = 0; i < head->info_num; i++)
1805 feature_type *f_ptr = &f_info[i];
1808 search_real_feat(&f_ptr->mimic);
1810 search_real_feat(&f_ptr->destroyed);
1812 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1818 * Grab one flag in an object_kind from a textual string
1820 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1825 for (i = 0; i < TR_FLAG_MAX; i++)
1827 if (streq(what, k_info_flags[i]))
1829 add_flag(k_ptr->flags, i);
1834 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1839 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1841 msg_format("Unknown object flag '%s'.", what);
1851 * Initialize the "k_info" array, by parsing an ascii "template" file
1853 errr parse_k_info(char *buf, header *head)
1860 static object_kind *k_ptr = NULL;
1863 /* Process 'N' for "New/Number/Name" */
1870 /* Find the colon before the name */
1871 s = my_strchr(buf+2, ':');
1873 /* Verify that colon */
1876 /* Nuke the colon, advance to the name */
1882 /* Verify information */
1883 if (i <= error_idx) return (4);
1885 /* Verify information */
1886 if (i >= head->info_num) return (2);
1888 /* Save the index */
1891 /* Point at the "info" */
1895 /* Paranoia -- require a name */
1896 if (!*s) return (1);
1898 /* Find the colon before the flavor */
1899 flavor = my_strchr(s, ':');
1901 /* Verify that colon */
1904 /* Nuke the colon, advance to the flavor */
1907 /* Store the flavor */
1908 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1911 /* Store the name */
1912 if (!add_name(&k_ptr->name, head, s)) return (7);
1916 /* There better be a current k_ptr */
1917 else if (!k_ptr) return (3);
1921 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1922 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1923 else if (buf[0] == 'E')
1928 else if (buf[0] == 'E')
1932 /* Acquire the name */
1935 /* Find the colon before the flavor */
1936 flavor = my_strchr(s, ':');
1938 /* Verify that colon */
1941 /* Nuke the colon, advance to the flavor */
1944 /* Store the flavor */
1945 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1948 /* Store the name */
1949 if (!add_name(&k_ptr->name, head, s)) return (7);
1953 /* Process 'D' for "Description" */
1954 else if (buf[0] == 'D')
1959 /* Acquire the text */
1964 /* Acquire the text */
1968 /* Store the text */
1969 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
1972 /* Process 'G' for "Graphics" (one line only) */
1973 else if (buf[0] == 'G')
1979 if (buf[1] != ':') return (1);
1980 if (!buf[2]) return (1);
1981 if (buf[3] != ':') return (1);
1982 if (!buf[4]) return (1);
1984 /* Extract the char */
1987 /* Extract the attr */
1988 tmp = color_char_to_attr(buf[4]);
1991 if (tmp > 127) return (1);
1993 /* Save the values */
1994 k_ptr->d_attr = tmp;
1995 k_ptr->d_char = sym;
1998 /* Process 'I' for "Info" (one line only) */
1999 else if (buf[0] == 'I')
2001 int tval, sval, pval;
2003 /* Scan for the values */
2004 if (3 != sscanf(buf+2, "%d:%d:%d",
2005 &tval, &sval, &pval)) return (1);
2007 /* Save the values */
2013 /* Process 'W' for "More Info" (one line only) */
2014 else if (buf[0] == 'W')
2016 int level, extra, wgt;
2019 /* Scan for the values */
2020 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2021 &level, &extra, &wgt, &cost)) return (1);
2023 /* Save the values */
2024 k_ptr->level = level;
2025 k_ptr->extra = extra;
2026 k_ptr->weight = wgt;
2030 /* Process 'A' for "Allocation" (one line only) */
2031 else if (buf[0] == 'A')
2035 /* XXX XXX XXX Simply read each number following a colon */
2036 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2038 /* Default chance */
2039 k_ptr->chance[i] = 1;
2041 /* Store the attack damage index */
2042 k_ptr->locale[i] = atoi(s+1);
2044 /* Find the slash */
2045 t = my_strchr(s+1, '/');
2047 /* Find the next colon */
2048 s = my_strchr(s+1, ':');
2050 /* If the slash is "nearby", use it */
2051 if (t && (!s || t < s))
2053 int chance = atoi(t+1);
2054 if (chance > 0) k_ptr->chance[i] = chance;
2059 /* Hack -- Process 'P' for "power" and such */
2060 else if (buf[0] == 'P')
2062 int ac, hd1, hd2, th, td, ta;
2064 /* Scan for the values */
2065 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2066 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2076 /* Hack -- Process 'F' for flags */
2077 else if (buf[0] == 'F')
2079 /* Parse every entry textually */
2080 for (s = buf + 2; *s; )
2082 /* Find the end of this entry */
2083 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2085 /* Nuke and skip any dividers */
2089 while (*t == ' ' || *t == '|') t++;
2092 /* Parse this entry */
2093 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2095 /* Start the next entry */
2111 * Grab one flag in an artifact_type from a textual string
2113 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2118 for (i = 0; i < TR_FLAG_MAX; i++)
2120 if (streq(what, k_info_flags[i]))
2122 add_flag(a_ptr->flags, i);
2127 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2132 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2134 msg_format("Unknown artifact flag '%s'.", what);
2143 * Grab one activation index flag
2145 static byte grab_one_activation_flag(cptr what)
2151 if (activation_info[i].flag == NULL) break;
2153 if (streq(what, activation_info[i].flag))
2155 return activation_info[i].index;
2167 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
2169 msg_format("Unknown activation flag '%s'.", what);
2178 * Initialize the "a_info" array, by parsing an ascii "template" file
2180 errr parse_a_info(char *buf, header *head)
2187 static artifact_type *a_ptr = NULL;
2190 /* Process 'N' for "New/Number/Name" */
2193 /* Find the colon before the name */
2194 s = my_strchr(buf+2, ':');
2196 /* Verify that colon */
2199 /* Nuke the colon, advance to the name */
2202 /* Paranoia -- require a name */
2203 if (!*s) return (1);
2208 /* Verify information */
2209 if (i < error_idx) return (4);
2211 /* Verify information */
2212 if (i >= head->info_num) return (2);
2214 /* Save the index */
2217 /* Point at the "info" */
2220 /* Ignore everything */
2221 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2222 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2223 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2224 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2226 /* Store the name */
2227 if (!add_name(&a_ptr->name, head, s)) return (7);
2231 /* There better be a current a_ptr */
2232 else if (!a_ptr) return (3);
2236 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2237 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2238 else if (buf[0] == 'E')
2243 else if (buf[0] == 'E')
2245 /* Acquire the Text */
2248 /* Store the name */
2249 if (!add_name(&a_ptr->name, head, s)) return (7);
2253 /* Process 'D' for "Description" */
2254 else if (buf[0] == 'D')
2259 /* Acquire the text */
2264 /* Acquire the text */
2268 /* Store the text */
2269 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2273 /* Process 'I' for "Info" (one line only) */
2274 else if (buf[0] == 'I')
2276 int tval, sval, pval;
2278 /* Scan for the values */
2279 if (3 != sscanf(buf+2, "%d:%d:%d",
2280 &tval, &sval, &pval)) return (1);
2282 /* Save the values */
2288 /* Process 'W' for "More Info" (one line only) */
2289 else if (buf[0] == 'W')
2291 int level, rarity, wgt;
2294 /* Scan for the values */
2295 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2296 &level, &rarity, &wgt, &cost)) return (1);
2298 /* Save the values */
2299 a_ptr->level = level;
2300 a_ptr->rarity = rarity;
2301 a_ptr->weight = wgt;
2305 /* Hack -- Process 'P' for "power" and such */
2306 else if (buf[0] == 'P')
2308 int ac, hd1, hd2, th, td, ta;
2310 /* Scan for the values */
2311 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2312 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2322 /* Hack -- Process 'U' for activation index */
2323 else if (buf[0] == 'U')
2326 n = grab_one_activation_flag(buf + 2);
2337 /* Hack -- Process 'F' for flags */
2338 else if (buf[0] == 'F')
2340 /* Parse every entry textually */
2341 for (s = buf + 2; *s; )
2343 /* Find the end of this entry */
2344 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2346 /* Nuke and skip any dividers */
2350 while ((*t == ' ') || (*t == '|')) t++;
2353 /* Parse this entry */
2354 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2356 /* Start the next entry */
2372 * Grab one flag in a ego-item_type from a textual string
2374 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2379 for (i = 0; i < TR_FLAG_MAX; i++)
2381 if (streq(what, k_info_flags[i]))
2383 add_flag(e_ptr->flags, i);
2388 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2393 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2395 msg_format("Unknown ego-item flag '%s'.", what);
2407 * Initialize the "e_info" array, by parsing an ascii "template" file
2409 errr parse_e_info(char *buf, header *head)
2416 static ego_item_type *e_ptr = NULL;
2419 /* Just before the first record */
2422 /* Just before the first line */
2426 /* Process 'N' for "New/Number/Name" */
2429 /* Find the colon before the name */
2430 s = my_strchr(buf+2, ':');
2432 /* Verify that colon */
2435 /* Nuke the colon, advance to the name */
2438 /* Paranoia -- require a name */
2439 if (!*s) return (1);
2444 /* Verify information */
2445 if (i < error_idx) return (4);
2447 /* Verify information */
2448 if (i >= head->info_num) return (2);
2450 /* Save the index */
2453 /* Point at the "info" */
2456 /* Store the name */
2457 if (!add_name(&e_ptr->name, head, s)) return (7);
2461 /* There better be a current e_ptr */
2462 else if (!e_ptr) return (3);
2466 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2467 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2468 else if (buf[0] == 'E')
2473 else if (buf[0] == 'E')
2475 /* Acquire the Text */
2478 /* Store the name */
2479 if (!add_name(&e_ptr->name, head, s)) return (7);
2484 /* Process 'D' for "Description" */
2485 else if (buf[0] == 'D')
2487 /* Acquire the text */
2490 /* Store the text */
2491 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2496 /* Process 'X' for "Xtra" (one line only) */
2497 else if (buf[0] == 'X')
2501 /* Scan for the values */
2502 if (2 != sscanf(buf+2, "%d:%d",
2503 &slot, &rating)) return (1);
2505 /* Save the values */
2507 e_ptr->rating = rating;
2510 /* Process 'W' for "More Info" (one line only) */
2511 else if (buf[0] == 'W')
2513 int level, rarity, pad2;
2516 /* Scan for the values */
2517 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2518 &level, &rarity, &pad2, &cost)) return (1);
2520 /* Save the values */
2521 e_ptr->level = level;
2522 e_ptr->rarity = rarity;
2523 /* e_ptr->weight = wgt; */
2527 /* Hack -- Process 'C' for "creation" */
2528 else if (buf[0] == 'C')
2532 /* Scan for the values */
2533 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2534 &th, &td, &ta, &pv)) return (1);
2536 e_ptr->max_to_h = th;
2537 e_ptr->max_to_d = td;
2538 e_ptr->max_to_a = ta;
2539 e_ptr->max_pval = pv;
2542 /* Hack -- Process 'U' for activation index */
2543 else if (buf[0] == 'U')
2546 n = grab_one_activation_flag(buf + 2);
2557 /* Hack -- Process 'F' for flags */
2558 else if (buf[0] == 'F')
2560 /* Parse every entry textually */
2561 for (s = buf + 2; *s; )
2563 /* Find the end of this entry */
2564 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2566 /* Nuke and skip any dividers */
2570 while ((*t == ' ') || (*t == '|')) t++;
2573 /* Parse this entry */
2574 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2576 /* Start the next entry */
2590 * Grab one (basic) flag in a monster_race from a textual string
2592 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2594 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2597 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2600 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2603 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2606 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2609 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2612 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2617 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2619 msg_format("Unknown monster flag '%s'.", what);
2629 * Grab one (spell) flag in a monster_race from a textual string
2631 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2633 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2636 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2639 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2644 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2646 msg_format("Unknown monster flag '%s'.", what);
2658 * Initialize the "r_info" array, by parsing an ascii "template" file
2660 errr parse_r_info(char *buf, header *head)
2667 static monster_race *r_ptr = NULL;
2670 /* Process 'N' for "New/Number/Name" */
2673 /* Find the colon before the name */
2674 s = my_strchr(buf+2, ':');
2676 /* Verify that colon */
2679 /* Nuke the colon, advance to the name */
2682 /* Paranoia -- require a name */
2683 if (!*s) return (1);
2688 /* Verify information */
2689 if (i < error_idx) return (4);
2691 /* Verify information */
2692 if (i >= head->info_num) return (2);
2694 /* Save the index */
2697 /* Point at the "info" */
2700 /* Store the name */
2701 if (!add_name(&r_ptr->name, head, s)) return (7);
2705 /* There better be a current r_ptr */
2706 else if (!r_ptr) return (3);
2710 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2711 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2712 else if (buf[0] == 'E')
2714 /* Acquire the Text */
2717 /* Store the name */
2718 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2721 else if (buf[0] == 'E')
2723 /* Acquire the Text */
2726 /* Store the name */
2727 if (!add_name(&r_ptr->name, head, s)) return (7);
2730 /* Process 'D' for "Description" */
2731 else if (buf[0] == 'D')
2736 /* Acquire the text */
2741 /* Acquire the text */
2745 /* Store the text */
2746 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2749 /* Process 'G' for "Graphics" (one line only) */
2750 else if (buf[0] == 'G')
2756 if (buf[1] != ':') return (1);
2757 if (!buf[2]) return (1);
2758 if (buf[3] != ':') return (1);
2759 if (!buf[4]) return (1);
2761 /* Extract the char */
2764 /* Extract the attr */
2765 tmp = color_char_to_attr(buf[4]);
2768 if (tmp > 127) return (1);
2770 /* Save the values */
2771 r_ptr->d_char = sym;
2772 r_ptr->d_attr = tmp;
2775 /* Process 'I' for "Info" (one line only) */
2776 else if (buf[0] == 'I')
2778 int spd, hp1, hp2, aaf, ac, slp;
2780 /* Scan for the other values */
2781 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2782 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2784 /* Save the values */
2786 r_ptr->hdice = MAX(hp1, 1);
2787 r_ptr->hside = MAX(hp2, 1);
2793 /* Process 'W' for "More Info" (one line only) */
2794 else if (buf[0] == 'W')
2801 /* Scan for the values */
2802 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2803 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2805 /* Save the values */
2807 r_ptr->rarity = rar;
2810 r_ptr->next_exp = nextexp;
2811 r_ptr->next_r_idx = nextmon;
2814 /* Process 'B' for "Blows" (up to four lines) */
2815 else if (buf[0] == 'B')
2819 /* Find the next empty blow slot (if any) */
2820 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2822 /* Oops, no more slots */
2823 if (i == 4) return (1);
2825 /* Analyze the first field */
2826 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2828 /* Terminate the field (if necessary) */
2829 if (*t == ':') *t++ = '\0';
2831 /* Analyze the method */
2832 for (n1 = 0; r_info_blow_method[n1]; n1++)
2834 if (streq(s, r_info_blow_method[n1])) break;
2837 /* Invalid method */
2838 if (!r_info_blow_method[n1]) return (1);
2840 /* Analyze the second field */
2841 for (s = t; *t && (*t != ':'); t++) /* loop */;
2843 /* Terminate the field (if necessary) */
2844 if (*t == ':') *t++ = '\0';
2846 /* Analyze effect */
2847 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2849 if (streq(s, r_info_blow_effect[n2])) break;
2852 /* Invalid effect */
2853 if (!r_info_blow_effect[n2]) return (1);
2855 /* Analyze the third field */
2856 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2858 /* Terminate the field (if necessary) */
2859 if (*t == 'd') *t++ = '\0';
2861 /* Save the method */
2862 r_ptr->blow[i].method = n1;
2864 /* Save the effect */
2865 r_ptr->blow[i].effect = n2;
2867 /* Extract the damage dice and sides */
2868 r_ptr->blow[i].d_dice = atoi(s);
2869 r_ptr->blow[i].d_side = atoi(t);
2872 /* Process 'F' for "Basic Flags" (multiple lines) */
2873 else if (buf[0] == 'F')
2875 /* Parse every entry */
2876 for (s = buf + 2; *s; )
2878 /* Find the end of this entry */
2879 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2881 /* Nuke and skip any dividers */
2885 while (*t == ' ' || *t == '|') t++;
2888 /* Parse this entry */
2889 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2891 /* Start the next entry */
2896 /* Process 'S' for "Spell Flags" (multiple lines) */
2897 else if (buf[0] == 'S')
2899 /* Parse every entry */
2900 for (s = buf + 2; *s; )
2902 /* Find the end of this entry */
2903 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2905 /* Nuke and skip any dividers */
2909 while ((*t == ' ') || (*t == '|')) t++;
2912 /* XXX XXX XXX Hack -- Read spell frequency */
2913 if (1 == sscanf(s, "1_IN_%d", &i))
2915 /* Extract a "frequency" */
2916 r_ptr->freq_spell = 100 / i;
2918 /* Start at next entry */
2925 /* Parse this entry */
2926 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2928 /* Start the next entry */
2943 * Grab one flag for a dungeon type from a textual string
2945 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2947 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2952 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2954 msg_format("Unknown dungeon type flag '%s'.", what);
2962 * Grab one (basic) flag in a monster_race from a textual string
2964 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2966 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2969 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2972 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2975 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2978 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2981 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2984 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2989 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2991 msg_format("Unknown monster flag '%s'.", what);
2999 * Grab one (spell) flag in a monster_race from a textual string
3001 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3003 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3006 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3009 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3014 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3016 msg_format("Unknown monster flag '%s'.", what);
3024 * Initialize the "d_info" array, by parsing an ascii "template" file
3026 errr parse_d_info(char *buf, header *head)
3033 static dungeon_info_type *d_ptr = NULL;
3036 /* Process 'N' for "New/Number/Name" */
3039 /* Find the colon before the name */
3040 s = my_strchr(buf+2, ':');
3042 /* Verify that colon */
3045 /* Nuke the colon, advance to the name */
3048 /* Paranoia -- require a name */
3049 if (!*s) return (1);
3054 /* Verify information */
3055 if (i < error_idx) return (4);
3057 /* Verify information */
3058 if (i >= head->info_num) return (2);
3060 /* Save the index */
3063 /* Point at the "info" */
3066 /* Store the name */
3067 if (!add_name(&d_ptr->name, head, s)) return (7);
3072 else if (buf[0] == 'E') return (0);
3074 else if (buf[0] == 'E')
3076 /* Acquire the Text */
3079 /* Store the name */
3080 if (!add_name(&d_ptr->name, head, s)) return (7);
3084 /* Process 'D' for "Description */
3085 else if (buf[0] == 'D')
3090 /* Acquire the text */
3095 /* Acquire the text */
3099 /* Store the text */
3100 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3103 /* Process 'W' for "More Info" (one line only) */
3104 else if (buf[0] == 'W')
3106 int min_lev, max_lev;
3108 int min_alloc, max_chance;
3109 int obj_good, obj_great;
3112 /* Scan for the values */
3113 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3114 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3116 /* Save the values */
3117 d_ptr->mindepth = min_lev;
3118 d_ptr->maxdepth = max_lev;
3119 d_ptr->min_plev = min_plev;
3121 d_ptr->min_m_alloc_level = min_alloc;
3122 d_ptr->max_m_alloc_chance = max_chance;
3123 d_ptr->obj_good = obj_good;
3124 d_ptr->obj_great = obj_great;
3129 /* Process 'P' for "Place Info" */
3130 else if (buf[0] == 'P')
3134 /* Scan for the values */
3135 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3137 /* Save the values */
3142 /* Process 'L' for "fLoor type" (one line only) */
3143 else if (buf[0] == 'L')
3147 /* Scan for the values */
3148 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3150 /* Save the values */
3151 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3153 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3154 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3156 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3158 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3161 /* Process 'A' for "wAll type" (one line only) */
3162 else if (buf[0] == 'A')
3166 /* Scan for the values */
3167 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3169 /* Save the values */
3170 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3172 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3173 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3175 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3178 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3179 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3181 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3182 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3184 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3185 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3187 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3188 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3191 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3192 else if (buf[0] == 'F')
3194 int artif = 0, monst = 0;
3196 /* Parse every entry */
3197 for (s = buf + 2; *s; )
3199 /* Find the end of this entry */
3200 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3202 /* Nuke and skip any dividers */
3206 while (*t == ' ' || *t == '|') t++;
3209 /* XXX XXX XXX Hack -- Read Final Artifact */
3210 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3212 /* Extract a "Final Artifact" */
3213 d_ptr->final_artifact = artif;
3215 /* Start at next entry */
3222 /* XXX XXX XXX Hack -- Read Final Object */
3223 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3225 /* Extract a "Final Artifact" */
3226 d_ptr->final_object = artif;
3228 /* Start at next entry */
3235 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3236 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3238 /* Extract a "Artifact Guardian" */
3239 d_ptr->final_guardian = monst;
3241 /* Start at next entry */
3248 /* XXX XXX XXX Hack -- Read Special Percentage */
3249 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3251 /* Extract a "Special %" */
3252 d_ptr->special_div = monst;
3254 /* Start at next entry */
3261 /* Parse this entry */
3262 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3264 /* Start the next entry */
3269 /* Process 'M' for "Basic Flags" (multiple lines) */
3270 else if (buf[0] == 'M')
3272 /* Parse every entry */
3273 for (s = buf + 2; *s; )
3275 /* Find the end of this entry */
3276 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3278 /* Nuke and skip any dividers */
3282 while (*t == ' ' || *t == '|') t++;
3285 /* Hack -- Read monster symbols */
3286 if (!strncmp(s, "R_CHAR_", 7))
3288 /* Skip "R_CHAR_" */
3292 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3294 /* Start at next entry */
3301 /* Parse this entry */
3302 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3304 /* Start the next entry */
3309 /* Process 'S' for "Spell Flags" (multiple lines) */
3310 else if (buf[0] == 'S')
3312 /* Parse every entry */
3313 for (s = buf + 2; *s; )
3315 /* Find the end of this entry */
3316 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3318 /* Nuke and skip any dividers */
3322 while ((*t == ' ') || (*t == '|')) t++;
3325 /* XXX XXX XXX Hack -- Read spell frequency */
3326 if (1 == sscanf(s, "1_IN_%d", &i))
3328 /* Start at next entry */
3335 /* Parse this entry */
3336 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3338 /* Start the next entry */
3351 #else /* ALLOW_TEMPLATES */
3357 #endif /* ALLOW_TEMPLATES */
3360 /* Random dungeon grid effects */
3361 #define RANDOM_NONE 0x00000000
3362 #define RANDOM_FEATURE 0x00000001
3363 #define RANDOM_MONSTER 0x00000002
3364 #define RANDOM_OBJECT 0x00000004
3365 #define RANDOM_EGO 0x00000008
3366 #define RANDOM_ARTIFACT 0x00000010
3367 #define RANDOM_TRAP 0x00000020
3370 typedef struct dungeon_grid dungeon_grid;
3374 int feature; /* Terrain feature */
3375 int monster; /* Monster */
3376 int object; /* Object */
3377 int ego; /* Ego-Item */
3378 int artifact; /* Artifact */
3379 int trap; /* Trap */
3380 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3381 int special; /* Reserved for special terrain info */
3382 int random; /* Number of the random effect */
3386 static dungeon_grid letter[255];
3390 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3392 static errr parse_line_feature(char *buf)
3398 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3400 /* Tokenize the line */
3401 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3403 /* Letter to assign */
3404 int index = zz[0][0];
3406 /* Reset the info for the letter */
3407 letter[index].feature = feat_none;
3408 letter[index].monster = 0;
3409 letter[index].object = 0;
3410 letter[index].ego = 0;
3411 letter[index].artifact = 0;
3412 letter[index].trap = feat_none;
3413 letter[index].cave_info = 0;
3414 letter[index].special = 0;
3415 letter[index].random = RANDOM_NONE;
3421 letter[index].special = atoi(zz[8]);
3425 if ((zz[7][0] == '*') && !zz[7][1])
3427 letter[index].random |= RANDOM_TRAP;
3431 letter[index].trap = f_tag_to_index(zz[7]);
3432 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3437 if (zz[6][0] == '*')
3439 letter[index].random |= RANDOM_ARTIFACT;
3440 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3442 else if (zz[6][0] == '!')
3444 if (p_ptr->inside_quest)
3446 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3451 letter[index].artifact = atoi(zz[6]);
3456 if (zz[5][0] == '*')
3458 letter[index].random |= RANDOM_EGO;
3459 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3463 letter[index].ego = atoi(zz[5]);
3468 if (zz[4][0] == '*')
3470 letter[index].random |= RANDOM_OBJECT;
3471 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3473 else if (zz[4][0] == '!')
3475 if (p_ptr->inside_quest)
3477 int a_idx = quest[p_ptr->inside_quest].k_idx;
3480 artifact_type *a_ptr = &a_info[a_idx];
3481 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3483 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3490 letter[index].object = atoi(zz[4]);
3495 if (zz[3][0] == '*')
3497 letter[index].random |= RANDOM_MONSTER;
3498 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3500 else if (zz[3][0] == 'c')
3502 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3503 letter[index].monster = - atoi(zz[3] + 1);
3507 letter[index].monster = atoi(zz[3]);
3512 letter[index].cave_info = atoi(zz[2]);
3516 if ((zz[1][0] == '*') && !zz[1][1])
3518 letter[index].random |= RANDOM_FEATURE;
3522 letter[index].feature = f_tag_to_index(zz[1]);
3523 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3536 * Process "B:<Index>:<Command>:..." -- Building definition
3538 static errr parse_line_building(char *buf)
3554 /* Get the building number */
3557 /* Find the colon after the building number */
3558 s = my_strchr(s, ':');
3560 /* Verify that colon */
3563 /* Nuke the colon, advance to the sub-index */
3566 /* Paranoia -- require a sub-index */
3567 if (!*s) return (1);
3569 /* Building definition sub-index */
3572 /* Building name, owner, race */
3575 if (tokenize(s + 2, 3, zz, 0) == 3)
3577 /* Name of the building */
3578 strcpy(building[index].name, zz[0]);
3580 /* Name of the owner */
3581 strcpy(building[index].owner_name, zz[1]);
3583 /* Race of the owner */
3584 strcpy(building[index].owner_race, zz[2]);
3589 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3592 /* Building Action */
3595 if (tokenize(s + 2, 8, zz, 0) >= 7)
3597 /* Index of the action */
3598 int action_index = atoi(zz[0]);
3600 /* Name of the action */
3601 strcpy(building[index].act_names[action_index], zz[1]);
3603 /* Cost of the action for members */
3604 building[index].member_costs[action_index] = atoi(zz[2]);
3606 /* Cost of the action for non-members */
3607 building[index].other_costs[action_index] = atoi(zz[3]);
3609 /* Letter assigned to the action */
3610 building[index].letters[action_index] = zz[4][0];
3613 building[index].actions[action_index] = atoi(zz[5]);
3615 /* Action restriction */
3616 building[index].action_restr[action_index] = atoi(zz[6]);
3621 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3624 /* Building Classes */
3627 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3629 for (i = 0; i < MAX_CLASS; i++)
3631 building[index].member_class[i] = atoi(zz[i]);
3637 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3640 /* Building Races */
3643 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3645 for (i = 0; i < MAX_RACES; i++)
3647 building[index].member_race[i] = atoi(zz[i]);
3653 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3656 /* Building Realms */
3659 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3661 for (i = 0; i < MAX_MAGIC; i++)
3663 building[index].member_realm[i+1] = atoi(zz[i]);
3669 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3674 /* Ignore scripts */
3680 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3689 * Place the object j_ptr to a grid
3691 static void drop_here(object_type *j_ptr, int y, int x)
3693 cave_type *c_ptr = &cave[y][x];
3696 /* Get new object */
3697 s16b o_idx = o_pop();
3699 /* Access new object */
3700 o_ptr = &o_list[o_idx];
3702 /* Structure copy */
3703 object_copy(o_ptr, j_ptr);
3711 o_ptr->held_m_idx = 0;
3714 o_ptr->next_o_idx = c_ptr->o_idx;
3716 /* Place the object */
3717 c_ptr->o_idx = o_idx;
3722 * Parse a sub-file of the "extra info"
3724 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3731 /* Skip "empty" lines */
3732 if (!buf[0]) return (0);
3734 /* Skip "blank" lines */
3735 if (isspace(buf[0])) return (0);
3738 if (buf[0] == '#') return (0);
3740 /* Require "?:*" format */
3741 if (buf[1] != ':') return (1);
3744 /* Process "%:<fname>" */
3747 /* Attempt to Process the given file */
3748 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3751 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3754 return parse_line_feature(buf);
3757 /* Process "D:<dungeon>" -- info for the cave grids */
3758 else if (buf[0] == 'D')
3760 object_type object_type_body;
3762 /* Acquire the text */
3765 /* Length of the text */
3766 int len = strlen(s);
3768 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3770 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3772 /* Access the grid */
3773 cave_type *c_ptr = &cave[*y][*x];
3777 int object_index = letter[idx].object;
3778 int monster_index = letter[idx].monster;
3779 int random = letter[idx].random;
3780 int artifact_index = letter[idx].artifact;
3782 /* Lay down a floor */
3783 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3785 /* Only the features */
3786 if (init_flags & INIT_ONLY_FEATURES) continue;
3789 c_ptr->info = letter[idx].cave_info;
3791 /* Create a monster */
3792 if (random & RANDOM_MONSTER)
3794 monster_level = base_level + monster_index;
3796 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3798 monster_level = base_level;
3800 else if (monster_index)
3802 int old_cur_num, old_max_num;
3805 if (monster_index < 0)
3807 monster_index = -monster_index;
3810 old_cur_num = r_info[monster_index].cur_num;
3811 old_max_num = r_info[monster_index].max_num;
3813 /* Make alive again */
3814 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3816 r_info[monster_index].cur_num = 0;
3817 r_info[monster_index].max_num = 1;
3820 /* Make alive again */
3821 /* Hack -- Non-unique Nazguls are semi-unique */
3822 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3824 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3826 r_info[monster_index].max_num++;
3831 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3835 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3837 /* Make alive again for real unique monster */
3838 r_info[monster_index].cur_num = old_cur_num;
3839 r_info[monster_index].max_num = old_max_num;
3843 /* Object (and possible trap) */
3844 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3846 object_level = base_level + object_index;
3849 * Random trap and random treasure defined
3850 * 25% chance for trap and 75% chance for object
3852 if (randint0(100) < 75)
3854 place_object(*y, *x, 0L);
3861 object_level = base_level;
3863 else if (random & RANDOM_OBJECT)
3865 object_level = base_level + object_index;
3867 /* Create an out of deep object */
3868 if (randint0(100) < 75)
3869 place_object(*y, *x, 0L);
3870 else if (randint0(100) < 80)
3871 place_object(*y, *x, AM_GOOD);
3873 place_object(*y, *x, AM_GOOD | AM_GREAT);
3875 object_level = base_level;
3878 else if (random & RANDOM_TRAP)
3882 /* Hidden trap (or door) */
3883 else if (letter[idx].trap)
3885 c_ptr->mimic = c_ptr->feat;
3886 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3888 else if (object_index)
3890 /* Get local object */
3891 object_type *o_ptr = &object_type_body;
3893 /* Create the item */
3894 object_prep(o_ptr, object_index);
3896 if (o_ptr->tval == TV_GOLD)
3898 coin_type = object_index - OBJ_GOLD_LIST;
3903 /* Apply magic (no messages, no artifacts) */
3904 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3906 drop_here(o_ptr, *y, *x);
3912 if (a_info[artifact_index].cur_num)
3914 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3916 object_type *q_ptr = &forge;
3918 object_prep(q_ptr, k_idx);
3920 /* Drop it in the dungeon */
3921 drop_here(q_ptr, *y, *x);
3925 /* Create the artifact */
3926 if (create_named_art(artifact_index, *y, *x))
3927 a_info[artifact_index].cur_num = 1;
3931 /* Terrain special */
3932 c_ptr->special = letter[idx].special;
3940 /* Process "Q:<number>:<command>:... -- quest info */
3941 else if (buf[0] == 'Q')
3948 num = tokenize(buf + 2, 33, zz, 0);
3952 num = tokenize(buf + 3, 33, zz, 0);
3955 /* Have we enough parameters? */
3956 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3959 q_ptr = &(quest[atoi(zz[0])]);
3961 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3962 if (zz[1][0] == 'Q')
3964 if (init_flags & INIT_ASSIGN)
3966 monster_race *r_ptr;
3967 artifact_type *a_ptr;
3969 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3971 q_ptr->type = atoi(zz[2]);
3972 q_ptr->num_mon = atoi(zz[3]);
3973 q_ptr->cur_num = atoi(zz[4]);
3974 q_ptr->max_num = atoi(zz[5]);
3975 q_ptr->level = atoi(zz[6]);
3976 q_ptr->r_idx = atoi(zz[7]);
3977 q_ptr->k_idx = atoi(zz[8]);
3978 q_ptr->dungeon = atoi(zz[9]);
3981 q_ptr->flags = atoi(zz[10]);
3983 r_ptr = &r_info[q_ptr->r_idx];
3984 if (r_ptr->flags1 & RF1_UNIQUE)
3985 r_ptr->flags1 |= RF1_QUESTOR;
3987 a_ptr = &a_info[q_ptr->k_idx];
3988 a_ptr->gen_flags |= TRG_QUESTITEM;
3993 else if (zz[1][0] == 'R')
3995 if (init_flags & INIT_ASSIGN)
4000 for (idx = 2; idx < num; idx++)
4002 int a_idx = atoi(zz[idx]);
4003 if (a_idx < 1) continue;
4004 if (a_info[a_idx].cur_num > 0) continue;
4006 if (one_in_(count)) reward_idx = a_idx;
4011 /* Set quest's rewarding artifact */
4012 q_ptr->k_idx = reward_idx;
4013 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4017 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4018 q_ptr->type = QUEST_TYPE_KILL_ALL;
4025 /* Process "Q:<q_index>:N:<name>" -- quest name */
4026 else if (zz[1][0] == 'N')
4028 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4030 strcpy(q_ptr->name, zz[2]);
4036 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4037 else if (zz[1][0] == 'T')
4039 if (init_flags & INIT_SHOW_TEXT)
4041 strcpy(quest_text[quest_text_line], zz[2]);
4049 /* Process "W:<command>: ..." -- info for the wilderness */
4050 else if (buf[0] == 'W')
4052 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4055 /* Process "P:<y>:<x>" -- player position */
4056 else if (buf[0] == 'P')
4058 if (init_flags & INIT_CREATE_DUNGEON)
4060 if (tokenize(buf + 2, 2, zz, 0) == 2)
4062 int panels_x, panels_y;
4064 /* Hack - Set the dungeon size */
4065 panels_y = (*y / SCREEN_HGT);
4066 if (*y % SCREEN_HGT) panels_y++;
4067 cur_hgt = panels_y * SCREEN_HGT;
4069 panels_x = (*x / SCREEN_WID);
4070 if (*x % SCREEN_WID) panels_x++;
4071 cur_wid = panels_x * SCREEN_WID;
4073 /* Assume illegal panel */
4074 panel_row_min = cur_hgt;
4075 panel_col_min = cur_wid;
4077 /* Place player in a quest level */
4078 if (p_ptr->inside_quest)
4082 /* Delete the monster (if any) */
4083 delete_monster(py, px);
4091 /* Place player in the town */
4092 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4094 p_ptr->oldpy = atoi(zz[0]);
4095 p_ptr->oldpx = atoi(zz[1]);
4103 /* Process "B:<Index>:<Command>:..." -- Building definition */
4104 else if (buf[0] == 'B')
4106 return parse_line_building(buf);
4109 /* Process "M:<type>:<maximum>" -- set maximum values */
4110 else if (buf[0] == 'M')
4112 if (tokenize(buf+2, 2, zz, 0) == 2)
4115 if (zz[0][0] == 'T')
4117 max_towns = atoi(zz[1]);
4120 /* Maximum quests */
4121 else if (zz[0][0] == 'Q')
4123 max_quests = atoi(zz[1]);
4127 else if (zz[0][0] == 'R')
4129 max_r_idx = atoi(zz[1]);
4133 else if (zz[0][0] == 'K')
4135 max_k_idx = atoi(zz[1]);
4139 else if (zz[0][0] == 'V')
4141 max_v_idx = atoi(zz[1]);
4145 else if (zz[0][0] == 'F')
4147 max_f_idx = atoi(zz[1]);
4151 else if (zz[0][0] == 'A')
4153 max_a_idx = atoi(zz[1]);
4157 else if (zz[0][0] == 'E')
4159 max_e_idx = atoi(zz[1]);
4163 else if (zz[0][0] == 'D')
4165 max_d_idx = atoi(zz[1]);
4169 else if (zz[0][0] == 'O')
4171 max_o_idx = atoi(zz[1]);
4175 else if (zz[0][0] == 'M')
4177 max_m_idx = atoi(zz[1]);
4180 /* Wilderness size */
4181 else if (zz[0][0] == 'W')
4183 /* Maximum wild_x_size */
4184 if (zz[0][1] == 'X')
4185 max_wild_x = atoi(zz[1]);
4186 /* Maximum wild_y_size */
4187 if (zz[0][1] == 'Y')
4188 max_wild_y = atoi(zz[1]);
4202 static cptr variant = "ZANGBAND";
4206 * Helper function for "process_dungeon_file()"
4208 static cptr process_dungeon_file_expr(char **sp, char *fp)
4224 while (isspace(*s)) s++;
4242 t = process_dungeon_file_expr(&s, &f);
4251 else if (streq(t, "IOR"))
4254 while (*s && (f != b2))
4256 t = process_dungeon_file_expr(&s, &f);
4257 if (*t && !streq(t, "0")) v = "1";
4262 else if (streq(t, "AND"))
4265 while (*s && (f != b2))
4267 t = process_dungeon_file_expr(&s, &f);
4268 if (*t && streq(t, "0")) v = "0";
4273 else if (streq(t, "NOT"))
4276 while (*s && (f != b2))
4278 t = process_dungeon_file_expr(&s, &f);
4279 if (*t && streq(t, "1")) v = "0";
4284 else if (streq(t, "EQU"))
4287 if (*s && (f != b2))
4289 t = process_dungeon_file_expr(&s, &f);
4291 while (*s && (f != b2))
4293 p = process_dungeon_file_expr(&s, &f);
4294 if (streq(t, p)) v = "1";
4299 else if (streq(t, "LEQ"))
4302 if (*s && (f != b2))
4304 t = process_dungeon_file_expr(&s, &f);
4306 while (*s && (f != b2))
4309 t = process_dungeon_file_expr(&s, &f);
4310 if (*t && atoi(p) > atoi(t)) v = "0";
4315 else if (streq(t, "GEQ"))
4318 if (*s && (f != b2))
4320 t = process_dungeon_file_expr(&s, &f);
4322 while (*s && (f != b2))
4325 t = process_dungeon_file_expr(&s, &f);
4327 /* Compare two numbers instead of string */
4328 if (*t && atoi(p) < atoi(t)) v = "0";
4335 while (*s && (f != b2))
4337 t = process_dungeon_file_expr(&s, &f);
4342 if (f != b2) v = "?x?x?";
4344 /* Extract final and Terminate */
4345 if ((f = *s) != '\0') *s++ = '\0';
4351 /* Accept all printables except spaces and brackets */
4353 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4355 if (iskanji(*s)) s++;
4359 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4362 /* Extract final and Terminate */
4363 if ((f = *s) != '\0') *s++ = '\0';
4369 if (streq(b+1, "SYS"))
4375 else if (streq(b+1, "GRAF"))
4380 else if (streq(b+1, "MONOCHROME"))
4389 else if (streq(b+1, "RACE"))
4392 v = rp_ptr->E_title;
4399 else if (streq(b+1, "CLASS"))
4402 v = cp_ptr->E_title;
4409 else if (streq(b+1, "REALM1"))
4412 v = E_realm_names[p_ptr->realm1];
4414 v = realm_names[p_ptr->realm1];
4419 else if (streq(b+1, "REALM2"))
4422 v = E_realm_names[p_ptr->realm2];
4424 v = realm_names[p_ptr->realm2];
4429 else if (streq(b+1, "PLAYER"))
4431 static char tmp_player_name[32];
4433 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4443 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4446 v = tmp_player_name;
4450 else if (streq(b+1, "TOWN"))
4452 sprintf(tmp, "%d", p_ptr->town_num);
4457 else if (streq(b+1, "LEVEL"))
4459 sprintf(tmp, "%d", p_ptr->lev);
4463 /* Current quest number */
4464 else if (streq(b+1, "QUEST_NUMBER"))
4466 sprintf(tmp, "%d", p_ptr->inside_quest);
4470 /* Number of last quest */
4471 else if (streq(b+1, "LEAVING_QUEST"))
4473 sprintf(tmp, "%d", leaving_quest);
4478 else if (prefix(b+1, "QUEST_TYPE"))
4480 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4481 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4486 else if (prefix(b+1, "QUEST"))
4488 /* "QUEST" uses a special parameter to determine the number of the quest */
4489 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4494 else if (prefix(b+1, "RANDOM"))
4496 /* "RANDOM" uses a special parameter to determine the number of the quest */
4497 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4502 else if (streq(b+1, "VARIANT"))
4508 else if (streq(b+1, "WILDERNESS"))
4511 sprintf(tmp, "NONE");
4513 sprintf(tmp, "LITE");
4515 sprintf(tmp, "NORMAL");
4538 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4548 bool bypass = FALSE;
4550 int x = xmin, y = ymin;
4553 /* Build the filename */
4554 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4557 fp = my_fopen(buf, "r");
4560 if (!fp) return (-1);
4563 /* Process the file */
4564 while (0 == my_fgets(fp, buf, sizeof(buf)))
4570 /* Skip "empty" lines */
4571 if (!buf[0]) continue;
4573 /* Skip "blank" lines */
4574 if (isspace(buf[0])) continue;
4577 if (buf[0] == '#') continue;
4580 /* Process "?:<expr>" */
4581 if ((buf[0] == '?') && (buf[1] == ':'))
4590 /* Parse the expr */
4591 v = process_dungeon_file_expr(&s, &f);
4594 bypass = (streq(v, "0") ? TRUE : FALSE);
4600 /* Apply conditionals */
4601 if (bypass) continue;
4603 /* Process the line */
4604 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4616 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4619 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4621 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4623 msg_format("Parsing '%s'.", buf);
4630 /* Close the file */
4640 void write_r_info_txt(void)
4642 int i, j, z, fc, bc;
4645 cptr flags[32 * 10];
4650 monster_race *r_ptr;
4652 monster_blow *b_ptr;
4654 FILE *fff = fopen("output.txt", "wt");
4662 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4664 fprintf(fff, "# Version stamp (required)\n\n");
4667 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4670 fprintf(fff, "##### The Player #####\n\n");
4672 for (z = -1; z < alloc_race_size; z++)
4674 /* Output the monsters in order */
4675 i = (z >= 0) ? alloc_race_table[z].index : 0;
4677 /* Acquire the monster */
4680 /* Ignore empty monsters */
4681 if (!strlen(r_name + r_ptr->name)) continue;
4683 /* Ignore useless monsters */
4684 if (i && !r_ptr->speed) continue;
4686 /* Write a note if necessary */
4687 if (i && (!r_ptr->level != !mode))
4692 fprintf(fff, "\n##### Town monsters #####\n\n");
4694 /* Note the dungeon */
4697 fprintf(fff, "\n##### Normal monsters #####\n\n");
4700 /* Record the change */
4701 mode = r_ptr->level;
4704 /* Acquire the flags */
4705 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4706 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4707 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4708 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4709 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4710 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4711 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4712 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4713 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4714 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4716 /* Write New/Number/Name */
4717 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4720 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4722 /* Write Information */
4723 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4724 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4726 /* Write more information */
4727 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4730 for(j = 0; j < 4; j++)
4732 b_ptr = &(r_ptr->blow[j]);
4734 /* Stop when done */
4735 if (!b_ptr->method) break;
4737 /* Write the blows */
4738 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4739 r_info_blow_effect[b_ptr->effect],
4740 b_ptr->d_dice, b_ptr->d_side);
4743 /* Extract the flags */
4744 for (fc = 0, j = 0; j < 32 * 3; j++)
4746 /* Check this flag */
4747 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4750 /* Extract the extra flags */
4751 for (j = 32 * 6; j < 32 * 10; j++)
4753 /* Check this flag */
4754 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4757 /* Write the flags */
4758 for (j = 0; j < fc;)
4762 /* Start the line */
4765 for (bc = 0; (bc < 60) && (j < fc); j++)
4769 /* Format the flag */
4770 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4772 /* Add it to the buffer */
4775 /* Note the length */
4779 /* Done with this line; write it */
4780 fprintf(fff, "%s\n", buf);
4783 /* Write Spells if applicable */
4784 if (r_ptr->freq_spell)
4786 /* Write the frequency */
4787 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4789 /* Extract the spell flags */
4790 for (fc = 0, j = 96; j < 192; j++)
4792 /* Check this flag */
4793 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4796 /* Write the flags */
4797 for (j = 0; j < fc;)
4801 /* Start the line */
4804 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4808 /* Format the flag */
4809 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4813 /* Note the length */
4820 /* Done with this line; write it */
4821 fprintf(fff, "%s\n", buf);
4825 /* Acquire the description */
4826 desc = r_text + r_ptr->text;
4827 dlen = strlen(desc);
4829 /* Write Description */
4830 for (j = 0; j < dlen;)
4834 /* Start the line */
4837 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4845 /* Done with this line; write it */
4846 fprintf(fff, "%s\n", buf);
4849 /* Space between entries */