5 #include "dungeon-file.h"
11 #include "player-skill.h"
16 #include "rooms-vault.h"
17 #include "objectkind.h"
19 dungeon_grid letter[255];
23 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
27 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
28 * This software may be copied and distributed for educational, research,
29 * and not for profit purposes provided that this copyright and statement
30 * are included in all such copies. Other copyrights may also apply.
31 * 2014 Deskull rearranged comment for Doxygen.\n
35 * This file is used to initialize various variables and arrays for the
36 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
37 * the common limitation of "read()" and "write()" to only 32767 bytes
39 * Several of the arrays for Angband are built from "template" files in
40 * the "lib/file" directory, from which quick-load binary "image" files
41 * are constructed whenever they are not present in the "lib/data"
42 * directory, or if those files become obsolete, if we are allowed.
43 * Warning -- the "ascii" file parsers use a minor hack to collect the
44 * name and text information in a single pass. Thus, the game will not
45 * be able to load any template file with more than 20K of names or 60K
46 * of text, even though technically, up to 64K should be legal.
48 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
49 * in this file is compiled out, and the game will not run unless valid
50 * "binary template files" already exist in "lib/data". Thus, one can
51 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
52 * "*.raw" files in "lib/data", and then quit, and recompile without
53 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
54 * from changing the ascii template files in potentially dangerous ways.
55 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
56 * このファイルのコードの多くはコンパイル出力され、本ゲームは
57 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
58 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
59 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
60 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
61 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
62 * テンプレートファイルを変更することを妨げることができる。
63 * The code could actually be removed and placed into a "stand-alone"
64 * program, but that feels a little silly, especially considering some
65 * of the platforms that we currently support.
70 #include "dungeon-file.h"
75 #include "cmd-activate.h"
79 #include "view-mainwindow.h"
80 #include "player-class.h"
84 #ifdef ALLOW_TEMPLATES
89 /*** Helper arrays for parsing ascii template files ***/
93 * Monster Blow Methods
95 static concptr r_info_blow_method[] =
128 * モンスターの打撃属性トークンの定義 /
129 * Monster Blow Effects
131 static concptr r_info_blow_effect[] =
176 static concptr f_info_flags[] =
301 static concptr r_info_flags1[] =
341 static concptr r_info_flags2[] =
381 static concptr r_info_flags3[] =
421 static concptr r_info_flags4[] =
458 * モンスター特性トークン(発動型能力1) /
461 static concptr r_a_ability_flags1[] =
498 * モンスター特性トークン(発動型能力2) /
501 static concptr r_a_ability_flags2[] =
518 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
539 * モンスター特性トークン(発動型能力3) /
542 static concptr r_a_ability_flags3[] =
581 * モンスター特性トークン(発動型能力4) /
584 static concptr r_a_ability_flags4[] =
626 static concptr r_info_flags7[] =
666 static concptr r_info_flags8[] =
698 "WILD_SWAMP", /* ToDo: Implement Swamp */
707 static concptr r_info_flags9[] =
746 * モンスター特性トークンの定義R(耐性) /
749 static concptr r_info_flagsr[] =
787 * オブジェクト基本特性トークンの定義 /
790 static concptr k_info_flags[] =
887 "XXX3", /* Fake flag for Smith */
888 "XXX4", /* Fake flag for Smith */
938 * オブジェクト生成特性トークンの定義 /
941 static concptr k_info_gen_flags[] =
981 static concptr d_info_flags1[] =
1019 * @brief データの可変文字列情報をテキストとして保管する /
1020 * Add a text to the text-storage and store offset to it.
1021 * @param offset 文字列保管ポインタからのオフセット
1022 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1024 * @param normal_text テキストの正規化を行う
1027 * Returns FALSE when there isn't enough space available to store
1030 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1032 /* Hack -- Verify space */
1033 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1039 /* Advance and save the text index */
1040 *offset = ++head->text_size;
1043 /* Additional text */
1044 else if (normal_text)
1047 * If neither the end of the last line nor
1048 * the beginning of current line is not a space,
1049 * fill up a space as a correct separator of two words.
1051 if (head->text_size > 0 &&
1053 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1054 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1055 (buf[0] != ' ') && !iskanji(buf[0])
1057 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1062 /* Append a space */
1063 *(head->text_ptr + head->text_size) = ' ';
1065 /* Advance the index */
1070 /* Append chars to the text */
1071 strcpy(head->text_ptr + head->text_size, buf);
1073 /* Advance the index */
1074 head->text_size += strlen(buf);
1082 * @brief データの可変文字列情報を名前として保管する /
1083 * Add a name to the name-storage and return an offset to it.
1084 * @param offset 文字列保管ポインタからのオフセット
1085 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1089 * Returns FALSE when there isn't enough space available to store
1092 static bool add_name(u32b *offset, header *head, concptr buf)
1094 /* Hack -- Verify space */
1095 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1101 /* Advance and save the name index */
1102 *offset = ++head->name_size;
1105 /* Append chars to the names */
1106 strcpy(head->name_ptr + head->name_size, buf);
1108 /* Advance the index */
1109 head->name_size += strlen(buf);
1117 * @brief データの可変文字列情報をタグとして保管する /
1118 * Add a tag to the tag-storage and return an offset to it.
1119 * @param offset 文字列保管ポインタからのオフセット
1120 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1124 * Returns FALSE when there isn't enough space available to store
1127 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1131 /* Search for an existing (fake) tag */
1132 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1135 if (streq(&head->tag_ptr[i], buf)) break;
1138 /* There was no existing tag */
1139 if (i >= head->tag_size)
1141 /* Hack -- Verify space */
1142 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1145 /* Append chars to the tags */
1146 strcpy(head->tag_ptr + head->tag_size, buf);
1148 /* Point the new tag */
1151 /* Advance the index */
1152 head->tag_size += strlen(buf) + 1;
1155 /* Return offset of the tag */
1163 /*** Initialize from ascii template files ***/
1167 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1168 * Initialize an "*_info" array, by parsing an ascii "template" file
1169 * @param fp 読み取りに使うファイルポインタ
1170 * @param buf 読み取りに使うバッファ領域
1171 * @param head ヘッダ構造体
1172 * @param parse_info_txt_line パース関数
1175 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1179 /* Just before the first record */
1182 /* Just before the first line */
1186 /* Prepare the "fake" stuff */
1187 head->name_size = 0;
1188 head->text_size = 0;
1192 while (0 == my_fgets(fp, buf, 1024))
1194 /* Advance the line number */
1197 /* Skip comments and blank lines */
1198 if (!buf[0] || (buf[0] == '#')) continue;
1200 /* Verify correct "colon" format */
1201 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1204 /* Hack -- Process 'V' for "Version" */
1211 /* Mega Hack -- Calculate Check Sum */
1212 if (buf[0] != 'N' && buf[0] != 'D')
1215 for (i = 0; buf[i]; i++)
1217 head->v_extra += (byte)buf[i];
1218 head->v_extra ^= (1 << (i % 8));
1222 /* Parse the line */
1223 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1228 /* Complete the "name" and "text" sizes */
1229 if (head->name_size) head->name_size++;
1230 if (head->text_size) head->text_size++;
1238 * @brief Vault情報(v_info)のパース関数 /
1239 * Initialize the "v_info" array, by parsing an ascii "template" file
1241 * @param head ヘッダ構造体
1244 errr parse_v_info(char *buf, header *head)
1250 static vault_type *v_ptr = NULL;
1252 /* Process 'N' for "New/Number/Name" */
1255 /* Find the colon before the name */
1256 s = my_strchr(buf + 2, ':');
1258 /* Verify that colon */
1261 /* Nuke the colon, advance to the name */
1264 /* Paranoia -- require a name */
1265 if (!*s) return (1);
1270 /* Verify information */
1271 if (i <= error_idx) return (4);
1273 /* Verify information */
1274 if (i >= head->info_num) return (2);
1276 /* Save the index */
1279 /* Point at the "info" */
1282 /* Store the name */
1283 if (!add_name(&v_ptr->name, head, s)) return (7);
1286 /* There better be a current v_ptr */
1287 else if (!v_ptr) return (3);
1289 /* Process 'D' for "Description" */
1290 else if (buf[0] == 'D')
1292 /* Acquire the text */
1295 /* Store the text */
1296 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1299 /* Process 'X' for "Extra info" (one line only) */
1300 else if (buf[0] == 'X')
1302 EFFECT_ID typ, rat, hgt, wid;
1304 /* Scan for the values */
1305 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1306 &typ, &rat, &hgt, &wid)) return (1);
1308 /* Save the values */
1309 v_ptr->typ = (ROOM_IDX)typ;
1310 v_ptr->rat = (PROB)rat;
1311 v_ptr->hgt = (POSITION)hgt;
1312 v_ptr->wid = (POSITION)wid;
1323 * @brief 職業技能情報(s_info)のパース関数 /
1324 * Initialize the "s_info" array, by parsing an ascii "template" file
1326 * @param head ヘッダ構造体
1329 errr parse_s_info(char *buf, header *head)
1334 static skill_table *s_ptr = NULL;
1337 /* Process 'N' for "New/Number/Name" */
1343 /* Verify information */
1344 if (i <= error_idx) return (4);
1346 /* Verify information */
1347 if (i >= head->info_num) return (2);
1349 /* Save the index */
1352 /* Point at the "info" */
1356 /* There better be a current s_ptr */
1357 else if (!s_ptr) return (3);
1359 /* Process 'W' for "Weapon exp" */
1360 else if (buf[0] == 'W')
1362 int tval, sval, start, max;
1363 const s16b exp_conv_table[] =
1365 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1366 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1369 /* Scan for the values */
1370 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1371 &tval, &sval, &start, &max)) return (1);
1373 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1374 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1376 /* Save the values */
1377 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1378 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1381 /* Process 'S' for "Skill exp" */
1382 else if (buf[0] == 'S')
1384 int num, start, max;
1386 /* Scan for the values */
1387 if (3 != sscanf(buf + 2, "%d:%d:%d",
1388 &num, &start, &max)) return (1);
1390 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1391 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1393 /* Save the values */
1394 s_ptr->s_start[num] = (SUB_EXP)start;
1395 s_ptr->s_max[num] = (SUB_EXP)max;
1407 * @brief 職業魔法情報(m_info)のパース関数 /
1408 * Initialize the "m_info" array, by parsing an ascii "template" file
1410 * @param head ヘッダ構造体
1413 errr parse_m_info(char *buf, header *head)
1420 static player_magic *m_ptr = NULL;
1423 static int realm, magic_idx = 0, readable = 0;
1426 /* Process 'N' for "New/Number/Name" */
1432 /* Verify information */
1433 if (i <= error_idx) return (4);
1435 /* Verify information */
1436 if (i >= head->info_num) return (2);
1438 /* Save the index */
1441 /* Point at the "info" */
1445 /* There better be a current m_ptr */
1446 else if (!m_ptr) return (3);
1448 /* Process 'I' for "Info" (one line only) */
1449 else if (buf[0] == 'I')
1452 int xtra, type, first, weight;
1454 /* Find the colon before the name */
1455 s = my_strchr(buf + 2, ':');
1457 /* Verify that colon */
1460 /* Nuke the colon, advance to the name */
1465 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1466 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1467 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1468 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1469 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1474 /* Find the colon before the name */
1475 s = my_strchr(s, ':');
1477 /* Verify that colon */
1480 /* Nuke the colon, advance to the name */
1483 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1484 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1485 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1486 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1487 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1488 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1492 /* Scan for the values */
1493 if (4 != sscanf(s, "%x:%d:%d:%d",
1494 (uint *)&xtra, &type, &first, &weight)) return (1);
1496 m_ptr->spell_xtra = xtra;
1497 m_ptr->spell_type = type;
1498 m_ptr->spell_first = first;
1499 m_ptr->spell_weight = weight;
1503 /* Process 'R' for "Realm" (one line only) */
1504 else if (buf[0] == 'R')
1506 /* Scan for the values */
1507 if (2 != sscanf(buf + 2, "%d:%d",
1508 &realm, &readable)) return (1);
1513 else if (buf[0] == 'T')
1515 int level, mana, fail, exp;
1517 if (!readable) return (1);
1518 /* Scan for the values */
1519 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1520 &level, &mana, &fail, &exp)) return (1);
1522 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1523 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1524 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1525 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1538 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1539 * Grab one flag from a textual string
1540 * @param flags ビットフラグを追加する先の参照ポインタ
1541 * @param names トークン定義配列
1542 * @param what 参照元の文字列ポインタ
1545 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1550 for (i = 0; i < 32; i++)
1552 if (streq(what, names[i]))
1554 *flags |= (1L << i);
1564 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1565 * Grab one flag in an feature_type from a textual string
1566 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1567 * @param what 参照元の文字列ポインタ
1570 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1575 for (i = 0; i < FF_FLAG_MAX; i++)
1577 if (streq(what, f_info_flags[i]))
1579 add_flag(f_ptr->flags, i);
1584 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1587 return PARSE_ERROR_GENERIC;
1592 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1593 * Grab an action in an feature_type from a textual string
1594 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1595 * @param what 参照元の文字列ポインタ
1596 * @param count ステートの保存先ID
1599 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1604 for (i = 0; i < FF_FLAG_MAX; i++)
1606 if (streq(what, f_info_flags[i]))
1608 f_ptr->state[count].action = i;
1613 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1616 return PARSE_ERROR_GENERIC;
1621 * @brief 地形情報(f_info)のパース関数 /
1622 * Initialize the "f_info" array, by parsing an ascii "template" file
1624 * @param head ヘッダ構造体
1627 errr parse_f_info(char *buf, header *head)
1634 static feature_type *f_ptr = NULL;
1637 /* Process 'N' for "New/Number/Name" */
1640 /* Find the colon before the name */
1641 s = my_strchr(buf + 2, ':');
1645 /* Nuke the colon, advance to the name */
1652 /* Verify information */
1653 if (i <= error_idx) return (4);
1655 /* Verify information */
1656 if (i >= head->info_num) return (2);
1658 /* Save the index */
1661 /* Point at the "info" */
1664 /* Tag name is given */
1668 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1671 /* Default "mimic" */
1672 f_ptr->mimic = (FEAT_IDX)i;
1674 /* Default "destroyed state" -- if not specified */
1675 f_ptr->destroyed = (FEAT_IDX)i;
1677 /* Default "states" */
1678 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1681 /* There better be a current f_ptr */
1682 else if (!f_ptr) return (3);
1685 else if (buf[0] == 'J')
1687 /* Store the name */
1688 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1691 else if (buf[0] == 'E')
1693 /* Ignore english name */
1696 else if (buf[0] == 'J')
1698 /* Ignore Japanese name */
1701 else if (buf[0] == 'E')
1703 /* Acquire the Text */
1706 /* Store the name */
1707 if (!add_name(&f_ptr->name, head, s)) return (7);
1712 /* Process 'M' for "Mimic" (one line only) */
1713 else if (buf[0] == 'M')
1717 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1719 /* Record a fake tag index */
1720 f_ptr->mimic_tag = offset;
1724 /* Process 'G' for "Graphics" (one line only) */
1725 else if (buf[0] == 'G')
1729 char char_tmp[F_LIT_MAX];
1730 if (buf[1] != ':') return (1);
1731 if (!buf[2]) return (1);
1732 if (buf[3] != ':') return (1);
1733 if (!buf[4]) return (1);
1735 /* Extract the char */
1736 char_tmp[F_LIT_STANDARD] = buf[2];
1738 /* Extract the color */
1739 s_attr = color_char_to_attr(buf[4]);
1740 if (s_attr > 127) return (1);
1742 /* Save the standard values */
1743 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1744 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1746 /* Is this feature supports lighting? */
1749 /* G:c:a:LIT (default) */
1750 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1752 /* G:c:a:lc:la:dc:da */
1753 if (!streq(buf + 6, "LIT"))
1755 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1757 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1758 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1759 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1760 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1762 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1764 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1767 /* Use default lighting */
1770 /* No lighting support */
1771 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1774 /* Extract the color */
1775 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1776 if (f_ptr->d_attr[j] > 127) return 1;
1779 f_ptr->d_char[j] = char_tmp[j];
1785 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1787 f_ptr->d_attr[j] = s_attr;
1788 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1794 /* Hack -- Process 'F' for flags */
1795 else if (buf[0] == 'F')
1797 /* Parse every entry textually */
1798 for (s = buf + 2; *s; )
1800 /* Find the end of this entry */
1801 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1803 /* Nuke and skip any dividers */
1807 while (*t == ' ' || *t == '|') t++;
1810 /* Hack -- Read feature subtype */
1811 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1813 /* Extract a "subtype" */
1814 f_ptr->subtype = (FEAT_SUBTYPE)i;
1816 /* Start at next entry */
1822 /* Hack -- Read feature power */
1823 if (1 == sscanf(s, "POWER_%d", &i))
1825 /* Extract a "power" */
1826 f_ptr->power = (FEAT_POWER)i;
1828 /* Start at next entry */
1833 /* Parse this entry */
1834 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1836 /* Start the next entry */
1841 /* Process 'W' for "More Info" (one line only) */
1842 else if (buf[0] == 'W')
1846 /* Scan for the value */
1847 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1849 /* Save the value */
1850 f_ptr->priority = (FEAT_PRIORITY)priority;
1853 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1854 else if (buf[0] == 'K')
1858 /* Find the next empty state slot (if any) */
1859 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1861 /* Oops, no more slots */
1862 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1864 /* Analyze the first field */
1865 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1867 /* Terminate the field (if necessary) */
1868 if (*t == ':') *t++ = '\0';
1870 /* Is this default entry? */
1871 if (streq(s, "DESTROYED"))
1873 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1875 /* Record a fake tag index */
1876 f_ptr->destroyed_tag = offset;
1881 f_ptr->state[i].action = 0;
1883 /* Parse this entry */
1884 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1886 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1888 /* Record a fake tag index */
1889 f_ptr->state[i].result_tag = offset;
1901 * @brief 地形タグからIDを得る /
1902 * Convert a fake tag to a real feat index
1906 s16b f_tag_to_index(concptr str)
1910 /* Search for real index corresponding to this fake tag */
1911 for (i = 0; i < f_head.info_num; i++)
1913 if (streq(f_tag + f_info[i].tag, str))
1915 /* Return the index */
1926 * @brief 地形タグからIDを得る /
1927 * Search for real index corresponding to this fake tag
1928 * @param feat タグ文字列のオフセット
1929 * @return 地形ID。該当がないなら-1
1931 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1935 /* Don't convert non-fake tag */
1941 /* Search for real index corresponding to this fake tag */
1942 for (i = 0; i < f_head.info_num; i++)
1944 if (feat == f_info[i].tag)
1946 /* Record real index */
1952 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1958 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1959 * Retouch fake tags of f_info
1960 * @param head ヘッダ構造体
1963 void retouch_f_info(header *head)
1967 /* Convert fake tags to real feat indices */
1968 for (i = 0; i < head->info_num; i++)
1970 feature_type *f_ptr = &f_info[i];
1973 k = search_real_feat(f_ptr->mimic_tag);
1974 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1975 k = search_real_feat(f_ptr->destroyed_tag);
1976 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1977 for (j = 0; j < MAX_FEAT_STATES; j++)
1979 k = search_real_feat(f_ptr->state[j].result_tag);
1980 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1987 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1988 * Grab one flag in an object_kind from a textual string
1989 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1990 * @param what 参照元の文字列ポインタ
1993 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1998 for (i = 0; i < TR_FLAG_MAX; i++)
2000 if (streq(what, k_info_flags[i]))
2002 add_flag(k_ptr->flags, i);
2007 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2010 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2017 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2018 * Grab one activation index flag
2019 * @param what 参照元の文字列ポインタ
2022 static byte grab_one_activation_flag(concptr what)
2028 if (activation_info[i].flag == NULL) break;
2030 if (streq(what, activation_info[i].flag))
2032 return activation_info[i].index;
2042 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2050 * @brief ベースアイテム(k_info)のパース関数 /
2051 * Initialize the "k_info" array, by parsing an ascii "template" file
2053 * @param head ヘッダ構造体
2056 errr parse_k_info(char *buf, header *head)
2063 static object_kind *k_ptr = NULL;
2066 /* Process 'N' for "New/Number/Name" */
2073 /* Find the colon before the name */
2074 s = my_strchr(buf + 2, ':');
2076 /* Verify that colon */
2079 /* Nuke the colon, advance to the name */
2085 /* Verify information */
2086 if (i <= error_idx) return (4);
2088 /* Verify information */
2089 if (i >= head->info_num) return (2);
2091 /* Save the index */
2094 /* Point at the "info" */
2098 /* Paranoia -- require a name */
2099 if (!*s) return (1);
2101 /* Find the colon before the flavor */
2102 flavor = my_strchr(s, ':');
2104 /* Verify that colon */
2107 /* Nuke the colon, advance to the flavor */
2110 /* Store the flavor */
2111 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2114 /* Store the name */
2115 if (!add_name(&k_ptr->name, head, s)) return (7);
2119 /* There better be a current k_ptr */
2120 else if (!k_ptr) return (3);
2125 /* 'E' から始まる行は英語名としている */
2126 else if (buf[0] == 'E')
2131 else if (buf[0] == 'E')
2135 /* Acquire the name */
2138 /* Find the colon before the flavor */
2139 flavor = my_strchr(s, ':');
2141 /* Verify that colon */
2144 /* Nuke the colon, advance to the flavor */
2147 /* Store the flavor */
2148 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2151 /* Store the name */
2152 if (!add_name(&k_ptr->name, head, s)) return (7);
2156 /* Process 'D' for "Description" */
2157 else if (buf[0] == 'D')
2162 /* Acquire the text */
2167 /* Acquire the text */
2171 /* Store the text */
2172 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2175 /* Process 'G' for "Graphics" (one line only) */
2176 else if (buf[0] == 'G')
2180 if (buf[1] != ':') return (1);
2181 if (!buf[2]) return (1);
2182 if (buf[3] != ':') return (1);
2183 if (!buf[4]) return (1);
2185 /* Extract the char */
2188 /* Extract the attr */
2189 tmp = color_char_to_attr(buf[4]);
2190 if (tmp > 127) return (1);
2192 /* Save the values */
2193 k_ptr->d_attr = tmp;
2194 k_ptr->d_char = sym;
2197 /* Process 'I' for "Info" (one line only) */
2198 else if (buf[0] == 'I')
2200 int tval, sval, pval;
2202 /* Scan for the values */
2203 if (3 != sscanf(buf + 2, "%d:%d:%d",
2204 &tval, &sval, &pval)) return (1);
2206 /* Save the values */
2207 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2208 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2209 k_ptr->pval = (PARAMETER_VALUE)pval;
2212 /* Process 'W' for "More Info" (one line only) */
2213 else if (buf[0] == 'W')
2215 int level, extra, wgt;
2218 /* Scan for the values */
2219 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2220 &level, &extra, &wgt, &cost)) return (1);
2222 /* Save the values */
2223 k_ptr->level = (DEPTH)level;
2224 k_ptr->extra = (BIT_FLAGS8)extra;
2225 k_ptr->weight = (WEIGHT)wgt;
2226 k_ptr->cost = (PRICE)cost;
2229 /* Process 'A' for "Allocation" (one line only) */
2230 else if (buf[0] == 'A')
2233 /* Simply read each number following a colon */
2234 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2236 /* Default chance */
2237 k_ptr->chance[i] = 1;
2239 /* Store the attack damage index */
2240 k_ptr->locale[i] = atoi(s + 1);
2242 /* Find the slash */
2243 t = my_strchr(s + 1, '/');
2245 /* Find the next colon */
2246 s = my_strchr(s + 1, ':');
2248 /* If the slash is "nearby", use it */
2249 if (t && (!s || t < s))
2251 int chance = atoi(t + 1);
2252 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2257 /* Hack -- Process 'P' for "power" and such */
2258 else if (buf[0] == 'P')
2260 int ac, hd1, hd2, th, td, ta;
2262 /* Scan for the values */
2263 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2264 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2266 k_ptr->ac = (ARMOUR_CLASS)ac;
2267 k_ptr->dd = (DICE_NUMBER)hd1;
2268 k_ptr->ds = (DICE_SID)hd2;
2269 k_ptr->to_h = (HIT_PROB)th;
2270 k_ptr->to_d = (HIT_POINT)td;
2271 k_ptr->to_a = (ARMOUR_CLASS)ta;
2274 /* Hack -- Process 'U' for activation index */
2275 else if (buf[0] == 'U')
2278 n = grab_one_activation_flag(buf + 2);
2289 /* Hack -- Process 'F' for flags */
2290 else if (buf[0] == 'F')
2292 /* Parse every entry textually */
2293 for (s = buf + 2; *s; )
2295 /* Find the end of this entry */
2296 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2298 /* Nuke and skip any dividers */
2302 while (*t == ' ' || *t == '|') t++;
2305 /* Parse this entry */
2306 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2308 /* Start the next entry */
2322 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2323 * Grab one activation index flag
2324 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2325 * @param what 参照元の文字列ポインタ
2326 * @return エラーがあった場合1、エラーがない場合0を返す
2328 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2333 for (i = 0; i < TR_FLAG_MAX; i++)
2335 if (streq(what, k_info_flags[i]))
2337 add_flag(a_ptr->flags, i);
2342 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2345 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2353 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2354 * Initialize the "a_info" array, by parsing an ascii "template" file
2356 * @param head ヘッダ構造体
2359 errr parse_a_info(char *buf, header *head)
2366 static artifact_type *a_ptr = NULL;
2369 /* Process 'N' for "New/Number/Name" */
2372 /* Find the colon before the name */
2373 s = my_strchr(buf + 2, ':');
2375 /* Verify that colon */
2378 /* Nuke the colon, advance to the name */
2381 /* Paranoia -- require a name */
2382 if (!*s) return (1);
2387 /* Verify information */
2388 if (i < error_idx) return (4);
2390 /* Verify information */
2391 if (i >= head->info_num) return (2);
2393 /* Save the index */
2396 /* Point at the "info" */
2399 /* Ignore everything */
2400 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2401 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2402 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2403 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2405 /* Store the name */
2406 if (!add_name(&a_ptr->name, head, s)) return (7);
2410 /* There better be a current a_ptr */
2411 else if (!a_ptr) return (3);
2416 /* 'E' から始まる行は英語名としている */
2417 else if (buf[0] == 'E')
2422 else if (buf[0] == 'E')
2424 /* Acquire the Text */
2427 /* Store the name */
2428 if (!add_name(&a_ptr->name, head, s)) return (7);
2432 /* Process 'D' for "Description" */
2433 else if (buf[0] == 'D')
2438 /* Acquire the text */
2443 /* Acquire the text */
2447 /* Store the text */
2448 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2452 /* Process 'I' for "Info" (one line only) */
2453 else if (buf[0] == 'I')
2455 int tval, sval, pval;
2457 /* Scan for the values */
2458 if (3 != sscanf(buf + 2, "%d:%d:%d",
2459 &tval, &sval, &pval)) return (1);
2461 /* Save the values */
2462 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2463 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2464 a_ptr->pval = (PARAMETER_VALUE)pval;
2467 /* Process 'W' for "More Info" (one line only) */
2468 else if (buf[0] == 'W')
2470 int level, rarity, wgt;
2473 /* Scan for the values */
2474 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2475 &level, &rarity, &wgt, &cost)) return (1);
2477 /* Save the values */
2478 a_ptr->level = (DEPTH)level;
2479 a_ptr->rarity = (RARITY)rarity;
2480 a_ptr->weight = (WEIGHT)wgt;
2481 a_ptr->cost = (PRICE)cost;
2484 /* Hack -- Process 'P' for "power" and such */
2485 else if (buf[0] == 'P')
2487 int ac, hd1, hd2, th, td, ta;
2489 /* Scan for the values */
2490 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2491 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2493 a_ptr->ac = (ARMOUR_CLASS)ac;
2494 a_ptr->dd = (DICE_NUMBER)hd1;
2495 a_ptr->ds = (DICE_SID)hd2;
2496 a_ptr->to_h = (HIT_PROB)th;
2497 a_ptr->to_d = (HIT_POINT)td;
2498 a_ptr->to_a = (ARMOUR_CLASS)ta;
2501 /* Hack -- Process 'U' for activation index */
2502 else if (buf[0] == 'U')
2505 n = grab_one_activation_flag(buf + 2);
2516 /* Hack -- Process 'F' for flags */
2517 else if (buf[0] == 'F')
2519 /* Parse every entry textually */
2520 for (s = buf + 2; *s; )
2522 /* Find the end of this entry */
2523 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2525 /* Nuke and skip any dividers */
2529 while ((*t == ' ') || (*t == '|')) t++;
2532 /* Parse this entry */
2533 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2535 /* Start the next entry */
2550 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2551 * Grab one flag in a ego-item_type from a textual string
2552 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2553 * @param what 参照元の文字列ポインタ
2554 * @return エラーがあった場合1、エラーがない場合0を返す
2556 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2561 for (i = 0; i < TR_FLAG_MAX; i++)
2563 if (streq(what, k_info_flags[i]))
2565 add_flag(e_ptr->flags, i);
2570 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2573 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2581 * @brief アイテムエゴ情報(e_info)のパース関数 /
2582 * Initialize the "e_info" array, by parsing an ascii "template" file
2584 * @param head ヘッダ構造体
2587 errr parse_e_info(char *buf, header *head)
2593 static ego_item_type *e_ptr = NULL;
2595 /* Just before the first record */
2598 /* Just before the first line */
2601 /* Process 'N' for "New/Number/Name" */
2604 /* Find the colon before the name */
2605 s = my_strchr(buf + 2, ':');
2607 /* Verify that colon */
2610 /* Nuke the colon, advance to the name */
2613 /* Paranoia -- require a name */
2614 if (!*s) return (1);
2619 /* Verify information */
2620 if (i < error_idx) return (4);
2622 /* Verify information */
2623 if (i >= head->info_num) return (2);
2625 /* Save the index */
2628 /* Point at the "info" */
2631 /* Store the name */
2632 if (!add_name(&e_ptr->name, head, s)) return (7);
2636 /* There better be a current e_ptr */
2637 else if (!e_ptr) return (3);
2642 /* 'E' から始まる行は英語名 */
2643 else if (buf[0] == 'E')
2648 else if (buf[0] == 'E')
2650 /* Acquire the Text */
2653 /* Store the name */
2654 if (!add_name(&e_ptr->name, head, s)) return (7);
2659 /* Process 'D' for "Description" */
2660 else if (buf[0] == 'D')
2662 /* Acquire the text */
2665 /* Store the text */
2666 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2671 /* Process 'X' for "Xtra" (one line only) */
2672 else if (buf[0] == 'X')
2676 /* Scan for the values */
2677 if (2 != sscanf(buf + 2, "%d:%d",
2678 &slot, &rating)) return (1);
2680 /* Save the values */
2681 e_ptr->slot = (INVENTORY_IDX)slot;
2682 e_ptr->rating = (PRICE)rating;
2685 /* Process 'W' for "More Info" (one line only) */
2686 else if (buf[0] == 'W')
2688 int level, rarity, pad2;
2691 /* Scan for the values */
2692 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2693 &level, &rarity, &pad2, &cost)) return (1);
2695 /* Save the values */
2696 e_ptr->level = level;
2697 e_ptr->rarity = (RARITY)rarity;
2698 /* e_ptr->weight = wgt; */
2702 /* Hack -- Process 'C' for "creation" */
2703 else if (buf[0] == 'C')
2705 int th, td, ta, pval;
2707 /* Scan for the values */
2708 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2709 &th, &td, &ta, &pval)) return (1);
2711 e_ptr->max_to_h = (HIT_PROB)th;
2712 e_ptr->max_to_d = (HIT_POINT)td;
2713 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2714 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2717 /* Hack -- Process 'U' for activation index */
2718 else if (buf[0] == 'U')
2721 n = grab_one_activation_flag(buf + 2);
2732 /* Hack -- Process 'F' for flags */
2733 else if (buf[0] == 'F')
2735 /* Parse every entry textually */
2736 for (s = buf + 2; *s; )
2738 /* Find the end of this entry */
2739 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2741 /* Nuke and skip any dividers */
2745 while ((*t == ' ') || (*t == '|')) t++;
2748 /* Parse this entry */
2749 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2751 /* Start the next entry */
2764 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2765 * Grab one (basic) flag in a monster_race from a textual string
2766 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2767 * @param what 参照元の文字列ポインタ
2770 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2772 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2775 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2778 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2781 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2784 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2787 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2790 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2793 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2801 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2802 * Grab one (spell) flag in a monster_race from a textual string
2803 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2804 * @param what 参照元の文字列ポインタ
2807 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2809 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2812 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2815 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2818 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2826 * @brief モンスター種族情報(r_info)のパース関数 /
2827 * Initialize the "r_info" array, by parsing an ascii "template" file
2829 * @param head ヘッダ構造体
2832 errr parse_r_info(char *buf, header *head)
2838 static monster_race *r_ptr = NULL;
2841 /* Process 'N' for "New/Number/Name" */
2844 /* Find the colon before the name */
2845 s = my_strchr(buf + 2, ':');
2847 /* Verify that colon */
2850 /* Nuke the colon, advance to the name */
2853 /* Paranoia -- require a name */
2854 if (!*s) return (1);
2859 /* Verify information */
2860 if (i < error_idx) return (4);
2862 /* Verify information */
2863 if (i >= head->info_num) return (2);
2865 /* Save the index */
2868 /* Point at the "info" */
2871 /* Store the name */
2872 if (!add_name(&r_ptr->name, head, s)) return (7);
2876 /* There better be a current r_ptr */
2877 else if (!r_ptr) return (3);
2882 /* 'E' から始まる行は英語名 */
2883 else if (buf[0] == 'E')
2885 /* Acquire the Text */
2888 /* Store the name */
2889 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2892 else if (buf[0] == 'E')
2894 /* Acquire the Text */
2897 /* Store the name */
2898 if (!add_name(&r_ptr->name, head, s)) return (7);
2901 /* Process 'D' for "Description" */
2902 else if (buf[0] == 'D')
2907 /* Acquire the text */
2912 /* Acquire the text */
2916 /* Store the text */
2917 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2920 /* Process 'G' for "Graphics" (one line only) */
2921 else if (buf[0] == 'G')
2925 if (buf[1] != ':') return (1);
2926 if (!buf[2]) return (1);
2927 if (buf[3] != ':') return (1);
2928 if (!buf[4]) return (1);
2930 /* Extract the char */
2933 /* Extract the attr */
2934 tmp = color_char_to_attr(buf[4]);
2935 if (tmp > 127) return (1);
2937 /* Save the values */
2938 r_ptr->d_char = sym;
2939 r_ptr->d_attr = tmp;
2942 /* Process 'I' for "Info" (one line only) */
2943 else if (buf[0] == 'I')
2945 int spd, hp1, hp2, aaf, ac, slp;
2947 /* Scan for the other values */
2948 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2949 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2951 /* Save the values */
2952 r_ptr->speed = (SPEED)spd;
2953 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2954 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2955 r_ptr->aaf = (POSITION)aaf;
2956 r_ptr->ac = (ARMOUR_CLASS)ac;
2957 r_ptr->sleep = (SLEEP_DEGREE)slp;
2960 /* Process 'W' for "More Info" (one line only) */
2961 else if (buf[0] == 'W')
2968 /* Scan for the values */
2969 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2970 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2972 /* Save the values */
2973 r_ptr->level = (DEPTH)lev;
2974 r_ptr->rarity = (RARITY)rar;
2975 r_ptr->extra = (BIT_FLAGS16)pad;
2976 r_ptr->mexp = (EXP)exp;
2977 r_ptr->next_exp = (EXP)nextexp;
2978 r_ptr->next_r_idx = (IDX)nextmon;
2981 /* Process 'R' for "Reinforcement" (up to six lines) */
2982 else if (buf[0] == 'R')
2985 /* Find the next empty blow slot (if any) */
2986 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2988 /* Oops, no more slots */
2989 if (i == 6) return (1);
2991 /* Scan for the values */
2992 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2993 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2994 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2995 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2998 /* Process 'B' for "Blows" (up to four lines) */
2999 else if (buf[0] == 'B')
3003 /* Find the next empty blow slot (if any) */
3004 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3006 /* Oops, no more slots */
3007 if (i == 4) return (1);
3009 /* Analyze the first field */
3010 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3012 /* Terminate the field (if necessary) */
3013 if (*t == ':') *t++ = '\0';
3015 /* Analyze the method */
3016 for (n1 = 0; r_info_blow_method[n1]; n1++)
3018 if (streq(s, r_info_blow_method[n1])) break;
3021 /* Invalid method */
3022 if (!r_info_blow_method[n1]) return (1);
3024 /* Analyze the second field */
3025 for (s = t; *t && (*t != ':'); t++) /* loop */;
3027 /* Terminate the field (if necessary) */
3028 if (*t == ':') *t++ = '\0';
3030 /* Analyze effect */
3031 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3033 if (streq(s, r_info_blow_effect[n2])) break;
3036 /* Invalid effect */
3037 if (!r_info_blow_effect[n2]) return (1);
3039 /* Analyze the third field */
3040 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3042 /* Terminate the field (if necessary) */
3043 if (*t == 'd') *t++ = '\0';
3045 /* Save the method */
3046 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3048 /* Save the effect */
3049 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3051 /* Extract the damage dice and sides */
3052 r_ptr->blow[i].d_dice = atoi(s);
3053 r_ptr->blow[i].d_side = atoi(t);
3056 /* Process 'F' for "Basic Flags" (multiple lines) */
3057 else if (buf[0] == 'F')
3059 /* Parse every entry */
3060 for (s = buf + 2; *s; )
3062 /* Find the end of this entry */
3063 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3065 /* Nuke and skip any dividers */
3069 while (*t == ' ' || *t == '|') t++;
3072 /* Parse this entry */
3073 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3075 /* Start the next entry */
3080 /* Process 'S' for "Spell Flags" (multiple lines) */
3081 else if (buf[0] == 'S')
3083 /* Parse every entry */
3084 for (s = buf + 2; *s; )
3086 /* Find the end of this entry */
3087 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3089 /* Nuke and skip any dividers */
3093 while ((*t == ' ') || (*t == '|')) t++;
3096 /* Hack -- Read spell frequency */
3097 if (1 == sscanf(s, "1_IN_%d", &i))
3099 /* Extract a "frequency" */
3100 r_ptr->freq_spell = 100 / i;
3102 /* Start at next entry */
3107 /* Parse this entry */
3108 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3110 /* Start the next entry */
3115 /* Process 'A' for "Artifact Flags" (multiple lines) */
3116 else if (buf[0] == 'A')
3118 int id, per, rarity;
3120 /* Find the next empty blow slot (if any) */
3121 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3123 /* Oops, no more slots */
3124 if (i == 4) return (1);
3126 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3127 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3128 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3129 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3132 /* Process 'V' for "Arena power value ratio" */
3133 else if (buf[0] == 'V')
3136 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3137 r_ptr->arena_ratio = (PERCENTAGE)val;
3149 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3150 * Grab one flag for a dungeon type from a textual string
3151 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3152 * @param what 参照元の文字列ポインタ
3155 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3157 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3160 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3167 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3168 * Grab one (basic) flag in a monster_race from a textual string
3169 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3170 * @param what 参照元の文字列ポインタ
3173 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3175 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3178 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3181 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3184 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3187 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3190 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3193 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3196 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3203 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3204 * Grab one (spell) flag in a monster_race from a textual string
3205 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3206 * @param what 参照元の文字列ポインタ
3209 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3211 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3214 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3217 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3220 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3227 * @brief ダンジョン情報(d_info)のパース関数 /
3228 * Initialize the "d_info" array, by parsing an ascii "template" file
3230 * @param head ヘッダ構造体
3233 errr parse_d_info(char *buf, header *head)
3239 static dungeon_type *d_ptr = NULL;
3241 /* Process 'N' for "New/Number/Name" */
3244 /* Find the colon before the name */
3245 s = my_strchr(buf + 2, ':');
3247 /* Verify that colon */
3250 /* Nuke the colon, advance to the name */
3253 /* Paranoia -- require a name */
3254 if (!*s) return (1);
3259 /* Verify information */
3260 if (i < error_idx) return (4);
3262 /* Verify information */
3263 if (i >= head->info_num) return (2);
3265 /* Save the index */
3268 /* Point at the "info" */
3271 /* Store the name */
3272 if (!add_name(&d_ptr->name, head, s)) return (7);
3277 else if (buf[0] == 'E') return (0);
3279 else if (buf[0] == 'E')
3281 /* Acquire the Text */
3284 /* Store the name */
3285 if (!add_name(&d_ptr->name, head, s)) return (7);
3289 /* Process 'D' for "Description */
3290 else if (buf[0] == 'D')
3295 /* Acquire the text */
3300 /* Acquire the text */
3304 /* Store the text */
3305 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3308 /* Process 'W' for "More Info" (one line only) */
3309 else if (buf[0] == 'W')
3311 int min_lev, max_lev;
3313 int min_alloc, max_chance;
3314 int obj_good, obj_great;
3317 /* Scan for the values */
3318 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3319 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3321 /* Save the values */
3322 d_ptr->mindepth = (DEPTH)min_lev;
3323 d_ptr->maxdepth = (DEPTH)max_lev;
3324 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3325 d_ptr->mode = (BIT_FLAGS8)mode;
3326 d_ptr->min_m_alloc_level = min_alloc;
3327 d_ptr->max_m_alloc_chance = max_chance;
3328 d_ptr->obj_good = obj_good;
3329 d_ptr->obj_great = obj_great;
3330 d_ptr->pit = (BIT_FLAGS16)pit;
3331 d_ptr->nest = (BIT_FLAGS16)nest;
3334 /* Process 'P' for "Place Info" */
3335 else if (buf[0] == 'P')
3339 /* Scan for the values */
3340 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3342 /* Save the values */
3347 /* Process 'L' for "fLoor type" (one line only) */
3348 else if (buf[0] == 'L')
3352 /* Scan for the values */
3353 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3355 /* Save the values */
3356 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3358 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3359 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3361 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3363 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3366 /* Process 'A' for "wAll type" (one line only) */
3367 else if (buf[0] == 'A')
3371 /* Scan for the values */
3372 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3374 /* Save the values */
3375 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3377 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3378 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3380 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3383 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3384 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3386 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3387 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3389 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3390 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3392 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3393 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3396 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3397 else if (buf[0] == 'F')
3399 int artif = 0, monst = 0;
3401 /* Parse every entry */
3402 for (s = buf + 2; *s; )
3404 /* Find the end of this entry */
3405 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3407 /* Nuke and skip any dividers */
3411 while (*t == ' ' || *t == '|') t++;
3414 /* Hack -- Read Final Artifact */
3415 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3417 /* Extract a "Final Artifact" */
3418 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3420 /* Start at next entry */
3425 /* Hack -- Read Final Object */
3426 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3428 /* Extract a "Final Artifact" */
3429 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3431 /* Start at next entry */
3436 /* Hack -- Read Artifact Guardian */
3437 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3439 /* Extract a "Artifact Guardian" */
3440 d_ptr->final_guardian = (MONRACE_IDX)monst;
3442 /* Start at next entry */
3447 /* Hack -- Read Special Percentage */
3448 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3450 /* Extract a "Special %" */
3451 d_ptr->special_div = (PROB)monst;
3453 /* Start at next entry */
3458 /* Parse this entry */
3459 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3461 /* Start the next entry */
3466 /* Process 'M' for "Basic Flags" (multiple lines) */
3467 else if (buf[0] == 'M')
3469 /* Parse every entry */
3470 for (s = buf + 2; *s; )
3472 /* Find the end of this entry */
3473 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3475 /* Nuke and skip any dividers */
3479 while (*t == ' ' || *t == '|') t++;
3482 /* Hack -- Read monster symbols */
3483 if (!strncmp(s, "R_CHAR_", 7))
3485 /* Skip "R_CHAR_" */
3489 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3491 /* Start at next entry */
3496 /* Parse this entry */
3497 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3499 /* Start the next entry */
3504 /* Process 'S' for "Spell Flags" (multiple lines) */
3505 else if (buf[0] == 'S')
3507 /* Parse every entry */
3508 for (s = buf + 2; *s; )
3510 /* Find the end of this entry */
3511 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3513 /* Nuke and skip any dividers */
3517 while ((*t == ' ') || (*t == '|')) t++;
3520 /* Hack -- Read spell frequency */
3521 if (1 == sscanf(s, "1_IN_%d", &i))
3523 /* Start at next entry */
3528 /* Parse this entry */
3529 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3531 /* Start the next entry */
3543 #else /* ALLOW_TEMPLATES */
3549 #endif /* ALLOW_TEMPLATES */
3553 * @brief 地形情報の「F:」情報をパースする
3554 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3558 static errr parse_line_feature(char *buf)
3563 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3565 /* Tokenize the line */
3566 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3568 /* Letter to assign */
3569 int index = zz[0][0];
3571 /* Reset the info for the letter */
3572 letter[index].feature = feat_none;
3573 letter[index].monster = 0;
3574 letter[index].object = 0;
3575 letter[index].ego = 0;
3576 letter[index].artifact = 0;
3577 letter[index].trap = feat_none;
3578 letter[index].cave_info = 0;
3579 letter[index].special = 0;
3580 letter[index].random = RANDOM_NONE;
3586 letter[index].special = (s16b)atoi(zz[8]);
3590 if ((zz[7][0] == '*') && !zz[7][1])
3592 letter[index].random |= RANDOM_TRAP;
3596 letter[index].trap = f_tag_to_index(zz[7]);
3597 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3602 if (zz[6][0] == '*')
3604 letter[index].random |= RANDOM_ARTIFACT;
3605 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3607 else if (zz[6][0] == '!')
3609 if (p_ptr->inside_quest)
3611 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3616 letter[index].artifact = (IDX)atoi(zz[6]);
3621 if (zz[5][0] == '*')
3623 letter[index].random |= RANDOM_EGO;
3624 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3628 letter[index].ego = (IDX)atoi(zz[5]);
3633 if (zz[4][0] == '*')
3635 letter[index].random |= RANDOM_OBJECT;
3636 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3638 else if (zz[4][0] == '!')
3640 if (p_ptr->inside_quest)
3642 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3645 artifact_type *a_ptr = &a_info[a_idx];
3646 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3648 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3655 letter[index].object = (IDX)atoi(zz[4]);
3660 if (zz[3][0] == '*')
3662 letter[index].random |= RANDOM_MONSTER;
3663 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3665 else if (zz[3][0] == 'c')
3667 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3668 letter[index].monster = -atoi(zz[3] + 1);
3672 letter[index].monster = (IDX)atoi(zz[3]);
3677 letter[index].cave_info = atoi(zz[2]);
3681 if ((zz[1][0] == '*') && !zz[1][1])
3683 letter[index].random |= RANDOM_FEATURE;
3687 letter[index].feature = f_tag_to_index(zz[1]);
3688 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3701 * @brief 地形情報の「B:」情報をパースする
3702 * Process "B:<Index>:<Command>:..." -- Building definition
3706 static errr parse_line_building(char *buf)
3722 /* Get the building number */
3725 /* Find the colon after the building number */
3726 s = my_strchr(s, ':');
3728 /* Verify that colon */
3731 /* Nuke the colon, advance to the sub-index */
3734 /* Paranoia -- require a sub-index */
3735 if (!*s) return (1);
3737 /* Building definition sub-index */
3740 /* Building name, owner, race */
3743 if (tokenize(s + 2, 3, zz, 0) == 3)
3745 /* Name of the building */
3746 strcpy(building[index].name, zz[0]);
3748 /* Name of the owner */
3749 strcpy(building[index].owner_name, zz[1]);
3751 /* Race of the owner */
3752 strcpy(building[index].owner_race, zz[2]);
3757 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3760 /* Building Action */
3763 if (tokenize(s + 2, 8, zz, 0) >= 7)
3765 /* Index of the action */
3766 int action_index = atoi(zz[0]);
3768 /* Name of the action */
3769 strcpy(building[index].act_names[action_index], zz[1]);
3771 /* Cost of the action for members */
3772 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3774 /* Cost of the action for non-members */
3775 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3777 /* Letter assigned to the action */
3778 building[index].letters[action_index] = zz[4][0];
3781 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3783 /* Action restriction */
3784 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3789 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3792 /* Building Classes */
3796 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3797 for (i = 0; i < MAX_CLASS; i++)
3799 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3804 /* Building Races */
3808 n = tokenize(s + 2, MAX_RACES, zz, 0);
3809 for (i = 0; i < MAX_RACES; i++)
3811 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3816 /* Building Realms */
3820 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3821 for (i = 0; i < MAX_MAGIC; i++)
3823 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3830 /* Ignore scripts */
3836 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3845 * @brief フロアの所定のマスにオブジェクトを配置する
3846 * Place the object j_ptr to a grid
3847 * @param j_ptr オブジェクト構造体の参照ポインタ
3852 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3854 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3857 OBJECT_IDX o_idx = o_pop();
3859 /* Access new object */
3860 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3862 /* Structure copy */
3863 object_copy(o_ptr, j_ptr);
3870 o_ptr->held_m_idx = 0;
3873 o_ptr->next_o_idx = g_ptr->o_idx;
3875 g_ptr->o_idx = o_idx;
3879 * @brief クエスト用固定ダンジョンをフロアに生成する
3880 * Parse a sub-file of the "extra info"
3890 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3895 /* Skip "empty" lines */
3896 if (!buf[0]) return (0);
3898 /* Skip "blank" lines */
3899 if (iswspace(buf[0])) return (0);
3902 if (buf[0] == '#') return (0);
3904 /* Require "?:*" format */
3905 if (buf[1] != ':') return (1);
3908 /* Process "%:<fname>" */
3911 /* Attempt to Process the given file */
3912 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3915 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3918 return parse_line_feature(buf);
3921 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3922 else if (buf[0] == 'D')
3924 object_type object_type_body;
3926 /* Acquire the text */
3929 /* Length of the text */
3930 int len = strlen(s);
3932 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3934 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3936 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3940 OBJECT_IDX object_index = letter[idx].object;
3941 MONSTER_IDX monster_index = letter[idx].monster;
3942 int random = letter[idx].random;
3943 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3945 /* Lay down a floor */
3946 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3948 /* Only the features */
3949 if (init_flags & INIT_ONLY_FEATURES) continue;
3952 g_ptr->info = letter[idx].cave_info;
3954 /* Create a monster */
3955 if (random & RANDOM_MONSTER)
3957 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3959 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3961 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3963 else if (monster_index)
3965 int old_cur_num, old_max_num;
3968 if (monster_index < 0)
3970 monster_index = -monster_index;
3973 old_cur_num = r_info[monster_index].cur_num;
3974 old_max_num = r_info[monster_index].max_num;
3976 /* Make alive again */
3977 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3979 r_info[monster_index].cur_num = 0;
3980 r_info[monster_index].max_num = 1;
3983 /* Make alive again */
3984 /* Hack -- Non-unique Nazguls are semi-unique */
3985 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3987 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3989 r_info[monster_index].max_num++;
3994 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3998 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
4000 /* Make alive again for real unique monster */
4001 r_info[monster_index].cur_num = old_cur_num;
4002 r_info[monster_index].max_num = old_max_num;
4006 /* Object (and possible trap) */
4007 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4009 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4012 * Random trap and random treasure defined
4013 * 25% chance for trap and 75% chance for object
4015 if (randint0(100) < 75)
4017 place_object(*y, *x, 0L);
4024 current_floor_ptr->object_level = current_floor_ptr->base_level;
4026 else if (random & RANDOM_OBJECT)
4028 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4030 /* Create an out of deep object */
4031 if (randint0(100) < 75)
4032 place_object(*y, *x, 0L);
4033 else if (randint0(100) < 80)
4034 place_object(*y, *x, AM_GOOD);
4036 place_object(*y, *x, AM_GOOD | AM_GREAT);
4038 current_floor_ptr->object_level = current_floor_ptr->base_level;
4041 else if (random & RANDOM_TRAP)
4045 /* Hidden trap (or door) */
4046 else if (letter[idx].trap)
4048 g_ptr->mimic = g_ptr->feat;
4049 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4051 else if (object_index)
4053 object_type *o_ptr = &object_type_body;
4054 object_prep(o_ptr, object_index);
4056 if (o_ptr->tval == TV_GOLD)
4058 coin_type = object_index - OBJ_GOLD_LIST;
4063 /* Apply magic (no messages, no artifacts) */
4064 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4066 drop_here(o_ptr, *y, *x);
4072 if (a_info[artifact_index].cur_num)
4074 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4076 object_type *q_ptr = &forge;
4078 object_prep(q_ptr, k_idx);
4079 drop_here(q_ptr, *y, *x);
4083 if (create_named_art(artifact_index, *y, *x))
4084 a_info[artifact_index].cur_num = 1;
4088 /* Terrain special */
4089 g_ptr->special = letter[idx].special;
4097 /* Process "Q:<number>:<command>:... -- quest info */
4098 else if (buf[0] == 'Q')
4105 num = tokenize(buf + 2, 33, zz, 0);
4109 num = tokenize(buf + 3, 33, zz, 0);
4112 /* Have we enough parameters? */
4113 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4116 q_ptr = &(quest[atoi(zz[0])]);
4118 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4119 if (zz[1][0] == 'Q')
4121 if (init_flags & INIT_ASSIGN)
4123 monster_race *r_ptr;
4124 artifact_type *a_ptr;
4126 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4128 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4129 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4130 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4131 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4132 q_ptr->level = (DEPTH)atoi(zz[6]);
4133 q_ptr->r_idx = (IDX)atoi(zz[7]);
4134 q_ptr->k_idx = (IDX)atoi(zz[8]);
4135 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4137 if (num > 10) q_ptr->flags = atoi(zz[10]);
4139 r_ptr = &r_info[q_ptr->r_idx];
4140 if (r_ptr->flags1 & RF1_UNIQUE)
4141 r_ptr->flags1 |= RF1_QUESTOR;
4143 a_ptr = &a_info[q_ptr->k_idx];
4144 a_ptr->gen_flags |= TRG_QUESTITEM;
4149 else if (zz[1][0] == 'R')
4151 if (init_flags & INIT_ASSIGN)
4154 IDX idx, reward_idx = 0;
4156 for (idx = 2; idx < num; idx++)
4158 IDX a_idx = (IDX)atoi(zz[idx]);
4159 if (a_idx < 1) continue;
4160 if (a_info[a_idx].cur_num > 0) continue;
4162 if (one_in_(count)) reward_idx = a_idx;
4167 /* Set quest's rewarding artifact */
4168 q_ptr->k_idx = reward_idx;
4169 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4173 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4174 q_ptr->type = QUEST_TYPE_KILL_ALL;
4181 /* Process "Q:<q_index>:N:<name>" -- quest name */
4182 else if (zz[1][0] == 'N')
4184 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4186 strcpy(q_ptr->name, zz[2]);
4192 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4193 else if (zz[1][0] == 'T')
4195 if (init_flags & INIT_SHOW_TEXT)
4197 strcpy(quest_text[quest_text_line], zz[2]);
4205 /* Process "W:<command>: ..." -- info for the wilderness */
4206 else if (buf[0] == 'W')
4208 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4211 /* Process "P:<y>:<x>" -- player position */
4212 else if (buf[0] == 'P')
4214 if (init_flags & INIT_CREATE_DUNGEON)
4216 if (tokenize(buf + 2, 2, zz, 0) == 2)
4218 int panels_x, panels_y;
4220 /* Hack - Set the dungeon size */
4221 panels_y = (*y / SCREEN_HGT);
4222 if (*y % SCREEN_HGT) panels_y++;
4223 current_floor_ptr->height = panels_y * SCREEN_HGT;
4225 panels_x = (*x / SCREEN_WID);
4226 if (*x % SCREEN_WID) panels_x++;
4227 current_floor_ptr->width = panels_x * SCREEN_WID;
4229 /* Assume illegal panel */
4230 panel_row_min = current_floor_ptr->height;
4231 panel_col_min = current_floor_ptr->width;
4233 /* Place player in a quest level */
4234 if (p_ptr->inside_quest)
4238 /* Delete the monster (if any) */
4239 delete_monster(p_ptr->y, p_ptr->x);
4247 /* Place player in the town */
4248 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4250 p_ptr->oldpy = atoi(zz[0]);
4251 p_ptr->oldpx = atoi(zz[1]);
4259 /* Process "B:<Index>:<Command>:..." -- Building definition */
4260 else if (buf[0] == 'B')
4262 return parse_line_building(buf);
4265 /* Process "M:<type>:<maximum>" -- set maximum values */
4266 else if (buf[0] == 'M')
4268 if (tokenize(buf + 2, 2, zz, 0) == 2)
4271 if (zz[0][0] == 'T')
4273 max_towns = (TOWN_IDX)atoi(zz[1]);
4276 /* Maximum quests */
4277 else if (zz[0][0] == 'Q')
4279 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4283 else if (zz[0][0] == 'R')
4285 max_r_idx = (IDX)atoi(zz[1]);
4289 else if (zz[0][0] == 'K')
4291 max_k_idx = (IDX)atoi(zz[1]);
4295 else if (zz[0][0] == 'V')
4297 max_v_idx = (IDX)atoi(zz[1]);
4301 else if (zz[0][0] == 'F')
4303 max_f_idx = (IDX)atoi(zz[1]);
4307 else if (zz[0][0] == 'A')
4309 max_a_idx = (IDX)atoi(zz[1]);
4313 else if (zz[0][0] == 'E')
4315 max_e_idx = (IDX)atoi(zz[1]);
4319 else if (zz[0][0] == 'D')
4321 max_d_idx = (IDX)atoi(zz[1]);
4325 else if (zz[0][0] == 'O')
4327 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4331 else if (zz[0][0] == 'M')
4333 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4336 /* Wilderness size */
4337 else if (zz[0][0] == 'W')
4339 /* Maximum wild_x_size */
4340 if (zz[0][1] == 'X')
4341 current_world_ptr->max_wild_x = atoi(zz[1]);
4342 /* Maximum wild_y_size */
4343 if (zz[0][1] == 'Y')
4344 current_world_ptr->max_wild_y = atoi(zz[1]);
4358 static concptr variant = "ZANGBAND";
4362 * @brief クエスト用固定ダンジョン生成時の分岐処理
4363 * Helper function for "process_dungeon_file()"
4368 static concptr process_dungeon_file_expr(char **sp, char *fp)
4384 while (iswspace(*s)) s++;
4402 t = process_dungeon_file_expr(&s, &f);
4410 else if (streq(t, "IOR"))
4413 while (*s && (f != b2))
4415 t = process_dungeon_file_expr(&s, &f);
4416 if (*t && !streq(t, "0")) v = "1";
4421 else if (streq(t, "AND"))
4424 while (*s && (f != b2))
4426 t = process_dungeon_file_expr(&s, &f);
4427 if (*t && streq(t, "0")) v = "0";
4432 else if (streq(t, "NOT"))
4435 while (*s && (f != b2))
4437 t = process_dungeon_file_expr(&s, &f);
4438 if (*t && streq(t, "1")) v = "0";
4443 else if (streq(t, "EQU"))
4446 if (*s && (f != b2))
4448 t = process_dungeon_file_expr(&s, &f);
4450 while (*s && (f != b2))
4452 p = process_dungeon_file_expr(&s, &f);
4453 if (streq(t, p)) v = "1";
4458 else if (streq(t, "LEQ"))
4461 if (*s && (f != b2))
4463 t = process_dungeon_file_expr(&s, &f);
4465 while (*s && (f != b2))
4468 t = process_dungeon_file_expr(&s, &f);
4469 if (*t && atoi(p) > atoi(t)) v = "0";
4474 else if (streq(t, "GEQ"))
4477 if (*s && (f != b2))
4479 t = process_dungeon_file_expr(&s, &f);
4481 while (*s && (f != b2))
4484 t = process_dungeon_file_expr(&s, &f);
4486 /* Compare two numbers instead of string */
4487 if (*t && atoi(p) < atoi(t)) v = "0";
4493 while (*s && (f != b2))
4495 t = process_dungeon_file_expr(&s, &f);
4500 if (f != b2) v = "?x?x?";
4502 /* Extract final and Terminate */
4503 if ((f = *s) != '\0') *s++ = '\0';
4509 /* Accept all printables except spaces and brackets */
4511 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4513 if (iskanji(*s)) s++;
4517 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4520 /* Extract final and Terminate */
4521 if ((f = *s) != '\0') *s++ = '\0';
4527 if (streq(b + 1, "SYS"))
4533 else if (streq(b + 1, "GRAF"))
4538 else if (streq(b + 1, "MONOCHROME"))
4547 else if (streq(b + 1, "RACE"))
4549 v = _(rp_ptr->E_title, rp_ptr->title);
4553 else if (streq(b + 1, "CLASS"))
4555 v = _(cp_ptr->E_title, cp_ptr->title);
4559 else if (streq(b + 1, "REALM1"))
4561 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4565 else if (streq(b + 1, "REALM2"))
4567 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4571 else if (streq(b + 1, "PLAYER"))
4573 static char tmp_player_name[32];
4575 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4585 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4588 v = tmp_player_name;
4592 else if (streq(b + 1, "TOWN"))
4594 sprintf(tmp, "%d", p_ptr->town_num);
4599 else if (streq(b + 1, "LEVEL"))
4601 sprintf(tmp, "%d", p_ptr->lev);
4605 /* Current quest number */
4606 else if (streq(b + 1, "QUEST_NUMBER"))
4608 sprintf(tmp, "%d", p_ptr->inside_quest);
4612 /* Number of last quest */
4613 else if (streq(b + 1, "LEAVING_QUEST"))
4615 sprintf(tmp, "%d", leaving_quest);
4620 else if (prefix(b + 1, "QUEST_TYPE"))
4622 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4623 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4628 else if (prefix(b + 1, "QUEST"))
4630 /* "QUEST" uses a special parameter to determine the number of the quest */
4631 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4636 else if (prefix(b + 1, "RANDOM"))
4638 /* "RANDOM" uses a special parameter to determine the number of the quest */
4639 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
4644 else if (streq(b + 1, "VARIANT"))
4650 else if (streq(b + 1, "WILDERNESS"))
4653 sprintf(tmp, "NONE");
4655 sprintf(tmp, "LITE");
4657 sprintf(tmp, "NORMAL");
4676 void write_r_info_txt(void)
4678 int i, j, z, fc, bc;
4681 concptr flags[32 * 10];
4686 monster_race *r_ptr;
4688 monster_blow *b_ptr;
4690 FILE *fff = fopen("output.txt", "wt");
4694 BIT_FLAGS mode = -1;
4698 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4700 fprintf(fff, "# Version stamp (required)\n\n");
4703 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4706 fprintf(fff, "##### The Player #####\n\n");
4708 for (z = -1; z < alloc_race_size; z++)
4710 /* Output the monsters in order */
4711 i = (z >= 0) ? alloc_race_table[z].index : 0;
4713 /* Acquire the monster */
4716 /* Ignore empty monsters */
4717 if (!strlen(r_name + r_ptr->name)) continue;
4719 /* Ignore useless monsters */
4720 if (i && !r_ptr->speed) continue;
4722 /* Write a note if necessary */
4723 if (i && (!r_ptr->level != !mode))
4728 fprintf(fff, "\n##### Town monsters #####\n\n");
4730 /* Note the dungeon */
4733 fprintf(fff, "\n##### Normal monsters #####\n\n");
4736 /* Record the change */
4737 mode = r_ptr->level;
4740 /* Acquire the flags */
4741 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4742 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4743 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4744 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4745 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4746 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4747 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4748 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4749 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4750 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4752 /* Write New/Number/Name */
4753 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4756 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4758 /* Write Information */
4759 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4760 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4762 /* Write more information */
4763 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4766 for (j = 0; j < 4; j++)
4768 b_ptr = &(r_ptr->blow[j]);
4770 /* Stop when done */
4771 if (!b_ptr->method) break;
4773 /* Write the blows */
4774 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4775 r_info_blow_effect[b_ptr->effect],
4776 b_ptr->d_dice, b_ptr->d_side);
4778 for (fc = 0, j = 0; j < 32 * 3; j++)
4780 /* Check this flag */
4781 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4784 /* Extract the extra flags */
4785 for (j = 32 * 6; j < 32 * 10; j++)
4787 /* Check this flag */
4788 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4791 /* Write the flags */
4792 for (j = 0; j < fc;)
4796 /* Start the line */
4799 for (bc = 0; (bc < 60) && (j < fc); j++)
4803 /* Format the flag */
4804 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4806 /* Add it to the buffer */
4809 /* Note the length */
4813 /* Done with this line; write it */
4814 fprintf(fff, "%s\n", buf);
4817 /* Write Spells if applicable */
4818 if (r_ptr->freq_spell)
4820 /* Write the frequency */
4821 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4823 /* Extract the spell flags */
4824 for (fc = 0, j = 96; j < 192; j++)
4826 /* Check this flag */
4827 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4830 /* Write the flags */
4831 for (j = 0; j < fc;)
4835 /* Start the line */
4838 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4842 /* Format the flag */
4843 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4847 /* Note the length */
4854 /* Done with this line; write it */
4855 fprintf(fff, "%s\n", buf);
4859 /* Acquire the description */
4860 desc = r_text + r_ptr->text;
4861 dlen = strlen(desc);
4863 /* Write Description */
4864 for (j = 0; j < dlen;)
4868 /* Start the line */
4871 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4879 /* Done with this line; write it */
4880 fprintf(fff, "%s\n", buf);
4883 /* Space between entries */
4894 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4895 * Helper function for "process_dungeon_file()"
4903 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4909 bool bypass = FALSE;
4910 int x = xmin, y = ymin;
4913 /* Build the filename */
4914 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4917 fp = my_fopen(buf, "r");
4920 if (!fp) return (-1);
4923 /* Process the file */
4924 while (0 == my_fgets(fp, buf, sizeof(buf)))
4930 /* Skip "empty" lines */
4931 if (!buf[0]) continue;
4933 /* Skip "blank" lines */
4934 if (iswspace(buf[0])) continue;
4937 if (buf[0] == '#') continue;
4940 /* Process "?:<expr>" */
4941 if ((buf[0] == '?') && (buf[1] == ':'))
4950 /* Parse the expr */
4951 v = process_dungeon_file_expr(&s, &f);
4954 bypass = (streq(v, "0") ? TRUE : FALSE);
4958 /* Apply conditionals */
4959 if (bypass) continue;
4961 /* Process the line */
4962 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4973 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4975 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4976 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);