4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 1) -BEN- */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
33 * in this file is compiled out, and the game will not run unless valid
34 * "binary template files" already exist in "lib/data". Thus, one can
35 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
36 * "*.raw" files in "lib/data", and then quit, and recompile without
37 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
38 * from changing the ascii template files in potentially dangerous ways.
40 * The code could actually be removed and placed into a "stand-alone"
41 * program, but that feels a little silly, especially considering some
42 * of the platforms that we currently support.
45 #ifdef ALLOW_TEMPLATES
50 /*** Helper arrays for parsing ascii template files ***/
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * Monster Blow Effects
90 static cptr r_info_blow_effect[] =
133 static cptr f_info_flags[] =
255 static cptr r_info_flags1[] =
294 static cptr r_info_flags2[] =
333 static cptr r_info_flags3[] =
372 static cptr r_info_flags4[] =
411 static cptr r_info_flags5[] =
450 static cptr r_info_flags6[] =
467 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
490 static cptr r_info_flags7[] =
529 static cptr r_info_flags8[] =
561 "WILD_SWAMP", /* ToDo: Implement Swamp */
567 * Monster race flags - Drops
569 static cptr r_info_flags9[] =
608 * Monster race flags - Resistances
610 static cptr r_info_flagsr[] =
650 static cptr k_info_flags[] =
775 static cptr k_info_gen_flags[] =
815 static cptr d_info_flags1[] =
853 * Add a text to the text-storage and store offset to it.
855 * Returns FALSE when there isn't enough space available to store
858 static bool add_text(u32b *offset, header *head, cptr buf)
860 /* Hack -- Verify space */
861 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
867 /* Advance and save the text index */
868 *offset = ++head->text_size;
871 /* Append chars to the text */
872 strcpy(head->text_ptr + head->text_size, buf);
874 /* Advance the index */
875 head->text_size += strlen(buf);
883 * Add a name to the name-storage and return an offset to it.
885 * Returns FALSE when there isn't enough space available to store
888 static bool add_name(u32b *offset, header *head, cptr buf)
890 /* Hack -- Verify space */
891 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
897 /* Advance and save the name index */
898 *offset = ++head->name_size;
901 /* Append chars to the names */
902 strcpy(head->name_ptr + head->name_size, buf);
904 /* Advance the index */
905 head->name_size += strlen(buf);
913 * Add a tag to the tag-storage and return an offset to it.
915 * Returns FALSE when there isn't enough space available to store
918 static bool add_tag(s16b *offset, header *head, cptr buf)
922 /* Search for an existing (fake) tag */
923 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
926 if (streq(&head->tag_ptr[i], buf)) break;
929 /* There was no existing tag */
930 if (i >= head->tag_size)
932 /* Hack -- Verify space */
933 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
936 /* Append chars to the tags */
937 strcpy(head->tag_ptr + head->tag_size, buf);
939 /* Point the new tag */
942 /* Advance the index */
943 head->tag_size += strlen(buf) + 1;
946 /* Return offset of the tag */
955 * Convert a "color letter" into an "actual" color
956 * The colors are: dwsorgbuDWvyRGBU, as shown below
958 byte color_char_to_attr(char c)
962 case 'd': return (TERM_DARK);
963 case 'w': return (TERM_WHITE);
964 case 's': return (TERM_SLATE);
965 case 'o': return (TERM_ORANGE);
966 case 'r': return (TERM_RED);
967 case 'g': return (TERM_GREEN);
968 case 'b': return (TERM_BLUE);
969 case 'u': return (TERM_UMBER);
971 case 'D': return (TERM_L_DARK);
972 case 'W': return (TERM_L_WHITE);
973 case 'v': return (TERM_VIOLET);
974 case 'y': return (TERM_YELLOW);
975 case 'R': return (TERM_L_RED);
976 case 'G': return (TERM_L_GREEN);
977 case 'B': return (TERM_L_BLUE);
978 case 'U': return (TERM_L_UMBER);
986 /*** Initialize from ascii template files ***/
990 * Initialize an "*_info" array, by parsing an ascii "template" file
992 errr init_info_txt(FILE *fp, char *buf, header *head,
993 parse_info_txt_func parse_info_txt_line)
997 /* Just before the first record */
1000 /* Just before the first line */
1004 /* Prepare the "fake" stuff */
1005 head->name_size = 0;
1006 head->text_size = 0;
1010 while (0 == my_fgets(fp, buf, 1024))
1012 /* Advance the line number */
1015 /* Skip comments and blank lines */
1016 if (!buf[0] || (buf[0] == '#')) continue;
1018 /* Verify correct "colon" format */
1019 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1022 /* Hack -- Process 'V' for "Version" */
1029 /* Mega Hack -- Calculate Check Sum */
1030 if (buf[0] != 'N' && buf[0] != 'D')
1033 for (i = 0; buf[i]; i++)
1035 head->v_extra += (byte)buf[i];
1036 head->v_extra ^= (1 << (i % 8));
1040 /* Parse the line */
1041 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1046 /* Complete the "name" and "text" sizes */
1047 if (head->name_size) head->name_size++;
1048 if (head->text_size) head->text_size++;
1056 * Initialize the "v_info" array, by parsing an ascii "template" file
1058 errr parse_v_info(char *buf, header *head)
1064 static vault_type *v_ptr = NULL;
1066 /* Process 'N' for "New/Number/Name" */
1069 /* Find the colon before the name */
1070 s = my_strchr(buf+2, ':');
1072 /* Verify that colon */
1075 /* Nuke the colon, advance to the name */
1078 /* Paranoia -- require a name */
1079 if (!*s) return (1);
1084 /* Verify information */
1085 if (i <= error_idx) return (4);
1087 /* Verify information */
1088 if (i >= head->info_num) return (2);
1090 /* Save the index */
1093 /* Point at the "info" */
1096 /* Store the name */
1097 if (!add_name(&v_ptr->name, head, s)) return (7);
1100 /* There better be a current v_ptr */
1101 else if (!v_ptr) return (3);
1103 /* Process 'D' for "Description" */
1104 else if (buf[0] == 'D')
1106 /* Acquire the text */
1109 /* Store the text */
1110 if (!add_text(&v_ptr->text, head, s)) return (7);
1113 /* Process 'X' for "Extra info" (one line only) */
1114 else if (buf[0] == 'X')
1116 int typ, rat, hgt, wid;
1118 /* Scan for the values */
1119 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1120 &typ, &rat, &hgt, &wid)) return (1);
1122 /* Save the values */
1139 * Initialize the "s_info" array, by parsing an ascii "template" file
1141 errr parse_s_info(char *buf, header *head)
1146 static skill_table *s_ptr = NULL;
1149 /* Process 'N' for "New/Number/Name" */
1155 /* Verify information */
1156 if (i <= error_idx) return (4);
1158 /* Verify information */
1159 if (i >= head->info_num) return (2);
1161 /* Save the index */
1164 /* Point at the "info" */
1168 /* There better be a current s_ptr */
1169 else if (!s_ptr) return (3);
1171 /* Process 'W' for "Weapon exp" */
1172 else if (buf[0] == 'W')
1174 int tval, sval, start, max;
1175 const s16b exp_conv_table[] =
1177 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1178 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1181 /* Scan for the values */
1182 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1183 &tval, &sval, &start, &max)) return (1);
1185 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1186 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1188 /* Save the values */
1189 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1190 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1193 /* Process 'S' for "Skill exp" */
1194 else if (buf[0] == 'S')
1196 int num, start, max;
1198 /* Scan for the values */
1199 if (3 != sscanf(buf+2, "%d:%d:%d",
1200 &num, &start, &max)) return (1);
1202 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1203 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1205 /* Save the values */
1206 s_ptr->s_start[num] = start;
1207 s_ptr->s_max[num] = max;
1220 * Initialize the "m_info" array, by parsing an ascii "template" file
1222 errr parse_m_info(char *buf, header *head)
1229 static player_magic *m_ptr = NULL;
1232 static int realm, magic_idx = 0, readable = 0;
1235 /* Process 'N' for "New/Number/Name" */
1241 /* Verify information */
1242 if (i <= error_idx) return (4);
1244 /* Verify information */
1245 if (i >= head->info_num) return (2);
1247 /* Save the index */
1250 /* Point at the "info" */
1254 /* There better be a current m_ptr */
1255 else if (!m_ptr) return (3);
1257 /* Process 'I' for "Info" (one line only) */
1258 else if (buf[0] == 'I')
1261 int xtra, type, first, weight;
1263 /* Find the colon before the name */
1264 s = my_strchr(buf+2, ':');
1266 /* Verify that colon */
1269 /* Nuke the colon, advance to the name */
1274 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1275 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1276 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1277 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1278 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1283 /* Find the colon before the name */
1284 s = my_strchr(s, ':');
1286 /* Verify that colon */
1289 /* Nuke the colon, advance to the name */
1292 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1293 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1294 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1295 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1296 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1297 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1301 /* Scan for the values */
1302 if (4 != sscanf(s, "%x:%d:%d:%d",
1303 (uint *)&xtra, &type, &first, &weight)) return (1);
1305 m_ptr->spell_xtra = xtra;
1306 m_ptr->spell_type = type;
1307 m_ptr->spell_first = first;
1308 m_ptr->spell_weight = weight;
1312 /* Process 'R' for "Realm" (one line only) */
1313 else if (buf[0] == 'R')
1315 /* Scan for the values */
1316 if (2 != sscanf(buf+2, "%d:%d",
1317 &realm, &readable)) return (1);
1322 else if (buf[0] == 'T')
1324 int level, mana, fail, exp;
1326 if (!readable) return (1);
1327 /* Scan for the values */
1328 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1329 &level, &mana, &fail, &exp)) return (1);
1331 m_ptr->info[realm][magic_idx].slevel = level;
1332 m_ptr->info[realm][magic_idx].smana = mana;
1333 m_ptr->info[realm][magic_idx].sfail = fail;
1334 m_ptr->info[realm][magic_idx].sexp = exp;
1348 * Grab one flag from a textual string
1350 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1355 for (i = 0; i < 32; i++)
1357 if (streq(what, names[i]))
1359 *flags |= (1L << i);
1369 * Grab one flag in an feature_type from a textual string
1371 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1376 for (i = 0; i < FF_FLAG_MAX; i++)
1378 if (streq(what, f_info_flags[i]))
1380 add_flag(f_ptr->flags, i);
1387 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1389 msg_format("Unknown feature flag '%s'.", what);
1393 return PARSE_ERROR_GENERIC;
1398 * Grab an action in an feature_type from a textual string
1400 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1405 for (i = 0; i < FF_FLAG_MAX; i++)
1407 if (streq(what, f_info_flags[i]))
1409 f_ptr->state[count].action = i;
1416 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1418 msg_format("Unknown feature action '%s'.", what);
1422 return PARSE_ERROR_GENERIC;
1427 * Initialize the "f_info" array, by parsing an ascii "template" file
1429 errr parse_f_info(char *buf, header *head)
1436 static feature_type *f_ptr = NULL;
1439 /* Process 'N' for "New/Number/Name" */
1442 /* Find the colon before the name */
1443 s = my_strchr(buf+2, ':');
1447 /* Nuke the colon, advance to the name */
1454 /* Verify information */
1455 if (i <= error_idx) return (4);
1457 /* Verify information */
1458 if (i >= head->info_num) return (2);
1460 /* Save the index */
1463 /* Point at the "info" */
1466 /* Tag name is given */
1470 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1473 /* Default "mimic" */
1476 /* Default "destroyed state" -- if not specified */
1477 f_ptr->destroyed = i;
1479 /* Default "states" */
1480 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1483 /* There better be a current f_ptr */
1484 else if (!f_ptr) return (3);
1487 else if (buf[0] == 'J')
1489 /* Store the name */
1490 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1493 else if (buf[0] == 'E')
1495 /* Ignore english name */
1498 else if (buf[0] == 'J')
1500 /* Ignore Japanese name */
1503 else if (buf[0] == 'E')
1505 /* Acquire the Text */
1508 /* Store the name */
1509 if (!add_name(&f_ptr->name, head, s)) return (7);
1514 /* Process 'M' for "Mimic" (one line only) */
1515 else if (buf[0] == 'M')
1519 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1521 /* Record a fake tag index */
1522 f_ptr->mimic = -offset;
1526 /* Process 'G' for "Graphics" (one line only) */
1527 else if (buf[0] == 'G')
1530 byte def_attr[F_LIT_MAX];
1531 char char_tmp[F_LIT_MAX];
1534 if (buf[1] != ':') return (1);
1535 if (!buf[2]) return (1);
1536 if (buf[3] != ':') return (1);
1537 if (!buf[4]) return (1);
1539 /* Extract the char */
1540 char_tmp[F_LIT_STANDARD] = buf[2];
1542 /* Extract the color */
1543 def_attr[F_LIT_STANDARD] = color_char_to_attr(buf[4]);
1546 if (def_attr[F_LIT_STANDARD] > 127) return (1);
1548 /* Save the default values for lighting */
1549 for (j = 0; j < F_LIT_MAX; j++)
1551 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1552 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1555 /* Is this feature supports lighting? */
1558 def_attr[F_LIT_LITE] = lighting_colours[def_attr[F_LIT_STANDARD]][0];
1559 def_attr[F_LIT_DARK] = lighting_colours[def_attr[F_LIT_STANDARD]][1];
1560 def_attr[F_LIT_DARKDARK] = lighting_colours[lighting_colours[def_attr[F_LIT_STANDARD]][1]][1];
1562 /* G:c:a:LIT (default) */
1563 if (streq(buf + 6, "LIT"))
1565 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1567 f_ptr->d_attr[j] = def_attr[j];
1571 /* G:c:a:lc:la:dc:da:Dc:Da */
1574 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1576 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c:%c:%c",
1577 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1578 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN],
1579 &char_tmp[F_LIT_DARKDARK], &attr_lite_tmp[F_LIT_DARKDARK - F_LIT_NS_BEGIN])) return 1;
1580 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1582 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1584 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1587 /* Use default lighting */
1588 f_ptr->d_attr[j] = def_attr[j];
1591 /* No lighting support */
1592 f_ptr->d_attr[j] = def_attr[F_LIT_STANDARD];
1595 /* Extract the color */
1596 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1597 if (f_ptr->d_attr[j] > 127) return 1;
1600 f_ptr->d_char[j] = char_tmp[j];
1604 else if (buf[5]) return 1;
1607 /* Hack -- Process 'F' for flags */
1608 else if (buf[0] == 'F')
1610 /* Parse every entry textually */
1611 for (s = buf + 2; *s; )
1613 /* Find the end of this entry */
1614 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1616 /* Nuke and skip any dividers */
1620 while (*t == ' ' || *t == '|') t++;
1623 /* XXX XXX XXX Hack -- Read feature power */
1624 if (1 == sscanf(s, "POWER_%d", &i))
1626 /* Extract a "power" */
1629 /* Start at next entry */
1636 /* Parse this entry */
1637 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1639 /* Start the next entry */
1644 /* Process 'W' for "More Info" (one line only) */
1645 else if (buf[0] == 'W')
1649 /* Scan for the value */
1650 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1652 /* Save the value */
1653 f_ptr->priority = priority;
1656 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1657 else if (buf[0] == 'K')
1661 /* Find the next empty state slot (if any) */
1662 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1664 /* Oops, no more slots */
1665 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1667 /* Analyze the first field */
1668 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1670 /* Terminate the field (if necessary) */
1671 if (*t == ':') *t++ = '\0';
1673 /* Is this default entry? */
1674 if (streq(s, "DESTROYED"))
1676 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1678 /* Record a fake tag index */
1679 f_ptr->destroyed = -offset;
1684 f_ptr->state[i].action = 0;
1686 /* Parse this entry */
1687 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1689 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1691 /* Record a fake tag index */
1692 f_ptr->state[i].result = -offset;
1705 * Convert a fake tag to a real feat index
1707 s16b f_tag_to_index(cptr str)
1711 /* Search for real index corresponding to this fake tag */
1712 for (i = 0; i < f_head.info_num; i++)
1714 if (streq(f_tag + f_info[i].tag, str))
1716 /* Return the index */
1727 * Search for real index corresponding to this fake tag
1729 static void search_real_feat(s16b *feat)
1733 /* Don't convert non-fake tag */
1734 if (*feat >= 0) return;
1736 /* Search for real index corresponding to this fake tag */
1737 for (i = 0; i < f_head.info_num; i++)
1739 if ((-(*feat)) == f_info[i].tag)
1741 /* Record real index */
1749 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1751 msg_format("%s is undefined.", f_tag + (-(*feat)));
1757 * Retouch fake tags of f_info
1759 void retouch_f_info(header *head)
1763 /* Convert fake tags to real feat indices */
1764 for (i = 0; i < head->info_num; i++)
1766 feature_type *f_ptr = &f_info[i];
1769 search_real_feat(&f_ptr->mimic);
1771 search_real_feat(&f_ptr->destroyed);
1773 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1779 * Grab one flag in an object_kind from a textual string
1781 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1786 for (i = 0; i < TR_FLAG_MAX; i++)
1788 if (streq(what, k_info_flags[i]))
1790 add_flag(k_ptr->flags, i);
1795 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1800 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1802 msg_format("Unknown object flag '%s'.", what);
1812 * Initialize the "k_info" array, by parsing an ascii "template" file
1814 errr parse_k_info(char *buf, header *head)
1821 static object_kind *k_ptr = NULL;
1824 /* Process 'N' for "New/Number/Name" */
1827 /* Find the colon before the name */
1828 s = my_strchr(buf+2, ':');
1830 /* Verify that colon */
1833 /* Nuke the colon, advance to the name */
1837 /* Paranoia -- require a name */
1838 if (!*s) return (1);
1843 /* Verify information */
1844 if (i <= error_idx) return (4);
1846 /* Verify information */
1847 if (i >= head->info_num) return (2);
1849 /* Save the index */
1852 /* Point at the "info" */
1856 /* Store the name */
1857 if (!add_name(&k_ptr->name, head, s)) return (7);
1861 /* There better be a current k_ptr */
1862 else if (!k_ptr) return (3);
1866 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1867 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1868 else if (buf[0] == 'E')
1873 else if (buf[0] == 'E')
1875 /* Acquire the Text */
1878 /* Store the name */
1879 if (!add_name(&k_ptr->name, head, s)) return (7);
1883 /* Process 'D' for "Description" */
1884 else if (buf[0] == 'D')
1889 /* Acquire the text */
1894 /* Acquire the text */
1898 /* Store the text */
1899 if (!add_text(&k_ptr->text, head, s)) return (7);
1902 /* Process 'G' for "Graphics" (one line only) */
1903 else if (buf[0] == 'G')
1909 if (buf[1] != ':') return (1);
1910 if (!buf[2]) return (1);
1911 if (buf[3] != ':') return (1);
1912 if (!buf[4]) return (1);
1914 /* Extract the char */
1917 /* Extract the attr */
1918 tmp = color_char_to_attr(buf[4]);
1921 if (tmp > 127) return (1);
1923 /* Save the values */
1924 k_ptr->d_attr = tmp;
1925 k_ptr->d_char = sym;
1928 /* Process 'I' for "Info" (one line only) */
1929 else if (buf[0] == 'I')
1931 int tval, sval, pval;
1933 /* Scan for the values */
1934 if (3 != sscanf(buf+2, "%d:%d:%d",
1935 &tval, &sval, &pval)) return (1);
1937 /* Save the values */
1943 /* Process 'W' for "More Info" (one line only) */
1944 else if (buf[0] == 'W')
1946 int level, extra, wgt;
1949 /* Scan for the values */
1950 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1951 &level, &extra, &wgt, &cost)) return (1);
1953 /* Save the values */
1954 k_ptr->level = level;
1955 k_ptr->extra = extra;
1956 k_ptr->weight = wgt;
1960 /* Process 'A' for "Allocation" (one line only) */
1961 else if (buf[0] == 'A')
1965 /* XXX XXX XXX Simply read each number following a colon */
1966 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1968 /* Default chance */
1969 k_ptr->chance[i] = 1;
1971 /* Store the attack damage index */
1972 k_ptr->locale[i] = atoi(s+1);
1974 /* Find the slash */
1975 t = my_strchr(s+1, '/');
1977 /* Find the next colon */
1978 s = my_strchr(s+1, ':');
1980 /* If the slash is "nearby", use it */
1981 if (t && (!s || t < s))
1983 int chance = atoi(t+1);
1984 if (chance > 0) k_ptr->chance[i] = chance;
1989 /* Hack -- Process 'P' for "power" and such */
1990 else if (buf[0] == 'P')
1992 int ac, hd1, hd2, th, td, ta;
1994 /* Scan for the values */
1995 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1996 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2006 /* Hack -- Process 'F' for flags */
2007 else if (buf[0] == 'F')
2009 /* Parse every entry textually */
2010 for (s = buf + 2; *s; )
2012 /* Find the end of this entry */
2013 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2015 /* Nuke and skip any dividers */
2019 while (*t == ' ' || *t == '|') t++;
2022 /* Parse this entry */
2023 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2025 /* Start the next entry */
2041 * Grab one flag in an artifact_type from a textual string
2043 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2048 for (i = 0; i < TR_FLAG_MAX; i++)
2050 if (streq(what, k_info_flags[i]))
2052 add_flag(a_ptr->flags, i);
2057 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2062 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2064 msg_format("Unknown artifact flag '%s'.", what);
2076 * Initialize the "a_info" array, by parsing an ascii "template" file
2078 errr parse_a_info(char *buf, header *head)
2085 static artifact_type *a_ptr = NULL;
2088 /* Process 'N' for "New/Number/Name" */
2091 /* Find the colon before the name */
2092 s = my_strchr(buf+2, ':');
2094 /* Verify that colon */
2097 /* Nuke the colon, advance to the name */
2100 /* Paranoia -- require a name */
2101 if (!*s) return (1);
2106 /* Verify information */
2107 if (i < error_idx) return (4);
2109 /* Verify information */
2110 if (i >= head->info_num) return (2);
2112 /* Save the index */
2115 /* Point at the "info" */
2118 /* Ignore everything */
2119 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2120 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2121 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2122 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2124 /* Store the name */
2125 if (!add_name(&a_ptr->name, head, s)) return (7);
2129 /* There better be a current a_ptr */
2130 else if (!a_ptr) return (3);
2134 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2135 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2136 else if (buf[0] == 'E')
2141 else if (buf[0] == 'E')
2143 /* Acquire the Text */
2146 /* Store the name */
2147 if (!add_name(&a_ptr->name, head, s)) return (7);
2151 /* Process 'D' for "Description" */
2152 else if (buf[0] == 'D')
2157 /* Acquire the text */
2162 /* Acquire the text */
2166 /* Store the text */
2167 if (!add_text(&a_ptr->text, head, s)) return (7);
2171 /* Process 'I' for "Info" (one line only) */
2172 else if (buf[0] == 'I')
2174 int tval, sval, pval;
2176 /* Scan for the values */
2177 if (3 != sscanf(buf+2, "%d:%d:%d",
2178 &tval, &sval, &pval)) return (1);
2180 /* Save the values */
2186 /* Process 'W' for "More Info" (one line only) */
2187 else if (buf[0] == 'W')
2189 int level, rarity, wgt;
2192 /* Scan for the values */
2193 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2194 &level, &rarity, &wgt, &cost)) return (1);
2196 /* Save the values */
2197 a_ptr->level = level;
2198 a_ptr->rarity = rarity;
2199 a_ptr->weight = wgt;
2203 /* Hack -- Process 'P' for "power" and such */
2204 else if (buf[0] == 'P')
2206 int ac, hd1, hd2, th, td, ta;
2208 /* Scan for the values */
2209 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2210 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2220 /* Hack -- Process 'F' for flags */
2221 else if (buf[0] == 'F')
2223 /* Parse every entry textually */
2224 for (s = buf + 2; *s; )
2226 /* Find the end of this entry */
2227 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2229 /* Nuke and skip any dividers */
2233 while ((*t == ' ') || (*t == '|')) t++;
2236 /* Parse this entry */
2237 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2239 /* Start the next entry */
2255 * Grab one flag in a ego-item_type from a textual string
2257 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2262 for (i = 0; i < TR_FLAG_MAX; i++)
2264 if (streq(what, k_info_flags[i]))
2266 add_flag(e_ptr->flags, i);
2271 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2276 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2278 msg_format("Unknown ego-item flag '%s'.", what);
2290 * Initialize the "e_info" array, by parsing an ascii "template" file
2292 errr parse_e_info(char *buf, header *head)
2299 static ego_item_type *e_ptr = NULL;
2302 /* Just before the first record */
2305 /* Just before the first line */
2309 /* Process 'N' for "New/Number/Name" */
2312 /* Find the colon before the name */
2313 s = my_strchr(buf+2, ':');
2315 /* Verify that colon */
2318 /* Nuke the colon, advance to the name */
2321 /* Paranoia -- require a name */
2322 if (!*s) return (1);
2327 /* Verify information */
2328 if (i < error_idx) return (4);
2330 /* Verify information */
2331 if (i >= head->info_num) return (2);
2333 /* Save the index */
2336 /* Point at the "info" */
2339 /* Store the name */
2340 if (!add_name(&e_ptr->name, head, s)) return (7);
2344 /* There better be a current e_ptr */
2345 else if (!e_ptr) return (3);
2349 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2350 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2351 else if (buf[0] == 'E')
2356 else if (buf[0] == 'E')
2358 /* Acquire the Text */
2361 /* Store the name */
2362 if (!add_name(&e_ptr->name, head, s)) return (7);
2367 /* Process 'D' for "Description" */
2368 else if (buf[0] == 'D')
2370 /* Acquire the text */
2373 /* Store the text */
2374 if (!add_text(&e_ptr->text, head, s)) return (7);
2379 /* Process 'X' for "Xtra" (one line only) */
2380 else if (buf[0] == 'X')
2384 /* Scan for the values */
2385 if (2 != sscanf(buf+2, "%d:%d",
2386 &slot, &rating)) return (1);
2388 /* Save the values */
2390 e_ptr->rating = rating;
2393 /* Process 'W' for "More Info" (one line only) */
2394 else if (buf[0] == 'W')
2396 int level, rarity, pad2;
2399 /* Scan for the values */
2400 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2401 &level, &rarity, &pad2, &cost)) return (1);
2403 /* Save the values */
2404 e_ptr->level = level;
2405 e_ptr->rarity = rarity;
2406 /* e_ptr->weight = wgt; */
2410 /* Hack -- Process 'C' for "creation" */
2411 else if (buf[0] == 'C')
2415 /* Scan for the values */
2416 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2417 &th, &td, &ta, &pv)) return (1);
2419 e_ptr->max_to_h = th;
2420 e_ptr->max_to_d = td;
2421 e_ptr->max_to_a = ta;
2422 e_ptr->max_pval = pv;
2425 /* Hack -- Process 'F' for flags */
2426 else if (buf[0] == 'F')
2428 /* Parse every entry textually */
2429 for (s = buf + 2; *s; )
2431 /* Find the end of this entry */
2432 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2434 /* Nuke and skip any dividers */
2438 while ((*t == ' ') || (*t == '|')) t++;
2441 /* Parse this entry */
2442 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2444 /* Start the next entry */
2458 * Grab one (basic) flag in a monster_race from a textual string
2460 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2462 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2465 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2468 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2471 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2474 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2477 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2480 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2485 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2487 msg_format("Unknown monster flag '%s'.", what);
2497 * Grab one (spell) flag in a monster_race from a textual string
2499 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2501 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2504 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2507 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2512 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2514 msg_format("Unknown monster flag '%s'.", what);
2526 * Initialize the "r_info" array, by parsing an ascii "template" file
2528 errr parse_r_info(char *buf, header *head)
2535 static monster_race *r_ptr = NULL;
2538 /* Process 'N' for "New/Number/Name" */
2541 /* Find the colon before the name */
2542 s = my_strchr(buf+2, ':');
2544 /* Verify that colon */
2547 /* Nuke the colon, advance to the name */
2550 /* Paranoia -- require a name */
2551 if (!*s) return (1);
2556 /* Verify information */
2557 if (i < error_idx) return (4);
2559 /* Verify information */
2560 if (i >= head->info_num) return (2);
2562 /* Save the index */
2565 /* Point at the "info" */
2568 /* Store the name */
2569 if (!add_name(&r_ptr->name, head, s)) return (7);
2573 /* There better be a current r_ptr */
2574 else if (!r_ptr) return (3);
2578 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2579 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2580 else if (buf[0] == 'E')
2582 /* Acquire the Text */
2585 /* Store the name */
2586 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2589 else if (buf[0] == 'E')
2591 /* Acquire the Text */
2594 /* Store the name */
2595 if (!add_name(&r_ptr->name, head, s)) return (7);
2598 /* Process 'D' for "Description" */
2599 else if (buf[0] == 'D')
2604 /* Acquire the text */
2609 /* Acquire the text */
2613 /* Store the text */
2614 if (!add_text(&r_ptr->text, head, s)) return (7);
2617 /* Process 'G' for "Graphics" (one line only) */
2618 else if (buf[0] == 'G')
2624 if (buf[1] != ':') return (1);
2625 if (!buf[2]) return (1);
2626 if (buf[3] != ':') return (1);
2627 if (!buf[4]) return (1);
2629 /* Extract the char */
2632 /* Extract the attr */
2633 tmp = color_char_to_attr(buf[4]);
2636 if (tmp > 127) return (1);
2638 /* Save the values */
2639 r_ptr->d_char = sym;
2640 r_ptr->d_attr = tmp;
2643 /* Process 'I' for "Info" (one line only) */
2644 else if (buf[0] == 'I')
2646 int spd, hp1, hp2, aaf, ac, slp;
2648 /* Scan for the other values */
2649 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2650 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2652 /* Save the values */
2661 /* Process 'W' for "More Info" (one line only) */
2662 else if (buf[0] == 'W')
2669 /* Scan for the values */
2670 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2671 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2673 /* Save the values */
2675 r_ptr->rarity = rar;
2678 r_ptr->next_exp = nextexp;
2679 r_ptr->next_r_idx = nextmon;
2682 /* Process 'B' for "Blows" (up to four lines) */
2683 else if (buf[0] == 'B')
2687 /* Find the next empty blow slot (if any) */
2688 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2690 /* Oops, no more slots */
2691 if (i == 4) return (1);
2693 /* Analyze the first field */
2694 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2696 /* Terminate the field (if necessary) */
2697 if (*t == ':') *t++ = '\0';
2699 /* Analyze the method */
2700 for (n1 = 0; r_info_blow_method[n1]; n1++)
2702 if (streq(s, r_info_blow_method[n1])) break;
2705 /* Invalid method */
2706 if (!r_info_blow_method[n1]) return (1);
2708 /* Analyze the second field */
2709 for (s = t; *t && (*t != ':'); t++) /* loop */;
2711 /* Terminate the field (if necessary) */
2712 if (*t == ':') *t++ = '\0';
2714 /* Analyze effect */
2715 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2717 if (streq(s, r_info_blow_effect[n2])) break;
2720 /* Invalid effect */
2721 if (!r_info_blow_effect[n2]) return (1);
2723 /* Analyze the third field */
2724 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2726 /* Terminate the field (if necessary) */
2727 if (*t == 'd') *t++ = '\0';
2729 /* Save the method */
2730 r_ptr->blow[i].method = n1;
2732 /* Save the effect */
2733 r_ptr->blow[i].effect = n2;
2735 /* Extract the damage dice and sides */
2736 r_ptr->blow[i].d_dice = atoi(s);
2737 r_ptr->blow[i].d_side = atoi(t);
2740 /* Process 'F' for "Basic Flags" (multiple lines) */
2741 else if (buf[0] == 'F')
2743 /* Parse every entry */
2744 for (s = buf + 2; *s; )
2746 /* Find the end of this entry */
2747 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2749 /* Nuke and skip any dividers */
2753 while (*t == ' ' || *t == '|') t++;
2756 /* Parse this entry */
2757 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2759 /* Start the next entry */
2764 /* Process 'S' for "Spell Flags" (multiple lines) */
2765 else if (buf[0] == 'S')
2767 /* Parse every entry */
2768 for (s = buf + 2; *s; )
2770 /* Find the end of this entry */
2771 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2773 /* Nuke and skip any dividers */
2777 while ((*t == ' ') || (*t == '|')) t++;
2780 /* XXX XXX XXX Hack -- Read spell frequency */
2781 if (1 == sscanf(s, "1_IN_%d", &i))
2783 /* Extract a "frequency" */
2784 r_ptr->freq_spell = 100 / i;
2786 /* Start at next entry */
2793 /* Parse this entry */
2794 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2796 /* Start the next entry */
2811 * Grab one flag for a dungeon type from a textual string
2813 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2815 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2820 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2822 msg_format("Unknown dungeon type flag '%s'.", what);
2830 * Grab one (basic) flag in a monster_race from a textual string
2832 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2834 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2837 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2840 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2843 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2846 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2849 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2852 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2857 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2859 msg_format("Unknown monster flag '%s'.", what);
2867 * Grab one (spell) flag in a monster_race from a textual string
2869 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2871 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2874 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2877 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2882 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2884 msg_format("Unknown monster flag '%s'.", what);
2892 * Initialize the "d_info" array, by parsing an ascii "template" file
2894 errr parse_d_info(char *buf, header *head)
2901 static dungeon_info_type *d_ptr = NULL;
2904 /* Process 'N' for "New/Number/Name" */
2907 /* Find the colon before the name */
2908 s = my_strchr(buf+2, ':');
2910 /* Verify that colon */
2913 /* Nuke the colon, advance to the name */
2916 /* Paranoia -- require a name */
2917 if (!*s) return (1);
2922 /* Verify information */
2923 if (i < error_idx) return (4);
2925 /* Verify information */
2926 if (i >= head->info_num) return (2);
2928 /* Save the index */
2931 /* Point at the "info" */
2934 /* Store the name */
2935 if (!add_name(&d_ptr->name, head, s)) return (7);
2940 else if (buf[0] == 'E') return (0);
2942 else if (buf[0] == 'E')
2944 /* Acquire the Text */
2947 /* Store the name */
2948 if (!add_name(&d_ptr->name, head, s)) return (7);
2952 /* Process 'D' for "Description */
2953 else if (buf[0] == 'D')
2958 /* Acquire the text */
2963 /* Acquire the text */
2967 /* Store the text */
2968 if (!add_text(&d_ptr->text, head, s)) return (7);
2971 /* Process 'W' for "More Info" (one line only) */
2972 else if (buf[0] == 'W')
2974 int min_lev, max_lev;
2976 int min_alloc, max_chance;
2977 int obj_good, obj_great;
2980 /* Scan for the values */
2981 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2982 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2984 /* Save the values */
2985 d_ptr->mindepth = min_lev;
2986 d_ptr->maxdepth = max_lev;
2987 d_ptr->min_plev = min_plev;
2989 d_ptr->min_m_alloc_level = min_alloc;
2990 d_ptr->max_m_alloc_chance = max_chance;
2991 d_ptr->obj_good = obj_good;
2992 d_ptr->obj_great = obj_great;
2997 /* Process 'P' for "Place Info" */
2998 else if (buf[0] == 'P')
3002 /* Scan for the values */
3003 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3005 /* Save the values */
3010 /* Process 'L' for "fLoor type" (one line only) */
3011 else if (buf[0] == 'L')
3015 /* Scan for the values */
3016 if (tokenize(buf+2, 7, zz, 0) != 7) return (1);
3018 /* Save the values */
3019 d_ptr->floor1 = f_tag_to_index(zz[0]);
3020 d_ptr->floor_percent1 = atoi(zz[1]);
3021 d_ptr->floor2 = f_tag_to_index(zz[2]);
3022 d_ptr->floor_percent2 = atoi(zz[3]);
3023 d_ptr->floor3 = f_tag_to_index(zz[4]);
3024 d_ptr->floor_percent3 = atoi(zz[5]);
3025 d_ptr->tunnel_percent = atoi(zz[6]);
3028 /* Process 'A' for "wAll type" (one line only) */
3029 else if (buf[0] == 'A')
3033 /* Scan for the values */
3034 if (tokenize(buf+2, 10, zz, 0) != 10) return (1);
3036 /* Save the values */
3037 d_ptr->fill_type1 = f_tag_to_index(zz[0]);
3038 d_ptr->fill_percent1 = atoi(zz[1]);
3039 d_ptr->fill_type2 = f_tag_to_index(zz[2]);
3040 d_ptr->fill_percent2 = atoi(zz[3]);
3041 d_ptr->fill_type3 = f_tag_to_index(zz[4]);
3042 d_ptr->fill_percent3 = atoi(zz[5]);
3043 d_ptr->outer_wall = f_tag_to_index(zz[6]);
3044 d_ptr->inner_wall = f_tag_to_index(zz[7]);
3045 d_ptr->stream1 = f_tag_to_index(zz[8]);
3046 d_ptr->stream2 = f_tag_to_index(zz[9]);
3049 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3050 else if (buf[0] == 'F')
3052 int artif = 0, monst = 0;
3054 /* Parse every entry */
3055 for (s = buf + 2; *s; )
3057 /* Find the end of this entry */
3058 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3060 /* Nuke and skip any dividers */
3064 while (*t == ' ' || *t == '|') t++;
3067 /* XXX XXX XXX Hack -- Read Final Artifact */
3068 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3070 /* Extract a "Final Artifact" */
3071 d_ptr->final_artifact = artif;
3073 /* Start at next entry */
3080 /* XXX XXX XXX Hack -- Read Final Object */
3081 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3083 /* Extract a "Final Artifact" */
3084 d_ptr->final_object = artif;
3086 /* Start at next entry */
3093 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3094 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3096 /* Extract a "Artifact Guardian" */
3097 d_ptr->final_guardian = monst;
3099 /* Start at next entry */
3106 /* XXX XXX XXX Hack -- Read Special Percentage */
3107 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3109 /* Extract a "Special %" */
3110 d_ptr->special_div = monst;
3112 /* Start at next entry */
3119 /* Parse this entry */
3120 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3122 /* Start the next entry */
3127 /* Process 'M' for "Basic Flags" (multiple lines) */
3128 else if (buf[0] == 'M')
3130 /* Parse every entry */
3131 for (s = buf + 2; *s; )
3133 /* Find the end of this entry */
3134 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3136 /* Nuke and skip any dividers */
3140 while (*t == ' ' || *t == '|') t++;
3143 /* Hack -- Read monster symbols */
3144 if (!strncmp(s, "R_CHAR_", 7))
3146 /* Skip "R_CHAR_" */
3150 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3152 /* Start at next entry */
3159 /* Parse this entry */
3160 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3162 /* Start the next entry */
3167 /* Process 'S' for "Spell Flags" (multiple lines) */
3168 else if (buf[0] == 'S')
3170 /* Parse every entry */
3171 for (s = buf + 2; *s; )
3173 /* Find the end of this entry */
3174 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3176 /* Nuke and skip any dividers */
3180 while ((*t == ' ') || (*t == '|')) t++;
3183 /* XXX XXX XXX Hack -- Read spell frequency */
3184 if (1 == sscanf(s, "1_IN_%d", &i))
3186 /* Start at next entry */
3193 /* Parse this entry */
3194 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3196 /* Start the next entry */
3209 #else /* ALLOW_TEMPLATES */
3215 #endif /* ALLOW_TEMPLATES */
3218 /* Random dungeon grid effects */
3219 #define RANDOM_NONE 0x00
3220 #define RANDOM_FEATURE 0x01
3221 #define RANDOM_MONSTER 0x02
3222 #define RANDOM_OBJECT 0x04
3223 #define RANDOM_EGO 0x08
3224 #define RANDOM_ARTIFACT 0x10
3225 #define RANDOM_TRAP 0x20
3228 typedef struct dungeon_grid dungeon_grid;
3232 int feature; /* Terrain feature */
3233 int monster; /* Monster */
3234 int object; /* Object */
3235 int ego; /* Ego-Item */
3236 int artifact; /* Artifact */
3237 int trap; /* Trap */
3238 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3239 int special; /* Reserved for special terrain info */
3240 int random; /* Number of the random effect */
3244 static dungeon_grid letter[255];
3248 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3250 static errr parse_line_feature(char *buf)
3256 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3258 /* Tokenize the line */
3259 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3261 /* Letter to assign */
3262 int index = zz[0][0];
3264 /* Reset the info for the letter */
3265 letter[index].feature = 0;
3266 letter[index].monster = 0;
3267 letter[index].object = 0;
3268 letter[index].ego = 0;
3269 letter[index].artifact = 0;
3270 letter[index].trap = 0;
3271 letter[index].cave_info = 0;
3272 letter[index].special = 0;
3273 letter[index].random = 0;
3279 letter[index].special = atoi(zz[8]);
3283 if (zz[7][0] == '*')
3285 letter[index].random |= RANDOM_TRAP;
3290 letter[index].trap = atoi(zz[7]);
3295 letter[index].trap = atoi(zz[7]);
3300 if (zz[6][0] == '*')
3302 letter[index].random |= RANDOM_ARTIFACT;
3307 letter[index].artifact = atoi(zz[6]);
3312 letter[index].artifact = atoi(zz[6]);
3317 if (zz[5][0] == '*')
3319 letter[index].random |= RANDOM_EGO;
3324 letter[index].ego = atoi(zz[5]);
3329 letter[index].ego = atoi(zz[5]);
3334 if (zz[4][0] == '*')
3336 letter[index].random |= RANDOM_OBJECT;
3341 letter[index].object = atoi(zz[4]);
3346 letter[index].object = atoi(zz[4]);
3351 if (zz[3][0] == '*')
3353 letter[index].random |= RANDOM_MONSTER;
3357 letter[index].monster = atoi(zz[3]);
3360 else if (zz[3][0] == 'c')
3362 letter[index].monster = - atoi(zz[3]+1);
3366 letter[index].monster = atoi(zz[3]);
3371 letter[index].cave_info = atoi(zz[2]);
3375 if (zz[1][0] == '*')
3377 letter[index].random |= RANDOM_FEATURE;
3381 letter[index].feature = atoi(zz[1]);
3386 letter[index].feature = atoi(zz[1]);
3399 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3401 static errr parse_line_building(char *buf)
3417 /* Get the building number */
3420 /* Find the colon after the building number */
3421 s = my_strchr(s, ':');
3423 /* Verify that colon */
3426 /* Nuke the colon, advance to the sub-index */
3429 /* Paranoia -- require a sub-index */
3430 if (!*s) return (1);
3432 /* Building definition sub-index */
3435 /* Building name, owner, race */
3438 if (tokenize(s + 2, 3, zz, 0) == 3)
3440 /* Name of the building */
3441 strcpy(building[index].name, zz[0]);
3443 /* Name of the owner */
3444 strcpy(building[index].owner_name, zz[1]);
3446 /* Race of the owner */
3447 strcpy(building[index].owner_race, zz[2]);
3452 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3455 /* Building Action */
3458 if (tokenize(s + 2, 8, zz, 0) >= 7)
3460 /* Index of the action */
3461 int action_index = atoi(zz[0]);
3463 /* Name of the action */
3464 strcpy(building[index].act_names[action_index], zz[1]);
3466 /* Cost of the action for members */
3467 building[index].member_costs[action_index] = atoi(zz[2]);
3469 /* Cost of the action for non-members */
3470 building[index].other_costs[action_index] = atoi(zz[3]);
3472 /* Letter assigned to the action */
3473 building[index].letters[action_index] = zz[4][0];
3476 building[index].actions[action_index] = atoi(zz[5]);
3478 /* Action restriction */
3479 building[index].action_restr[action_index] = atoi(zz[6]);
3484 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3487 /* Building Classes */
3490 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3492 for (i = 0; i < MAX_CLASS; i++)
3494 building[index].member_class[i] = atoi(zz[i]);
3500 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3503 /* Building Races */
3506 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3508 for (i = 0; i < MAX_RACES; i++)
3510 building[index].member_race[i] = atoi(zz[i]);
3516 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3519 /* Building Realms */
3522 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3524 for (i = 0; i < MAX_MAGIC; i++)
3526 building[index].member_realm[i+1] = atoi(zz[i]);
3532 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3537 /* Ignore scripts */
3543 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3552 * Parse a sub-file of the "extra info"
3554 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3561 /* Skip "empty" lines */
3562 if (!buf[0]) return (0);
3564 /* Skip "blank" lines */
3565 if (isspace(buf[0])) return (0);
3568 if (buf[0] == '#') return (0);
3570 /* Require "?:*" format */
3571 if (buf[1] != ':') return (1);
3574 /* Process "%:<fname>" */
3577 /* Attempt to Process the given file */
3578 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3581 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3584 return parse_line_feature(buf);
3587 /* Process "D:<dungeon>" -- info for the cave grids */
3588 else if (buf[0] == 'D')
3590 object_type object_type_body;
3592 /* Acquire the text */
3595 /* Length of the text */
3596 int len = strlen(s);
3598 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3600 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3602 /* Access the grid */
3603 cave_type *c_ptr = &cave[*y][*x];
3607 int object_index = letter[idx].object;
3608 int monster_index = letter[idx].monster;
3609 int random = letter[idx].random;
3610 int artifact_index = letter[idx].artifact;
3612 /* Lay down a floor */
3613 c_ptr->feat = letter[idx].feature;
3615 /* Only the features */
3616 if (init_flags & INIT_ONLY_FEATURES) continue;
3619 c_ptr->info = letter[idx].cave_info;
3621 /* Create a monster */
3622 if (random & RANDOM_MONSTER)
3624 monster_level = base_level + monster_index;
3626 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3628 monster_level = base_level;
3630 else if (monster_index)
3632 int old_cur_num, old_max_num;
3635 if (monster_index < 0)
3637 monster_index = -monster_index;
3640 old_cur_num = r_info[monster_index].cur_num;
3641 old_max_num = r_info[monster_index].max_num;
3643 /* Make alive again */
3644 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3646 r_info[monster_index].cur_num = 0;
3647 r_info[monster_index].max_num = 1;
3650 /* Make alive again */
3651 /* Hack -- Non-unique Nazguls are semi-unique */
3652 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3654 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3656 r_info[monster_index].max_num++;
3661 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3665 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3667 /* Make alive again for real unique monster */
3668 r_info[monster_index].cur_num = old_cur_num;
3669 r_info[monster_index].max_num = old_max_num;
3673 /* Object (and possible trap) */
3674 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3676 object_level = base_level + object_index;
3679 * Random trap and random treasure defined
3680 * 25% chance for trap and 75% chance for object
3682 if (randint0(100) < 75)
3684 place_object(*y, *x, 0L);
3691 object_level = base_level;
3693 else if (random & RANDOM_OBJECT)
3695 object_level = base_level + object_index;
3697 /* Create an out of deep object */
3698 if (randint0(100) < 75)
3699 place_object(*y, *x, 0L);
3700 else if (randint0(100) < 80)
3701 place_object(*y, *x, AM_GOOD);
3703 place_object(*y, *x, AM_GOOD | AM_GREAT);
3705 object_level = base_level;
3708 else if (random & RANDOM_TRAP)
3712 /* Hidden trap (or door) */
3713 else if (letter[idx].trap)
3715 c_ptr->mimic = c_ptr->feat;
3716 c_ptr->feat = letter[idx].trap;
3718 else if (object_index)
3720 /* Get local object */
3721 object_type *o_ptr = &object_type_body;
3723 /* Create the item */
3724 object_prep(o_ptr, object_index);
3726 if (o_ptr->tval == TV_GOLD)
3728 coin_type = object_index - OBJ_GOLD_LIST;
3733 /* Apply magic (no messages, no artifacts) */
3734 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3736 (void)drop_near(o_ptr, -1, *y, *x);
3742 if (a_info[artifact_index].cur_num)
3744 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3746 object_type *q_ptr = &forge;
3748 object_prep(q_ptr, k_idx);
3750 /* Drop it in the dungeon */
3751 (void)drop_near(q_ptr, -1, *y, *x);
3755 /* Create the artifact */
3756 create_named_art(artifact_index, *y, *x);
3758 a_info[artifact_index].cur_num = 1;
3762 /* Terrain special */
3763 c_ptr->special = letter[idx].special;
3771 /* Process "Q:<number>:<command>:... -- quest info */
3772 else if (buf[0] == 'Q')
3779 num = tokenize(buf + 2, 33, zz, 0);
3783 num = tokenize(buf + 3, 33, zz, 0);
3786 /* Have we enough parameters? */
3787 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3790 q_ptr = &(quest[atoi(zz[0])]);
3792 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3793 if (zz[1][0] == 'Q')
3795 if (init_flags & INIT_ASSIGN)
3797 monster_race *r_ptr;
3798 artifact_type *a_ptr;
3800 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3802 q_ptr->type = atoi(zz[2]);
3803 q_ptr->num_mon = atoi(zz[3]);
3804 q_ptr->cur_num = atoi(zz[4]);
3805 q_ptr->max_num = atoi(zz[5]);
3806 q_ptr->level = atoi(zz[6]);
3807 q_ptr->r_idx = atoi(zz[7]);
3808 q_ptr->k_idx = atoi(zz[8]);
3809 q_ptr->dungeon = atoi(zz[9]);
3812 q_ptr->flags = atoi(zz[10]);
3814 r_ptr = &r_info[q_ptr->r_idx];
3815 if (r_ptr->flags1 & RF1_UNIQUE)
3816 r_ptr->flags1 |= RF1_QUESTOR;
3818 a_ptr = &a_info[q_ptr->k_idx];
3819 a_ptr->gen_flags |= TRG_QUESTITEM;
3824 /* Process "Q:<q_index>:N:<name>" -- quest name */
3825 else if (zz[1][0] == 'N')
3827 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3829 strcpy(q_ptr->name, zz[2]);
3835 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3836 else if (zz[1][0] == 'T')
3838 if (init_flags & INIT_SHOW_TEXT)
3840 strcpy(quest_text[quest_text_line], zz[2]);
3848 /* Process "W:<command>: ..." -- info for the wilderness */
3849 else if (buf[0] == 'W')
3851 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3854 /* Process "P:<y>:<x>" -- player position */
3855 else if (buf[0] == 'P')
3857 if (init_flags & INIT_CREATE_DUNGEON)
3859 if (tokenize(buf + 2, 2, zz, 0) == 2)
3861 int panels_x, panels_y;
3863 /* Hack - Set the dungeon size */
3864 panels_y = (*y / SCREEN_HGT);
3865 if (*y % SCREEN_HGT) panels_y++;
3866 cur_hgt = panels_y * SCREEN_HGT;
3868 panels_x = (*x / SCREEN_WID);
3869 if (*x % SCREEN_WID) panels_x++;
3870 cur_wid = panels_x * SCREEN_WID;
3872 /* Assume illegal panel */
3873 panel_row_min = cur_hgt;
3874 panel_col_min = cur_wid;
3876 /* Place player in a quest level */
3877 if (p_ptr->inside_quest)
3881 /* Delete the monster (if any) */
3882 delete_monster(py, px);
3890 /* Place player in the town */
3891 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3893 p_ptr->oldpy = atoi(zz[0]);
3894 p_ptr->oldpx = atoi(zz[1]);
3902 /* Process "B:<Index>:<Command>:..." -- Building definition */
3903 else if (buf[0] == 'B')
3905 return parse_line_building(buf);
3908 /* Process "M:<type>:<maximum>" -- set maximum values */
3909 else if (buf[0] == 'M')
3911 if (tokenize(buf+2, 2, zz, 0) == 2)
3914 if (zz[0][0] == 'T')
3916 max_towns = atoi(zz[1]);
3919 /* Maximum quests */
3920 else if (zz[0][0] == 'Q')
3922 max_quests = atoi(zz[1]);
3926 else if (zz[0][0] == 'R')
3928 max_r_idx = atoi(zz[1]);
3932 else if (zz[0][0] == 'K')
3934 max_k_idx = atoi(zz[1]);
3938 else if (zz[0][0] == 'V')
3940 max_v_idx = atoi(zz[1]);
3944 else if (zz[0][0] == 'F')
3946 max_f_idx = atoi(zz[1]);
3950 else if (zz[0][0] == 'A')
3952 max_a_idx = atoi(zz[1]);
3956 else if (zz[0][0] == 'E')
3958 max_e_idx = atoi(zz[1]);
3962 else if (zz[0][0] == 'D')
3964 max_d_idx = atoi(zz[1]);
3968 else if (zz[0][0] == 'O')
3970 max_o_idx = atoi(zz[1]);
3974 else if (zz[0][0] == 'M')
3976 max_m_idx = atoi(zz[1]);
3979 /* Wilderness size */
3980 else if (zz[0][0] == 'W')
3982 /* Maximum wild_x_size */
3983 if (zz[0][1] == 'X')
3984 max_wild_x = atoi(zz[1]);
3985 /* Maximum wild_y_size */
3986 if (zz[0][1] == 'Y')
3987 max_wild_y = atoi(zz[1]);
4001 static cptr variant = "ZANGBAND";
4005 * Helper function for "process_dungeon_file()"
4007 static cptr process_dungeon_file_expr(char **sp, char *fp)
4023 while (isspace(*s)) s++;
4041 t = process_dungeon_file_expr(&s, &f);
4050 else if (streq(t, "IOR"))
4053 while (*s && (f != b2))
4055 t = process_dungeon_file_expr(&s, &f);
4056 if (*t && !streq(t, "0")) v = "1";
4061 else if (streq(t, "AND"))
4064 while (*s && (f != b2))
4066 t = process_dungeon_file_expr(&s, &f);
4067 if (*t && streq(t, "0")) v = "0";
4072 else if (streq(t, "NOT"))
4075 while (*s && (f != b2))
4077 t = process_dungeon_file_expr(&s, &f);
4078 if (*t && streq(t, "1")) v = "0";
4083 else if (streq(t, "EQU"))
4086 if (*s && (f != b2))
4088 t = process_dungeon_file_expr(&s, &f);
4090 while (*s && (f != b2))
4092 p = process_dungeon_file_expr(&s, &f);
4093 if (streq(t, p)) v = "1";
4098 else if (streq(t, "LEQ"))
4101 if (*s && (f != b2))
4103 t = process_dungeon_file_expr(&s, &f);
4105 while (*s && (f != b2))
4108 t = process_dungeon_file_expr(&s, &f);
4109 if (*t && atoi(p) > atoi(t)) v = "0";
4114 else if (streq(t, "GEQ"))
4117 if (*s && (f != b2))
4119 t = process_dungeon_file_expr(&s, &f);
4121 while (*s && (f != b2))
4124 t = process_dungeon_file_expr(&s, &f);
4126 /* Compare two numbers instead of string */
4127 if (*t && atoi(p) < atoi(t)) v = "0";
4134 while (*s && (f != b2))
4136 t = process_dungeon_file_expr(&s, &f);
4141 if (f != b2) v = "?x?x?";
4143 /* Extract final and Terminate */
4144 if ((f = *s) != '\0') *s++ = '\0';
4150 /* Accept all printables except spaces and brackets */
4151 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4153 /* Extract final and Terminate */
4154 if ((f = *s) != '\0') *s++ = '\0';
4160 if (streq(b+1, "SYS"))
4166 else if (streq(b+1, "GRAF"))
4171 else if (streq(b+1, "MONOCHROME"))
4180 else if (streq(b+1, "RACE"))
4183 v = rp_ptr->E_title;
4190 else if (streq(b+1, "CLASS"))
4193 v = cp_ptr->E_title;
4200 else if (streq(b+1, "REALM1"))
4203 v = E_realm_names[p_ptr->realm1];
4205 v = realm_names[p_ptr->realm1];
4210 else if (streq(b+1, "REALM2"))
4213 v = E_realm_names[p_ptr->realm2];
4215 v = realm_names[p_ptr->realm2];
4220 else if (streq(b+1, "PLAYER"))
4226 else if (streq(b+1, "TOWN"))
4228 sprintf(tmp, "%d", p_ptr->town_num);
4233 else if (streq(b+1, "LEVEL"))
4235 sprintf(tmp, "%d", p_ptr->lev);
4239 /* Current quest number */
4240 else if (streq(b+1, "QUEST_NUMBER"))
4242 sprintf(tmp, "%d", p_ptr->inside_quest);
4246 /* Number of last quest */
4247 else if (streq(b+1, "LEAVING_QUEST"))
4249 sprintf(tmp, "%d", leaving_quest);
4254 else if (prefix(b+1, "QUEST"))
4256 /* "QUEST" uses a special parameter to determine the number of the quest */
4257 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4262 else if (prefix(b+1, "RANDOM"))
4264 /* "RANDOM" uses a special parameter to determine the number of the quest */
4265 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4270 else if (streq(b+1, "VARIANT"))
4276 else if (streq(b+1, "WILDERNESS"))
4279 sprintf(tmp, "NONE");
4281 sprintf(tmp, "LITE");
4283 sprintf(tmp, "NORMAL");
4306 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4316 bool bypass = FALSE;
4318 int x = xmin, y = ymin;
4321 /* Build the filename */
4322 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4325 fp = my_fopen(buf, "r");
4328 if (!fp) return (-1);
4331 /* Process the file */
4332 while (0 == my_fgets(fp, buf, sizeof(buf)))
4338 /* Skip "empty" lines */
4339 if (!buf[0]) continue;
4341 /* Skip "blank" lines */
4342 if (isspace(buf[0])) continue;
4345 if (buf[0] == '#') continue;
4348 /* Process "?:<expr>" */
4349 if ((buf[0] == '?') && (buf[1] == ':'))
4358 /* Parse the expr */
4359 v = process_dungeon_file_expr(&s, &f);
4362 bypass = (streq(v, "0") ? TRUE : FALSE);
4368 /* Apply conditionals */
4369 if (bypass) continue;
4371 /* Process the line */
4372 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4384 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4387 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4389 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4391 msg_format("Parsing '%s'.", buf);
4398 /* Close the file */
4408 void write_r_info_txt(void)
4410 int i, j, z, fc, bc;
4413 cptr flags[32 * 10];
4418 monster_race *r_ptr;
4420 monster_blow *b_ptr;
4422 FILE *fff = fopen("output.txt", "wt");
4430 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4432 fprintf(fff, "# Version stamp (required)\n\n");
4435 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4438 fprintf(fff, "##### The Player #####\n\n");
4440 for (z = -1; z < alloc_race_size; z++)
4442 /* Output the monsters in order */
4443 i = (z >= 0) ? alloc_race_table[z].index : 0;
4445 /* Acquire the monster */
4448 /* Ignore empty monsters */
4449 if (!strlen(r_name + r_ptr->name)) continue;
4451 /* Ignore useless monsters */
4452 if (i && !r_ptr->speed) continue;
4454 /* Write a note if necessary */
4455 if (i && (!r_ptr->level != !mode))
4460 fprintf(fff, "\n##### Town monsters #####\n\n");
4462 /* Note the dungeon */
4465 fprintf(fff, "\n##### Normal monsters #####\n\n");
4468 /* Record the change */
4469 mode = r_ptr->level;
4472 /* Acquire the flags */
4473 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4474 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4475 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4476 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4477 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4478 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4479 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4480 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4481 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4482 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4484 /* Write New/Number/Name */
4485 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4488 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4490 /* Write Information */
4491 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4492 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4494 /* Write more information */
4495 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4498 for(j = 0; j < 4; j++)
4500 b_ptr = &(r_ptr->blow[j]);
4502 /* Stop when done */
4503 if (!b_ptr->method) break;
4505 /* Write the blows */
4506 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4507 r_info_blow_effect[b_ptr->effect],
4508 b_ptr->d_dice, b_ptr->d_side);
4511 /* Extract the flags */
4512 for (fc = 0, j = 0; j < 32 * 3; j++)
4514 /* Check this flag */
4515 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4518 /* Extract the extra flags */
4519 for (j = 32 * 6; j < 32 * 10; j++)
4521 /* Check this flag */
4522 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4525 /* Write the flags */
4526 for (j = 0; j < fc;)
4530 /* Start the line */
4533 for (bc = 0; (bc < 60) && (j < fc); j++)
4537 /* Format the flag */
4538 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4540 /* Add it to the buffer */
4543 /* Note the length */
4547 /* Done with this line; write it */
4548 fprintf(fff, "%s\n", buf);
4551 /* Write Spells if applicable */
4552 if (r_ptr->freq_spell)
4554 /* Write the frequency */
4555 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4557 /* Extract the spell flags */
4558 for (fc = 0, j = 96; j < 192; j++)
4560 /* Check this flag */
4561 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4564 /* Write the flags */
4565 for (j = 0; j < fc;)
4569 /* Start the line */
4572 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4576 /* Format the flag */
4577 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4581 /* Note the length */
4588 /* Done with this line; write it */
4589 fprintf(fff, "%s\n", buf);
4593 /* Acquire the description */
4594 desc = r_text + r_ptr->text;
4595 dlen = strlen(desc);
4597 /* Write Description */
4598 for (j = 0; j < dlen;)
4602 /* Start the line */
4605 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4613 /* Done with this line; write it */
4614 fprintf(fff, "%s\n", buf);
4617 /* Space between entries */