7 #include "dungeon-file.h"
8 #include "rooms-vault.h"
14 #include "player-skill.h"
15 #include "player-race.h"
20 #include "rooms-vault.h"
21 #include "objectkind.h"
22 #include "object-ego.h"
23 #include "monsterrace.h"
24 #include "floor-town.h"
27 dungeon_grid letter[255];
31 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
35 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
36 * This software may be copied and distributed for educational, research,
37 * and not for profit purposes provided that this copyright and statement
38 * are included in all such copies. Other copyrights may also apply.
39 * 2014 Deskull rearranged comment for Doxygen.\n
43 * This file is used to initialize various variables and arrays for the
44 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
45 * the common limitation of "read()" and "write()" to only 32767 bytes
47 * Several of the arrays for Angband are built from "template" files in
48 * the "lib/file" directory, from which quick-load binary "image" files
49 * are constructed whenever they are not present in the "lib/data"
50 * directory, or if those files become obsolete, if we are allowed.
51 * Warning -- the "ascii" file parsers use a minor hack to collect the
52 * name and text information in a single pass. Thus, the game will not
53 * be able to load any template file with more than 20K of names or 60K
54 * of text, even though technically, up to 64K should be legal.
56 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
57 * in this file is compiled out, and the game will not run unless valid
58 * "binary template files" already exist in "lib/data". Thus, one can
59 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
60 * "*.raw" files in "lib/data", and then quit, and recompile without
61 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
62 * from changing the ascii template files in potentially dangerous ways.
63 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
64 * このファイルのコードの多くはコンパイル出力され、本ゲームは
65 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
66 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
67 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
68 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
69 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
70 * テンプレートファイルを変更することを妨げることができる。
71 * The code could actually be removed and placed into a "stand-alone"
72 * program, but that feels a little silly, especially considering some
73 * of the platforms that we currently support.
78 #include "dungeon-file.h"
83 #include "cmd-activate.h"
87 #include "view-mainwindow.h"
88 #include "player-class.h"
92 #ifdef ALLOW_TEMPLATES
97 /*** Helper arrays for parsing ascii template files ***/
100 * モンスターの打撃手段トークンの定義 /
101 * Monster Blow Methods
103 static concptr r_info_blow_method[] =
136 * モンスターの打撃属性トークンの定義 /
137 * Monster Blow Effects
139 static concptr r_info_blow_effect[] =
184 static concptr f_info_flags[] =
309 static concptr r_info_flags1[] =
349 static concptr r_info_flags2[] =
389 static concptr r_info_flags3[] =
429 static concptr r_info_flags4[] =
466 * モンスター特性トークン(発動型能力1) /
469 static concptr r_a_ability_flags1[] =
506 * モンスター特性トークン(発動型能力2) /
509 static concptr r_a_ability_flags2[] =
526 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
547 * モンスター特性トークン(発動型能力3) /
550 static concptr r_a_ability_flags3[] =
589 * モンスター特性トークン(発動型能力4) /
592 static concptr r_a_ability_flags4[] =
634 static concptr r_info_flags7[] =
674 static concptr r_info_flags8[] =
706 "WILD_SWAMP", /* ToDo: Implement Swamp */
715 static concptr r_info_flags9[] =
754 * モンスター特性トークンの定義R(耐性) /
757 static concptr r_info_flagsr[] =
795 * オブジェクト基本特性トークンの定義 /
798 static concptr k_info_flags[] =
895 "XXX3", /* Fake flag for Smith */
896 "XXX4", /* Fake flag for Smith */
946 * オブジェクト生成特性トークンの定義 /
949 static concptr k_info_gen_flags[] =
989 static concptr d_info_flags1[] =
1027 * @brief データの可変文字列情報をテキストとして保管する /
1028 * Add a text to the text-storage and store offset to it.
1029 * @param offset 文字列保管ポインタからのオフセット
1030 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1032 * @param normal_text テキストの正規化を行う
1035 * Returns FALSE when there isn't enough space available to store
1038 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1040 /* Hack -- Verify space */
1041 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1047 /* Advance and save the text index */
1048 *offset = ++head->text_size;
1051 /* Additional text */
1052 else if (normal_text)
1055 * If neither the end of the last line nor
1056 * the beginning of current line is not a space,
1057 * fill up a space as a correct separator of two words.
1059 if (head->text_size > 0 &&
1061 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1062 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1063 (buf[0] != ' ') && !iskanji(buf[0])
1065 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1070 /* Append a space */
1071 *(head->text_ptr + head->text_size) = ' ';
1073 /* Advance the index */
1078 /* Append chars to the text */
1079 strcpy(head->text_ptr + head->text_size, buf);
1081 /* Advance the index */
1082 head->text_size += strlen(buf);
1090 * @brief データの可変文字列情報を名前として保管する /
1091 * Add a name to the name-storage and return an offset to it.
1092 * @param offset 文字列保管ポインタからのオフセット
1093 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1097 * Returns FALSE when there isn't enough space available to store
1100 static bool add_name(u32b *offset, header *head, concptr buf)
1102 /* Hack -- Verify space */
1103 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1109 /* Advance and save the name index */
1110 *offset = ++head->name_size;
1113 /* Append chars to the names */
1114 strcpy(head->name_ptr + head->name_size, buf);
1116 /* Advance the index */
1117 head->name_size += strlen(buf);
1125 * @brief データの可変文字列情報をタグとして保管する /
1126 * Add a tag to the tag-storage and return an offset to it.
1127 * @param offset 文字列保管ポインタからのオフセット
1128 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1132 * Returns FALSE when there isn't enough space available to store
1135 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1139 /* Search for an existing (fake) tag */
1140 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1143 if (streq(&head->tag_ptr[i], buf)) break;
1146 /* There was no existing tag */
1147 if (i >= head->tag_size)
1149 /* Hack -- Verify space */
1150 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1153 /* Append chars to the tags */
1154 strcpy(head->tag_ptr + head->tag_size, buf);
1156 /* Point the new tag */
1159 /* Advance the index */
1160 head->tag_size += strlen(buf) + 1;
1163 /* Return offset of the tag */
1171 /*** Initialize from ascii template files ***/
1175 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1176 * Initialize an "*_info" array, by parsing an ascii "template" file
1177 * @param fp 読み取りに使うファイルポインタ
1178 * @param buf 読み取りに使うバッファ領域
1179 * @param head ヘッダ構造体
1180 * @param parse_info_txt_line パース関数
1183 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1187 /* Just before the first record */
1190 /* Just before the first line */
1194 /* Prepare the "fake" stuff */
1195 head->name_size = 0;
1196 head->text_size = 0;
1200 while (0 == my_fgets(fp, buf, 1024))
1202 /* Advance the line number */
1205 /* Skip comments and blank lines */
1206 if (!buf[0] || (buf[0] == '#')) continue;
1208 /* Verify correct "colon" format */
1209 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1212 /* Hack -- Process 'V' for "Version" */
1219 /* Mega Hack -- Calculate Check Sum */
1220 if (buf[0] != 'N' && buf[0] != 'D')
1223 for (i = 0; buf[i]; i++)
1225 head->v_extra += (byte)buf[i];
1226 head->v_extra ^= (1 << (i % 8));
1230 /* Parse the line */
1231 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1236 /* Complete the "name" and "text" sizes */
1237 if (head->name_size) head->name_size++;
1238 if (head->text_size) head->text_size++;
1246 * @brief Vault情報(v_info)のパース関数 /
1247 * Initialize the "v_info" array, by parsing an ascii "template" file
1249 * @param head ヘッダ構造体
1252 errr parse_v_info(char *buf, header *head)
1258 static vault_type *v_ptr = NULL;
1260 /* Process 'N' for "New/Number/Name" */
1263 /* Find the colon before the name */
1264 s = my_strchr(buf + 2, ':');
1266 /* Verify that colon */
1269 /* Nuke the colon, advance to the name */
1272 /* Paranoia -- require a name */
1273 if (!*s) return (1);
1278 /* Verify information */
1279 if (i <= error_idx) return (4);
1281 /* Verify information */
1282 if (i >= head->info_num) return (2);
1284 /* Save the index */
1287 /* Point at the "info" */
1290 /* Store the name */
1291 if (!add_name(&v_ptr->name, head, s)) return (7);
1294 /* There better be a current v_ptr */
1295 else if (!v_ptr) return (3);
1297 /* Process 'D' for "Description" */
1298 else if (buf[0] == 'D')
1300 /* Acquire the text */
1303 /* Store the text */
1304 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1307 /* Process 'X' for "Extra info" (one line only) */
1308 else if (buf[0] == 'X')
1310 EFFECT_ID typ, rat, hgt, wid;
1312 /* Scan for the values */
1313 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1314 &typ, &rat, &hgt, &wid)) return (1);
1316 /* Save the values */
1317 v_ptr->typ = (ROOM_IDX)typ;
1318 v_ptr->rat = (PROB)rat;
1319 v_ptr->hgt = (POSITION)hgt;
1320 v_ptr->wid = (POSITION)wid;
1331 * @brief 職業技能情報(s_info)のパース関数 /
1332 * Initialize the "s_info" array, by parsing an ascii "template" file
1334 * @param head ヘッダ構造体
1337 errr parse_s_info(char *buf, header *head)
1342 static skill_table *s_ptr = NULL;
1345 /* Process 'N' for "New/Number/Name" */
1351 /* Verify information */
1352 if (i <= error_idx) return (4);
1354 /* Verify information */
1355 if (i >= head->info_num) return (2);
1357 /* Save the index */
1360 /* Point at the "info" */
1364 /* There better be a current s_ptr */
1365 else if (!s_ptr) return (3);
1367 /* Process 'W' for "Weapon exp" */
1368 else if (buf[0] == 'W')
1370 int tval, sval, start, max;
1371 const s16b exp_conv_table[] =
1373 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1374 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1377 /* Scan for the values */
1378 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1379 &tval, &sval, &start, &max)) return (1);
1381 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1382 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1384 /* Save the values */
1385 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1386 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1389 /* Process 'S' for "Skill exp" */
1390 else if (buf[0] == 'S')
1392 int num, start, max;
1394 /* Scan for the values */
1395 if (3 != sscanf(buf + 2, "%d:%d:%d",
1396 &num, &start, &max)) return (1);
1398 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1399 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1401 /* Save the values */
1402 s_ptr->s_start[num] = (SUB_EXP)start;
1403 s_ptr->s_max[num] = (SUB_EXP)max;
1415 * @brief 職業魔法情報(m_info)のパース関数 /
1416 * Initialize the "m_info" array, by parsing an ascii "template" file
1418 * @param head ヘッダ構造体
1421 errr parse_m_info(char *buf, header *head)
1428 static player_magic *m_ptr = NULL;
1431 static int realm, magic_idx = 0, readable = 0;
1434 /* Process 'N' for "New/Number/Name" */
1440 /* Verify information */
1441 if (i <= error_idx) return (4);
1443 /* Verify information */
1444 if (i >= head->info_num) return (2);
1446 /* Save the index */
1449 /* Point at the "info" */
1453 /* There better be a current m_ptr */
1454 else if (!m_ptr) return (3);
1456 /* Process 'I' for "Info" (one line only) */
1457 else if (buf[0] == 'I')
1460 int xtra, type, first, weight;
1462 /* Find the colon before the name */
1463 s = my_strchr(buf + 2, ':');
1465 /* Verify that colon */
1468 /* Nuke the colon, advance to the name */
1473 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1474 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1475 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1476 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1477 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1482 /* Find the colon before the name */
1483 s = my_strchr(s, ':');
1485 /* Verify that colon */
1488 /* Nuke the colon, advance to the name */
1491 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1492 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1493 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1494 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1495 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1496 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1500 /* Scan for the values */
1501 if (4 != sscanf(s, "%x:%d:%d:%d",
1502 (uint *)&xtra, &type, &first, &weight)) return (1);
1504 m_ptr->spell_xtra = xtra;
1505 m_ptr->spell_type = type;
1506 m_ptr->spell_first = first;
1507 m_ptr->spell_weight = weight;
1511 /* Process 'R' for "Realm" (one line only) */
1512 else if (buf[0] == 'R')
1514 /* Scan for the values */
1515 if (2 != sscanf(buf + 2, "%d:%d",
1516 &realm, &readable)) return (1);
1521 else if (buf[0] == 'T')
1523 int level, mana, fail, exp;
1525 if (!readable) return (1);
1526 /* Scan for the values */
1527 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1528 &level, &mana, &fail, &exp)) return (1);
1530 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1531 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1532 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1533 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1546 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1547 * Grab one flag from a textual string
1548 * @param flags ビットフラグを追加する先の参照ポインタ
1549 * @param names トークン定義配列
1550 * @param what 参照元の文字列ポインタ
1553 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1558 for (i = 0; i < 32; i++)
1560 if (streq(what, names[i]))
1562 *flags |= (1L << i);
1572 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1573 * Grab one flag in an feature_type from a textual string
1574 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1575 * @param what 参照元の文字列ポインタ
1578 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1583 for (i = 0; i < FF_FLAG_MAX; i++)
1585 if (streq(what, f_info_flags[i]))
1587 add_flag(f_ptr->flags, i);
1592 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1595 return PARSE_ERROR_GENERIC;
1600 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1601 * Grab an action in an feature_type from a textual string
1602 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1603 * @param what 参照元の文字列ポインタ
1604 * @param count ステートの保存先ID
1607 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1612 for (i = 0; i < FF_FLAG_MAX; i++)
1614 if (streq(what, f_info_flags[i]))
1616 f_ptr->state[count].action = i;
1621 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1624 return PARSE_ERROR_GENERIC;
1629 * @brief 地形情報(f_info)のパース関数 /
1630 * Initialize the "f_info" array, by parsing an ascii "template" file
1632 * @param head ヘッダ構造体
1635 errr parse_f_info(char *buf, header *head)
1642 static feature_type *f_ptr = NULL;
1645 /* Process 'N' for "New/Number/Name" */
1648 /* Find the colon before the name */
1649 s = my_strchr(buf + 2, ':');
1653 /* Nuke the colon, advance to the name */
1660 /* Verify information */
1661 if (i <= error_idx) return (4);
1663 /* Verify information */
1664 if (i >= head->info_num) return (2);
1666 /* Save the index */
1669 /* Point at the "info" */
1672 /* Tag name is given */
1676 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1679 /* Default "mimic" */
1680 f_ptr->mimic = (FEAT_IDX)i;
1682 /* Default "destroyed state" -- if not specified */
1683 f_ptr->destroyed = (FEAT_IDX)i;
1685 /* Default "states" */
1686 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1689 /* There better be a current f_ptr */
1690 else if (!f_ptr) return (3);
1693 else if (buf[0] == 'J')
1695 /* Store the name */
1696 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1699 else if (buf[0] == 'E')
1701 /* Ignore english name */
1704 else if (buf[0] == 'J')
1706 /* Ignore Japanese name */
1709 else if (buf[0] == 'E')
1711 /* Acquire the Text */
1714 /* Store the name */
1715 if (!add_name(&f_ptr->name, head, s)) return (7);
1720 /* Process 'M' for "Mimic" (one line only) */
1721 else if (buf[0] == 'M')
1725 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1727 /* Record a fake tag index */
1728 f_ptr->mimic_tag = offset;
1732 /* Process 'G' for "Graphics" (one line only) */
1733 else if (buf[0] == 'G')
1737 char char_tmp[F_LIT_MAX];
1738 if (buf[1] != ':') return (1);
1739 if (!buf[2]) return (1);
1740 if (buf[3] != ':') return (1);
1741 if (!buf[4]) return (1);
1743 /* Extract the char */
1744 char_tmp[F_LIT_STANDARD] = buf[2];
1746 /* Extract the color */
1747 s_attr = color_char_to_attr(buf[4]);
1748 if (s_attr > 127) return (1);
1750 /* Save the standard values */
1751 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1752 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1754 /* Is this feature supports lighting? */
1757 /* G:c:a:LIT (default) */
1758 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1760 /* G:c:a:lc:la:dc:da */
1761 if (!streq(buf + 6, "LIT"))
1763 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1765 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1766 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1767 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1768 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1770 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1772 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1775 /* Use default lighting */
1778 /* No lighting support */
1779 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1782 /* Extract the color */
1783 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1784 if (f_ptr->d_attr[j] > 127) return 1;
1787 f_ptr->d_char[j] = char_tmp[j];
1793 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1795 f_ptr->d_attr[j] = s_attr;
1796 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1802 /* Hack -- Process 'F' for flags */
1803 else if (buf[0] == 'F')
1805 /* Parse every entry textually */
1806 for (s = buf + 2; *s; )
1808 /* Find the end of this entry */
1809 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1811 /* Nuke and skip any dividers */
1815 while (*t == ' ' || *t == '|') t++;
1818 /* Hack -- Read feature subtype */
1819 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1821 /* Extract a "subtype" */
1822 f_ptr->subtype = (FEAT_SUBTYPE)i;
1824 /* Start at next entry */
1830 /* Hack -- Read feature power */
1831 if (1 == sscanf(s, "POWER_%d", &i))
1833 /* Extract a "power" */
1834 f_ptr->power = (FEAT_POWER)i;
1836 /* Start at next entry */
1841 /* Parse this entry */
1842 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1844 /* Start the next entry */
1849 /* Process 'W' for "More Info" (one line only) */
1850 else if (buf[0] == 'W')
1854 /* Scan for the value */
1855 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1857 /* Save the value */
1858 f_ptr->priority = (FEAT_PRIORITY)priority;
1861 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1862 else if (buf[0] == 'K')
1866 /* Find the next empty state slot (if any) */
1867 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1869 /* Oops, no more slots */
1870 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1872 /* Analyze the first field */
1873 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1875 /* Terminate the field (if necessary) */
1876 if (*t == ':') *t++ = '\0';
1878 /* Is this default entry? */
1879 if (streq(s, "DESTROYED"))
1881 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1883 /* Record a fake tag index */
1884 f_ptr->destroyed_tag = offset;
1889 f_ptr->state[i].action = 0;
1891 /* Parse this entry */
1892 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1894 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1896 /* Record a fake tag index */
1897 f_ptr->state[i].result_tag = offset;
1909 * @brief 地形タグからIDを得る /
1910 * Convert a fake tag to a real feat index
1914 s16b f_tag_to_index(concptr str)
1918 /* Search for real index corresponding to this fake tag */
1919 for (i = 0; i < f_head.info_num; i++)
1921 if (streq(f_tag + f_info[i].tag, str))
1923 /* Return the index */
1934 * @brief 地形タグからIDを得る /
1935 * Search for real index corresponding to this fake tag
1936 * @param feat タグ文字列のオフセット
1937 * @return 地形ID。該当がないなら-1
1939 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1943 /* Don't convert non-fake tag */
1949 /* Search for real index corresponding to this fake tag */
1950 for (i = 0; i < f_head.info_num; i++)
1952 if (feat == f_info[i].tag)
1954 /* Record real index */
1960 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1966 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1967 * Retouch fake tags of f_info
1968 * @param head ヘッダ構造体
1971 void retouch_f_info(header *head)
1975 /* Convert fake tags to real feat indices */
1976 for (i = 0; i < head->info_num; i++)
1978 feature_type *f_ptr = &f_info[i];
1981 k = search_real_feat(f_ptr->mimic_tag);
1982 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1983 k = search_real_feat(f_ptr->destroyed_tag);
1984 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1985 for (j = 0; j < MAX_FEAT_STATES; j++)
1987 k = search_real_feat(f_ptr->state[j].result_tag);
1988 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1995 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1996 * Grab one flag in an object_kind from a textual string
1997 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1998 * @param what 参照元の文字列ポインタ
2001 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
2006 for (i = 0; i < TR_FLAG_MAX; i++)
2008 if (streq(what, k_info_flags[i]))
2010 add_flag(k_ptr->flags, i);
2015 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2018 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2025 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2026 * Grab one activation index flag
2027 * @param what 参照元の文字列ポインタ
2030 static byte grab_one_activation_flag(concptr what)
2036 if (activation_info[i].flag == NULL) break;
2038 if (streq(what, activation_info[i].flag))
2040 return activation_info[i].index;
2050 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2058 * @brief ベースアイテム(k_info)のパース関数 /
2059 * Initialize the "k_info" array, by parsing an ascii "template" file
2061 * @param head ヘッダ構造体
2064 errr parse_k_info(char *buf, header *head)
2071 static object_kind *k_ptr = NULL;
2074 /* Process 'N' for "New/Number/Name" */
2081 /* Find the colon before the name */
2082 s = my_strchr(buf + 2, ':');
2084 /* Verify that colon */
2087 /* Nuke the colon, advance to the name */
2093 /* Verify information */
2094 if (i <= error_idx) return (4);
2096 /* Verify information */
2097 if (i >= head->info_num) return (2);
2099 /* Save the index */
2102 /* Point at the "info" */
2106 /* Paranoia -- require a name */
2107 if (!*s) return (1);
2109 /* Find the colon before the flavor */
2110 flavor = my_strchr(s, ':');
2112 /* Verify that colon */
2115 /* Nuke the colon, advance to the flavor */
2118 /* Store the flavor */
2119 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2122 /* Store the name */
2123 if (!add_name(&k_ptr->name, head, s)) return (7);
2127 /* There better be a current k_ptr */
2128 else if (!k_ptr) return (3);
2133 /* 'E' から始まる行は英語名としている */
2134 else if (buf[0] == 'E')
2139 else if (buf[0] == 'E')
2143 /* Acquire the name */
2146 /* Find the colon before the flavor */
2147 flavor = my_strchr(s, ':');
2149 /* Verify that colon */
2152 /* Nuke the colon, advance to the flavor */
2155 /* Store the flavor */
2156 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2159 /* Store the name */
2160 if (!add_name(&k_ptr->name, head, s)) return (7);
2164 /* Process 'D' for "Description" */
2165 else if (buf[0] == 'D')
2170 /* Acquire the text */
2175 /* Acquire the text */
2179 /* Store the text */
2180 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2183 /* Process 'G' for "Graphics" (one line only) */
2184 else if (buf[0] == 'G')
2188 if (buf[1] != ':') return (1);
2189 if (!buf[2]) return (1);
2190 if (buf[3] != ':') return (1);
2191 if (!buf[4]) return (1);
2193 /* Extract the char */
2196 /* Extract the attr */
2197 tmp = color_char_to_attr(buf[4]);
2198 if (tmp > 127) return (1);
2200 /* Save the values */
2201 k_ptr->d_attr = tmp;
2202 k_ptr->d_char = sym;
2205 /* Process 'I' for "Info" (one line only) */
2206 else if (buf[0] == 'I')
2208 int tval, sval, pval;
2210 /* Scan for the values */
2211 if (3 != sscanf(buf + 2, "%d:%d:%d",
2212 &tval, &sval, &pval)) return (1);
2214 /* Save the values */
2215 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2216 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2217 k_ptr->pval = (PARAMETER_VALUE)pval;
2220 /* Process 'W' for "More Info" (one line only) */
2221 else if (buf[0] == 'W')
2223 int level, extra, wgt;
2226 /* Scan for the values */
2227 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2228 &level, &extra, &wgt, &cost)) return (1);
2230 /* Save the values */
2231 k_ptr->level = (DEPTH)level;
2232 k_ptr->extra = (BIT_FLAGS8)extra;
2233 k_ptr->weight = (WEIGHT)wgt;
2234 k_ptr->cost = (PRICE)cost;
2237 /* Process 'A' for "Allocation" (one line only) */
2238 else if (buf[0] == 'A')
2241 /* Simply read each number following a colon */
2242 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2244 /* Default chance */
2245 k_ptr->chance[i] = 1;
2247 /* Store the attack damage index */
2248 k_ptr->locale[i] = atoi(s + 1);
2250 /* Find the slash */
2251 t = my_strchr(s + 1, '/');
2253 /* Find the next colon */
2254 s = my_strchr(s + 1, ':');
2256 /* If the slash is "nearby", use it */
2257 if (t && (!s || t < s))
2259 int chance = atoi(t + 1);
2260 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2265 /* Hack -- Process 'P' for "power" and such */
2266 else if (buf[0] == 'P')
2268 int ac, hd1, hd2, th, td, ta;
2270 /* Scan for the values */
2271 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2272 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2274 k_ptr->ac = (ARMOUR_CLASS)ac;
2275 k_ptr->dd = (DICE_NUMBER)hd1;
2276 k_ptr->ds = (DICE_SID)hd2;
2277 k_ptr->to_h = (HIT_PROB)th;
2278 k_ptr->to_d = (HIT_POINT)td;
2279 k_ptr->to_a = (ARMOUR_CLASS)ta;
2282 /* Hack -- Process 'U' for activation index */
2283 else if (buf[0] == 'U')
2286 n = grab_one_activation_flag(buf + 2);
2297 /* Hack -- Process 'F' for flags */
2298 else if (buf[0] == 'F')
2300 /* Parse every entry textually */
2301 for (s = buf + 2; *s; )
2303 /* Find the end of this entry */
2304 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2306 /* Nuke and skip any dividers */
2310 while (*t == ' ' || *t == '|') t++;
2313 /* Parse this entry */
2314 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2316 /* Start the next entry */
2330 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2331 * Grab one activation index flag
2332 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2333 * @param what 参照元の文字列ポインタ
2334 * @return エラーがあった場合1、エラーがない場合0を返す
2336 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2341 for (i = 0; i < TR_FLAG_MAX; i++)
2343 if (streq(what, k_info_flags[i]))
2345 add_flag(a_ptr->flags, i);
2350 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2353 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2361 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2362 * Initialize the "a_info" array, by parsing an ascii "template" file
2364 * @param head ヘッダ構造体
2367 errr parse_a_info(char *buf, header *head)
2374 static artifact_type *a_ptr = NULL;
2377 /* Process 'N' for "New/Number/Name" */
2380 /* Find the colon before the name */
2381 s = my_strchr(buf + 2, ':');
2383 /* Verify that colon */
2386 /* Nuke the colon, advance to the name */
2389 /* Paranoia -- require a name */
2390 if (!*s) return (1);
2395 /* Verify information */
2396 if (i < error_idx) return (4);
2398 /* Verify information */
2399 if (i >= head->info_num) return (2);
2401 /* Save the index */
2404 /* Point at the "info" */
2407 /* Ignore everything */
2408 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2409 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2410 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2411 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2413 /* Store the name */
2414 if (!add_name(&a_ptr->name, head, s)) return (7);
2418 /* There better be a current a_ptr */
2419 else if (!a_ptr) return (3);
2424 /* 'E' から始まる行は英語名としている */
2425 else if (buf[0] == 'E')
2430 else if (buf[0] == 'E')
2432 /* Acquire the Text */
2435 /* Store the name */
2436 if (!add_name(&a_ptr->name, head, s)) return (7);
2440 /* Process 'D' for "Description" */
2441 else if (buf[0] == 'D')
2446 /* Acquire the text */
2451 /* Acquire the text */
2455 /* Store the text */
2456 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2460 /* Process 'I' for "Info" (one line only) */
2461 else if (buf[0] == 'I')
2463 int tval, sval, pval;
2465 /* Scan for the values */
2466 if (3 != sscanf(buf + 2, "%d:%d:%d",
2467 &tval, &sval, &pval)) return (1);
2469 /* Save the values */
2470 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2471 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2472 a_ptr->pval = (PARAMETER_VALUE)pval;
2475 /* Process 'W' for "More Info" (one line only) */
2476 else if (buf[0] == 'W')
2478 int level, rarity, wgt;
2481 /* Scan for the values */
2482 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2483 &level, &rarity, &wgt, &cost)) return (1);
2485 /* Save the values */
2486 a_ptr->level = (DEPTH)level;
2487 a_ptr->rarity = (RARITY)rarity;
2488 a_ptr->weight = (WEIGHT)wgt;
2489 a_ptr->cost = (PRICE)cost;
2492 /* Hack -- Process 'P' for "power" and such */
2493 else if (buf[0] == 'P')
2495 int ac, hd1, hd2, th, td, ta;
2497 /* Scan for the values */
2498 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2499 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2501 a_ptr->ac = (ARMOUR_CLASS)ac;
2502 a_ptr->dd = (DICE_NUMBER)hd1;
2503 a_ptr->ds = (DICE_SID)hd2;
2504 a_ptr->to_h = (HIT_PROB)th;
2505 a_ptr->to_d = (HIT_POINT)td;
2506 a_ptr->to_a = (ARMOUR_CLASS)ta;
2509 /* Hack -- Process 'U' for activation index */
2510 else if (buf[0] == 'U')
2513 n = grab_one_activation_flag(buf + 2);
2524 /* Hack -- Process 'F' for flags */
2525 else if (buf[0] == 'F')
2527 /* Parse every entry textually */
2528 for (s = buf + 2; *s; )
2530 /* Find the end of this entry */
2531 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2533 /* Nuke and skip any dividers */
2537 while ((*t == ' ') || (*t == '|')) t++;
2540 /* Parse this entry */
2541 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2543 /* Start the next entry */
2558 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2559 * Grab one flag in a ego-item_type from a textual string
2560 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2561 * @param what 参照元の文字列ポインタ
2562 * @return エラーがあった場合1、エラーがない場合0を返す
2564 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2569 for (i = 0; i < TR_FLAG_MAX; i++)
2571 if (streq(what, k_info_flags[i]))
2573 add_flag(e_ptr->flags, i);
2578 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2581 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2589 * @brief アイテムエゴ情報(e_info)のパース関数 /
2590 * Initialize the "e_info" array, by parsing an ascii "template" file
2592 * @param head ヘッダ構造体
2595 errr parse_e_info(char *buf, header *head)
2601 static ego_item_type *e_ptr = NULL;
2603 /* Just before the first record */
2606 /* Just before the first line */
2609 /* Process 'N' for "New/Number/Name" */
2612 /* Find the colon before the name */
2613 s = my_strchr(buf + 2, ':');
2615 /* Verify that colon */
2618 /* Nuke the colon, advance to the name */
2621 /* Paranoia -- require a name */
2622 if (!*s) return (1);
2627 /* Verify information */
2628 if (i < error_idx) return (4);
2630 /* Verify information */
2631 if (i >= head->info_num) return (2);
2633 /* Save the index */
2636 /* Point at the "info" */
2639 /* Store the name */
2640 if (!add_name(&e_ptr->name, head, s)) return (7);
2644 /* There better be a current e_ptr */
2645 else if (!e_ptr) return (3);
2650 /* 'E' から始まる行は英語名 */
2651 else if (buf[0] == 'E')
2656 else if (buf[0] == 'E')
2658 /* Acquire the Text */
2661 /* Store the name */
2662 if (!add_name(&e_ptr->name, head, s)) return (7);
2667 /* Process 'D' for "Description" */
2668 else if (buf[0] == 'D')
2670 /* Acquire the text */
2673 /* Store the text */
2674 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2679 /* Process 'X' for "Xtra" (one line only) */
2680 else if (buf[0] == 'X')
2684 /* Scan for the values */
2685 if (2 != sscanf(buf + 2, "%d:%d",
2686 &slot, &rating)) return (1);
2688 /* Save the values */
2689 e_ptr->slot = (INVENTORY_IDX)slot;
2690 e_ptr->rating = (PRICE)rating;
2693 /* Process 'W' for "More Info" (one line only) */
2694 else if (buf[0] == 'W')
2696 int level, rarity, pad2;
2699 /* Scan for the values */
2700 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2701 &level, &rarity, &pad2, &cost)) return (1);
2703 /* Save the values */
2704 e_ptr->level = level;
2705 e_ptr->rarity = (RARITY)rarity;
2706 /* e_ptr->weight = wgt; */
2710 /* Hack -- Process 'C' for "creation" */
2711 else if (buf[0] == 'C')
2713 int th, td, ta, pval;
2715 /* Scan for the values */
2716 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2717 &th, &td, &ta, &pval)) return (1);
2719 e_ptr->max_to_h = (HIT_PROB)th;
2720 e_ptr->max_to_d = (HIT_POINT)td;
2721 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2722 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2725 /* Hack -- Process 'U' for activation index */
2726 else if (buf[0] == 'U')
2729 n = grab_one_activation_flag(buf + 2);
2740 /* Hack -- Process 'F' for flags */
2741 else if (buf[0] == 'F')
2743 /* Parse every entry textually */
2744 for (s = buf + 2; *s; )
2746 /* Find the end of this entry */
2747 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2749 /* Nuke and skip any dividers */
2753 while ((*t == ' ') || (*t == '|')) t++;
2756 /* Parse this entry */
2757 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2759 /* Start the next entry */
2772 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2773 * Grab one (basic) flag in a monster_race from a textual string
2774 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2775 * @param what 参照元の文字列ポインタ
2778 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2780 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2783 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2786 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2789 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2792 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2795 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2798 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2801 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2809 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2810 * Grab one (spell) flag in a monster_race from a textual string
2811 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2812 * @param what 参照元の文字列ポインタ
2815 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2817 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2820 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2823 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2826 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2834 * @brief モンスター種族情報(r_info)のパース関数 /
2835 * Initialize the "r_info" array, by parsing an ascii "template" file
2837 * @param head ヘッダ構造体
2840 errr parse_r_info(char *buf, header *head)
2846 static monster_race *r_ptr = NULL;
2849 /* Process 'N' for "New/Number/Name" */
2852 /* Find the colon before the name */
2853 s = my_strchr(buf + 2, ':');
2855 /* Verify that colon */
2858 /* Nuke the colon, advance to the name */
2861 /* Paranoia -- require a name */
2862 if (!*s) return (1);
2867 /* Verify information */
2868 if (i < error_idx) return (4);
2870 /* Verify information */
2871 if (i >= head->info_num) return (2);
2873 /* Save the index */
2876 /* Point at the "info" */
2879 /* Store the name */
2880 if (!add_name(&r_ptr->name, head, s)) return (7);
2884 /* There better be a current r_ptr */
2885 else if (!r_ptr) return (3);
2890 /* 'E' から始まる行は英語名 */
2891 else if (buf[0] == 'E')
2893 /* Acquire the Text */
2896 /* Store the name */
2897 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2900 else if (buf[0] == 'E')
2902 /* Acquire the Text */
2905 /* Store the name */
2906 if (!add_name(&r_ptr->name, head, s)) return (7);
2909 /* Process 'D' for "Description" */
2910 else if (buf[0] == 'D')
2915 /* Acquire the text */
2920 /* Acquire the text */
2924 /* Store the text */
2925 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2928 /* Process 'G' for "Graphics" (one line only) */
2929 else if (buf[0] == 'G')
2933 if (buf[1] != ':') return (1);
2934 if (!buf[2]) return (1);
2935 if (buf[3] != ':') return (1);
2936 if (!buf[4]) return (1);
2938 /* Extract the char */
2941 /* Extract the attr */
2942 tmp = color_char_to_attr(buf[4]);
2943 if (tmp > 127) return (1);
2945 /* Save the values */
2946 r_ptr->d_char = sym;
2947 r_ptr->d_attr = tmp;
2950 /* Process 'I' for "Info" (one line only) */
2951 else if (buf[0] == 'I')
2953 int spd, hp1, hp2, aaf, ac, slp;
2955 /* Scan for the other values */
2956 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2957 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2959 /* Save the values */
2960 r_ptr->speed = (SPEED)spd;
2961 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2962 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2963 r_ptr->aaf = (POSITION)aaf;
2964 r_ptr->ac = (ARMOUR_CLASS)ac;
2965 r_ptr->sleep = (SLEEP_DEGREE)slp;
2968 /* Process 'W' for "More Info" (one line only) */
2969 else if (buf[0] == 'W')
2976 /* Scan for the values */
2977 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2978 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2980 /* Save the values */
2981 r_ptr->level = (DEPTH)lev;
2982 r_ptr->rarity = (RARITY)rar;
2983 r_ptr->extra = (BIT_FLAGS16)pad;
2984 r_ptr->mexp = (EXP)exp;
2985 r_ptr->next_exp = (EXP)nextexp;
2986 r_ptr->next_r_idx = (MONRACE_IDX)nextmon;
2989 /* Process 'R' for "Reinforcement" (up to six lines) */
2990 else if (buf[0] == 'R')
2993 /* Find the next empty blow slot (if any) */
2994 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2996 /* Oops, no more slots */
2997 if (i == 6) return (1);
2999 /* Scan for the values */
3000 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
3001 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
3002 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
3003 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
3006 /* Process 'B' for "Blows" (up to four lines) */
3007 else if (buf[0] == 'B')
3011 /* Find the next empty blow slot (if any) */
3012 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3014 /* Oops, no more slots */
3015 if (i == 4) return (1);
3017 /* Analyze the first field */
3018 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3020 /* Terminate the field (if necessary) */
3021 if (*t == ':') *t++ = '\0';
3023 /* Analyze the method */
3024 for (n1 = 0; r_info_blow_method[n1]; n1++)
3026 if (streq(s, r_info_blow_method[n1])) break;
3029 /* Invalid method */
3030 if (!r_info_blow_method[n1]) return (1);
3032 /* Analyze the second field */
3033 for (s = t; *t && (*t != ':'); t++) /* loop */;
3035 /* Terminate the field (if necessary) */
3036 if (*t == ':') *t++ = '\0';
3038 /* Analyze effect */
3039 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3041 if (streq(s, r_info_blow_effect[n2])) break;
3044 /* Invalid effect */
3045 if (!r_info_blow_effect[n2]) return (1);
3047 /* Analyze the third field */
3048 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3050 /* Terminate the field (if necessary) */
3051 if (*t == 'd') *t++ = '\0';
3053 /* Save the method */
3054 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3056 /* Save the effect */
3057 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3059 /* Extract the damage dice and sides */
3060 r_ptr->blow[i].d_dice = atoi(s);
3061 r_ptr->blow[i].d_side = atoi(t);
3064 /* Process 'F' for "Basic Flags" (multiple lines) */
3065 else if (buf[0] == 'F')
3067 /* Parse every entry */
3068 for (s = buf + 2; *s; )
3070 /* Find the end of this entry */
3071 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3073 /* Nuke and skip any dividers */
3077 while (*t == ' ' || *t == '|') t++;
3080 /* Parse this entry */
3081 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3083 /* Start the next entry */
3088 /* Process 'S' for "Spell Flags" (multiple lines) */
3089 else if (buf[0] == 'S')
3091 /* Parse every entry */
3092 for (s = buf + 2; *s; )
3094 /* Find the end of this entry */
3095 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3097 /* Nuke and skip any dividers */
3101 while ((*t == ' ') || (*t == '|')) t++;
3104 /* Hack -- Read spell frequency */
3105 if (1 == sscanf(s, "1_IN_%d", &i))
3107 /* Extract a "frequency" */
3108 r_ptr->freq_spell = 100 / i;
3110 /* Start at next entry */
3115 /* Parse this entry */
3116 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3118 /* Start the next entry */
3123 /* Process 'A' for "Artifact Flags" (multiple lines) */
3124 else if (buf[0] == 'A')
3126 int id, per, rarity;
3128 /* Find the next empty blow slot (if any) */
3129 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3131 /* Oops, no more slots */
3132 if (i == 4) return (1);
3134 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3135 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3136 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3137 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3140 /* Process 'V' for "Arena power value ratio" */
3141 else if (buf[0] == 'V')
3144 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3145 r_ptr->arena_ratio = (PERCENTAGE)val;
3157 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3158 * Grab one flag for a dungeon type from a textual string
3159 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3160 * @param what 参照元の文字列ポインタ
3163 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3165 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3168 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3175 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3176 * Grab one (basic) flag in a monster_race from a textual string
3177 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3178 * @param what 参照元の文字列ポインタ
3181 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3183 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3186 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3189 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3192 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3195 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3198 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3201 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3204 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3211 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3212 * Grab one (spell) flag in a monster_race from a textual string
3213 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3214 * @param what 参照元の文字列ポインタ
3217 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3219 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3222 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3225 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3228 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3235 * @brief ダンジョン情報(d_info)のパース関数 /
3236 * Initialize the "d_info" array, by parsing an ascii "template" file
3238 * @param head ヘッダ構造体
3241 errr parse_d_info(char *buf, header *head)
3247 static dungeon_type *d_ptr = NULL;
3249 /* Process 'N' for "New/Number/Name" */
3252 /* Find the colon before the name */
3253 s = my_strchr(buf + 2, ':');
3255 /* Verify that colon */
3258 /* Nuke the colon, advance to the name */
3261 /* Paranoia -- require a name */
3262 if (!*s) return (1);
3267 /* Verify information */
3268 if (i < error_idx) return (4);
3270 /* Verify information */
3271 if (i >= head->info_num) return (2);
3273 /* Save the index */
3276 /* Point at the "info" */
3279 /* Store the name */
3280 if (!add_name(&d_ptr->name, head, s)) return (7);
3285 else if (buf[0] == 'E') return (0);
3287 else if (buf[0] == 'E')
3289 /* Acquire the Text */
3292 /* Store the name */
3293 if (!add_name(&d_ptr->name, head, s)) return (7);
3297 /* Process 'D' for "Description */
3298 else if (buf[0] == 'D')
3303 /* Acquire the text */
3308 /* Acquire the text */
3312 /* Store the text */
3313 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3316 /* Process 'W' for "More Info" (one line only) */
3317 else if (buf[0] == 'W')
3319 int min_lev, max_lev;
3321 int min_alloc, max_chance;
3322 int obj_good, obj_great;
3325 /* Scan for the values */
3326 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3327 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3329 /* Save the values */
3330 d_ptr->mindepth = (DEPTH)min_lev;
3331 d_ptr->maxdepth = (DEPTH)max_lev;
3332 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3333 d_ptr->mode = (BIT_FLAGS8)mode;
3334 d_ptr->min_m_alloc_level = min_alloc;
3335 d_ptr->max_m_alloc_chance = max_chance;
3336 d_ptr->obj_good = obj_good;
3337 d_ptr->obj_great = obj_great;
3338 d_ptr->pit = (BIT_FLAGS16)pit;
3339 d_ptr->nest = (BIT_FLAGS16)nest;
3342 /* Process 'P' for "Place Info" */
3343 else if (buf[0] == 'P')
3347 /* Scan for the values */
3348 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3350 /* Save the values */
3355 /* Process 'L' for "fLoor type" (one line only) */
3356 else if (buf[0] == 'L')
3360 /* Scan for the values */
3361 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3363 /* Save the values */
3364 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3366 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3367 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3369 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3371 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3374 /* Process 'A' for "wAll type" (one line only) */
3375 else if (buf[0] == 'A')
3379 /* Scan for the values */
3380 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3382 /* Save the values */
3383 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3385 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3386 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3388 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3391 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3392 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3394 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3395 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3397 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3398 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3400 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3401 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3404 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3405 else if (buf[0] == 'F')
3407 int artif = 0, monst = 0;
3409 /* Parse every entry */
3410 for (s = buf + 2; *s; )
3412 /* Find the end of this entry */
3413 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3415 /* Nuke and skip any dividers */
3419 while (*t == ' ' || *t == '|') t++;
3422 /* Hack -- Read Final Artifact */
3423 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3425 /* Extract a "Final Artifact" */
3426 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3428 /* Start at next entry */
3433 /* Hack -- Read Final Object */
3434 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3436 /* Extract a "Final Artifact" */
3437 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3439 /* Start at next entry */
3444 /* Hack -- Read Artifact Guardian */
3445 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3447 /* Extract a "Artifact Guardian" */
3448 d_ptr->final_guardian = (MONRACE_IDX)monst;
3450 /* Start at next entry */
3455 /* Hack -- Read Special Percentage */
3456 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3458 /* Extract a "Special %" */
3459 d_ptr->special_div = (PROB)monst;
3461 /* Start at next entry */
3466 /* Parse this entry */
3467 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3469 /* Start the next entry */
3474 /* Process 'M' for "Basic Flags" (multiple lines) */
3475 else if (buf[0] == 'M')
3477 /* Parse every entry */
3478 for (s = buf + 2; *s; )
3480 /* Find the end of this entry */
3481 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3483 /* Nuke and skip any dividers */
3487 while (*t == ' ' || *t == '|') t++;
3490 /* Hack -- Read monster symbols */
3491 if (!strncmp(s, "R_CHAR_", 7))
3493 /* Skip "R_CHAR_" */
3497 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3499 /* Start at next entry */
3504 /* Parse this entry */
3505 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3507 /* Start the next entry */
3512 /* Process 'S' for "Spell Flags" (multiple lines) */
3513 else if (buf[0] == 'S')
3515 /* Parse every entry */
3516 for (s = buf + 2; *s; )
3518 /* Find the end of this entry */
3519 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3521 /* Nuke and skip any dividers */
3525 while ((*t == ' ') || (*t == '|')) t++;
3528 /* Hack -- Read spell frequency */
3529 if (1 == sscanf(s, "1_IN_%d", &i))
3531 /* Start at next entry */
3536 /* Parse this entry */
3537 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3539 /* Start the next entry */
3551 #else /* ALLOW_TEMPLATES */
3557 #endif /* ALLOW_TEMPLATES */
3561 * @brief 地形情報の「F:」情報をパースする
3562 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3566 static errr parse_line_feature(char *buf)
3571 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3573 /* Tokenize the line */
3574 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3576 /* Letter to assign */
3577 int index = zz[0][0];
3579 /* Reset the info for the letter */
3580 letter[index].feature = feat_none;
3581 letter[index].monster = 0;
3582 letter[index].object = 0;
3583 letter[index].ego = 0;
3584 letter[index].artifact = 0;
3585 letter[index].trap = feat_none;
3586 letter[index].cave_info = 0;
3587 letter[index].special = 0;
3588 letter[index].random = RANDOM_NONE;
3594 letter[index].special = (s16b)atoi(zz[8]);
3598 if ((zz[7][0] == '*') && !zz[7][1])
3600 letter[index].random |= RANDOM_TRAP;
3604 letter[index].trap = f_tag_to_index(zz[7]);
3605 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3610 if (zz[6][0] == '*')
3612 letter[index].random |= RANDOM_ARTIFACT;
3613 if (zz[6][1]) letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6] + 1);
3615 else if (zz[6][0] == '!')
3617 if (p_ptr->inside_quest)
3619 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3624 letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6]);
3629 if (zz[5][0] == '*')
3631 letter[index].random |= RANDOM_EGO;
3632 if (zz[5][1]) letter[index].ego = (EGO_IDX)atoi(zz[5] + 1);
3636 letter[index].ego = (EGO_IDX)atoi(zz[5]);
3641 if (zz[4][0] == '*')
3643 letter[index].random |= RANDOM_OBJECT;
3644 if (zz[4][1]) letter[index].object = (OBJECT_IDX)atoi(zz[4] + 1);
3646 else if (zz[4][0] == '!')
3648 if (p_ptr->inside_quest)
3650 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3653 artifact_type *a_ptr = &a_info[a_idx];
3654 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3656 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3663 letter[index].object = (IDX)atoi(zz[4]);
3668 if (zz[3][0] == '*')
3670 letter[index].random |= RANDOM_MONSTER;
3671 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3673 else if (zz[3][0] == 'c')
3675 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3676 letter[index].monster = -atoi(zz[3] + 1);
3680 letter[index].monster = (IDX)atoi(zz[3]);
3685 letter[index].cave_info = atoi(zz[2]);
3689 if ((zz[1][0] == '*') && !zz[1][1])
3691 letter[index].random |= RANDOM_FEATURE;
3695 letter[index].feature = f_tag_to_index(zz[1]);
3696 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3709 * @brief 地形情報の「B:」情報をパースする
3710 * Process "B:<Index>:<Command>:..." -- Building definition
3714 static errr parse_line_building(char *buf)
3730 /* Get the building number */
3733 /* Find the colon after the building number */
3734 s = my_strchr(s, ':');
3736 /* Verify that colon */
3739 /* Nuke the colon, advance to the sub-index */
3742 /* Paranoia -- require a sub-index */
3743 if (!*s) return (1);
3745 /* Building definition sub-index */
3748 /* Building name, owner, race */
3751 if (tokenize(s + 2, 3, zz, 0) == 3)
3753 /* Name of the building */
3754 strcpy(building[index].name, zz[0]);
3756 /* Name of the owner */
3757 strcpy(building[index].owner_name, zz[1]);
3759 /* Race of the owner */
3760 strcpy(building[index].owner_race, zz[2]);
3765 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3768 /* Building Action */
3771 if (tokenize(s + 2, 8, zz, 0) >= 7)
3773 /* Index of the action */
3774 int action_index = atoi(zz[0]);
3776 /* Name of the action */
3777 strcpy(building[index].act_names[action_index], zz[1]);
3779 /* Cost of the action for members */
3780 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3782 /* Cost of the action for non-members */
3783 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3785 /* Letter assigned to the action */
3786 building[index].letters[action_index] = zz[4][0];
3789 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3791 /* Action restriction */
3792 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3797 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3800 /* Building Classes */
3804 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3805 for (i = 0; i < MAX_CLASS; i++)
3807 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3812 /* Building Races */
3816 n = tokenize(s + 2, MAX_RACES, zz, 0);
3817 for (i = 0; i < MAX_RACES; i++)
3819 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3824 /* Building Realms */
3828 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3829 for (i = 0; i < MAX_MAGIC; i++)
3831 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3838 /* Ignore scripts */
3844 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3853 * @brief フロアの所定のマスにオブジェクトを配置する
3854 * Place the object j_ptr to a grid
3855 * @param j_ptr オブジェクト構造体の参照ポインタ
3860 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3862 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3865 OBJECT_IDX o_idx = o_pop();
3867 /* Access new object */
3868 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3870 /* Structure copy */
3871 object_copy(o_ptr, j_ptr);
3878 o_ptr->held_m_idx = 0;
3881 o_ptr->next_o_idx = g_ptr->o_idx;
3883 g_ptr->o_idx = o_idx;
3887 * @brief クエスト用固定ダンジョンをフロアに生成する
3888 * Parse a sub-file of the "extra info"
3898 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3903 /* Skip "empty" lines */
3904 if (!buf[0]) return (0);
3906 /* Skip "blank" lines */
3907 if (iswspace(buf[0])) return (0);
3910 if (buf[0] == '#') return (0);
3912 /* Require "?:*" format */
3913 if (buf[1] != ':') return (1);
3916 /* Process "%:<fname>" */
3919 /* Attempt to Process the given file */
3920 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3923 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3926 return parse_line_feature(buf);
3929 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3930 else if (buf[0] == 'D')
3932 object_type object_type_body;
3934 /* Acquire the text */
3937 /* Length of the text */
3938 int len = strlen(s);
3940 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3942 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3944 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3948 OBJECT_IDX object_index = letter[idx].object;
3949 MONSTER_IDX monster_index = letter[idx].monster;
3950 int random = letter[idx].random;
3951 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3953 /* Lay down a floor */
3954 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3956 /* Only the features */
3957 if (init_flags & INIT_ONLY_FEATURES) continue;
3960 g_ptr->info = letter[idx].cave_info;
3962 /* Create a monster */
3963 if (random & RANDOM_MONSTER)
3965 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3967 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3969 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3971 else if (monster_index)
3973 int old_cur_num, old_max_num;
3976 if (monster_index < 0)
3978 monster_index = -monster_index;
3981 old_cur_num = r_info[monster_index].cur_num;
3982 old_max_num = r_info[monster_index].max_num;
3984 /* Make alive again */
3985 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3987 r_info[monster_index].cur_num = 0;
3988 r_info[monster_index].max_num = 1;
3991 /* Make alive again */
3992 /* Hack -- Non-unique Nazguls are semi-unique */
3993 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3995 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3997 r_info[monster_index].max_num++;
4002 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4006 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
4008 /* Make alive again for real unique monster */
4009 r_info[monster_index].cur_num = old_cur_num;
4010 r_info[monster_index].max_num = old_max_num;
4014 /* Object (and possible trap) */
4015 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4017 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4020 * Random trap and random treasure defined
4021 * 25% chance for trap and 75% chance for object
4023 if (randint0(100) < 75)
4025 place_object(*y, *x, 0L);
4032 current_floor_ptr->object_level = current_floor_ptr->base_level;
4034 else if (random & RANDOM_OBJECT)
4036 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4038 /* Create an out of deep object */
4039 if (randint0(100) < 75)
4040 place_object(*y, *x, 0L);
4041 else if (randint0(100) < 80)
4042 place_object(*y, *x, AM_GOOD);
4044 place_object(*y, *x, AM_GOOD | AM_GREAT);
4046 current_floor_ptr->object_level = current_floor_ptr->base_level;
4049 else if (random & RANDOM_TRAP)
4053 /* Hidden trap (or door) */
4054 else if (letter[idx].trap)
4056 g_ptr->mimic = g_ptr->feat;
4057 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4059 else if (object_index)
4061 object_type *o_ptr = &object_type_body;
4062 object_prep(o_ptr, object_index);
4064 if (o_ptr->tval == TV_GOLD)
4066 coin_type = object_index - OBJ_GOLD_LIST;
4071 /* Apply magic (no messages, no artifacts) */
4072 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4074 drop_here(o_ptr, *y, *x);
4080 if (a_info[artifact_index].cur_num)
4082 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4084 object_type *q_ptr = &forge;
4086 object_prep(q_ptr, k_idx);
4087 drop_here(q_ptr, *y, *x);
4091 if (create_named_art(artifact_index, *y, *x))
4092 a_info[artifact_index].cur_num = 1;
4096 /* Terrain special */
4097 g_ptr->special = letter[idx].special;
4105 /* Process "Q:<number>:<command>:... -- quest info */
4106 else if (buf[0] == 'Q')
4113 num = tokenize(buf + 2, 33, zz, 0);
4117 num = tokenize(buf + 3, 33, zz, 0);
4120 /* Have we enough parameters? */
4121 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4124 q_ptr = &(quest[atoi(zz[0])]);
4126 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4127 if (zz[1][0] == 'Q')
4129 if (init_flags & INIT_ASSIGN)
4131 monster_race *r_ptr;
4132 artifact_type *a_ptr;
4134 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4136 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4137 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4138 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4139 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4140 q_ptr->level = (DEPTH)atoi(zz[6]);
4141 q_ptr->r_idx = (IDX)atoi(zz[7]);
4142 q_ptr->k_idx = (IDX)atoi(zz[8]);
4143 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4145 if (num > 10) q_ptr->flags = atoi(zz[10]);
4147 r_ptr = &r_info[q_ptr->r_idx];
4148 if (r_ptr->flags1 & RF1_UNIQUE)
4149 r_ptr->flags1 |= RF1_QUESTOR;
4151 a_ptr = &a_info[q_ptr->k_idx];
4152 a_ptr->gen_flags |= TRG_QUESTITEM;
4157 else if (zz[1][0] == 'R')
4159 if (init_flags & INIT_ASSIGN)
4162 IDX idx, reward_idx = 0;
4164 for (idx = 2; idx < num; idx++)
4166 IDX a_idx = (IDX)atoi(zz[idx]);
4167 if (a_idx < 1) continue;
4168 if (a_info[a_idx].cur_num > 0) continue;
4170 if (one_in_(count)) reward_idx = a_idx;
4175 /* Set quest's rewarding artifact */
4176 q_ptr->k_idx = reward_idx;
4177 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4181 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4182 q_ptr->type = QUEST_TYPE_KILL_ALL;
4189 /* Process "Q:<q_index>:N:<name>" -- quest name */
4190 else if (zz[1][0] == 'N')
4192 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4194 strcpy(q_ptr->name, zz[2]);
4200 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4201 else if (zz[1][0] == 'T')
4203 if (init_flags & INIT_SHOW_TEXT)
4205 strcpy(quest_text[quest_text_line], zz[2]);
4213 /* Process "W:<command>: ..." -- info for the wilderness */
4214 else if (buf[0] == 'W')
4216 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4219 /* Process "P:<y>:<x>" -- player position */
4220 else if (buf[0] == 'P')
4222 if (init_flags & INIT_CREATE_DUNGEON)
4224 if (tokenize(buf + 2, 2, zz, 0) == 2)
4226 int panels_x, panels_y;
4228 /* Hack - Set the dungeon size */
4229 panels_y = (*y / SCREEN_HGT);
4230 if (*y % SCREEN_HGT) panels_y++;
4231 current_floor_ptr->height = panels_y * SCREEN_HGT;
4233 panels_x = (*x / SCREEN_WID);
4234 if (*x % SCREEN_WID) panels_x++;
4235 current_floor_ptr->width = panels_x * SCREEN_WID;
4237 /* Assume illegal panel */
4238 panel_row_min = current_floor_ptr->height;
4239 panel_col_min = current_floor_ptr->width;
4241 /* Place player in a quest level */
4242 if (p_ptr->inside_quest)
4246 /* Delete the monster (if any) */
4247 delete_monster(p_ptr->y, p_ptr->x);
4255 /* Place player in the town */
4256 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4258 p_ptr->oldpy = atoi(zz[0]);
4259 p_ptr->oldpx = atoi(zz[1]);
4267 /* Process "B:<Index>:<Command>:..." -- Building definition */
4268 else if (buf[0] == 'B')
4270 return parse_line_building(buf);
4273 /* Process "M:<type>:<maximum>" -- set maximum values */
4274 else if (buf[0] == 'M')
4276 if (tokenize(buf + 2, 2, zz, 0) == 2)
4279 if (zz[0][0] == 'T')
4281 max_towns = (TOWN_IDX)atoi(zz[1]);
4284 /* Maximum quests */
4285 else if (zz[0][0] == 'Q')
4287 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4291 else if (zz[0][0] == 'R')
4293 max_r_idx = (RACE_IDX)atoi(zz[1]);
4297 else if (zz[0][0] == 'K')
4299 max_k_idx = (KIND_OBJECT_IDX)atoi(zz[1]);
4303 else if (zz[0][0] == 'V')
4305 max_v_idx = (VAULT_IDX)atoi(zz[1]);
4309 else if (zz[0][0] == 'F')
4311 max_f_idx = (FEAT_IDX)atoi(zz[1]);
4315 else if (zz[0][0] == 'A')
4317 max_a_idx = (ARTIFACT_IDX)atoi(zz[1]);
4321 else if (zz[0][0] == 'E')
4323 max_e_idx = (EGO_IDX)atoi(zz[1]);
4327 else if (zz[0][0] == 'D')
4329 max_d_idx = (DUNGEON_IDX)atoi(zz[1]);
4333 else if (zz[0][0] == 'O')
4335 current_floor_ptr->max_o_idx = (OBJECT_IDX)atoi(zz[1]);
4339 else if (zz[0][0] == 'M')
4341 current_floor_ptr->max_m_idx = (MONSTER_IDX)atoi(zz[1]);
4344 /* Wilderness size */
4345 else if (zz[0][0] == 'W')
4347 /* Maximum wild_x_size */
4348 if (zz[0][1] == 'X')
4349 current_world_ptr->max_wild_x = (POSITION)atoi(zz[1]);
4350 /* Maximum wild_y_size */
4351 if (zz[0][1] == 'Y')
4352 current_world_ptr->max_wild_y = (POSITION)atoi(zz[1]);
4366 static concptr variant = "ZANGBAND";
4370 * @brief クエスト用固定ダンジョン生成時の分岐処理
4371 * Helper function for "process_dungeon_file()"
4376 static concptr process_dungeon_file_expr(char **sp, char *fp)
4392 while (iswspace(*s)) s++;
4410 t = process_dungeon_file_expr(&s, &f);
4418 else if (streq(t, "IOR"))
4421 while (*s && (f != b2))
4423 t = process_dungeon_file_expr(&s, &f);
4424 if (*t && !streq(t, "0")) v = "1";
4429 else if (streq(t, "AND"))
4432 while (*s && (f != b2))
4434 t = process_dungeon_file_expr(&s, &f);
4435 if (*t && streq(t, "0")) v = "0";
4440 else if (streq(t, "NOT"))
4443 while (*s && (f != b2))
4445 t = process_dungeon_file_expr(&s, &f);
4446 if (*t && streq(t, "1")) v = "0";
4451 else if (streq(t, "EQU"))
4454 if (*s && (f != b2))
4456 t = process_dungeon_file_expr(&s, &f);
4458 while (*s && (f != b2))
4460 p = process_dungeon_file_expr(&s, &f);
4461 if (streq(t, p)) v = "1";
4466 else if (streq(t, "LEQ"))
4469 if (*s && (f != b2))
4471 t = process_dungeon_file_expr(&s, &f);
4473 while (*s && (f != b2))
4476 t = process_dungeon_file_expr(&s, &f);
4477 if (*t && atoi(p) > atoi(t)) v = "0";
4482 else if (streq(t, "GEQ"))
4485 if (*s && (f != b2))
4487 t = process_dungeon_file_expr(&s, &f);
4489 while (*s && (f != b2))
4492 t = process_dungeon_file_expr(&s, &f);
4494 /* Compare two numbers instead of string */
4495 if (*t && atoi(p) < atoi(t)) v = "0";
4501 while (*s && (f != b2))
4503 t = process_dungeon_file_expr(&s, &f);
4508 if (f != b2) v = "?x?x?";
4510 /* Extract final and Terminate */
4511 if ((f = *s) != '\0') *s++ = '\0';
4517 /* Accept all printables except spaces and brackets */
4519 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4521 if (iskanji(*s)) s++;
4525 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4528 /* Extract final and Terminate */
4529 if ((f = *s) != '\0') *s++ = '\0';
4535 if (streq(b + 1, "SYS"))
4541 else if (streq(b + 1, "GRAF"))
4546 else if (streq(b + 1, "MONOCHROME"))
4555 else if (streq(b + 1, "RACE"))
4557 v = _(rp_ptr->E_title, rp_ptr->title);
4561 else if (streq(b + 1, "CLASS"))
4563 v = _(cp_ptr->E_title, cp_ptr->title);
4567 else if (streq(b + 1, "REALM1"))
4569 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4573 else if (streq(b + 1, "REALM2"))
4575 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4579 else if (streq(b + 1, "PLAYER"))
4581 static char tmp_player_name[32];
4583 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4593 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4596 v = tmp_player_name;
4600 else if (streq(b + 1, "TOWN"))
4602 sprintf(tmp, "%d", p_ptr->town_num);
4607 else if (streq(b + 1, "LEVEL"))
4609 sprintf(tmp, "%d", p_ptr->lev);
4613 /* Current quest number */
4614 else if (streq(b + 1, "QUEST_NUMBER"))
4616 sprintf(tmp, "%d", p_ptr->inside_quest);
4620 /* Number of last quest */
4621 else if (streq(b + 1, "LEAVING_QUEST"))
4623 sprintf(tmp, "%d", leaving_quest);
4628 else if (prefix(b + 1, "QUEST_TYPE"))
4630 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4631 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4636 else if (prefix(b + 1, "QUEST"))
4638 /* "QUEST" uses a special parameter to determine the number of the quest */
4639 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4644 else if (prefix(b + 1, "RANDOM"))
4646 /* "RANDOM" uses a special parameter to determine the number of the quest */
4647 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
4652 else if (streq(b + 1, "VARIANT"))
4658 else if (streq(b + 1, "WILDERNESS"))
4661 sprintf(tmp, "NONE");
4663 sprintf(tmp, "LITE");
4665 sprintf(tmp, "NORMAL");
4684 void write_r_info_txt(void)
4686 int i, j, z, fc, bc;
4689 concptr flags[32 * 10];
4694 monster_race *r_ptr;
4696 monster_blow *b_ptr;
4698 FILE *fff = fopen("output.txt", "wt");
4702 BIT_FLAGS mode = -1;
4706 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4708 fprintf(fff, "# Version stamp (required)\n\n");
4711 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4714 fprintf(fff, "##### The Player #####\n\n");
4716 for (z = -1; z < alloc_race_size; z++)
4718 /* Output the monsters in order */
4719 i = (z >= 0) ? alloc_race_table[z].index : 0;
4721 /* Acquire the monster */
4724 /* Ignore empty monsters */
4725 if (!strlen(r_name + r_ptr->name)) continue;
4727 /* Ignore useless monsters */
4728 if (i && !r_ptr->speed) continue;
4730 /* Write a note if necessary */
4731 if (i && (!r_ptr->level != !mode))
4736 fprintf(fff, "\n##### Town monsters #####\n\n");
4738 /* Note the dungeon */
4741 fprintf(fff, "\n##### Normal monsters #####\n\n");
4744 /* Record the change */
4745 mode = r_ptr->level;
4748 /* Acquire the flags */
4749 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4750 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4751 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4752 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4753 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4754 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4755 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4756 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4757 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4758 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4760 /* Write New/Number/Name */
4761 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4764 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4766 /* Write Information */
4767 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4768 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4770 /* Write more information */
4771 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4774 for (j = 0; j < 4; j++)
4776 b_ptr = &(r_ptr->blow[j]);
4778 /* Stop when done */
4779 if (!b_ptr->method) break;
4781 /* Write the blows */
4782 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4783 r_info_blow_effect[b_ptr->effect],
4784 b_ptr->d_dice, b_ptr->d_side);
4786 for (fc = 0, j = 0; j < 32 * 3; j++)
4788 /* Check this flag */
4789 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4792 /* Extract the extra flags */
4793 for (j = 32 * 6; j < 32 * 10; j++)
4795 /* Check this flag */
4796 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4799 /* Write the flags */
4800 for (j = 0; j < fc;)
4804 /* Start the line */
4807 for (bc = 0; (bc < 60) && (j < fc); j++)
4811 /* Format the flag */
4812 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4814 /* Add it to the buffer */
4817 /* Note the length */
4821 /* Done with this line; write it */
4822 fprintf(fff, "%s\n", buf);
4825 /* Write Spells if applicable */
4826 if (r_ptr->freq_spell)
4828 /* Write the frequency */
4829 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4831 /* Extract the spell flags */
4832 for (fc = 0, j = 96; j < 192; j++)
4834 /* Check this flag */
4835 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4838 /* Write the flags */
4839 for (j = 0; j < fc;)
4843 /* Start the line */
4846 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4850 /* Format the flag */
4851 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4855 /* Note the length */
4862 /* Done with this line; write it */
4863 fprintf(fff, "%s\n", buf);
4867 /* Acquire the description */
4868 desc = r_text + r_ptr->text;
4869 dlen = strlen(desc);
4871 /* Write Description */
4872 for (j = 0; j < dlen;)
4876 /* Start the line */
4879 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4887 /* Done with this line; write it */
4888 fprintf(fff, "%s\n", buf);
4891 /* Space between entries */
4902 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4903 * Helper function for "process_dungeon_file()"
4911 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4917 bool bypass = FALSE;
4918 int x = xmin, y = ymin;
4920 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4923 fp = my_fopen(buf, "r");
4926 if (!fp) return (-1);
4929 /* Process the file */
4930 while (0 == my_fgets(fp, buf, sizeof(buf)))
4936 /* Skip "empty" lines */
4937 if (!buf[0]) continue;
4939 /* Skip "blank" lines */
4940 if (iswspace(buf[0])) continue;
4943 if (buf[0] == '#') continue;
4946 /* Process "?:<expr>" */
4947 if ((buf[0] == '?') && (buf[1] == ':'))
4956 /* Parse the expr */
4957 v = process_dungeon_file_expr(&s, &f);
4960 bypass = (streq(v, "0") ? TRUE : FALSE);
4964 /* Apply conditionals */
4965 if (bypass) continue;
4967 /* Process the line */
4968 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4979 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4981 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4982 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);