5 #include "dungeon-file.h"
11 #include "player-skill.h"
16 #include "rooms-vault.h"
17 #include "objectkind.h"
18 #include "object-ego.h"
19 #include "monsterrace.h"
21 dungeon_grid letter[255];
25 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
29 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
30 * This software may be copied and distributed for educational, research,
31 * and not for profit purposes provided that this copyright and statement
32 * are included in all such copies. Other copyrights may also apply.
33 * 2014 Deskull rearranged comment for Doxygen.\n
37 * This file is used to initialize various variables and arrays for the
38 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
39 * the common limitation of "read()" and "write()" to only 32767 bytes
41 * Several of the arrays for Angband are built from "template" files in
42 * the "lib/file" directory, from which quick-load binary "image" files
43 * are constructed whenever they are not present in the "lib/data"
44 * directory, or if those files become obsolete, if we are allowed.
45 * Warning -- the "ascii" file parsers use a minor hack to collect the
46 * name and text information in a single pass. Thus, the game will not
47 * be able to load any template file with more than 20K of names or 60K
48 * of text, even though technically, up to 64K should be legal.
50 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
51 * in this file is compiled out, and the game will not run unless valid
52 * "binary template files" already exist in "lib/data". Thus, one can
53 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
54 * "*.raw" files in "lib/data", and then quit, and recompile without
55 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
56 * from changing the ascii template files in potentially dangerous ways.
57 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
58 * このファイルのコードの多くはコンパイル出力され、本ゲームは
59 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
60 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
61 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
62 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
63 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
64 * テンプレートファイルを変更することを妨げることができる。
65 * The code could actually be removed and placed into a "stand-alone"
66 * program, but that feels a little silly, especially considering some
67 * of the platforms that we currently support.
72 #include "dungeon-file.h"
77 #include "cmd-activate.h"
81 #include "view-mainwindow.h"
82 #include "player-class.h"
86 #ifdef ALLOW_TEMPLATES
91 /*** Helper arrays for parsing ascii template files ***/
95 * Monster Blow Methods
97 static concptr r_info_blow_method[] =
130 * モンスターの打撃属性トークンの定義 /
131 * Monster Blow Effects
133 static concptr r_info_blow_effect[] =
178 static concptr f_info_flags[] =
303 static concptr r_info_flags1[] =
343 static concptr r_info_flags2[] =
383 static concptr r_info_flags3[] =
423 static concptr r_info_flags4[] =
460 * モンスター特性トークン(発動型能力1) /
463 static concptr r_a_ability_flags1[] =
500 * モンスター特性トークン(発動型能力2) /
503 static concptr r_a_ability_flags2[] =
520 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
541 * モンスター特性トークン(発動型能力3) /
544 static concptr r_a_ability_flags3[] =
583 * モンスター特性トークン(発動型能力4) /
586 static concptr r_a_ability_flags4[] =
628 static concptr r_info_flags7[] =
668 static concptr r_info_flags8[] =
700 "WILD_SWAMP", /* ToDo: Implement Swamp */
709 static concptr r_info_flags9[] =
748 * モンスター特性トークンの定義R(耐性) /
751 static concptr r_info_flagsr[] =
789 * オブジェクト基本特性トークンの定義 /
792 static concptr k_info_flags[] =
889 "XXX3", /* Fake flag for Smith */
890 "XXX4", /* Fake flag for Smith */
940 * オブジェクト生成特性トークンの定義 /
943 static concptr k_info_gen_flags[] =
983 static concptr d_info_flags1[] =
1021 * @brief データの可変文字列情報をテキストとして保管する /
1022 * Add a text to the text-storage and store offset to it.
1023 * @param offset 文字列保管ポインタからのオフセット
1024 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1026 * @param normal_text テキストの正規化を行う
1029 * Returns FALSE when there isn't enough space available to store
1032 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1034 /* Hack -- Verify space */
1035 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1041 /* Advance and save the text index */
1042 *offset = ++head->text_size;
1045 /* Additional text */
1046 else if (normal_text)
1049 * If neither the end of the last line nor
1050 * the beginning of current line is not a space,
1051 * fill up a space as a correct separator of two words.
1053 if (head->text_size > 0 &&
1055 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1056 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1057 (buf[0] != ' ') && !iskanji(buf[0])
1059 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1064 /* Append a space */
1065 *(head->text_ptr + head->text_size) = ' ';
1067 /* Advance the index */
1072 /* Append chars to the text */
1073 strcpy(head->text_ptr + head->text_size, buf);
1075 /* Advance the index */
1076 head->text_size += strlen(buf);
1084 * @brief データの可変文字列情報を名前として保管する /
1085 * Add a name to the name-storage and return an offset to it.
1086 * @param offset 文字列保管ポインタからのオフセット
1087 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1091 * Returns FALSE when there isn't enough space available to store
1094 static bool add_name(u32b *offset, header *head, concptr buf)
1096 /* Hack -- Verify space */
1097 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1103 /* Advance and save the name index */
1104 *offset = ++head->name_size;
1107 /* Append chars to the names */
1108 strcpy(head->name_ptr + head->name_size, buf);
1110 /* Advance the index */
1111 head->name_size += strlen(buf);
1119 * @brief データの可変文字列情報をタグとして保管する /
1120 * Add a tag to the tag-storage and return an offset to it.
1121 * @param offset 文字列保管ポインタからのオフセット
1122 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1126 * Returns FALSE when there isn't enough space available to store
1129 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1133 /* Search for an existing (fake) tag */
1134 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1137 if (streq(&head->tag_ptr[i], buf)) break;
1140 /* There was no existing tag */
1141 if (i >= head->tag_size)
1143 /* Hack -- Verify space */
1144 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1147 /* Append chars to the tags */
1148 strcpy(head->tag_ptr + head->tag_size, buf);
1150 /* Point the new tag */
1153 /* Advance the index */
1154 head->tag_size += strlen(buf) + 1;
1157 /* Return offset of the tag */
1165 /*** Initialize from ascii template files ***/
1169 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1170 * Initialize an "*_info" array, by parsing an ascii "template" file
1171 * @param fp 読み取りに使うファイルポインタ
1172 * @param buf 読み取りに使うバッファ領域
1173 * @param head ヘッダ構造体
1174 * @param parse_info_txt_line パース関数
1177 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1181 /* Just before the first record */
1184 /* Just before the first line */
1188 /* Prepare the "fake" stuff */
1189 head->name_size = 0;
1190 head->text_size = 0;
1194 while (0 == my_fgets(fp, buf, 1024))
1196 /* Advance the line number */
1199 /* Skip comments and blank lines */
1200 if (!buf[0] || (buf[0] == '#')) continue;
1202 /* Verify correct "colon" format */
1203 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1206 /* Hack -- Process 'V' for "Version" */
1213 /* Mega Hack -- Calculate Check Sum */
1214 if (buf[0] != 'N' && buf[0] != 'D')
1217 for (i = 0; buf[i]; i++)
1219 head->v_extra += (byte)buf[i];
1220 head->v_extra ^= (1 << (i % 8));
1224 /* Parse the line */
1225 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1230 /* Complete the "name" and "text" sizes */
1231 if (head->name_size) head->name_size++;
1232 if (head->text_size) head->text_size++;
1240 * @brief Vault情報(v_info)のパース関数 /
1241 * Initialize the "v_info" array, by parsing an ascii "template" file
1243 * @param head ヘッダ構造体
1246 errr parse_v_info(char *buf, header *head)
1252 static vault_type *v_ptr = NULL;
1254 /* Process 'N' for "New/Number/Name" */
1257 /* Find the colon before the name */
1258 s = my_strchr(buf + 2, ':');
1260 /* Verify that colon */
1263 /* Nuke the colon, advance to the name */
1266 /* Paranoia -- require a name */
1267 if (!*s) return (1);
1272 /* Verify information */
1273 if (i <= error_idx) return (4);
1275 /* Verify information */
1276 if (i >= head->info_num) return (2);
1278 /* Save the index */
1281 /* Point at the "info" */
1284 /* Store the name */
1285 if (!add_name(&v_ptr->name, head, s)) return (7);
1288 /* There better be a current v_ptr */
1289 else if (!v_ptr) return (3);
1291 /* Process 'D' for "Description" */
1292 else if (buf[0] == 'D')
1294 /* Acquire the text */
1297 /* Store the text */
1298 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1301 /* Process 'X' for "Extra info" (one line only) */
1302 else if (buf[0] == 'X')
1304 EFFECT_ID typ, rat, hgt, wid;
1306 /* Scan for the values */
1307 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1308 &typ, &rat, &hgt, &wid)) return (1);
1310 /* Save the values */
1311 v_ptr->typ = (ROOM_IDX)typ;
1312 v_ptr->rat = (PROB)rat;
1313 v_ptr->hgt = (POSITION)hgt;
1314 v_ptr->wid = (POSITION)wid;
1325 * @brief 職業技能情報(s_info)のパース関数 /
1326 * Initialize the "s_info" array, by parsing an ascii "template" file
1328 * @param head ヘッダ構造体
1331 errr parse_s_info(char *buf, header *head)
1336 static skill_table *s_ptr = NULL;
1339 /* Process 'N' for "New/Number/Name" */
1345 /* Verify information */
1346 if (i <= error_idx) return (4);
1348 /* Verify information */
1349 if (i >= head->info_num) return (2);
1351 /* Save the index */
1354 /* Point at the "info" */
1358 /* There better be a current s_ptr */
1359 else if (!s_ptr) return (3);
1361 /* Process 'W' for "Weapon exp" */
1362 else if (buf[0] == 'W')
1364 int tval, sval, start, max;
1365 const s16b exp_conv_table[] =
1367 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1368 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1371 /* Scan for the values */
1372 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1373 &tval, &sval, &start, &max)) return (1);
1375 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1376 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1378 /* Save the values */
1379 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1380 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1383 /* Process 'S' for "Skill exp" */
1384 else if (buf[0] == 'S')
1386 int num, start, max;
1388 /* Scan for the values */
1389 if (3 != sscanf(buf + 2, "%d:%d:%d",
1390 &num, &start, &max)) return (1);
1392 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1393 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1395 /* Save the values */
1396 s_ptr->s_start[num] = (SUB_EXP)start;
1397 s_ptr->s_max[num] = (SUB_EXP)max;
1409 * @brief 職業魔法情報(m_info)のパース関数 /
1410 * Initialize the "m_info" array, by parsing an ascii "template" file
1412 * @param head ヘッダ構造体
1415 errr parse_m_info(char *buf, header *head)
1422 static player_magic *m_ptr = NULL;
1425 static int realm, magic_idx = 0, readable = 0;
1428 /* Process 'N' for "New/Number/Name" */
1434 /* Verify information */
1435 if (i <= error_idx) return (4);
1437 /* Verify information */
1438 if (i >= head->info_num) return (2);
1440 /* Save the index */
1443 /* Point at the "info" */
1447 /* There better be a current m_ptr */
1448 else if (!m_ptr) return (3);
1450 /* Process 'I' for "Info" (one line only) */
1451 else if (buf[0] == 'I')
1454 int xtra, type, first, weight;
1456 /* Find the colon before the name */
1457 s = my_strchr(buf + 2, ':');
1459 /* Verify that colon */
1462 /* Nuke the colon, advance to the name */
1467 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1468 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1469 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1470 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1471 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1476 /* Find the colon before the name */
1477 s = my_strchr(s, ':');
1479 /* Verify that colon */
1482 /* Nuke the colon, advance to the name */
1485 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1486 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1487 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1488 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1489 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1490 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1494 /* Scan for the values */
1495 if (4 != sscanf(s, "%x:%d:%d:%d",
1496 (uint *)&xtra, &type, &first, &weight)) return (1);
1498 m_ptr->spell_xtra = xtra;
1499 m_ptr->spell_type = type;
1500 m_ptr->spell_first = first;
1501 m_ptr->spell_weight = weight;
1505 /* Process 'R' for "Realm" (one line only) */
1506 else if (buf[0] == 'R')
1508 /* Scan for the values */
1509 if (2 != sscanf(buf + 2, "%d:%d",
1510 &realm, &readable)) return (1);
1515 else if (buf[0] == 'T')
1517 int level, mana, fail, exp;
1519 if (!readable) return (1);
1520 /* Scan for the values */
1521 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1522 &level, &mana, &fail, &exp)) return (1);
1524 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1525 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1526 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1527 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1540 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1541 * Grab one flag from a textual string
1542 * @param flags ビットフラグを追加する先の参照ポインタ
1543 * @param names トークン定義配列
1544 * @param what 参照元の文字列ポインタ
1547 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1552 for (i = 0; i < 32; i++)
1554 if (streq(what, names[i]))
1556 *flags |= (1L << i);
1566 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1567 * Grab one flag in an feature_type from a textual string
1568 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1569 * @param what 参照元の文字列ポインタ
1572 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1577 for (i = 0; i < FF_FLAG_MAX; i++)
1579 if (streq(what, f_info_flags[i]))
1581 add_flag(f_ptr->flags, i);
1586 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1589 return PARSE_ERROR_GENERIC;
1594 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1595 * Grab an action in an feature_type from a textual string
1596 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1597 * @param what 参照元の文字列ポインタ
1598 * @param count ステートの保存先ID
1601 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1606 for (i = 0; i < FF_FLAG_MAX; i++)
1608 if (streq(what, f_info_flags[i]))
1610 f_ptr->state[count].action = i;
1615 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1618 return PARSE_ERROR_GENERIC;
1623 * @brief 地形情報(f_info)のパース関数 /
1624 * Initialize the "f_info" array, by parsing an ascii "template" file
1626 * @param head ヘッダ構造体
1629 errr parse_f_info(char *buf, header *head)
1636 static feature_type *f_ptr = NULL;
1639 /* Process 'N' for "New/Number/Name" */
1642 /* Find the colon before the name */
1643 s = my_strchr(buf + 2, ':');
1647 /* Nuke the colon, advance to the name */
1654 /* Verify information */
1655 if (i <= error_idx) return (4);
1657 /* Verify information */
1658 if (i >= head->info_num) return (2);
1660 /* Save the index */
1663 /* Point at the "info" */
1666 /* Tag name is given */
1670 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1673 /* Default "mimic" */
1674 f_ptr->mimic = (FEAT_IDX)i;
1676 /* Default "destroyed state" -- if not specified */
1677 f_ptr->destroyed = (FEAT_IDX)i;
1679 /* Default "states" */
1680 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1683 /* There better be a current f_ptr */
1684 else if (!f_ptr) return (3);
1687 else if (buf[0] == 'J')
1689 /* Store the name */
1690 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1693 else if (buf[0] == 'E')
1695 /* Ignore english name */
1698 else if (buf[0] == 'J')
1700 /* Ignore Japanese name */
1703 else if (buf[0] == 'E')
1705 /* Acquire the Text */
1708 /* Store the name */
1709 if (!add_name(&f_ptr->name, head, s)) return (7);
1714 /* Process 'M' for "Mimic" (one line only) */
1715 else if (buf[0] == 'M')
1719 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1721 /* Record a fake tag index */
1722 f_ptr->mimic_tag = offset;
1726 /* Process 'G' for "Graphics" (one line only) */
1727 else if (buf[0] == 'G')
1731 char char_tmp[F_LIT_MAX];
1732 if (buf[1] != ':') return (1);
1733 if (!buf[2]) return (1);
1734 if (buf[3] != ':') return (1);
1735 if (!buf[4]) return (1);
1737 /* Extract the char */
1738 char_tmp[F_LIT_STANDARD] = buf[2];
1740 /* Extract the color */
1741 s_attr = color_char_to_attr(buf[4]);
1742 if (s_attr > 127) return (1);
1744 /* Save the standard values */
1745 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1746 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1748 /* Is this feature supports lighting? */
1751 /* G:c:a:LIT (default) */
1752 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1754 /* G:c:a:lc:la:dc:da */
1755 if (!streq(buf + 6, "LIT"))
1757 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1759 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1760 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1761 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1762 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1764 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1766 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1769 /* Use default lighting */
1772 /* No lighting support */
1773 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1776 /* Extract the color */
1777 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1778 if (f_ptr->d_attr[j] > 127) return 1;
1781 f_ptr->d_char[j] = char_tmp[j];
1787 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1789 f_ptr->d_attr[j] = s_attr;
1790 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1796 /* Hack -- Process 'F' for flags */
1797 else if (buf[0] == 'F')
1799 /* Parse every entry textually */
1800 for (s = buf + 2; *s; )
1802 /* Find the end of this entry */
1803 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1805 /* Nuke and skip any dividers */
1809 while (*t == ' ' || *t == '|') t++;
1812 /* Hack -- Read feature subtype */
1813 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1815 /* Extract a "subtype" */
1816 f_ptr->subtype = (FEAT_SUBTYPE)i;
1818 /* Start at next entry */
1824 /* Hack -- Read feature power */
1825 if (1 == sscanf(s, "POWER_%d", &i))
1827 /* Extract a "power" */
1828 f_ptr->power = (FEAT_POWER)i;
1830 /* Start at next entry */
1835 /* Parse this entry */
1836 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1838 /* Start the next entry */
1843 /* Process 'W' for "More Info" (one line only) */
1844 else if (buf[0] == 'W')
1848 /* Scan for the value */
1849 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1851 /* Save the value */
1852 f_ptr->priority = (FEAT_PRIORITY)priority;
1855 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1856 else if (buf[0] == 'K')
1860 /* Find the next empty state slot (if any) */
1861 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1863 /* Oops, no more slots */
1864 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1866 /* Analyze the first field */
1867 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1869 /* Terminate the field (if necessary) */
1870 if (*t == ':') *t++ = '\0';
1872 /* Is this default entry? */
1873 if (streq(s, "DESTROYED"))
1875 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1877 /* Record a fake tag index */
1878 f_ptr->destroyed_tag = offset;
1883 f_ptr->state[i].action = 0;
1885 /* Parse this entry */
1886 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1888 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1890 /* Record a fake tag index */
1891 f_ptr->state[i].result_tag = offset;
1903 * @brief 地形タグからIDを得る /
1904 * Convert a fake tag to a real feat index
1908 s16b f_tag_to_index(concptr str)
1912 /* Search for real index corresponding to this fake tag */
1913 for (i = 0; i < f_head.info_num; i++)
1915 if (streq(f_tag + f_info[i].tag, str))
1917 /* Return the index */
1928 * @brief 地形タグからIDを得る /
1929 * Search for real index corresponding to this fake tag
1930 * @param feat タグ文字列のオフセット
1931 * @return 地形ID。該当がないなら-1
1933 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1937 /* Don't convert non-fake tag */
1943 /* Search for real index corresponding to this fake tag */
1944 for (i = 0; i < f_head.info_num; i++)
1946 if (feat == f_info[i].tag)
1948 /* Record real index */
1954 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1960 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1961 * Retouch fake tags of f_info
1962 * @param head ヘッダ構造体
1965 void retouch_f_info(header *head)
1969 /* Convert fake tags to real feat indices */
1970 for (i = 0; i < head->info_num; i++)
1972 feature_type *f_ptr = &f_info[i];
1975 k = search_real_feat(f_ptr->mimic_tag);
1976 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1977 k = search_real_feat(f_ptr->destroyed_tag);
1978 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1979 for (j = 0; j < MAX_FEAT_STATES; j++)
1981 k = search_real_feat(f_ptr->state[j].result_tag);
1982 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1989 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1990 * Grab one flag in an object_kind from a textual string
1991 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1992 * @param what 参照元の文字列ポインタ
1995 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
2000 for (i = 0; i < TR_FLAG_MAX; i++)
2002 if (streq(what, k_info_flags[i]))
2004 add_flag(k_ptr->flags, i);
2009 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2012 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2019 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2020 * Grab one activation index flag
2021 * @param what 参照元の文字列ポインタ
2024 static byte grab_one_activation_flag(concptr what)
2030 if (activation_info[i].flag == NULL) break;
2032 if (streq(what, activation_info[i].flag))
2034 return activation_info[i].index;
2044 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2052 * @brief ベースアイテム(k_info)のパース関数 /
2053 * Initialize the "k_info" array, by parsing an ascii "template" file
2055 * @param head ヘッダ構造体
2058 errr parse_k_info(char *buf, header *head)
2065 static object_kind *k_ptr = NULL;
2068 /* Process 'N' for "New/Number/Name" */
2075 /* Find the colon before the name */
2076 s = my_strchr(buf + 2, ':');
2078 /* Verify that colon */
2081 /* Nuke the colon, advance to the name */
2087 /* Verify information */
2088 if (i <= error_idx) return (4);
2090 /* Verify information */
2091 if (i >= head->info_num) return (2);
2093 /* Save the index */
2096 /* Point at the "info" */
2100 /* Paranoia -- require a name */
2101 if (!*s) return (1);
2103 /* Find the colon before the flavor */
2104 flavor = my_strchr(s, ':');
2106 /* Verify that colon */
2109 /* Nuke the colon, advance to the flavor */
2112 /* Store the flavor */
2113 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2116 /* Store the name */
2117 if (!add_name(&k_ptr->name, head, s)) return (7);
2121 /* There better be a current k_ptr */
2122 else if (!k_ptr) return (3);
2127 /* 'E' から始まる行は英語名としている */
2128 else if (buf[0] == 'E')
2133 else if (buf[0] == 'E')
2137 /* Acquire the name */
2140 /* Find the colon before the flavor */
2141 flavor = my_strchr(s, ':');
2143 /* Verify that colon */
2146 /* Nuke the colon, advance to the flavor */
2149 /* Store the flavor */
2150 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2153 /* Store the name */
2154 if (!add_name(&k_ptr->name, head, s)) return (7);
2158 /* Process 'D' for "Description" */
2159 else if (buf[0] == 'D')
2164 /* Acquire the text */
2169 /* Acquire the text */
2173 /* Store the text */
2174 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2177 /* Process 'G' for "Graphics" (one line only) */
2178 else if (buf[0] == 'G')
2182 if (buf[1] != ':') return (1);
2183 if (!buf[2]) return (1);
2184 if (buf[3] != ':') return (1);
2185 if (!buf[4]) return (1);
2187 /* Extract the char */
2190 /* Extract the attr */
2191 tmp = color_char_to_attr(buf[4]);
2192 if (tmp > 127) return (1);
2194 /* Save the values */
2195 k_ptr->d_attr = tmp;
2196 k_ptr->d_char = sym;
2199 /* Process 'I' for "Info" (one line only) */
2200 else if (buf[0] == 'I')
2202 int tval, sval, pval;
2204 /* Scan for the values */
2205 if (3 != sscanf(buf + 2, "%d:%d:%d",
2206 &tval, &sval, &pval)) return (1);
2208 /* Save the values */
2209 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2210 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2211 k_ptr->pval = (PARAMETER_VALUE)pval;
2214 /* Process 'W' for "More Info" (one line only) */
2215 else if (buf[0] == 'W')
2217 int level, extra, wgt;
2220 /* Scan for the values */
2221 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2222 &level, &extra, &wgt, &cost)) return (1);
2224 /* Save the values */
2225 k_ptr->level = (DEPTH)level;
2226 k_ptr->extra = (BIT_FLAGS8)extra;
2227 k_ptr->weight = (WEIGHT)wgt;
2228 k_ptr->cost = (PRICE)cost;
2231 /* Process 'A' for "Allocation" (one line only) */
2232 else if (buf[0] == 'A')
2235 /* Simply read each number following a colon */
2236 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2238 /* Default chance */
2239 k_ptr->chance[i] = 1;
2241 /* Store the attack damage index */
2242 k_ptr->locale[i] = atoi(s + 1);
2244 /* Find the slash */
2245 t = my_strchr(s + 1, '/');
2247 /* Find the next colon */
2248 s = my_strchr(s + 1, ':');
2250 /* If the slash is "nearby", use it */
2251 if (t && (!s || t < s))
2253 int chance = atoi(t + 1);
2254 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2259 /* Hack -- Process 'P' for "power" and such */
2260 else if (buf[0] == 'P')
2262 int ac, hd1, hd2, th, td, ta;
2264 /* Scan for the values */
2265 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2266 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2268 k_ptr->ac = (ARMOUR_CLASS)ac;
2269 k_ptr->dd = (DICE_NUMBER)hd1;
2270 k_ptr->ds = (DICE_SID)hd2;
2271 k_ptr->to_h = (HIT_PROB)th;
2272 k_ptr->to_d = (HIT_POINT)td;
2273 k_ptr->to_a = (ARMOUR_CLASS)ta;
2276 /* Hack -- Process 'U' for activation index */
2277 else if (buf[0] == 'U')
2280 n = grab_one_activation_flag(buf + 2);
2291 /* Hack -- Process 'F' for flags */
2292 else if (buf[0] == 'F')
2294 /* Parse every entry textually */
2295 for (s = buf + 2; *s; )
2297 /* Find the end of this entry */
2298 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2300 /* Nuke and skip any dividers */
2304 while (*t == ' ' || *t == '|') t++;
2307 /* Parse this entry */
2308 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2310 /* Start the next entry */
2324 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2325 * Grab one activation index flag
2326 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2327 * @param what 参照元の文字列ポインタ
2328 * @return エラーがあった場合1、エラーがない場合0を返す
2330 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2335 for (i = 0; i < TR_FLAG_MAX; i++)
2337 if (streq(what, k_info_flags[i]))
2339 add_flag(a_ptr->flags, i);
2344 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2347 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2355 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2356 * Initialize the "a_info" array, by parsing an ascii "template" file
2358 * @param head ヘッダ構造体
2361 errr parse_a_info(char *buf, header *head)
2368 static artifact_type *a_ptr = NULL;
2371 /* Process 'N' for "New/Number/Name" */
2374 /* Find the colon before the name */
2375 s = my_strchr(buf + 2, ':');
2377 /* Verify that colon */
2380 /* Nuke the colon, advance to the name */
2383 /* Paranoia -- require a name */
2384 if (!*s) return (1);
2389 /* Verify information */
2390 if (i < error_idx) return (4);
2392 /* Verify information */
2393 if (i >= head->info_num) return (2);
2395 /* Save the index */
2398 /* Point at the "info" */
2401 /* Ignore everything */
2402 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2403 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2404 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2405 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2407 /* Store the name */
2408 if (!add_name(&a_ptr->name, head, s)) return (7);
2412 /* There better be a current a_ptr */
2413 else if (!a_ptr) return (3);
2418 /* 'E' から始まる行は英語名としている */
2419 else if (buf[0] == 'E')
2424 else if (buf[0] == 'E')
2426 /* Acquire the Text */
2429 /* Store the name */
2430 if (!add_name(&a_ptr->name, head, s)) return (7);
2434 /* Process 'D' for "Description" */
2435 else if (buf[0] == 'D')
2440 /* Acquire the text */
2445 /* Acquire the text */
2449 /* Store the text */
2450 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2454 /* Process 'I' for "Info" (one line only) */
2455 else if (buf[0] == 'I')
2457 int tval, sval, pval;
2459 /* Scan for the values */
2460 if (3 != sscanf(buf + 2, "%d:%d:%d",
2461 &tval, &sval, &pval)) return (1);
2463 /* Save the values */
2464 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2465 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2466 a_ptr->pval = (PARAMETER_VALUE)pval;
2469 /* Process 'W' for "More Info" (one line only) */
2470 else if (buf[0] == 'W')
2472 int level, rarity, wgt;
2475 /* Scan for the values */
2476 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2477 &level, &rarity, &wgt, &cost)) return (1);
2479 /* Save the values */
2480 a_ptr->level = (DEPTH)level;
2481 a_ptr->rarity = (RARITY)rarity;
2482 a_ptr->weight = (WEIGHT)wgt;
2483 a_ptr->cost = (PRICE)cost;
2486 /* Hack -- Process 'P' for "power" and such */
2487 else if (buf[0] == 'P')
2489 int ac, hd1, hd2, th, td, ta;
2491 /* Scan for the values */
2492 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2493 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2495 a_ptr->ac = (ARMOUR_CLASS)ac;
2496 a_ptr->dd = (DICE_NUMBER)hd1;
2497 a_ptr->ds = (DICE_SID)hd2;
2498 a_ptr->to_h = (HIT_PROB)th;
2499 a_ptr->to_d = (HIT_POINT)td;
2500 a_ptr->to_a = (ARMOUR_CLASS)ta;
2503 /* Hack -- Process 'U' for activation index */
2504 else if (buf[0] == 'U')
2507 n = grab_one_activation_flag(buf + 2);
2518 /* Hack -- Process 'F' for flags */
2519 else if (buf[0] == 'F')
2521 /* Parse every entry textually */
2522 for (s = buf + 2; *s; )
2524 /* Find the end of this entry */
2525 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2527 /* Nuke and skip any dividers */
2531 while ((*t == ' ') || (*t == '|')) t++;
2534 /* Parse this entry */
2535 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2537 /* Start the next entry */
2552 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2553 * Grab one flag in a ego-item_type from a textual string
2554 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2555 * @param what 参照元の文字列ポインタ
2556 * @return エラーがあった場合1、エラーがない場合0を返す
2558 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2563 for (i = 0; i < TR_FLAG_MAX; i++)
2565 if (streq(what, k_info_flags[i]))
2567 add_flag(e_ptr->flags, i);
2572 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2575 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2583 * @brief アイテムエゴ情報(e_info)のパース関数 /
2584 * Initialize the "e_info" array, by parsing an ascii "template" file
2586 * @param head ヘッダ構造体
2589 errr parse_e_info(char *buf, header *head)
2595 static ego_item_type *e_ptr = NULL;
2597 /* Just before the first record */
2600 /* Just before the first line */
2603 /* Process 'N' for "New/Number/Name" */
2606 /* Find the colon before the name */
2607 s = my_strchr(buf + 2, ':');
2609 /* Verify that colon */
2612 /* Nuke the colon, advance to the name */
2615 /* Paranoia -- require a name */
2616 if (!*s) return (1);
2621 /* Verify information */
2622 if (i < error_idx) return (4);
2624 /* Verify information */
2625 if (i >= head->info_num) return (2);
2627 /* Save the index */
2630 /* Point at the "info" */
2633 /* Store the name */
2634 if (!add_name(&e_ptr->name, head, s)) return (7);
2638 /* There better be a current e_ptr */
2639 else if (!e_ptr) return (3);
2644 /* 'E' から始まる行は英語名 */
2645 else if (buf[0] == 'E')
2650 else if (buf[0] == 'E')
2652 /* Acquire the Text */
2655 /* Store the name */
2656 if (!add_name(&e_ptr->name, head, s)) return (7);
2661 /* Process 'D' for "Description" */
2662 else if (buf[0] == 'D')
2664 /* Acquire the text */
2667 /* Store the text */
2668 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2673 /* Process 'X' for "Xtra" (one line only) */
2674 else if (buf[0] == 'X')
2678 /* Scan for the values */
2679 if (2 != sscanf(buf + 2, "%d:%d",
2680 &slot, &rating)) return (1);
2682 /* Save the values */
2683 e_ptr->slot = (INVENTORY_IDX)slot;
2684 e_ptr->rating = (PRICE)rating;
2687 /* Process 'W' for "More Info" (one line only) */
2688 else if (buf[0] == 'W')
2690 int level, rarity, pad2;
2693 /* Scan for the values */
2694 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2695 &level, &rarity, &pad2, &cost)) return (1);
2697 /* Save the values */
2698 e_ptr->level = level;
2699 e_ptr->rarity = (RARITY)rarity;
2700 /* e_ptr->weight = wgt; */
2704 /* Hack -- Process 'C' for "creation" */
2705 else if (buf[0] == 'C')
2707 int th, td, ta, pval;
2709 /* Scan for the values */
2710 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2711 &th, &td, &ta, &pval)) return (1);
2713 e_ptr->max_to_h = (HIT_PROB)th;
2714 e_ptr->max_to_d = (HIT_POINT)td;
2715 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2716 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2719 /* Hack -- Process 'U' for activation index */
2720 else if (buf[0] == 'U')
2723 n = grab_one_activation_flag(buf + 2);
2734 /* Hack -- Process 'F' for flags */
2735 else if (buf[0] == 'F')
2737 /* Parse every entry textually */
2738 for (s = buf + 2; *s; )
2740 /* Find the end of this entry */
2741 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2743 /* Nuke and skip any dividers */
2747 while ((*t == ' ') || (*t == '|')) t++;
2750 /* Parse this entry */
2751 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2753 /* Start the next entry */
2766 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2767 * Grab one (basic) flag in a monster_race from a textual string
2768 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2769 * @param what 参照元の文字列ポインタ
2772 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2774 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2777 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2780 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2783 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2786 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2789 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2792 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2795 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2803 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2804 * Grab one (spell) flag in a monster_race from a textual string
2805 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2806 * @param what 参照元の文字列ポインタ
2809 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2811 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2814 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2817 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2820 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2828 * @brief モンスター種族情報(r_info)のパース関数 /
2829 * Initialize the "r_info" array, by parsing an ascii "template" file
2831 * @param head ヘッダ構造体
2834 errr parse_r_info(char *buf, header *head)
2840 static monster_race *r_ptr = NULL;
2843 /* Process 'N' for "New/Number/Name" */
2846 /* Find the colon before the name */
2847 s = my_strchr(buf + 2, ':');
2849 /* Verify that colon */
2852 /* Nuke the colon, advance to the name */
2855 /* Paranoia -- require a name */
2856 if (!*s) return (1);
2861 /* Verify information */
2862 if (i < error_idx) return (4);
2864 /* Verify information */
2865 if (i >= head->info_num) return (2);
2867 /* Save the index */
2870 /* Point at the "info" */
2873 /* Store the name */
2874 if (!add_name(&r_ptr->name, head, s)) return (7);
2878 /* There better be a current r_ptr */
2879 else if (!r_ptr) return (3);
2884 /* 'E' から始まる行は英語名 */
2885 else if (buf[0] == 'E')
2887 /* Acquire the Text */
2890 /* Store the name */
2891 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2894 else if (buf[0] == 'E')
2896 /* Acquire the Text */
2899 /* Store the name */
2900 if (!add_name(&r_ptr->name, head, s)) return (7);
2903 /* Process 'D' for "Description" */
2904 else if (buf[0] == 'D')
2909 /* Acquire the text */
2914 /* Acquire the text */
2918 /* Store the text */
2919 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2922 /* Process 'G' for "Graphics" (one line only) */
2923 else if (buf[0] == 'G')
2927 if (buf[1] != ':') return (1);
2928 if (!buf[2]) return (1);
2929 if (buf[3] != ':') return (1);
2930 if (!buf[4]) return (1);
2932 /* Extract the char */
2935 /* Extract the attr */
2936 tmp = color_char_to_attr(buf[4]);
2937 if (tmp > 127) return (1);
2939 /* Save the values */
2940 r_ptr->d_char = sym;
2941 r_ptr->d_attr = tmp;
2944 /* Process 'I' for "Info" (one line only) */
2945 else if (buf[0] == 'I')
2947 int spd, hp1, hp2, aaf, ac, slp;
2949 /* Scan for the other values */
2950 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2951 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2953 /* Save the values */
2954 r_ptr->speed = (SPEED)spd;
2955 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2956 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2957 r_ptr->aaf = (POSITION)aaf;
2958 r_ptr->ac = (ARMOUR_CLASS)ac;
2959 r_ptr->sleep = (SLEEP_DEGREE)slp;
2962 /* Process 'W' for "More Info" (one line only) */
2963 else if (buf[0] == 'W')
2970 /* Scan for the values */
2971 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2972 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2974 /* Save the values */
2975 r_ptr->level = (DEPTH)lev;
2976 r_ptr->rarity = (RARITY)rar;
2977 r_ptr->extra = (BIT_FLAGS16)pad;
2978 r_ptr->mexp = (EXP)exp;
2979 r_ptr->next_exp = (EXP)nextexp;
2980 r_ptr->next_r_idx = (IDX)nextmon;
2983 /* Process 'R' for "Reinforcement" (up to six lines) */
2984 else if (buf[0] == 'R')
2987 /* Find the next empty blow slot (if any) */
2988 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2990 /* Oops, no more slots */
2991 if (i == 6) return (1);
2993 /* Scan for the values */
2994 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2995 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2996 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2997 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
3000 /* Process 'B' for "Blows" (up to four lines) */
3001 else if (buf[0] == 'B')
3005 /* Find the next empty blow slot (if any) */
3006 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3008 /* Oops, no more slots */
3009 if (i == 4) return (1);
3011 /* Analyze the first field */
3012 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3014 /* Terminate the field (if necessary) */
3015 if (*t == ':') *t++ = '\0';
3017 /* Analyze the method */
3018 for (n1 = 0; r_info_blow_method[n1]; n1++)
3020 if (streq(s, r_info_blow_method[n1])) break;
3023 /* Invalid method */
3024 if (!r_info_blow_method[n1]) return (1);
3026 /* Analyze the second field */
3027 for (s = t; *t && (*t != ':'); t++) /* loop */;
3029 /* Terminate the field (if necessary) */
3030 if (*t == ':') *t++ = '\0';
3032 /* Analyze effect */
3033 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3035 if (streq(s, r_info_blow_effect[n2])) break;
3038 /* Invalid effect */
3039 if (!r_info_blow_effect[n2]) return (1);
3041 /* Analyze the third field */
3042 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3044 /* Terminate the field (if necessary) */
3045 if (*t == 'd') *t++ = '\0';
3047 /* Save the method */
3048 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3050 /* Save the effect */
3051 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3053 /* Extract the damage dice and sides */
3054 r_ptr->blow[i].d_dice = atoi(s);
3055 r_ptr->blow[i].d_side = atoi(t);
3058 /* Process 'F' for "Basic Flags" (multiple lines) */
3059 else if (buf[0] == 'F')
3061 /* Parse every entry */
3062 for (s = buf + 2; *s; )
3064 /* Find the end of this entry */
3065 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3067 /* Nuke and skip any dividers */
3071 while (*t == ' ' || *t == '|') t++;
3074 /* Parse this entry */
3075 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3077 /* Start the next entry */
3082 /* Process 'S' for "Spell Flags" (multiple lines) */
3083 else if (buf[0] == 'S')
3085 /* Parse every entry */
3086 for (s = buf + 2; *s; )
3088 /* Find the end of this entry */
3089 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3091 /* Nuke and skip any dividers */
3095 while ((*t == ' ') || (*t == '|')) t++;
3098 /* Hack -- Read spell frequency */
3099 if (1 == sscanf(s, "1_IN_%d", &i))
3101 /* Extract a "frequency" */
3102 r_ptr->freq_spell = 100 / i;
3104 /* Start at next entry */
3109 /* Parse this entry */
3110 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3112 /* Start the next entry */
3117 /* Process 'A' for "Artifact Flags" (multiple lines) */
3118 else if (buf[0] == 'A')
3120 int id, per, rarity;
3122 /* Find the next empty blow slot (if any) */
3123 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3125 /* Oops, no more slots */
3126 if (i == 4) return (1);
3128 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3129 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3130 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3131 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3134 /* Process 'V' for "Arena power value ratio" */
3135 else if (buf[0] == 'V')
3138 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3139 r_ptr->arena_ratio = (PERCENTAGE)val;
3151 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3152 * Grab one flag for a dungeon type from a textual string
3153 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3154 * @param what 参照元の文字列ポインタ
3157 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3159 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3162 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3169 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3170 * Grab one (basic) flag in a monster_race from a textual string
3171 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3172 * @param what 参照元の文字列ポインタ
3175 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3177 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3180 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3183 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3186 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3189 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3192 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3195 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3198 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3205 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3206 * Grab one (spell) flag in a monster_race from a textual string
3207 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3208 * @param what 参照元の文字列ポインタ
3211 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3213 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3216 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3219 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3222 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3229 * @brief ダンジョン情報(d_info)のパース関数 /
3230 * Initialize the "d_info" array, by parsing an ascii "template" file
3232 * @param head ヘッダ構造体
3235 errr parse_d_info(char *buf, header *head)
3241 static dungeon_type *d_ptr = NULL;
3243 /* Process 'N' for "New/Number/Name" */
3246 /* Find the colon before the name */
3247 s = my_strchr(buf + 2, ':');
3249 /* Verify that colon */
3252 /* Nuke the colon, advance to the name */
3255 /* Paranoia -- require a name */
3256 if (!*s) return (1);
3261 /* Verify information */
3262 if (i < error_idx) return (4);
3264 /* Verify information */
3265 if (i >= head->info_num) return (2);
3267 /* Save the index */
3270 /* Point at the "info" */
3273 /* Store the name */
3274 if (!add_name(&d_ptr->name, head, s)) return (7);
3279 else if (buf[0] == 'E') return (0);
3281 else if (buf[0] == 'E')
3283 /* Acquire the Text */
3286 /* Store the name */
3287 if (!add_name(&d_ptr->name, head, s)) return (7);
3291 /* Process 'D' for "Description */
3292 else if (buf[0] == 'D')
3297 /* Acquire the text */
3302 /* Acquire the text */
3306 /* Store the text */
3307 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3310 /* Process 'W' for "More Info" (one line only) */
3311 else if (buf[0] == 'W')
3313 int min_lev, max_lev;
3315 int min_alloc, max_chance;
3316 int obj_good, obj_great;
3319 /* Scan for the values */
3320 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3321 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3323 /* Save the values */
3324 d_ptr->mindepth = (DEPTH)min_lev;
3325 d_ptr->maxdepth = (DEPTH)max_lev;
3326 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3327 d_ptr->mode = (BIT_FLAGS8)mode;
3328 d_ptr->min_m_alloc_level = min_alloc;
3329 d_ptr->max_m_alloc_chance = max_chance;
3330 d_ptr->obj_good = obj_good;
3331 d_ptr->obj_great = obj_great;
3332 d_ptr->pit = (BIT_FLAGS16)pit;
3333 d_ptr->nest = (BIT_FLAGS16)nest;
3336 /* Process 'P' for "Place Info" */
3337 else if (buf[0] == 'P')
3341 /* Scan for the values */
3342 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3344 /* Save the values */
3349 /* Process 'L' for "fLoor type" (one line only) */
3350 else if (buf[0] == 'L')
3354 /* Scan for the values */
3355 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3357 /* Save the values */
3358 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3360 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3361 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3363 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3365 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3368 /* Process 'A' for "wAll type" (one line only) */
3369 else if (buf[0] == 'A')
3373 /* Scan for the values */
3374 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3376 /* Save the values */
3377 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3379 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3380 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3382 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3385 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3386 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3388 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3389 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3391 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3392 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3394 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3395 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3398 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3399 else if (buf[0] == 'F')
3401 int artif = 0, monst = 0;
3403 /* Parse every entry */
3404 for (s = buf + 2; *s; )
3406 /* Find the end of this entry */
3407 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3409 /* Nuke and skip any dividers */
3413 while (*t == ' ' || *t == '|') t++;
3416 /* Hack -- Read Final Artifact */
3417 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3419 /* Extract a "Final Artifact" */
3420 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3422 /* Start at next entry */
3427 /* Hack -- Read Final Object */
3428 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3430 /* Extract a "Final Artifact" */
3431 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3433 /* Start at next entry */
3438 /* Hack -- Read Artifact Guardian */
3439 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3441 /* Extract a "Artifact Guardian" */
3442 d_ptr->final_guardian = (MONRACE_IDX)monst;
3444 /* Start at next entry */
3449 /* Hack -- Read Special Percentage */
3450 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3452 /* Extract a "Special %" */
3453 d_ptr->special_div = (PROB)monst;
3455 /* Start at next entry */
3460 /* Parse this entry */
3461 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3463 /* Start the next entry */
3468 /* Process 'M' for "Basic Flags" (multiple lines) */
3469 else if (buf[0] == 'M')
3471 /* Parse every entry */
3472 for (s = buf + 2; *s; )
3474 /* Find the end of this entry */
3475 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3477 /* Nuke and skip any dividers */
3481 while (*t == ' ' || *t == '|') t++;
3484 /* Hack -- Read monster symbols */
3485 if (!strncmp(s, "R_CHAR_", 7))
3487 /* Skip "R_CHAR_" */
3491 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3493 /* Start at next entry */
3498 /* Parse this entry */
3499 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3501 /* Start the next entry */
3506 /* Process 'S' for "Spell Flags" (multiple lines) */
3507 else if (buf[0] == 'S')
3509 /* Parse every entry */
3510 for (s = buf + 2; *s; )
3512 /* Find the end of this entry */
3513 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3515 /* Nuke and skip any dividers */
3519 while ((*t == ' ') || (*t == '|')) t++;
3522 /* Hack -- Read spell frequency */
3523 if (1 == sscanf(s, "1_IN_%d", &i))
3525 /* Start at next entry */
3530 /* Parse this entry */
3531 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3533 /* Start the next entry */
3545 #else /* ALLOW_TEMPLATES */
3551 #endif /* ALLOW_TEMPLATES */
3555 * @brief 地形情報の「F:」情報をパースする
3556 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3560 static errr parse_line_feature(char *buf)
3565 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3567 /* Tokenize the line */
3568 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3570 /* Letter to assign */
3571 int index = zz[0][0];
3573 /* Reset the info for the letter */
3574 letter[index].feature = feat_none;
3575 letter[index].monster = 0;
3576 letter[index].object = 0;
3577 letter[index].ego = 0;
3578 letter[index].artifact = 0;
3579 letter[index].trap = feat_none;
3580 letter[index].cave_info = 0;
3581 letter[index].special = 0;
3582 letter[index].random = RANDOM_NONE;
3588 letter[index].special = (s16b)atoi(zz[8]);
3592 if ((zz[7][0] == '*') && !zz[7][1])
3594 letter[index].random |= RANDOM_TRAP;
3598 letter[index].trap = f_tag_to_index(zz[7]);
3599 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3604 if (zz[6][0] == '*')
3606 letter[index].random |= RANDOM_ARTIFACT;
3607 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3609 else if (zz[6][0] == '!')
3611 if (p_ptr->inside_quest)
3613 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3618 letter[index].artifact = (IDX)atoi(zz[6]);
3623 if (zz[5][0] == '*')
3625 letter[index].random |= RANDOM_EGO;
3626 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3630 letter[index].ego = (IDX)atoi(zz[5]);
3635 if (zz[4][0] == '*')
3637 letter[index].random |= RANDOM_OBJECT;
3638 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3640 else if (zz[4][0] == '!')
3642 if (p_ptr->inside_quest)
3644 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3647 artifact_type *a_ptr = &a_info[a_idx];
3648 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3650 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3657 letter[index].object = (IDX)atoi(zz[4]);
3662 if (zz[3][0] == '*')
3664 letter[index].random |= RANDOM_MONSTER;
3665 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3667 else if (zz[3][0] == 'c')
3669 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3670 letter[index].monster = -atoi(zz[3] + 1);
3674 letter[index].monster = (IDX)atoi(zz[3]);
3679 letter[index].cave_info = atoi(zz[2]);
3683 if ((zz[1][0] == '*') && !zz[1][1])
3685 letter[index].random |= RANDOM_FEATURE;
3689 letter[index].feature = f_tag_to_index(zz[1]);
3690 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3703 * @brief 地形情報の「B:」情報をパースする
3704 * Process "B:<Index>:<Command>:..." -- Building definition
3708 static errr parse_line_building(char *buf)
3724 /* Get the building number */
3727 /* Find the colon after the building number */
3728 s = my_strchr(s, ':');
3730 /* Verify that colon */
3733 /* Nuke the colon, advance to the sub-index */
3736 /* Paranoia -- require a sub-index */
3737 if (!*s) return (1);
3739 /* Building definition sub-index */
3742 /* Building name, owner, race */
3745 if (tokenize(s + 2, 3, zz, 0) == 3)
3747 /* Name of the building */
3748 strcpy(building[index].name, zz[0]);
3750 /* Name of the owner */
3751 strcpy(building[index].owner_name, zz[1]);
3753 /* Race of the owner */
3754 strcpy(building[index].owner_race, zz[2]);
3759 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3762 /* Building Action */
3765 if (tokenize(s + 2, 8, zz, 0) >= 7)
3767 /* Index of the action */
3768 int action_index = atoi(zz[0]);
3770 /* Name of the action */
3771 strcpy(building[index].act_names[action_index], zz[1]);
3773 /* Cost of the action for members */
3774 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3776 /* Cost of the action for non-members */
3777 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3779 /* Letter assigned to the action */
3780 building[index].letters[action_index] = zz[4][0];
3783 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3785 /* Action restriction */
3786 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3791 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3794 /* Building Classes */
3798 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3799 for (i = 0; i < MAX_CLASS; i++)
3801 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3806 /* Building Races */
3810 n = tokenize(s + 2, MAX_RACES, zz, 0);
3811 for (i = 0; i < MAX_RACES; i++)
3813 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3818 /* Building Realms */
3822 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3823 for (i = 0; i < MAX_MAGIC; i++)
3825 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3832 /* Ignore scripts */
3838 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3847 * @brief フロアの所定のマスにオブジェクトを配置する
3848 * Place the object j_ptr to a grid
3849 * @param j_ptr オブジェクト構造体の参照ポインタ
3854 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3856 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3859 OBJECT_IDX o_idx = o_pop();
3861 /* Access new object */
3862 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3864 /* Structure copy */
3865 object_copy(o_ptr, j_ptr);
3872 o_ptr->held_m_idx = 0;
3875 o_ptr->next_o_idx = g_ptr->o_idx;
3877 g_ptr->o_idx = o_idx;
3881 * @brief クエスト用固定ダンジョンをフロアに生成する
3882 * Parse a sub-file of the "extra info"
3892 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3897 /* Skip "empty" lines */
3898 if (!buf[0]) return (0);
3900 /* Skip "blank" lines */
3901 if (iswspace(buf[0])) return (0);
3904 if (buf[0] == '#') return (0);
3906 /* Require "?:*" format */
3907 if (buf[1] != ':') return (1);
3910 /* Process "%:<fname>" */
3913 /* Attempt to Process the given file */
3914 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3917 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3920 return parse_line_feature(buf);
3923 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3924 else if (buf[0] == 'D')
3926 object_type object_type_body;
3928 /* Acquire the text */
3931 /* Length of the text */
3932 int len = strlen(s);
3934 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3936 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3938 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3942 OBJECT_IDX object_index = letter[idx].object;
3943 MONSTER_IDX monster_index = letter[idx].monster;
3944 int random = letter[idx].random;
3945 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3947 /* Lay down a floor */
3948 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3950 /* Only the features */
3951 if (init_flags & INIT_ONLY_FEATURES) continue;
3954 g_ptr->info = letter[idx].cave_info;
3956 /* Create a monster */
3957 if (random & RANDOM_MONSTER)
3959 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3961 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3963 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3965 else if (monster_index)
3967 int old_cur_num, old_max_num;
3970 if (monster_index < 0)
3972 monster_index = -monster_index;
3975 old_cur_num = r_info[monster_index].cur_num;
3976 old_max_num = r_info[monster_index].max_num;
3978 /* Make alive again */
3979 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3981 r_info[monster_index].cur_num = 0;
3982 r_info[monster_index].max_num = 1;
3985 /* Make alive again */
3986 /* Hack -- Non-unique Nazguls are semi-unique */
3987 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3989 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3991 r_info[monster_index].max_num++;
3996 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4000 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
4002 /* Make alive again for real unique monster */
4003 r_info[monster_index].cur_num = old_cur_num;
4004 r_info[monster_index].max_num = old_max_num;
4008 /* Object (and possible trap) */
4009 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4011 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4014 * Random trap and random treasure defined
4015 * 25% chance for trap and 75% chance for object
4017 if (randint0(100) < 75)
4019 place_object(*y, *x, 0L);
4026 current_floor_ptr->object_level = current_floor_ptr->base_level;
4028 else if (random & RANDOM_OBJECT)
4030 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4032 /* Create an out of deep object */
4033 if (randint0(100) < 75)
4034 place_object(*y, *x, 0L);
4035 else if (randint0(100) < 80)
4036 place_object(*y, *x, AM_GOOD);
4038 place_object(*y, *x, AM_GOOD | AM_GREAT);
4040 current_floor_ptr->object_level = current_floor_ptr->base_level;
4043 else if (random & RANDOM_TRAP)
4047 /* Hidden trap (or door) */
4048 else if (letter[idx].trap)
4050 g_ptr->mimic = g_ptr->feat;
4051 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4053 else if (object_index)
4055 object_type *o_ptr = &object_type_body;
4056 object_prep(o_ptr, object_index);
4058 if (o_ptr->tval == TV_GOLD)
4060 coin_type = object_index - OBJ_GOLD_LIST;
4065 /* Apply magic (no messages, no artifacts) */
4066 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4068 drop_here(o_ptr, *y, *x);
4074 if (a_info[artifact_index].cur_num)
4076 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4078 object_type *q_ptr = &forge;
4080 object_prep(q_ptr, k_idx);
4081 drop_here(q_ptr, *y, *x);
4085 if (create_named_art(artifact_index, *y, *x))
4086 a_info[artifact_index].cur_num = 1;
4090 /* Terrain special */
4091 g_ptr->special = letter[idx].special;
4099 /* Process "Q:<number>:<command>:... -- quest info */
4100 else if (buf[0] == 'Q')
4107 num = tokenize(buf + 2, 33, zz, 0);
4111 num = tokenize(buf + 3, 33, zz, 0);
4114 /* Have we enough parameters? */
4115 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4118 q_ptr = &(quest[atoi(zz[0])]);
4120 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4121 if (zz[1][0] == 'Q')
4123 if (init_flags & INIT_ASSIGN)
4125 monster_race *r_ptr;
4126 artifact_type *a_ptr;
4128 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4130 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4131 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4132 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4133 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4134 q_ptr->level = (DEPTH)atoi(zz[6]);
4135 q_ptr->r_idx = (IDX)atoi(zz[7]);
4136 q_ptr->k_idx = (IDX)atoi(zz[8]);
4137 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4139 if (num > 10) q_ptr->flags = atoi(zz[10]);
4141 r_ptr = &r_info[q_ptr->r_idx];
4142 if (r_ptr->flags1 & RF1_UNIQUE)
4143 r_ptr->flags1 |= RF1_QUESTOR;
4145 a_ptr = &a_info[q_ptr->k_idx];
4146 a_ptr->gen_flags |= TRG_QUESTITEM;
4151 else if (zz[1][0] == 'R')
4153 if (init_flags & INIT_ASSIGN)
4156 IDX idx, reward_idx = 0;
4158 for (idx = 2; idx < num; idx++)
4160 IDX a_idx = (IDX)atoi(zz[idx]);
4161 if (a_idx < 1) continue;
4162 if (a_info[a_idx].cur_num > 0) continue;
4164 if (one_in_(count)) reward_idx = a_idx;
4169 /* Set quest's rewarding artifact */
4170 q_ptr->k_idx = reward_idx;
4171 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4175 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4176 q_ptr->type = QUEST_TYPE_KILL_ALL;
4183 /* Process "Q:<q_index>:N:<name>" -- quest name */
4184 else if (zz[1][0] == 'N')
4186 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4188 strcpy(q_ptr->name, zz[2]);
4194 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4195 else if (zz[1][0] == 'T')
4197 if (init_flags & INIT_SHOW_TEXT)
4199 strcpy(quest_text[quest_text_line], zz[2]);
4207 /* Process "W:<command>: ..." -- info for the wilderness */
4208 else if (buf[0] == 'W')
4210 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4213 /* Process "P:<y>:<x>" -- player position */
4214 else if (buf[0] == 'P')
4216 if (init_flags & INIT_CREATE_DUNGEON)
4218 if (tokenize(buf + 2, 2, zz, 0) == 2)
4220 int panels_x, panels_y;
4222 /* Hack - Set the dungeon size */
4223 panels_y = (*y / SCREEN_HGT);
4224 if (*y % SCREEN_HGT) panels_y++;
4225 current_floor_ptr->height = panels_y * SCREEN_HGT;
4227 panels_x = (*x / SCREEN_WID);
4228 if (*x % SCREEN_WID) panels_x++;
4229 current_floor_ptr->width = panels_x * SCREEN_WID;
4231 /* Assume illegal panel */
4232 panel_row_min = current_floor_ptr->height;
4233 panel_col_min = current_floor_ptr->width;
4235 /* Place player in a quest level */
4236 if (p_ptr->inside_quest)
4240 /* Delete the monster (if any) */
4241 delete_monster(p_ptr->y, p_ptr->x);
4249 /* Place player in the town */
4250 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4252 p_ptr->oldpy = atoi(zz[0]);
4253 p_ptr->oldpx = atoi(zz[1]);
4261 /* Process "B:<Index>:<Command>:..." -- Building definition */
4262 else if (buf[0] == 'B')
4264 return parse_line_building(buf);
4267 /* Process "M:<type>:<maximum>" -- set maximum values */
4268 else if (buf[0] == 'M')
4270 if (tokenize(buf + 2, 2, zz, 0) == 2)
4273 if (zz[0][0] == 'T')
4275 max_towns = (TOWN_IDX)atoi(zz[1]);
4278 /* Maximum quests */
4279 else if (zz[0][0] == 'Q')
4281 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4285 else if (zz[0][0] == 'R')
4287 max_r_idx = (IDX)atoi(zz[1]);
4291 else if (zz[0][0] == 'K')
4293 max_k_idx = (IDX)atoi(zz[1]);
4297 else if (zz[0][0] == 'V')
4299 max_v_idx = (IDX)atoi(zz[1]);
4303 else if (zz[0][0] == 'F')
4305 max_f_idx = (IDX)atoi(zz[1]);
4309 else if (zz[0][0] == 'A')
4311 max_a_idx = (IDX)atoi(zz[1]);
4315 else if (zz[0][0] == 'E')
4317 max_e_idx = (IDX)atoi(zz[1]);
4321 else if (zz[0][0] == 'D')
4323 max_d_idx = (IDX)atoi(zz[1]);
4327 else if (zz[0][0] == 'O')
4329 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4333 else if (zz[0][0] == 'M')
4335 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4338 /* Wilderness size */
4339 else if (zz[0][0] == 'W')
4341 /* Maximum wild_x_size */
4342 if (zz[0][1] == 'X')
4343 current_world_ptr->max_wild_x = atoi(zz[1]);
4344 /* Maximum wild_y_size */
4345 if (zz[0][1] == 'Y')
4346 current_world_ptr->max_wild_y = atoi(zz[1]);
4360 static concptr variant = "ZANGBAND";
4364 * @brief クエスト用固定ダンジョン生成時の分岐処理
4365 * Helper function for "process_dungeon_file()"
4370 static concptr process_dungeon_file_expr(char **sp, char *fp)
4386 while (iswspace(*s)) s++;
4404 t = process_dungeon_file_expr(&s, &f);
4412 else if (streq(t, "IOR"))
4415 while (*s && (f != b2))
4417 t = process_dungeon_file_expr(&s, &f);
4418 if (*t && !streq(t, "0")) v = "1";
4423 else if (streq(t, "AND"))
4426 while (*s && (f != b2))
4428 t = process_dungeon_file_expr(&s, &f);
4429 if (*t && streq(t, "0")) v = "0";
4434 else if (streq(t, "NOT"))
4437 while (*s && (f != b2))
4439 t = process_dungeon_file_expr(&s, &f);
4440 if (*t && streq(t, "1")) v = "0";
4445 else if (streq(t, "EQU"))
4448 if (*s && (f != b2))
4450 t = process_dungeon_file_expr(&s, &f);
4452 while (*s && (f != b2))
4454 p = process_dungeon_file_expr(&s, &f);
4455 if (streq(t, p)) v = "1";
4460 else if (streq(t, "LEQ"))
4463 if (*s && (f != b2))
4465 t = process_dungeon_file_expr(&s, &f);
4467 while (*s && (f != b2))
4470 t = process_dungeon_file_expr(&s, &f);
4471 if (*t && atoi(p) > atoi(t)) v = "0";
4476 else if (streq(t, "GEQ"))
4479 if (*s && (f != b2))
4481 t = process_dungeon_file_expr(&s, &f);
4483 while (*s && (f != b2))
4486 t = process_dungeon_file_expr(&s, &f);
4488 /* Compare two numbers instead of string */
4489 if (*t && atoi(p) < atoi(t)) v = "0";
4495 while (*s && (f != b2))
4497 t = process_dungeon_file_expr(&s, &f);
4502 if (f != b2) v = "?x?x?";
4504 /* Extract final and Terminate */
4505 if ((f = *s) != '\0') *s++ = '\0';
4511 /* Accept all printables except spaces and brackets */
4513 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4515 if (iskanji(*s)) s++;
4519 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4522 /* Extract final and Terminate */
4523 if ((f = *s) != '\0') *s++ = '\0';
4529 if (streq(b + 1, "SYS"))
4535 else if (streq(b + 1, "GRAF"))
4540 else if (streq(b + 1, "MONOCHROME"))
4549 else if (streq(b + 1, "RACE"))
4551 v = _(rp_ptr->E_title, rp_ptr->title);
4555 else if (streq(b + 1, "CLASS"))
4557 v = _(cp_ptr->E_title, cp_ptr->title);
4561 else if (streq(b + 1, "REALM1"))
4563 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4567 else if (streq(b + 1, "REALM2"))
4569 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4573 else if (streq(b + 1, "PLAYER"))
4575 static char tmp_player_name[32];
4577 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4587 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4590 v = tmp_player_name;
4594 else if (streq(b + 1, "TOWN"))
4596 sprintf(tmp, "%d", p_ptr->town_num);
4601 else if (streq(b + 1, "LEVEL"))
4603 sprintf(tmp, "%d", p_ptr->lev);
4607 /* Current quest number */
4608 else if (streq(b + 1, "QUEST_NUMBER"))
4610 sprintf(tmp, "%d", p_ptr->inside_quest);
4614 /* Number of last quest */
4615 else if (streq(b + 1, "LEAVING_QUEST"))
4617 sprintf(tmp, "%d", leaving_quest);
4622 else if (prefix(b + 1, "QUEST_TYPE"))
4624 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4625 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4630 else if (prefix(b + 1, "QUEST"))
4632 /* "QUEST" uses a special parameter to determine the number of the quest */
4633 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4638 else if (prefix(b + 1, "RANDOM"))
4640 /* "RANDOM" uses a special parameter to determine the number of the quest */
4641 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
4646 else if (streq(b + 1, "VARIANT"))
4652 else if (streq(b + 1, "WILDERNESS"))
4655 sprintf(tmp, "NONE");
4657 sprintf(tmp, "LITE");
4659 sprintf(tmp, "NORMAL");
4678 void write_r_info_txt(void)
4680 int i, j, z, fc, bc;
4683 concptr flags[32 * 10];
4688 monster_race *r_ptr;
4690 monster_blow *b_ptr;
4692 FILE *fff = fopen("output.txt", "wt");
4696 BIT_FLAGS mode = -1;
4700 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4702 fprintf(fff, "# Version stamp (required)\n\n");
4705 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4708 fprintf(fff, "##### The Player #####\n\n");
4710 for (z = -1; z < alloc_race_size; z++)
4712 /* Output the monsters in order */
4713 i = (z >= 0) ? alloc_race_table[z].index : 0;
4715 /* Acquire the monster */
4718 /* Ignore empty monsters */
4719 if (!strlen(r_name + r_ptr->name)) continue;
4721 /* Ignore useless monsters */
4722 if (i && !r_ptr->speed) continue;
4724 /* Write a note if necessary */
4725 if (i && (!r_ptr->level != !mode))
4730 fprintf(fff, "\n##### Town monsters #####\n\n");
4732 /* Note the dungeon */
4735 fprintf(fff, "\n##### Normal monsters #####\n\n");
4738 /* Record the change */
4739 mode = r_ptr->level;
4742 /* Acquire the flags */
4743 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4744 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4745 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4746 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4747 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4748 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4749 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4750 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4751 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4752 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4754 /* Write New/Number/Name */
4755 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4758 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4760 /* Write Information */
4761 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4762 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4764 /* Write more information */
4765 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4768 for (j = 0; j < 4; j++)
4770 b_ptr = &(r_ptr->blow[j]);
4772 /* Stop when done */
4773 if (!b_ptr->method) break;
4775 /* Write the blows */
4776 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4777 r_info_blow_effect[b_ptr->effect],
4778 b_ptr->d_dice, b_ptr->d_side);
4780 for (fc = 0, j = 0; j < 32 * 3; j++)
4782 /* Check this flag */
4783 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4786 /* Extract the extra flags */
4787 for (j = 32 * 6; j < 32 * 10; j++)
4789 /* Check this flag */
4790 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4793 /* Write the flags */
4794 for (j = 0; j < fc;)
4798 /* Start the line */
4801 for (bc = 0; (bc < 60) && (j < fc); j++)
4805 /* Format the flag */
4806 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4808 /* Add it to the buffer */
4811 /* Note the length */
4815 /* Done with this line; write it */
4816 fprintf(fff, "%s\n", buf);
4819 /* Write Spells if applicable */
4820 if (r_ptr->freq_spell)
4822 /* Write the frequency */
4823 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4825 /* Extract the spell flags */
4826 for (fc = 0, j = 96; j < 192; 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, t = buf + 2; (bc < 60) && (j < fc); j++)
4844 /* Format the flag */
4845 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4849 /* Note the length */
4856 /* Done with this line; write it */
4857 fprintf(fff, "%s\n", buf);
4861 /* Acquire the description */
4862 desc = r_text + r_ptr->text;
4863 dlen = strlen(desc);
4865 /* Write Description */
4866 for (j = 0; j < dlen;)
4870 /* Start the line */
4873 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4881 /* Done with this line; write it */
4882 fprintf(fff, "%s\n", buf);
4885 /* Space between entries */
4896 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4897 * Helper function for "process_dungeon_file()"
4905 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4911 bool bypass = FALSE;
4912 int x = xmin, y = ymin;
4915 /* Build the filename */
4916 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4919 fp = my_fopen(buf, "r");
4922 if (!fp) return (-1);
4925 /* Process the file */
4926 while (0 == my_fgets(fp, buf, sizeof(buf)))
4932 /* Skip "empty" lines */
4933 if (!buf[0]) continue;
4935 /* Skip "blank" lines */
4936 if (iswspace(buf[0])) continue;
4939 if (buf[0] == '#') continue;
4942 /* Process "?:<expr>" */
4943 if ((buf[0] == '?') && (buf[1] == ':'))
4952 /* Parse the expr */
4953 v = process_dungeon_file_expr(&s, &f);
4956 bypass = (streq(v, "0") ? TRUE : FALSE);
4960 /* Apply conditionals */
4961 if (bypass) continue;
4963 /* Process the line */
4964 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4975 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4977 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4978 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);