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[] =
780 static cptr k_info_gen_flags[] =
819 struct k_info_activation_flag
823 } k_info_activation_flags[] =
825 { "SUNLIGHT", ACT_SUNLIGHT },
826 { "BO_MISS_1", ACT_BO_MISS_1 },
827 { "BA_POIS_1", ACT_BA_POIS_1 },
828 { "BO_ELEC_1", ACT_BO_ELEC_1 },
829 { "BO_ACID_1", ACT_BO_ACID_1 },
830 { "BO_COLD_1", ACT_BO_COLD_1 },
831 { "BO_FIRE_1", ACT_BO_FIRE_1 },
832 { "BA_COLD_1", ACT_BA_COLD_1 },
833 { "BA_FIRE_1", ACT_BA_FIRE_1 },
834 { "DRAIN_1", ACT_DRAIN_1 },
835 { "BA_COLD_2", ACT_BA_COLD_2 },
836 { "BA_ELEC_2", ACT_BA_ELEC_2 },
837 { "DRAIN_2", ACT_DRAIN_2 },
838 { "VAMPIRE_1", ACT_VAMPIRE_1 },
839 { "BO_MISS_2", ACT_BO_MISS_2 },
840 { "BA_FIRE_2", ACT_BA_FIRE_2 },
841 { "BA_COLD_3", ACT_BA_COLD_3 },
842 { "BA_ELEC_3", ACT_BA_ELEC_3 },
843 { "WHIRLWIND", ACT_WHIRLWIND },
844 { "VAMPIRE_2", ACT_VAMPIRE_2 },
845 { "CALL_CHAOS", ACT_CALL_CHAOS },
846 { "ROCKET", ACT_ROCKET },
847 { "DISP_EVIL", ACT_DISP_EVIL },
848 { "BA_MISS_3", ACT_BA_MISS_3 },
849 { "DISP_GOOD", ACT_DISP_GOOD },
851 { "CONFUSE", ACT_CONFUSE },
852 { "SLEEP", ACT_SLEEP },
853 { "QUAKE", ACT_QUAKE },
854 { "TERROR", ACT_TERROR },
855 { "TELE_AWAY", ACT_TELE_AWAY },
856 { "BANISH_EVIL", ACT_BANISH_EVIL },
857 { "GENOCIDE", ACT_GENOCIDE },
858 { "MASS_GENO", ACT_MASS_GENO },
860 { "CHARM_ANIMAL", ACT_CHARM_ANIMAL },
861 { "CHARM_UNDEAD", ACT_CHARM_UNDEAD },
862 { "CHARM_OTHER", ACT_CHARM_OTHER },
863 { "CHARM_ANIMALS", ACT_CHARM_ANIMALS },
864 { "CHARM_OTHERS", ACT_CHARM_OTHERS },
865 { "SUMMON_ANIMAL", ACT_SUMMON_ANIMAL },
866 { "SUMMON_PHANTOM", ACT_SUMMON_PHANTOM },
867 { "SUMMON_ELEMENTAL", ACT_SUMMON_ELEMENTAL },
868 { "SUMMON_DEMON", ACT_SUMMON_DEMON },
869 { "SUMMON_UNDEAD", ACT_SUMMON_UNDEAD },
871 { "CURE_LW", ACT_CURE_LW },
872 { "CURE_MW", ACT_CURE_MW },
873 { "CURE_POISON", ACT_CURE_POISON },
874 { "REST_LIFE", ACT_REST_LIFE },
875 { "REST_ALL", ACT_REST_ALL },
876 { "CURE_700", ACT_CURE_700 },
877 { "CURE_1000", ACT_CURE_1000 },
880 { "BERSERK", ACT_BERSERK },
881 { "PROT_EVIL", ACT_PROT_EVIL },
882 { "RESIST_ALL", ACT_RESIST_ALL },
883 { "SPEED", ACT_SPEED },
884 { "XTRA_SPEED", ACT_XTRA_SPEED },
885 { "WRAITH", ACT_WRAITH },
886 { "INVULN", ACT_INVULN },
888 { "LIGHT", ACT_LIGHT },
889 { "MAP_LIGHT", ACT_MAP_LIGHT },
890 { "DETECT_ALL", ACT_DETECT_ALL },
891 { "DETECT_XTRA", ACT_DETECT_XTRA },
892 { "ID_FULL", ACT_ID_FULL },
893 { "ID_PLAIN", ACT_ID_PLAIN },
894 { "RUNE_EXPLO", ACT_RUNE_EXPLO },
895 { "RUNE_PROT", ACT_RUNE_PROT },
896 { "SATIATE", ACT_SATIATE },
897 { "DEST_DOOR", ACT_DEST_DOOR },
898 { "STONE_MUD", ACT_STONE_MUD },
899 { "RECHARGE", ACT_RECHARGE },
900 { "ALCHEMY", ACT_ALCHEMY },
901 { "DIM_DOOR", ACT_DIM_DOOR },
902 { "TELEPORT", ACT_TELEPORT },
903 { "RECALL", ACT_RECALL },
911 static cptr d_info_flags1[] =
949 * Add a text to the text-storage and store offset to it.
951 * Returns FALSE when there isn't enough space available to store
954 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
956 /* Hack -- Verify space */
957 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
963 /* Advance and save the text index */
964 *offset = ++head->text_size;
967 /* Additional text */
968 else if (normal_text)
971 * If neither the end of the last line nor
972 * the beginning of current line is not a space,
973 * fill up a space as a correct separator of two words.
975 if (head->text_size > 0 &&
977 (*(head->text_ptr + head->text_size - 1) != ' ') &&
978 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
979 (buf[0] != ' ') && !iskanji(buf[0])
981 (*(head->text_ptr + head->text_size - 1) != ' ') &&
987 *(head->text_ptr + head->text_size) = ' ';
989 /* Advance the index */
994 /* Append chars to the text */
995 strcpy(head->text_ptr + head->text_size, buf);
997 /* Advance the index */
998 head->text_size += strlen(buf);
1006 * Add a name to the name-storage and return an offset to it.
1008 * Returns FALSE when there isn't enough space available to store
1011 static bool add_name(u32b *offset, header *head, cptr buf)
1013 /* Hack -- Verify space */
1014 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1020 /* Advance and save the name index */
1021 *offset = ++head->name_size;
1024 /* Append chars to the names */
1025 strcpy(head->name_ptr + head->name_size, buf);
1027 /* Advance the index */
1028 head->name_size += strlen(buf);
1036 * Add a tag to the tag-storage and return an offset to it.
1038 * Returns FALSE when there isn't enough space available to store
1041 static bool add_tag(s16b *offset, header *head, cptr buf)
1045 /* Search for an existing (fake) tag */
1046 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1049 if (streq(&head->tag_ptr[i], buf)) break;
1052 /* There was no existing tag */
1053 if (i >= head->tag_size)
1055 /* Hack -- Verify space */
1056 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1059 /* Append chars to the tags */
1060 strcpy(head->tag_ptr + head->tag_size, buf);
1062 /* Point the new tag */
1065 /* Advance the index */
1066 head->tag_size += strlen(buf) + 1;
1069 /* Return offset of the tag */
1078 * Convert a "color letter" into an "actual" color
1079 * The colors are: dwsorgbuDWvyRGBU, as shown below
1081 byte color_char_to_attr(char c)
1085 case 'd': return (TERM_DARK);
1086 case 'w': return (TERM_WHITE);
1087 case 's': return (TERM_SLATE);
1088 case 'o': return (TERM_ORANGE);
1089 case 'r': return (TERM_RED);
1090 case 'g': return (TERM_GREEN);
1091 case 'b': return (TERM_BLUE);
1092 case 'u': return (TERM_UMBER);
1094 case 'D': return (TERM_L_DARK);
1095 case 'W': return (TERM_L_WHITE);
1096 case 'v': return (TERM_VIOLET);
1097 case 'y': return (TERM_YELLOW);
1098 case 'R': return (TERM_L_RED);
1099 case 'G': return (TERM_L_GREEN);
1100 case 'B': return (TERM_L_BLUE);
1101 case 'U': return (TERM_L_UMBER);
1109 /*** Initialize from ascii template files ***/
1113 * Initialize an "*_info" array, by parsing an ascii "template" file
1115 errr init_info_txt(FILE *fp, char *buf, header *head,
1116 parse_info_txt_func parse_info_txt_line)
1120 /* Just before the first record */
1123 /* Just before the first line */
1127 /* Prepare the "fake" stuff */
1128 head->name_size = 0;
1129 head->text_size = 0;
1133 while (0 == my_fgets(fp, buf, 1024))
1135 /* Advance the line number */
1138 /* Skip comments and blank lines */
1139 if (!buf[0] || (buf[0] == '#')) continue;
1141 /* Verify correct "colon" format */
1142 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1145 /* Hack -- Process 'V' for "Version" */
1152 /* Mega Hack -- Calculate Check Sum */
1153 if (buf[0] != 'N' && buf[0] != 'D')
1156 for (i = 0; buf[i]; i++)
1158 head->v_extra += (byte)buf[i];
1159 head->v_extra ^= (1 << (i % 8));
1163 /* Parse the line */
1164 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1169 /* Complete the "name" and "text" sizes */
1170 if (head->name_size) head->name_size++;
1171 if (head->text_size) head->text_size++;
1179 * Initialize the "v_info" array, by parsing an ascii "template" file
1181 errr parse_v_info(char *buf, header *head)
1187 static vault_type *v_ptr = NULL;
1189 /* Process 'N' for "New/Number/Name" */
1192 /* Find the colon before the name */
1193 s = my_strchr(buf+2, ':');
1195 /* Verify that colon */
1198 /* Nuke the colon, advance to the name */
1201 /* Paranoia -- require a name */
1202 if (!*s) return (1);
1207 /* Verify information */
1208 if (i <= error_idx) return (4);
1210 /* Verify information */
1211 if (i >= head->info_num) return (2);
1213 /* Save the index */
1216 /* Point at the "info" */
1219 /* Store the name */
1220 if (!add_name(&v_ptr->name, head, s)) return (7);
1223 /* There better be a current v_ptr */
1224 else if (!v_ptr) return (3);
1226 /* Process 'D' for "Description" */
1227 else if (buf[0] == 'D')
1229 /* Acquire the text */
1232 /* Store the text */
1233 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1236 /* Process 'X' for "Extra info" (one line only) */
1237 else if (buf[0] == 'X')
1239 int typ, rat, hgt, wid;
1241 /* Scan for the values */
1242 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1243 &typ, &rat, &hgt, &wid)) return (1);
1245 /* Save the values */
1262 * Initialize the "s_info" array, by parsing an ascii "template" file
1264 errr parse_s_info(char *buf, header *head)
1269 static skill_table *s_ptr = NULL;
1272 /* Process 'N' for "New/Number/Name" */
1278 /* Verify information */
1279 if (i <= error_idx) return (4);
1281 /* Verify information */
1282 if (i >= head->info_num) return (2);
1284 /* Save the index */
1287 /* Point at the "info" */
1291 /* There better be a current s_ptr */
1292 else if (!s_ptr) return (3);
1294 /* Process 'W' for "Weapon exp" */
1295 else if (buf[0] == 'W')
1297 int tval, sval, start, max;
1298 const s16b exp_conv_table[] =
1300 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1301 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1304 /* Scan for the values */
1305 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1306 &tval, &sval, &start, &max)) return (1);
1308 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1309 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1311 /* Save the values */
1312 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1313 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1316 /* Process 'S' for "Skill exp" */
1317 else if (buf[0] == 'S')
1319 int num, start, max;
1321 /* Scan for the values */
1322 if (3 != sscanf(buf+2, "%d:%d:%d",
1323 &num, &start, &max)) return (1);
1325 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1326 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1328 /* Save the values */
1329 s_ptr->s_start[num] = start;
1330 s_ptr->s_max[num] = max;
1343 * Initialize the "m_info" array, by parsing an ascii "template" file
1345 errr parse_m_info(char *buf, header *head)
1352 static player_magic *m_ptr = NULL;
1355 static int realm, magic_idx = 0, readable = 0;
1358 /* Process 'N' for "New/Number/Name" */
1364 /* Verify information */
1365 if (i <= error_idx) return (4);
1367 /* Verify information */
1368 if (i >= head->info_num) return (2);
1370 /* Save the index */
1373 /* Point at the "info" */
1377 /* There better be a current m_ptr */
1378 else if (!m_ptr) return (3);
1380 /* Process 'I' for "Info" (one line only) */
1381 else if (buf[0] == 'I')
1384 int xtra, type, first, weight;
1386 /* Find the colon before the name */
1387 s = my_strchr(buf+2, ':');
1389 /* Verify that colon */
1392 /* Nuke the colon, advance to the name */
1397 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1398 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1399 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1400 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1401 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1406 /* Find the colon before the name */
1407 s = my_strchr(s, ':');
1409 /* Verify that colon */
1412 /* Nuke the colon, advance to the name */
1415 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1416 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1417 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1418 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1419 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1420 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1424 /* Scan for the values */
1425 if (4 != sscanf(s, "%x:%d:%d:%d",
1426 (uint *)&xtra, &type, &first, &weight)) return (1);
1428 m_ptr->spell_xtra = xtra;
1429 m_ptr->spell_type = type;
1430 m_ptr->spell_first = first;
1431 m_ptr->spell_weight = weight;
1435 /* Process 'R' for "Realm" (one line only) */
1436 else if (buf[0] == 'R')
1438 /* Scan for the values */
1439 if (2 != sscanf(buf+2, "%d:%d",
1440 &realm, &readable)) return (1);
1445 else if (buf[0] == 'T')
1447 int level, mana, fail, exp;
1449 if (!readable) return (1);
1450 /* Scan for the values */
1451 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1452 &level, &mana, &fail, &exp)) return (1);
1454 m_ptr->info[realm][magic_idx].slevel = level;
1455 m_ptr->info[realm][magic_idx].smana = mana;
1456 m_ptr->info[realm][magic_idx].sfail = fail;
1457 m_ptr->info[realm][magic_idx].sexp = exp;
1471 * Grab one flag from a textual string
1473 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1478 for (i = 0; i < 32; i++)
1480 if (streq(what, names[i]))
1482 *flags |= (1L << i);
1492 * Grab one flag in an feature_type from a textual string
1494 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1499 for (i = 0; i < FF_FLAG_MAX; i++)
1501 if (streq(what, f_info_flags[i]))
1503 add_flag(f_ptr->flags, i);
1510 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1512 msg_format("Unknown feature flag '%s'.", what);
1516 return PARSE_ERROR_GENERIC;
1521 * Grab an action in an feature_type from a textual string
1523 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1528 for (i = 0; i < FF_FLAG_MAX; i++)
1530 if (streq(what, f_info_flags[i]))
1532 f_ptr->state[count].action = i;
1539 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1541 msg_format("Unknown feature action '%s'.", what);
1545 return PARSE_ERROR_GENERIC;
1550 * Initialize the "f_info" array, by parsing an ascii "template" file
1552 errr parse_f_info(char *buf, header *head)
1559 static feature_type *f_ptr = NULL;
1562 /* Process 'N' for "New/Number/Name" */
1565 /* Find the colon before the name */
1566 s = my_strchr(buf+2, ':');
1570 /* Nuke the colon, advance to the name */
1577 /* Verify information */
1578 if (i <= error_idx) return (4);
1580 /* Verify information */
1581 if (i >= head->info_num) return (2);
1583 /* Save the index */
1586 /* Point at the "info" */
1589 /* Tag name is given */
1593 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1596 /* Default "mimic" */
1599 /* Default "destroyed state" -- if not specified */
1600 f_ptr->destroyed = i;
1602 /* Default "states" */
1603 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1606 /* There better be a current f_ptr */
1607 else if (!f_ptr) return (3);
1610 else if (buf[0] == 'J')
1612 /* Store the name */
1613 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1616 else if (buf[0] == 'E')
1618 /* Ignore english name */
1621 else if (buf[0] == 'J')
1623 /* Ignore Japanese name */
1626 else if (buf[0] == 'E')
1628 /* Acquire the Text */
1631 /* Store the name */
1632 if (!add_name(&f_ptr->name, head, s)) return (7);
1637 /* Process 'M' for "Mimic" (one line only) */
1638 else if (buf[0] == 'M')
1642 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1644 /* Record a fake tag index */
1645 f_ptr->mimic = -offset;
1649 /* Process 'G' for "Graphics" (one line only) */
1650 else if (buf[0] == 'G')
1654 char char_tmp[F_LIT_MAX];
1657 if (buf[1] != ':') return (1);
1658 if (!buf[2]) return (1);
1659 if (buf[3] != ':') return (1);
1660 if (!buf[4]) return (1);
1662 /* Extract the char */
1663 char_tmp[F_LIT_STANDARD] = buf[2];
1665 /* Extract the color */
1666 s_attr = color_char_to_attr(buf[4]);
1669 if (s_attr > 127) return (1);
1671 /* Save the standard values */
1672 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1673 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1675 /* Is this feature supports lighting? */
1678 /* G:c:a:LIT (default) */
1679 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1681 /* G:c:a:lc:la:dc:da */
1682 if (!streq(buf + 6, "LIT"))
1684 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1686 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1687 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1688 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1689 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1691 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1693 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1696 /* Use default lighting */
1699 /* No lighting support */
1700 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1703 /* Extract the color */
1704 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1705 if (f_ptr->d_attr[j] > 127) return 1;
1708 f_ptr->d_char[j] = char_tmp[j];
1714 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1716 f_ptr->d_attr[j] = s_attr;
1717 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1723 /* Hack -- Process 'F' for flags */
1724 else if (buf[0] == 'F')
1726 /* Parse every entry textually */
1727 for (s = buf + 2; *s; )
1729 /* Find the end of this entry */
1730 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1732 /* Nuke and skip any dividers */
1736 while (*t == ' ' || *t == '|') t++;
1739 /* XXX XXX XXX Hack -- Read feature subtype */
1740 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1742 /* Extract a "subtype" */
1745 /* Start at next entry */
1752 /* XXX XXX XXX Hack -- Read feature power */
1753 if (1 == sscanf(s, "POWER_%d", &i))
1755 /* Extract a "power" */
1758 /* Start at next entry */
1765 /* Parse this entry */
1766 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1768 /* Start the next entry */
1773 /* Process 'W' for "More Info" (one line only) */
1774 else if (buf[0] == 'W')
1778 /* Scan for the value */
1779 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1781 /* Save the value */
1782 f_ptr->priority = priority;
1785 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1786 else if (buf[0] == 'K')
1790 /* Find the next empty state slot (if any) */
1791 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1793 /* Oops, no more slots */
1794 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1796 /* Analyze the first field */
1797 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1799 /* Terminate the field (if necessary) */
1800 if (*t == ':') *t++ = '\0';
1802 /* Is this default entry? */
1803 if (streq(s, "DESTROYED"))
1805 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1807 /* Record a fake tag index */
1808 f_ptr->destroyed = -offset;
1813 f_ptr->state[i].action = 0;
1815 /* Parse this entry */
1816 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1818 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1820 /* Record a fake tag index */
1821 f_ptr->state[i].result = -offset;
1834 * Convert a fake tag to a real feat index
1836 s16b f_tag_to_index(cptr str)
1840 /* Search for real index corresponding to this fake tag */
1841 for (i = 0; i < f_head.info_num; i++)
1843 if (streq(f_tag + f_info[i].tag, str))
1845 /* Return the index */
1856 * Search for real index corresponding to this fake tag
1858 static void search_real_feat(s16b *feat)
1862 /* Don't convert non-fake tag */
1863 if (*feat >= 0) return;
1865 /* Search for real index corresponding to this fake tag */
1866 for (i = 0; i < f_head.info_num; i++)
1868 if ((-(*feat)) == f_info[i].tag)
1870 /* Record real index */
1878 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1880 msg_format("%s is undefined.", f_tag + (-(*feat)));
1886 * Retouch fake tags of f_info
1888 void retouch_f_info(header *head)
1892 /* Convert fake tags to real feat indices */
1893 for (i = 0; i < head->info_num; i++)
1895 feature_type *f_ptr = &f_info[i];
1898 search_real_feat(&f_ptr->mimic);
1900 search_real_feat(&f_ptr->destroyed);
1902 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1908 * Grab one flag in an object_kind from a textual string
1910 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1915 for (i = 0; i < TR_FLAG_MAX; i++)
1917 if (streq(what, k_info_flags[i]))
1919 add_flag(k_ptr->flags, i);
1924 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1929 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1931 msg_format("Unknown object flag '%s'.", what);
1941 * Initialize the "k_info" array, by parsing an ascii "template" file
1943 errr parse_k_info(char *buf, header *head)
1950 static object_kind *k_ptr = NULL;
1953 /* Process 'N' for "New/Number/Name" */
1960 /* Find the colon before the name */
1961 s = my_strchr(buf+2, ':');
1963 /* Verify that colon */
1966 /* Nuke the colon, advance to the name */
1972 /* Verify information */
1973 if (i <= error_idx) return (4);
1975 /* Verify information */
1976 if (i >= head->info_num) return (2);
1978 /* Save the index */
1981 /* Point at the "info" */
1985 /* Paranoia -- require a name */
1986 if (!*s) return (1);
1988 /* Find the colon before the flavor */
1989 flavor = my_strchr(s, ':');
1991 /* Verify that colon */
1994 /* Nuke the colon, advance to the flavor */
1997 /* Store the flavor */
1998 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2001 /* Store the name */
2002 if (!add_name(&k_ptr->name, head, s)) return (7);
2006 /* There better be a current k_ptr */
2007 else if (!k_ptr) return (3);
2011 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2012 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2013 else if (buf[0] == 'E')
2018 else if (buf[0] == 'E')
2022 /* Acquire the name */
2025 /* Find the colon before the flavor */
2026 flavor = my_strchr(s, ':');
2028 /* Verify that colon */
2031 /* Nuke the colon, advance to the flavor */
2034 /* Store the flavor */
2035 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2038 /* Store the name */
2039 if (!add_name(&k_ptr->name, head, s)) return (7);
2043 /* Process 'D' for "Description" */
2044 else if (buf[0] == 'D')
2049 /* Acquire the text */
2054 /* Acquire the text */
2058 /* Store the text */
2059 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2062 /* Process 'G' for "Graphics" (one line only) */
2063 else if (buf[0] == 'G')
2069 if (buf[1] != ':') return (1);
2070 if (!buf[2]) return (1);
2071 if (buf[3] != ':') return (1);
2072 if (!buf[4]) return (1);
2074 /* Extract the char */
2077 /* Extract the attr */
2078 tmp = color_char_to_attr(buf[4]);
2081 if (tmp > 127) return (1);
2083 /* Save the values */
2084 k_ptr->d_attr = tmp;
2085 k_ptr->d_char = sym;
2088 /* Process 'I' for "Info" (one line only) */
2089 else if (buf[0] == 'I')
2091 int tval, sval, pval;
2093 /* Scan for the values */
2094 if (3 != sscanf(buf+2, "%d:%d:%d",
2095 &tval, &sval, &pval)) return (1);
2097 /* Save the values */
2103 /* Process 'W' for "More Info" (one line only) */
2104 else if (buf[0] == 'W')
2106 int level, extra, wgt;
2109 /* Scan for the values */
2110 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2111 &level, &extra, &wgt, &cost)) return (1);
2113 /* Save the values */
2114 k_ptr->level = level;
2115 k_ptr->extra = extra;
2116 k_ptr->weight = wgt;
2120 /* Process 'A' for "Allocation" (one line only) */
2121 else if (buf[0] == 'A')
2125 /* XXX XXX XXX Simply read each number following a colon */
2126 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2128 /* Default chance */
2129 k_ptr->chance[i] = 1;
2131 /* Store the attack damage index */
2132 k_ptr->locale[i] = atoi(s+1);
2134 /* Find the slash */
2135 t = my_strchr(s+1, '/');
2137 /* Find the next colon */
2138 s = my_strchr(s+1, ':');
2140 /* If the slash is "nearby", use it */
2141 if (t && (!s || t < s))
2143 int chance = atoi(t+1);
2144 if (chance > 0) k_ptr->chance[i] = chance;
2149 /* Hack -- Process 'P' for "power" and such */
2150 else if (buf[0] == 'P')
2152 int ac, hd1, hd2, th, td, ta;
2154 /* Scan for the values */
2155 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2156 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2166 /* Hack -- Process 'F' for flags */
2167 else if (buf[0] == 'F')
2169 /* Parse every entry textually */
2170 for (s = buf + 2; *s; )
2172 /* Find the end of this entry */
2173 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2175 /* Nuke and skip any dividers */
2179 while (*t == ' ' || *t == '|') t++;
2182 /* Parse this entry */
2183 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2185 /* Start the next entry */
2201 * Grab one flag in an artifact_type from a textual string
2203 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2208 for (i = 0; i < TR_FLAG_MAX; i++)
2210 if (streq(what, k_info_flags[i]))
2212 add_flag(a_ptr->flags, i);
2217 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2222 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2224 msg_format("Unknown artifact flag '%s'.", what);
2233 * Grab one activation index flag
2235 static byte grab_one_activation_flag(cptr what)
2241 if (k_info_activation_flags[i].flag == NULL) break;
2243 if (streq(what, k_info_activation_flags[i].flag))
2245 return k_info_activation_flags[i].index;
2257 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
2259 msg_format("Unknown activation flag '%s'.", what);
2268 * Initialize the "a_info" array, by parsing an ascii "template" file
2270 errr parse_a_info(char *buf, header *head)
2277 static artifact_type *a_ptr = NULL;
2280 /* Process 'N' for "New/Number/Name" */
2283 /* Find the colon before the name */
2284 s = my_strchr(buf+2, ':');
2286 /* Verify that colon */
2289 /* Nuke the colon, advance to the name */
2292 /* Paranoia -- require a name */
2293 if (!*s) return (1);
2298 /* Verify information */
2299 if (i < error_idx) return (4);
2301 /* Verify information */
2302 if (i >= head->info_num) return (2);
2304 /* Save the index */
2307 /* Point at the "info" */
2310 /* Ignore everything */
2311 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2312 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2313 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2314 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2316 /* Store the name */
2317 if (!add_name(&a_ptr->name, head, s)) return (7);
2321 /* There better be a current a_ptr */
2322 else if (!a_ptr) return (3);
2326 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2327 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2328 else if (buf[0] == 'E')
2333 else if (buf[0] == 'E')
2335 /* Acquire the Text */
2338 /* Store the name */
2339 if (!add_name(&a_ptr->name, head, s)) return (7);
2343 /* Process 'D' for "Description" */
2344 else if (buf[0] == 'D')
2349 /* Acquire the text */
2354 /* Acquire the text */
2358 /* Store the text */
2359 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2363 /* Process 'I' for "Info" (one line only) */
2364 else if (buf[0] == 'I')
2366 int tval, sval, pval;
2368 /* Scan for the values */
2369 if (3 != sscanf(buf+2, "%d:%d:%d",
2370 &tval, &sval, &pval)) return (1);
2372 /* Save the values */
2378 /* Process 'W' for "More Info" (one line only) */
2379 else if (buf[0] == 'W')
2381 int level, rarity, wgt;
2384 /* Scan for the values */
2385 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2386 &level, &rarity, &wgt, &cost)) return (1);
2388 /* Save the values */
2389 a_ptr->level = level;
2390 a_ptr->rarity = rarity;
2391 a_ptr->weight = wgt;
2395 /* Hack -- Process 'P' for "power" and such */
2396 else if (buf[0] == 'P')
2398 int ac, hd1, hd2, th, td, ta;
2400 /* Scan for the values */
2401 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2402 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2412 /* Hack -- Process 'U' for activation index */
2413 else if (buf[0] == 'U')
2416 n = grab_one_activation_flag(buf + 2);
2427 /* Hack -- Process 'F' for flags */
2428 else if (buf[0] == 'F')
2430 /* Parse every entry textually */
2431 for (s = buf + 2; *s; )
2433 /* Find the end of this entry */
2434 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2436 /* Nuke and skip any dividers */
2440 while ((*t == ' ') || (*t == '|')) t++;
2443 /* Parse this entry */
2444 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2446 /* Start the next entry */
2462 * Grab one flag in a ego-item_type from a textual string
2464 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2469 for (i = 0; i < TR_FLAG_MAX; i++)
2471 if (streq(what, k_info_flags[i]))
2473 add_flag(e_ptr->flags, i);
2478 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2483 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2485 msg_format("Unknown ego-item flag '%s'.", what);
2497 * Initialize the "e_info" array, by parsing an ascii "template" file
2499 errr parse_e_info(char *buf, header *head)
2506 static ego_item_type *e_ptr = NULL;
2509 /* Just before the first record */
2512 /* Just before the first line */
2516 /* Process 'N' for "New/Number/Name" */
2519 /* Find the colon before the name */
2520 s = my_strchr(buf+2, ':');
2522 /* Verify that colon */
2525 /* Nuke the colon, advance to the name */
2528 /* Paranoia -- require a name */
2529 if (!*s) return (1);
2534 /* Verify information */
2535 if (i < error_idx) return (4);
2537 /* Verify information */
2538 if (i >= head->info_num) return (2);
2540 /* Save the index */
2543 /* Point at the "info" */
2546 /* Store the name */
2547 if (!add_name(&e_ptr->name, head, s)) return (7);
2551 /* There better be a current e_ptr */
2552 else if (!e_ptr) return (3);
2556 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2557 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2558 else if (buf[0] == 'E')
2563 else if (buf[0] == 'E')
2565 /* Acquire the Text */
2568 /* Store the name */
2569 if (!add_name(&e_ptr->name, head, s)) return (7);
2574 /* Process 'D' for "Description" */
2575 else if (buf[0] == 'D')
2577 /* Acquire the text */
2580 /* Store the text */
2581 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2586 /* Process 'X' for "Xtra" (one line only) */
2587 else if (buf[0] == 'X')
2591 /* Scan for the values */
2592 if (2 != sscanf(buf+2, "%d:%d",
2593 &slot, &rating)) return (1);
2595 /* Save the values */
2597 e_ptr->rating = rating;
2600 /* Process 'W' for "More Info" (one line only) */
2601 else if (buf[0] == 'W')
2603 int level, rarity, pad2;
2606 /* Scan for the values */
2607 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2608 &level, &rarity, &pad2, &cost)) return (1);
2610 /* Save the values */
2611 e_ptr->level = level;
2612 e_ptr->rarity = rarity;
2613 /* e_ptr->weight = wgt; */
2617 /* Hack -- Process 'C' for "creation" */
2618 else if (buf[0] == 'C')
2622 /* Scan for the values */
2623 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2624 &th, &td, &ta, &pv)) return (1);
2626 e_ptr->max_to_h = th;
2627 e_ptr->max_to_d = td;
2628 e_ptr->max_to_a = ta;
2629 e_ptr->max_pval = pv;
2632 /* Hack -- Process 'F' for flags */
2633 else if (buf[0] == 'F')
2635 /* Parse every entry textually */
2636 for (s = buf + 2; *s; )
2638 /* Find the end of this entry */
2639 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2641 /* Nuke and skip any dividers */
2645 while ((*t == ' ') || (*t == '|')) t++;
2648 /* Parse this entry */
2649 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2651 /* Start the next entry */
2665 * Grab one (basic) flag in a monster_race from a textual string
2667 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2669 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2672 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2675 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2678 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2681 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2684 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2687 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2692 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2694 msg_format("Unknown monster flag '%s'.", what);
2704 * Grab one (spell) flag in a monster_race from a textual string
2706 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2708 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2711 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2714 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2719 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2721 msg_format("Unknown monster flag '%s'.", what);
2733 * Initialize the "r_info" array, by parsing an ascii "template" file
2735 errr parse_r_info(char *buf, header *head)
2742 static monster_race *r_ptr = NULL;
2745 /* Process 'N' for "New/Number/Name" */
2748 /* Find the colon before the name */
2749 s = my_strchr(buf+2, ':');
2751 /* Verify that colon */
2754 /* Nuke the colon, advance to the name */
2757 /* Paranoia -- require a name */
2758 if (!*s) return (1);
2763 /* Verify information */
2764 if (i < error_idx) return (4);
2766 /* Verify information */
2767 if (i >= head->info_num) return (2);
2769 /* Save the index */
2772 /* Point at the "info" */
2775 /* Store the name */
2776 if (!add_name(&r_ptr->name, head, s)) return (7);
2780 /* There better be a current r_ptr */
2781 else if (!r_ptr) return (3);
2785 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2786 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2787 else if (buf[0] == 'E')
2789 /* Acquire the Text */
2792 /* Store the name */
2793 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2796 else if (buf[0] == 'E')
2798 /* Acquire the Text */
2801 /* Store the name */
2802 if (!add_name(&r_ptr->name, head, s)) return (7);
2805 /* Process 'D' for "Description" */
2806 else if (buf[0] == 'D')
2811 /* Acquire the text */
2816 /* Acquire the text */
2820 /* Store the text */
2821 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2824 /* Process 'G' for "Graphics" (one line only) */
2825 else if (buf[0] == 'G')
2831 if (buf[1] != ':') return (1);
2832 if (!buf[2]) return (1);
2833 if (buf[3] != ':') return (1);
2834 if (!buf[4]) return (1);
2836 /* Extract the char */
2839 /* Extract the attr */
2840 tmp = color_char_to_attr(buf[4]);
2843 if (tmp > 127) return (1);
2845 /* Save the values */
2846 r_ptr->d_char = sym;
2847 r_ptr->d_attr = tmp;
2850 /* Process 'I' for "Info" (one line only) */
2851 else if (buf[0] == 'I')
2853 int spd, hp1, hp2, aaf, ac, slp;
2855 /* Scan for the other values */
2856 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2857 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2859 /* Save the values */
2861 r_ptr->hdice = MAX(hp1, 1);
2862 r_ptr->hside = MAX(hp2, 1);
2868 /* Process 'W' for "More Info" (one line only) */
2869 else if (buf[0] == 'W')
2876 /* Scan for the values */
2877 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2878 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2880 /* Save the values */
2882 r_ptr->rarity = rar;
2885 r_ptr->next_exp = nextexp;
2886 r_ptr->next_r_idx = nextmon;
2889 /* Process 'B' for "Blows" (up to four lines) */
2890 else if (buf[0] == 'B')
2894 /* Find the next empty blow slot (if any) */
2895 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2897 /* Oops, no more slots */
2898 if (i == 4) return (1);
2900 /* Analyze the first field */
2901 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2903 /* Terminate the field (if necessary) */
2904 if (*t == ':') *t++ = '\0';
2906 /* Analyze the method */
2907 for (n1 = 0; r_info_blow_method[n1]; n1++)
2909 if (streq(s, r_info_blow_method[n1])) break;
2912 /* Invalid method */
2913 if (!r_info_blow_method[n1]) return (1);
2915 /* Analyze the second field */
2916 for (s = t; *t && (*t != ':'); t++) /* loop */;
2918 /* Terminate the field (if necessary) */
2919 if (*t == ':') *t++ = '\0';
2921 /* Analyze effect */
2922 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2924 if (streq(s, r_info_blow_effect[n2])) break;
2927 /* Invalid effect */
2928 if (!r_info_blow_effect[n2]) return (1);
2930 /* Analyze the third field */
2931 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2933 /* Terminate the field (if necessary) */
2934 if (*t == 'd') *t++ = '\0';
2936 /* Save the method */
2937 r_ptr->blow[i].method = n1;
2939 /* Save the effect */
2940 r_ptr->blow[i].effect = n2;
2942 /* Extract the damage dice and sides */
2943 r_ptr->blow[i].d_dice = atoi(s);
2944 r_ptr->blow[i].d_side = atoi(t);
2947 /* Process 'F' for "Basic Flags" (multiple lines) */
2948 else if (buf[0] == 'F')
2950 /* Parse every entry */
2951 for (s = buf + 2; *s; )
2953 /* Find the end of this entry */
2954 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2956 /* Nuke and skip any dividers */
2960 while (*t == ' ' || *t == '|') t++;
2963 /* Parse this entry */
2964 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2966 /* Start the next entry */
2971 /* Process 'S' for "Spell Flags" (multiple lines) */
2972 else if (buf[0] == 'S')
2974 /* Parse every entry */
2975 for (s = buf + 2; *s; )
2977 /* Find the end of this entry */
2978 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2980 /* Nuke and skip any dividers */
2984 while ((*t == ' ') || (*t == '|')) t++;
2987 /* XXX XXX XXX Hack -- Read spell frequency */
2988 if (1 == sscanf(s, "1_IN_%d", &i))
2990 /* Extract a "frequency" */
2991 r_ptr->freq_spell = 100 / i;
2993 /* Start at next entry */
3000 /* Parse this entry */
3001 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3003 /* Start the next entry */
3018 * Grab one flag for a dungeon type from a textual string
3020 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3022 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3027 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3029 msg_format("Unknown dungeon type flag '%s'.", what);
3037 * Grab one (basic) flag in a monster_race from a textual string
3039 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3041 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3044 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3047 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3050 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3053 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3056 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3059 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3064 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3066 msg_format("Unknown monster flag '%s'.", what);
3074 * Grab one (spell) flag in a monster_race from a textual string
3076 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3078 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3081 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3084 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3089 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3091 msg_format("Unknown monster flag '%s'.", what);
3099 * Initialize the "d_info" array, by parsing an ascii "template" file
3101 errr parse_d_info(char *buf, header *head)
3108 static dungeon_info_type *d_ptr = NULL;
3111 /* Process 'N' for "New/Number/Name" */
3114 /* Find the colon before the name */
3115 s = my_strchr(buf+2, ':');
3117 /* Verify that colon */
3120 /* Nuke the colon, advance to the name */
3123 /* Paranoia -- require a name */
3124 if (!*s) return (1);
3129 /* Verify information */
3130 if (i < error_idx) return (4);
3132 /* Verify information */
3133 if (i >= head->info_num) return (2);
3135 /* Save the index */
3138 /* Point at the "info" */
3141 /* Store the name */
3142 if (!add_name(&d_ptr->name, head, s)) return (7);
3147 else if (buf[0] == 'E') return (0);
3149 else if (buf[0] == 'E')
3151 /* Acquire the Text */
3154 /* Store the name */
3155 if (!add_name(&d_ptr->name, head, s)) return (7);
3159 /* Process 'D' for "Description */
3160 else if (buf[0] == 'D')
3165 /* Acquire the text */
3170 /* Acquire the text */
3174 /* Store the text */
3175 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3178 /* Process 'W' for "More Info" (one line only) */
3179 else if (buf[0] == 'W')
3181 int min_lev, max_lev;
3183 int min_alloc, max_chance;
3184 int obj_good, obj_great;
3187 /* Scan for the values */
3188 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3189 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3191 /* Save the values */
3192 d_ptr->mindepth = min_lev;
3193 d_ptr->maxdepth = max_lev;
3194 d_ptr->min_plev = min_plev;
3196 d_ptr->min_m_alloc_level = min_alloc;
3197 d_ptr->max_m_alloc_chance = max_chance;
3198 d_ptr->obj_good = obj_good;
3199 d_ptr->obj_great = obj_great;
3204 /* Process 'P' for "Place Info" */
3205 else if (buf[0] == 'P')
3209 /* Scan for the values */
3210 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3212 /* Save the values */
3217 /* Process 'L' for "fLoor type" (one line only) */
3218 else if (buf[0] == 'L')
3222 /* Scan for the values */
3223 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3225 /* Save the values */
3226 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3228 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3229 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3231 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3233 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3236 /* Process 'A' for "wAll type" (one line only) */
3237 else if (buf[0] == 'A')
3241 /* Scan for the values */
3242 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3244 /* Save the values */
3245 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3247 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3248 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3250 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3253 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3254 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3256 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3257 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3259 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3260 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3262 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3263 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3266 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3267 else if (buf[0] == 'F')
3269 int artif = 0, monst = 0;
3271 /* Parse every entry */
3272 for (s = buf + 2; *s; )
3274 /* Find the end of this entry */
3275 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3277 /* Nuke and skip any dividers */
3281 while (*t == ' ' || *t == '|') t++;
3284 /* XXX XXX XXX Hack -- Read Final Artifact */
3285 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3287 /* Extract a "Final Artifact" */
3288 d_ptr->final_artifact = artif;
3290 /* Start at next entry */
3297 /* XXX XXX XXX Hack -- Read Final Object */
3298 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3300 /* Extract a "Final Artifact" */
3301 d_ptr->final_object = artif;
3303 /* Start at next entry */
3310 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3311 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3313 /* Extract a "Artifact Guardian" */
3314 d_ptr->final_guardian = monst;
3316 /* Start at next entry */
3323 /* XXX XXX XXX Hack -- Read Special Percentage */
3324 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3326 /* Extract a "Special %" */
3327 d_ptr->special_div = monst;
3329 /* Start at next entry */
3336 /* Parse this entry */
3337 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3339 /* Start the next entry */
3344 /* Process 'M' for "Basic Flags" (multiple lines) */
3345 else if (buf[0] == 'M')
3347 /* Parse every entry */
3348 for (s = buf + 2; *s; )
3350 /* Find the end of this entry */
3351 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3353 /* Nuke and skip any dividers */
3357 while (*t == ' ' || *t == '|') t++;
3360 /* Hack -- Read monster symbols */
3361 if (!strncmp(s, "R_CHAR_", 7))
3363 /* Skip "R_CHAR_" */
3367 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3369 /* Start at next entry */
3376 /* Parse this entry */
3377 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3379 /* Start the next entry */
3384 /* Process 'S' for "Spell Flags" (multiple lines) */
3385 else if (buf[0] == 'S')
3387 /* Parse every entry */
3388 for (s = buf + 2; *s; )
3390 /* Find the end of this entry */
3391 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3393 /* Nuke and skip any dividers */
3397 while ((*t == ' ') || (*t == '|')) t++;
3400 /* XXX XXX XXX Hack -- Read spell frequency */
3401 if (1 == sscanf(s, "1_IN_%d", &i))
3403 /* Start at next entry */
3410 /* Parse this entry */
3411 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3413 /* Start the next entry */
3426 #else /* ALLOW_TEMPLATES */
3432 #endif /* ALLOW_TEMPLATES */
3435 /* Random dungeon grid effects */
3436 #define RANDOM_NONE 0x00000000
3437 #define RANDOM_FEATURE 0x00000001
3438 #define RANDOM_MONSTER 0x00000002
3439 #define RANDOM_OBJECT 0x00000004
3440 #define RANDOM_EGO 0x00000008
3441 #define RANDOM_ARTIFACT 0x00000010
3442 #define RANDOM_TRAP 0x00000020
3445 typedef struct dungeon_grid dungeon_grid;
3449 int feature; /* Terrain feature */
3450 int monster; /* Monster */
3451 int object; /* Object */
3452 int ego; /* Ego-Item */
3453 int artifact; /* Artifact */
3454 int trap; /* Trap */
3455 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3456 int special; /* Reserved for special terrain info */
3457 int random; /* Number of the random effect */
3461 static dungeon_grid letter[255];
3465 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3467 static errr parse_line_feature(char *buf)
3473 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3475 /* Tokenize the line */
3476 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3478 /* Letter to assign */
3479 int index = zz[0][0];
3481 /* Reset the info for the letter */
3482 letter[index].feature = feat_none;
3483 letter[index].monster = 0;
3484 letter[index].object = 0;
3485 letter[index].ego = 0;
3486 letter[index].artifact = 0;
3487 letter[index].trap = feat_none;
3488 letter[index].cave_info = 0;
3489 letter[index].special = 0;
3490 letter[index].random = RANDOM_NONE;
3496 letter[index].special = atoi(zz[8]);
3500 if ((zz[7][0] == '*') && !zz[7][1])
3502 letter[index].random |= RANDOM_TRAP;
3506 letter[index].trap = f_tag_to_index(zz[7]);
3507 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3512 if (zz[6][0] == '*')
3514 letter[index].random |= RANDOM_ARTIFACT;
3515 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3517 else if (zz[6][0] == '!')
3519 if (p_ptr->inside_quest)
3521 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3526 letter[index].artifact = atoi(zz[6]);
3531 if (zz[5][0] == '*')
3533 letter[index].random |= RANDOM_EGO;
3534 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3538 letter[index].ego = atoi(zz[5]);
3543 if (zz[4][0] == '*')
3545 letter[index].random |= RANDOM_OBJECT;
3546 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3548 else if (zz[4][0] == '!')
3550 if (p_ptr->inside_quest)
3552 int a_idx = quest[p_ptr->inside_quest].k_idx;
3555 artifact_type *a_ptr = &a_info[a_idx];
3556 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3558 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3565 letter[index].object = atoi(zz[4]);
3570 if (zz[3][0] == '*')
3572 letter[index].random |= RANDOM_MONSTER;
3573 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3575 else if (zz[3][0] == 'c')
3577 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3578 letter[index].monster = - atoi(zz[3] + 1);
3582 letter[index].monster = atoi(zz[3]);
3587 letter[index].cave_info = atoi(zz[2]);
3591 if ((zz[1][0] == '*') && !zz[1][1])
3593 letter[index].random |= RANDOM_FEATURE;
3597 letter[index].feature = f_tag_to_index(zz[1]);
3598 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3611 * Process "B:<Index>:<Command>:..." -- Building definition
3613 static errr parse_line_building(char *buf)
3629 /* Get the building number */
3632 /* Find the colon after the building number */
3633 s = my_strchr(s, ':');
3635 /* Verify that colon */
3638 /* Nuke the colon, advance to the sub-index */
3641 /* Paranoia -- require a sub-index */
3642 if (!*s) return (1);
3644 /* Building definition sub-index */
3647 /* Building name, owner, race */
3650 if (tokenize(s + 2, 3, zz, 0) == 3)
3652 /* Name of the building */
3653 strcpy(building[index].name, zz[0]);
3655 /* Name of the owner */
3656 strcpy(building[index].owner_name, zz[1]);
3658 /* Race of the owner */
3659 strcpy(building[index].owner_race, zz[2]);
3664 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3667 /* Building Action */
3670 if (tokenize(s + 2, 8, zz, 0) >= 7)
3672 /* Index of the action */
3673 int action_index = atoi(zz[0]);
3675 /* Name of the action */
3676 strcpy(building[index].act_names[action_index], zz[1]);
3678 /* Cost of the action for members */
3679 building[index].member_costs[action_index] = atoi(zz[2]);
3681 /* Cost of the action for non-members */
3682 building[index].other_costs[action_index] = atoi(zz[3]);
3684 /* Letter assigned to the action */
3685 building[index].letters[action_index] = zz[4][0];
3688 building[index].actions[action_index] = atoi(zz[5]);
3690 /* Action restriction */
3691 building[index].action_restr[action_index] = atoi(zz[6]);
3696 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3699 /* Building Classes */
3702 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3704 for (i = 0; i < MAX_CLASS; i++)
3706 building[index].member_class[i] = atoi(zz[i]);
3712 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3715 /* Building Races */
3718 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3720 for (i = 0; i < MAX_RACES; i++)
3722 building[index].member_race[i] = atoi(zz[i]);
3728 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3731 /* Building Realms */
3734 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3736 for (i = 0; i < MAX_MAGIC; i++)
3738 building[index].member_realm[i+1] = atoi(zz[i]);
3744 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3749 /* Ignore scripts */
3755 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3764 * Place the object j_ptr to a grid
3766 static void drop_here(object_type *j_ptr, int y, int x)
3768 cave_type *c_ptr = &cave[y][x];
3771 /* Get new object */
3772 s16b o_idx = o_pop();
3774 /* Access new object */
3775 o_ptr = &o_list[o_idx];
3777 /* Structure copy */
3778 object_copy(o_ptr, j_ptr);
3786 o_ptr->held_m_idx = 0;
3789 o_ptr->next_o_idx = c_ptr->o_idx;
3791 /* Place the object */
3792 c_ptr->o_idx = o_idx;
3797 * Parse a sub-file of the "extra info"
3799 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3806 /* Skip "empty" lines */
3807 if (!buf[0]) return (0);
3809 /* Skip "blank" lines */
3810 if (isspace(buf[0])) return (0);
3813 if (buf[0] == '#') return (0);
3815 /* Require "?:*" format */
3816 if (buf[1] != ':') return (1);
3819 /* Process "%:<fname>" */
3822 /* Attempt to Process the given file */
3823 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3826 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3829 return parse_line_feature(buf);
3832 /* Process "D:<dungeon>" -- info for the cave grids */
3833 else if (buf[0] == 'D')
3835 object_type object_type_body;
3837 /* Acquire the text */
3840 /* Length of the text */
3841 int len = strlen(s);
3843 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3845 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3847 /* Access the grid */
3848 cave_type *c_ptr = &cave[*y][*x];
3852 int object_index = letter[idx].object;
3853 int monster_index = letter[idx].monster;
3854 int random = letter[idx].random;
3855 int artifact_index = letter[idx].artifact;
3857 /* Lay down a floor */
3858 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3860 /* Only the features */
3861 if (init_flags & INIT_ONLY_FEATURES) continue;
3864 c_ptr->info = letter[idx].cave_info;
3866 /* Create a monster */
3867 if (random & RANDOM_MONSTER)
3869 monster_level = base_level + monster_index;
3871 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3873 monster_level = base_level;
3875 else if (monster_index)
3877 int old_cur_num, old_max_num;
3880 if (monster_index < 0)
3882 monster_index = -monster_index;
3885 old_cur_num = r_info[monster_index].cur_num;
3886 old_max_num = r_info[monster_index].max_num;
3888 /* Make alive again */
3889 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3891 r_info[monster_index].cur_num = 0;
3892 r_info[monster_index].max_num = 1;
3895 /* Make alive again */
3896 /* Hack -- Non-unique Nazguls are semi-unique */
3897 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3899 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3901 r_info[monster_index].max_num++;
3906 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3910 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3912 /* Make alive again for real unique monster */
3913 r_info[monster_index].cur_num = old_cur_num;
3914 r_info[monster_index].max_num = old_max_num;
3918 /* Object (and possible trap) */
3919 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3921 object_level = base_level + object_index;
3924 * Random trap and random treasure defined
3925 * 25% chance for trap and 75% chance for object
3927 if (randint0(100) < 75)
3929 place_object(*y, *x, 0L);
3936 object_level = base_level;
3938 else if (random & RANDOM_OBJECT)
3940 object_level = base_level + object_index;
3942 /* Create an out of deep object */
3943 if (randint0(100) < 75)
3944 place_object(*y, *x, 0L);
3945 else if (randint0(100) < 80)
3946 place_object(*y, *x, AM_GOOD);
3948 place_object(*y, *x, AM_GOOD | AM_GREAT);
3950 object_level = base_level;
3953 else if (random & RANDOM_TRAP)
3957 /* Hidden trap (or door) */
3958 else if (letter[idx].trap)
3960 c_ptr->mimic = c_ptr->feat;
3961 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3963 else if (object_index)
3965 /* Get local object */
3966 object_type *o_ptr = &object_type_body;
3968 /* Create the item */
3969 object_prep(o_ptr, object_index);
3971 if (o_ptr->tval == TV_GOLD)
3973 coin_type = object_index - OBJ_GOLD_LIST;
3978 /* Apply magic (no messages, no artifacts) */
3979 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
3981 drop_here(o_ptr, *y, *x);
3987 if (a_info[artifact_index].cur_num)
3989 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3991 object_type *q_ptr = &forge;
3993 object_prep(q_ptr, k_idx);
3995 /* Drop it in the dungeon */
3996 drop_here(q_ptr, *y, *x);
4000 /* Create the artifact */
4001 if (create_named_art(artifact_index, *y, *x))
4002 a_info[artifact_index].cur_num = 1;
4006 /* Terrain special */
4007 c_ptr->special = letter[idx].special;
4015 /* Process "Q:<number>:<command>:... -- quest info */
4016 else if (buf[0] == 'Q')
4023 num = tokenize(buf + 2, 33, zz, 0);
4027 num = tokenize(buf + 3, 33, zz, 0);
4030 /* Have we enough parameters? */
4031 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4034 q_ptr = &(quest[atoi(zz[0])]);
4036 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4037 if (zz[1][0] == 'Q')
4039 if (init_flags & INIT_ASSIGN)
4041 monster_race *r_ptr;
4042 artifact_type *a_ptr;
4044 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4046 q_ptr->type = atoi(zz[2]);
4047 q_ptr->num_mon = atoi(zz[3]);
4048 q_ptr->cur_num = atoi(zz[4]);
4049 q_ptr->max_num = atoi(zz[5]);
4050 q_ptr->level = atoi(zz[6]);
4051 q_ptr->r_idx = atoi(zz[7]);
4052 q_ptr->k_idx = atoi(zz[8]);
4053 q_ptr->dungeon = atoi(zz[9]);
4056 q_ptr->flags = atoi(zz[10]);
4058 r_ptr = &r_info[q_ptr->r_idx];
4059 if (r_ptr->flags1 & RF1_UNIQUE)
4060 r_ptr->flags1 |= RF1_QUESTOR;
4062 a_ptr = &a_info[q_ptr->k_idx];
4063 a_ptr->gen_flags |= TRG_QUESTITEM;
4068 else if (zz[1][0] == 'R')
4070 if (init_flags & INIT_ASSIGN)
4075 for (idx = 2; idx < num; idx++)
4077 int a_idx = atoi(zz[idx]);
4078 if (a_idx < 1) continue;
4079 if (a_info[a_idx].cur_num > 0) continue;
4081 if (one_in_(count)) reward_idx = a_idx;
4086 /* Set quest's rewarding artifact */
4087 q_ptr->k_idx = reward_idx;
4088 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4092 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4093 q_ptr->type = QUEST_TYPE_KILL_ALL;
4100 /* Process "Q:<q_index>:N:<name>" -- quest name */
4101 else if (zz[1][0] == 'N')
4103 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4105 strcpy(q_ptr->name, zz[2]);
4111 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4112 else if (zz[1][0] == 'T')
4114 if (init_flags & INIT_SHOW_TEXT)
4116 strcpy(quest_text[quest_text_line], zz[2]);
4124 /* Process "W:<command>: ..." -- info for the wilderness */
4125 else if (buf[0] == 'W')
4127 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4130 /* Process "P:<y>:<x>" -- player position */
4131 else if (buf[0] == 'P')
4133 if (init_flags & INIT_CREATE_DUNGEON)
4135 if (tokenize(buf + 2, 2, zz, 0) == 2)
4137 int panels_x, panels_y;
4139 /* Hack - Set the dungeon size */
4140 panels_y = (*y / SCREEN_HGT);
4141 if (*y % SCREEN_HGT) panels_y++;
4142 cur_hgt = panels_y * SCREEN_HGT;
4144 panels_x = (*x / SCREEN_WID);
4145 if (*x % SCREEN_WID) panels_x++;
4146 cur_wid = panels_x * SCREEN_WID;
4148 /* Assume illegal panel */
4149 panel_row_min = cur_hgt;
4150 panel_col_min = cur_wid;
4152 /* Place player in a quest level */
4153 if (p_ptr->inside_quest)
4157 /* Delete the monster (if any) */
4158 delete_monster(py, px);
4166 /* Place player in the town */
4167 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4169 p_ptr->oldpy = atoi(zz[0]);
4170 p_ptr->oldpx = atoi(zz[1]);
4178 /* Process "B:<Index>:<Command>:..." -- Building definition */
4179 else if (buf[0] == 'B')
4181 return parse_line_building(buf);
4184 /* Process "M:<type>:<maximum>" -- set maximum values */
4185 else if (buf[0] == 'M')
4187 if (tokenize(buf+2, 2, zz, 0) == 2)
4190 if (zz[0][0] == 'T')
4192 max_towns = atoi(zz[1]);
4195 /* Maximum quests */
4196 else if (zz[0][0] == 'Q')
4198 max_quests = atoi(zz[1]);
4202 else if (zz[0][0] == 'R')
4204 max_r_idx = atoi(zz[1]);
4208 else if (zz[0][0] == 'K')
4210 max_k_idx = atoi(zz[1]);
4214 else if (zz[0][0] == 'V')
4216 max_v_idx = atoi(zz[1]);
4220 else if (zz[0][0] == 'F')
4222 max_f_idx = atoi(zz[1]);
4226 else if (zz[0][0] == 'A')
4228 max_a_idx = atoi(zz[1]);
4232 else if (zz[0][0] == 'E')
4234 max_e_idx = atoi(zz[1]);
4238 else if (zz[0][0] == 'D')
4240 max_d_idx = atoi(zz[1]);
4244 else if (zz[0][0] == 'O')
4246 max_o_idx = atoi(zz[1]);
4250 else if (zz[0][0] == 'M')
4252 max_m_idx = atoi(zz[1]);
4255 /* Wilderness size */
4256 else if (zz[0][0] == 'W')
4258 /* Maximum wild_x_size */
4259 if (zz[0][1] == 'X')
4260 max_wild_x = atoi(zz[1]);
4261 /* Maximum wild_y_size */
4262 if (zz[0][1] == 'Y')
4263 max_wild_y = atoi(zz[1]);
4277 static cptr variant = "ZANGBAND";
4281 * Helper function for "process_dungeon_file()"
4283 static cptr process_dungeon_file_expr(char **sp, char *fp)
4299 while (isspace(*s)) s++;
4317 t = process_dungeon_file_expr(&s, &f);
4326 else if (streq(t, "IOR"))
4329 while (*s && (f != b2))
4331 t = process_dungeon_file_expr(&s, &f);
4332 if (*t && !streq(t, "0")) v = "1";
4337 else if (streq(t, "AND"))
4340 while (*s && (f != b2))
4342 t = process_dungeon_file_expr(&s, &f);
4343 if (*t && streq(t, "0")) v = "0";
4348 else if (streq(t, "NOT"))
4351 while (*s && (f != b2))
4353 t = process_dungeon_file_expr(&s, &f);
4354 if (*t && streq(t, "1")) v = "0";
4359 else if (streq(t, "EQU"))
4362 if (*s && (f != b2))
4364 t = process_dungeon_file_expr(&s, &f);
4366 while (*s && (f != b2))
4368 p = process_dungeon_file_expr(&s, &f);
4369 if (streq(t, p)) v = "1";
4374 else if (streq(t, "LEQ"))
4377 if (*s && (f != b2))
4379 t = process_dungeon_file_expr(&s, &f);
4381 while (*s && (f != b2))
4384 t = process_dungeon_file_expr(&s, &f);
4385 if (*t && atoi(p) > atoi(t)) v = "0";
4390 else if (streq(t, "GEQ"))
4393 if (*s && (f != b2))
4395 t = process_dungeon_file_expr(&s, &f);
4397 while (*s && (f != b2))
4400 t = process_dungeon_file_expr(&s, &f);
4402 /* Compare two numbers instead of string */
4403 if (*t && atoi(p) < atoi(t)) v = "0";
4410 while (*s && (f != b2))
4412 t = process_dungeon_file_expr(&s, &f);
4417 if (f != b2) v = "?x?x?";
4419 /* Extract final and Terminate */
4420 if ((f = *s) != '\0') *s++ = '\0';
4426 /* Accept all printables except spaces and brackets */
4428 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4430 if (iskanji(*s)) s++;
4434 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4437 /* Extract final and Terminate */
4438 if ((f = *s) != '\0') *s++ = '\0';
4444 if (streq(b+1, "SYS"))
4450 else if (streq(b+1, "GRAF"))
4455 else if (streq(b+1, "MONOCHROME"))
4464 else if (streq(b+1, "RACE"))
4467 v = rp_ptr->E_title;
4474 else if (streq(b+1, "CLASS"))
4477 v = cp_ptr->E_title;
4484 else if (streq(b+1, "REALM1"))
4487 v = E_realm_names[p_ptr->realm1];
4489 v = realm_names[p_ptr->realm1];
4494 else if (streq(b+1, "REALM2"))
4497 v = E_realm_names[p_ptr->realm2];
4499 v = realm_names[p_ptr->realm2];
4504 else if (streq(b+1, "PLAYER"))
4506 static char tmp_player_name[32];
4508 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4518 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4521 v = tmp_player_name;
4525 else if (streq(b+1, "TOWN"))
4527 sprintf(tmp, "%d", p_ptr->town_num);
4532 else if (streq(b+1, "LEVEL"))
4534 sprintf(tmp, "%d", p_ptr->lev);
4538 /* Current quest number */
4539 else if (streq(b+1, "QUEST_NUMBER"))
4541 sprintf(tmp, "%d", p_ptr->inside_quest);
4545 /* Number of last quest */
4546 else if (streq(b+1, "LEAVING_QUEST"))
4548 sprintf(tmp, "%d", leaving_quest);
4553 else if (prefix(b+1, "QUEST_TYPE"))
4555 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4556 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4561 else if (prefix(b+1, "QUEST"))
4563 /* "QUEST" uses a special parameter to determine the number of the quest */
4564 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4569 else if (prefix(b+1, "RANDOM"))
4571 /* "RANDOM" uses a special parameter to determine the number of the quest */
4572 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4577 else if (streq(b+1, "VARIANT"))
4583 else if (streq(b+1, "WILDERNESS"))
4586 sprintf(tmp, "NONE");
4588 sprintf(tmp, "LITE");
4590 sprintf(tmp, "NORMAL");
4613 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4623 bool bypass = FALSE;
4625 int x = xmin, y = ymin;
4628 /* Build the filename */
4629 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4632 fp = my_fopen(buf, "r");
4635 if (!fp) return (-1);
4638 /* Process the file */
4639 while (0 == my_fgets(fp, buf, sizeof(buf)))
4645 /* Skip "empty" lines */
4646 if (!buf[0]) continue;
4648 /* Skip "blank" lines */
4649 if (isspace(buf[0])) continue;
4652 if (buf[0] == '#') continue;
4655 /* Process "?:<expr>" */
4656 if ((buf[0] == '?') && (buf[1] == ':'))
4665 /* Parse the expr */
4666 v = process_dungeon_file_expr(&s, &f);
4669 bypass = (streq(v, "0") ? TRUE : FALSE);
4675 /* Apply conditionals */
4676 if (bypass) continue;
4678 /* Process the line */
4679 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4691 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4694 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4696 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4698 msg_format("Parsing '%s'.", buf);
4705 /* Close the file */
4715 void write_r_info_txt(void)
4717 int i, j, z, fc, bc;
4720 cptr flags[32 * 10];
4725 monster_race *r_ptr;
4727 monster_blow *b_ptr;
4729 FILE *fff = fopen("output.txt", "wt");
4737 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4739 fprintf(fff, "# Version stamp (required)\n\n");
4742 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4745 fprintf(fff, "##### The Player #####\n\n");
4747 for (z = -1; z < alloc_race_size; z++)
4749 /* Output the monsters in order */
4750 i = (z >= 0) ? alloc_race_table[z].index : 0;
4752 /* Acquire the monster */
4755 /* Ignore empty monsters */
4756 if (!strlen(r_name + r_ptr->name)) continue;
4758 /* Ignore useless monsters */
4759 if (i && !r_ptr->speed) continue;
4761 /* Write a note if necessary */
4762 if (i && (!r_ptr->level != !mode))
4767 fprintf(fff, "\n##### Town monsters #####\n\n");
4769 /* Note the dungeon */
4772 fprintf(fff, "\n##### Normal monsters #####\n\n");
4775 /* Record the change */
4776 mode = r_ptr->level;
4779 /* Acquire the flags */
4780 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4781 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4782 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4783 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4784 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4785 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4786 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4787 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4788 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4789 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4791 /* Write New/Number/Name */
4792 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4795 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4797 /* Write Information */
4798 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4799 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4801 /* Write more information */
4802 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4805 for(j = 0; j < 4; j++)
4807 b_ptr = &(r_ptr->blow[j]);
4809 /* Stop when done */
4810 if (!b_ptr->method) break;
4812 /* Write the blows */
4813 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4814 r_info_blow_effect[b_ptr->effect],
4815 b_ptr->d_dice, b_ptr->d_side);
4818 /* Extract the flags */
4819 for (fc = 0, j = 0; j < 32 * 3; j++)
4821 /* Check this flag */
4822 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4825 /* Extract the extra flags */
4826 for (j = 32 * 6; j < 32 * 10; j++)
4828 /* Check this flag */
4829 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4832 /* Write the flags */
4833 for (j = 0; j < fc;)
4837 /* Start the line */
4840 for (bc = 0; (bc < 60) && (j < fc); j++)
4844 /* Format the flag */
4845 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4847 /* Add it to the buffer */
4850 /* Note the length */
4854 /* Done with this line; write it */
4855 fprintf(fff, "%s\n", buf);
4858 /* Write Spells if applicable */
4859 if (r_ptr->freq_spell)
4861 /* Write the frequency */
4862 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4864 /* Extract the spell flags */
4865 for (fc = 0, j = 96; j < 192; j++)
4867 /* Check this flag */
4868 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4871 /* Write the flags */
4872 for (j = 0; j < fc;)
4876 /* Start the line */
4879 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4883 /* Format the flag */
4884 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4888 /* Note the length */
4895 /* Done with this line; write it */
4896 fprintf(fff, "%s\n", buf);
4900 /* Acquire the description */
4901 desc = r_text + r_ptr->text;
4902 dlen = strlen(desc);
4904 /* Write Description */
4905 for (j = 0; j < dlen;)
4909 /* Start the line */
4912 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4920 /* Done with this line; write it */
4921 fprintf(fff, "%s\n", buf);
4924 /* Space between entries */