5 #include "dungeon-file.h"
11 #include "player-skill.h"
13 dungeon_grid letter[255];
17 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
21 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
22 * This software may be copied and distributed for educational, research,
23 * and not for profit purposes provided that this copyright and statement
24 * are included in all such copies. Other copyrights may also apply.
25 * 2014 Deskull rearranged comment for Doxygen.\n
29 * This file is used to initialize various variables and arrays for the
30 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
31 * the common limitation of "read()" and "write()" to only 32767 bytes
33 * Several of the arrays for Angband are built from "template" files in
34 * the "lib/file" directory, from which quick-load binary "image" files
35 * are constructed whenever they are not present in the "lib/data"
36 * directory, or if those files become obsolete, if we are allowed.
37 * Warning -- the "ascii" file parsers use a minor hack to collect the
38 * name and text information in a single pass. Thus, the game will not
39 * be able to load any template file with more than 20K of names or 60K
40 * of text, even though technically, up to 64K should be legal.
42 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
43 * in this file is compiled out, and the game will not run unless valid
44 * "binary template files" already exist in "lib/data". Thus, one can
45 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
46 * "*.raw" files in "lib/data", and then quit, and recompile without
47 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
48 * from changing the ascii template files in potentially dangerous ways.
49 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
50 * このファイルのコードの多くはコンパイル出力され、本ゲームは
51 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
52 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
53 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
54 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
55 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
56 * テンプレートファイルを変更することを妨げることができる。
57 * The code could actually be removed and placed into a "stand-alone"
58 * program, but that feels a little silly, especially considering some
59 * of the platforms that we currently support.
64 #include "dungeon-file.h"
69 #include "cmd-activate.h"
73 #include "view-mainwindow.h"
77 #ifdef ALLOW_TEMPLATES
82 /*** Helper arrays for parsing ascii template files ***/
86 * Monster Blow Methods
88 static concptr r_info_blow_method[] =
121 * モンスターの打撃属性トークンの定義 /
122 * Monster Blow Effects
124 static concptr r_info_blow_effect[] =
169 static concptr f_info_flags[] =
294 static concptr r_info_flags1[] =
334 static concptr r_info_flags2[] =
374 static concptr r_info_flags3[] =
414 static concptr r_info_flags4[] =
451 * モンスター特性トークン(発動型能力1) /
454 static concptr r_a_ability_flags1[] =
491 * モンスター特性トークン(発動型能力2) /
494 static concptr r_a_ability_flags2[] =
511 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
532 * モンスター特性トークン(発動型能力3) /
535 static concptr r_a_ability_flags3[] =
574 * モンスター特性トークン(発動型能力4) /
577 static concptr r_a_ability_flags4[] =
619 static concptr r_info_flags7[] =
659 static concptr r_info_flags8[] =
691 "WILD_SWAMP", /* ToDo: Implement Swamp */
700 static concptr r_info_flags9[] =
739 * モンスター特性トークンの定義R(耐性) /
742 static concptr r_info_flagsr[] =
780 * オブジェクト基本特性トークンの定義 /
783 static concptr k_info_flags[] =
880 "XXX3", /* Fake flag for Smith */
881 "XXX4", /* Fake flag for Smith */
931 * オブジェクト生成特性トークンの定義 /
934 static concptr k_info_gen_flags[] =
974 static concptr d_info_flags1[] =
1012 * @brief データの可変文字列情報をテキストとして保管する /
1013 * Add a text to the text-storage and store offset to it.
1014 * @param offset 文字列保管ポインタからのオフセット
1015 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1017 * @param normal_text テキストの正規化を行う
1020 * Returns FALSE when there isn't enough space available to store
1023 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1025 /* Hack -- Verify space */
1026 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1032 /* Advance and save the text index */
1033 *offset = ++head->text_size;
1036 /* Additional text */
1037 else if (normal_text)
1040 * If neither the end of the last line nor
1041 * the beginning of current line is not a space,
1042 * fill up a space as a correct separator of two words.
1044 if (head->text_size > 0 &&
1046 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1047 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1048 (buf[0] != ' ') && !iskanji(buf[0])
1050 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1055 /* Append a space */
1056 *(head->text_ptr + head->text_size) = ' ';
1058 /* Advance the index */
1063 /* Append chars to the text */
1064 strcpy(head->text_ptr + head->text_size, buf);
1066 /* Advance the index */
1067 head->text_size += strlen(buf);
1075 * @brief データの可変文字列情報を名前として保管する /
1076 * Add a name to the name-storage and return an offset to it.
1077 * @param offset 文字列保管ポインタからのオフセット
1078 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1082 * Returns FALSE when there isn't enough space available to store
1085 static bool add_name(u32b *offset, header *head, concptr buf)
1087 /* Hack -- Verify space */
1088 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1094 /* Advance and save the name index */
1095 *offset = ++head->name_size;
1098 /* Append chars to the names */
1099 strcpy(head->name_ptr + head->name_size, buf);
1101 /* Advance the index */
1102 head->name_size += strlen(buf);
1110 * @brief データの可変文字列情報をタグとして保管する /
1111 * Add a tag to the tag-storage and return an offset to it.
1112 * @param offset 文字列保管ポインタからのオフセット
1113 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1117 * Returns FALSE when there isn't enough space available to store
1120 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1124 /* Search for an existing (fake) tag */
1125 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1128 if (streq(&head->tag_ptr[i], buf)) break;
1131 /* There was no existing tag */
1132 if (i >= head->tag_size)
1134 /* Hack -- Verify space */
1135 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1138 /* Append chars to the tags */
1139 strcpy(head->tag_ptr + head->tag_size, buf);
1141 /* Point the new tag */
1144 /* Advance the index */
1145 head->tag_size += strlen(buf) + 1;
1148 /* Return offset of the tag */
1156 /*** Initialize from ascii template files ***/
1160 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1161 * Initialize an "*_info" array, by parsing an ascii "template" file
1162 * @param fp 読み取りに使うファイルポインタ
1163 * @param buf 読み取りに使うバッファ領域
1164 * @param head ヘッダ構造体
1165 * @param parse_info_txt_line パース関数
1168 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1172 /* Just before the first record */
1175 /* Just before the first line */
1179 /* Prepare the "fake" stuff */
1180 head->name_size = 0;
1181 head->text_size = 0;
1185 while (0 == my_fgets(fp, buf, 1024))
1187 /* Advance the line number */
1190 /* Skip comments and blank lines */
1191 if (!buf[0] || (buf[0] == '#')) continue;
1193 /* Verify correct "colon" format */
1194 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1197 /* Hack -- Process 'V' for "Version" */
1204 /* Mega Hack -- Calculate Check Sum */
1205 if (buf[0] != 'N' && buf[0] != 'D')
1208 for (i = 0; buf[i]; i++)
1210 head->v_extra += (byte)buf[i];
1211 head->v_extra ^= (1 << (i % 8));
1215 /* Parse the line */
1216 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1221 /* Complete the "name" and "text" sizes */
1222 if (head->name_size) head->name_size++;
1223 if (head->text_size) head->text_size++;
1231 * @brief Vault情報(v_info)のパース関数 /
1232 * Initialize the "v_info" array, by parsing an ascii "template" file
1234 * @param head ヘッダ構造体
1237 errr parse_v_info(char *buf, header *head)
1243 static vault_type *v_ptr = NULL;
1245 /* Process 'N' for "New/Number/Name" */
1248 /* Find the colon before the name */
1249 s = my_strchr(buf + 2, ':');
1251 /* Verify that colon */
1254 /* Nuke the colon, advance to the name */
1257 /* Paranoia -- require a name */
1258 if (!*s) return (1);
1263 /* Verify information */
1264 if (i <= error_idx) return (4);
1266 /* Verify information */
1267 if (i >= head->info_num) return (2);
1269 /* Save the index */
1272 /* Point at the "info" */
1275 /* Store the name */
1276 if (!add_name(&v_ptr->name, head, s)) return (7);
1279 /* There better be a current v_ptr */
1280 else if (!v_ptr) return (3);
1282 /* Process 'D' for "Description" */
1283 else if (buf[0] == 'D')
1285 /* Acquire the text */
1288 /* Store the text */
1289 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1292 /* Process 'X' for "Extra info" (one line only) */
1293 else if (buf[0] == 'X')
1295 EFFECT_ID typ, rat, hgt, wid;
1297 /* Scan for the values */
1298 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1299 &typ, &rat, &hgt, &wid)) return (1);
1301 /* Save the values */
1302 v_ptr->typ = (ROOM_IDX)typ;
1303 v_ptr->rat = (PROB)rat;
1304 v_ptr->hgt = (POSITION)hgt;
1305 v_ptr->wid = (POSITION)wid;
1316 * @brief 職業技能情報(s_info)のパース関数 /
1317 * Initialize the "s_info" array, by parsing an ascii "template" file
1319 * @param head ヘッダ構造体
1322 errr parse_s_info(char *buf, header *head)
1327 static skill_table *s_ptr = NULL;
1330 /* Process 'N' for "New/Number/Name" */
1336 /* Verify information */
1337 if (i <= error_idx) return (4);
1339 /* Verify information */
1340 if (i >= head->info_num) return (2);
1342 /* Save the index */
1345 /* Point at the "info" */
1349 /* There better be a current s_ptr */
1350 else if (!s_ptr) return (3);
1352 /* Process 'W' for "Weapon exp" */
1353 else if (buf[0] == 'W')
1355 int tval, sval, start, max;
1356 const s16b exp_conv_table[] =
1358 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1359 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1362 /* Scan for the values */
1363 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1364 &tval, &sval, &start, &max)) return (1);
1366 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1367 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1369 /* Save the values */
1370 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1371 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1374 /* Process 'S' for "Skill exp" */
1375 else if (buf[0] == 'S')
1377 int num, start, max;
1379 /* Scan for the values */
1380 if (3 != sscanf(buf + 2, "%d:%d:%d",
1381 &num, &start, &max)) return (1);
1383 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1384 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1386 /* Save the values */
1387 s_ptr->s_start[num] = (SUB_EXP)start;
1388 s_ptr->s_max[num] = (SUB_EXP)max;
1400 * @brief 職業魔法情報(m_info)のパース関数 /
1401 * Initialize the "m_info" array, by parsing an ascii "template" file
1403 * @param head ヘッダ構造体
1406 errr parse_m_info(char *buf, header *head)
1413 static player_magic *m_ptr = NULL;
1416 static int realm, magic_idx = 0, readable = 0;
1419 /* Process 'N' for "New/Number/Name" */
1425 /* Verify information */
1426 if (i <= error_idx) return (4);
1428 /* Verify information */
1429 if (i >= head->info_num) return (2);
1431 /* Save the index */
1434 /* Point at the "info" */
1438 /* There better be a current m_ptr */
1439 else if (!m_ptr) return (3);
1441 /* Process 'I' for "Info" (one line only) */
1442 else if (buf[0] == 'I')
1445 int xtra, type, first, weight;
1447 /* Find the colon before the name */
1448 s = my_strchr(buf + 2, ':');
1450 /* Verify that colon */
1453 /* Nuke the colon, advance to the name */
1458 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1459 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1460 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1461 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1462 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1467 /* Find the colon before the name */
1468 s = my_strchr(s, ':');
1470 /* Verify that colon */
1473 /* Nuke the colon, advance to the name */
1476 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1477 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1478 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1479 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1480 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1481 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1485 /* Scan for the values */
1486 if (4 != sscanf(s, "%x:%d:%d:%d",
1487 (uint *)&xtra, &type, &first, &weight)) return (1);
1489 m_ptr->spell_xtra = xtra;
1490 m_ptr->spell_type = type;
1491 m_ptr->spell_first = first;
1492 m_ptr->spell_weight = weight;
1496 /* Process 'R' for "Realm" (one line only) */
1497 else if (buf[0] == 'R')
1499 /* Scan for the values */
1500 if (2 != sscanf(buf + 2, "%d:%d",
1501 &realm, &readable)) return (1);
1506 else if (buf[0] == 'T')
1508 int level, mana, fail, exp;
1510 if (!readable) return (1);
1511 /* Scan for the values */
1512 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1513 &level, &mana, &fail, &exp)) return (1);
1515 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1516 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1517 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1518 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1531 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1532 * Grab one flag from a textual string
1533 * @param flags ビットフラグを追加する先の参照ポインタ
1534 * @param names トークン定義配列
1535 * @param what 参照元の文字列ポインタ
1538 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1543 for (i = 0; i < 32; i++)
1545 if (streq(what, names[i]))
1547 *flags |= (1L << i);
1557 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1558 * Grab one flag in an feature_type from a textual string
1559 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1560 * @param what 参照元の文字列ポインタ
1563 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1568 for (i = 0; i < FF_FLAG_MAX; i++)
1570 if (streq(what, f_info_flags[i]))
1572 add_flag(f_ptr->flags, i);
1577 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1580 return PARSE_ERROR_GENERIC;
1585 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1586 * Grab an action in an feature_type from a textual string
1587 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1588 * @param what 参照元の文字列ポインタ
1589 * @param count ステートの保存先ID
1592 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1597 for (i = 0; i < FF_FLAG_MAX; i++)
1599 if (streq(what, f_info_flags[i]))
1601 f_ptr->state[count].action = i;
1606 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1609 return PARSE_ERROR_GENERIC;
1614 * @brief 地形情報(f_info)のパース関数 /
1615 * Initialize the "f_info" array, by parsing an ascii "template" file
1617 * @param head ヘッダ構造体
1620 errr parse_f_info(char *buf, header *head)
1627 static feature_type *f_ptr = NULL;
1630 /* Process 'N' for "New/Number/Name" */
1633 /* Find the colon before the name */
1634 s = my_strchr(buf + 2, ':');
1638 /* Nuke the colon, advance to the name */
1645 /* Verify information */
1646 if (i <= error_idx) return (4);
1648 /* Verify information */
1649 if (i >= head->info_num) return (2);
1651 /* Save the index */
1654 /* Point at the "info" */
1657 /* Tag name is given */
1661 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1664 /* Default "mimic" */
1665 f_ptr->mimic = (FEAT_IDX)i;
1667 /* Default "destroyed state" -- if not specified */
1668 f_ptr->destroyed = (FEAT_IDX)i;
1670 /* Default "states" */
1671 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1674 /* There better be a current f_ptr */
1675 else if (!f_ptr) return (3);
1678 else if (buf[0] == 'J')
1680 /* Store the name */
1681 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1684 else if (buf[0] == 'E')
1686 /* Ignore english name */
1689 else if (buf[0] == 'J')
1691 /* Ignore Japanese name */
1694 else if (buf[0] == 'E')
1696 /* Acquire the Text */
1699 /* Store the name */
1700 if (!add_name(&f_ptr->name, head, s)) return (7);
1705 /* Process 'M' for "Mimic" (one line only) */
1706 else if (buf[0] == 'M')
1710 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1712 /* Record a fake tag index */
1713 f_ptr->mimic_tag = offset;
1717 /* Process 'G' for "Graphics" (one line only) */
1718 else if (buf[0] == 'G')
1722 char char_tmp[F_LIT_MAX];
1723 if (buf[1] != ':') return (1);
1724 if (!buf[2]) return (1);
1725 if (buf[3] != ':') return (1);
1726 if (!buf[4]) return (1);
1728 /* Extract the char */
1729 char_tmp[F_LIT_STANDARD] = buf[2];
1731 /* Extract the color */
1732 s_attr = color_char_to_attr(buf[4]);
1733 if (s_attr > 127) return (1);
1735 /* Save the standard values */
1736 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1737 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1739 /* Is this feature supports lighting? */
1742 /* G:c:a:LIT (default) */
1743 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1745 /* G:c:a:lc:la:dc:da */
1746 if (!streq(buf + 6, "LIT"))
1748 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1750 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1751 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1752 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1753 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1755 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1757 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1760 /* Use default lighting */
1763 /* No lighting support */
1764 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1767 /* Extract the color */
1768 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1769 if (f_ptr->d_attr[j] > 127) return 1;
1772 f_ptr->d_char[j] = char_tmp[j];
1778 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1780 f_ptr->d_attr[j] = s_attr;
1781 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1787 /* Hack -- Process 'F' for flags */
1788 else if (buf[0] == 'F')
1790 /* Parse every entry textually */
1791 for (s = buf + 2; *s; )
1793 /* Find the end of this entry */
1794 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1796 /* Nuke and skip any dividers */
1800 while (*t == ' ' || *t == '|') t++;
1803 /* Hack -- Read feature subtype */
1804 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1806 /* Extract a "subtype" */
1807 f_ptr->subtype = (FEAT_SUBTYPE)i;
1809 /* Start at next entry */
1815 /* Hack -- Read feature power */
1816 if (1 == sscanf(s, "POWER_%d", &i))
1818 /* Extract a "power" */
1819 f_ptr->power = (FEAT_POWER)i;
1821 /* Start at next entry */
1826 /* Parse this entry */
1827 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1829 /* Start the next entry */
1834 /* Process 'W' for "More Info" (one line only) */
1835 else if (buf[0] == 'W')
1839 /* Scan for the value */
1840 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1842 /* Save the value */
1843 f_ptr->priority = (FEAT_PRIORITY)priority;
1846 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1847 else if (buf[0] == 'K')
1851 /* Find the next empty state slot (if any) */
1852 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1854 /* Oops, no more slots */
1855 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1857 /* Analyze the first field */
1858 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1860 /* Terminate the field (if necessary) */
1861 if (*t == ':') *t++ = '\0';
1863 /* Is this default entry? */
1864 if (streq(s, "DESTROYED"))
1866 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1868 /* Record a fake tag index */
1869 f_ptr->destroyed_tag = offset;
1874 f_ptr->state[i].action = 0;
1876 /* Parse this entry */
1877 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1879 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1881 /* Record a fake tag index */
1882 f_ptr->state[i].result_tag = offset;
1894 * @brief 地形タグからIDを得る /
1895 * Convert a fake tag to a real feat index
1899 s16b f_tag_to_index(concptr str)
1903 /* Search for real index corresponding to this fake tag */
1904 for (i = 0; i < f_head.info_num; i++)
1906 if (streq(f_tag + f_info[i].tag, str))
1908 /* Return the index */
1919 * @brief 地形タグからIDを得る /
1920 * Search for real index corresponding to this fake tag
1921 * @param feat タグ文字列のオフセット
1922 * @return 地形ID。該当がないなら-1
1924 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1928 /* Don't convert non-fake tag */
1934 /* Search for real index corresponding to this fake tag */
1935 for (i = 0; i < f_head.info_num; i++)
1937 if (feat == f_info[i].tag)
1939 /* Record real index */
1945 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1951 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1952 * Retouch fake tags of f_info
1953 * @param head ヘッダ構造体
1956 void retouch_f_info(header *head)
1960 /* Convert fake tags to real feat indices */
1961 for (i = 0; i < head->info_num; i++)
1963 feature_type *f_ptr = &f_info[i];
1966 k = search_real_feat(f_ptr->mimic_tag);
1967 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1968 k = search_real_feat(f_ptr->destroyed_tag);
1969 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1970 for (j = 0; j < MAX_FEAT_STATES; j++)
1972 k = search_real_feat(f_ptr->state[j].result_tag);
1973 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1980 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1981 * Grab one flag in an object_kind from a textual string
1982 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1983 * @param what 参照元の文字列ポインタ
1986 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1991 for (i = 0; i < TR_FLAG_MAX; i++)
1993 if (streq(what, k_info_flags[i]))
1995 add_flag(k_ptr->flags, i);
2000 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2003 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2010 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2011 * Grab one activation index flag
2012 * @param what 参照元の文字列ポインタ
2015 static byte grab_one_activation_flag(concptr what)
2021 if (activation_info[i].flag == NULL) break;
2023 if (streq(what, activation_info[i].flag))
2025 return activation_info[i].index;
2035 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2043 * @brief ベースアイテム(k_info)のパース関数 /
2044 * Initialize the "k_info" array, by parsing an ascii "template" file
2046 * @param head ヘッダ構造体
2049 errr parse_k_info(char *buf, header *head)
2056 static object_kind *k_ptr = NULL;
2059 /* Process 'N' for "New/Number/Name" */
2066 /* Find the colon before the name */
2067 s = my_strchr(buf + 2, ':');
2069 /* Verify that colon */
2072 /* Nuke the colon, advance to the name */
2078 /* Verify information */
2079 if (i <= error_idx) return (4);
2081 /* Verify information */
2082 if (i >= head->info_num) return (2);
2084 /* Save the index */
2087 /* Point at the "info" */
2091 /* Paranoia -- require a name */
2092 if (!*s) return (1);
2094 /* Find the colon before the flavor */
2095 flavor = my_strchr(s, ':');
2097 /* Verify that colon */
2100 /* Nuke the colon, advance to the flavor */
2103 /* Store the flavor */
2104 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2107 /* Store the name */
2108 if (!add_name(&k_ptr->name, head, s)) return (7);
2112 /* There better be a current k_ptr */
2113 else if (!k_ptr) return (3);
2118 /* 'E' から始まる行は英語名としている */
2119 else if (buf[0] == 'E')
2124 else if (buf[0] == 'E')
2128 /* Acquire the name */
2131 /* Find the colon before the flavor */
2132 flavor = my_strchr(s, ':');
2134 /* Verify that colon */
2137 /* Nuke the colon, advance to the flavor */
2140 /* Store the flavor */
2141 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2144 /* Store the name */
2145 if (!add_name(&k_ptr->name, head, s)) return (7);
2149 /* Process 'D' for "Description" */
2150 else if (buf[0] == 'D')
2155 /* Acquire the text */
2160 /* Acquire the text */
2164 /* Store the text */
2165 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2168 /* Process 'G' for "Graphics" (one line only) */
2169 else if (buf[0] == 'G')
2173 if (buf[1] != ':') return (1);
2174 if (!buf[2]) return (1);
2175 if (buf[3] != ':') return (1);
2176 if (!buf[4]) return (1);
2178 /* Extract the char */
2181 /* Extract the attr */
2182 tmp = color_char_to_attr(buf[4]);
2183 if (tmp > 127) return (1);
2185 /* Save the values */
2186 k_ptr->d_attr = tmp;
2187 k_ptr->d_char = sym;
2190 /* Process 'I' for "Info" (one line only) */
2191 else if (buf[0] == 'I')
2193 int tval, sval, pval;
2195 /* Scan for the values */
2196 if (3 != sscanf(buf + 2, "%d:%d:%d",
2197 &tval, &sval, &pval)) return (1);
2199 /* Save the values */
2200 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2201 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2202 k_ptr->pval = (PARAMETER_VALUE)pval;
2205 /* Process 'W' for "More Info" (one line only) */
2206 else if (buf[0] == 'W')
2208 int level, extra, wgt;
2211 /* Scan for the values */
2212 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2213 &level, &extra, &wgt, &cost)) return (1);
2215 /* Save the values */
2216 k_ptr->level = (DEPTH)level;
2217 k_ptr->extra = (BIT_FLAGS8)extra;
2218 k_ptr->weight = (WEIGHT)wgt;
2219 k_ptr->cost = (PRICE)cost;
2222 /* Process 'A' for "Allocation" (one line only) */
2223 else if (buf[0] == 'A')
2226 /* Simply read each number following a colon */
2227 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2229 /* Default chance */
2230 k_ptr->chance[i] = 1;
2232 /* Store the attack damage index */
2233 k_ptr->locale[i] = atoi(s + 1);
2235 /* Find the slash */
2236 t = my_strchr(s + 1, '/');
2238 /* Find the next colon */
2239 s = my_strchr(s + 1, ':');
2241 /* If the slash is "nearby", use it */
2242 if (t && (!s || t < s))
2244 int chance = atoi(t + 1);
2245 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2250 /* Hack -- Process 'P' for "power" and such */
2251 else if (buf[0] == 'P')
2253 int ac, hd1, hd2, th, td, ta;
2255 /* Scan for the values */
2256 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2257 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2259 k_ptr->ac = (ARMOUR_CLASS)ac;
2260 k_ptr->dd = (DICE_NUMBER)hd1;
2261 k_ptr->ds = (DICE_SID)hd2;
2262 k_ptr->to_h = (HIT_PROB)th;
2263 k_ptr->to_d = (HIT_POINT)td;
2264 k_ptr->to_a = (ARMOUR_CLASS)ta;
2267 /* Hack -- Process 'U' for activation index */
2268 else if (buf[0] == 'U')
2271 n = grab_one_activation_flag(buf + 2);
2282 /* Hack -- Process 'F' for flags */
2283 else if (buf[0] == 'F')
2285 /* Parse every entry textually */
2286 for (s = buf + 2; *s; )
2288 /* Find the end of this entry */
2289 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2291 /* Nuke and skip any dividers */
2295 while (*t == ' ' || *t == '|') t++;
2298 /* Parse this entry */
2299 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2301 /* Start the next entry */
2315 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2316 * Grab one activation index flag
2317 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2318 * @param what 参照元の文字列ポインタ
2319 * @return エラーがあった場合1、エラーがない場合0を返す
2321 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2326 for (i = 0; i < TR_FLAG_MAX; i++)
2328 if (streq(what, k_info_flags[i]))
2330 add_flag(a_ptr->flags, i);
2335 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2338 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2346 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2347 * Initialize the "a_info" array, by parsing an ascii "template" file
2349 * @param head ヘッダ構造体
2352 errr parse_a_info(char *buf, header *head)
2359 static artifact_type *a_ptr = NULL;
2362 /* Process 'N' for "New/Number/Name" */
2365 /* Find the colon before the name */
2366 s = my_strchr(buf + 2, ':');
2368 /* Verify that colon */
2371 /* Nuke the colon, advance to the name */
2374 /* Paranoia -- require a name */
2375 if (!*s) return (1);
2380 /* Verify information */
2381 if (i < error_idx) return (4);
2383 /* Verify information */
2384 if (i >= head->info_num) return (2);
2386 /* Save the index */
2389 /* Point at the "info" */
2392 /* Ignore everything */
2393 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2394 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2395 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2396 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2398 /* Store the name */
2399 if (!add_name(&a_ptr->name, head, s)) return (7);
2403 /* There better be a current a_ptr */
2404 else if (!a_ptr) return (3);
2409 /* 'E' から始まる行は英語名としている */
2410 else if (buf[0] == 'E')
2415 else if (buf[0] == 'E')
2417 /* Acquire the Text */
2420 /* Store the name */
2421 if (!add_name(&a_ptr->name, head, s)) return (7);
2425 /* Process 'D' for "Description" */
2426 else if (buf[0] == 'D')
2431 /* Acquire the text */
2436 /* Acquire the text */
2440 /* Store the text */
2441 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2445 /* Process 'I' for "Info" (one line only) */
2446 else if (buf[0] == 'I')
2448 int tval, sval, pval;
2450 /* Scan for the values */
2451 if (3 != sscanf(buf + 2, "%d:%d:%d",
2452 &tval, &sval, &pval)) return (1);
2454 /* Save the values */
2455 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2456 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2457 a_ptr->pval = (PARAMETER_VALUE)pval;
2460 /* Process 'W' for "More Info" (one line only) */
2461 else if (buf[0] == 'W')
2463 int level, rarity, wgt;
2466 /* Scan for the values */
2467 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2468 &level, &rarity, &wgt, &cost)) return (1);
2470 /* Save the values */
2471 a_ptr->level = (DEPTH)level;
2472 a_ptr->rarity = (RARITY)rarity;
2473 a_ptr->weight = (WEIGHT)wgt;
2474 a_ptr->cost = (PRICE)cost;
2477 /* Hack -- Process 'P' for "power" and such */
2478 else if (buf[0] == 'P')
2480 int ac, hd1, hd2, th, td, ta;
2482 /* Scan for the values */
2483 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2484 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2486 a_ptr->ac = (ARMOUR_CLASS)ac;
2487 a_ptr->dd = (DICE_NUMBER)hd1;
2488 a_ptr->ds = (DICE_SID)hd2;
2489 a_ptr->to_h = (HIT_PROB)th;
2490 a_ptr->to_d = (HIT_POINT)td;
2491 a_ptr->to_a = (ARMOUR_CLASS)ta;
2494 /* Hack -- Process 'U' for activation index */
2495 else if (buf[0] == 'U')
2498 n = grab_one_activation_flag(buf + 2);
2509 /* Hack -- Process 'F' for flags */
2510 else if (buf[0] == 'F')
2512 /* Parse every entry textually */
2513 for (s = buf + 2; *s; )
2515 /* Find the end of this entry */
2516 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2518 /* Nuke and skip any dividers */
2522 while ((*t == ' ') || (*t == '|')) t++;
2525 /* Parse this entry */
2526 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2528 /* Start the next entry */
2543 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2544 * Grab one flag in a ego-item_type from a textual string
2545 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2546 * @param what 参照元の文字列ポインタ
2547 * @return エラーがあった場合1、エラーがない場合0を返す
2549 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2554 for (i = 0; i < TR_FLAG_MAX; i++)
2556 if (streq(what, k_info_flags[i]))
2558 add_flag(e_ptr->flags, i);
2563 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2566 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2574 * @brief アイテムエゴ情報(e_info)のパース関数 /
2575 * Initialize the "e_info" array, by parsing an ascii "template" file
2577 * @param head ヘッダ構造体
2580 errr parse_e_info(char *buf, header *head)
2586 static ego_item_type *e_ptr = NULL;
2588 /* Just before the first record */
2591 /* Just before the first line */
2594 /* Process 'N' for "New/Number/Name" */
2597 /* Find the colon before the name */
2598 s = my_strchr(buf + 2, ':');
2600 /* Verify that colon */
2603 /* Nuke the colon, advance to the name */
2606 /* Paranoia -- require a name */
2607 if (!*s) return (1);
2612 /* Verify information */
2613 if (i < error_idx) return (4);
2615 /* Verify information */
2616 if (i >= head->info_num) return (2);
2618 /* Save the index */
2621 /* Point at the "info" */
2624 /* Store the name */
2625 if (!add_name(&e_ptr->name, head, s)) return (7);
2629 /* There better be a current e_ptr */
2630 else if (!e_ptr) return (3);
2635 /* 'E' から始まる行は英語名 */
2636 else if (buf[0] == 'E')
2641 else if (buf[0] == 'E')
2643 /* Acquire the Text */
2646 /* Store the name */
2647 if (!add_name(&e_ptr->name, head, s)) return (7);
2652 /* Process 'D' for "Description" */
2653 else if (buf[0] == 'D')
2655 /* Acquire the text */
2658 /* Store the text */
2659 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2664 /* Process 'X' for "Xtra" (one line only) */
2665 else if (buf[0] == 'X')
2669 /* Scan for the values */
2670 if (2 != sscanf(buf + 2, "%d:%d",
2671 &slot, &rating)) return (1);
2673 /* Save the values */
2674 e_ptr->slot = (INVENTORY_IDX)slot;
2675 e_ptr->rating = (PRICE)rating;
2678 /* Process 'W' for "More Info" (one line only) */
2679 else if (buf[0] == 'W')
2681 int level, rarity, pad2;
2684 /* Scan for the values */
2685 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2686 &level, &rarity, &pad2, &cost)) return (1);
2688 /* Save the values */
2689 e_ptr->level = level;
2690 e_ptr->rarity = (RARITY)rarity;
2691 /* e_ptr->weight = wgt; */
2695 /* Hack -- Process 'C' for "creation" */
2696 else if (buf[0] == 'C')
2698 int th, td, ta, pval;
2700 /* Scan for the values */
2701 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2702 &th, &td, &ta, &pval)) return (1);
2704 e_ptr->max_to_h = (HIT_PROB)th;
2705 e_ptr->max_to_d = (HIT_POINT)td;
2706 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2707 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2710 /* Hack -- Process 'U' for activation index */
2711 else if (buf[0] == 'U')
2714 n = grab_one_activation_flag(buf + 2);
2725 /* Hack -- Process 'F' for flags */
2726 else if (buf[0] == 'F')
2728 /* Parse every entry textually */
2729 for (s = buf + 2; *s; )
2731 /* Find the end of this entry */
2732 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2734 /* Nuke and skip any dividers */
2738 while ((*t == ' ') || (*t == '|')) t++;
2741 /* Parse this entry */
2742 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2744 /* Start the next entry */
2757 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2758 * Grab one (basic) flag in a monster_race from a textual string
2759 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2760 * @param what 参照元の文字列ポインタ
2763 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2765 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2768 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2771 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2774 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2777 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2780 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2783 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2786 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2794 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2795 * Grab one (spell) flag in a monster_race from a textual string
2796 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2797 * @param what 参照元の文字列ポインタ
2800 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2802 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2805 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2808 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2811 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2819 * @brief モンスター種族情報(r_info)のパース関数 /
2820 * Initialize the "r_info" array, by parsing an ascii "template" file
2822 * @param head ヘッダ構造体
2825 errr parse_r_info(char *buf, header *head)
2831 static monster_race *r_ptr = NULL;
2834 /* Process 'N' for "New/Number/Name" */
2837 /* Find the colon before the name */
2838 s = my_strchr(buf + 2, ':');
2840 /* Verify that colon */
2843 /* Nuke the colon, advance to the name */
2846 /* Paranoia -- require a name */
2847 if (!*s) return (1);
2852 /* Verify information */
2853 if (i < error_idx) return (4);
2855 /* Verify information */
2856 if (i >= head->info_num) return (2);
2858 /* Save the index */
2861 /* Point at the "info" */
2864 /* Store the name */
2865 if (!add_name(&r_ptr->name, head, s)) return (7);
2869 /* There better be a current r_ptr */
2870 else if (!r_ptr) return (3);
2875 /* 'E' から始まる行は英語名 */
2876 else if (buf[0] == 'E')
2878 /* Acquire the Text */
2881 /* Store the name */
2882 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2885 else if (buf[0] == 'E')
2887 /* Acquire the Text */
2890 /* Store the name */
2891 if (!add_name(&r_ptr->name, head, s)) return (7);
2894 /* Process 'D' for "Description" */
2895 else if (buf[0] == 'D')
2900 /* Acquire the text */
2905 /* Acquire the text */
2909 /* Store the text */
2910 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2913 /* Process 'G' for "Graphics" (one line only) */
2914 else if (buf[0] == 'G')
2918 if (buf[1] != ':') return (1);
2919 if (!buf[2]) return (1);
2920 if (buf[3] != ':') return (1);
2921 if (!buf[4]) return (1);
2923 /* Extract the char */
2926 /* Extract the attr */
2927 tmp = color_char_to_attr(buf[4]);
2928 if (tmp > 127) return (1);
2930 /* Save the values */
2931 r_ptr->d_char = sym;
2932 r_ptr->d_attr = tmp;
2935 /* Process 'I' for "Info" (one line only) */
2936 else if (buf[0] == 'I')
2938 int spd, hp1, hp2, aaf, ac, slp;
2940 /* Scan for the other values */
2941 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2942 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2944 /* Save the values */
2945 r_ptr->speed = (SPEED)spd;
2946 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2947 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2948 r_ptr->aaf = (POSITION)aaf;
2949 r_ptr->ac = (ARMOUR_CLASS)ac;
2950 r_ptr->sleep = (SLEEP_DEGREE)slp;
2953 /* Process 'W' for "More Info" (one line only) */
2954 else if (buf[0] == 'W')
2961 /* Scan for the values */
2962 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2963 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2965 /* Save the values */
2966 r_ptr->level = (DEPTH)lev;
2967 r_ptr->rarity = (RARITY)rar;
2968 r_ptr->extra = (BIT_FLAGS16)pad;
2969 r_ptr->mexp = (EXP)exp;
2970 r_ptr->next_exp = (EXP)nextexp;
2971 r_ptr->next_r_idx = (IDX)nextmon;
2974 /* Process 'R' for "Reinforcement" (up to six lines) */
2975 else if (buf[0] == 'R')
2978 /* Find the next empty blow slot (if any) */
2979 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2981 /* Oops, no more slots */
2982 if (i == 6) return (1);
2984 /* Scan for the values */
2985 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2986 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2987 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2988 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2991 /* Process 'B' for "Blows" (up to four lines) */
2992 else if (buf[0] == 'B')
2996 /* Find the next empty blow slot (if any) */
2997 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2999 /* Oops, no more slots */
3000 if (i == 4) return (1);
3002 /* Analyze the first field */
3003 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3005 /* Terminate the field (if necessary) */
3006 if (*t == ':') *t++ = '\0';
3008 /* Analyze the method */
3009 for (n1 = 0; r_info_blow_method[n1]; n1++)
3011 if (streq(s, r_info_blow_method[n1])) break;
3014 /* Invalid method */
3015 if (!r_info_blow_method[n1]) return (1);
3017 /* Analyze the second field */
3018 for (s = t; *t && (*t != ':'); t++) /* loop */;
3020 /* Terminate the field (if necessary) */
3021 if (*t == ':') *t++ = '\0';
3023 /* Analyze effect */
3024 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3026 if (streq(s, r_info_blow_effect[n2])) break;
3029 /* Invalid effect */
3030 if (!r_info_blow_effect[n2]) return (1);
3032 /* Analyze the third field */
3033 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3035 /* Terminate the field (if necessary) */
3036 if (*t == 'd') *t++ = '\0';
3038 /* Save the method */
3039 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3041 /* Save the effect */
3042 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3044 /* Extract the damage dice and sides */
3045 r_ptr->blow[i].d_dice = atoi(s);
3046 r_ptr->blow[i].d_side = atoi(t);
3049 /* Process 'F' for "Basic Flags" (multiple lines) */
3050 else if (buf[0] == 'F')
3052 /* Parse every entry */
3053 for (s = buf + 2; *s; )
3055 /* Find the end of this entry */
3056 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3058 /* Nuke and skip any dividers */
3062 while (*t == ' ' || *t == '|') t++;
3065 /* Parse this entry */
3066 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3068 /* Start the next entry */
3073 /* Process 'S' for "Spell Flags" (multiple lines) */
3074 else if (buf[0] == 'S')
3076 /* Parse every entry */
3077 for (s = buf + 2; *s; )
3079 /* Find the end of this entry */
3080 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3082 /* Nuke and skip any dividers */
3086 while ((*t == ' ') || (*t == '|')) t++;
3089 /* Hack -- Read spell frequency */
3090 if (1 == sscanf(s, "1_IN_%d", &i))
3092 /* Extract a "frequency" */
3093 r_ptr->freq_spell = 100 / i;
3095 /* Start at next entry */
3100 /* Parse this entry */
3101 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3103 /* Start the next entry */
3108 /* Process 'A' for "Artifact Flags" (multiple lines) */
3109 else if (buf[0] == 'A')
3111 int id, per, rarity;
3113 /* Find the next empty blow slot (if any) */
3114 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3116 /* Oops, no more slots */
3117 if (i == 4) return (1);
3119 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3120 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3121 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3122 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3125 /* Process 'V' for "Arena power value ratio" */
3126 else if (buf[0] == 'V')
3129 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3130 r_ptr->arena_ratio = (PERCENTAGE)val;
3142 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3143 * Grab one flag for a dungeon type from a textual string
3144 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3145 * @param what 参照元の文字列ポインタ
3148 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3150 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3153 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3160 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3161 * Grab one (basic) flag in a monster_race from a textual string
3162 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3163 * @param what 参照元の文字列ポインタ
3166 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3168 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3171 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3174 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3177 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3180 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3183 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3186 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3189 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3196 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3197 * Grab one (spell) flag in a monster_race from a textual string
3198 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3199 * @param what 参照元の文字列ポインタ
3202 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3204 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3207 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3210 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3213 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3220 * @brief ダンジョン情報(d_info)のパース関数 /
3221 * Initialize the "d_info" array, by parsing an ascii "template" file
3223 * @param head ヘッダ構造体
3226 errr parse_d_info(char *buf, header *head)
3232 static dungeon_type *d_ptr = NULL;
3234 /* Process 'N' for "New/Number/Name" */
3237 /* Find the colon before the name */
3238 s = my_strchr(buf + 2, ':');
3240 /* Verify that colon */
3243 /* Nuke the colon, advance to the name */
3246 /* Paranoia -- require a name */
3247 if (!*s) return (1);
3252 /* Verify information */
3253 if (i < error_idx) return (4);
3255 /* Verify information */
3256 if (i >= head->info_num) return (2);
3258 /* Save the index */
3261 /* Point at the "info" */
3264 /* Store the name */
3265 if (!add_name(&d_ptr->name, head, s)) return (7);
3270 else if (buf[0] == 'E') return (0);
3272 else if (buf[0] == 'E')
3274 /* Acquire the Text */
3277 /* Store the name */
3278 if (!add_name(&d_ptr->name, head, s)) return (7);
3282 /* Process 'D' for "Description */
3283 else if (buf[0] == 'D')
3288 /* Acquire the text */
3293 /* Acquire the text */
3297 /* Store the text */
3298 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3301 /* Process 'W' for "More Info" (one line only) */
3302 else if (buf[0] == 'W')
3304 int min_lev, max_lev;
3306 int min_alloc, max_chance;
3307 int obj_good, obj_great;
3310 /* Scan for the values */
3311 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3312 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3314 /* Save the values */
3315 d_ptr->mindepth = (DEPTH)min_lev;
3316 d_ptr->maxdepth = (DEPTH)max_lev;
3317 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3318 d_ptr->mode = (BIT_FLAGS8)mode;
3319 d_ptr->min_m_alloc_level = min_alloc;
3320 d_ptr->max_m_alloc_chance = max_chance;
3321 d_ptr->obj_good = obj_good;
3322 d_ptr->obj_great = obj_great;
3323 d_ptr->pit = (BIT_FLAGS16)pit;
3324 d_ptr->nest = (BIT_FLAGS16)nest;
3327 /* Process 'P' for "Place Info" */
3328 else if (buf[0] == 'P')
3332 /* Scan for the values */
3333 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3335 /* Save the values */
3340 /* Process 'L' for "fLoor type" (one line only) */
3341 else if (buf[0] == 'L')
3345 /* Scan for the values */
3346 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3348 /* Save the values */
3349 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3351 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3352 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3354 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3356 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3359 /* Process 'A' for "wAll type" (one line only) */
3360 else if (buf[0] == 'A')
3364 /* Scan for the values */
3365 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3367 /* Save the values */
3368 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3370 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3371 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3373 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3376 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3377 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3379 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3380 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3382 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3383 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3385 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3386 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3389 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3390 else if (buf[0] == 'F')
3392 int artif = 0, monst = 0;
3394 /* Parse every entry */
3395 for (s = buf + 2; *s; )
3397 /* Find the end of this entry */
3398 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3400 /* Nuke and skip any dividers */
3404 while (*t == ' ' || *t == '|') t++;
3407 /* Hack -- Read Final Artifact */
3408 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3410 /* Extract a "Final Artifact" */
3411 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3413 /* Start at next entry */
3418 /* Hack -- Read Final Object */
3419 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3421 /* Extract a "Final Artifact" */
3422 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3424 /* Start at next entry */
3429 /* Hack -- Read Artifact Guardian */
3430 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3432 /* Extract a "Artifact Guardian" */
3433 d_ptr->final_guardian = (MONRACE_IDX)monst;
3435 /* Start at next entry */
3440 /* Hack -- Read Special Percentage */
3441 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3443 /* Extract a "Special %" */
3444 d_ptr->special_div = (PROB)monst;
3446 /* Start at next entry */
3451 /* Parse this entry */
3452 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3454 /* Start the next entry */
3459 /* Process 'M' for "Basic Flags" (multiple lines) */
3460 else if (buf[0] == 'M')
3462 /* Parse every entry */
3463 for (s = buf + 2; *s; )
3465 /* Find the end of this entry */
3466 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3468 /* Nuke and skip any dividers */
3472 while (*t == ' ' || *t == '|') t++;
3475 /* Hack -- Read monster symbols */
3476 if (!strncmp(s, "R_CHAR_", 7))
3478 /* Skip "R_CHAR_" */
3482 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3484 /* Start at next entry */
3489 /* Parse this entry */
3490 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3492 /* Start the next entry */
3497 /* Process 'S' for "Spell Flags" (multiple lines) */
3498 else if (buf[0] == 'S')
3500 /* Parse every entry */
3501 for (s = buf + 2; *s; )
3503 /* Find the end of this entry */
3504 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3506 /* Nuke and skip any dividers */
3510 while ((*t == ' ') || (*t == '|')) t++;
3513 /* Hack -- Read spell frequency */
3514 if (1 == sscanf(s, "1_IN_%d", &i))
3516 /* Start at next entry */
3521 /* Parse this entry */
3522 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3524 /* Start the next entry */
3536 #else /* ALLOW_TEMPLATES */
3542 #endif /* ALLOW_TEMPLATES */
3546 * @brief 地形情報の「F:」情報をパースする
3547 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3551 static errr parse_line_feature(char *buf)
3556 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3558 /* Tokenize the line */
3559 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3561 /* Letter to assign */
3562 int index = zz[0][0];
3564 /* Reset the info for the letter */
3565 letter[index].feature = feat_none;
3566 letter[index].monster = 0;
3567 letter[index].object = 0;
3568 letter[index].ego = 0;
3569 letter[index].artifact = 0;
3570 letter[index].trap = feat_none;
3571 letter[index].cave_info = 0;
3572 letter[index].special = 0;
3573 letter[index].random = RANDOM_NONE;
3579 letter[index].special = (s16b)atoi(zz[8]);
3583 if ((zz[7][0] == '*') && !zz[7][1])
3585 letter[index].random |= RANDOM_TRAP;
3589 letter[index].trap = f_tag_to_index(zz[7]);
3590 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3595 if (zz[6][0] == '*')
3597 letter[index].random |= RANDOM_ARTIFACT;
3598 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3600 else if (zz[6][0] == '!')
3602 if (p_ptr->inside_quest)
3604 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3609 letter[index].artifact = (IDX)atoi(zz[6]);
3614 if (zz[5][0] == '*')
3616 letter[index].random |= RANDOM_EGO;
3617 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3621 letter[index].ego = (IDX)atoi(zz[5]);
3626 if (zz[4][0] == '*')
3628 letter[index].random |= RANDOM_OBJECT;
3629 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3631 else if (zz[4][0] == '!')
3633 if (p_ptr->inside_quest)
3635 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3638 artifact_type *a_ptr = &a_info[a_idx];
3639 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3641 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3648 letter[index].object = (IDX)atoi(zz[4]);
3653 if (zz[3][0] == '*')
3655 letter[index].random |= RANDOM_MONSTER;
3656 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3658 else if (zz[3][0] == 'c')
3660 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3661 letter[index].monster = -atoi(zz[3] + 1);
3665 letter[index].monster = (IDX)atoi(zz[3]);
3670 letter[index].cave_info = atoi(zz[2]);
3674 if ((zz[1][0] == '*') && !zz[1][1])
3676 letter[index].random |= RANDOM_FEATURE;
3680 letter[index].feature = f_tag_to_index(zz[1]);
3681 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3694 * @brief 地形情報の「B:」情報をパースする
3695 * Process "B:<Index>:<Command>:..." -- Building definition
3699 static errr parse_line_building(char *buf)
3715 /* Get the building number */
3718 /* Find the colon after the building number */
3719 s = my_strchr(s, ':');
3721 /* Verify that colon */
3724 /* Nuke the colon, advance to the sub-index */
3727 /* Paranoia -- require a sub-index */
3728 if (!*s) return (1);
3730 /* Building definition sub-index */
3733 /* Building name, owner, race */
3736 if (tokenize(s + 2, 3, zz, 0) == 3)
3738 /* Name of the building */
3739 strcpy(building[index].name, zz[0]);
3741 /* Name of the owner */
3742 strcpy(building[index].owner_name, zz[1]);
3744 /* Race of the owner */
3745 strcpy(building[index].owner_race, zz[2]);
3750 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3753 /* Building Action */
3756 if (tokenize(s + 2, 8, zz, 0) >= 7)
3758 /* Index of the action */
3759 int action_index = atoi(zz[0]);
3761 /* Name of the action */
3762 strcpy(building[index].act_names[action_index], zz[1]);
3764 /* Cost of the action for members */
3765 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3767 /* Cost of the action for non-members */
3768 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3770 /* Letter assigned to the action */
3771 building[index].letters[action_index] = zz[4][0];
3774 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3776 /* Action restriction */
3777 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3782 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3785 /* Building Classes */
3789 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3790 for (i = 0; i < MAX_CLASS; i++)
3792 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3797 /* Building Races */
3801 n = tokenize(s + 2, MAX_RACES, zz, 0);
3802 for (i = 0; i < MAX_RACES; i++)
3804 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3809 /* Building Realms */
3813 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3814 for (i = 0; i < MAX_MAGIC; i++)
3816 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3823 /* Ignore scripts */
3829 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3838 * @brief フロアの所定のマスにオブジェクトを配置する
3839 * Place the object j_ptr to a grid
3840 * @param j_ptr オブジェクト構造体の参照ポインタ
3845 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3847 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3850 OBJECT_IDX o_idx = o_pop();
3852 /* Access new object */
3853 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3855 /* Structure copy */
3856 object_copy(o_ptr, j_ptr);
3863 o_ptr->held_m_idx = 0;
3866 o_ptr->next_o_idx = g_ptr->o_idx;
3868 g_ptr->o_idx = o_idx;
3872 * @brief クエスト用固定ダンジョンをフロアに生成する
3873 * Parse a sub-file of the "extra info"
3883 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3888 /* Skip "empty" lines */
3889 if (!buf[0]) return (0);
3891 /* Skip "blank" lines */
3892 if (iswspace(buf[0])) return (0);
3895 if (buf[0] == '#') return (0);
3897 /* Require "?:*" format */
3898 if (buf[1] != ':') return (1);
3901 /* Process "%:<fname>" */
3904 /* Attempt to Process the given file */
3905 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3908 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3911 return parse_line_feature(buf);
3914 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3915 else if (buf[0] == 'D')
3917 object_type object_type_body;
3919 /* Acquire the text */
3922 /* Length of the text */
3923 int len = strlen(s);
3925 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3927 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3929 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3933 OBJECT_IDX object_index = letter[idx].object;
3934 MONSTER_IDX monster_index = letter[idx].monster;
3935 int random = letter[idx].random;
3936 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3938 /* Lay down a floor */
3939 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3941 /* Only the features */
3942 if (init_flags & INIT_ONLY_FEATURES) continue;
3945 g_ptr->info = letter[idx].cave_info;
3947 /* Create a monster */
3948 if (random & RANDOM_MONSTER)
3950 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3952 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3954 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3956 else if (monster_index)
3958 int old_cur_num, old_max_num;
3961 if (monster_index < 0)
3963 monster_index = -monster_index;
3966 old_cur_num = r_info[monster_index].cur_num;
3967 old_max_num = r_info[monster_index].max_num;
3969 /* Make alive again */
3970 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3972 r_info[monster_index].cur_num = 0;
3973 r_info[monster_index].max_num = 1;
3976 /* Make alive again */
3977 /* Hack -- Non-unique Nazguls are semi-unique */
3978 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3980 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3982 r_info[monster_index].max_num++;
3987 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3991 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3993 /* Make alive again for real unique monster */
3994 r_info[monster_index].cur_num = old_cur_num;
3995 r_info[monster_index].max_num = old_max_num;
3999 /* Object (and possible trap) */
4000 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4002 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4005 * Random trap and random treasure defined
4006 * 25% chance for trap and 75% chance for object
4008 if (randint0(100) < 75)
4010 place_object(*y, *x, 0L);
4017 current_floor_ptr->object_level = current_floor_ptr->base_level;
4019 else if (random & RANDOM_OBJECT)
4021 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4023 /* Create an out of deep object */
4024 if (randint0(100) < 75)
4025 place_object(*y, *x, 0L);
4026 else if (randint0(100) < 80)
4027 place_object(*y, *x, AM_GOOD);
4029 place_object(*y, *x, AM_GOOD | AM_GREAT);
4031 current_floor_ptr->object_level = current_floor_ptr->base_level;
4034 else if (random & RANDOM_TRAP)
4038 /* Hidden trap (or door) */
4039 else if (letter[idx].trap)
4041 g_ptr->mimic = g_ptr->feat;
4042 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4044 else if (object_index)
4046 object_type *o_ptr = &object_type_body;
4047 object_prep(o_ptr, object_index);
4049 if (o_ptr->tval == TV_GOLD)
4051 coin_type = object_index - OBJ_GOLD_LIST;
4056 /* Apply magic (no messages, no artifacts) */
4057 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4059 drop_here(o_ptr, *y, *x);
4065 if (a_info[artifact_index].cur_num)
4067 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4069 object_type *q_ptr = &forge;
4071 object_prep(q_ptr, k_idx);
4072 drop_here(q_ptr, *y, *x);
4076 if (create_named_art(artifact_index, *y, *x))
4077 a_info[artifact_index].cur_num = 1;
4081 /* Terrain special */
4082 g_ptr->special = letter[idx].special;
4090 /* Process "Q:<number>:<command>:... -- quest info */
4091 else if (buf[0] == 'Q')
4098 num = tokenize(buf + 2, 33, zz, 0);
4102 num = tokenize(buf + 3, 33, zz, 0);
4105 /* Have we enough parameters? */
4106 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4109 q_ptr = &(quest[atoi(zz[0])]);
4111 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4112 if (zz[1][0] == 'Q')
4114 if (init_flags & INIT_ASSIGN)
4116 monster_race *r_ptr;
4117 artifact_type *a_ptr;
4119 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4121 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4122 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4123 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4124 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4125 q_ptr->level = (DEPTH)atoi(zz[6]);
4126 q_ptr->r_idx = (IDX)atoi(zz[7]);
4127 q_ptr->k_idx = (IDX)atoi(zz[8]);
4128 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4130 if (num > 10) q_ptr->flags = atoi(zz[10]);
4132 r_ptr = &r_info[q_ptr->r_idx];
4133 if (r_ptr->flags1 & RF1_UNIQUE)
4134 r_ptr->flags1 |= RF1_QUESTOR;
4136 a_ptr = &a_info[q_ptr->k_idx];
4137 a_ptr->gen_flags |= TRG_QUESTITEM;
4142 else if (zz[1][0] == 'R')
4144 if (init_flags & INIT_ASSIGN)
4147 IDX idx, reward_idx = 0;
4149 for (idx = 2; idx < num; idx++)
4151 IDX a_idx = (IDX)atoi(zz[idx]);
4152 if (a_idx < 1) continue;
4153 if (a_info[a_idx].cur_num > 0) continue;
4155 if (one_in_(count)) reward_idx = a_idx;
4160 /* Set quest's rewarding artifact */
4161 q_ptr->k_idx = reward_idx;
4162 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4166 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4167 q_ptr->type = QUEST_TYPE_KILL_ALL;
4174 /* Process "Q:<q_index>:N:<name>" -- quest name */
4175 else if (zz[1][0] == 'N')
4177 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4179 strcpy(q_ptr->name, zz[2]);
4185 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4186 else if (zz[1][0] == 'T')
4188 if (init_flags & INIT_SHOW_TEXT)
4190 strcpy(quest_text[quest_text_line], zz[2]);
4198 /* Process "W:<command>: ..." -- info for the wilderness */
4199 else if (buf[0] == 'W')
4201 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4204 /* Process "P:<y>:<x>" -- player position */
4205 else if (buf[0] == 'P')
4207 if (init_flags & INIT_CREATE_DUNGEON)
4209 if (tokenize(buf + 2, 2, zz, 0) == 2)
4211 int panels_x, panels_y;
4213 /* Hack - Set the dungeon size */
4214 panels_y = (*y / SCREEN_HGT);
4215 if (*y % SCREEN_HGT) panels_y++;
4216 current_floor_ptr->height = panels_y * SCREEN_HGT;
4218 panels_x = (*x / SCREEN_WID);
4219 if (*x % SCREEN_WID) panels_x++;
4220 current_floor_ptr->width = panels_x * SCREEN_WID;
4222 /* Assume illegal panel */
4223 panel_row_min = current_floor_ptr->height;
4224 panel_col_min = current_floor_ptr->width;
4226 /* Place player in a quest level */
4227 if (p_ptr->inside_quest)
4231 /* Delete the monster (if any) */
4232 delete_monster(p_ptr->y, p_ptr->x);
4240 /* Place player in the town */
4241 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4243 p_ptr->oldpy = atoi(zz[0]);
4244 p_ptr->oldpx = atoi(zz[1]);
4252 /* Process "B:<Index>:<Command>:..." -- Building definition */
4253 else if (buf[0] == 'B')
4255 return parse_line_building(buf);
4258 /* Process "M:<type>:<maximum>" -- set maximum values */
4259 else if (buf[0] == 'M')
4261 if (tokenize(buf + 2, 2, zz, 0) == 2)
4264 if (zz[0][0] == 'T')
4266 max_towns = (TOWN_IDX)atoi(zz[1]);
4269 /* Maximum quests */
4270 else if (zz[0][0] == 'Q')
4272 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4276 else if (zz[0][0] == 'R')
4278 max_r_idx = (IDX)atoi(zz[1]);
4282 else if (zz[0][0] == 'K')
4284 max_k_idx = (IDX)atoi(zz[1]);
4288 else if (zz[0][0] == 'V')
4290 max_v_idx = (IDX)atoi(zz[1]);
4294 else if (zz[0][0] == 'F')
4296 max_f_idx = (IDX)atoi(zz[1]);
4300 else if (zz[0][0] == 'A')
4302 max_a_idx = (IDX)atoi(zz[1]);
4306 else if (zz[0][0] == 'E')
4308 max_e_idx = (IDX)atoi(zz[1]);
4312 else if (zz[0][0] == 'D')
4314 max_d_idx = (IDX)atoi(zz[1]);
4318 else if (zz[0][0] == 'O')
4320 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4324 else if (zz[0][0] == 'M')
4326 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4329 /* Wilderness size */
4330 else if (zz[0][0] == 'W')
4332 /* Maximum wild_x_size */
4333 if (zz[0][1] == 'X')
4334 current_world_ptr->max_wild_x = atoi(zz[1]);
4335 /* Maximum wild_y_size */
4336 if (zz[0][1] == 'Y')
4337 current_world_ptr->max_wild_y = atoi(zz[1]);
4351 static concptr variant = "ZANGBAND";
4355 * @brief クエスト用固定ダンジョン生成時の分岐処理
4356 * Helper function for "process_dungeon_file()"
4361 static concptr process_dungeon_file_expr(char **sp, char *fp)
4377 while (iswspace(*s)) s++;
4395 t = process_dungeon_file_expr(&s, &f);
4403 else if (streq(t, "IOR"))
4406 while (*s && (f != b2))
4408 t = process_dungeon_file_expr(&s, &f);
4409 if (*t && !streq(t, "0")) v = "1";
4414 else if (streq(t, "AND"))
4417 while (*s && (f != b2))
4419 t = process_dungeon_file_expr(&s, &f);
4420 if (*t && streq(t, "0")) v = "0";
4425 else if (streq(t, "NOT"))
4428 while (*s && (f != b2))
4430 t = process_dungeon_file_expr(&s, &f);
4431 if (*t && streq(t, "1")) v = "0";
4436 else if (streq(t, "EQU"))
4439 if (*s && (f != b2))
4441 t = process_dungeon_file_expr(&s, &f);
4443 while (*s && (f != b2))
4445 p = process_dungeon_file_expr(&s, &f);
4446 if (streq(t, p)) v = "1";
4451 else if (streq(t, "LEQ"))
4454 if (*s && (f != b2))
4456 t = process_dungeon_file_expr(&s, &f);
4458 while (*s && (f != b2))
4461 t = process_dungeon_file_expr(&s, &f);
4462 if (*t && atoi(p) > atoi(t)) v = "0";
4467 else if (streq(t, "GEQ"))
4470 if (*s && (f != b2))
4472 t = process_dungeon_file_expr(&s, &f);
4474 while (*s && (f != b2))
4477 t = process_dungeon_file_expr(&s, &f);
4479 /* Compare two numbers instead of string */
4480 if (*t && atoi(p) < atoi(t)) v = "0";
4486 while (*s && (f != b2))
4488 t = process_dungeon_file_expr(&s, &f);
4493 if (f != b2) v = "?x?x?";
4495 /* Extract final and Terminate */
4496 if ((f = *s) != '\0') *s++ = '\0';
4502 /* Accept all printables except spaces and brackets */
4504 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4506 if (iskanji(*s)) s++;
4510 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4513 /* Extract final and Terminate */
4514 if ((f = *s) != '\0') *s++ = '\0';
4520 if (streq(b + 1, "SYS"))
4526 else if (streq(b + 1, "GRAF"))
4531 else if (streq(b + 1, "MONOCHROME"))
4540 else if (streq(b + 1, "RACE"))
4542 v = _(rp_ptr->E_title, rp_ptr->title);
4546 else if (streq(b + 1, "CLASS"))
4548 v = _(cp_ptr->E_title, cp_ptr->title);
4552 else if (streq(b + 1, "REALM1"))
4554 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4558 else if (streq(b + 1, "REALM2"))
4560 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4564 else if (streq(b + 1, "PLAYER"))
4566 static char tmp_player_name[32];
4568 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4578 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4581 v = tmp_player_name;
4585 else if (streq(b + 1, "TOWN"))
4587 sprintf(tmp, "%d", p_ptr->town_num);
4592 else if (streq(b + 1, "LEVEL"))
4594 sprintf(tmp, "%d", p_ptr->lev);
4598 /* Current quest number */
4599 else if (streq(b + 1, "QUEST_NUMBER"))
4601 sprintf(tmp, "%d", p_ptr->inside_quest);
4605 /* Number of last quest */
4606 else if (streq(b + 1, "LEAVING_QUEST"))
4608 sprintf(tmp, "%d", leaving_quest);
4613 else if (prefix(b + 1, "QUEST_TYPE"))
4615 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4616 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4621 else if (prefix(b + 1, "QUEST"))
4623 /* "QUEST" uses a special parameter to determine the number of the quest */
4624 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4629 else if (prefix(b + 1, "RANDOM"))
4631 /* "RANDOM" uses a special parameter to determine the number of the quest */
4632 sprintf(tmp, "%d", (int)(seed_town%atoi(b + 7)));
4637 else if (streq(b + 1, "VARIANT"))
4643 else if (streq(b + 1, "WILDERNESS"))
4646 sprintf(tmp, "NONE");
4648 sprintf(tmp, "LITE");
4650 sprintf(tmp, "NORMAL");
4669 void write_r_info_txt(void)
4671 int i, j, z, fc, bc;
4674 concptr flags[32 * 10];
4679 monster_race *r_ptr;
4681 monster_blow *b_ptr;
4683 FILE *fff = fopen("output.txt", "wt");
4687 BIT_FLAGS mode = -1;
4691 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4693 fprintf(fff, "# Version stamp (required)\n\n");
4696 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4699 fprintf(fff, "##### The Player #####\n\n");
4701 for (z = -1; z < alloc_race_size; z++)
4703 /* Output the monsters in order */
4704 i = (z >= 0) ? alloc_race_table[z].index : 0;
4706 /* Acquire the monster */
4709 /* Ignore empty monsters */
4710 if (!strlen(r_name + r_ptr->name)) continue;
4712 /* Ignore useless monsters */
4713 if (i && !r_ptr->speed) continue;
4715 /* Write a note if necessary */
4716 if (i && (!r_ptr->level != !mode))
4721 fprintf(fff, "\n##### Town monsters #####\n\n");
4723 /* Note the dungeon */
4726 fprintf(fff, "\n##### Normal monsters #####\n\n");
4729 /* Record the change */
4730 mode = r_ptr->level;
4733 /* Acquire the flags */
4734 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4735 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4736 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4737 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4738 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4739 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4740 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4741 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4742 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4743 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4745 /* Write New/Number/Name */
4746 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4749 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4751 /* Write Information */
4752 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4753 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4755 /* Write more information */
4756 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4759 for (j = 0; j < 4; j++)
4761 b_ptr = &(r_ptr->blow[j]);
4763 /* Stop when done */
4764 if (!b_ptr->method) break;
4766 /* Write the blows */
4767 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4768 r_info_blow_effect[b_ptr->effect],
4769 b_ptr->d_dice, b_ptr->d_side);
4771 for (fc = 0, j = 0; j < 32 * 3; j++)
4773 /* Check this flag */
4774 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4777 /* Extract the extra flags */
4778 for (j = 32 * 6; j < 32 * 10; j++)
4780 /* Check this flag */
4781 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4784 /* Write the flags */
4785 for (j = 0; j < fc;)
4789 /* Start the line */
4792 for (bc = 0; (bc < 60) && (j < fc); j++)
4796 /* Format the flag */
4797 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4799 /* Add it to the buffer */
4802 /* Note the length */
4806 /* Done with this line; write it */
4807 fprintf(fff, "%s\n", buf);
4810 /* Write Spells if applicable */
4811 if (r_ptr->freq_spell)
4813 /* Write the frequency */
4814 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4816 /* Extract the spell flags */
4817 for (fc = 0, j = 96; j < 192; j++)
4819 /* Check this flag */
4820 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4823 /* Write the flags */
4824 for (j = 0; j < fc;)
4828 /* Start the line */
4831 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4835 /* Format the flag */
4836 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4840 /* Note the length */
4847 /* Done with this line; write it */
4848 fprintf(fff, "%s\n", buf);
4852 /* Acquire the description */
4853 desc = r_text + r_ptr->text;
4854 dlen = strlen(desc);
4856 /* Write Description */
4857 for (j = 0; j < dlen;)
4861 /* Start the line */
4864 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4872 /* Done with this line; write it */
4873 fprintf(fff, "%s\n", buf);
4876 /* Space between entries */
4887 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4888 * Helper function for "process_dungeon_file()"
4896 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4902 bool bypass = FALSE;
4903 int x = xmin, y = ymin;
4906 /* Build the filename */
4907 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4910 fp = my_fopen(buf, "r");
4913 if (!fp) return (-1);
4916 /* Process the file */
4917 while (0 == my_fgets(fp, buf, sizeof(buf)))
4923 /* Skip "empty" lines */
4924 if (!buf[0]) continue;
4926 /* Skip "blank" lines */
4927 if (iswspace(buf[0])) continue;
4930 if (buf[0] == '#') continue;
4933 /* Process "?:<expr>" */
4934 if ((buf[0] == '?') && (buf[1] == ':'))
4943 /* Parse the expr */
4944 v = process_dungeon_file_expr(&s, &f);
4947 bypass = (streq(v, "0") ? TRUE : FALSE);
4951 /* Apply conditionals */
4952 if (bypass) continue;
4954 /* Process the line */
4955 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4966 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4968 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4969 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);