5 #include "dungeon-file.h"
11 #include "player-skill.h"
15 dungeon_grid letter[255];
19 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
23 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
24 * This software may be copied and distributed for educational, research,
25 * and not for profit purposes provided that this copyright and statement
26 * are included in all such copies. Other copyrights may also apply.
27 * 2014 Deskull rearranged comment for Doxygen.\n
31 * This file is used to initialize various variables and arrays for the
32 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
33 * the common limitation of "read()" and "write()" to only 32767 bytes
35 * Several of the arrays for Angband are built from "template" files in
36 * the "lib/file" directory, from which quick-load binary "image" files
37 * are constructed whenever they are not present in the "lib/data"
38 * directory, or if those files become obsolete, if we are allowed.
39 * Warning -- the "ascii" file parsers use a minor hack to collect the
40 * name and text information in a single pass. Thus, the game will not
41 * be able to load any template file with more than 20K of names or 60K
42 * of text, even though technically, up to 64K should be legal.
44 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
45 * in this file is compiled out, and the game will not run unless valid
46 * "binary template files" already exist in "lib/data". Thus, one can
47 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
48 * "*.raw" files in "lib/data", and then quit, and recompile without
49 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
50 * from changing the ascii template files in potentially dangerous ways.
51 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
52 * このファイルのコードの多くはコンパイル出力され、本ゲームは
53 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
54 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
55 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
56 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
57 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
58 * テンプレートファイルを変更することを妨げることができる。
59 * The code could actually be removed and placed into a "stand-alone"
60 * program, but that feels a little silly, especially considering some
61 * of the platforms that we currently support.
66 #include "dungeon-file.h"
71 #include "cmd-activate.h"
75 #include "view-mainwindow.h"
79 #ifdef ALLOW_TEMPLATES
84 /*** Helper arrays for parsing ascii template files ***/
88 * Monster Blow Methods
90 static concptr r_info_blow_method[] =
123 * モンスターの打撃属性トークンの定義 /
124 * Monster Blow Effects
126 static concptr r_info_blow_effect[] =
171 static concptr f_info_flags[] =
296 static concptr r_info_flags1[] =
336 static concptr r_info_flags2[] =
376 static concptr r_info_flags3[] =
416 static concptr r_info_flags4[] =
453 * モンスター特性トークン(発動型能力1) /
456 static concptr r_a_ability_flags1[] =
493 * モンスター特性トークン(発動型能力2) /
496 static concptr r_a_ability_flags2[] =
513 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
534 * モンスター特性トークン(発動型能力3) /
537 static concptr r_a_ability_flags3[] =
576 * モンスター特性トークン(発動型能力4) /
579 static concptr r_a_ability_flags4[] =
621 static concptr r_info_flags7[] =
661 static concptr r_info_flags8[] =
693 "WILD_SWAMP", /* ToDo: Implement Swamp */
702 static concptr r_info_flags9[] =
741 * モンスター特性トークンの定義R(耐性) /
744 static concptr r_info_flagsr[] =
782 * オブジェクト基本特性トークンの定義 /
785 static concptr k_info_flags[] =
882 "XXX3", /* Fake flag for Smith */
883 "XXX4", /* Fake flag for Smith */
933 * オブジェクト生成特性トークンの定義 /
936 static concptr k_info_gen_flags[] =
976 static concptr d_info_flags1[] =
1014 * @brief データの可変文字列情報をテキストとして保管する /
1015 * Add a text to the text-storage and store offset to it.
1016 * @param offset 文字列保管ポインタからのオフセット
1017 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1019 * @param normal_text テキストの正規化を行う
1022 * Returns FALSE when there isn't enough space available to store
1025 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1027 /* Hack -- Verify space */
1028 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1034 /* Advance and save the text index */
1035 *offset = ++head->text_size;
1038 /* Additional text */
1039 else if (normal_text)
1042 * If neither the end of the last line nor
1043 * the beginning of current line is not a space,
1044 * fill up a space as a correct separator of two words.
1046 if (head->text_size > 0 &&
1048 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1049 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1050 (buf[0] != ' ') && !iskanji(buf[0])
1052 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1057 /* Append a space */
1058 *(head->text_ptr + head->text_size) = ' ';
1060 /* Advance the index */
1065 /* Append chars to the text */
1066 strcpy(head->text_ptr + head->text_size, buf);
1068 /* Advance the index */
1069 head->text_size += strlen(buf);
1077 * @brief データの可変文字列情報を名前として保管する /
1078 * Add a name to the name-storage and return an offset to it.
1079 * @param offset 文字列保管ポインタからのオフセット
1080 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1084 * Returns FALSE when there isn't enough space available to store
1087 static bool add_name(u32b *offset, header *head, concptr buf)
1089 /* Hack -- Verify space */
1090 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1096 /* Advance and save the name index */
1097 *offset = ++head->name_size;
1100 /* Append chars to the names */
1101 strcpy(head->name_ptr + head->name_size, buf);
1103 /* Advance the index */
1104 head->name_size += strlen(buf);
1112 * @brief データの可変文字列情報をタグとして保管する /
1113 * Add a tag to the tag-storage and return an offset to it.
1114 * @param offset 文字列保管ポインタからのオフセット
1115 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1119 * Returns FALSE when there isn't enough space available to store
1122 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1126 /* Search for an existing (fake) tag */
1127 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1130 if (streq(&head->tag_ptr[i], buf)) break;
1133 /* There was no existing tag */
1134 if (i >= head->tag_size)
1136 /* Hack -- Verify space */
1137 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1140 /* Append chars to the tags */
1141 strcpy(head->tag_ptr + head->tag_size, buf);
1143 /* Point the new tag */
1146 /* Advance the index */
1147 head->tag_size += strlen(buf) + 1;
1150 /* Return offset of the tag */
1158 /*** Initialize from ascii template files ***/
1162 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1163 * Initialize an "*_info" array, by parsing an ascii "template" file
1164 * @param fp 読み取りに使うファイルポインタ
1165 * @param buf 読み取りに使うバッファ領域
1166 * @param head ヘッダ構造体
1167 * @param parse_info_txt_line パース関数
1170 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1174 /* Just before the first record */
1177 /* Just before the first line */
1181 /* Prepare the "fake" stuff */
1182 head->name_size = 0;
1183 head->text_size = 0;
1187 while (0 == my_fgets(fp, buf, 1024))
1189 /* Advance the line number */
1192 /* Skip comments and blank lines */
1193 if (!buf[0] || (buf[0] == '#')) continue;
1195 /* Verify correct "colon" format */
1196 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1199 /* Hack -- Process 'V' for "Version" */
1206 /* Mega Hack -- Calculate Check Sum */
1207 if (buf[0] != 'N' && buf[0] != 'D')
1210 for (i = 0; buf[i]; i++)
1212 head->v_extra += (byte)buf[i];
1213 head->v_extra ^= (1 << (i % 8));
1217 /* Parse the line */
1218 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1223 /* Complete the "name" and "text" sizes */
1224 if (head->name_size) head->name_size++;
1225 if (head->text_size) head->text_size++;
1233 * @brief Vault情報(v_info)のパース関数 /
1234 * Initialize the "v_info" array, by parsing an ascii "template" file
1236 * @param head ヘッダ構造体
1239 errr parse_v_info(char *buf, header *head)
1245 static vault_type *v_ptr = NULL;
1247 /* Process 'N' for "New/Number/Name" */
1250 /* Find the colon before the name */
1251 s = my_strchr(buf + 2, ':');
1253 /* Verify that colon */
1256 /* Nuke the colon, advance to the name */
1259 /* Paranoia -- require a name */
1260 if (!*s) return (1);
1265 /* Verify information */
1266 if (i <= error_idx) return (4);
1268 /* Verify information */
1269 if (i >= head->info_num) return (2);
1271 /* Save the index */
1274 /* Point at the "info" */
1277 /* Store the name */
1278 if (!add_name(&v_ptr->name, head, s)) return (7);
1281 /* There better be a current v_ptr */
1282 else if (!v_ptr) return (3);
1284 /* Process 'D' for "Description" */
1285 else if (buf[0] == 'D')
1287 /* Acquire the text */
1290 /* Store the text */
1291 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1294 /* Process 'X' for "Extra info" (one line only) */
1295 else if (buf[0] == 'X')
1297 EFFECT_ID typ, rat, hgt, wid;
1299 /* Scan for the values */
1300 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1301 &typ, &rat, &hgt, &wid)) return (1);
1303 /* Save the values */
1304 v_ptr->typ = (ROOM_IDX)typ;
1305 v_ptr->rat = (PROB)rat;
1306 v_ptr->hgt = (POSITION)hgt;
1307 v_ptr->wid = (POSITION)wid;
1318 * @brief 職業技能情報(s_info)のパース関数 /
1319 * Initialize the "s_info" array, by parsing an ascii "template" file
1321 * @param head ヘッダ構造体
1324 errr parse_s_info(char *buf, header *head)
1329 static skill_table *s_ptr = NULL;
1332 /* Process 'N' for "New/Number/Name" */
1338 /* Verify information */
1339 if (i <= error_idx) return (4);
1341 /* Verify information */
1342 if (i >= head->info_num) return (2);
1344 /* Save the index */
1347 /* Point at the "info" */
1351 /* There better be a current s_ptr */
1352 else if (!s_ptr) return (3);
1354 /* Process 'W' for "Weapon exp" */
1355 else if (buf[0] == 'W')
1357 int tval, sval, start, max;
1358 const s16b exp_conv_table[] =
1360 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1361 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1364 /* Scan for the values */
1365 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1366 &tval, &sval, &start, &max)) return (1);
1368 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1369 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1371 /* Save the values */
1372 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1373 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1376 /* Process 'S' for "Skill exp" */
1377 else if (buf[0] == 'S')
1379 int num, start, max;
1381 /* Scan for the values */
1382 if (3 != sscanf(buf + 2, "%d:%d:%d",
1383 &num, &start, &max)) return (1);
1385 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1386 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1388 /* Save the values */
1389 s_ptr->s_start[num] = (SUB_EXP)start;
1390 s_ptr->s_max[num] = (SUB_EXP)max;
1402 * @brief 職業魔法情報(m_info)のパース関数 /
1403 * Initialize the "m_info" array, by parsing an ascii "template" file
1405 * @param head ヘッダ構造体
1408 errr parse_m_info(char *buf, header *head)
1415 static player_magic *m_ptr = NULL;
1418 static int realm, magic_idx = 0, readable = 0;
1421 /* Process 'N' for "New/Number/Name" */
1427 /* Verify information */
1428 if (i <= error_idx) return (4);
1430 /* Verify information */
1431 if (i >= head->info_num) return (2);
1433 /* Save the index */
1436 /* Point at the "info" */
1440 /* There better be a current m_ptr */
1441 else if (!m_ptr) return (3);
1443 /* Process 'I' for "Info" (one line only) */
1444 else if (buf[0] == 'I')
1447 int xtra, type, first, weight;
1449 /* Find the colon before the name */
1450 s = my_strchr(buf + 2, ':');
1452 /* Verify that colon */
1455 /* Nuke the colon, advance to the name */
1460 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1461 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1462 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1463 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1464 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1469 /* Find the colon before the name */
1470 s = my_strchr(s, ':');
1472 /* Verify that colon */
1475 /* Nuke the colon, advance to the name */
1478 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1479 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1480 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1481 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1482 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1483 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1487 /* Scan for the values */
1488 if (4 != sscanf(s, "%x:%d:%d:%d",
1489 (uint *)&xtra, &type, &first, &weight)) return (1);
1491 m_ptr->spell_xtra = xtra;
1492 m_ptr->spell_type = type;
1493 m_ptr->spell_first = first;
1494 m_ptr->spell_weight = weight;
1498 /* Process 'R' for "Realm" (one line only) */
1499 else if (buf[0] == 'R')
1501 /* Scan for the values */
1502 if (2 != sscanf(buf + 2, "%d:%d",
1503 &realm, &readable)) return (1);
1508 else if (buf[0] == 'T')
1510 int level, mana, fail, exp;
1512 if (!readable) return (1);
1513 /* Scan for the values */
1514 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1515 &level, &mana, &fail, &exp)) return (1);
1517 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1518 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1519 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1520 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1533 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1534 * Grab one flag from a textual string
1535 * @param flags ビットフラグを追加する先の参照ポインタ
1536 * @param names トークン定義配列
1537 * @param what 参照元の文字列ポインタ
1540 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1545 for (i = 0; i < 32; i++)
1547 if (streq(what, names[i]))
1549 *flags |= (1L << i);
1559 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1560 * Grab one flag in an feature_type from a textual string
1561 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1562 * @param what 参照元の文字列ポインタ
1565 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1570 for (i = 0; i < FF_FLAG_MAX; i++)
1572 if (streq(what, f_info_flags[i]))
1574 add_flag(f_ptr->flags, i);
1579 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1582 return PARSE_ERROR_GENERIC;
1587 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1588 * Grab an action in an feature_type from a textual string
1589 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1590 * @param what 参照元の文字列ポインタ
1591 * @param count ステートの保存先ID
1594 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1599 for (i = 0; i < FF_FLAG_MAX; i++)
1601 if (streq(what, f_info_flags[i]))
1603 f_ptr->state[count].action = i;
1608 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1611 return PARSE_ERROR_GENERIC;
1616 * @brief 地形情報(f_info)のパース関数 /
1617 * Initialize the "f_info" array, by parsing an ascii "template" file
1619 * @param head ヘッダ構造体
1622 errr parse_f_info(char *buf, header *head)
1629 static feature_type *f_ptr = NULL;
1632 /* Process 'N' for "New/Number/Name" */
1635 /* Find the colon before the name */
1636 s = my_strchr(buf + 2, ':');
1640 /* Nuke the colon, advance to the name */
1647 /* Verify information */
1648 if (i <= error_idx) return (4);
1650 /* Verify information */
1651 if (i >= head->info_num) return (2);
1653 /* Save the index */
1656 /* Point at the "info" */
1659 /* Tag name is given */
1663 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1666 /* Default "mimic" */
1667 f_ptr->mimic = (FEAT_IDX)i;
1669 /* Default "destroyed state" -- if not specified */
1670 f_ptr->destroyed = (FEAT_IDX)i;
1672 /* Default "states" */
1673 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1676 /* There better be a current f_ptr */
1677 else if (!f_ptr) return (3);
1680 else if (buf[0] == 'J')
1682 /* Store the name */
1683 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1686 else if (buf[0] == 'E')
1688 /* Ignore english name */
1691 else if (buf[0] == 'J')
1693 /* Ignore Japanese name */
1696 else if (buf[0] == 'E')
1698 /* Acquire the Text */
1701 /* Store the name */
1702 if (!add_name(&f_ptr->name, head, s)) return (7);
1707 /* Process 'M' for "Mimic" (one line only) */
1708 else if (buf[0] == 'M')
1712 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1714 /* Record a fake tag index */
1715 f_ptr->mimic_tag = offset;
1719 /* Process 'G' for "Graphics" (one line only) */
1720 else if (buf[0] == 'G')
1724 char char_tmp[F_LIT_MAX];
1725 if (buf[1] != ':') return (1);
1726 if (!buf[2]) return (1);
1727 if (buf[3] != ':') return (1);
1728 if (!buf[4]) return (1);
1730 /* Extract the char */
1731 char_tmp[F_LIT_STANDARD] = buf[2];
1733 /* Extract the color */
1734 s_attr = color_char_to_attr(buf[4]);
1735 if (s_attr > 127) return (1);
1737 /* Save the standard values */
1738 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1739 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1741 /* Is this feature supports lighting? */
1744 /* G:c:a:LIT (default) */
1745 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1747 /* G:c:a:lc:la:dc:da */
1748 if (!streq(buf + 6, "LIT"))
1750 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1752 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1753 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1754 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1755 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1757 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1759 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1762 /* Use default lighting */
1765 /* No lighting support */
1766 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1769 /* Extract the color */
1770 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1771 if (f_ptr->d_attr[j] > 127) return 1;
1774 f_ptr->d_char[j] = char_tmp[j];
1780 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1782 f_ptr->d_attr[j] = s_attr;
1783 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1789 /* Hack -- Process 'F' for flags */
1790 else if (buf[0] == 'F')
1792 /* Parse every entry textually */
1793 for (s = buf + 2; *s; )
1795 /* Find the end of this entry */
1796 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1798 /* Nuke and skip any dividers */
1802 while (*t == ' ' || *t == '|') t++;
1805 /* Hack -- Read feature subtype */
1806 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1808 /* Extract a "subtype" */
1809 f_ptr->subtype = (FEAT_SUBTYPE)i;
1811 /* Start at next entry */
1817 /* Hack -- Read feature power */
1818 if (1 == sscanf(s, "POWER_%d", &i))
1820 /* Extract a "power" */
1821 f_ptr->power = (FEAT_POWER)i;
1823 /* Start at next entry */
1828 /* Parse this entry */
1829 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1831 /* Start the next entry */
1836 /* Process 'W' for "More Info" (one line only) */
1837 else if (buf[0] == 'W')
1841 /* Scan for the value */
1842 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1844 /* Save the value */
1845 f_ptr->priority = (FEAT_PRIORITY)priority;
1848 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1849 else if (buf[0] == 'K')
1853 /* Find the next empty state slot (if any) */
1854 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1856 /* Oops, no more slots */
1857 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1859 /* Analyze the first field */
1860 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1862 /* Terminate the field (if necessary) */
1863 if (*t == ':') *t++ = '\0';
1865 /* Is this default entry? */
1866 if (streq(s, "DESTROYED"))
1868 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1870 /* Record a fake tag index */
1871 f_ptr->destroyed_tag = offset;
1876 f_ptr->state[i].action = 0;
1878 /* Parse this entry */
1879 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1881 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1883 /* Record a fake tag index */
1884 f_ptr->state[i].result_tag = offset;
1896 * @brief 地形タグからIDを得る /
1897 * Convert a fake tag to a real feat index
1901 s16b f_tag_to_index(concptr str)
1905 /* Search for real index corresponding to this fake tag */
1906 for (i = 0; i < f_head.info_num; i++)
1908 if (streq(f_tag + f_info[i].tag, str))
1910 /* Return the index */
1921 * @brief 地形タグからIDを得る /
1922 * Search for real index corresponding to this fake tag
1923 * @param feat タグ文字列のオフセット
1924 * @return 地形ID。該当がないなら-1
1926 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1930 /* Don't convert non-fake tag */
1936 /* Search for real index corresponding to this fake tag */
1937 for (i = 0; i < f_head.info_num; i++)
1939 if (feat == f_info[i].tag)
1941 /* Record real index */
1947 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1953 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1954 * Retouch fake tags of f_info
1955 * @param head ヘッダ構造体
1958 void retouch_f_info(header *head)
1962 /* Convert fake tags to real feat indices */
1963 for (i = 0; i < head->info_num; i++)
1965 feature_type *f_ptr = &f_info[i];
1968 k = search_real_feat(f_ptr->mimic_tag);
1969 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1970 k = search_real_feat(f_ptr->destroyed_tag);
1971 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1972 for (j = 0; j < MAX_FEAT_STATES; j++)
1974 k = search_real_feat(f_ptr->state[j].result_tag);
1975 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1982 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1983 * Grab one flag in an object_kind from a textual string
1984 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1985 * @param what 参照元の文字列ポインタ
1988 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1993 for (i = 0; i < TR_FLAG_MAX; i++)
1995 if (streq(what, k_info_flags[i]))
1997 add_flag(k_ptr->flags, i);
2002 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2005 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2012 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2013 * Grab one activation index flag
2014 * @param what 参照元の文字列ポインタ
2017 static byte grab_one_activation_flag(concptr what)
2023 if (activation_info[i].flag == NULL) break;
2025 if (streq(what, activation_info[i].flag))
2027 return activation_info[i].index;
2037 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2045 * @brief ベースアイテム(k_info)のパース関数 /
2046 * Initialize the "k_info" array, by parsing an ascii "template" file
2048 * @param head ヘッダ構造体
2051 errr parse_k_info(char *buf, header *head)
2058 static object_kind *k_ptr = NULL;
2061 /* Process 'N' for "New/Number/Name" */
2068 /* Find the colon before the name */
2069 s = my_strchr(buf + 2, ':');
2071 /* Verify that colon */
2074 /* Nuke the colon, advance to the name */
2080 /* Verify information */
2081 if (i <= error_idx) return (4);
2083 /* Verify information */
2084 if (i >= head->info_num) return (2);
2086 /* Save the index */
2089 /* Point at the "info" */
2093 /* Paranoia -- require a name */
2094 if (!*s) return (1);
2096 /* Find the colon before the flavor */
2097 flavor = my_strchr(s, ':');
2099 /* Verify that colon */
2102 /* Nuke the colon, advance to the flavor */
2105 /* Store the flavor */
2106 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2109 /* Store the name */
2110 if (!add_name(&k_ptr->name, head, s)) return (7);
2114 /* There better be a current k_ptr */
2115 else if (!k_ptr) return (3);
2120 /* 'E' から始まる行は英語名としている */
2121 else if (buf[0] == 'E')
2126 else if (buf[0] == 'E')
2130 /* Acquire the name */
2133 /* Find the colon before the flavor */
2134 flavor = my_strchr(s, ':');
2136 /* Verify that colon */
2139 /* Nuke the colon, advance to the flavor */
2142 /* Store the flavor */
2143 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2146 /* Store the name */
2147 if (!add_name(&k_ptr->name, head, s)) return (7);
2151 /* Process 'D' for "Description" */
2152 else if (buf[0] == 'D')
2157 /* Acquire the text */
2162 /* Acquire the text */
2166 /* Store the text */
2167 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2170 /* Process 'G' for "Graphics" (one line only) */
2171 else if (buf[0] == 'G')
2175 if (buf[1] != ':') return (1);
2176 if (!buf[2]) return (1);
2177 if (buf[3] != ':') return (1);
2178 if (!buf[4]) return (1);
2180 /* Extract the char */
2183 /* Extract the attr */
2184 tmp = color_char_to_attr(buf[4]);
2185 if (tmp > 127) return (1);
2187 /* Save the values */
2188 k_ptr->d_attr = tmp;
2189 k_ptr->d_char = sym;
2192 /* Process 'I' for "Info" (one line only) */
2193 else if (buf[0] == 'I')
2195 int tval, sval, pval;
2197 /* Scan for the values */
2198 if (3 != sscanf(buf + 2, "%d:%d:%d",
2199 &tval, &sval, &pval)) return (1);
2201 /* Save the values */
2202 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2203 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2204 k_ptr->pval = (PARAMETER_VALUE)pval;
2207 /* Process 'W' for "More Info" (one line only) */
2208 else if (buf[0] == 'W')
2210 int level, extra, wgt;
2213 /* Scan for the values */
2214 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2215 &level, &extra, &wgt, &cost)) return (1);
2217 /* Save the values */
2218 k_ptr->level = (DEPTH)level;
2219 k_ptr->extra = (BIT_FLAGS8)extra;
2220 k_ptr->weight = (WEIGHT)wgt;
2221 k_ptr->cost = (PRICE)cost;
2224 /* Process 'A' for "Allocation" (one line only) */
2225 else if (buf[0] == 'A')
2228 /* Simply read each number following a colon */
2229 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2231 /* Default chance */
2232 k_ptr->chance[i] = 1;
2234 /* Store the attack damage index */
2235 k_ptr->locale[i] = atoi(s + 1);
2237 /* Find the slash */
2238 t = my_strchr(s + 1, '/');
2240 /* Find the next colon */
2241 s = my_strchr(s + 1, ':');
2243 /* If the slash is "nearby", use it */
2244 if (t && (!s || t < s))
2246 int chance = atoi(t + 1);
2247 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2252 /* Hack -- Process 'P' for "power" and such */
2253 else if (buf[0] == 'P')
2255 int ac, hd1, hd2, th, td, ta;
2257 /* Scan for the values */
2258 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2259 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2261 k_ptr->ac = (ARMOUR_CLASS)ac;
2262 k_ptr->dd = (DICE_NUMBER)hd1;
2263 k_ptr->ds = (DICE_SID)hd2;
2264 k_ptr->to_h = (HIT_PROB)th;
2265 k_ptr->to_d = (HIT_POINT)td;
2266 k_ptr->to_a = (ARMOUR_CLASS)ta;
2269 /* Hack -- Process 'U' for activation index */
2270 else if (buf[0] == 'U')
2273 n = grab_one_activation_flag(buf + 2);
2284 /* Hack -- Process 'F' for flags */
2285 else if (buf[0] == 'F')
2287 /* Parse every entry textually */
2288 for (s = buf + 2; *s; )
2290 /* Find the end of this entry */
2291 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2293 /* Nuke and skip any dividers */
2297 while (*t == ' ' || *t == '|') t++;
2300 /* Parse this entry */
2301 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2303 /* Start the next entry */
2317 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2318 * Grab one activation index flag
2319 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2320 * @param what 参照元の文字列ポインタ
2321 * @return エラーがあった場合1、エラーがない場合0を返す
2323 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2328 for (i = 0; i < TR_FLAG_MAX; i++)
2330 if (streq(what, k_info_flags[i]))
2332 add_flag(a_ptr->flags, i);
2337 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2340 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2348 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2349 * Initialize the "a_info" array, by parsing an ascii "template" file
2351 * @param head ヘッダ構造体
2354 errr parse_a_info(char *buf, header *head)
2361 static artifact_type *a_ptr = NULL;
2364 /* Process 'N' for "New/Number/Name" */
2367 /* Find the colon before the name */
2368 s = my_strchr(buf + 2, ':');
2370 /* Verify that colon */
2373 /* Nuke the colon, advance to the name */
2376 /* Paranoia -- require a name */
2377 if (!*s) return (1);
2382 /* Verify information */
2383 if (i < error_idx) return (4);
2385 /* Verify information */
2386 if (i >= head->info_num) return (2);
2388 /* Save the index */
2391 /* Point at the "info" */
2394 /* Ignore everything */
2395 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2396 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2397 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2398 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2400 /* Store the name */
2401 if (!add_name(&a_ptr->name, head, s)) return (7);
2405 /* There better be a current a_ptr */
2406 else if (!a_ptr) return (3);
2411 /* 'E' から始まる行は英語名としている */
2412 else if (buf[0] == 'E')
2417 else if (buf[0] == 'E')
2419 /* Acquire the Text */
2422 /* Store the name */
2423 if (!add_name(&a_ptr->name, head, s)) return (7);
2427 /* Process 'D' for "Description" */
2428 else if (buf[0] == 'D')
2433 /* Acquire the text */
2438 /* Acquire the text */
2442 /* Store the text */
2443 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2447 /* Process 'I' for "Info" (one line only) */
2448 else if (buf[0] == 'I')
2450 int tval, sval, pval;
2452 /* Scan for the values */
2453 if (3 != sscanf(buf + 2, "%d:%d:%d",
2454 &tval, &sval, &pval)) return (1);
2456 /* Save the values */
2457 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2458 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2459 a_ptr->pval = (PARAMETER_VALUE)pval;
2462 /* Process 'W' for "More Info" (one line only) */
2463 else if (buf[0] == 'W')
2465 int level, rarity, wgt;
2468 /* Scan for the values */
2469 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2470 &level, &rarity, &wgt, &cost)) return (1);
2472 /* Save the values */
2473 a_ptr->level = (DEPTH)level;
2474 a_ptr->rarity = (RARITY)rarity;
2475 a_ptr->weight = (WEIGHT)wgt;
2476 a_ptr->cost = (PRICE)cost;
2479 /* Hack -- Process 'P' for "power" and such */
2480 else if (buf[0] == 'P')
2482 int ac, hd1, hd2, th, td, ta;
2484 /* Scan for the values */
2485 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2486 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2488 a_ptr->ac = (ARMOUR_CLASS)ac;
2489 a_ptr->dd = (DICE_NUMBER)hd1;
2490 a_ptr->ds = (DICE_SID)hd2;
2491 a_ptr->to_h = (HIT_PROB)th;
2492 a_ptr->to_d = (HIT_POINT)td;
2493 a_ptr->to_a = (ARMOUR_CLASS)ta;
2496 /* Hack -- Process 'U' for activation index */
2497 else if (buf[0] == 'U')
2500 n = grab_one_activation_flag(buf + 2);
2511 /* Hack -- Process 'F' for flags */
2512 else if (buf[0] == 'F')
2514 /* Parse every entry textually */
2515 for (s = buf + 2; *s; )
2517 /* Find the end of this entry */
2518 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2520 /* Nuke and skip any dividers */
2524 while ((*t == ' ') || (*t == '|')) t++;
2527 /* Parse this entry */
2528 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2530 /* Start the next entry */
2545 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2546 * Grab one flag in a ego-item_type from a textual string
2547 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2548 * @param what 参照元の文字列ポインタ
2549 * @return エラーがあった場合1、エラーがない場合0を返す
2551 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2556 for (i = 0; i < TR_FLAG_MAX; i++)
2558 if (streq(what, k_info_flags[i]))
2560 add_flag(e_ptr->flags, i);
2565 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2568 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2576 * @brief アイテムエゴ情報(e_info)のパース関数 /
2577 * Initialize the "e_info" array, by parsing an ascii "template" file
2579 * @param head ヘッダ構造体
2582 errr parse_e_info(char *buf, header *head)
2588 static ego_item_type *e_ptr = NULL;
2590 /* Just before the first record */
2593 /* Just before the first line */
2596 /* Process 'N' for "New/Number/Name" */
2599 /* Find the colon before the name */
2600 s = my_strchr(buf + 2, ':');
2602 /* Verify that colon */
2605 /* Nuke the colon, advance to the name */
2608 /* Paranoia -- require a name */
2609 if (!*s) return (1);
2614 /* Verify information */
2615 if (i < error_idx) return (4);
2617 /* Verify information */
2618 if (i >= head->info_num) return (2);
2620 /* Save the index */
2623 /* Point at the "info" */
2626 /* Store the name */
2627 if (!add_name(&e_ptr->name, head, s)) return (7);
2631 /* There better be a current e_ptr */
2632 else if (!e_ptr) return (3);
2637 /* 'E' から始まる行は英語名 */
2638 else if (buf[0] == 'E')
2643 else if (buf[0] == 'E')
2645 /* Acquire the Text */
2648 /* Store the name */
2649 if (!add_name(&e_ptr->name, head, s)) return (7);
2654 /* Process 'D' for "Description" */
2655 else if (buf[0] == 'D')
2657 /* Acquire the text */
2660 /* Store the text */
2661 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2666 /* Process 'X' for "Xtra" (one line only) */
2667 else if (buf[0] == 'X')
2671 /* Scan for the values */
2672 if (2 != sscanf(buf + 2, "%d:%d",
2673 &slot, &rating)) return (1);
2675 /* Save the values */
2676 e_ptr->slot = (INVENTORY_IDX)slot;
2677 e_ptr->rating = (PRICE)rating;
2680 /* Process 'W' for "More Info" (one line only) */
2681 else if (buf[0] == 'W')
2683 int level, rarity, pad2;
2686 /* Scan for the values */
2687 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2688 &level, &rarity, &pad2, &cost)) return (1);
2690 /* Save the values */
2691 e_ptr->level = level;
2692 e_ptr->rarity = (RARITY)rarity;
2693 /* e_ptr->weight = wgt; */
2697 /* Hack -- Process 'C' for "creation" */
2698 else if (buf[0] == 'C')
2700 int th, td, ta, pval;
2702 /* Scan for the values */
2703 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2704 &th, &td, &ta, &pval)) return (1);
2706 e_ptr->max_to_h = (HIT_PROB)th;
2707 e_ptr->max_to_d = (HIT_POINT)td;
2708 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2709 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2712 /* Hack -- Process 'U' for activation index */
2713 else if (buf[0] == 'U')
2716 n = grab_one_activation_flag(buf + 2);
2727 /* Hack -- Process 'F' for flags */
2728 else if (buf[0] == 'F')
2730 /* Parse every entry textually */
2731 for (s = buf + 2; *s; )
2733 /* Find the end of this entry */
2734 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2736 /* Nuke and skip any dividers */
2740 while ((*t == ' ') || (*t == '|')) t++;
2743 /* Parse this entry */
2744 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2746 /* Start the next entry */
2759 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2760 * Grab one (basic) flag in a monster_race from a textual string
2761 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2762 * @param what 参照元の文字列ポインタ
2765 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2767 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2770 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2773 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2776 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2779 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2782 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2785 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2788 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2796 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2797 * Grab one (spell) flag in a monster_race from a textual string
2798 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2799 * @param what 参照元の文字列ポインタ
2802 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2804 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2807 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2810 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2813 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2821 * @brief モンスター種族情報(r_info)のパース関数 /
2822 * Initialize the "r_info" array, by parsing an ascii "template" file
2824 * @param head ヘッダ構造体
2827 errr parse_r_info(char *buf, header *head)
2833 static monster_race *r_ptr = NULL;
2836 /* Process 'N' for "New/Number/Name" */
2839 /* Find the colon before the name */
2840 s = my_strchr(buf + 2, ':');
2842 /* Verify that colon */
2845 /* Nuke the colon, advance to the name */
2848 /* Paranoia -- require a name */
2849 if (!*s) return (1);
2854 /* Verify information */
2855 if (i < error_idx) return (4);
2857 /* Verify information */
2858 if (i >= head->info_num) return (2);
2860 /* Save the index */
2863 /* Point at the "info" */
2866 /* Store the name */
2867 if (!add_name(&r_ptr->name, head, s)) return (7);
2871 /* There better be a current r_ptr */
2872 else if (!r_ptr) return (3);
2877 /* 'E' から始まる行は英語名 */
2878 else if (buf[0] == 'E')
2880 /* Acquire the Text */
2883 /* Store the name */
2884 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2887 else if (buf[0] == 'E')
2889 /* Acquire the Text */
2892 /* Store the name */
2893 if (!add_name(&r_ptr->name, head, s)) return (7);
2896 /* Process 'D' for "Description" */
2897 else if (buf[0] == 'D')
2902 /* Acquire the text */
2907 /* Acquire the text */
2911 /* Store the text */
2912 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2915 /* Process 'G' for "Graphics" (one line only) */
2916 else if (buf[0] == 'G')
2920 if (buf[1] != ':') return (1);
2921 if (!buf[2]) return (1);
2922 if (buf[3] != ':') return (1);
2923 if (!buf[4]) return (1);
2925 /* Extract the char */
2928 /* Extract the attr */
2929 tmp = color_char_to_attr(buf[4]);
2930 if (tmp > 127) return (1);
2932 /* Save the values */
2933 r_ptr->d_char = sym;
2934 r_ptr->d_attr = tmp;
2937 /* Process 'I' for "Info" (one line only) */
2938 else if (buf[0] == 'I')
2940 int spd, hp1, hp2, aaf, ac, slp;
2942 /* Scan for the other values */
2943 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2944 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2946 /* Save the values */
2947 r_ptr->speed = (SPEED)spd;
2948 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2949 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2950 r_ptr->aaf = (POSITION)aaf;
2951 r_ptr->ac = (ARMOUR_CLASS)ac;
2952 r_ptr->sleep = (SLEEP_DEGREE)slp;
2955 /* Process 'W' for "More Info" (one line only) */
2956 else if (buf[0] == 'W')
2963 /* Scan for the values */
2964 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2965 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2967 /* Save the values */
2968 r_ptr->level = (DEPTH)lev;
2969 r_ptr->rarity = (RARITY)rar;
2970 r_ptr->extra = (BIT_FLAGS16)pad;
2971 r_ptr->mexp = (EXP)exp;
2972 r_ptr->next_exp = (EXP)nextexp;
2973 r_ptr->next_r_idx = (IDX)nextmon;
2976 /* Process 'R' for "Reinforcement" (up to six lines) */
2977 else if (buf[0] == 'R')
2980 /* Find the next empty blow slot (if any) */
2981 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2983 /* Oops, no more slots */
2984 if (i == 6) return (1);
2986 /* Scan for the values */
2987 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2988 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2989 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2990 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2993 /* Process 'B' for "Blows" (up to four lines) */
2994 else if (buf[0] == 'B')
2998 /* Find the next empty blow slot (if any) */
2999 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3001 /* Oops, no more slots */
3002 if (i == 4) return (1);
3004 /* Analyze the first field */
3005 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3007 /* Terminate the field (if necessary) */
3008 if (*t == ':') *t++ = '\0';
3010 /* Analyze the method */
3011 for (n1 = 0; r_info_blow_method[n1]; n1++)
3013 if (streq(s, r_info_blow_method[n1])) break;
3016 /* Invalid method */
3017 if (!r_info_blow_method[n1]) return (1);
3019 /* Analyze the second field */
3020 for (s = t; *t && (*t != ':'); t++) /* loop */;
3022 /* Terminate the field (if necessary) */
3023 if (*t == ':') *t++ = '\0';
3025 /* Analyze effect */
3026 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3028 if (streq(s, r_info_blow_effect[n2])) break;
3031 /* Invalid effect */
3032 if (!r_info_blow_effect[n2]) return (1);
3034 /* Analyze the third field */
3035 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3037 /* Terminate the field (if necessary) */
3038 if (*t == 'd') *t++ = '\0';
3040 /* Save the method */
3041 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3043 /* Save the effect */
3044 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3046 /* Extract the damage dice and sides */
3047 r_ptr->blow[i].d_dice = atoi(s);
3048 r_ptr->blow[i].d_side = atoi(t);
3051 /* Process 'F' for "Basic Flags" (multiple lines) */
3052 else if (buf[0] == 'F')
3054 /* Parse every entry */
3055 for (s = buf + 2; *s; )
3057 /* Find the end of this entry */
3058 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3060 /* Nuke and skip any dividers */
3064 while (*t == ' ' || *t == '|') t++;
3067 /* Parse this entry */
3068 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3070 /* Start the next entry */
3075 /* Process 'S' for "Spell Flags" (multiple lines) */
3076 else if (buf[0] == 'S')
3078 /* Parse every entry */
3079 for (s = buf + 2; *s; )
3081 /* Find the end of this entry */
3082 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3084 /* Nuke and skip any dividers */
3088 while ((*t == ' ') || (*t == '|')) t++;
3091 /* Hack -- Read spell frequency */
3092 if (1 == sscanf(s, "1_IN_%d", &i))
3094 /* Extract a "frequency" */
3095 r_ptr->freq_spell = 100 / i;
3097 /* Start at next entry */
3102 /* Parse this entry */
3103 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3105 /* Start the next entry */
3110 /* Process 'A' for "Artifact Flags" (multiple lines) */
3111 else if (buf[0] == 'A')
3113 int id, per, rarity;
3115 /* Find the next empty blow slot (if any) */
3116 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3118 /* Oops, no more slots */
3119 if (i == 4) return (1);
3121 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3122 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3123 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3124 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3127 /* Process 'V' for "Arena power value ratio" */
3128 else if (buf[0] == 'V')
3131 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3132 r_ptr->arena_ratio = (PERCENTAGE)val;
3144 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3145 * Grab one flag for a dungeon type from a textual string
3146 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3147 * @param what 参照元の文字列ポインタ
3150 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3152 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3155 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3162 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3163 * Grab one (basic) flag in a monster_race from a textual string
3164 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3165 * @param what 参照元の文字列ポインタ
3168 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3170 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3173 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3176 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3179 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3182 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3185 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3188 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3191 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3198 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3199 * Grab one (spell) flag in a monster_race from a textual string
3200 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3201 * @param what 参照元の文字列ポインタ
3204 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3206 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3209 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3212 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3215 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3222 * @brief ダンジョン情報(d_info)のパース関数 /
3223 * Initialize the "d_info" array, by parsing an ascii "template" file
3225 * @param head ヘッダ構造体
3228 errr parse_d_info(char *buf, header *head)
3234 static dungeon_type *d_ptr = NULL;
3236 /* Process 'N' for "New/Number/Name" */
3239 /* Find the colon before the name */
3240 s = my_strchr(buf + 2, ':');
3242 /* Verify that colon */
3245 /* Nuke the colon, advance to the name */
3248 /* Paranoia -- require a name */
3249 if (!*s) return (1);
3254 /* Verify information */
3255 if (i < error_idx) return (4);
3257 /* Verify information */
3258 if (i >= head->info_num) return (2);
3260 /* Save the index */
3263 /* Point at the "info" */
3266 /* Store the name */
3267 if (!add_name(&d_ptr->name, head, s)) return (7);
3272 else if (buf[0] == 'E') return (0);
3274 else if (buf[0] == 'E')
3276 /* Acquire the Text */
3279 /* Store the name */
3280 if (!add_name(&d_ptr->name, head, s)) return (7);
3284 /* Process 'D' for "Description */
3285 else if (buf[0] == 'D')
3290 /* Acquire the text */
3295 /* Acquire the text */
3299 /* Store the text */
3300 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3303 /* Process 'W' for "More Info" (one line only) */
3304 else if (buf[0] == 'W')
3306 int min_lev, max_lev;
3308 int min_alloc, max_chance;
3309 int obj_good, obj_great;
3312 /* Scan for the values */
3313 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3314 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3316 /* Save the values */
3317 d_ptr->mindepth = (DEPTH)min_lev;
3318 d_ptr->maxdepth = (DEPTH)max_lev;
3319 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3320 d_ptr->mode = (BIT_FLAGS8)mode;
3321 d_ptr->min_m_alloc_level = min_alloc;
3322 d_ptr->max_m_alloc_chance = max_chance;
3323 d_ptr->obj_good = obj_good;
3324 d_ptr->obj_great = obj_great;
3325 d_ptr->pit = (BIT_FLAGS16)pit;
3326 d_ptr->nest = (BIT_FLAGS16)nest;
3329 /* Process 'P' for "Place Info" */
3330 else if (buf[0] == 'P')
3334 /* Scan for the values */
3335 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3337 /* Save the values */
3342 /* Process 'L' for "fLoor type" (one line only) */
3343 else if (buf[0] == 'L')
3347 /* Scan for the values */
3348 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3350 /* Save the values */
3351 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3353 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3354 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3356 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3358 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3361 /* Process 'A' for "wAll type" (one line only) */
3362 else if (buf[0] == 'A')
3366 /* Scan for the values */
3367 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3369 /* Save the values */
3370 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3372 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3373 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3375 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3378 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3379 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3381 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3382 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3384 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3385 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3387 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3388 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3391 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3392 else if (buf[0] == 'F')
3394 int artif = 0, monst = 0;
3396 /* Parse every entry */
3397 for (s = buf + 2; *s; )
3399 /* Find the end of this entry */
3400 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3402 /* Nuke and skip any dividers */
3406 while (*t == ' ' || *t == '|') t++;
3409 /* Hack -- Read Final Artifact */
3410 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3412 /* Extract a "Final Artifact" */
3413 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3415 /* Start at next entry */
3420 /* Hack -- Read Final Object */
3421 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3423 /* Extract a "Final Artifact" */
3424 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3426 /* Start at next entry */
3431 /* Hack -- Read Artifact Guardian */
3432 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3434 /* Extract a "Artifact Guardian" */
3435 d_ptr->final_guardian = (MONRACE_IDX)monst;
3437 /* Start at next entry */
3442 /* Hack -- Read Special Percentage */
3443 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3445 /* Extract a "Special %" */
3446 d_ptr->special_div = (PROB)monst;
3448 /* Start at next entry */
3453 /* Parse this entry */
3454 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3456 /* Start the next entry */
3461 /* Process 'M' for "Basic Flags" (multiple lines) */
3462 else if (buf[0] == 'M')
3464 /* Parse every entry */
3465 for (s = buf + 2; *s; )
3467 /* Find the end of this entry */
3468 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3470 /* Nuke and skip any dividers */
3474 while (*t == ' ' || *t == '|') t++;
3477 /* Hack -- Read monster symbols */
3478 if (!strncmp(s, "R_CHAR_", 7))
3480 /* Skip "R_CHAR_" */
3484 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3486 /* Start at next entry */
3491 /* Parse this entry */
3492 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3494 /* Start the next entry */
3499 /* Process 'S' for "Spell Flags" (multiple lines) */
3500 else if (buf[0] == 'S')
3502 /* Parse every entry */
3503 for (s = buf + 2; *s; )
3505 /* Find the end of this entry */
3506 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3508 /* Nuke and skip any dividers */
3512 while ((*t == ' ') || (*t == '|')) t++;
3515 /* Hack -- Read spell frequency */
3516 if (1 == sscanf(s, "1_IN_%d", &i))
3518 /* Start at next entry */
3523 /* Parse this entry */
3524 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3526 /* Start the next entry */
3538 #else /* ALLOW_TEMPLATES */
3544 #endif /* ALLOW_TEMPLATES */
3548 * @brief 地形情報の「F:」情報をパースする
3549 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3553 static errr parse_line_feature(char *buf)
3558 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3560 /* Tokenize the line */
3561 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3563 /* Letter to assign */
3564 int index = zz[0][0];
3566 /* Reset the info for the letter */
3567 letter[index].feature = feat_none;
3568 letter[index].monster = 0;
3569 letter[index].object = 0;
3570 letter[index].ego = 0;
3571 letter[index].artifact = 0;
3572 letter[index].trap = feat_none;
3573 letter[index].cave_info = 0;
3574 letter[index].special = 0;
3575 letter[index].random = RANDOM_NONE;
3581 letter[index].special = (s16b)atoi(zz[8]);
3585 if ((zz[7][0] == '*') && !zz[7][1])
3587 letter[index].random |= RANDOM_TRAP;
3591 letter[index].trap = f_tag_to_index(zz[7]);
3592 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3597 if (zz[6][0] == '*')
3599 letter[index].random |= RANDOM_ARTIFACT;
3600 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3602 else if (zz[6][0] == '!')
3604 if (p_ptr->inside_quest)
3606 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3611 letter[index].artifact = (IDX)atoi(zz[6]);
3616 if (zz[5][0] == '*')
3618 letter[index].random |= RANDOM_EGO;
3619 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3623 letter[index].ego = (IDX)atoi(zz[5]);
3628 if (zz[4][0] == '*')
3630 letter[index].random |= RANDOM_OBJECT;
3631 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3633 else if (zz[4][0] == '!')
3635 if (p_ptr->inside_quest)
3637 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3640 artifact_type *a_ptr = &a_info[a_idx];
3641 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3643 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3650 letter[index].object = (IDX)atoi(zz[4]);
3655 if (zz[3][0] == '*')
3657 letter[index].random |= RANDOM_MONSTER;
3658 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3660 else if (zz[3][0] == 'c')
3662 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3663 letter[index].monster = -atoi(zz[3] + 1);
3667 letter[index].monster = (IDX)atoi(zz[3]);
3672 letter[index].cave_info = atoi(zz[2]);
3676 if ((zz[1][0] == '*') && !zz[1][1])
3678 letter[index].random |= RANDOM_FEATURE;
3682 letter[index].feature = f_tag_to_index(zz[1]);
3683 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3696 * @brief 地形情報の「B:」情報をパースする
3697 * Process "B:<Index>:<Command>:..." -- Building definition
3701 static errr parse_line_building(char *buf)
3717 /* Get the building number */
3720 /* Find the colon after the building number */
3721 s = my_strchr(s, ':');
3723 /* Verify that colon */
3726 /* Nuke the colon, advance to the sub-index */
3729 /* Paranoia -- require a sub-index */
3730 if (!*s) return (1);
3732 /* Building definition sub-index */
3735 /* Building name, owner, race */
3738 if (tokenize(s + 2, 3, zz, 0) == 3)
3740 /* Name of the building */
3741 strcpy(building[index].name, zz[0]);
3743 /* Name of the owner */
3744 strcpy(building[index].owner_name, zz[1]);
3746 /* Race of the owner */
3747 strcpy(building[index].owner_race, zz[2]);
3752 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3755 /* Building Action */
3758 if (tokenize(s + 2, 8, zz, 0) >= 7)
3760 /* Index of the action */
3761 int action_index = atoi(zz[0]);
3763 /* Name of the action */
3764 strcpy(building[index].act_names[action_index], zz[1]);
3766 /* Cost of the action for members */
3767 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3769 /* Cost of the action for non-members */
3770 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3772 /* Letter assigned to the action */
3773 building[index].letters[action_index] = zz[4][0];
3776 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3778 /* Action restriction */
3779 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3784 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3787 /* Building Classes */
3791 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3792 for (i = 0; i < MAX_CLASS; i++)
3794 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3799 /* Building Races */
3803 n = tokenize(s + 2, MAX_RACES, zz, 0);
3804 for (i = 0; i < MAX_RACES; i++)
3806 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3811 /* Building Realms */
3815 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3816 for (i = 0; i < MAX_MAGIC; i++)
3818 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3825 /* Ignore scripts */
3831 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3840 * @brief フロアの所定のマスにオブジェクトを配置する
3841 * Place the object j_ptr to a grid
3842 * @param j_ptr オブジェクト構造体の参照ポインタ
3847 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3849 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3852 OBJECT_IDX o_idx = o_pop();
3854 /* Access new object */
3855 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3857 /* Structure copy */
3858 object_copy(o_ptr, j_ptr);
3865 o_ptr->held_m_idx = 0;
3868 o_ptr->next_o_idx = g_ptr->o_idx;
3870 g_ptr->o_idx = o_idx;
3874 * @brief クエスト用固定ダンジョンをフロアに生成する
3875 * Parse a sub-file of the "extra info"
3885 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3890 /* Skip "empty" lines */
3891 if (!buf[0]) return (0);
3893 /* Skip "blank" lines */
3894 if (iswspace(buf[0])) return (0);
3897 if (buf[0] == '#') return (0);
3899 /* Require "?:*" format */
3900 if (buf[1] != ':') return (1);
3903 /* Process "%:<fname>" */
3906 /* Attempt to Process the given file */
3907 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3910 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3913 return parse_line_feature(buf);
3916 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3917 else if (buf[0] == 'D')
3919 object_type object_type_body;
3921 /* Acquire the text */
3924 /* Length of the text */
3925 int len = strlen(s);
3927 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3929 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3931 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3935 OBJECT_IDX object_index = letter[idx].object;
3936 MONSTER_IDX monster_index = letter[idx].monster;
3937 int random = letter[idx].random;
3938 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3940 /* Lay down a floor */
3941 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3943 /* Only the features */
3944 if (init_flags & INIT_ONLY_FEATURES) continue;
3947 g_ptr->info = letter[idx].cave_info;
3949 /* Create a monster */
3950 if (random & RANDOM_MONSTER)
3952 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3954 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3956 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3958 else if (monster_index)
3960 int old_cur_num, old_max_num;
3963 if (monster_index < 0)
3965 monster_index = -monster_index;
3968 old_cur_num = r_info[monster_index].cur_num;
3969 old_max_num = r_info[monster_index].max_num;
3971 /* Make alive again */
3972 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3974 r_info[monster_index].cur_num = 0;
3975 r_info[monster_index].max_num = 1;
3978 /* Make alive again */
3979 /* Hack -- Non-unique Nazguls are semi-unique */
3980 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3982 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3984 r_info[monster_index].max_num++;
3989 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3993 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3995 /* Make alive again for real unique monster */
3996 r_info[monster_index].cur_num = old_cur_num;
3997 r_info[monster_index].max_num = old_max_num;
4001 /* Object (and possible trap) */
4002 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4004 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4007 * Random trap and random treasure defined
4008 * 25% chance for trap and 75% chance for object
4010 if (randint0(100) < 75)
4012 place_object(*y, *x, 0L);
4019 current_floor_ptr->object_level = current_floor_ptr->base_level;
4021 else if (random & RANDOM_OBJECT)
4023 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4025 /* Create an out of deep object */
4026 if (randint0(100) < 75)
4027 place_object(*y, *x, 0L);
4028 else if (randint0(100) < 80)
4029 place_object(*y, *x, AM_GOOD);
4031 place_object(*y, *x, AM_GOOD | AM_GREAT);
4033 current_floor_ptr->object_level = current_floor_ptr->base_level;
4036 else if (random & RANDOM_TRAP)
4040 /* Hidden trap (or door) */
4041 else if (letter[idx].trap)
4043 g_ptr->mimic = g_ptr->feat;
4044 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4046 else if (object_index)
4048 object_type *o_ptr = &object_type_body;
4049 object_prep(o_ptr, object_index);
4051 if (o_ptr->tval == TV_GOLD)
4053 coin_type = object_index - OBJ_GOLD_LIST;
4058 /* Apply magic (no messages, no artifacts) */
4059 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4061 drop_here(o_ptr, *y, *x);
4067 if (a_info[artifact_index].cur_num)
4069 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4071 object_type *q_ptr = &forge;
4073 object_prep(q_ptr, k_idx);
4074 drop_here(q_ptr, *y, *x);
4078 if (create_named_art(artifact_index, *y, *x))
4079 a_info[artifact_index].cur_num = 1;
4083 /* Terrain special */
4084 g_ptr->special = letter[idx].special;
4092 /* Process "Q:<number>:<command>:... -- quest info */
4093 else if (buf[0] == 'Q')
4100 num = tokenize(buf + 2, 33, zz, 0);
4104 num = tokenize(buf + 3, 33, zz, 0);
4107 /* Have we enough parameters? */
4108 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4111 q_ptr = &(quest[atoi(zz[0])]);
4113 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4114 if (zz[1][0] == 'Q')
4116 if (init_flags & INIT_ASSIGN)
4118 monster_race *r_ptr;
4119 artifact_type *a_ptr;
4121 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4123 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4124 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4125 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4126 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4127 q_ptr->level = (DEPTH)atoi(zz[6]);
4128 q_ptr->r_idx = (IDX)atoi(zz[7]);
4129 q_ptr->k_idx = (IDX)atoi(zz[8]);
4130 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4132 if (num > 10) q_ptr->flags = atoi(zz[10]);
4134 r_ptr = &r_info[q_ptr->r_idx];
4135 if (r_ptr->flags1 & RF1_UNIQUE)
4136 r_ptr->flags1 |= RF1_QUESTOR;
4138 a_ptr = &a_info[q_ptr->k_idx];
4139 a_ptr->gen_flags |= TRG_QUESTITEM;
4144 else if (zz[1][0] == 'R')
4146 if (init_flags & INIT_ASSIGN)
4149 IDX idx, reward_idx = 0;
4151 for (idx = 2; idx < num; idx++)
4153 IDX a_idx = (IDX)atoi(zz[idx]);
4154 if (a_idx < 1) continue;
4155 if (a_info[a_idx].cur_num > 0) continue;
4157 if (one_in_(count)) reward_idx = a_idx;
4162 /* Set quest's rewarding artifact */
4163 q_ptr->k_idx = reward_idx;
4164 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4168 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4169 q_ptr->type = QUEST_TYPE_KILL_ALL;
4176 /* Process "Q:<q_index>:N:<name>" -- quest name */
4177 else if (zz[1][0] == 'N')
4179 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4181 strcpy(q_ptr->name, zz[2]);
4187 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4188 else if (zz[1][0] == 'T')
4190 if (init_flags & INIT_SHOW_TEXT)
4192 strcpy(quest_text[quest_text_line], zz[2]);
4200 /* Process "W:<command>: ..." -- info for the wilderness */
4201 else if (buf[0] == 'W')
4203 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4206 /* Process "P:<y>:<x>" -- player position */
4207 else if (buf[0] == 'P')
4209 if (init_flags & INIT_CREATE_DUNGEON)
4211 if (tokenize(buf + 2, 2, zz, 0) == 2)
4213 int panels_x, panels_y;
4215 /* Hack - Set the dungeon size */
4216 panels_y = (*y / SCREEN_HGT);
4217 if (*y % SCREEN_HGT) panels_y++;
4218 current_floor_ptr->height = panels_y * SCREEN_HGT;
4220 panels_x = (*x / SCREEN_WID);
4221 if (*x % SCREEN_WID) panels_x++;
4222 current_floor_ptr->width = panels_x * SCREEN_WID;
4224 /* Assume illegal panel */
4225 panel_row_min = current_floor_ptr->height;
4226 panel_col_min = current_floor_ptr->width;
4228 /* Place player in a quest level */
4229 if (p_ptr->inside_quest)
4233 /* Delete the monster (if any) */
4234 delete_monster(p_ptr->y, p_ptr->x);
4242 /* Place player in the town */
4243 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4245 p_ptr->oldpy = atoi(zz[0]);
4246 p_ptr->oldpx = atoi(zz[1]);
4254 /* Process "B:<Index>:<Command>:..." -- Building definition */
4255 else if (buf[0] == 'B')
4257 return parse_line_building(buf);
4260 /* Process "M:<type>:<maximum>" -- set maximum values */
4261 else if (buf[0] == 'M')
4263 if (tokenize(buf + 2, 2, zz, 0) == 2)
4266 if (zz[0][0] == 'T')
4268 max_towns = (TOWN_IDX)atoi(zz[1]);
4271 /* Maximum quests */
4272 else if (zz[0][0] == 'Q')
4274 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4278 else if (zz[0][0] == 'R')
4280 max_r_idx = (IDX)atoi(zz[1]);
4284 else if (zz[0][0] == 'K')
4286 max_k_idx = (IDX)atoi(zz[1]);
4290 else if (zz[0][0] == 'V')
4292 max_v_idx = (IDX)atoi(zz[1]);
4296 else if (zz[0][0] == 'F')
4298 max_f_idx = (IDX)atoi(zz[1]);
4302 else if (zz[0][0] == 'A')
4304 max_a_idx = (IDX)atoi(zz[1]);
4308 else if (zz[0][0] == 'E')
4310 max_e_idx = (IDX)atoi(zz[1]);
4314 else if (zz[0][0] == 'D')
4316 max_d_idx = (IDX)atoi(zz[1]);
4320 else if (zz[0][0] == 'O')
4322 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4326 else if (zz[0][0] == 'M')
4328 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4331 /* Wilderness size */
4332 else if (zz[0][0] == 'W')
4334 /* Maximum wild_x_size */
4335 if (zz[0][1] == 'X')
4336 current_world_ptr->max_wild_x = atoi(zz[1]);
4337 /* Maximum wild_y_size */
4338 if (zz[0][1] == 'Y')
4339 current_world_ptr->max_wild_y = atoi(zz[1]);
4353 static concptr variant = "ZANGBAND";
4357 * @brief クエスト用固定ダンジョン生成時の分岐処理
4358 * Helper function for "process_dungeon_file()"
4363 static concptr process_dungeon_file_expr(char **sp, char *fp)
4379 while (iswspace(*s)) s++;
4397 t = process_dungeon_file_expr(&s, &f);
4405 else if (streq(t, "IOR"))
4408 while (*s && (f != b2))
4410 t = process_dungeon_file_expr(&s, &f);
4411 if (*t && !streq(t, "0")) v = "1";
4416 else if (streq(t, "AND"))
4419 while (*s && (f != b2))
4421 t = process_dungeon_file_expr(&s, &f);
4422 if (*t && streq(t, "0")) v = "0";
4427 else if (streq(t, "NOT"))
4430 while (*s && (f != b2))
4432 t = process_dungeon_file_expr(&s, &f);
4433 if (*t && streq(t, "1")) v = "0";
4438 else if (streq(t, "EQU"))
4441 if (*s && (f != b2))
4443 t = process_dungeon_file_expr(&s, &f);
4445 while (*s && (f != b2))
4447 p = process_dungeon_file_expr(&s, &f);
4448 if (streq(t, p)) v = "1";
4453 else if (streq(t, "LEQ"))
4456 if (*s && (f != b2))
4458 t = process_dungeon_file_expr(&s, &f);
4460 while (*s && (f != b2))
4463 t = process_dungeon_file_expr(&s, &f);
4464 if (*t && atoi(p) > atoi(t)) v = "0";
4469 else if (streq(t, "GEQ"))
4472 if (*s && (f != b2))
4474 t = process_dungeon_file_expr(&s, &f);
4476 while (*s && (f != b2))
4479 t = process_dungeon_file_expr(&s, &f);
4481 /* Compare two numbers instead of string */
4482 if (*t && atoi(p) < atoi(t)) v = "0";
4488 while (*s && (f != b2))
4490 t = process_dungeon_file_expr(&s, &f);
4495 if (f != b2) v = "?x?x?";
4497 /* Extract final and Terminate */
4498 if ((f = *s) != '\0') *s++ = '\0';
4504 /* Accept all printables except spaces and brackets */
4506 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4508 if (iskanji(*s)) s++;
4512 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4515 /* Extract final and Terminate */
4516 if ((f = *s) != '\0') *s++ = '\0';
4522 if (streq(b + 1, "SYS"))
4528 else if (streq(b + 1, "GRAF"))
4533 else if (streq(b + 1, "MONOCHROME"))
4542 else if (streq(b + 1, "RACE"))
4544 v = _(rp_ptr->E_title, rp_ptr->title);
4548 else if (streq(b + 1, "CLASS"))
4550 v = _(cp_ptr->E_title, cp_ptr->title);
4554 else if (streq(b + 1, "REALM1"))
4556 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4560 else if (streq(b + 1, "REALM2"))
4562 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4566 else if (streq(b + 1, "PLAYER"))
4568 static char tmp_player_name[32];
4570 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4580 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4583 v = tmp_player_name;
4587 else if (streq(b + 1, "TOWN"))
4589 sprintf(tmp, "%d", p_ptr->town_num);
4594 else if (streq(b + 1, "LEVEL"))
4596 sprintf(tmp, "%d", p_ptr->lev);
4600 /* Current quest number */
4601 else if (streq(b + 1, "QUEST_NUMBER"))
4603 sprintf(tmp, "%d", p_ptr->inside_quest);
4607 /* Number of last quest */
4608 else if (streq(b + 1, "LEAVING_QUEST"))
4610 sprintf(tmp, "%d", leaving_quest);
4615 else if (prefix(b + 1, "QUEST_TYPE"))
4617 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4618 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4623 else if (prefix(b + 1, "QUEST"))
4625 /* "QUEST" uses a special parameter to determine the number of the quest */
4626 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4631 else if (prefix(b + 1, "RANDOM"))
4633 /* "RANDOM" uses a special parameter to determine the number of the quest */
4634 sprintf(tmp, "%d", (int)(seed_town%atoi(b + 7)));
4639 else if (streq(b + 1, "VARIANT"))
4645 else if (streq(b + 1, "WILDERNESS"))
4648 sprintf(tmp, "NONE");
4650 sprintf(tmp, "LITE");
4652 sprintf(tmp, "NORMAL");
4671 void write_r_info_txt(void)
4673 int i, j, z, fc, bc;
4676 concptr flags[32 * 10];
4681 monster_race *r_ptr;
4683 monster_blow *b_ptr;
4685 FILE *fff = fopen("output.txt", "wt");
4689 BIT_FLAGS mode = -1;
4693 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4695 fprintf(fff, "# Version stamp (required)\n\n");
4698 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4701 fprintf(fff, "##### The Player #####\n\n");
4703 for (z = -1; z < alloc_race_size; z++)
4705 /* Output the monsters in order */
4706 i = (z >= 0) ? alloc_race_table[z].index : 0;
4708 /* Acquire the monster */
4711 /* Ignore empty monsters */
4712 if (!strlen(r_name + r_ptr->name)) continue;
4714 /* Ignore useless monsters */
4715 if (i && !r_ptr->speed) continue;
4717 /* Write a note if necessary */
4718 if (i && (!r_ptr->level != !mode))
4723 fprintf(fff, "\n##### Town monsters #####\n\n");
4725 /* Note the dungeon */
4728 fprintf(fff, "\n##### Normal monsters #####\n\n");
4731 /* Record the change */
4732 mode = r_ptr->level;
4735 /* Acquire the flags */
4736 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4737 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4738 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4739 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4740 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4741 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4742 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4743 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4744 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4745 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4747 /* Write New/Number/Name */
4748 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4751 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4753 /* Write Information */
4754 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4755 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4757 /* Write more information */
4758 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4761 for (j = 0; j < 4; j++)
4763 b_ptr = &(r_ptr->blow[j]);
4765 /* Stop when done */
4766 if (!b_ptr->method) break;
4768 /* Write the blows */
4769 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4770 r_info_blow_effect[b_ptr->effect],
4771 b_ptr->d_dice, b_ptr->d_side);
4773 for (fc = 0, j = 0; j < 32 * 3; j++)
4775 /* Check this flag */
4776 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4779 /* Extract the extra flags */
4780 for (j = 32 * 6; j < 32 * 10; j++)
4782 /* Check this flag */
4783 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4786 /* Write the flags */
4787 for (j = 0; j < fc;)
4791 /* Start the line */
4794 for (bc = 0; (bc < 60) && (j < fc); j++)
4798 /* Format the flag */
4799 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4801 /* Add it to the buffer */
4804 /* Note the length */
4808 /* Done with this line; write it */
4809 fprintf(fff, "%s\n", buf);
4812 /* Write Spells if applicable */
4813 if (r_ptr->freq_spell)
4815 /* Write the frequency */
4816 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4818 /* Extract the spell flags */
4819 for (fc = 0, j = 96; j < 192; j++)
4821 /* Check this flag */
4822 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4825 /* Write the flags */
4826 for (j = 0; j < fc;)
4830 /* Start the line */
4833 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4837 /* Format the flag */
4838 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4842 /* Note the length */
4849 /* Done with this line; write it */
4850 fprintf(fff, "%s\n", buf);
4854 /* Acquire the description */
4855 desc = r_text + r_ptr->text;
4856 dlen = strlen(desc);
4858 /* Write Description */
4859 for (j = 0; j < dlen;)
4863 /* Start the line */
4866 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4874 /* Done with this line; write it */
4875 fprintf(fff, "%s\n", buf);
4878 /* Space between entries */
4889 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4890 * Helper function for "process_dungeon_file()"
4898 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4904 bool bypass = FALSE;
4905 int x = xmin, y = ymin;
4908 /* Build the filename */
4909 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4912 fp = my_fopen(buf, "r");
4915 if (!fp) return (-1);
4918 /* Process the file */
4919 while (0 == my_fgets(fp, buf, sizeof(buf)))
4925 /* Skip "empty" lines */
4926 if (!buf[0]) continue;
4928 /* Skip "blank" lines */
4929 if (iswspace(buf[0])) continue;
4932 if (buf[0] == '#') continue;
4935 /* Process "?:<expr>" */
4936 if ((buf[0] == '?') && (buf[1] == ':'))
4945 /* Parse the expr */
4946 v = process_dungeon_file_expr(&s, &f);
4949 bypass = (streq(v, "0") ? TRUE : FALSE);
4953 /* Apply conditionals */
4954 if (bypass) continue;
4956 /* Process the line */
4957 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4968 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4970 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4971 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);