4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 1) -BEN- */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
33 * in this file is compiled out, and the game will not run unless valid
34 * "binary template files" already exist in "lib/data". Thus, one can
35 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
36 * "*.raw" files in "lib/data", and then quit, and recompile without
37 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
38 * from changing the ascii template files in potentially dangerous ways.
40 * The code could actually be removed and placed into a "stand-alone"
41 * program, but that feels a little silly, especially considering some
42 * of the platforms that we currently support.
45 #ifdef ALLOW_TEMPLATES
50 /*** Helper arrays for parsing ascii template files ***/
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * Monster Blow Effects
90 static cptr r_info_blow_effect[] =
133 static cptr f_info_flags[] =
257 static cptr r_info_flags1[] =
296 static cptr r_info_flags2[] =
335 static cptr r_info_flags3[] =
374 static cptr r_info_flags4[] =
413 static cptr r_info_flags5[] =
452 static cptr r_info_flags6[] =
469 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
492 static cptr r_info_flags7[] =
531 static cptr r_info_flags8[] =
563 "WILD_SWAMP", /* ToDo: Implement Swamp */
569 * Monster race flags - Drops
571 static cptr r_info_flags9[] =
610 * Monster race flags - Resistances
612 static cptr r_info_flagsr[] =
652 static cptr k_info_flags[] =
778 static cptr k_info_gen_flags[] =
818 static cptr d_info_flags1[] =
856 * Add a text to the text-storage and store offset to it.
858 * Returns FALSE when there isn't enough space available to store
861 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
863 /* Hack -- Verify space */
864 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
870 /* Advance and save the text index */
871 *offset = ++head->text_size;
874 /* Additional text */
875 else if (normal_text)
878 * If neither the end of the last line nor
879 * the beginning of current line is not a space,
880 * fill up a space as a correct separator of two words.
882 if (head->text_size > 0 &&
884 (*(head->text_ptr + head->text_size - 1) != ' ') &&
885 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
886 (buf[0] != ' ') && !iskanji(buf[0])
888 (*(head->text_ptr + head->text_size - 1) != ' ') &&
894 *(head->text_ptr + head->text_size) = ' ';
896 /* Advance the index */
901 /* Append chars to the text */
902 strcpy(head->text_ptr + head->text_size, buf);
904 /* Advance the index */
905 head->text_size += strlen(buf);
913 * Add a name to the name-storage and return an offset to it.
915 * Returns FALSE when there isn't enough space available to store
918 static bool add_name(u32b *offset, header *head, cptr buf)
920 /* Hack -- Verify space */
921 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
927 /* Advance and save the name index */
928 *offset = ++head->name_size;
931 /* Append chars to the names */
932 strcpy(head->name_ptr + head->name_size, buf);
934 /* Advance the index */
935 head->name_size += strlen(buf);
943 * Add a tag to the tag-storage and return an offset to it.
945 * Returns FALSE when there isn't enough space available to store
948 static bool add_tag(s16b *offset, header *head, cptr buf)
952 /* Search for an existing (fake) tag */
953 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
956 if (streq(&head->tag_ptr[i], buf)) break;
959 /* There was no existing tag */
960 if (i >= head->tag_size)
962 /* Hack -- Verify space */
963 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
966 /* Append chars to the tags */
967 strcpy(head->tag_ptr + head->tag_size, buf);
969 /* Point the new tag */
972 /* Advance the index */
973 head->tag_size += strlen(buf) + 1;
976 /* Return offset of the tag */
985 * Convert a "color letter" into an "actual" color
986 * The colors are: dwsorgbuDWvyRGBU, as shown below
988 byte color_char_to_attr(char c)
992 case 'd': return (TERM_DARK);
993 case 'w': return (TERM_WHITE);
994 case 's': return (TERM_SLATE);
995 case 'o': return (TERM_ORANGE);
996 case 'r': return (TERM_RED);
997 case 'g': return (TERM_GREEN);
998 case 'b': return (TERM_BLUE);
999 case 'u': return (TERM_UMBER);
1001 case 'D': return (TERM_L_DARK);
1002 case 'W': return (TERM_L_WHITE);
1003 case 'v': return (TERM_VIOLET);
1004 case 'y': return (TERM_YELLOW);
1005 case 'R': return (TERM_L_RED);
1006 case 'G': return (TERM_L_GREEN);
1007 case 'B': return (TERM_L_BLUE);
1008 case 'U': return (TERM_L_UMBER);
1016 /*** Initialize from ascii template files ***/
1020 * Initialize an "*_info" array, by parsing an ascii "template" file
1022 errr init_info_txt(FILE *fp, char *buf, header *head,
1023 parse_info_txt_func parse_info_txt_line)
1027 /* Just before the first record */
1030 /* Just before the first line */
1034 /* Prepare the "fake" stuff */
1035 head->name_size = 0;
1036 head->text_size = 0;
1040 while (0 == my_fgets(fp, buf, 1024))
1042 /* Advance the line number */
1045 /* Skip comments and blank lines */
1046 if (!buf[0] || (buf[0] == '#')) continue;
1048 /* Verify correct "colon" format */
1049 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1052 /* Hack -- Process 'V' for "Version" */
1059 /* Mega Hack -- Calculate Check Sum */
1060 if (buf[0] != 'N' && buf[0] != 'D')
1063 for (i = 0; buf[i]; i++)
1065 head->v_extra += (byte)buf[i];
1066 head->v_extra ^= (1 << (i % 8));
1070 /* Parse the line */
1071 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1076 /* Complete the "name" and "text" sizes */
1077 if (head->name_size) head->name_size++;
1078 if (head->text_size) head->text_size++;
1086 * Initialize the "v_info" array, by parsing an ascii "template" file
1088 errr parse_v_info(char *buf, header *head)
1094 static vault_type *v_ptr = NULL;
1096 /* Process 'N' for "New/Number/Name" */
1099 /* Find the colon before the name */
1100 s = my_strchr(buf+2, ':');
1102 /* Verify that colon */
1105 /* Nuke the colon, advance to the name */
1108 /* Paranoia -- require a name */
1109 if (!*s) return (1);
1114 /* Verify information */
1115 if (i <= error_idx) return (4);
1117 /* Verify information */
1118 if (i >= head->info_num) return (2);
1120 /* Save the index */
1123 /* Point at the "info" */
1126 /* Store the name */
1127 if (!add_name(&v_ptr->name, head, s)) return (7);
1130 /* There better be a current v_ptr */
1131 else if (!v_ptr) return (3);
1133 /* Process 'D' for "Description" */
1134 else if (buf[0] == 'D')
1136 /* Acquire the text */
1139 /* Store the text */
1140 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1143 /* Process 'X' for "Extra info" (one line only) */
1144 else if (buf[0] == 'X')
1146 int typ, rat, hgt, wid;
1148 /* Scan for the values */
1149 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1150 &typ, &rat, &hgt, &wid)) return (1);
1152 /* Save the values */
1169 * Initialize the "s_info" array, by parsing an ascii "template" file
1171 errr parse_s_info(char *buf, header *head)
1176 static skill_table *s_ptr = NULL;
1179 /* Process 'N' for "New/Number/Name" */
1185 /* Verify information */
1186 if (i <= error_idx) return (4);
1188 /* Verify information */
1189 if (i >= head->info_num) return (2);
1191 /* Save the index */
1194 /* Point at the "info" */
1198 /* There better be a current s_ptr */
1199 else if (!s_ptr) return (3);
1201 /* Process 'W' for "Weapon exp" */
1202 else if (buf[0] == 'W')
1204 int tval, sval, start, max;
1205 const s16b exp_conv_table[] =
1207 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1208 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1211 /* Scan for the values */
1212 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1213 &tval, &sval, &start, &max)) return (1);
1215 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1216 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1218 /* Save the values */
1219 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1220 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1223 /* Process 'S' for "Skill exp" */
1224 else if (buf[0] == 'S')
1226 int num, start, max;
1228 /* Scan for the values */
1229 if (3 != sscanf(buf+2, "%d:%d:%d",
1230 &num, &start, &max)) return (1);
1232 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1233 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1235 /* Save the values */
1236 s_ptr->s_start[num] = start;
1237 s_ptr->s_max[num] = max;
1250 * Initialize the "m_info" array, by parsing an ascii "template" file
1252 errr parse_m_info(char *buf, header *head)
1259 static player_magic *m_ptr = NULL;
1262 static int realm, magic_idx = 0, readable = 0;
1265 /* Process 'N' for "New/Number/Name" */
1271 /* Verify information */
1272 if (i <= error_idx) return (4);
1274 /* Verify information */
1275 if (i >= head->info_num) return (2);
1277 /* Save the index */
1280 /* Point at the "info" */
1284 /* There better be a current m_ptr */
1285 else if (!m_ptr) return (3);
1287 /* Process 'I' for "Info" (one line only) */
1288 else if (buf[0] == 'I')
1291 int xtra, type, first, weight;
1293 /* Find the colon before the name */
1294 s = my_strchr(buf+2, ':');
1296 /* Verify that colon */
1299 /* Nuke the colon, advance to the name */
1304 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1305 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1306 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1307 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1308 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1313 /* Find the colon before the name */
1314 s = my_strchr(s, ':');
1316 /* Verify that colon */
1319 /* Nuke the colon, advance to the name */
1322 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1323 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1324 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1325 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1326 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1327 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1331 /* Scan for the values */
1332 if (4 != sscanf(s, "%x:%d:%d:%d",
1333 (uint *)&xtra, &type, &first, &weight)) return (1);
1335 m_ptr->spell_xtra = xtra;
1336 m_ptr->spell_type = type;
1337 m_ptr->spell_first = first;
1338 m_ptr->spell_weight = weight;
1342 /* Process 'R' for "Realm" (one line only) */
1343 else if (buf[0] == 'R')
1345 /* Scan for the values */
1346 if (2 != sscanf(buf+2, "%d:%d",
1347 &realm, &readable)) return (1);
1352 else if (buf[0] == 'T')
1354 int level, mana, fail, exp;
1356 if (!readable) return (1);
1357 /* Scan for the values */
1358 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1359 &level, &mana, &fail, &exp)) return (1);
1361 m_ptr->info[realm][magic_idx].slevel = level;
1362 m_ptr->info[realm][magic_idx].smana = mana;
1363 m_ptr->info[realm][magic_idx].sfail = fail;
1364 m_ptr->info[realm][magic_idx].sexp = exp;
1378 * Grab one flag from a textual string
1380 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1385 for (i = 0; i < 32; i++)
1387 if (streq(what, names[i]))
1389 *flags |= (1L << i);
1399 * Grab one flag in an feature_type from a textual string
1401 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1406 for (i = 0; i < FF_FLAG_MAX; i++)
1408 if (streq(what, f_info_flags[i]))
1410 add_flag(f_ptr->flags, i);
1417 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1419 msg_format("Unknown feature flag '%s'.", what);
1423 return PARSE_ERROR_GENERIC;
1428 * Grab an action in an feature_type from a textual string
1430 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1435 for (i = 0; i < FF_FLAG_MAX; i++)
1437 if (streq(what, f_info_flags[i]))
1439 f_ptr->state[count].action = i;
1446 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1448 msg_format("Unknown feature action '%s'.", what);
1452 return PARSE_ERROR_GENERIC;
1457 * Initialize the "f_info" array, by parsing an ascii "template" file
1459 errr parse_f_info(char *buf, header *head)
1466 static feature_type *f_ptr = NULL;
1469 /* Process 'N' for "New/Number/Name" */
1472 /* Find the colon before the name */
1473 s = my_strchr(buf+2, ':');
1477 /* Nuke the colon, advance to the name */
1484 /* Verify information */
1485 if (i <= error_idx) return (4);
1487 /* Verify information */
1488 if (i >= head->info_num) return (2);
1490 /* Save the index */
1493 /* Point at the "info" */
1496 /* Tag name is given */
1500 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1503 /* Default "mimic" */
1506 /* Default "destroyed state" -- if not specified */
1507 f_ptr->destroyed = i;
1509 /* Default "states" */
1510 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1513 /* There better be a current f_ptr */
1514 else if (!f_ptr) return (3);
1517 else if (buf[0] == 'J')
1519 /* Store the name */
1520 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1523 else if (buf[0] == 'E')
1525 /* Ignore english name */
1528 else if (buf[0] == 'J')
1530 /* Ignore Japanese name */
1533 else if (buf[0] == 'E')
1535 /* Acquire the Text */
1538 /* Store the name */
1539 if (!add_name(&f_ptr->name, head, s)) return (7);
1544 /* Process 'M' for "Mimic" (one line only) */
1545 else if (buf[0] == 'M')
1549 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1551 /* Record a fake tag index */
1552 f_ptr->mimic = -offset;
1556 /* Process 'G' for "Graphics" (one line only) */
1557 else if (buf[0] == 'G')
1561 char char_tmp[F_LIT_MAX];
1564 if (buf[1] != ':') return (1);
1565 if (!buf[2]) return (1);
1566 if (buf[3] != ':') return (1);
1567 if (!buf[4]) return (1);
1569 /* Extract the char */
1570 char_tmp[F_LIT_STANDARD] = buf[2];
1572 /* Extract the color */
1573 s_attr = color_char_to_attr(buf[4]);
1576 if (s_attr > 127) return (1);
1578 /* Save the standard values */
1579 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1580 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1582 /* Is this feature supports lighting? */
1585 /* G:c:a:LIT (default) */
1586 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1588 /* G:c:a:lc:la:dc:da */
1589 if (!streq(buf + 6, "LIT"))
1591 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1593 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1594 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1595 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1596 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1598 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1600 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1603 /* Use default lighting */
1606 /* No lighting support */
1607 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1610 /* Extract the color */
1611 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1612 if (f_ptr->d_attr[j] > 127) return 1;
1615 f_ptr->d_char[j] = char_tmp[j];
1621 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1623 f_ptr->d_attr[j] = s_attr;
1624 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1630 /* Hack -- Process 'F' for flags */
1631 else if (buf[0] == 'F')
1633 /* Parse every entry textually */
1634 for (s = buf + 2; *s; )
1636 /* Find the end of this entry */
1637 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1639 /* Nuke and skip any dividers */
1643 while (*t == ' ' || *t == '|') t++;
1646 /* XXX XXX XXX Hack -- Read feature subtype */
1647 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1649 /* Extract a "subtype" */
1652 /* Start at next entry */
1659 /* XXX XXX XXX Hack -- Read feature power */
1660 if (1 == sscanf(s, "POWER_%d", &i))
1662 /* Extract a "power" */
1665 /* Start at next entry */
1672 /* Parse this entry */
1673 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1675 /* Start the next entry */
1680 /* Process 'W' for "More Info" (one line only) */
1681 else if (buf[0] == 'W')
1685 /* Scan for the value */
1686 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1688 /* Save the value */
1689 f_ptr->priority = priority;
1692 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1693 else if (buf[0] == 'K')
1697 /* Find the next empty state slot (if any) */
1698 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1700 /* Oops, no more slots */
1701 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1703 /* Analyze the first field */
1704 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1706 /* Terminate the field (if necessary) */
1707 if (*t == ':') *t++ = '\0';
1709 /* Is this default entry? */
1710 if (streq(s, "DESTROYED"))
1712 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1714 /* Record a fake tag index */
1715 f_ptr->destroyed = -offset;
1720 f_ptr->state[i].action = 0;
1722 /* Parse this entry */
1723 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1725 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1727 /* Record a fake tag index */
1728 f_ptr->state[i].result = -offset;
1741 * Convert a fake tag to a real feat index
1743 s16b f_tag_to_index(cptr str)
1747 /* Search for real index corresponding to this fake tag */
1748 for (i = 0; i < f_head.info_num; i++)
1750 if (streq(f_tag + f_info[i].tag, str))
1752 /* Return the index */
1763 * Search for real index corresponding to this fake tag
1765 static void search_real_feat(s16b *feat)
1769 /* Don't convert non-fake tag */
1770 if (*feat >= 0) return;
1772 /* Search for real index corresponding to this fake tag */
1773 for (i = 0; i < f_head.info_num; i++)
1775 if ((-(*feat)) == f_info[i].tag)
1777 /* Record real index */
1785 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1787 msg_format("%s is undefined.", f_tag + (-(*feat)));
1793 * Retouch fake tags of f_info
1795 void retouch_f_info(header *head)
1799 /* Convert fake tags to real feat indices */
1800 for (i = 0; i < head->info_num; i++)
1802 feature_type *f_ptr = &f_info[i];
1805 search_real_feat(&f_ptr->mimic);
1807 search_real_feat(&f_ptr->destroyed);
1809 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1815 * Grab one flag in an object_kind from a textual string
1817 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1822 for (i = 0; i < TR_FLAG_MAX; i++)
1824 if (streq(what, k_info_flags[i]))
1826 add_flag(k_ptr->flags, i);
1831 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1836 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1838 msg_format("Unknown object flag '%s'.", what);
1848 * Initialize the "k_info" array, by parsing an ascii "template" file
1850 errr parse_k_info(char *buf, header *head)
1857 static object_kind *k_ptr = NULL;
1860 /* Process 'N' for "New/Number/Name" */
1867 /* Find the colon before the name */
1868 s = my_strchr(buf+2, ':');
1870 /* Verify that colon */
1873 /* Nuke the colon, advance to the name */
1879 /* Verify information */
1880 if (i <= error_idx) return (4);
1882 /* Verify information */
1883 if (i >= head->info_num) return (2);
1885 /* Save the index */
1888 /* Point at the "info" */
1892 /* Paranoia -- require a name */
1893 if (!*s) return (1);
1895 /* Find the colon before the flavor */
1896 flavor = my_strchr(s, ':');
1898 /* Verify that colon */
1901 /* Nuke the colon, advance to the flavor */
1904 /* Store the flavor */
1905 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1908 /* Store the name */
1909 if (!add_name(&k_ptr->name, head, s)) return (7);
1913 /* There better be a current k_ptr */
1914 else if (!k_ptr) return (3);
1918 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1919 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1920 else if (buf[0] == 'E')
1925 else if (buf[0] == 'E')
1929 /* Acquire the name */
1932 /* Find the colon before the flavor */
1933 flavor = my_strchr(s, ':');
1935 /* Verify that colon */
1938 /* Nuke the colon, advance to the flavor */
1941 /* Store the flavor */
1942 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1945 /* Store the name */
1946 if (!add_name(&k_ptr->name, head, s)) return (7);
1950 /* Process 'D' for "Description" */
1951 else if (buf[0] == 'D')
1956 /* Acquire the text */
1961 /* Acquire the text */
1965 /* Store the text */
1966 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
1969 /* Process 'G' for "Graphics" (one line only) */
1970 else if (buf[0] == 'G')
1976 if (buf[1] != ':') return (1);
1977 if (!buf[2]) return (1);
1978 if (buf[3] != ':') return (1);
1979 if (!buf[4]) return (1);
1981 /* Extract the char */
1984 /* Extract the attr */
1985 tmp = color_char_to_attr(buf[4]);
1988 if (tmp > 127) return (1);
1990 /* Save the values */
1991 k_ptr->d_attr = tmp;
1992 k_ptr->d_char = sym;
1995 /* Process 'I' for "Info" (one line only) */
1996 else if (buf[0] == 'I')
1998 int tval, sval, pval;
2000 /* Scan for the values */
2001 if (3 != sscanf(buf+2, "%d:%d:%d",
2002 &tval, &sval, &pval)) return (1);
2004 /* Save the values */
2010 /* Process 'W' for "More Info" (one line only) */
2011 else if (buf[0] == 'W')
2013 int level, extra, wgt;
2016 /* Scan for the values */
2017 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2018 &level, &extra, &wgt, &cost)) return (1);
2020 /* Save the values */
2021 k_ptr->level = level;
2022 k_ptr->extra = extra;
2023 k_ptr->weight = wgt;
2027 /* Process 'A' for "Allocation" (one line only) */
2028 else if (buf[0] == 'A')
2032 /* XXX XXX XXX Simply read each number following a colon */
2033 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2035 /* Default chance */
2036 k_ptr->chance[i] = 1;
2038 /* Store the attack damage index */
2039 k_ptr->locale[i] = atoi(s+1);
2041 /* Find the slash */
2042 t = my_strchr(s+1, '/');
2044 /* Find the next colon */
2045 s = my_strchr(s+1, ':');
2047 /* If the slash is "nearby", use it */
2048 if (t && (!s || t < s))
2050 int chance = atoi(t+1);
2051 if (chance > 0) k_ptr->chance[i] = chance;
2056 /* Hack -- Process 'P' for "power" and such */
2057 else if (buf[0] == 'P')
2059 int ac, hd1, hd2, th, td, ta;
2061 /* Scan for the values */
2062 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2063 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2073 /* Hack -- Process 'F' for flags */
2074 else if (buf[0] == 'F')
2076 /* Parse every entry textually */
2077 for (s = buf + 2; *s; )
2079 /* Find the end of this entry */
2080 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2082 /* Nuke and skip any dividers */
2086 while (*t == ' ' || *t == '|') t++;
2089 /* Parse this entry */
2090 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2092 /* Start the next entry */
2108 * Grab one flag in an artifact_type from a textual string
2110 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2115 for (i = 0; i < TR_FLAG_MAX; i++)
2117 if (streq(what, k_info_flags[i]))
2119 add_flag(a_ptr->flags, i);
2124 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2129 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2131 msg_format("Unknown artifact flag '%s'.", what);
2143 * Initialize the "a_info" array, by parsing an ascii "template" file
2145 errr parse_a_info(char *buf, header *head)
2152 static artifact_type *a_ptr = NULL;
2155 /* Process 'N' for "New/Number/Name" */
2158 /* Find the colon before the name */
2159 s = my_strchr(buf+2, ':');
2161 /* Verify that colon */
2164 /* Nuke the colon, advance to the name */
2167 /* Paranoia -- require a name */
2168 if (!*s) return (1);
2173 /* Verify information */
2174 if (i < error_idx) return (4);
2176 /* Verify information */
2177 if (i >= head->info_num) return (2);
2179 /* Save the index */
2182 /* Point at the "info" */
2185 /* Ignore everything */
2186 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2187 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2188 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2189 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2191 /* Store the name */
2192 if (!add_name(&a_ptr->name, head, s)) return (7);
2196 /* There better be a current a_ptr */
2197 else if (!a_ptr) return (3);
2201 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2202 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2203 else if (buf[0] == 'E')
2208 else if (buf[0] == 'E')
2210 /* Acquire the Text */
2213 /* Store the name */
2214 if (!add_name(&a_ptr->name, head, s)) return (7);
2218 /* Process 'D' for "Description" */
2219 else if (buf[0] == 'D')
2224 /* Acquire the text */
2229 /* Acquire the text */
2233 /* Store the text */
2234 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2238 /* Process 'I' for "Info" (one line only) */
2239 else if (buf[0] == 'I')
2241 int tval, sval, pval;
2243 /* Scan for the values */
2244 if (3 != sscanf(buf+2, "%d:%d:%d",
2245 &tval, &sval, &pval)) return (1);
2247 /* Save the values */
2253 /* Process 'W' for "More Info" (one line only) */
2254 else if (buf[0] == 'W')
2256 int level, rarity, wgt;
2259 /* Scan for the values */
2260 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2261 &level, &rarity, &wgt, &cost)) return (1);
2263 /* Save the values */
2264 a_ptr->level = level;
2265 a_ptr->rarity = rarity;
2266 a_ptr->weight = wgt;
2270 /* Hack -- Process 'P' for "power" and such */
2271 else if (buf[0] == 'P')
2273 int ac, hd1, hd2, th, td, ta;
2275 /* Scan for the values */
2276 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2277 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2287 /* Hack -- Process 'F' for flags */
2288 else if (buf[0] == 'F')
2290 /* Parse every entry textually */
2291 for (s = buf + 2; *s; )
2293 /* Find the end of this entry */
2294 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2296 /* Nuke and skip any dividers */
2300 while ((*t == ' ') || (*t == '|')) t++;
2303 /* Parse this entry */
2304 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2306 /* Start the next entry */
2322 * Grab one flag in a ego-item_type from a textual string
2324 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2329 for (i = 0; i < TR_FLAG_MAX; i++)
2331 if (streq(what, k_info_flags[i]))
2333 add_flag(e_ptr->flags, i);
2338 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2343 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2345 msg_format("Unknown ego-item flag '%s'.", what);
2357 * Initialize the "e_info" array, by parsing an ascii "template" file
2359 errr parse_e_info(char *buf, header *head)
2366 static ego_item_type *e_ptr = NULL;
2369 /* Just before the first record */
2372 /* Just before the first line */
2376 /* Process 'N' for "New/Number/Name" */
2379 /* Find the colon before the name */
2380 s = my_strchr(buf+2, ':');
2382 /* Verify that colon */
2385 /* Nuke the colon, advance to the name */
2388 /* Paranoia -- require a name */
2389 if (!*s) return (1);
2394 /* Verify information */
2395 if (i < error_idx) return (4);
2397 /* Verify information */
2398 if (i >= head->info_num) return (2);
2400 /* Save the index */
2403 /* Point at the "info" */
2406 /* Store the name */
2407 if (!add_name(&e_ptr->name, head, s)) return (7);
2411 /* There better be a current e_ptr */
2412 else if (!e_ptr) return (3);
2416 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2417 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2418 else if (buf[0] == 'E')
2423 else if (buf[0] == 'E')
2425 /* Acquire the Text */
2428 /* Store the name */
2429 if (!add_name(&e_ptr->name, head, s)) return (7);
2434 /* Process 'D' for "Description" */
2435 else if (buf[0] == 'D')
2437 /* Acquire the text */
2440 /* Store the text */
2441 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2446 /* Process 'X' for "Xtra" (one line only) */
2447 else if (buf[0] == 'X')
2451 /* Scan for the values */
2452 if (2 != sscanf(buf+2, "%d:%d",
2453 &slot, &rating)) return (1);
2455 /* Save the values */
2457 e_ptr->rating = rating;
2460 /* Process 'W' for "More Info" (one line only) */
2461 else if (buf[0] == 'W')
2463 int level, rarity, pad2;
2466 /* Scan for the values */
2467 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2468 &level, &rarity, &pad2, &cost)) return (1);
2470 /* Save the values */
2471 e_ptr->level = level;
2472 e_ptr->rarity = rarity;
2473 /* e_ptr->weight = wgt; */
2477 /* Hack -- Process 'C' for "creation" */
2478 else if (buf[0] == 'C')
2482 /* Scan for the values */
2483 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2484 &th, &td, &ta, &pv)) return (1);
2486 e_ptr->max_to_h = th;
2487 e_ptr->max_to_d = td;
2488 e_ptr->max_to_a = ta;
2489 e_ptr->max_pval = pv;
2492 /* Hack -- Process 'F' for flags */
2493 else if (buf[0] == 'F')
2495 /* Parse every entry textually */
2496 for (s = buf + 2; *s; )
2498 /* Find the end of this entry */
2499 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2501 /* Nuke and skip any dividers */
2505 while ((*t == ' ') || (*t == '|')) t++;
2508 /* Parse this entry */
2509 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2511 /* Start the next entry */
2525 * Grab one (basic) flag in a monster_race from a textual string
2527 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2529 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2532 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2535 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2538 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2541 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2544 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2547 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2552 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2554 msg_format("Unknown monster flag '%s'.", what);
2564 * Grab one (spell) flag in a monster_race from a textual string
2566 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2568 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2571 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2574 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2579 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2581 msg_format("Unknown monster flag '%s'.", what);
2593 * Initialize the "r_info" array, by parsing an ascii "template" file
2595 errr parse_r_info(char *buf, header *head)
2602 static monster_race *r_ptr = NULL;
2605 /* Process 'N' for "New/Number/Name" */
2608 /* Find the colon before the name */
2609 s = my_strchr(buf+2, ':');
2611 /* Verify that colon */
2614 /* Nuke the colon, advance to the name */
2617 /* Paranoia -- require a name */
2618 if (!*s) return (1);
2623 /* Verify information */
2624 if (i < error_idx) return (4);
2626 /* Verify information */
2627 if (i >= head->info_num) return (2);
2629 /* Save the index */
2632 /* Point at the "info" */
2635 /* Store the name */
2636 if (!add_name(&r_ptr->name, head, s)) return (7);
2640 /* There better be a current r_ptr */
2641 else if (!r_ptr) return (3);
2645 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2646 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2647 else if (buf[0] == 'E')
2649 /* Acquire the Text */
2652 /* Store the name */
2653 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2656 else if (buf[0] == 'E')
2658 /* Acquire the Text */
2661 /* Store the name */
2662 if (!add_name(&r_ptr->name, head, s)) return (7);
2665 /* Process 'D' for "Description" */
2666 else if (buf[0] == 'D')
2671 /* Acquire the text */
2676 /* Acquire the text */
2680 /* Store the text */
2681 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2684 /* Process 'G' for "Graphics" (one line only) */
2685 else if (buf[0] == 'G')
2691 if (buf[1] != ':') return (1);
2692 if (!buf[2]) return (1);
2693 if (buf[3] != ':') return (1);
2694 if (!buf[4]) return (1);
2696 /* Extract the char */
2699 /* Extract the attr */
2700 tmp = color_char_to_attr(buf[4]);
2703 if (tmp > 127) return (1);
2705 /* Save the values */
2706 r_ptr->d_char = sym;
2707 r_ptr->d_attr = tmp;
2710 /* Process 'I' for "Info" (one line only) */
2711 else if (buf[0] == 'I')
2713 int spd, hp1, hp2, aaf, ac, slp;
2715 /* Scan for the other values */
2716 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2717 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2719 /* Save the values */
2721 r_ptr->hdice = MAX(hp1, 1);
2722 r_ptr->hside = MAX(hp2, 1);
2728 /* Process 'W' for "More Info" (one line only) */
2729 else if (buf[0] == 'W')
2736 /* Scan for the values */
2737 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2738 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2740 /* Save the values */
2742 r_ptr->rarity = rar;
2745 r_ptr->next_exp = nextexp;
2746 r_ptr->next_r_idx = nextmon;
2749 /* Process 'B' for "Blows" (up to four lines) */
2750 else if (buf[0] == 'B')
2754 /* Find the next empty blow slot (if any) */
2755 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2757 /* Oops, no more slots */
2758 if (i == 4) return (1);
2760 /* Analyze the first field */
2761 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2763 /* Terminate the field (if necessary) */
2764 if (*t == ':') *t++ = '\0';
2766 /* Analyze the method */
2767 for (n1 = 0; r_info_blow_method[n1]; n1++)
2769 if (streq(s, r_info_blow_method[n1])) break;
2772 /* Invalid method */
2773 if (!r_info_blow_method[n1]) return (1);
2775 /* Analyze the second field */
2776 for (s = t; *t && (*t != ':'); t++) /* loop */;
2778 /* Terminate the field (if necessary) */
2779 if (*t == ':') *t++ = '\0';
2781 /* Analyze effect */
2782 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2784 if (streq(s, r_info_blow_effect[n2])) break;
2787 /* Invalid effect */
2788 if (!r_info_blow_effect[n2]) return (1);
2790 /* Analyze the third field */
2791 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2793 /* Terminate the field (if necessary) */
2794 if (*t == 'd') *t++ = '\0';
2796 /* Save the method */
2797 r_ptr->blow[i].method = n1;
2799 /* Save the effect */
2800 r_ptr->blow[i].effect = n2;
2802 /* Extract the damage dice and sides */
2803 r_ptr->blow[i].d_dice = atoi(s);
2804 r_ptr->blow[i].d_side = atoi(t);
2807 /* Process 'F' for "Basic Flags" (multiple lines) */
2808 else if (buf[0] == 'F')
2810 /* Parse every entry */
2811 for (s = buf + 2; *s; )
2813 /* Find the end of this entry */
2814 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2816 /* Nuke and skip any dividers */
2820 while (*t == ' ' || *t == '|') t++;
2823 /* Parse this entry */
2824 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2826 /* Start the next entry */
2831 /* Process 'S' for "Spell Flags" (multiple lines) */
2832 else if (buf[0] == 'S')
2834 /* Parse every entry */
2835 for (s = buf + 2; *s; )
2837 /* Find the end of this entry */
2838 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2840 /* Nuke and skip any dividers */
2844 while ((*t == ' ') || (*t == '|')) t++;
2847 /* XXX XXX XXX Hack -- Read spell frequency */
2848 if (1 == sscanf(s, "1_IN_%d", &i))
2850 /* Extract a "frequency" */
2851 r_ptr->freq_spell = 100 / i;
2853 /* Start at next entry */
2860 /* Parse this entry */
2861 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2863 /* Start the next entry */
2878 * Grab one flag for a dungeon type from a textual string
2880 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2882 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2887 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2889 msg_format("Unknown dungeon type flag '%s'.", what);
2897 * Grab one (basic) flag in a monster_race from a textual string
2899 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2901 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2904 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2907 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2910 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2913 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2916 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2919 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2924 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2926 msg_format("Unknown monster flag '%s'.", what);
2934 * Grab one (spell) flag in a monster_race from a textual string
2936 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2938 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2941 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
2944 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
2949 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2951 msg_format("Unknown monster flag '%s'.", what);
2959 * Initialize the "d_info" array, by parsing an ascii "template" file
2961 errr parse_d_info(char *buf, header *head)
2968 static dungeon_info_type *d_ptr = NULL;
2971 /* Process 'N' for "New/Number/Name" */
2974 /* Find the colon before the name */
2975 s = my_strchr(buf+2, ':');
2977 /* Verify that colon */
2980 /* Nuke the colon, advance to the name */
2983 /* Paranoia -- require a name */
2984 if (!*s) return (1);
2989 /* Verify information */
2990 if (i < error_idx) return (4);
2992 /* Verify information */
2993 if (i >= head->info_num) return (2);
2995 /* Save the index */
2998 /* Point at the "info" */
3001 /* Store the name */
3002 if (!add_name(&d_ptr->name, head, s)) return (7);
3007 else if (buf[0] == 'E') return (0);
3009 else if (buf[0] == 'E')
3011 /* Acquire the Text */
3014 /* Store the name */
3015 if (!add_name(&d_ptr->name, head, s)) return (7);
3019 /* Process 'D' for "Description */
3020 else if (buf[0] == 'D')
3025 /* Acquire the text */
3030 /* Acquire the text */
3034 /* Store the text */
3035 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3038 /* Process 'W' for "More Info" (one line only) */
3039 else if (buf[0] == 'W')
3041 int min_lev, max_lev;
3043 int min_alloc, max_chance;
3044 int obj_good, obj_great;
3047 /* Scan for the values */
3048 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3049 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3051 /* Save the values */
3052 d_ptr->mindepth = min_lev;
3053 d_ptr->maxdepth = max_lev;
3054 d_ptr->min_plev = min_plev;
3056 d_ptr->min_m_alloc_level = min_alloc;
3057 d_ptr->max_m_alloc_chance = max_chance;
3058 d_ptr->obj_good = obj_good;
3059 d_ptr->obj_great = obj_great;
3064 /* Process 'P' for "Place Info" */
3065 else if (buf[0] == 'P')
3069 /* Scan for the values */
3070 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3072 /* Save the values */
3077 /* Process 'L' for "fLoor type" (one line only) */
3078 else if (buf[0] == 'L')
3082 /* Scan for the values */
3083 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3085 /* Save the values */
3086 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3088 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3089 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3091 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3093 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3096 /* Process 'A' for "wAll type" (one line only) */
3097 else if (buf[0] == 'A')
3101 /* Scan for the values */
3102 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3104 /* Save the values */
3105 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3107 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3108 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3110 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3113 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3114 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3116 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3117 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3119 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3120 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3122 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3123 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3126 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3127 else if (buf[0] == 'F')
3129 int artif = 0, monst = 0;
3131 /* Parse every entry */
3132 for (s = buf + 2; *s; )
3134 /* Find the end of this entry */
3135 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3137 /* Nuke and skip any dividers */
3141 while (*t == ' ' || *t == '|') t++;
3144 /* XXX XXX XXX Hack -- Read Final Artifact */
3145 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3147 /* Extract a "Final Artifact" */
3148 d_ptr->final_artifact = artif;
3150 /* Start at next entry */
3157 /* XXX XXX XXX Hack -- Read Final Object */
3158 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3160 /* Extract a "Final Artifact" */
3161 d_ptr->final_object = artif;
3163 /* Start at next entry */
3170 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3171 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3173 /* Extract a "Artifact Guardian" */
3174 d_ptr->final_guardian = monst;
3176 /* Start at next entry */
3183 /* XXX XXX XXX Hack -- Read Special Percentage */
3184 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3186 /* Extract a "Special %" */
3187 d_ptr->special_div = monst;
3189 /* Start at next entry */
3196 /* Parse this entry */
3197 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3199 /* Start the next entry */
3204 /* Process 'M' for "Basic Flags" (multiple lines) */
3205 else if (buf[0] == 'M')
3207 /* Parse every entry */
3208 for (s = buf + 2; *s; )
3210 /* Find the end of this entry */
3211 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3213 /* Nuke and skip any dividers */
3217 while (*t == ' ' || *t == '|') t++;
3220 /* Hack -- Read monster symbols */
3221 if (!strncmp(s, "R_CHAR_", 7))
3223 /* Skip "R_CHAR_" */
3227 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3229 /* Start at next entry */
3236 /* Parse this entry */
3237 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3239 /* Start the next entry */
3244 /* Process 'S' for "Spell Flags" (multiple lines) */
3245 else if (buf[0] == 'S')
3247 /* Parse every entry */
3248 for (s = buf + 2; *s; )
3250 /* Find the end of this entry */
3251 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3253 /* Nuke and skip any dividers */
3257 while ((*t == ' ') || (*t == '|')) t++;
3260 /* XXX XXX XXX Hack -- Read spell frequency */
3261 if (1 == sscanf(s, "1_IN_%d", &i))
3263 /* Start at next entry */
3270 /* Parse this entry */
3271 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3273 /* Start the next entry */
3286 #else /* ALLOW_TEMPLATES */
3292 #endif /* ALLOW_TEMPLATES */
3295 /* Random dungeon grid effects */
3296 #define RANDOM_NONE 0x00000000
3297 #define RANDOM_FEATURE 0x00000001
3298 #define RANDOM_MONSTER 0x00000002
3299 #define RANDOM_OBJECT 0x00000004
3300 #define RANDOM_EGO 0x00000008
3301 #define RANDOM_ARTIFACT 0x00000010
3302 #define RANDOM_TRAP 0x00000020
3305 typedef struct dungeon_grid dungeon_grid;
3309 int feature; /* Terrain feature */
3310 int monster; /* Monster */
3311 int object; /* Object */
3312 int ego; /* Ego-Item */
3313 int artifact; /* Artifact */
3314 int trap; /* Trap */
3315 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3316 int special; /* Reserved for special terrain info */
3317 int random; /* Number of the random effect */
3321 static dungeon_grid letter[255];
3325 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3327 static errr parse_line_feature(char *buf)
3333 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3335 /* Tokenize the line */
3336 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3338 /* Letter to assign */
3339 int index = zz[0][0];
3341 /* Reset the info for the letter */
3342 letter[index].feature = feat_none;
3343 letter[index].monster = 0;
3344 letter[index].object = 0;
3345 letter[index].ego = 0;
3346 letter[index].artifact = 0;
3347 letter[index].trap = feat_none;
3348 letter[index].cave_info = 0;
3349 letter[index].special = 0;
3350 letter[index].random = RANDOM_NONE;
3356 letter[index].special = atoi(zz[8]);
3360 if ((zz[7][0] == '*') && !zz[7][1])
3362 letter[index].random |= RANDOM_TRAP;
3366 letter[index].trap = f_tag_to_index(zz[7]);
3367 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3372 if (zz[6][0] == '*')
3374 letter[index].random |= RANDOM_ARTIFACT;
3375 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3377 else if (zz[6][0] == '!')
3379 if (p_ptr->inside_quest)
3381 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3386 letter[index].artifact = atoi(zz[6]);
3391 if (zz[5][0] == '*')
3393 letter[index].random |= RANDOM_EGO;
3394 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3398 letter[index].ego = atoi(zz[5]);
3403 if (zz[4][0] == '*')
3405 letter[index].random |= RANDOM_OBJECT;
3406 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3408 else if (zz[4][0] == '!')
3410 if (p_ptr->inside_quest)
3412 int a_idx = quest[p_ptr->inside_quest].k_idx;
3415 artifact_type *a_ptr = &a_info[a_idx];
3416 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3418 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3425 letter[index].object = atoi(zz[4]);
3430 if (zz[3][0] == '*')
3432 letter[index].random |= RANDOM_MONSTER;
3433 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3435 else if (zz[3][0] == 'c')
3437 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3438 letter[index].monster = - atoi(zz[3] + 1);
3442 letter[index].monster = atoi(zz[3]);
3447 letter[index].cave_info = atoi(zz[2]);
3451 if ((zz[1][0] == '*') && !zz[1][1])
3453 letter[index].random |= RANDOM_FEATURE;
3457 letter[index].feature = f_tag_to_index(zz[1]);
3458 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3471 * Process "B:<Index>:<Command>:..." -- Building definition
3473 static errr parse_line_building(char *buf)
3489 /* Get the building number */
3492 /* Find the colon after the building number */
3493 s = my_strchr(s, ':');
3495 /* Verify that colon */
3498 /* Nuke the colon, advance to the sub-index */
3501 /* Paranoia -- require a sub-index */
3502 if (!*s) return (1);
3504 /* Building definition sub-index */
3507 /* Building name, owner, race */
3510 if (tokenize(s + 2, 3, zz, 0) == 3)
3512 /* Name of the building */
3513 strcpy(building[index].name, zz[0]);
3515 /* Name of the owner */
3516 strcpy(building[index].owner_name, zz[1]);
3518 /* Race of the owner */
3519 strcpy(building[index].owner_race, zz[2]);
3524 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3527 /* Building Action */
3530 if (tokenize(s + 2, 8, zz, 0) >= 7)
3532 /* Index of the action */
3533 int action_index = atoi(zz[0]);
3535 /* Name of the action */
3536 strcpy(building[index].act_names[action_index], zz[1]);
3538 /* Cost of the action for members */
3539 building[index].member_costs[action_index] = atoi(zz[2]);
3541 /* Cost of the action for non-members */
3542 building[index].other_costs[action_index] = atoi(zz[3]);
3544 /* Letter assigned to the action */
3545 building[index].letters[action_index] = zz[4][0];
3548 building[index].actions[action_index] = atoi(zz[5]);
3550 /* Action restriction */
3551 building[index].action_restr[action_index] = atoi(zz[6]);
3556 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3559 /* Building Classes */
3562 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3564 for (i = 0; i < MAX_CLASS; i++)
3566 building[index].member_class[i] = atoi(zz[i]);
3572 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3575 /* Building Races */
3578 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3580 for (i = 0; i < MAX_RACES; i++)
3582 building[index].member_race[i] = atoi(zz[i]);
3588 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3591 /* Building Realms */
3594 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3596 for (i = 0; i < MAX_MAGIC; i++)
3598 building[index].member_realm[i+1] = atoi(zz[i]);
3604 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3609 /* Ignore scripts */
3615 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3624 * Place the object j_ptr to a grid
3626 static void drop_here(object_type *j_ptr, int y, int x)
3628 cave_type *c_ptr = &cave[y][x];
3631 /* Get new object */
3632 s16b o_idx = o_pop();
3634 /* Access new object */
3635 o_ptr = &o_list[o_idx];
3637 /* Structure copy */
3638 object_copy(o_ptr, j_ptr);
3646 o_ptr->held_m_idx = 0;
3649 o_ptr->next_o_idx = c_ptr->o_idx;
3651 /* Place the object */
3652 c_ptr->o_idx = o_idx;
3657 * Parse a sub-file of the "extra info"
3659 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3666 /* Skip "empty" lines */
3667 if (!buf[0]) return (0);
3669 /* Skip "blank" lines */
3670 if (isspace(buf[0])) return (0);
3673 if (buf[0] == '#') return (0);
3675 /* Require "?:*" format */
3676 if (buf[1] != ':') return (1);
3679 /* Process "%:<fname>" */
3682 /* Attempt to Process the given file */
3683 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3686 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3689 return parse_line_feature(buf);
3692 /* Process "D:<dungeon>" -- info for the cave grids */
3693 else if (buf[0] == 'D')
3695 object_type object_type_body;
3697 /* Acquire the text */
3700 /* Length of the text */
3701 int len = strlen(s);
3703 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3705 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3707 /* Access the grid */
3708 cave_type *c_ptr = &cave[*y][*x];
3712 int object_index = letter[idx].object;
3713 int monster_index = letter[idx].monster;
3714 int random = letter[idx].random;
3715 int artifact_index = letter[idx].artifact;
3717 /* Lay down a floor */
3718 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3720 /* Only the features */
3721 if (init_flags & INIT_ONLY_FEATURES) continue;
3724 c_ptr->info = letter[idx].cave_info;
3726 /* Create a monster */
3727 if (random & RANDOM_MONSTER)
3729 monster_level = base_level + monster_index;
3731 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3733 monster_level = base_level;
3735 else if (monster_index)
3737 int old_cur_num, old_max_num;
3740 if (monster_index < 0)
3742 monster_index = -monster_index;
3745 old_cur_num = r_info[monster_index].cur_num;
3746 old_max_num = r_info[monster_index].max_num;
3748 /* Make alive again */
3749 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3751 r_info[monster_index].cur_num = 0;
3752 r_info[monster_index].max_num = 1;
3755 /* Make alive again */
3756 /* Hack -- Non-unique Nazguls are semi-unique */
3757 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3759 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3761 r_info[monster_index].max_num++;
3766 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3770 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3772 /* Make alive again for real unique monster */
3773 r_info[monster_index].cur_num = old_cur_num;
3774 r_info[monster_index].max_num = old_max_num;
3778 /* Object (and possible trap) */
3779 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3781 object_level = base_level + object_index;
3784 * Random trap and random treasure defined
3785 * 25% chance for trap and 75% chance for object
3787 if (randint0(100) < 75)
3789 place_object(*y, *x, 0L);
3796 object_level = base_level;
3798 else if (random & RANDOM_OBJECT)
3800 object_level = base_level + object_index;
3802 /* Create an out of deep object */
3803 if (randint0(100) < 75)
3804 place_object(*y, *x, 0L);
3805 else if (randint0(100) < 80)
3806 place_object(*y, *x, AM_GOOD);
3808 place_object(*y, *x, AM_GOOD | AM_GREAT);
3810 object_level = base_level;
3813 else if (random & RANDOM_TRAP)
3817 /* Hidden trap (or door) */
3818 else if (letter[idx].trap)
3820 c_ptr->mimic = c_ptr->feat;
3821 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3823 else if (object_index)
3825 /* Get local object */
3826 object_type *o_ptr = &object_type_body;
3828 /* Create the item */
3829 object_prep(o_ptr, object_index);
3831 if (o_ptr->tval == TV_GOLD)
3833 coin_type = object_index - OBJ_GOLD_LIST;
3838 /* Apply magic (no messages, no artifacts) */
3839 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3841 drop_here(o_ptr, *y, *x);
3847 if (a_info[artifact_index].cur_num)
3849 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3851 object_type *q_ptr = &forge;
3853 object_prep(q_ptr, k_idx);
3855 /* Drop it in the dungeon */
3856 drop_here(q_ptr, *y, *x);
3860 /* Create the artifact */
3861 if (create_named_art(artifact_index, *y, *x))
3862 a_info[artifact_index].cur_num = 1;
3866 /* Terrain special */
3867 c_ptr->special = letter[idx].special;
3875 /* Process "Q:<number>:<command>:... -- quest info */
3876 else if (buf[0] == 'Q')
3883 num = tokenize(buf + 2, 33, zz, 0);
3887 num = tokenize(buf + 3, 33, zz, 0);
3890 /* Have we enough parameters? */
3891 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3894 q_ptr = &(quest[atoi(zz[0])]);
3896 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3897 if (zz[1][0] == 'Q')
3899 if (init_flags & INIT_ASSIGN)
3901 monster_race *r_ptr;
3902 artifact_type *a_ptr;
3904 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3906 q_ptr->type = atoi(zz[2]);
3907 q_ptr->num_mon = atoi(zz[3]);
3908 q_ptr->cur_num = atoi(zz[4]);
3909 q_ptr->max_num = atoi(zz[5]);
3910 q_ptr->level = atoi(zz[6]);
3911 q_ptr->r_idx = atoi(zz[7]);
3912 q_ptr->k_idx = atoi(zz[8]);
3913 q_ptr->dungeon = atoi(zz[9]);
3916 q_ptr->flags = atoi(zz[10]);
3918 r_ptr = &r_info[q_ptr->r_idx];
3919 if (r_ptr->flags1 & RF1_UNIQUE)
3920 r_ptr->flags1 |= RF1_QUESTOR;
3922 a_ptr = &a_info[q_ptr->k_idx];
3923 a_ptr->gen_flags |= TRG_QUESTITEM;
3928 else if (zz[1][0] == 'R')
3930 if (init_flags & INIT_ASSIGN)
3935 for (idx = 2; idx < num; idx++)
3937 int a_idx = atoi(zz[idx]);
3938 if (a_idx < 1) continue;
3939 if (a_info[a_idx].cur_num > 0) continue;
3941 if (one_in_(count)) reward_idx = a_idx;
3946 /* Set quest's rewarding artifact */
3947 q_ptr->k_idx = reward_idx;
3948 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
3952 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
3953 q_ptr->type = QUEST_TYPE_KILL_ALL;
3960 /* Process "Q:<q_index>:N:<name>" -- quest name */
3961 else if (zz[1][0] == 'N')
3963 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
3965 strcpy(q_ptr->name, zz[2]);
3971 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3972 else if (zz[1][0] == 'T')
3974 if (init_flags & INIT_SHOW_TEXT)
3976 strcpy(quest_text[quest_text_line], zz[2]);
3984 /* Process "W:<command>: ..." -- info for the wilderness */
3985 else if (buf[0] == 'W')
3987 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3990 /* Process "P:<y>:<x>" -- player position */
3991 else if (buf[0] == 'P')
3993 if (init_flags & INIT_CREATE_DUNGEON)
3995 if (tokenize(buf + 2, 2, zz, 0) == 2)
3997 int panels_x, panels_y;
3999 /* Hack - Set the dungeon size */
4000 panels_y = (*y / SCREEN_HGT);
4001 if (*y % SCREEN_HGT) panels_y++;
4002 cur_hgt = panels_y * SCREEN_HGT;
4004 panels_x = (*x / SCREEN_WID);
4005 if (*x % SCREEN_WID) panels_x++;
4006 cur_wid = panels_x * SCREEN_WID;
4008 /* Assume illegal panel */
4009 panel_row_min = cur_hgt;
4010 panel_col_min = cur_wid;
4012 /* Place player in a quest level */
4013 if (p_ptr->inside_quest)
4017 /* Delete the monster (if any) */
4018 delete_monster(py, px);
4026 /* Place player in the town */
4027 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4029 p_ptr->oldpy = atoi(zz[0]);
4030 p_ptr->oldpx = atoi(zz[1]);
4038 /* Process "B:<Index>:<Command>:..." -- Building definition */
4039 else if (buf[0] == 'B')
4041 return parse_line_building(buf);
4044 /* Process "M:<type>:<maximum>" -- set maximum values */
4045 else if (buf[0] == 'M')
4047 if (tokenize(buf+2, 2, zz, 0) == 2)
4050 if (zz[0][0] == 'T')
4052 max_towns = atoi(zz[1]);
4055 /* Maximum quests */
4056 else if (zz[0][0] == 'Q')
4058 max_quests = atoi(zz[1]);
4062 else if (zz[0][0] == 'R')
4064 max_r_idx = atoi(zz[1]);
4068 else if (zz[0][0] == 'K')
4070 max_k_idx = atoi(zz[1]);
4074 else if (zz[0][0] == 'V')
4076 max_v_idx = atoi(zz[1]);
4080 else if (zz[0][0] == 'F')
4082 max_f_idx = atoi(zz[1]);
4086 else if (zz[0][0] == 'A')
4088 max_a_idx = atoi(zz[1]);
4092 else if (zz[0][0] == 'E')
4094 max_e_idx = atoi(zz[1]);
4098 else if (zz[0][0] == 'D')
4100 max_d_idx = atoi(zz[1]);
4104 else if (zz[0][0] == 'O')
4106 max_o_idx = atoi(zz[1]);
4110 else if (zz[0][0] == 'M')
4112 max_m_idx = atoi(zz[1]);
4115 /* Wilderness size */
4116 else if (zz[0][0] == 'W')
4118 /* Maximum wild_x_size */
4119 if (zz[0][1] == 'X')
4120 max_wild_x = atoi(zz[1]);
4121 /* Maximum wild_y_size */
4122 if (zz[0][1] == 'Y')
4123 max_wild_y = atoi(zz[1]);
4137 static cptr variant = "ZANGBAND";
4141 * Helper function for "process_dungeon_file()"
4143 static cptr process_dungeon_file_expr(char **sp, char *fp)
4159 while (isspace(*s)) s++;
4177 t = process_dungeon_file_expr(&s, &f);
4186 else if (streq(t, "IOR"))
4189 while (*s && (f != b2))
4191 t = process_dungeon_file_expr(&s, &f);
4192 if (*t && !streq(t, "0")) v = "1";
4197 else if (streq(t, "AND"))
4200 while (*s && (f != b2))
4202 t = process_dungeon_file_expr(&s, &f);
4203 if (*t && streq(t, "0")) v = "0";
4208 else if (streq(t, "NOT"))
4211 while (*s && (f != b2))
4213 t = process_dungeon_file_expr(&s, &f);
4214 if (*t && streq(t, "1")) v = "0";
4219 else if (streq(t, "EQU"))
4222 if (*s && (f != b2))
4224 t = process_dungeon_file_expr(&s, &f);
4226 while (*s && (f != b2))
4228 p = process_dungeon_file_expr(&s, &f);
4229 if (streq(t, p)) v = "1";
4234 else if (streq(t, "LEQ"))
4237 if (*s && (f != b2))
4239 t = process_dungeon_file_expr(&s, &f);
4241 while (*s && (f != b2))
4244 t = process_dungeon_file_expr(&s, &f);
4245 if (*t && atoi(p) > atoi(t)) v = "0";
4250 else if (streq(t, "GEQ"))
4253 if (*s && (f != b2))
4255 t = process_dungeon_file_expr(&s, &f);
4257 while (*s && (f != b2))
4260 t = process_dungeon_file_expr(&s, &f);
4262 /* Compare two numbers instead of string */
4263 if (*t && atoi(p) < atoi(t)) v = "0";
4270 while (*s && (f != b2))
4272 t = process_dungeon_file_expr(&s, &f);
4277 if (f != b2) v = "?x?x?";
4279 /* Extract final and Terminate */
4280 if ((f = *s) != '\0') *s++ = '\0';
4286 /* Accept all printables except spaces and brackets */
4288 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4290 if (iskanji(*s)) s++;
4294 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4297 /* Extract final and Terminate */
4298 if ((f = *s) != '\0') *s++ = '\0';
4304 if (streq(b+1, "SYS"))
4310 else if (streq(b+1, "GRAF"))
4315 else if (streq(b+1, "MONOCHROME"))
4324 else if (streq(b+1, "RACE"))
4327 v = rp_ptr->E_title;
4334 else if (streq(b+1, "CLASS"))
4337 v = cp_ptr->E_title;
4344 else if (streq(b+1, "REALM1"))
4347 v = E_realm_names[p_ptr->realm1];
4349 v = realm_names[p_ptr->realm1];
4354 else if (streq(b+1, "REALM2"))
4357 v = E_realm_names[p_ptr->realm2];
4359 v = realm_names[p_ptr->realm2];
4364 else if (streq(b+1, "PLAYER"))
4366 static char tmp_player_name[32];
4368 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4378 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4381 v = tmp_player_name;
4385 else if (streq(b+1, "TOWN"))
4387 sprintf(tmp, "%d", p_ptr->town_num);
4392 else if (streq(b+1, "LEVEL"))
4394 sprintf(tmp, "%d", p_ptr->lev);
4398 /* Current quest number */
4399 else if (streq(b+1, "QUEST_NUMBER"))
4401 sprintf(tmp, "%d", p_ptr->inside_quest);
4405 /* Number of last quest */
4406 else if (streq(b+1, "LEAVING_QUEST"))
4408 sprintf(tmp, "%d", leaving_quest);
4413 else if (prefix(b+1, "QUEST_TYPE"))
4415 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4416 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4421 else if (prefix(b+1, "QUEST"))
4423 /* "QUEST" uses a special parameter to determine the number of the quest */
4424 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4429 else if (prefix(b+1, "RANDOM"))
4431 /* "RANDOM" uses a special parameter to determine the number of the quest */
4432 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4437 else if (streq(b+1, "VARIANT"))
4443 else if (streq(b+1, "WILDERNESS"))
4446 sprintf(tmp, "NONE");
4448 sprintf(tmp, "LITE");
4450 sprintf(tmp, "NORMAL");
4473 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4483 bool bypass = FALSE;
4485 int x = xmin, y = ymin;
4488 /* Build the filename */
4489 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4492 fp = my_fopen(buf, "r");
4495 if (!fp) return (-1);
4498 /* Process the file */
4499 while (0 == my_fgets(fp, buf, sizeof(buf)))
4505 /* Skip "empty" lines */
4506 if (!buf[0]) continue;
4508 /* Skip "blank" lines */
4509 if (isspace(buf[0])) continue;
4512 if (buf[0] == '#') continue;
4515 /* Process "?:<expr>" */
4516 if ((buf[0] == '?') && (buf[1] == ':'))
4525 /* Parse the expr */
4526 v = process_dungeon_file_expr(&s, &f);
4529 bypass = (streq(v, "0") ? TRUE : FALSE);
4535 /* Apply conditionals */
4536 if (bypass) continue;
4538 /* Process the line */
4539 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4551 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4554 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4556 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4558 msg_format("Parsing '%s'.", buf);
4565 /* Close the file */
4575 void write_r_info_txt(void)
4577 int i, j, z, fc, bc;
4580 cptr flags[32 * 10];
4585 monster_race *r_ptr;
4587 monster_blow *b_ptr;
4589 FILE *fff = fopen("output.txt", "wt");
4597 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4599 fprintf(fff, "# Version stamp (required)\n\n");
4602 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4605 fprintf(fff, "##### The Player #####\n\n");
4607 for (z = -1; z < alloc_race_size; z++)
4609 /* Output the monsters in order */
4610 i = (z >= 0) ? alloc_race_table[z].index : 0;
4612 /* Acquire the monster */
4615 /* Ignore empty monsters */
4616 if (!strlen(r_name + r_ptr->name)) continue;
4618 /* Ignore useless monsters */
4619 if (i && !r_ptr->speed) continue;
4621 /* Write a note if necessary */
4622 if (i && (!r_ptr->level != !mode))
4627 fprintf(fff, "\n##### Town monsters #####\n\n");
4629 /* Note the dungeon */
4632 fprintf(fff, "\n##### Normal monsters #####\n\n");
4635 /* Record the change */
4636 mode = r_ptr->level;
4639 /* Acquire the flags */
4640 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4641 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4642 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4643 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4644 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4645 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4646 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4647 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4648 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4649 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4651 /* Write New/Number/Name */
4652 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4655 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4657 /* Write Information */
4658 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4659 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4661 /* Write more information */
4662 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4665 for(j = 0; j < 4; j++)
4667 b_ptr = &(r_ptr->blow[j]);
4669 /* Stop when done */
4670 if (!b_ptr->method) break;
4672 /* Write the blows */
4673 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4674 r_info_blow_effect[b_ptr->effect],
4675 b_ptr->d_dice, b_ptr->d_side);
4678 /* Extract the flags */
4679 for (fc = 0, j = 0; j < 32 * 3; j++)
4681 /* Check this flag */
4682 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4685 /* Extract the extra flags */
4686 for (j = 32 * 6; j < 32 * 10; j++)
4688 /* Check this flag */
4689 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4692 /* Write the flags */
4693 for (j = 0; j < fc;)
4697 /* Start the line */
4700 for (bc = 0; (bc < 60) && (j < fc); j++)
4704 /* Format the flag */
4705 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4707 /* Add it to the buffer */
4710 /* Note the length */
4714 /* Done with this line; write it */
4715 fprintf(fff, "%s\n", buf);
4718 /* Write Spells if applicable */
4719 if (r_ptr->freq_spell)
4721 /* Write the frequency */
4722 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4724 /* Extract the spell flags */
4725 for (fc = 0, j = 96; j < 192; j++)
4727 /* Check this flag */
4728 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4731 /* Write the flags */
4732 for (j = 0; j < fc;)
4736 /* Start the line */
4739 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4743 /* Format the flag */
4744 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4748 /* Note the length */
4755 /* Done with this line; write it */
4756 fprintf(fff, "%s\n", buf);
4760 /* Acquire the description */
4761 desc = r_text + r_ptr->text;
4762 dlen = strlen(desc);
4764 /* Write Description */
4765 for (j = 0; j < dlen;)
4769 /* Start the line */
4772 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4780 /* Done with this line; write it */
4781 fprintf(fff, "%s\n", buf);
4784 /* Space between entries */