5 #include "dungeon-file.h"
11 #include "player-skill.h"
16 #include "rooms-vault.h"
17 #include "objectkind.h"
18 #include "monsterrace.h"
20 dungeon_grid letter[255];
24 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
28 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
29 * This software may be copied and distributed for educational, research,
30 * and not for profit purposes provided that this copyright and statement
31 * are included in all such copies. Other copyrights may also apply.
32 * 2014 Deskull rearranged comment for Doxygen.\n
36 * This file is used to initialize various variables and arrays for the
37 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
38 * the common limitation of "read()" and "write()" to only 32767 bytes
40 * Several of the arrays for Angband are built from "template" files in
41 * the "lib/file" directory, from which quick-load binary "image" files
42 * are constructed whenever they are not present in the "lib/data"
43 * directory, or if those files become obsolete, if we are allowed.
44 * Warning -- the "ascii" file parsers use a minor hack to collect the
45 * name and text information in a single pass. Thus, the game will not
46 * be able to load any template file with more than 20K of names or 60K
47 * of text, even though technically, up to 64K should be legal.
49 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
50 * in this file is compiled out, and the game will not run unless valid
51 * "binary template files" already exist in "lib/data". Thus, one can
52 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
53 * "*.raw" files in "lib/data", and then quit, and recompile without
54 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
55 * from changing the ascii template files in potentially dangerous ways.
56 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
57 * このファイルのコードの多くはコンパイル出力され、本ゲームは
58 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
59 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
60 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
61 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
62 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
63 * テンプレートファイルを変更することを妨げることができる。
64 * The code could actually be removed and placed into a "stand-alone"
65 * program, but that feels a little silly, especially considering some
66 * of the platforms that we currently support.
71 #include "dungeon-file.h"
76 #include "cmd-activate.h"
80 #include "view-mainwindow.h"
81 #include "player-class.h"
85 #ifdef ALLOW_TEMPLATES
90 /*** Helper arrays for parsing ascii template files ***/
94 * Monster Blow Methods
96 static concptr r_info_blow_method[] =
129 * モンスターの打撃属性トークンの定義 /
130 * Monster Blow Effects
132 static concptr r_info_blow_effect[] =
177 static concptr f_info_flags[] =
302 static concptr r_info_flags1[] =
342 static concptr r_info_flags2[] =
382 static concptr r_info_flags3[] =
422 static concptr r_info_flags4[] =
459 * モンスター特性トークン(発動型能力1) /
462 static concptr r_a_ability_flags1[] =
499 * モンスター特性トークン(発動型能力2) /
502 static concptr r_a_ability_flags2[] =
519 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
540 * モンスター特性トークン(発動型能力3) /
543 static concptr r_a_ability_flags3[] =
582 * モンスター特性トークン(発動型能力4) /
585 static concptr r_a_ability_flags4[] =
627 static concptr r_info_flags7[] =
667 static concptr r_info_flags8[] =
699 "WILD_SWAMP", /* ToDo: Implement Swamp */
708 static concptr r_info_flags9[] =
747 * モンスター特性トークンの定義R(耐性) /
750 static concptr r_info_flagsr[] =
788 * オブジェクト基本特性トークンの定義 /
791 static concptr k_info_flags[] =
888 "XXX3", /* Fake flag for Smith */
889 "XXX4", /* Fake flag for Smith */
939 * オブジェクト生成特性トークンの定義 /
942 static concptr k_info_gen_flags[] =
982 static concptr d_info_flags1[] =
1020 * @brief データの可変文字列情報をテキストとして保管する /
1021 * Add a text to the text-storage and store offset to it.
1022 * @param offset 文字列保管ポインタからのオフセット
1023 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1025 * @param normal_text テキストの正規化を行う
1028 * Returns FALSE when there isn't enough space available to store
1031 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1033 /* Hack -- Verify space */
1034 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1040 /* Advance and save the text index */
1041 *offset = ++head->text_size;
1044 /* Additional text */
1045 else if (normal_text)
1048 * If neither the end of the last line nor
1049 * the beginning of current line is not a space,
1050 * fill up a space as a correct separator of two words.
1052 if (head->text_size > 0 &&
1054 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1055 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1056 (buf[0] != ' ') && !iskanji(buf[0])
1058 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1063 /* Append a space */
1064 *(head->text_ptr + head->text_size) = ' ';
1066 /* Advance the index */
1071 /* Append chars to the text */
1072 strcpy(head->text_ptr + head->text_size, buf);
1074 /* Advance the index */
1075 head->text_size += strlen(buf);
1083 * @brief データの可変文字列情報を名前として保管する /
1084 * Add a name to the name-storage and return an offset to it.
1085 * @param offset 文字列保管ポインタからのオフセット
1086 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1090 * Returns FALSE when there isn't enough space available to store
1093 static bool add_name(u32b *offset, header *head, concptr buf)
1095 /* Hack -- Verify space */
1096 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1102 /* Advance and save the name index */
1103 *offset = ++head->name_size;
1106 /* Append chars to the names */
1107 strcpy(head->name_ptr + head->name_size, buf);
1109 /* Advance the index */
1110 head->name_size += strlen(buf);
1118 * @brief データの可変文字列情報をタグとして保管する /
1119 * Add a tag to the tag-storage and return an offset to it.
1120 * @param offset 文字列保管ポインタからのオフセット
1121 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1125 * Returns FALSE when there isn't enough space available to store
1128 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1132 /* Search for an existing (fake) tag */
1133 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1136 if (streq(&head->tag_ptr[i], buf)) break;
1139 /* There was no existing tag */
1140 if (i >= head->tag_size)
1142 /* Hack -- Verify space */
1143 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1146 /* Append chars to the tags */
1147 strcpy(head->tag_ptr + head->tag_size, buf);
1149 /* Point the new tag */
1152 /* Advance the index */
1153 head->tag_size += strlen(buf) + 1;
1156 /* Return offset of the tag */
1164 /*** Initialize from ascii template files ***/
1168 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1169 * Initialize an "*_info" array, by parsing an ascii "template" file
1170 * @param fp 読み取りに使うファイルポインタ
1171 * @param buf 読み取りに使うバッファ領域
1172 * @param head ヘッダ構造体
1173 * @param parse_info_txt_line パース関数
1176 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1180 /* Just before the first record */
1183 /* Just before the first line */
1187 /* Prepare the "fake" stuff */
1188 head->name_size = 0;
1189 head->text_size = 0;
1193 while (0 == my_fgets(fp, buf, 1024))
1195 /* Advance the line number */
1198 /* Skip comments and blank lines */
1199 if (!buf[0] || (buf[0] == '#')) continue;
1201 /* Verify correct "colon" format */
1202 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1205 /* Hack -- Process 'V' for "Version" */
1212 /* Mega Hack -- Calculate Check Sum */
1213 if (buf[0] != 'N' && buf[0] != 'D')
1216 for (i = 0; buf[i]; i++)
1218 head->v_extra += (byte)buf[i];
1219 head->v_extra ^= (1 << (i % 8));
1223 /* Parse the line */
1224 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1229 /* Complete the "name" and "text" sizes */
1230 if (head->name_size) head->name_size++;
1231 if (head->text_size) head->text_size++;
1239 * @brief Vault情報(v_info)のパース関数 /
1240 * Initialize the "v_info" array, by parsing an ascii "template" file
1242 * @param head ヘッダ構造体
1245 errr parse_v_info(char *buf, header *head)
1251 static vault_type *v_ptr = NULL;
1253 /* Process 'N' for "New/Number/Name" */
1256 /* Find the colon before the name */
1257 s = my_strchr(buf + 2, ':');
1259 /* Verify that colon */
1262 /* Nuke the colon, advance to the name */
1265 /* Paranoia -- require a name */
1266 if (!*s) return (1);
1271 /* Verify information */
1272 if (i <= error_idx) return (4);
1274 /* Verify information */
1275 if (i >= head->info_num) return (2);
1277 /* Save the index */
1280 /* Point at the "info" */
1283 /* Store the name */
1284 if (!add_name(&v_ptr->name, head, s)) return (7);
1287 /* There better be a current v_ptr */
1288 else if (!v_ptr) return (3);
1290 /* Process 'D' for "Description" */
1291 else if (buf[0] == 'D')
1293 /* Acquire the text */
1296 /* Store the text */
1297 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1300 /* Process 'X' for "Extra info" (one line only) */
1301 else if (buf[0] == 'X')
1303 EFFECT_ID typ, rat, hgt, wid;
1305 /* Scan for the values */
1306 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1307 &typ, &rat, &hgt, &wid)) return (1);
1309 /* Save the values */
1310 v_ptr->typ = (ROOM_IDX)typ;
1311 v_ptr->rat = (PROB)rat;
1312 v_ptr->hgt = (POSITION)hgt;
1313 v_ptr->wid = (POSITION)wid;
1324 * @brief 職業技能情報(s_info)のパース関数 /
1325 * Initialize the "s_info" array, by parsing an ascii "template" file
1327 * @param head ヘッダ構造体
1330 errr parse_s_info(char *buf, header *head)
1335 static skill_table *s_ptr = NULL;
1338 /* Process 'N' for "New/Number/Name" */
1344 /* Verify information */
1345 if (i <= error_idx) return (4);
1347 /* Verify information */
1348 if (i >= head->info_num) return (2);
1350 /* Save the index */
1353 /* Point at the "info" */
1357 /* There better be a current s_ptr */
1358 else if (!s_ptr) return (3);
1360 /* Process 'W' for "Weapon exp" */
1361 else if (buf[0] == 'W')
1363 int tval, sval, start, max;
1364 const s16b exp_conv_table[] =
1366 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1367 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1370 /* Scan for the values */
1371 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1372 &tval, &sval, &start, &max)) return (1);
1374 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1375 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1377 /* Save the values */
1378 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1379 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1382 /* Process 'S' for "Skill exp" */
1383 else if (buf[0] == 'S')
1385 int num, start, max;
1387 /* Scan for the values */
1388 if (3 != sscanf(buf + 2, "%d:%d:%d",
1389 &num, &start, &max)) return (1);
1391 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1392 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1394 /* Save the values */
1395 s_ptr->s_start[num] = (SUB_EXP)start;
1396 s_ptr->s_max[num] = (SUB_EXP)max;
1408 * @brief 職業魔法情報(m_info)のパース関数 /
1409 * Initialize the "m_info" array, by parsing an ascii "template" file
1411 * @param head ヘッダ構造体
1414 errr parse_m_info(char *buf, header *head)
1421 static player_magic *m_ptr = NULL;
1424 static int realm, magic_idx = 0, readable = 0;
1427 /* Process 'N' for "New/Number/Name" */
1433 /* Verify information */
1434 if (i <= error_idx) return (4);
1436 /* Verify information */
1437 if (i >= head->info_num) return (2);
1439 /* Save the index */
1442 /* Point at the "info" */
1446 /* There better be a current m_ptr */
1447 else if (!m_ptr) return (3);
1449 /* Process 'I' for "Info" (one line only) */
1450 else if (buf[0] == 'I')
1453 int xtra, type, first, weight;
1455 /* Find the colon before the name */
1456 s = my_strchr(buf + 2, ':');
1458 /* Verify that colon */
1461 /* Nuke the colon, advance to the name */
1466 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1467 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1468 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1469 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1470 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1475 /* Find the colon before the name */
1476 s = my_strchr(s, ':');
1478 /* Verify that colon */
1481 /* Nuke the colon, advance to the name */
1484 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1485 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1486 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1487 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1488 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1489 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1493 /* Scan for the values */
1494 if (4 != sscanf(s, "%x:%d:%d:%d",
1495 (uint *)&xtra, &type, &first, &weight)) return (1);
1497 m_ptr->spell_xtra = xtra;
1498 m_ptr->spell_type = type;
1499 m_ptr->spell_first = first;
1500 m_ptr->spell_weight = weight;
1504 /* Process 'R' for "Realm" (one line only) */
1505 else if (buf[0] == 'R')
1507 /* Scan for the values */
1508 if (2 != sscanf(buf + 2, "%d:%d",
1509 &realm, &readable)) return (1);
1514 else if (buf[0] == 'T')
1516 int level, mana, fail, exp;
1518 if (!readable) return (1);
1519 /* Scan for the values */
1520 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1521 &level, &mana, &fail, &exp)) return (1);
1523 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1524 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1525 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1526 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1539 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1540 * Grab one flag from a textual string
1541 * @param flags ビットフラグを追加する先の参照ポインタ
1542 * @param names トークン定義配列
1543 * @param what 参照元の文字列ポインタ
1546 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1551 for (i = 0; i < 32; i++)
1553 if (streq(what, names[i]))
1555 *flags |= (1L << i);
1565 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1566 * Grab one flag in an feature_type from a textual string
1567 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1568 * @param what 参照元の文字列ポインタ
1571 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1576 for (i = 0; i < FF_FLAG_MAX; i++)
1578 if (streq(what, f_info_flags[i]))
1580 add_flag(f_ptr->flags, i);
1585 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1588 return PARSE_ERROR_GENERIC;
1593 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1594 * Grab an action in an feature_type from a textual string
1595 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1596 * @param what 参照元の文字列ポインタ
1597 * @param count ステートの保存先ID
1600 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1605 for (i = 0; i < FF_FLAG_MAX; i++)
1607 if (streq(what, f_info_flags[i]))
1609 f_ptr->state[count].action = i;
1614 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1617 return PARSE_ERROR_GENERIC;
1622 * @brief 地形情報(f_info)のパース関数 /
1623 * Initialize the "f_info" array, by parsing an ascii "template" file
1625 * @param head ヘッダ構造体
1628 errr parse_f_info(char *buf, header *head)
1635 static feature_type *f_ptr = NULL;
1638 /* Process 'N' for "New/Number/Name" */
1641 /* Find the colon before the name */
1642 s = my_strchr(buf + 2, ':');
1646 /* Nuke the colon, advance to the name */
1653 /* Verify information */
1654 if (i <= error_idx) return (4);
1656 /* Verify information */
1657 if (i >= head->info_num) return (2);
1659 /* Save the index */
1662 /* Point at the "info" */
1665 /* Tag name is given */
1669 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1672 /* Default "mimic" */
1673 f_ptr->mimic = (FEAT_IDX)i;
1675 /* Default "destroyed state" -- if not specified */
1676 f_ptr->destroyed = (FEAT_IDX)i;
1678 /* Default "states" */
1679 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1682 /* There better be a current f_ptr */
1683 else if (!f_ptr) return (3);
1686 else if (buf[0] == 'J')
1688 /* Store the name */
1689 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1692 else if (buf[0] == 'E')
1694 /* Ignore english name */
1697 else if (buf[0] == 'J')
1699 /* Ignore Japanese name */
1702 else if (buf[0] == 'E')
1704 /* Acquire the Text */
1707 /* Store the name */
1708 if (!add_name(&f_ptr->name, head, s)) return (7);
1713 /* Process 'M' for "Mimic" (one line only) */
1714 else if (buf[0] == 'M')
1718 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1720 /* Record a fake tag index */
1721 f_ptr->mimic_tag = offset;
1725 /* Process 'G' for "Graphics" (one line only) */
1726 else if (buf[0] == 'G')
1730 char char_tmp[F_LIT_MAX];
1731 if (buf[1] != ':') return (1);
1732 if (!buf[2]) return (1);
1733 if (buf[3] != ':') return (1);
1734 if (!buf[4]) return (1);
1736 /* Extract the char */
1737 char_tmp[F_LIT_STANDARD] = buf[2];
1739 /* Extract the color */
1740 s_attr = color_char_to_attr(buf[4]);
1741 if (s_attr > 127) return (1);
1743 /* Save the standard values */
1744 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1745 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1747 /* Is this feature supports lighting? */
1750 /* G:c:a:LIT (default) */
1751 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1753 /* G:c:a:lc:la:dc:da */
1754 if (!streq(buf + 6, "LIT"))
1756 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1758 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1759 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1760 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1761 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1763 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1765 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1768 /* Use default lighting */
1771 /* No lighting support */
1772 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1775 /* Extract the color */
1776 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1777 if (f_ptr->d_attr[j] > 127) return 1;
1780 f_ptr->d_char[j] = char_tmp[j];
1786 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1788 f_ptr->d_attr[j] = s_attr;
1789 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1795 /* Hack -- Process 'F' for flags */
1796 else if (buf[0] == 'F')
1798 /* Parse every entry textually */
1799 for (s = buf + 2; *s; )
1801 /* Find the end of this entry */
1802 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1804 /* Nuke and skip any dividers */
1808 while (*t == ' ' || *t == '|') t++;
1811 /* Hack -- Read feature subtype */
1812 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1814 /* Extract a "subtype" */
1815 f_ptr->subtype = (FEAT_SUBTYPE)i;
1817 /* Start at next entry */
1823 /* Hack -- Read feature power */
1824 if (1 == sscanf(s, "POWER_%d", &i))
1826 /* Extract a "power" */
1827 f_ptr->power = (FEAT_POWER)i;
1829 /* Start at next entry */
1834 /* Parse this entry */
1835 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1837 /* Start the next entry */
1842 /* Process 'W' for "More Info" (one line only) */
1843 else if (buf[0] == 'W')
1847 /* Scan for the value */
1848 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1850 /* Save the value */
1851 f_ptr->priority = (FEAT_PRIORITY)priority;
1854 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1855 else if (buf[0] == 'K')
1859 /* Find the next empty state slot (if any) */
1860 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1862 /* Oops, no more slots */
1863 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1865 /* Analyze the first field */
1866 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1868 /* Terminate the field (if necessary) */
1869 if (*t == ':') *t++ = '\0';
1871 /* Is this default entry? */
1872 if (streq(s, "DESTROYED"))
1874 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1876 /* Record a fake tag index */
1877 f_ptr->destroyed_tag = offset;
1882 f_ptr->state[i].action = 0;
1884 /* Parse this entry */
1885 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1887 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1889 /* Record a fake tag index */
1890 f_ptr->state[i].result_tag = offset;
1902 * @brief 地形タグからIDを得る /
1903 * Convert a fake tag to a real feat index
1907 s16b f_tag_to_index(concptr str)
1911 /* Search for real index corresponding to this fake tag */
1912 for (i = 0; i < f_head.info_num; i++)
1914 if (streq(f_tag + f_info[i].tag, str))
1916 /* Return the index */
1927 * @brief 地形タグからIDを得る /
1928 * Search for real index corresponding to this fake tag
1929 * @param feat タグ文字列のオフセット
1930 * @return 地形ID。該当がないなら-1
1932 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1936 /* Don't convert non-fake tag */
1942 /* Search for real index corresponding to this fake tag */
1943 for (i = 0; i < f_head.info_num; i++)
1945 if (feat == f_info[i].tag)
1947 /* Record real index */
1953 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1959 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1960 * Retouch fake tags of f_info
1961 * @param head ヘッダ構造体
1964 void retouch_f_info(header *head)
1968 /* Convert fake tags to real feat indices */
1969 for (i = 0; i < head->info_num; i++)
1971 feature_type *f_ptr = &f_info[i];
1974 k = search_real_feat(f_ptr->mimic_tag);
1975 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1976 k = search_real_feat(f_ptr->destroyed_tag);
1977 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1978 for (j = 0; j < MAX_FEAT_STATES; j++)
1980 k = search_real_feat(f_ptr->state[j].result_tag);
1981 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1988 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1989 * Grab one flag in an object_kind from a textual string
1990 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1991 * @param what 参照元の文字列ポインタ
1994 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1999 for (i = 0; i < TR_FLAG_MAX; i++)
2001 if (streq(what, k_info_flags[i]))
2003 add_flag(k_ptr->flags, i);
2008 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2011 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2018 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2019 * Grab one activation index flag
2020 * @param what 参照元の文字列ポインタ
2023 static byte grab_one_activation_flag(concptr what)
2029 if (activation_info[i].flag == NULL) break;
2031 if (streq(what, activation_info[i].flag))
2033 return activation_info[i].index;
2043 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2051 * @brief ベースアイテム(k_info)のパース関数 /
2052 * Initialize the "k_info" array, by parsing an ascii "template" file
2054 * @param head ヘッダ構造体
2057 errr parse_k_info(char *buf, header *head)
2064 static object_kind *k_ptr = NULL;
2067 /* Process 'N' for "New/Number/Name" */
2074 /* Find the colon before the name */
2075 s = my_strchr(buf + 2, ':');
2077 /* Verify that colon */
2080 /* Nuke the colon, advance to the name */
2086 /* Verify information */
2087 if (i <= error_idx) return (4);
2089 /* Verify information */
2090 if (i >= head->info_num) return (2);
2092 /* Save the index */
2095 /* Point at the "info" */
2099 /* Paranoia -- require a name */
2100 if (!*s) return (1);
2102 /* Find the colon before the flavor */
2103 flavor = my_strchr(s, ':');
2105 /* Verify that colon */
2108 /* Nuke the colon, advance to the flavor */
2111 /* Store the flavor */
2112 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2115 /* Store the name */
2116 if (!add_name(&k_ptr->name, head, s)) return (7);
2120 /* There better be a current k_ptr */
2121 else if (!k_ptr) return (3);
2126 /* 'E' から始まる行は英語名としている */
2127 else if (buf[0] == 'E')
2132 else if (buf[0] == 'E')
2136 /* Acquire the name */
2139 /* Find the colon before the flavor */
2140 flavor = my_strchr(s, ':');
2142 /* Verify that colon */
2145 /* Nuke the colon, advance to the flavor */
2148 /* Store the flavor */
2149 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2152 /* Store the name */
2153 if (!add_name(&k_ptr->name, head, s)) return (7);
2157 /* Process 'D' for "Description" */
2158 else if (buf[0] == 'D')
2163 /* Acquire the text */
2168 /* Acquire the text */
2172 /* Store the text */
2173 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2176 /* Process 'G' for "Graphics" (one line only) */
2177 else if (buf[0] == 'G')
2181 if (buf[1] != ':') return (1);
2182 if (!buf[2]) return (1);
2183 if (buf[3] != ':') return (1);
2184 if (!buf[4]) return (1);
2186 /* Extract the char */
2189 /* Extract the attr */
2190 tmp = color_char_to_attr(buf[4]);
2191 if (tmp > 127) return (1);
2193 /* Save the values */
2194 k_ptr->d_attr = tmp;
2195 k_ptr->d_char = sym;
2198 /* Process 'I' for "Info" (one line only) */
2199 else if (buf[0] == 'I')
2201 int tval, sval, pval;
2203 /* Scan for the values */
2204 if (3 != sscanf(buf + 2, "%d:%d:%d",
2205 &tval, &sval, &pval)) return (1);
2207 /* Save the values */
2208 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2209 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2210 k_ptr->pval = (PARAMETER_VALUE)pval;
2213 /* Process 'W' for "More Info" (one line only) */
2214 else if (buf[0] == 'W')
2216 int level, extra, wgt;
2219 /* Scan for the values */
2220 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2221 &level, &extra, &wgt, &cost)) return (1);
2223 /* Save the values */
2224 k_ptr->level = (DEPTH)level;
2225 k_ptr->extra = (BIT_FLAGS8)extra;
2226 k_ptr->weight = (WEIGHT)wgt;
2227 k_ptr->cost = (PRICE)cost;
2230 /* Process 'A' for "Allocation" (one line only) */
2231 else if (buf[0] == 'A')
2234 /* Simply read each number following a colon */
2235 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2237 /* Default chance */
2238 k_ptr->chance[i] = 1;
2240 /* Store the attack damage index */
2241 k_ptr->locale[i] = atoi(s + 1);
2243 /* Find the slash */
2244 t = my_strchr(s + 1, '/');
2246 /* Find the next colon */
2247 s = my_strchr(s + 1, ':');
2249 /* If the slash is "nearby", use it */
2250 if (t && (!s || t < s))
2252 int chance = atoi(t + 1);
2253 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2258 /* Hack -- Process 'P' for "power" and such */
2259 else if (buf[0] == 'P')
2261 int ac, hd1, hd2, th, td, ta;
2263 /* Scan for the values */
2264 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2265 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2267 k_ptr->ac = (ARMOUR_CLASS)ac;
2268 k_ptr->dd = (DICE_NUMBER)hd1;
2269 k_ptr->ds = (DICE_SID)hd2;
2270 k_ptr->to_h = (HIT_PROB)th;
2271 k_ptr->to_d = (HIT_POINT)td;
2272 k_ptr->to_a = (ARMOUR_CLASS)ta;
2275 /* Hack -- Process 'U' for activation index */
2276 else if (buf[0] == 'U')
2279 n = grab_one_activation_flag(buf + 2);
2290 /* Hack -- Process 'F' for flags */
2291 else if (buf[0] == 'F')
2293 /* Parse every entry textually */
2294 for (s = buf + 2; *s; )
2296 /* Find the end of this entry */
2297 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2299 /* Nuke and skip any dividers */
2303 while (*t == ' ' || *t == '|') t++;
2306 /* Parse this entry */
2307 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2309 /* Start the next entry */
2323 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2324 * Grab one activation index flag
2325 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2326 * @param what 参照元の文字列ポインタ
2327 * @return エラーがあった場合1、エラーがない場合0を返す
2329 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2334 for (i = 0; i < TR_FLAG_MAX; i++)
2336 if (streq(what, k_info_flags[i]))
2338 add_flag(a_ptr->flags, i);
2343 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2346 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2354 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2355 * Initialize the "a_info" array, by parsing an ascii "template" file
2357 * @param head ヘッダ構造体
2360 errr parse_a_info(char *buf, header *head)
2367 static artifact_type *a_ptr = NULL;
2370 /* Process 'N' for "New/Number/Name" */
2373 /* Find the colon before the name */
2374 s = my_strchr(buf + 2, ':');
2376 /* Verify that colon */
2379 /* Nuke the colon, advance to the name */
2382 /* Paranoia -- require a name */
2383 if (!*s) return (1);
2388 /* Verify information */
2389 if (i < error_idx) return (4);
2391 /* Verify information */
2392 if (i >= head->info_num) return (2);
2394 /* Save the index */
2397 /* Point at the "info" */
2400 /* Ignore everything */
2401 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2402 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2403 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2404 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2406 /* Store the name */
2407 if (!add_name(&a_ptr->name, head, s)) return (7);
2411 /* There better be a current a_ptr */
2412 else if (!a_ptr) return (3);
2417 /* 'E' から始まる行は英語名としている */
2418 else if (buf[0] == 'E')
2423 else if (buf[0] == 'E')
2425 /* Acquire the Text */
2428 /* Store the name */
2429 if (!add_name(&a_ptr->name, head, s)) return (7);
2433 /* Process 'D' for "Description" */
2434 else if (buf[0] == 'D')
2439 /* Acquire the text */
2444 /* Acquire the text */
2448 /* Store the text */
2449 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2453 /* Process 'I' for "Info" (one line only) */
2454 else if (buf[0] == 'I')
2456 int tval, sval, pval;
2458 /* Scan for the values */
2459 if (3 != sscanf(buf + 2, "%d:%d:%d",
2460 &tval, &sval, &pval)) return (1);
2462 /* Save the values */
2463 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2464 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2465 a_ptr->pval = (PARAMETER_VALUE)pval;
2468 /* Process 'W' for "More Info" (one line only) */
2469 else if (buf[0] == 'W')
2471 int level, rarity, wgt;
2474 /* Scan for the values */
2475 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2476 &level, &rarity, &wgt, &cost)) return (1);
2478 /* Save the values */
2479 a_ptr->level = (DEPTH)level;
2480 a_ptr->rarity = (RARITY)rarity;
2481 a_ptr->weight = (WEIGHT)wgt;
2482 a_ptr->cost = (PRICE)cost;
2485 /* Hack -- Process 'P' for "power" and such */
2486 else if (buf[0] == 'P')
2488 int ac, hd1, hd2, th, td, ta;
2490 /* Scan for the values */
2491 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2492 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2494 a_ptr->ac = (ARMOUR_CLASS)ac;
2495 a_ptr->dd = (DICE_NUMBER)hd1;
2496 a_ptr->ds = (DICE_SID)hd2;
2497 a_ptr->to_h = (HIT_PROB)th;
2498 a_ptr->to_d = (HIT_POINT)td;
2499 a_ptr->to_a = (ARMOUR_CLASS)ta;
2502 /* Hack -- Process 'U' for activation index */
2503 else if (buf[0] == 'U')
2506 n = grab_one_activation_flag(buf + 2);
2517 /* Hack -- Process 'F' for flags */
2518 else if (buf[0] == 'F')
2520 /* Parse every entry textually */
2521 for (s = buf + 2; *s; )
2523 /* Find the end of this entry */
2524 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2526 /* Nuke and skip any dividers */
2530 while ((*t == ' ') || (*t == '|')) t++;
2533 /* Parse this entry */
2534 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2536 /* Start the next entry */
2551 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2552 * Grab one flag in a ego-item_type from a textual string
2553 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2554 * @param what 参照元の文字列ポインタ
2555 * @return エラーがあった場合1、エラーがない場合0を返す
2557 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2562 for (i = 0; i < TR_FLAG_MAX; i++)
2564 if (streq(what, k_info_flags[i]))
2566 add_flag(e_ptr->flags, i);
2571 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2574 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2582 * @brief アイテムエゴ情報(e_info)のパース関数 /
2583 * Initialize the "e_info" array, by parsing an ascii "template" file
2585 * @param head ヘッダ構造体
2588 errr parse_e_info(char *buf, header *head)
2594 static ego_item_type *e_ptr = NULL;
2596 /* Just before the first record */
2599 /* Just before the first line */
2602 /* Process 'N' for "New/Number/Name" */
2605 /* Find the colon before the name */
2606 s = my_strchr(buf + 2, ':');
2608 /* Verify that colon */
2611 /* Nuke the colon, advance to the name */
2614 /* Paranoia -- require a name */
2615 if (!*s) return (1);
2620 /* Verify information */
2621 if (i < error_idx) return (4);
2623 /* Verify information */
2624 if (i >= head->info_num) return (2);
2626 /* Save the index */
2629 /* Point at the "info" */
2632 /* Store the name */
2633 if (!add_name(&e_ptr->name, head, s)) return (7);
2637 /* There better be a current e_ptr */
2638 else if (!e_ptr) return (3);
2643 /* 'E' から始まる行は英語名 */
2644 else if (buf[0] == 'E')
2649 else if (buf[0] == 'E')
2651 /* Acquire the Text */
2654 /* Store the name */
2655 if (!add_name(&e_ptr->name, head, s)) return (7);
2660 /* Process 'D' for "Description" */
2661 else if (buf[0] == 'D')
2663 /* Acquire the text */
2666 /* Store the text */
2667 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2672 /* Process 'X' for "Xtra" (one line only) */
2673 else if (buf[0] == 'X')
2677 /* Scan for the values */
2678 if (2 != sscanf(buf + 2, "%d:%d",
2679 &slot, &rating)) return (1);
2681 /* Save the values */
2682 e_ptr->slot = (INVENTORY_IDX)slot;
2683 e_ptr->rating = (PRICE)rating;
2686 /* Process 'W' for "More Info" (one line only) */
2687 else if (buf[0] == 'W')
2689 int level, rarity, pad2;
2692 /* Scan for the values */
2693 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2694 &level, &rarity, &pad2, &cost)) return (1);
2696 /* Save the values */
2697 e_ptr->level = level;
2698 e_ptr->rarity = (RARITY)rarity;
2699 /* e_ptr->weight = wgt; */
2703 /* Hack -- Process 'C' for "creation" */
2704 else if (buf[0] == 'C')
2706 int th, td, ta, pval;
2708 /* Scan for the values */
2709 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2710 &th, &td, &ta, &pval)) return (1);
2712 e_ptr->max_to_h = (HIT_PROB)th;
2713 e_ptr->max_to_d = (HIT_POINT)td;
2714 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2715 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2718 /* Hack -- Process 'U' for activation index */
2719 else if (buf[0] == 'U')
2722 n = grab_one_activation_flag(buf + 2);
2733 /* Hack -- Process 'F' for flags */
2734 else if (buf[0] == 'F')
2736 /* Parse every entry textually */
2737 for (s = buf + 2; *s; )
2739 /* Find the end of this entry */
2740 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2742 /* Nuke and skip any dividers */
2746 while ((*t == ' ') || (*t == '|')) t++;
2749 /* Parse this entry */
2750 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2752 /* Start the next entry */
2765 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2766 * Grab one (basic) flag in a monster_race from a textual string
2767 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2768 * @param what 参照元の文字列ポインタ
2771 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2773 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2776 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2779 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2782 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2785 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2788 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2791 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2794 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2802 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2803 * Grab one (spell) flag in a monster_race from a textual string
2804 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2805 * @param what 参照元の文字列ポインタ
2808 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2810 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2813 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2816 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2819 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2827 * @brief モンスター種族情報(r_info)のパース関数 /
2828 * Initialize the "r_info" array, by parsing an ascii "template" file
2830 * @param head ヘッダ構造体
2833 errr parse_r_info(char *buf, header *head)
2839 static monster_race *r_ptr = NULL;
2842 /* Process 'N' for "New/Number/Name" */
2845 /* Find the colon before the name */
2846 s = my_strchr(buf + 2, ':');
2848 /* Verify that colon */
2851 /* Nuke the colon, advance to the name */
2854 /* Paranoia -- require a name */
2855 if (!*s) return (1);
2860 /* Verify information */
2861 if (i < error_idx) return (4);
2863 /* Verify information */
2864 if (i >= head->info_num) return (2);
2866 /* Save the index */
2869 /* Point at the "info" */
2872 /* Store the name */
2873 if (!add_name(&r_ptr->name, head, s)) return (7);
2877 /* There better be a current r_ptr */
2878 else if (!r_ptr) return (3);
2883 /* 'E' から始まる行は英語名 */
2884 else if (buf[0] == 'E')
2886 /* Acquire the Text */
2889 /* Store the name */
2890 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2893 else if (buf[0] == 'E')
2895 /* Acquire the Text */
2898 /* Store the name */
2899 if (!add_name(&r_ptr->name, head, s)) return (7);
2902 /* Process 'D' for "Description" */
2903 else if (buf[0] == 'D')
2908 /* Acquire the text */
2913 /* Acquire the text */
2917 /* Store the text */
2918 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2921 /* Process 'G' for "Graphics" (one line only) */
2922 else if (buf[0] == 'G')
2926 if (buf[1] != ':') return (1);
2927 if (!buf[2]) return (1);
2928 if (buf[3] != ':') return (1);
2929 if (!buf[4]) return (1);
2931 /* Extract the char */
2934 /* Extract the attr */
2935 tmp = color_char_to_attr(buf[4]);
2936 if (tmp > 127) return (1);
2938 /* Save the values */
2939 r_ptr->d_char = sym;
2940 r_ptr->d_attr = tmp;
2943 /* Process 'I' for "Info" (one line only) */
2944 else if (buf[0] == 'I')
2946 int spd, hp1, hp2, aaf, ac, slp;
2948 /* Scan for the other values */
2949 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2950 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2952 /* Save the values */
2953 r_ptr->speed = (SPEED)spd;
2954 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2955 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2956 r_ptr->aaf = (POSITION)aaf;
2957 r_ptr->ac = (ARMOUR_CLASS)ac;
2958 r_ptr->sleep = (SLEEP_DEGREE)slp;
2961 /* Process 'W' for "More Info" (one line only) */
2962 else if (buf[0] == 'W')
2969 /* Scan for the values */
2970 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2971 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2973 /* Save the values */
2974 r_ptr->level = (DEPTH)lev;
2975 r_ptr->rarity = (RARITY)rar;
2976 r_ptr->extra = (BIT_FLAGS16)pad;
2977 r_ptr->mexp = (EXP)exp;
2978 r_ptr->next_exp = (EXP)nextexp;
2979 r_ptr->next_r_idx = (IDX)nextmon;
2982 /* Process 'R' for "Reinforcement" (up to six lines) */
2983 else if (buf[0] == 'R')
2986 /* Find the next empty blow slot (if any) */
2987 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2989 /* Oops, no more slots */
2990 if (i == 6) return (1);
2992 /* Scan for the values */
2993 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2994 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2995 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2996 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2999 /* Process 'B' for "Blows" (up to four lines) */
3000 else if (buf[0] == 'B')
3004 /* Find the next empty blow slot (if any) */
3005 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3007 /* Oops, no more slots */
3008 if (i == 4) return (1);
3010 /* Analyze the first field */
3011 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3013 /* Terminate the field (if necessary) */
3014 if (*t == ':') *t++ = '\0';
3016 /* Analyze the method */
3017 for (n1 = 0; r_info_blow_method[n1]; n1++)
3019 if (streq(s, r_info_blow_method[n1])) break;
3022 /* Invalid method */
3023 if (!r_info_blow_method[n1]) return (1);
3025 /* Analyze the second field */
3026 for (s = t; *t && (*t != ':'); t++) /* loop */;
3028 /* Terminate the field (if necessary) */
3029 if (*t == ':') *t++ = '\0';
3031 /* Analyze effect */
3032 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3034 if (streq(s, r_info_blow_effect[n2])) break;
3037 /* Invalid effect */
3038 if (!r_info_blow_effect[n2]) return (1);
3040 /* Analyze the third field */
3041 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3043 /* Terminate the field (if necessary) */
3044 if (*t == 'd') *t++ = '\0';
3046 /* Save the method */
3047 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3049 /* Save the effect */
3050 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3052 /* Extract the damage dice and sides */
3053 r_ptr->blow[i].d_dice = atoi(s);
3054 r_ptr->blow[i].d_side = atoi(t);
3057 /* Process 'F' for "Basic Flags" (multiple lines) */
3058 else if (buf[0] == 'F')
3060 /* Parse every entry */
3061 for (s = buf + 2; *s; )
3063 /* Find the end of this entry */
3064 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3066 /* Nuke and skip any dividers */
3070 while (*t == ' ' || *t == '|') t++;
3073 /* Parse this entry */
3074 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3076 /* Start the next entry */
3081 /* Process 'S' for "Spell Flags" (multiple lines) */
3082 else if (buf[0] == 'S')
3084 /* Parse every entry */
3085 for (s = buf + 2; *s; )
3087 /* Find the end of this entry */
3088 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3090 /* Nuke and skip any dividers */
3094 while ((*t == ' ') || (*t == '|')) t++;
3097 /* Hack -- Read spell frequency */
3098 if (1 == sscanf(s, "1_IN_%d", &i))
3100 /* Extract a "frequency" */
3101 r_ptr->freq_spell = 100 / i;
3103 /* Start at next entry */
3108 /* Parse this entry */
3109 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3111 /* Start the next entry */
3116 /* Process 'A' for "Artifact Flags" (multiple lines) */
3117 else if (buf[0] == 'A')
3119 int id, per, rarity;
3121 /* Find the next empty blow slot (if any) */
3122 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3124 /* Oops, no more slots */
3125 if (i == 4) return (1);
3127 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3128 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3129 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3130 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3133 /* Process 'V' for "Arena power value ratio" */
3134 else if (buf[0] == 'V')
3137 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3138 r_ptr->arena_ratio = (PERCENTAGE)val;
3150 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3151 * Grab one flag for a dungeon type from a textual string
3152 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3153 * @param what 参照元の文字列ポインタ
3156 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3158 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3161 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3168 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3169 * Grab one (basic) flag in a monster_race from a textual string
3170 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3171 * @param what 参照元の文字列ポインタ
3174 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3176 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3179 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3182 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3185 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3188 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3191 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3194 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3197 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3204 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3205 * Grab one (spell) flag in a monster_race from a textual string
3206 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3207 * @param what 参照元の文字列ポインタ
3210 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3212 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3215 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3218 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3221 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3228 * @brief ダンジョン情報(d_info)のパース関数 /
3229 * Initialize the "d_info" array, by parsing an ascii "template" file
3231 * @param head ヘッダ構造体
3234 errr parse_d_info(char *buf, header *head)
3240 static dungeon_type *d_ptr = NULL;
3242 /* Process 'N' for "New/Number/Name" */
3245 /* Find the colon before the name */
3246 s = my_strchr(buf + 2, ':');
3248 /* Verify that colon */
3251 /* Nuke the colon, advance to the name */
3254 /* Paranoia -- require a name */
3255 if (!*s) return (1);
3260 /* Verify information */
3261 if (i < error_idx) return (4);
3263 /* Verify information */
3264 if (i >= head->info_num) return (2);
3266 /* Save the index */
3269 /* Point at the "info" */
3272 /* Store the name */
3273 if (!add_name(&d_ptr->name, head, s)) return (7);
3278 else if (buf[0] == 'E') return (0);
3280 else if (buf[0] == 'E')
3282 /* Acquire the Text */
3285 /* Store the name */
3286 if (!add_name(&d_ptr->name, head, s)) return (7);
3290 /* Process 'D' for "Description */
3291 else if (buf[0] == 'D')
3296 /* Acquire the text */
3301 /* Acquire the text */
3305 /* Store the text */
3306 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3309 /* Process 'W' for "More Info" (one line only) */
3310 else if (buf[0] == 'W')
3312 int min_lev, max_lev;
3314 int min_alloc, max_chance;
3315 int obj_good, obj_great;
3318 /* Scan for the values */
3319 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3320 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3322 /* Save the values */
3323 d_ptr->mindepth = (DEPTH)min_lev;
3324 d_ptr->maxdepth = (DEPTH)max_lev;
3325 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3326 d_ptr->mode = (BIT_FLAGS8)mode;
3327 d_ptr->min_m_alloc_level = min_alloc;
3328 d_ptr->max_m_alloc_chance = max_chance;
3329 d_ptr->obj_good = obj_good;
3330 d_ptr->obj_great = obj_great;
3331 d_ptr->pit = (BIT_FLAGS16)pit;
3332 d_ptr->nest = (BIT_FLAGS16)nest;
3335 /* Process 'P' for "Place Info" */
3336 else if (buf[0] == 'P')
3340 /* Scan for the values */
3341 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3343 /* Save the values */
3348 /* Process 'L' for "fLoor type" (one line only) */
3349 else if (buf[0] == 'L')
3353 /* Scan for the values */
3354 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3356 /* Save the values */
3357 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3359 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3360 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3362 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3364 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3367 /* Process 'A' for "wAll type" (one line only) */
3368 else if (buf[0] == 'A')
3372 /* Scan for the values */
3373 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3375 /* Save the values */
3376 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3378 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3379 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3381 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3384 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3385 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3387 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3388 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3390 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3391 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3393 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3394 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3397 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3398 else if (buf[0] == 'F')
3400 int artif = 0, monst = 0;
3402 /* Parse every entry */
3403 for (s = buf + 2; *s; )
3405 /* Find the end of this entry */
3406 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3408 /* Nuke and skip any dividers */
3412 while (*t == ' ' || *t == '|') t++;
3415 /* Hack -- Read Final Artifact */
3416 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3418 /* Extract a "Final Artifact" */
3419 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3421 /* Start at next entry */
3426 /* Hack -- Read Final Object */
3427 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3429 /* Extract a "Final Artifact" */
3430 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3432 /* Start at next entry */
3437 /* Hack -- Read Artifact Guardian */
3438 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3440 /* Extract a "Artifact Guardian" */
3441 d_ptr->final_guardian = (MONRACE_IDX)monst;
3443 /* Start at next entry */
3448 /* Hack -- Read Special Percentage */
3449 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3451 /* Extract a "Special %" */
3452 d_ptr->special_div = (PROB)monst;
3454 /* Start at next entry */
3459 /* Parse this entry */
3460 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3462 /* Start the next entry */
3467 /* Process 'M' for "Basic Flags" (multiple lines) */
3468 else if (buf[0] == 'M')
3470 /* Parse every entry */
3471 for (s = buf + 2; *s; )
3473 /* Find the end of this entry */
3474 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3476 /* Nuke and skip any dividers */
3480 while (*t == ' ' || *t == '|') t++;
3483 /* Hack -- Read monster symbols */
3484 if (!strncmp(s, "R_CHAR_", 7))
3486 /* Skip "R_CHAR_" */
3490 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3492 /* Start at next entry */
3497 /* Parse this entry */
3498 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3500 /* Start the next entry */
3505 /* Process 'S' for "Spell Flags" (multiple lines) */
3506 else if (buf[0] == 'S')
3508 /* Parse every entry */
3509 for (s = buf + 2; *s; )
3511 /* Find the end of this entry */
3512 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3514 /* Nuke and skip any dividers */
3518 while ((*t == ' ') || (*t == '|')) t++;
3521 /* Hack -- Read spell frequency */
3522 if (1 == sscanf(s, "1_IN_%d", &i))
3524 /* Start at next entry */
3529 /* Parse this entry */
3530 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3532 /* Start the next entry */
3544 #else /* ALLOW_TEMPLATES */
3550 #endif /* ALLOW_TEMPLATES */
3554 * @brief 地形情報の「F:」情報をパースする
3555 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3559 static errr parse_line_feature(char *buf)
3564 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3566 /* Tokenize the line */
3567 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3569 /* Letter to assign */
3570 int index = zz[0][0];
3572 /* Reset the info for the letter */
3573 letter[index].feature = feat_none;
3574 letter[index].monster = 0;
3575 letter[index].object = 0;
3576 letter[index].ego = 0;
3577 letter[index].artifact = 0;
3578 letter[index].trap = feat_none;
3579 letter[index].cave_info = 0;
3580 letter[index].special = 0;
3581 letter[index].random = RANDOM_NONE;
3587 letter[index].special = (s16b)atoi(zz[8]);
3591 if ((zz[7][0] == '*') && !zz[7][1])
3593 letter[index].random |= RANDOM_TRAP;
3597 letter[index].trap = f_tag_to_index(zz[7]);
3598 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3603 if (zz[6][0] == '*')
3605 letter[index].random |= RANDOM_ARTIFACT;
3606 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3608 else if (zz[6][0] == '!')
3610 if (p_ptr->inside_quest)
3612 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3617 letter[index].artifact = (IDX)atoi(zz[6]);
3622 if (zz[5][0] == '*')
3624 letter[index].random |= RANDOM_EGO;
3625 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3629 letter[index].ego = (IDX)atoi(zz[5]);
3634 if (zz[4][0] == '*')
3636 letter[index].random |= RANDOM_OBJECT;
3637 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3639 else if (zz[4][0] == '!')
3641 if (p_ptr->inside_quest)
3643 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3646 artifact_type *a_ptr = &a_info[a_idx];
3647 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3649 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3656 letter[index].object = (IDX)atoi(zz[4]);
3661 if (zz[3][0] == '*')
3663 letter[index].random |= RANDOM_MONSTER;
3664 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3666 else if (zz[3][0] == 'c')
3668 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3669 letter[index].monster = -atoi(zz[3] + 1);
3673 letter[index].monster = (IDX)atoi(zz[3]);
3678 letter[index].cave_info = atoi(zz[2]);
3682 if ((zz[1][0] == '*') && !zz[1][1])
3684 letter[index].random |= RANDOM_FEATURE;
3688 letter[index].feature = f_tag_to_index(zz[1]);
3689 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3702 * @brief 地形情報の「B:」情報をパースする
3703 * Process "B:<Index>:<Command>:..." -- Building definition
3707 static errr parse_line_building(char *buf)
3723 /* Get the building number */
3726 /* Find the colon after the building number */
3727 s = my_strchr(s, ':');
3729 /* Verify that colon */
3732 /* Nuke the colon, advance to the sub-index */
3735 /* Paranoia -- require a sub-index */
3736 if (!*s) return (1);
3738 /* Building definition sub-index */
3741 /* Building name, owner, race */
3744 if (tokenize(s + 2, 3, zz, 0) == 3)
3746 /* Name of the building */
3747 strcpy(building[index].name, zz[0]);
3749 /* Name of the owner */
3750 strcpy(building[index].owner_name, zz[1]);
3752 /* Race of the owner */
3753 strcpy(building[index].owner_race, zz[2]);
3758 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3761 /* Building Action */
3764 if (tokenize(s + 2, 8, zz, 0) >= 7)
3766 /* Index of the action */
3767 int action_index = atoi(zz[0]);
3769 /* Name of the action */
3770 strcpy(building[index].act_names[action_index], zz[1]);
3772 /* Cost of the action for members */
3773 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3775 /* Cost of the action for non-members */
3776 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3778 /* Letter assigned to the action */
3779 building[index].letters[action_index] = zz[4][0];
3782 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3784 /* Action restriction */
3785 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3790 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3793 /* Building Classes */
3797 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3798 for (i = 0; i < MAX_CLASS; i++)
3800 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3805 /* Building Races */
3809 n = tokenize(s + 2, MAX_RACES, zz, 0);
3810 for (i = 0; i < MAX_RACES; i++)
3812 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3817 /* Building Realms */
3821 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3822 for (i = 0; i < MAX_MAGIC; i++)
3824 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3831 /* Ignore scripts */
3837 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3846 * @brief フロアの所定のマスにオブジェクトを配置する
3847 * Place the object j_ptr to a grid
3848 * @param j_ptr オブジェクト構造体の参照ポインタ
3853 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3855 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3858 OBJECT_IDX o_idx = o_pop();
3860 /* Access new object */
3861 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3863 /* Structure copy */
3864 object_copy(o_ptr, j_ptr);
3871 o_ptr->held_m_idx = 0;
3874 o_ptr->next_o_idx = g_ptr->o_idx;
3876 g_ptr->o_idx = o_idx;
3880 * @brief クエスト用固定ダンジョンをフロアに生成する
3881 * Parse a sub-file of the "extra info"
3891 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3896 /* Skip "empty" lines */
3897 if (!buf[0]) return (0);
3899 /* Skip "blank" lines */
3900 if (iswspace(buf[0])) return (0);
3903 if (buf[0] == '#') return (0);
3905 /* Require "?:*" format */
3906 if (buf[1] != ':') return (1);
3909 /* Process "%:<fname>" */
3912 /* Attempt to Process the given file */
3913 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3916 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3919 return parse_line_feature(buf);
3922 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3923 else if (buf[0] == 'D')
3925 object_type object_type_body;
3927 /* Acquire the text */
3930 /* Length of the text */
3931 int len = strlen(s);
3933 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3935 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3937 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3941 OBJECT_IDX object_index = letter[idx].object;
3942 MONSTER_IDX monster_index = letter[idx].monster;
3943 int random = letter[idx].random;
3944 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3946 /* Lay down a floor */
3947 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3949 /* Only the features */
3950 if (init_flags & INIT_ONLY_FEATURES) continue;
3953 g_ptr->info = letter[idx].cave_info;
3955 /* Create a monster */
3956 if (random & RANDOM_MONSTER)
3958 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3960 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3962 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3964 else if (monster_index)
3966 int old_cur_num, old_max_num;
3969 if (monster_index < 0)
3971 monster_index = -monster_index;
3974 old_cur_num = r_info[monster_index].cur_num;
3975 old_max_num = r_info[monster_index].max_num;
3977 /* Make alive again */
3978 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3980 r_info[monster_index].cur_num = 0;
3981 r_info[monster_index].max_num = 1;
3984 /* Make alive again */
3985 /* Hack -- Non-unique Nazguls are semi-unique */
3986 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3988 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3990 r_info[monster_index].max_num++;
3995 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3999 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
4001 /* Make alive again for real unique monster */
4002 r_info[monster_index].cur_num = old_cur_num;
4003 r_info[monster_index].max_num = old_max_num;
4007 /* Object (and possible trap) */
4008 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4010 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4013 * Random trap and random treasure defined
4014 * 25% chance for trap and 75% chance for object
4016 if (randint0(100) < 75)
4018 place_object(*y, *x, 0L);
4025 current_floor_ptr->object_level = current_floor_ptr->base_level;
4027 else if (random & RANDOM_OBJECT)
4029 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4031 /* Create an out of deep object */
4032 if (randint0(100) < 75)
4033 place_object(*y, *x, 0L);
4034 else if (randint0(100) < 80)
4035 place_object(*y, *x, AM_GOOD);
4037 place_object(*y, *x, AM_GOOD | AM_GREAT);
4039 current_floor_ptr->object_level = current_floor_ptr->base_level;
4042 else if (random & RANDOM_TRAP)
4046 /* Hidden trap (or door) */
4047 else if (letter[idx].trap)
4049 g_ptr->mimic = g_ptr->feat;
4050 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4052 else if (object_index)
4054 object_type *o_ptr = &object_type_body;
4055 object_prep(o_ptr, object_index);
4057 if (o_ptr->tval == TV_GOLD)
4059 coin_type = object_index - OBJ_GOLD_LIST;
4064 /* Apply magic (no messages, no artifacts) */
4065 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4067 drop_here(o_ptr, *y, *x);
4073 if (a_info[artifact_index].cur_num)
4075 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4077 object_type *q_ptr = &forge;
4079 object_prep(q_ptr, k_idx);
4080 drop_here(q_ptr, *y, *x);
4084 if (create_named_art(artifact_index, *y, *x))
4085 a_info[artifact_index].cur_num = 1;
4089 /* Terrain special */
4090 g_ptr->special = letter[idx].special;
4098 /* Process "Q:<number>:<command>:... -- quest info */
4099 else if (buf[0] == 'Q')
4106 num = tokenize(buf + 2, 33, zz, 0);
4110 num = tokenize(buf + 3, 33, zz, 0);
4113 /* Have we enough parameters? */
4114 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4117 q_ptr = &(quest[atoi(zz[0])]);
4119 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4120 if (zz[1][0] == 'Q')
4122 if (init_flags & INIT_ASSIGN)
4124 monster_race *r_ptr;
4125 artifact_type *a_ptr;
4127 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4129 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4130 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4131 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4132 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4133 q_ptr->level = (DEPTH)atoi(zz[6]);
4134 q_ptr->r_idx = (IDX)atoi(zz[7]);
4135 q_ptr->k_idx = (IDX)atoi(zz[8]);
4136 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4138 if (num > 10) q_ptr->flags = atoi(zz[10]);
4140 r_ptr = &r_info[q_ptr->r_idx];
4141 if (r_ptr->flags1 & RF1_UNIQUE)
4142 r_ptr->flags1 |= RF1_QUESTOR;
4144 a_ptr = &a_info[q_ptr->k_idx];
4145 a_ptr->gen_flags |= TRG_QUESTITEM;
4150 else if (zz[1][0] == 'R')
4152 if (init_flags & INIT_ASSIGN)
4155 IDX idx, reward_idx = 0;
4157 for (idx = 2; idx < num; idx++)
4159 IDX a_idx = (IDX)atoi(zz[idx]);
4160 if (a_idx < 1) continue;
4161 if (a_info[a_idx].cur_num > 0) continue;
4163 if (one_in_(count)) reward_idx = a_idx;
4168 /* Set quest's rewarding artifact */
4169 q_ptr->k_idx = reward_idx;
4170 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4174 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4175 q_ptr->type = QUEST_TYPE_KILL_ALL;
4182 /* Process "Q:<q_index>:N:<name>" -- quest name */
4183 else if (zz[1][0] == 'N')
4185 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4187 strcpy(q_ptr->name, zz[2]);
4193 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4194 else if (zz[1][0] == 'T')
4196 if (init_flags & INIT_SHOW_TEXT)
4198 strcpy(quest_text[quest_text_line], zz[2]);
4206 /* Process "W:<command>: ..." -- info for the wilderness */
4207 else if (buf[0] == 'W')
4209 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4212 /* Process "P:<y>:<x>" -- player position */
4213 else if (buf[0] == 'P')
4215 if (init_flags & INIT_CREATE_DUNGEON)
4217 if (tokenize(buf + 2, 2, zz, 0) == 2)
4219 int panels_x, panels_y;
4221 /* Hack - Set the dungeon size */
4222 panels_y = (*y / SCREEN_HGT);
4223 if (*y % SCREEN_HGT) panels_y++;
4224 current_floor_ptr->height = panels_y * SCREEN_HGT;
4226 panels_x = (*x / SCREEN_WID);
4227 if (*x % SCREEN_WID) panels_x++;
4228 current_floor_ptr->width = panels_x * SCREEN_WID;
4230 /* Assume illegal panel */
4231 panel_row_min = current_floor_ptr->height;
4232 panel_col_min = current_floor_ptr->width;
4234 /* Place player in a quest level */
4235 if (p_ptr->inside_quest)
4239 /* Delete the monster (if any) */
4240 delete_monster(p_ptr->y, p_ptr->x);
4248 /* Place player in the town */
4249 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4251 p_ptr->oldpy = atoi(zz[0]);
4252 p_ptr->oldpx = atoi(zz[1]);
4260 /* Process "B:<Index>:<Command>:..." -- Building definition */
4261 else if (buf[0] == 'B')
4263 return parse_line_building(buf);
4266 /* Process "M:<type>:<maximum>" -- set maximum values */
4267 else if (buf[0] == 'M')
4269 if (tokenize(buf + 2, 2, zz, 0) == 2)
4272 if (zz[0][0] == 'T')
4274 max_towns = (TOWN_IDX)atoi(zz[1]);
4277 /* Maximum quests */
4278 else if (zz[0][0] == 'Q')
4280 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4284 else if (zz[0][0] == 'R')
4286 max_r_idx = (IDX)atoi(zz[1]);
4290 else if (zz[0][0] == 'K')
4292 max_k_idx = (IDX)atoi(zz[1]);
4296 else if (zz[0][0] == 'V')
4298 max_v_idx = (IDX)atoi(zz[1]);
4302 else if (zz[0][0] == 'F')
4304 max_f_idx = (IDX)atoi(zz[1]);
4308 else if (zz[0][0] == 'A')
4310 max_a_idx = (IDX)atoi(zz[1]);
4314 else if (zz[0][0] == 'E')
4316 max_e_idx = (IDX)atoi(zz[1]);
4320 else if (zz[0][0] == 'D')
4322 max_d_idx = (IDX)atoi(zz[1]);
4326 else if (zz[0][0] == 'O')
4328 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4332 else if (zz[0][0] == 'M')
4334 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4337 /* Wilderness size */
4338 else if (zz[0][0] == 'W')
4340 /* Maximum wild_x_size */
4341 if (zz[0][1] == 'X')
4342 current_world_ptr->max_wild_x = atoi(zz[1]);
4343 /* Maximum wild_y_size */
4344 if (zz[0][1] == 'Y')
4345 current_world_ptr->max_wild_y = atoi(zz[1]);
4359 static concptr variant = "ZANGBAND";
4363 * @brief クエスト用固定ダンジョン生成時の分岐処理
4364 * Helper function for "process_dungeon_file()"
4369 static concptr process_dungeon_file_expr(char **sp, char *fp)
4385 while (iswspace(*s)) s++;
4403 t = process_dungeon_file_expr(&s, &f);
4411 else if (streq(t, "IOR"))
4414 while (*s && (f != b2))
4416 t = process_dungeon_file_expr(&s, &f);
4417 if (*t && !streq(t, "0")) v = "1";
4422 else if (streq(t, "AND"))
4425 while (*s && (f != b2))
4427 t = process_dungeon_file_expr(&s, &f);
4428 if (*t && streq(t, "0")) v = "0";
4433 else if (streq(t, "NOT"))
4436 while (*s && (f != b2))
4438 t = process_dungeon_file_expr(&s, &f);
4439 if (*t && streq(t, "1")) v = "0";
4444 else if (streq(t, "EQU"))
4447 if (*s && (f != b2))
4449 t = process_dungeon_file_expr(&s, &f);
4451 while (*s && (f != b2))
4453 p = process_dungeon_file_expr(&s, &f);
4454 if (streq(t, p)) v = "1";
4459 else if (streq(t, "LEQ"))
4462 if (*s && (f != b2))
4464 t = process_dungeon_file_expr(&s, &f);
4466 while (*s && (f != b2))
4469 t = process_dungeon_file_expr(&s, &f);
4470 if (*t && atoi(p) > atoi(t)) v = "0";
4475 else if (streq(t, "GEQ"))
4478 if (*s && (f != b2))
4480 t = process_dungeon_file_expr(&s, &f);
4482 while (*s && (f != b2))
4485 t = process_dungeon_file_expr(&s, &f);
4487 /* Compare two numbers instead of string */
4488 if (*t && atoi(p) < atoi(t)) v = "0";
4494 while (*s && (f != b2))
4496 t = process_dungeon_file_expr(&s, &f);
4501 if (f != b2) v = "?x?x?";
4503 /* Extract final and Terminate */
4504 if ((f = *s) != '\0') *s++ = '\0';
4510 /* Accept all printables except spaces and brackets */
4512 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4514 if (iskanji(*s)) s++;
4518 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4521 /* Extract final and Terminate */
4522 if ((f = *s) != '\0') *s++ = '\0';
4528 if (streq(b + 1, "SYS"))
4534 else if (streq(b + 1, "GRAF"))
4539 else if (streq(b + 1, "MONOCHROME"))
4548 else if (streq(b + 1, "RACE"))
4550 v = _(rp_ptr->E_title, rp_ptr->title);
4554 else if (streq(b + 1, "CLASS"))
4556 v = _(cp_ptr->E_title, cp_ptr->title);
4560 else if (streq(b + 1, "REALM1"))
4562 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4566 else if (streq(b + 1, "REALM2"))
4568 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4572 else if (streq(b + 1, "PLAYER"))
4574 static char tmp_player_name[32];
4576 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4586 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4589 v = tmp_player_name;
4593 else if (streq(b + 1, "TOWN"))
4595 sprintf(tmp, "%d", p_ptr->town_num);
4600 else if (streq(b + 1, "LEVEL"))
4602 sprintf(tmp, "%d", p_ptr->lev);
4606 /* Current quest number */
4607 else if (streq(b + 1, "QUEST_NUMBER"))
4609 sprintf(tmp, "%d", p_ptr->inside_quest);
4613 /* Number of last quest */
4614 else if (streq(b + 1, "LEAVING_QUEST"))
4616 sprintf(tmp, "%d", leaving_quest);
4621 else if (prefix(b + 1, "QUEST_TYPE"))
4623 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4624 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4629 else if (prefix(b + 1, "QUEST"))
4631 /* "QUEST" uses a special parameter to determine the number of the quest */
4632 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4637 else if (prefix(b + 1, "RANDOM"))
4639 /* "RANDOM" uses a special parameter to determine the number of the quest */
4640 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
4645 else if (streq(b + 1, "VARIANT"))
4651 else if (streq(b + 1, "WILDERNESS"))
4654 sprintf(tmp, "NONE");
4656 sprintf(tmp, "LITE");
4658 sprintf(tmp, "NORMAL");
4677 void write_r_info_txt(void)
4679 int i, j, z, fc, bc;
4682 concptr flags[32 * 10];
4687 monster_race *r_ptr;
4689 monster_blow *b_ptr;
4691 FILE *fff = fopen("output.txt", "wt");
4695 BIT_FLAGS mode = -1;
4699 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4701 fprintf(fff, "# Version stamp (required)\n\n");
4704 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4707 fprintf(fff, "##### The Player #####\n\n");
4709 for (z = -1; z < alloc_race_size; z++)
4711 /* Output the monsters in order */
4712 i = (z >= 0) ? alloc_race_table[z].index : 0;
4714 /* Acquire the monster */
4717 /* Ignore empty monsters */
4718 if (!strlen(r_name + r_ptr->name)) continue;
4720 /* Ignore useless monsters */
4721 if (i && !r_ptr->speed) continue;
4723 /* Write a note if necessary */
4724 if (i && (!r_ptr->level != !mode))
4729 fprintf(fff, "\n##### Town monsters #####\n\n");
4731 /* Note the dungeon */
4734 fprintf(fff, "\n##### Normal monsters #####\n\n");
4737 /* Record the change */
4738 mode = r_ptr->level;
4741 /* Acquire the flags */
4742 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4743 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4744 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4745 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4746 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4747 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4748 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4749 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4750 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4751 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4753 /* Write New/Number/Name */
4754 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4757 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4759 /* Write Information */
4760 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4761 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4763 /* Write more information */
4764 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4767 for (j = 0; j < 4; j++)
4769 b_ptr = &(r_ptr->blow[j]);
4771 /* Stop when done */
4772 if (!b_ptr->method) break;
4774 /* Write the blows */
4775 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4776 r_info_blow_effect[b_ptr->effect],
4777 b_ptr->d_dice, b_ptr->d_side);
4779 for (fc = 0, j = 0; j < 32 * 3; j++)
4781 /* Check this flag */
4782 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4785 /* Extract the extra flags */
4786 for (j = 32 * 6; j < 32 * 10; j++)
4788 /* Check this flag */
4789 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4792 /* Write the flags */
4793 for (j = 0; j < fc;)
4797 /* Start the line */
4800 for (bc = 0; (bc < 60) && (j < fc); j++)
4804 /* Format the flag */
4805 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4807 /* Add it to the buffer */
4810 /* Note the length */
4814 /* Done with this line; write it */
4815 fprintf(fff, "%s\n", buf);
4818 /* Write Spells if applicable */
4819 if (r_ptr->freq_spell)
4821 /* Write the frequency */
4822 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4824 /* Extract the spell flags */
4825 for (fc = 0, j = 96; j < 192; j++)
4827 /* Check this flag */
4828 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4831 /* Write the flags */
4832 for (j = 0; j < fc;)
4836 /* Start the line */
4839 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4843 /* Format the flag */
4844 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4848 /* Note the length */
4855 /* Done with this line; write it */
4856 fprintf(fff, "%s\n", buf);
4860 /* Acquire the description */
4861 desc = r_text + r_ptr->text;
4862 dlen = strlen(desc);
4864 /* Write Description */
4865 for (j = 0; j < dlen;)
4869 /* Start the line */
4872 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4880 /* Done with this line; write it */
4881 fprintf(fff, "%s\n", buf);
4884 /* Space between entries */
4895 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4896 * Helper function for "process_dungeon_file()"
4904 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4910 bool bypass = FALSE;
4911 int x = xmin, y = ymin;
4914 /* Build the filename */
4915 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4918 fp = my_fopen(buf, "r");
4921 if (!fp) return (-1);
4924 /* Process the file */
4925 while (0 == my_fgets(fp, buf, sizeof(buf)))
4931 /* Skip "empty" lines */
4932 if (!buf[0]) continue;
4934 /* Skip "blank" lines */
4935 if (iswspace(buf[0])) continue;
4938 if (buf[0] == '#') continue;
4941 /* Process "?:<expr>" */
4942 if ((buf[0] == '?') && (buf[1] == ':'))
4951 /* Parse the expr */
4952 v = process_dungeon_file_expr(&s, &f);
4955 bypass = (streq(v, "0") ? TRUE : FALSE);
4959 /* Apply conditionals */
4960 if (bypass) continue;
4962 /* Process the line */
4963 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4974 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4976 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4977 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);