4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 1) -BEN- */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
33 * in this file is compiled out, and the game will not run unless valid
34 * "binary template files" already exist in "lib/data". Thus, one can
35 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
36 * "*.raw" files in "lib/data", and then quit, and recompile without
37 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
38 * from changing the ascii template files in potentially dangerous ways.
40 * The code could actually be removed and placed into a "stand-alone"
41 * program, but that feels a little silly, especially considering some
42 * of the platforms that we currently support.
45 #ifdef ALLOW_TEMPLATES
50 /*** Helper arrays for parsing ascii template files ***/
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * Monster Blow Effects
90 static cptr r_info_blow_effect[] =
135 static cptr f_info_flags[] =
259 static cptr r_info_flags1[] =
298 static cptr r_info_flags2[] =
337 static cptr r_info_flags3[] =
376 static cptr r_info_flags4[] =
415 static cptr r_info_flags5[] =
454 static cptr r_info_flags6[] =
471 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
494 static cptr r_info_flags7[] =
533 static cptr r_info_flags8[] =
565 "WILD_SWAMP", /* ToDo: Implement Swamp */
571 * Monster race flags - Drops
573 static cptr r_info_flags9[] =
612 * Monster race flags - Resistances
614 static cptr r_info_flagsr[] =
654 static cptr k_info_flags[] =
751 "XXX3", /* Fake flag for Smith */
752 "XXX4", /* Fake flag for Smith */
782 static cptr k_info_gen_flags[] =
821 static cptr d_info_flags1[] =
859 * Add a text to the text-storage and store offset to it.
861 * Returns FALSE when there isn't enough space available to store
864 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
866 /* Hack -- Verify space */
867 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
873 /* Advance and save the text index */
874 *offset = ++head->text_size;
877 /* Additional text */
878 else if (normal_text)
881 * If neither the end of the last line nor
882 * the beginning of current line is not a space,
883 * fill up a space as a correct separator of two words.
885 if (head->text_size > 0 &&
887 (*(head->text_ptr + head->text_size - 1) != ' ') &&
888 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
889 (buf[0] != ' ') && !iskanji(buf[0])
891 (*(head->text_ptr + head->text_size - 1) != ' ') &&
897 *(head->text_ptr + head->text_size) = ' ';
899 /* Advance the index */
904 /* Append chars to the text */
905 strcpy(head->text_ptr + head->text_size, buf);
907 /* Advance the index */
908 head->text_size += strlen(buf);
916 * Add a name to the name-storage and return an offset to it.
918 * Returns FALSE when there isn't enough space available to store
921 static bool add_name(u32b *offset, header *head, cptr buf)
923 /* Hack -- Verify space */
924 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
930 /* Advance and save the name index */
931 *offset = ++head->name_size;
934 /* Append chars to the names */
935 strcpy(head->name_ptr + head->name_size, buf);
937 /* Advance the index */
938 head->name_size += strlen(buf);
946 * Add a tag to the tag-storage and return an offset to it.
948 * Returns FALSE when there isn't enough space available to store
951 static bool add_tag(s16b *offset, header *head, cptr buf)
955 /* Search for an existing (fake) tag */
956 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
959 if (streq(&head->tag_ptr[i], buf)) break;
962 /* There was no existing tag */
963 if (i >= head->tag_size)
965 /* Hack -- Verify space */
966 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
969 /* Append chars to the tags */
970 strcpy(head->tag_ptr + head->tag_size, buf);
972 /* Point the new tag */
975 /* Advance the index */
976 head->tag_size += strlen(buf) + 1;
979 /* Return offset of the tag */
988 * Convert a "color letter" into an "actual" color
989 * The colors are: dwsorgbuDWvyRGBU, as shown below
991 byte color_char_to_attr(char c)
995 case 'd': return (TERM_DARK);
996 case 'w': return (TERM_WHITE);
997 case 's': return (TERM_SLATE);
998 case 'o': return (TERM_ORANGE);
999 case 'r': return (TERM_RED);
1000 case 'g': return (TERM_GREEN);
1001 case 'b': return (TERM_BLUE);
1002 case 'u': return (TERM_UMBER);
1004 case 'D': return (TERM_L_DARK);
1005 case 'W': return (TERM_L_WHITE);
1006 case 'v': return (TERM_VIOLET);
1007 case 'y': return (TERM_YELLOW);
1008 case 'R': return (TERM_L_RED);
1009 case 'G': return (TERM_L_GREEN);
1010 case 'B': return (TERM_L_BLUE);
1011 case 'U': return (TERM_L_UMBER);
1019 /*** Initialize from ascii template files ***/
1023 * Initialize an "*_info" array, by parsing an ascii "template" file
1025 errr init_info_txt(FILE *fp, char *buf, header *head,
1026 parse_info_txt_func parse_info_txt_line)
1030 /* Just before the first record */
1033 /* Just before the first line */
1037 /* Prepare the "fake" stuff */
1038 head->name_size = 0;
1039 head->text_size = 0;
1043 while (0 == my_fgets(fp, buf, 1024))
1045 /* Advance the line number */
1048 /* Skip comments and blank lines */
1049 if (!buf[0] || (buf[0] == '#')) continue;
1051 /* Verify correct "colon" format */
1052 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1055 /* Hack -- Process 'V' for "Version" */
1062 /* Mega Hack -- Calculate Check Sum */
1063 if (buf[0] != 'N' && buf[0] != 'D')
1066 for (i = 0; buf[i]; i++)
1068 head->v_extra += (byte)buf[i];
1069 head->v_extra ^= (1 << (i % 8));
1073 /* Parse the line */
1074 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1079 /* Complete the "name" and "text" sizes */
1080 if (head->name_size) head->name_size++;
1081 if (head->text_size) head->text_size++;
1089 * Initialize the "v_info" array, by parsing an ascii "template" file
1091 errr parse_v_info(char *buf, header *head)
1097 static vault_type *v_ptr = NULL;
1099 /* Process 'N' for "New/Number/Name" */
1102 /* Find the colon before the name */
1103 s = my_strchr(buf+2, ':');
1105 /* Verify that colon */
1108 /* Nuke the colon, advance to the name */
1111 /* Paranoia -- require a name */
1112 if (!*s) return (1);
1117 /* Verify information */
1118 if (i <= error_idx) return (4);
1120 /* Verify information */
1121 if (i >= head->info_num) return (2);
1123 /* Save the index */
1126 /* Point at the "info" */
1129 /* Store the name */
1130 if (!add_name(&v_ptr->name, head, s)) return (7);
1133 /* There better be a current v_ptr */
1134 else if (!v_ptr) return (3);
1136 /* Process 'D' for "Description" */
1137 else if (buf[0] == 'D')
1139 /* Acquire the text */
1142 /* Store the text */
1143 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1146 /* Process 'X' for "Extra info" (one line only) */
1147 else if (buf[0] == 'X')
1149 int typ, rat, hgt, wid;
1151 /* Scan for the values */
1152 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1153 &typ, &rat, &hgt, &wid)) return (1);
1155 /* Save the values */
1172 * Initialize the "s_info" array, by parsing an ascii "template" file
1174 errr parse_s_info(char *buf, header *head)
1179 static skill_table *s_ptr = NULL;
1182 /* Process 'N' for "New/Number/Name" */
1188 /* Verify information */
1189 if (i <= error_idx) return (4);
1191 /* Verify information */
1192 if (i >= head->info_num) return (2);
1194 /* Save the index */
1197 /* Point at the "info" */
1201 /* There better be a current s_ptr */
1202 else if (!s_ptr) return (3);
1204 /* Process 'W' for "Weapon exp" */
1205 else if (buf[0] == 'W')
1207 int tval, sval, start, max;
1208 const s16b exp_conv_table[] =
1210 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1211 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1214 /* Scan for the values */
1215 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1216 &tval, &sval, &start, &max)) return (1);
1218 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1219 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1221 /* Save the values */
1222 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1223 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1226 /* Process 'S' for "Skill exp" */
1227 else if (buf[0] == 'S')
1229 int num, start, max;
1231 /* Scan for the values */
1232 if (3 != sscanf(buf+2, "%d:%d:%d",
1233 &num, &start, &max)) return (1);
1235 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1236 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1238 /* Save the values */
1239 s_ptr->s_start[num] = start;
1240 s_ptr->s_max[num] = max;
1253 * Initialize the "m_info" array, by parsing an ascii "template" file
1255 errr parse_m_info(char *buf, header *head)
1262 static player_magic *m_ptr = NULL;
1265 static int realm, magic_idx = 0, readable = 0;
1268 /* Process 'N' for "New/Number/Name" */
1274 /* Verify information */
1275 if (i <= error_idx) return (4);
1277 /* Verify information */
1278 if (i >= head->info_num) return (2);
1280 /* Save the index */
1283 /* Point at the "info" */
1287 /* There better be a current m_ptr */
1288 else if (!m_ptr) return (3);
1290 /* Process 'I' for "Info" (one line only) */
1291 else if (buf[0] == 'I')
1294 int xtra, type, first, weight;
1296 /* Find the colon before the name */
1297 s = my_strchr(buf+2, ':');
1299 /* Verify that colon */
1302 /* Nuke the colon, advance to the name */
1307 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1308 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1309 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1310 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1311 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1316 /* Find the colon before the name */
1317 s = my_strchr(s, ':');
1319 /* Verify that colon */
1322 /* Nuke the colon, advance to the name */
1325 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1326 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1327 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1328 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1329 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1330 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1334 /* Scan for the values */
1335 if (4 != sscanf(s, "%x:%d:%d:%d",
1336 (uint *)&xtra, &type, &first, &weight)) return (1);
1338 m_ptr->spell_xtra = xtra;
1339 m_ptr->spell_type = type;
1340 m_ptr->spell_first = first;
1341 m_ptr->spell_weight = weight;
1345 /* Process 'R' for "Realm" (one line only) */
1346 else if (buf[0] == 'R')
1348 /* Scan for the values */
1349 if (2 != sscanf(buf+2, "%d:%d",
1350 &realm, &readable)) return (1);
1355 else if (buf[0] == 'T')
1357 int level, mana, fail, exp;
1359 if (!readable) return (1);
1360 /* Scan for the values */
1361 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1362 &level, &mana, &fail, &exp)) return (1);
1364 m_ptr->info[realm][magic_idx].slevel = level;
1365 m_ptr->info[realm][magic_idx].smana = mana;
1366 m_ptr->info[realm][magic_idx].sfail = fail;
1367 m_ptr->info[realm][magic_idx].sexp = exp;
1381 * Grab one flag from a textual string
1383 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1388 for (i = 0; i < 32; i++)
1390 if (streq(what, names[i]))
1392 *flags |= (1L << i);
1402 * Grab one flag in an feature_type from a textual string
1404 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1409 for (i = 0; i < FF_FLAG_MAX; i++)
1411 if (streq(what, f_info_flags[i]))
1413 add_flag(f_ptr->flags, i);
1420 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1422 msg_format("Unknown feature flag '%s'.", what);
1426 return PARSE_ERROR_GENERIC;
1431 * Grab an action in an feature_type from a textual string
1433 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1438 for (i = 0; i < FF_FLAG_MAX; i++)
1440 if (streq(what, f_info_flags[i]))
1442 f_ptr->state[count].action = i;
1449 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1451 msg_format("Unknown feature action '%s'.", what);
1455 return PARSE_ERROR_GENERIC;
1460 * Initialize the "f_info" array, by parsing an ascii "template" file
1462 errr parse_f_info(char *buf, header *head)
1469 static feature_type *f_ptr = NULL;
1472 /* Process 'N' for "New/Number/Name" */
1475 /* Find the colon before the name */
1476 s = my_strchr(buf+2, ':');
1480 /* Nuke the colon, advance to the name */
1487 /* Verify information */
1488 if (i <= error_idx) return (4);
1490 /* Verify information */
1491 if (i >= head->info_num) return (2);
1493 /* Save the index */
1496 /* Point at the "info" */
1499 /* Tag name is given */
1503 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1506 /* Default "mimic" */
1509 /* Default "destroyed state" -- if not specified */
1510 f_ptr->destroyed = i;
1512 /* Default "states" */
1513 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1516 /* There better be a current f_ptr */
1517 else if (!f_ptr) return (3);
1520 else if (buf[0] == 'J')
1522 /* Store the name */
1523 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1526 else if (buf[0] == 'E')
1528 /* Ignore english name */
1531 else if (buf[0] == 'J')
1533 /* Ignore Japanese name */
1536 else if (buf[0] == 'E')
1538 /* Acquire the Text */
1541 /* Store the name */
1542 if (!add_name(&f_ptr->name, head, s)) return (7);
1547 /* Process 'M' for "Mimic" (one line only) */
1548 else if (buf[0] == 'M')
1552 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1554 /* Record a fake tag index */
1555 f_ptr->mimic = -offset;
1559 /* Process 'G' for "Graphics" (one line only) */
1560 else if (buf[0] == 'G')
1564 char char_tmp[F_LIT_MAX];
1567 if (buf[1] != ':') return (1);
1568 if (!buf[2]) return (1);
1569 if (buf[3] != ':') return (1);
1570 if (!buf[4]) return (1);
1572 /* Extract the char */
1573 char_tmp[F_LIT_STANDARD] = buf[2];
1575 /* Extract the color */
1576 s_attr = color_char_to_attr(buf[4]);
1579 if (s_attr > 127) return (1);
1581 /* Save the standard values */
1582 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1583 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1585 /* Is this feature supports lighting? */
1588 /* G:c:a:LIT (default) */
1589 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1591 /* G:c:a:lc:la:dc:da */
1592 if (!streq(buf + 6, "LIT"))
1594 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1596 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1597 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1598 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1599 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1601 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1603 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1606 /* Use default lighting */
1609 /* No lighting support */
1610 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1613 /* Extract the color */
1614 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1615 if (f_ptr->d_attr[j] > 127) return 1;
1618 f_ptr->d_char[j] = char_tmp[j];
1624 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1626 f_ptr->d_attr[j] = s_attr;
1627 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1633 /* Hack -- Process 'F' for flags */
1634 else if (buf[0] == 'F')
1636 /* Parse every entry textually */
1637 for (s = buf + 2; *s; )
1639 /* Find the end of this entry */
1640 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1642 /* Nuke and skip any dividers */
1646 while (*t == ' ' || *t == '|') t++;
1649 /* XXX XXX XXX Hack -- Read feature subtype */
1650 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1652 /* Extract a "subtype" */
1655 /* Start at next entry */
1662 /* XXX XXX XXX Hack -- Read feature power */
1663 if (1 == sscanf(s, "POWER_%d", &i))
1665 /* Extract a "power" */
1668 /* Start at next entry */
1675 /* Parse this entry */
1676 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1678 /* Start the next entry */
1683 /* Process 'W' for "More Info" (one line only) */
1684 else if (buf[0] == 'W')
1688 /* Scan for the value */
1689 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1691 /* Save the value */
1692 f_ptr->priority = priority;
1695 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1696 else if (buf[0] == 'K')
1700 /* Find the next empty state slot (if any) */
1701 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1703 /* Oops, no more slots */
1704 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1706 /* Analyze the first field */
1707 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1709 /* Terminate the field (if necessary) */
1710 if (*t == ':') *t++ = '\0';
1712 /* Is this default entry? */
1713 if (streq(s, "DESTROYED"))
1715 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1717 /* Record a fake tag index */
1718 f_ptr->destroyed = -offset;
1723 f_ptr->state[i].action = 0;
1725 /* Parse this entry */
1726 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1728 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1730 /* Record a fake tag index */
1731 f_ptr->state[i].result = -offset;
1744 * Convert a fake tag to a real feat index
1746 s16b f_tag_to_index(cptr str)
1750 /* Search for real index corresponding to this fake tag */
1751 for (i = 0; i < f_head.info_num; i++)
1753 if (streq(f_tag + f_info[i].tag, str))
1755 /* Return the index */
1766 * Search for real index corresponding to this fake tag
1768 static void search_real_feat(s16b *feat)
1772 /* Don't convert non-fake tag */
1773 if (*feat >= 0) return;
1775 /* Search for real index corresponding to this fake tag */
1776 for (i = 0; i < f_head.info_num; i++)
1778 if ((-(*feat)) == f_info[i].tag)
1780 /* Record real index */
1788 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1790 msg_format("%s is undefined.", f_tag + (-(*feat)));
1796 * Retouch fake tags of f_info
1798 void retouch_f_info(header *head)
1802 /* Convert fake tags to real feat indices */
1803 for (i = 0; i < head->info_num; i++)
1805 feature_type *f_ptr = &f_info[i];
1808 search_real_feat(&f_ptr->mimic);
1810 search_real_feat(&f_ptr->destroyed);
1812 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1818 * Grab one flag in an object_kind from a textual string
1820 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1825 for (i = 0; i < TR_FLAG_MAX; i++)
1827 if (streq(what, k_info_flags[i]))
1829 add_flag(k_ptr->flags, i);
1834 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1839 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1841 msg_format("Unknown object flag '%s'.", what);
1850 * Grab one activation index flag
1852 static byte grab_one_activation_flag(cptr what)
1858 if (activation_info[i].flag == NULL) break;
1860 if (streq(what, activation_info[i].flag))
1862 return activation_info[i].index;
1874 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
1876 msg_format("Unknown activation flag '%s'.", what);
1885 * Initialize the "k_info" array, by parsing an ascii "template" file
1887 errr parse_k_info(char *buf, header *head)
1894 static object_kind *k_ptr = NULL;
1897 /* Process 'N' for "New/Number/Name" */
1904 /* Find the colon before the name */
1905 s = my_strchr(buf+2, ':');
1907 /* Verify that colon */
1910 /* Nuke the colon, advance to the name */
1916 /* Verify information */
1917 if (i <= error_idx) return (4);
1919 /* Verify information */
1920 if (i >= head->info_num) return (2);
1922 /* Save the index */
1925 /* Point at the "info" */
1929 /* Paranoia -- require a name */
1930 if (!*s) return (1);
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 /* There better be a current k_ptr */
1951 else if (!k_ptr) return (3);
1955 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1956 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1957 else if (buf[0] == 'E')
1962 else if (buf[0] == 'E')
1966 /* Acquire the name */
1969 /* Find the colon before the flavor */
1970 flavor = my_strchr(s, ':');
1972 /* Verify that colon */
1975 /* Nuke the colon, advance to the flavor */
1978 /* Store the flavor */
1979 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
1982 /* Store the name */
1983 if (!add_name(&k_ptr->name, head, s)) return (7);
1987 /* Process 'D' for "Description" */
1988 else if (buf[0] == 'D')
1993 /* Acquire the text */
1998 /* Acquire the text */
2002 /* Store the text */
2003 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2006 /* Process 'G' for "Graphics" (one line only) */
2007 else if (buf[0] == 'G')
2013 if (buf[1] != ':') return (1);
2014 if (!buf[2]) return (1);
2015 if (buf[3] != ':') return (1);
2016 if (!buf[4]) return (1);
2018 /* Extract the char */
2021 /* Extract the attr */
2022 tmp = color_char_to_attr(buf[4]);
2025 if (tmp > 127) return (1);
2027 /* Save the values */
2028 k_ptr->d_attr = tmp;
2029 k_ptr->d_char = sym;
2032 /* Process 'I' for "Info" (one line only) */
2033 else if (buf[0] == 'I')
2035 int tval, sval, pval;
2037 /* Scan for the values */
2038 if (3 != sscanf(buf+2, "%d:%d:%d",
2039 &tval, &sval, &pval)) return (1);
2041 /* Save the values */
2047 /* Process 'W' for "More Info" (one line only) */
2048 else if (buf[0] == 'W')
2050 int level, extra, wgt;
2053 /* Scan for the values */
2054 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2055 &level, &extra, &wgt, &cost)) return (1);
2057 /* Save the values */
2058 k_ptr->level = level;
2059 k_ptr->extra = extra;
2060 k_ptr->weight = wgt;
2064 /* Process 'A' for "Allocation" (one line only) */
2065 else if (buf[0] == 'A')
2069 /* XXX XXX XXX Simply read each number following a colon */
2070 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2072 /* Default chance */
2073 k_ptr->chance[i] = 1;
2075 /* Store the attack damage index */
2076 k_ptr->locale[i] = atoi(s+1);
2078 /* Find the slash */
2079 t = my_strchr(s+1, '/');
2081 /* Find the next colon */
2082 s = my_strchr(s+1, ':');
2084 /* If the slash is "nearby", use it */
2085 if (t && (!s || t < s))
2087 int chance = atoi(t+1);
2088 if (chance > 0) k_ptr->chance[i] = chance;
2093 /* Hack -- Process 'P' for "power" and such */
2094 else if (buf[0] == 'P')
2096 int ac, hd1, hd2, th, td, ta;
2098 /* Scan for the values */
2099 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2100 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2110 /* Hack -- Process 'U' for activation index */
2111 else if (buf[0] == 'U')
2114 n = grab_one_activation_flag(buf + 2);
2125 /* Hack -- Process 'F' for flags */
2126 else if (buf[0] == 'F')
2128 /* Parse every entry textually */
2129 for (s = buf + 2; *s; )
2131 /* Find the end of this entry */
2132 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2134 /* Nuke and skip any dividers */
2138 while (*t == ' ' || *t == '|') t++;
2141 /* Parse this entry */
2142 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2144 /* Start the next entry */
2160 * Grab one flag in an artifact_type from a textual string
2162 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2167 for (i = 0; i < TR_FLAG_MAX; i++)
2169 if (streq(what, k_info_flags[i]))
2171 add_flag(a_ptr->flags, i);
2176 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2181 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2183 msg_format("Unknown artifact flag '%s'.", what);
2193 * Initialize the "a_info" array, by parsing an ascii "template" file
2195 errr parse_a_info(char *buf, header *head)
2202 static artifact_type *a_ptr = NULL;
2205 /* Process 'N' for "New/Number/Name" */
2208 /* Find the colon before the name */
2209 s = my_strchr(buf+2, ':');
2211 /* Verify that colon */
2214 /* Nuke the colon, advance to the name */
2217 /* Paranoia -- require a name */
2218 if (!*s) return (1);
2223 /* Verify information */
2224 if (i < error_idx) return (4);
2226 /* Verify information */
2227 if (i >= head->info_num) return (2);
2229 /* Save the index */
2232 /* Point at the "info" */
2235 /* Ignore everything */
2236 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2237 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2238 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2239 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2241 /* Store the name */
2242 if (!add_name(&a_ptr->name, head, s)) return (7);
2246 /* There better be a current a_ptr */
2247 else if (!a_ptr) return (3);
2251 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2252 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2253 else if (buf[0] == 'E')
2258 else if (buf[0] == 'E')
2260 /* Acquire the Text */
2263 /* Store the name */
2264 if (!add_name(&a_ptr->name, head, s)) return (7);
2268 /* Process 'D' for "Description" */
2269 else if (buf[0] == 'D')
2274 /* Acquire the text */
2279 /* Acquire the text */
2283 /* Store the text */
2284 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2288 /* Process 'I' for "Info" (one line only) */
2289 else if (buf[0] == 'I')
2291 int tval, sval, pval;
2293 /* Scan for the values */
2294 if (3 != sscanf(buf+2, "%d:%d:%d",
2295 &tval, &sval, &pval)) return (1);
2297 /* Save the values */
2303 /* Process 'W' for "More Info" (one line only) */
2304 else if (buf[0] == 'W')
2306 int level, rarity, wgt;
2309 /* Scan for the values */
2310 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2311 &level, &rarity, &wgt, &cost)) return (1);
2313 /* Save the values */
2314 a_ptr->level = level;
2315 a_ptr->rarity = rarity;
2316 a_ptr->weight = wgt;
2320 /* Hack -- Process 'P' for "power" and such */
2321 else if (buf[0] == 'P')
2323 int ac, hd1, hd2, th, td, ta;
2325 /* Scan for the values */
2326 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2327 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2337 /* Hack -- Process 'U' for activation index */
2338 else if (buf[0] == 'U')
2341 n = grab_one_activation_flag(buf + 2);
2352 /* Hack -- Process 'F' for flags */
2353 else if (buf[0] == 'F')
2355 /* Parse every entry textually */
2356 for (s = buf + 2; *s; )
2358 /* Find the end of this entry */
2359 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2361 /* Nuke and skip any dividers */
2365 while ((*t == ' ') || (*t == '|')) t++;
2368 /* Parse this entry */
2369 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2371 /* Start the next entry */
2387 * Grab one flag in a ego-item_type from a textual string
2389 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2394 for (i = 0; i < TR_FLAG_MAX; i++)
2396 if (streq(what, k_info_flags[i]))
2398 add_flag(e_ptr->flags, i);
2403 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2408 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2410 msg_format("Unknown ego-item flag '%s'.", what);
2422 * Initialize the "e_info" array, by parsing an ascii "template" file
2424 errr parse_e_info(char *buf, header *head)
2431 static ego_item_type *e_ptr = NULL;
2434 /* Just before the first record */
2437 /* Just before the first line */
2441 /* Process 'N' for "New/Number/Name" */
2444 /* Find the colon before the name */
2445 s = my_strchr(buf+2, ':');
2447 /* Verify that colon */
2450 /* Nuke the colon, advance to the name */
2453 /* Paranoia -- require a name */
2454 if (!*s) return (1);
2459 /* Verify information */
2460 if (i < error_idx) return (4);
2462 /* Verify information */
2463 if (i >= head->info_num) return (2);
2465 /* Save the index */
2468 /* Point at the "info" */
2471 /* Store the name */
2472 if (!add_name(&e_ptr->name, head, s)) return (7);
2476 /* There better be a current e_ptr */
2477 else if (!e_ptr) return (3);
2481 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2482 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2483 else if (buf[0] == 'E')
2488 else if (buf[0] == 'E')
2490 /* Acquire the Text */
2493 /* Store the name */
2494 if (!add_name(&e_ptr->name, head, s)) return (7);
2499 /* Process 'D' for "Description" */
2500 else if (buf[0] == 'D')
2502 /* Acquire the text */
2505 /* Store the text */
2506 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2511 /* Process 'X' for "Xtra" (one line only) */
2512 else if (buf[0] == 'X')
2516 /* Scan for the values */
2517 if (2 != sscanf(buf+2, "%d:%d",
2518 &slot, &rating)) return (1);
2520 /* Save the values */
2522 e_ptr->rating = rating;
2525 /* Process 'W' for "More Info" (one line only) */
2526 else if (buf[0] == 'W')
2528 int level, rarity, pad2;
2531 /* Scan for the values */
2532 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2533 &level, &rarity, &pad2, &cost)) return (1);
2535 /* Save the values */
2536 e_ptr->level = level;
2537 e_ptr->rarity = rarity;
2538 /* e_ptr->weight = wgt; */
2542 /* Hack -- Process 'C' for "creation" */
2543 else if (buf[0] == 'C')
2547 /* Scan for the values */
2548 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2549 &th, &td, &ta, &pv)) return (1);
2551 e_ptr->max_to_h = th;
2552 e_ptr->max_to_d = td;
2553 e_ptr->max_to_a = ta;
2554 e_ptr->max_pval = pv;
2557 /* Hack -- Process 'U' for activation index */
2558 else if (buf[0] == 'U')
2561 n = grab_one_activation_flag(buf + 2);
2572 /* Hack -- Process 'F' for flags */
2573 else if (buf[0] == 'F')
2575 /* Parse every entry textually */
2576 for (s = buf + 2; *s; )
2578 /* Find the end of this entry */
2579 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2581 /* Nuke and skip any dividers */
2585 while ((*t == ' ') || (*t == '|')) t++;
2588 /* Parse this entry */
2589 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2591 /* Start the next entry */
2605 * Grab one (basic) flag in a monster_race from a textual string
2607 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2609 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2612 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2615 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2618 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2621 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2624 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2627 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2632 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2634 msg_format("Unknown monster flag '%s'.", what);
2644 * Grab one (spell) flag in a monster_race from a textual string
2646 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2648 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2651 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2654 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2659 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2661 msg_format("Unknown monster flag '%s'.", what);
2673 * Initialize the "r_info" array, by parsing an ascii "template" file
2675 errr parse_r_info(char *buf, header *head)
2682 static monster_race *r_ptr = NULL;
2685 /* Process 'N' for "New/Number/Name" */
2688 /* Find the colon before the name */
2689 s = my_strchr(buf+2, ':');
2691 /* Verify that colon */
2694 /* Nuke the colon, advance to the name */
2697 /* Paranoia -- require a name */
2698 if (!*s) return (1);
2703 /* Verify information */
2704 if (i < error_idx) return (4);
2706 /* Verify information */
2707 if (i >= head->info_num) return (2);
2709 /* Save the index */
2712 /* Point at the "info" */
2715 /* Store the name */
2716 if (!add_name(&r_ptr->name, head, s)) return (7);
2720 /* There better be a current r_ptr */
2721 else if (!r_ptr) return (3);
2725 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2726 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2727 else if (buf[0] == 'E')
2729 /* Acquire the Text */
2732 /* Store the name */
2733 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2736 else if (buf[0] == 'E')
2738 /* Acquire the Text */
2741 /* Store the name */
2742 if (!add_name(&r_ptr->name, head, s)) return (7);
2745 /* Process 'D' for "Description" */
2746 else if (buf[0] == 'D')
2751 /* Acquire the text */
2756 /* Acquire the text */
2760 /* Store the text */
2761 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2764 /* Process 'G' for "Graphics" (one line only) */
2765 else if (buf[0] == 'G')
2771 if (buf[1] != ':') return (1);
2772 if (!buf[2]) return (1);
2773 if (buf[3] != ':') return (1);
2774 if (!buf[4]) return (1);
2776 /* Extract the char */
2779 /* Extract the attr */
2780 tmp = color_char_to_attr(buf[4]);
2783 if (tmp > 127) return (1);
2785 /* Save the values */
2786 r_ptr->d_char = sym;
2787 r_ptr->d_attr = tmp;
2790 /* Process 'I' for "Info" (one line only) */
2791 else if (buf[0] == 'I')
2793 int spd, hp1, hp2, aaf, ac, slp;
2795 /* Scan for the other values */
2796 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2797 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2799 /* Save the values */
2801 r_ptr->hdice = MAX(hp1, 1);
2802 r_ptr->hside = MAX(hp2, 1);
2808 /* Process 'W' for "More Info" (one line only) */
2809 else if (buf[0] == 'W')
2816 /* Scan for the values */
2817 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2818 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2820 /* Save the values */
2822 r_ptr->rarity = rar;
2825 r_ptr->next_exp = nextexp;
2826 r_ptr->next_r_idx = nextmon;
2829 /* Process 'B' for "Blows" (up to four lines) */
2830 else if (buf[0] == 'B')
2834 /* Find the next empty blow slot (if any) */
2835 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2837 /* Oops, no more slots */
2838 if (i == 4) return (1);
2840 /* Analyze the first field */
2841 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2843 /* Terminate the field (if necessary) */
2844 if (*t == ':') *t++ = '\0';
2846 /* Analyze the method */
2847 for (n1 = 0; r_info_blow_method[n1]; n1++)
2849 if (streq(s, r_info_blow_method[n1])) break;
2852 /* Invalid method */
2853 if (!r_info_blow_method[n1]) return (1);
2855 /* Analyze the second field */
2856 for (s = t; *t && (*t != ':'); t++) /* loop */;
2858 /* Terminate the field (if necessary) */
2859 if (*t == ':') *t++ = '\0';
2861 /* Analyze effect */
2862 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2864 if (streq(s, r_info_blow_effect[n2])) break;
2867 /* Invalid effect */
2868 if (!r_info_blow_effect[n2]) return (1);
2870 /* Analyze the third field */
2871 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2873 /* Terminate the field (if necessary) */
2874 if (*t == 'd') *t++ = '\0';
2876 /* Save the method */
2877 r_ptr->blow[i].method = n1;
2879 /* Save the effect */
2880 r_ptr->blow[i].effect = n2;
2882 /* Extract the damage dice and sides */
2883 r_ptr->blow[i].d_dice = atoi(s);
2884 r_ptr->blow[i].d_side = atoi(t);
2887 /* Process 'F' for "Basic Flags" (multiple lines) */
2888 else if (buf[0] == 'F')
2890 /* Parse every entry */
2891 for (s = buf + 2; *s; )
2893 /* Find the end of this entry */
2894 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2896 /* Nuke and skip any dividers */
2900 while (*t == ' ' || *t == '|') t++;
2903 /* Parse this entry */
2904 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2906 /* Start the next entry */
2911 /* Process 'S' for "Spell Flags" (multiple lines) */
2912 else if (buf[0] == 'S')
2914 /* Parse every entry */
2915 for (s = buf + 2; *s; )
2917 /* Find the end of this entry */
2918 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2920 /* Nuke and skip any dividers */
2924 while ((*t == ' ') || (*t == '|')) t++;
2927 /* XXX XXX XXX Hack -- Read spell frequency */
2928 if (1 == sscanf(s, "1_IN_%d", &i))
2930 /* Extract a "frequency" */
2931 r_ptr->freq_spell = 100 / i;
2933 /* Start at next entry */
2940 /* Parse this entry */
2941 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2943 /* Start the next entry */
2958 * Grab one flag for a dungeon type from a textual string
2960 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2962 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2967 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2969 msg_format("Unknown dungeon type flag '%s'.", what);
2977 * Grab one (basic) flag in a monster_race from a textual string
2979 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2981 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2984 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2987 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2990 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2993 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2996 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2999 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3004 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3006 msg_format("Unknown monster flag '%s'.", what);
3014 * Grab one (spell) flag in a monster_race from a textual string
3016 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3018 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3021 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3024 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3029 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3031 msg_format("Unknown monster flag '%s'.", what);
3039 * Initialize the "d_info" array, by parsing an ascii "template" file
3041 errr parse_d_info(char *buf, header *head)
3048 static dungeon_info_type *d_ptr = NULL;
3051 /* Process 'N' for "New/Number/Name" */
3054 /* Find the colon before the name */
3055 s = my_strchr(buf+2, ':');
3057 /* Verify that colon */
3060 /* Nuke the colon, advance to the name */
3063 /* Paranoia -- require a name */
3064 if (!*s) return (1);
3069 /* Verify information */
3070 if (i < error_idx) return (4);
3072 /* Verify information */
3073 if (i >= head->info_num) return (2);
3075 /* Save the index */
3078 /* Point at the "info" */
3081 /* Store the name */
3082 if (!add_name(&d_ptr->name, head, s)) return (7);
3087 else if (buf[0] == 'E') return (0);
3089 else if (buf[0] == 'E')
3091 /* Acquire the Text */
3094 /* Store the name */
3095 if (!add_name(&d_ptr->name, head, s)) return (7);
3099 /* Process 'D' for "Description */
3100 else if (buf[0] == 'D')
3105 /* Acquire the text */
3110 /* Acquire the text */
3114 /* Store the text */
3115 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3118 /* Process 'W' for "More Info" (one line only) */
3119 else if (buf[0] == 'W')
3121 int min_lev, max_lev;
3123 int min_alloc, max_chance;
3124 int obj_good, obj_great;
3127 /* Scan for the values */
3128 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3129 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3131 /* Save the values */
3132 d_ptr->mindepth = min_lev;
3133 d_ptr->maxdepth = max_lev;
3134 d_ptr->min_plev = min_plev;
3136 d_ptr->min_m_alloc_level = min_alloc;
3137 d_ptr->max_m_alloc_chance = max_chance;
3138 d_ptr->obj_good = obj_good;
3139 d_ptr->obj_great = obj_great;
3144 /* Process 'P' for "Place Info" */
3145 else if (buf[0] == 'P')
3149 /* Scan for the values */
3150 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3152 /* Save the values */
3157 /* Process 'L' for "fLoor type" (one line only) */
3158 else if (buf[0] == 'L')
3162 /* Scan for the values */
3163 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3165 /* Save the values */
3166 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3168 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3169 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3171 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3173 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3176 /* Process 'A' for "wAll type" (one line only) */
3177 else if (buf[0] == 'A')
3181 /* Scan for the values */
3182 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3184 /* Save the values */
3185 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3187 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3188 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3190 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3193 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3194 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3196 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3197 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3199 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3200 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3202 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3203 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3206 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3207 else if (buf[0] == 'F')
3209 int artif = 0, monst = 0;
3211 /* Parse every entry */
3212 for (s = buf + 2; *s; )
3214 /* Find the end of this entry */
3215 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3217 /* Nuke and skip any dividers */
3221 while (*t == ' ' || *t == '|') t++;
3224 /* XXX XXX XXX Hack -- Read Final Artifact */
3225 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3227 /* Extract a "Final Artifact" */
3228 d_ptr->final_artifact = artif;
3230 /* Start at next entry */
3237 /* XXX XXX XXX Hack -- Read Final Object */
3238 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3240 /* Extract a "Final Artifact" */
3241 d_ptr->final_object = artif;
3243 /* Start at next entry */
3250 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3251 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3253 /* Extract a "Artifact Guardian" */
3254 d_ptr->final_guardian = monst;
3256 /* Start at next entry */
3263 /* XXX XXX XXX Hack -- Read Special Percentage */
3264 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3266 /* Extract a "Special %" */
3267 d_ptr->special_div = monst;
3269 /* Start at next entry */
3276 /* Parse this entry */
3277 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3279 /* Start the next entry */
3284 /* Process 'M' for "Basic Flags" (multiple lines) */
3285 else if (buf[0] == 'M')
3287 /* Parse every entry */
3288 for (s = buf + 2; *s; )
3290 /* Find the end of this entry */
3291 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3293 /* Nuke and skip any dividers */
3297 while (*t == ' ' || *t == '|') t++;
3300 /* Hack -- Read monster symbols */
3301 if (!strncmp(s, "R_CHAR_", 7))
3303 /* Skip "R_CHAR_" */
3307 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3309 /* Start at next entry */
3316 /* Parse this entry */
3317 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3319 /* Start the next entry */
3324 /* Process 'S' for "Spell Flags" (multiple lines) */
3325 else if (buf[0] == 'S')
3327 /* Parse every entry */
3328 for (s = buf + 2; *s; )
3330 /* Find the end of this entry */
3331 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3333 /* Nuke and skip any dividers */
3337 while ((*t == ' ') || (*t == '|')) t++;
3340 /* XXX XXX XXX Hack -- Read spell frequency */
3341 if (1 == sscanf(s, "1_IN_%d", &i))
3343 /* Start at next entry */
3350 /* Parse this entry */
3351 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3353 /* Start the next entry */
3366 #else /* ALLOW_TEMPLATES */
3372 #endif /* ALLOW_TEMPLATES */
3375 /* Random dungeon grid effects */
3376 #define RANDOM_NONE 0x00000000
3377 #define RANDOM_FEATURE 0x00000001
3378 #define RANDOM_MONSTER 0x00000002
3379 #define RANDOM_OBJECT 0x00000004
3380 #define RANDOM_EGO 0x00000008
3381 #define RANDOM_ARTIFACT 0x00000010
3382 #define RANDOM_TRAP 0x00000020
3385 typedef struct dungeon_grid dungeon_grid;
3389 int feature; /* Terrain feature */
3390 int monster; /* Monster */
3391 int object; /* Object */
3392 int ego; /* Ego-Item */
3393 int artifact; /* Artifact */
3394 int trap; /* Trap */
3395 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3396 int special; /* Reserved for special terrain info */
3397 int random; /* Number of the random effect */
3401 static dungeon_grid letter[255];
3405 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3407 static errr parse_line_feature(char *buf)
3413 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3415 /* Tokenize the line */
3416 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3418 /* Letter to assign */
3419 int index = zz[0][0];
3421 /* Reset the info for the letter */
3422 letter[index].feature = feat_none;
3423 letter[index].monster = 0;
3424 letter[index].object = 0;
3425 letter[index].ego = 0;
3426 letter[index].artifact = 0;
3427 letter[index].trap = feat_none;
3428 letter[index].cave_info = 0;
3429 letter[index].special = 0;
3430 letter[index].random = RANDOM_NONE;
3436 letter[index].special = atoi(zz[8]);
3440 if ((zz[7][0] == '*') && !zz[7][1])
3442 letter[index].random |= RANDOM_TRAP;
3446 letter[index].trap = f_tag_to_index(zz[7]);
3447 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3452 if (zz[6][0] == '*')
3454 letter[index].random |= RANDOM_ARTIFACT;
3455 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3457 else if (zz[6][0] == '!')
3459 if (p_ptr->inside_quest)
3461 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3466 letter[index].artifact = atoi(zz[6]);
3471 if (zz[5][0] == '*')
3473 letter[index].random |= RANDOM_EGO;
3474 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3478 letter[index].ego = atoi(zz[5]);
3483 if (zz[4][0] == '*')
3485 letter[index].random |= RANDOM_OBJECT;
3486 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3488 else if (zz[4][0] == '!')
3490 if (p_ptr->inside_quest)
3492 int a_idx = quest[p_ptr->inside_quest].k_idx;
3495 artifact_type *a_ptr = &a_info[a_idx];
3496 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3498 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3505 letter[index].object = atoi(zz[4]);
3510 if (zz[3][0] == '*')
3512 letter[index].random |= RANDOM_MONSTER;
3513 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3515 else if (zz[3][0] == 'c')
3517 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3518 letter[index].monster = - atoi(zz[3] + 1);
3522 letter[index].monster = atoi(zz[3]);
3527 letter[index].cave_info = atoi(zz[2]);
3531 if ((zz[1][0] == '*') && !zz[1][1])
3533 letter[index].random |= RANDOM_FEATURE;
3537 letter[index].feature = f_tag_to_index(zz[1]);
3538 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3551 * Process "B:<Index>:<Command>:..." -- Building definition
3553 static errr parse_line_building(char *buf)
3569 /* Get the building number */
3572 /* Find the colon after the building number */
3573 s = my_strchr(s, ':');
3575 /* Verify that colon */
3578 /* Nuke the colon, advance to the sub-index */
3581 /* Paranoia -- require a sub-index */
3582 if (!*s) return (1);
3584 /* Building definition sub-index */
3587 /* Building name, owner, race */
3590 if (tokenize(s + 2, 3, zz, 0) == 3)
3592 /* Name of the building */
3593 strcpy(building[index].name, zz[0]);
3595 /* Name of the owner */
3596 strcpy(building[index].owner_name, zz[1]);
3598 /* Race of the owner */
3599 strcpy(building[index].owner_race, zz[2]);
3604 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3607 /* Building Action */
3610 if (tokenize(s + 2, 8, zz, 0) >= 7)
3612 /* Index of the action */
3613 int action_index = atoi(zz[0]);
3615 /* Name of the action */
3616 strcpy(building[index].act_names[action_index], zz[1]);
3618 /* Cost of the action for members */
3619 building[index].member_costs[action_index] = atoi(zz[2]);
3621 /* Cost of the action for non-members */
3622 building[index].other_costs[action_index] = atoi(zz[3]);
3624 /* Letter assigned to the action */
3625 building[index].letters[action_index] = zz[4][0];
3628 building[index].actions[action_index] = atoi(zz[5]);
3630 /* Action restriction */
3631 building[index].action_restr[action_index] = atoi(zz[6]);
3636 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3639 /* Building Classes */
3642 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3644 for (i = 0; i < MAX_CLASS; i++)
3646 building[index].member_class[i] = atoi(zz[i]);
3652 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3655 /* Building Races */
3658 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3660 for (i = 0; i < MAX_RACES; i++)
3662 building[index].member_race[i] = atoi(zz[i]);
3668 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3671 /* Building Realms */
3674 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3676 for (i = 0; i < MAX_MAGIC; i++)
3678 building[index].member_realm[i+1] = atoi(zz[i]);
3684 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3689 /* Ignore scripts */
3695 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3704 * Place the object j_ptr to a grid
3706 static void drop_here(object_type *j_ptr, int y, int x)
3708 cave_type *c_ptr = &cave[y][x];
3711 /* Get new object */
3712 s16b o_idx = o_pop();
3714 /* Access new object */
3715 o_ptr = &o_list[o_idx];
3717 /* Structure copy */
3718 object_copy(o_ptr, j_ptr);
3726 o_ptr->held_m_idx = 0;
3729 o_ptr->next_o_idx = c_ptr->o_idx;
3731 /* Place the object */
3732 c_ptr->o_idx = o_idx;
3737 * Parse a sub-file of the "extra info"
3739 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3746 /* Skip "empty" lines */
3747 if (!buf[0]) return (0);
3749 /* Skip "blank" lines */
3750 if (isspace(buf[0])) return (0);
3753 if (buf[0] == '#') return (0);
3755 /* Require "?:*" format */
3756 if (buf[1] != ':') return (1);
3759 /* Process "%:<fname>" */
3762 /* Attempt to Process the given file */
3763 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3766 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3769 return parse_line_feature(buf);
3772 /* Process "D:<dungeon>" -- info for the cave grids */
3773 else if (buf[0] == 'D')
3775 object_type object_type_body;
3777 /* Acquire the text */
3780 /* Length of the text */
3781 int len = strlen(s);
3783 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3785 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3787 /* Access the grid */
3788 cave_type *c_ptr = &cave[*y][*x];
3792 int object_index = letter[idx].object;
3793 int monster_index = letter[idx].monster;
3794 int random = letter[idx].random;
3795 int artifact_index = letter[idx].artifact;
3797 /* Lay down a floor */
3798 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3800 /* Only the features */
3801 if (init_flags & INIT_ONLY_FEATURES) continue;
3804 c_ptr->info = letter[idx].cave_info;
3806 /* Create a monster */
3807 if (random & RANDOM_MONSTER)
3809 monster_level = base_level + monster_index;
3811 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3813 monster_level = base_level;
3815 else if (monster_index)
3817 int old_cur_num, old_max_num;
3820 if (monster_index < 0)
3822 monster_index = -monster_index;
3825 old_cur_num = r_info[monster_index].cur_num;
3826 old_max_num = r_info[monster_index].max_num;
3828 /* Make alive again */
3829 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3831 r_info[monster_index].cur_num = 0;
3832 r_info[monster_index].max_num = 1;
3835 /* Make alive again */
3836 /* Hack -- Non-unique Nazguls are semi-unique */
3837 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3839 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3841 r_info[monster_index].max_num++;
3846 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3850 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3852 /* Make alive again for real unique monster */
3853 r_info[monster_index].cur_num = old_cur_num;
3854 r_info[monster_index].max_num = old_max_num;
3858 /* Object (and possible trap) */
3859 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3861 object_level = base_level + object_index;
3864 * Random trap and random treasure defined
3865 * 25% chance for trap and 75% chance for object
3867 if (randint0(100) < 75)
3869 place_object(*y, *x, 0L);
3876 object_level = base_level;
3878 else if (random & RANDOM_OBJECT)
3880 object_level = base_level + object_index;
3882 /* Create an out of deep object */
3883 if (randint0(100) < 75)
3884 place_object(*y, *x, 0L);
3885 else if (randint0(100) < 80)
3886 place_object(*y, *x, AM_GOOD);
3888 place_object(*y, *x, AM_GOOD | AM_GREAT);
3890 object_level = base_level;
3893 else if (random & RANDOM_TRAP)
3897 /* Hidden trap (or door) */
3898 else if (letter[idx].trap)
3900 c_ptr->mimic = c_ptr->feat;
3901 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3903 else if (object_index)
3905 /* Get local object */
3906 object_type *o_ptr = &object_type_body;
3908 /* Create the item */
3909 object_prep(o_ptr, object_index);
3911 if (o_ptr->tval == TV_GOLD)
3913 coin_type = object_index - OBJ_GOLD_LIST;
3918 /* Apply magic (no messages, no artifacts) */
3919 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3921 drop_here(o_ptr, *y, *x);
3927 if (a_info[artifact_index].cur_num)
3929 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3931 object_type *q_ptr = &forge;
3933 object_prep(q_ptr, k_idx);
3935 /* Drop it in the dungeon */
3936 drop_here(q_ptr, *y, *x);
3940 /* Create the artifact */
3941 if (create_named_art(artifact_index, *y, *x))
3942 a_info[artifact_index].cur_num = 1;
3946 /* Terrain special */
3947 c_ptr->special = letter[idx].special;
3955 /* Process "Q:<number>:<command>:... -- quest info */
3956 else if (buf[0] == 'Q')
3963 num = tokenize(buf + 2, 33, zz, 0);
3967 num = tokenize(buf + 3, 33, zz, 0);
3970 /* Have we enough parameters? */
3971 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3974 q_ptr = &(quest[atoi(zz[0])]);
3976 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3977 if (zz[1][0] == 'Q')
3979 if (init_flags & INIT_ASSIGN)
3981 monster_race *r_ptr;
3982 artifact_type *a_ptr;
3984 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3986 q_ptr->type = atoi(zz[2]);
3987 q_ptr->num_mon = atoi(zz[3]);
3988 q_ptr->cur_num = atoi(zz[4]);
3989 q_ptr->max_num = atoi(zz[5]);
3990 q_ptr->level = atoi(zz[6]);
3991 q_ptr->r_idx = atoi(zz[7]);
3992 q_ptr->k_idx = atoi(zz[8]);
3993 q_ptr->dungeon = atoi(zz[9]);
3996 q_ptr->flags = atoi(zz[10]);
3998 r_ptr = &r_info[q_ptr->r_idx];
3999 if (r_ptr->flags1 & RF1_UNIQUE)
4000 r_ptr->flags1 |= RF1_QUESTOR;
4002 a_ptr = &a_info[q_ptr->k_idx];
4003 a_ptr->gen_flags |= TRG_QUESTITEM;
4008 else if (zz[1][0] == 'R')
4010 if (init_flags & INIT_ASSIGN)
4015 for (idx = 2; idx < num; idx++)
4017 int a_idx = atoi(zz[idx]);
4018 if (a_idx < 1) continue;
4019 if (a_info[a_idx].cur_num > 0) continue;
4021 if (one_in_(count)) reward_idx = a_idx;
4026 /* Set quest's rewarding artifact */
4027 q_ptr->k_idx = reward_idx;
4028 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4032 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4033 q_ptr->type = QUEST_TYPE_KILL_ALL;
4040 /* Process "Q:<q_index>:N:<name>" -- quest name */
4041 else if (zz[1][0] == 'N')
4043 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4045 strcpy(q_ptr->name, zz[2]);
4051 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4052 else if (zz[1][0] == 'T')
4054 if (init_flags & INIT_SHOW_TEXT)
4056 strcpy(quest_text[quest_text_line], zz[2]);
4064 /* Process "W:<command>: ..." -- info for the wilderness */
4065 else if (buf[0] == 'W')
4067 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4070 /* Process "P:<y>:<x>" -- player position */
4071 else if (buf[0] == 'P')
4073 if (init_flags & INIT_CREATE_DUNGEON)
4075 if (tokenize(buf + 2, 2, zz, 0) == 2)
4077 int panels_x, panels_y;
4079 /* Hack - Set the dungeon size */
4080 panels_y = (*y / SCREEN_HGT);
4081 if (*y % SCREEN_HGT) panels_y++;
4082 cur_hgt = panels_y * SCREEN_HGT;
4084 panels_x = (*x / SCREEN_WID);
4085 if (*x % SCREEN_WID) panels_x++;
4086 cur_wid = panels_x * SCREEN_WID;
4088 /* Assume illegal panel */
4089 panel_row_min = cur_hgt;
4090 panel_col_min = cur_wid;
4092 /* Place player in a quest level */
4093 if (p_ptr->inside_quest)
4097 /* Delete the monster (if any) */
4098 delete_monster(py, px);
4106 /* Place player in the town */
4107 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4109 p_ptr->oldpy = atoi(zz[0]);
4110 p_ptr->oldpx = atoi(zz[1]);
4118 /* Process "B:<Index>:<Command>:..." -- Building definition */
4119 else if (buf[0] == 'B')
4121 return parse_line_building(buf);
4124 /* Process "M:<type>:<maximum>" -- set maximum values */
4125 else if (buf[0] == 'M')
4127 if (tokenize(buf+2, 2, zz, 0) == 2)
4130 if (zz[0][0] == 'T')
4132 max_towns = atoi(zz[1]);
4135 /* Maximum quests */
4136 else if (zz[0][0] == 'Q')
4138 max_quests = atoi(zz[1]);
4142 else if (zz[0][0] == 'R')
4144 max_r_idx = atoi(zz[1]);
4148 else if (zz[0][0] == 'K')
4150 max_k_idx = atoi(zz[1]);
4154 else if (zz[0][0] == 'V')
4156 max_v_idx = atoi(zz[1]);
4160 else if (zz[0][0] == 'F')
4162 max_f_idx = atoi(zz[1]);
4166 else if (zz[0][0] == 'A')
4168 max_a_idx = atoi(zz[1]);
4172 else if (zz[0][0] == 'E')
4174 max_e_idx = atoi(zz[1]);
4178 else if (zz[0][0] == 'D')
4180 max_d_idx = atoi(zz[1]);
4184 else if (zz[0][0] == 'O')
4186 max_o_idx = atoi(zz[1]);
4190 else if (zz[0][0] == 'M')
4192 max_m_idx = atoi(zz[1]);
4195 /* Wilderness size */
4196 else if (zz[0][0] == 'W')
4198 /* Maximum wild_x_size */
4199 if (zz[0][1] == 'X')
4200 max_wild_x = atoi(zz[1]);
4201 /* Maximum wild_y_size */
4202 if (zz[0][1] == 'Y')
4203 max_wild_y = atoi(zz[1]);
4217 static cptr variant = "ZANGBAND";
4221 * Helper function for "process_dungeon_file()"
4223 static cptr process_dungeon_file_expr(char **sp, char *fp)
4239 while (isspace(*s)) s++;
4257 t = process_dungeon_file_expr(&s, &f);
4266 else if (streq(t, "IOR"))
4269 while (*s && (f != b2))
4271 t = process_dungeon_file_expr(&s, &f);
4272 if (*t && !streq(t, "0")) v = "1";
4277 else if (streq(t, "AND"))
4280 while (*s && (f != b2))
4282 t = process_dungeon_file_expr(&s, &f);
4283 if (*t && streq(t, "0")) v = "0";
4288 else if (streq(t, "NOT"))
4291 while (*s && (f != b2))
4293 t = process_dungeon_file_expr(&s, &f);
4294 if (*t && streq(t, "1")) v = "0";
4299 else if (streq(t, "EQU"))
4302 if (*s && (f != b2))
4304 t = process_dungeon_file_expr(&s, &f);
4306 while (*s && (f != b2))
4308 p = process_dungeon_file_expr(&s, &f);
4309 if (streq(t, p)) v = "1";
4314 else if (streq(t, "LEQ"))
4317 if (*s && (f != b2))
4319 t = process_dungeon_file_expr(&s, &f);
4321 while (*s && (f != b2))
4324 t = process_dungeon_file_expr(&s, &f);
4325 if (*t && atoi(p) > atoi(t)) v = "0";
4330 else if (streq(t, "GEQ"))
4333 if (*s && (f != b2))
4335 t = process_dungeon_file_expr(&s, &f);
4337 while (*s && (f != b2))
4340 t = process_dungeon_file_expr(&s, &f);
4342 /* Compare two numbers instead of string */
4343 if (*t && atoi(p) < atoi(t)) v = "0";
4350 while (*s && (f != b2))
4352 t = process_dungeon_file_expr(&s, &f);
4357 if (f != b2) v = "?x?x?";
4359 /* Extract final and Terminate */
4360 if ((f = *s) != '\0') *s++ = '\0';
4366 /* Accept all printables except spaces and brackets */
4368 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4370 if (iskanji(*s)) s++;
4374 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4377 /* Extract final and Terminate */
4378 if ((f = *s) != '\0') *s++ = '\0';
4384 if (streq(b+1, "SYS"))
4390 else if (streq(b+1, "GRAF"))
4395 else if (streq(b+1, "MONOCHROME"))
4404 else if (streq(b+1, "RACE"))
4407 v = rp_ptr->E_title;
4414 else if (streq(b+1, "CLASS"))
4417 v = cp_ptr->E_title;
4424 else if (streq(b+1, "REALM1"))
4427 v = E_realm_names[p_ptr->realm1];
4429 v = realm_names[p_ptr->realm1];
4434 else if (streq(b+1, "REALM2"))
4437 v = E_realm_names[p_ptr->realm2];
4439 v = realm_names[p_ptr->realm2];
4444 else if (streq(b+1, "PLAYER"))
4446 static char tmp_player_name[32];
4448 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4458 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4461 v = tmp_player_name;
4465 else if (streq(b+1, "TOWN"))
4467 sprintf(tmp, "%d", p_ptr->town_num);
4472 else if (streq(b+1, "LEVEL"))
4474 sprintf(tmp, "%d", p_ptr->lev);
4478 /* Current quest number */
4479 else if (streq(b+1, "QUEST_NUMBER"))
4481 sprintf(tmp, "%d", p_ptr->inside_quest);
4485 /* Number of last quest */
4486 else if (streq(b+1, "LEAVING_QUEST"))
4488 sprintf(tmp, "%d", leaving_quest);
4493 else if (prefix(b+1, "QUEST_TYPE"))
4495 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4496 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4501 else if (prefix(b+1, "QUEST"))
4503 /* "QUEST" uses a special parameter to determine the number of the quest */
4504 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4509 else if (prefix(b+1, "RANDOM"))
4511 /* "RANDOM" uses a special parameter to determine the number of the quest */
4512 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4517 else if (streq(b+1, "VARIANT"))
4523 else if (streq(b+1, "WILDERNESS"))
4526 sprintf(tmp, "NONE");
4528 sprintf(tmp, "LITE");
4530 sprintf(tmp, "NORMAL");
4553 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4563 bool bypass = FALSE;
4565 int x = xmin, y = ymin;
4568 /* Build the filename */
4569 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4572 fp = my_fopen(buf, "r");
4575 if (!fp) return (-1);
4578 /* Process the file */
4579 while (0 == my_fgets(fp, buf, sizeof(buf)))
4585 /* Skip "empty" lines */
4586 if (!buf[0]) continue;
4588 /* Skip "blank" lines */
4589 if (isspace(buf[0])) continue;
4592 if (buf[0] == '#') continue;
4595 /* Process "?:<expr>" */
4596 if ((buf[0] == '?') && (buf[1] == ':'))
4605 /* Parse the expr */
4606 v = process_dungeon_file_expr(&s, &f);
4609 bypass = (streq(v, "0") ? TRUE : FALSE);
4615 /* Apply conditionals */
4616 if (bypass) continue;
4618 /* Process the line */
4619 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4631 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4634 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4636 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4638 msg_format("Parsing '%s'.", buf);
4645 /* Close the file */
4655 void write_r_info_txt(void)
4657 int i, j, z, fc, bc;
4660 cptr flags[32 * 10];
4665 monster_race *r_ptr;
4667 monster_blow *b_ptr;
4669 FILE *fff = fopen("output.txt", "wt");
4677 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4679 fprintf(fff, "# Version stamp (required)\n\n");
4682 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4685 fprintf(fff, "##### The Player #####\n\n");
4687 for (z = -1; z < alloc_race_size; z++)
4689 /* Output the monsters in order */
4690 i = (z >= 0) ? alloc_race_table[z].index : 0;
4692 /* Acquire the monster */
4695 /* Ignore empty monsters */
4696 if (!strlen(r_name + r_ptr->name)) continue;
4698 /* Ignore useless monsters */
4699 if (i && !r_ptr->speed) continue;
4701 /* Write a note if necessary */
4702 if (i && (!r_ptr->level != !mode))
4707 fprintf(fff, "\n##### Town monsters #####\n\n");
4709 /* Note the dungeon */
4712 fprintf(fff, "\n##### Normal monsters #####\n\n");
4715 /* Record the change */
4716 mode = r_ptr->level;
4719 /* Acquire the flags */
4720 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4721 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4722 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4723 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4724 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4725 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4726 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4727 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4728 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4729 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4731 /* Write New/Number/Name */
4732 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4735 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4737 /* Write Information */
4738 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4739 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4741 /* Write more information */
4742 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4745 for(j = 0; j < 4; j++)
4747 b_ptr = &(r_ptr->blow[j]);
4749 /* Stop when done */
4750 if (!b_ptr->method) break;
4752 /* Write the blows */
4753 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4754 r_info_blow_effect[b_ptr->effect],
4755 b_ptr->d_dice, b_ptr->d_side);
4758 /* Extract the flags */
4759 for (fc = 0, j = 0; j < 32 * 3; j++)
4761 /* Check this flag */
4762 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4765 /* Extract the extra flags */
4766 for (j = 32 * 6; j < 32 * 10; j++)
4768 /* Check this flag */
4769 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4772 /* Write the flags */
4773 for (j = 0; j < fc;)
4777 /* Start the line */
4780 for (bc = 0; (bc < 60) && (j < fc); j++)
4784 /* Format the flag */
4785 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4787 /* Add it to the buffer */
4790 /* Note the length */
4794 /* Done with this line; write it */
4795 fprintf(fff, "%s\n", buf);
4798 /* Write Spells if applicable */
4799 if (r_ptr->freq_spell)
4801 /* Write the frequency */
4802 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4804 /* Extract the spell flags */
4805 for (fc = 0, j = 96; j < 192; j++)
4807 /* Check this flag */
4808 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4811 /* Write the flags */
4812 for (j = 0; j < fc;)
4816 /* Start the line */
4819 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4823 /* Format the flag */
4824 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4828 /* Note the length */
4835 /* Done with this line; write it */
4836 fprintf(fff, "%s\n", buf);
4840 /* Acquire the description */
4841 desc = r_text + r_ptr->text;
4842 dlen = strlen(desc);
4844 /* Write Description */
4845 for (j = 0; j < dlen;)
4849 /* Start the line */
4852 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4860 /* Done with this line; write it */
4861 fprintf(fff, "%s\n", buf);
4864 /* Space between entries */