5 #include "dungeon-file.h"
11 dungeon_grid letter[255];
15 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
19 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
20 * This software may be copied and distributed for educational, research,
21 * and not for profit purposes provided that this copyright and statement
22 * are included in all such copies. Other copyrights may also apply.
23 * 2014 Deskull rearranged comment for Doxygen.\n
27 * This file is used to initialize various variables and arrays for the
28 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
29 * the common limitation of "read()" and "write()" to only 32767 bytes
31 * Several of the arrays for Angband are built from "template" files in
32 * the "lib/file" directory, from which quick-load binary "image" files
33 * are constructed whenever they are not present in the "lib/data"
34 * directory, or if those files become obsolete, if we are allowed.
35 * Warning -- the "ascii" file parsers use a minor hack to collect the
36 * name and text information in a single pass. Thus, the game will not
37 * be able to load any template file with more than 20K of names or 60K
38 * of text, even though technically, up to 64K should be legal.
40 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
41 * in this file is compiled out, and the game will not run unless valid
42 * "binary template files" already exist in "lib/data". Thus, one can
43 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
44 * "*.raw" files in "lib/data", and then quit, and recompile without
45 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
46 * from changing the ascii template files in potentially dangerous ways.
47 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
48 * このファイルのコードの多くはコンパイル出力され、本ゲームは
49 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
50 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
51 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
52 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
53 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
54 * テンプレートファイルを変更することを妨げることができる。
55 * The code could actually be removed and placed into a "stand-alone"
56 * program, but that feels a little silly, especially considering some
57 * of the platforms that we currently support.
62 #include "dungeon-file.h"
67 #include "cmd-activate.h"
71 #include "view-mainwindow.h"
75 #ifdef ALLOW_TEMPLATES
80 /*** Helper arrays for parsing ascii template files ***/
84 * Monster Blow Methods
86 static concptr r_info_blow_method[] =
119 * モンスターの打撃属性トークンの定義 /
120 * Monster Blow Effects
122 static concptr r_info_blow_effect[] =
167 static concptr f_info_flags[] =
292 static concptr r_info_flags1[] =
332 static concptr r_info_flags2[] =
372 static concptr r_info_flags3[] =
412 static concptr r_info_flags4[] =
449 * モンスター特性トークン(発動型能力1) /
452 static concptr r_a_ability_flags1[] =
489 * モンスター特性トークン(発動型能力2) /
492 static concptr r_a_ability_flags2[] =
509 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
530 * モンスター特性トークン(発動型能力3) /
533 static concptr r_a_ability_flags3[] =
572 * モンスター特性トークン(発動型能力4) /
575 static concptr r_a_ability_flags4[] =
617 static concptr r_info_flags7[] =
657 static concptr r_info_flags8[] =
689 "WILD_SWAMP", /* ToDo: Implement Swamp */
698 static concptr r_info_flags9[] =
737 * モンスター特性トークンの定義R(耐性) /
740 static concptr r_info_flagsr[] =
778 * オブジェクト基本特性トークンの定義 /
781 static concptr k_info_flags[] =
878 "XXX3", /* Fake flag for Smith */
879 "XXX4", /* Fake flag for Smith */
929 * オブジェクト生成特性トークンの定義 /
932 static concptr k_info_gen_flags[] =
972 static concptr d_info_flags1[] =
1010 * @brief データの可変文字列情報をテキストとして保管する /
1011 * Add a text to the text-storage and store offset to it.
1012 * @param offset 文字列保管ポインタからのオフセット
1013 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1015 * @param normal_text テキストの正規化を行う
1018 * Returns FALSE when there isn't enough space available to store
1021 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1023 /* Hack -- Verify space */
1024 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1030 /* Advance and save the text index */
1031 *offset = ++head->text_size;
1034 /* Additional text */
1035 else if (normal_text)
1038 * If neither the end of the last line nor
1039 * the beginning of current line is not a space,
1040 * fill up a space as a correct separator of two words.
1042 if (head->text_size > 0 &&
1044 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1045 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1046 (buf[0] != ' ') && !iskanji(buf[0])
1048 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1053 /* Append a space */
1054 *(head->text_ptr + head->text_size) = ' ';
1056 /* Advance the index */
1061 /* Append chars to the text */
1062 strcpy(head->text_ptr + head->text_size, buf);
1064 /* Advance the index */
1065 head->text_size += strlen(buf);
1073 * @brief データの可変文字列情報を名前として保管する /
1074 * Add a name to the name-storage and return an offset to it.
1075 * @param offset 文字列保管ポインタからのオフセット
1076 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1080 * Returns FALSE when there isn't enough space available to store
1083 static bool add_name(u32b *offset, header *head, concptr buf)
1085 /* Hack -- Verify space */
1086 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1092 /* Advance and save the name index */
1093 *offset = ++head->name_size;
1096 /* Append chars to the names */
1097 strcpy(head->name_ptr + head->name_size, buf);
1099 /* Advance the index */
1100 head->name_size += strlen(buf);
1108 * @brief データの可変文字列情報をタグとして保管する /
1109 * Add a tag to the tag-storage and return an offset to it.
1110 * @param offset 文字列保管ポインタからのオフセット
1111 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1115 * Returns FALSE when there isn't enough space available to store
1118 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1122 /* Search for an existing (fake) tag */
1123 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1126 if (streq(&head->tag_ptr[i], buf)) break;
1129 /* There was no existing tag */
1130 if (i >= head->tag_size)
1132 /* Hack -- Verify space */
1133 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1136 /* Append chars to the tags */
1137 strcpy(head->tag_ptr + head->tag_size, buf);
1139 /* Point the new tag */
1142 /* Advance the index */
1143 head->tag_size += strlen(buf) + 1;
1146 /* Return offset of the tag */
1154 /*** Initialize from ascii template files ***/
1158 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1159 * Initialize an "*_info" array, by parsing an ascii "template" file
1160 * @param fp 読み取りに使うファイルポインタ
1161 * @param buf 読み取りに使うバッファ領域
1162 * @param head ヘッダ構造体
1163 * @param parse_info_txt_line パース関数
1166 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1170 /* Just before the first record */
1173 /* Just before the first line */
1177 /* Prepare the "fake" stuff */
1178 head->name_size = 0;
1179 head->text_size = 0;
1183 while (0 == my_fgets(fp, buf, 1024))
1185 /* Advance the line number */
1188 /* Skip comments and blank lines */
1189 if (!buf[0] || (buf[0] == '#')) continue;
1191 /* Verify correct "colon" format */
1192 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1195 /* Hack -- Process 'V' for "Version" */
1202 /* Mega Hack -- Calculate Check Sum */
1203 if (buf[0] != 'N' && buf[0] != 'D')
1206 for (i = 0; buf[i]; i++)
1208 head->v_extra += (byte)buf[i];
1209 head->v_extra ^= (1 << (i % 8));
1213 /* Parse the line */
1214 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1219 /* Complete the "name" and "text" sizes */
1220 if (head->name_size) head->name_size++;
1221 if (head->text_size) head->text_size++;
1229 * @brief Vault情報(v_info)のパース関数 /
1230 * Initialize the "v_info" array, by parsing an ascii "template" file
1232 * @param head ヘッダ構造体
1235 errr parse_v_info(char *buf, header *head)
1241 static vault_type *v_ptr = NULL;
1243 /* Process 'N' for "New/Number/Name" */
1246 /* Find the colon before the name */
1247 s = my_strchr(buf + 2, ':');
1249 /* Verify that colon */
1252 /* Nuke the colon, advance to the name */
1255 /* Paranoia -- require a name */
1256 if (!*s) return (1);
1261 /* Verify information */
1262 if (i <= error_idx) return (4);
1264 /* Verify information */
1265 if (i >= head->info_num) return (2);
1267 /* Save the index */
1270 /* Point at the "info" */
1273 /* Store the name */
1274 if (!add_name(&v_ptr->name, head, s)) return (7);
1277 /* There better be a current v_ptr */
1278 else if (!v_ptr) return (3);
1280 /* Process 'D' for "Description" */
1281 else if (buf[0] == 'D')
1283 /* Acquire the text */
1286 /* Store the text */
1287 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1290 /* Process 'X' for "Extra info" (one line only) */
1291 else if (buf[0] == 'X')
1293 EFFECT_ID typ, rat, hgt, wid;
1295 /* Scan for the values */
1296 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1297 &typ, &rat, &hgt, &wid)) return (1);
1299 /* Save the values */
1300 v_ptr->typ = (ROOM_IDX)typ;
1301 v_ptr->rat = (PROB)rat;
1302 v_ptr->hgt = (POSITION)hgt;
1303 v_ptr->wid = (POSITION)wid;
1314 * @brief 職業技能情報(s_info)のパース関数 /
1315 * Initialize the "s_info" array, by parsing an ascii "template" file
1317 * @param head ヘッダ構造体
1320 errr parse_s_info(char *buf, header *head)
1325 static skill_table *s_ptr = NULL;
1328 /* Process 'N' for "New/Number/Name" */
1334 /* Verify information */
1335 if (i <= error_idx) return (4);
1337 /* Verify information */
1338 if (i >= head->info_num) return (2);
1340 /* Save the index */
1343 /* Point at the "info" */
1347 /* There better be a current s_ptr */
1348 else if (!s_ptr) return (3);
1350 /* Process 'W' for "Weapon exp" */
1351 else if (buf[0] == 'W')
1353 int tval, sval, start, max;
1354 const s16b exp_conv_table[] =
1356 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1357 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1360 /* Scan for the values */
1361 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1362 &tval, &sval, &start, &max)) return (1);
1364 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1365 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1367 /* Save the values */
1368 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1369 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1372 /* Process 'S' for "Skill exp" */
1373 else if (buf[0] == 'S')
1375 int num, start, max;
1377 /* Scan for the values */
1378 if (3 != sscanf(buf + 2, "%d:%d:%d",
1379 &num, &start, &max)) return (1);
1381 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1382 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1384 /* Save the values */
1385 s_ptr->s_start[num] = (SUB_EXP)start;
1386 s_ptr->s_max[num] = (SUB_EXP)max;
1398 * @brief 職業魔法情報(m_info)のパース関数 /
1399 * Initialize the "m_info" array, by parsing an ascii "template" file
1401 * @param head ヘッダ構造体
1404 errr parse_m_info(char *buf, header *head)
1411 static player_magic *m_ptr = NULL;
1414 static int realm, magic_idx = 0, readable = 0;
1417 /* Process 'N' for "New/Number/Name" */
1423 /* Verify information */
1424 if (i <= error_idx) return (4);
1426 /* Verify information */
1427 if (i >= head->info_num) return (2);
1429 /* Save the index */
1432 /* Point at the "info" */
1436 /* There better be a current m_ptr */
1437 else if (!m_ptr) return (3);
1439 /* Process 'I' for "Info" (one line only) */
1440 else if (buf[0] == 'I')
1443 int xtra, type, first, weight;
1445 /* Find the colon before the name */
1446 s = my_strchr(buf + 2, ':');
1448 /* Verify that colon */
1451 /* Nuke the colon, advance to the name */
1456 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1457 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1458 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1459 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1460 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1465 /* Find the colon before the name */
1466 s = my_strchr(s, ':');
1468 /* Verify that colon */
1471 /* Nuke the colon, advance to the name */
1474 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1475 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1476 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1477 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1478 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1479 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1483 /* Scan for the values */
1484 if (4 != sscanf(s, "%x:%d:%d:%d",
1485 (uint *)&xtra, &type, &first, &weight)) return (1);
1487 m_ptr->spell_xtra = xtra;
1488 m_ptr->spell_type = type;
1489 m_ptr->spell_first = first;
1490 m_ptr->spell_weight = weight;
1494 /* Process 'R' for "Realm" (one line only) */
1495 else if (buf[0] == 'R')
1497 /* Scan for the values */
1498 if (2 != sscanf(buf + 2, "%d:%d",
1499 &realm, &readable)) return (1);
1504 else if (buf[0] == 'T')
1506 int level, mana, fail, exp;
1508 if (!readable) return (1);
1509 /* Scan for the values */
1510 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1511 &level, &mana, &fail, &exp)) return (1);
1513 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1514 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1515 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1516 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1529 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1530 * Grab one flag from a textual string
1531 * @param flags ビットフラグを追加する先の参照ポインタ
1532 * @param names トークン定義配列
1533 * @param what 参照元の文字列ポインタ
1536 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1541 for (i = 0; i < 32; i++)
1543 if (streq(what, names[i]))
1545 *flags |= (1L << i);
1555 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1556 * Grab one flag in an feature_type from a textual string
1557 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1558 * @param what 参照元の文字列ポインタ
1561 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1566 for (i = 0; i < FF_FLAG_MAX; i++)
1568 if (streq(what, f_info_flags[i]))
1570 add_flag(f_ptr->flags, i);
1575 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1578 return PARSE_ERROR_GENERIC;
1583 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1584 * Grab an action in an feature_type from a textual string
1585 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1586 * @param what 参照元の文字列ポインタ
1587 * @param count ステートの保存先ID
1590 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1595 for (i = 0; i < FF_FLAG_MAX; i++)
1597 if (streq(what, f_info_flags[i]))
1599 f_ptr->state[count].action = i;
1604 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1607 return PARSE_ERROR_GENERIC;
1612 * @brief 地形情報(f_info)のパース関数 /
1613 * Initialize the "f_info" array, by parsing an ascii "template" file
1615 * @param head ヘッダ構造体
1618 errr parse_f_info(char *buf, header *head)
1625 static feature_type *f_ptr = NULL;
1628 /* Process 'N' for "New/Number/Name" */
1631 /* Find the colon before the name */
1632 s = my_strchr(buf + 2, ':');
1636 /* Nuke the colon, advance to the name */
1643 /* Verify information */
1644 if (i <= error_idx) return (4);
1646 /* Verify information */
1647 if (i >= head->info_num) return (2);
1649 /* Save the index */
1652 /* Point at the "info" */
1655 /* Tag name is given */
1659 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1662 /* Default "mimic" */
1663 f_ptr->mimic = (FEAT_IDX)i;
1665 /* Default "destroyed state" -- if not specified */
1666 f_ptr->destroyed = (FEAT_IDX)i;
1668 /* Default "states" */
1669 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1672 /* There better be a current f_ptr */
1673 else if (!f_ptr) return (3);
1676 else if (buf[0] == 'J')
1678 /* Store the name */
1679 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1682 else if (buf[0] == 'E')
1684 /* Ignore english name */
1687 else if (buf[0] == 'J')
1689 /* Ignore Japanese name */
1692 else if (buf[0] == 'E')
1694 /* Acquire the Text */
1697 /* Store the name */
1698 if (!add_name(&f_ptr->name, head, s)) return (7);
1703 /* Process 'M' for "Mimic" (one line only) */
1704 else if (buf[0] == 'M')
1708 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1710 /* Record a fake tag index */
1711 f_ptr->mimic_tag = offset;
1715 /* Process 'G' for "Graphics" (one line only) */
1716 else if (buf[0] == 'G')
1720 char char_tmp[F_LIT_MAX];
1721 if (buf[1] != ':') return (1);
1722 if (!buf[2]) return (1);
1723 if (buf[3] != ':') return (1);
1724 if (!buf[4]) return (1);
1726 /* Extract the char */
1727 char_tmp[F_LIT_STANDARD] = buf[2];
1729 /* Extract the color */
1730 s_attr = color_char_to_attr(buf[4]);
1731 if (s_attr > 127) return (1);
1733 /* Save the standard values */
1734 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1735 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1737 /* Is this feature supports lighting? */
1740 /* G:c:a:LIT (default) */
1741 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1743 /* G:c:a:lc:la:dc:da */
1744 if (!streq(buf + 6, "LIT"))
1746 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1748 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1749 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1750 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1751 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1753 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1755 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1758 /* Use default lighting */
1761 /* No lighting support */
1762 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1765 /* Extract the color */
1766 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1767 if (f_ptr->d_attr[j] > 127) return 1;
1770 f_ptr->d_char[j] = char_tmp[j];
1776 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1778 f_ptr->d_attr[j] = s_attr;
1779 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1785 /* Hack -- Process 'F' for flags */
1786 else if (buf[0] == 'F')
1788 /* Parse every entry textually */
1789 for (s = buf + 2; *s; )
1791 /* Find the end of this entry */
1792 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1794 /* Nuke and skip any dividers */
1798 while (*t == ' ' || *t == '|') t++;
1801 /* Hack -- Read feature subtype */
1802 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1804 /* Extract a "subtype" */
1805 f_ptr->subtype = (FEAT_SUBTYPE)i;
1807 /* Start at next entry */
1813 /* Hack -- Read feature power */
1814 if (1 == sscanf(s, "POWER_%d", &i))
1816 /* Extract a "power" */
1817 f_ptr->power = (FEAT_POWER)i;
1819 /* Start at next entry */
1824 /* Parse this entry */
1825 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1827 /* Start the next entry */
1832 /* Process 'W' for "More Info" (one line only) */
1833 else if (buf[0] == 'W')
1837 /* Scan for the value */
1838 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1840 /* Save the value */
1841 f_ptr->priority = (FEAT_PRIORITY)priority;
1844 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1845 else if (buf[0] == 'K')
1849 /* Find the next empty state slot (if any) */
1850 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1852 /* Oops, no more slots */
1853 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1855 /* Analyze the first field */
1856 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1858 /* Terminate the field (if necessary) */
1859 if (*t == ':') *t++ = '\0';
1861 /* Is this default entry? */
1862 if (streq(s, "DESTROYED"))
1864 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1866 /* Record a fake tag index */
1867 f_ptr->destroyed_tag = offset;
1872 f_ptr->state[i].action = 0;
1874 /* Parse this entry */
1875 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1877 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1879 /* Record a fake tag index */
1880 f_ptr->state[i].result_tag = offset;
1892 * @brief 地形タグからIDを得る /
1893 * Convert a fake tag to a real feat index
1897 s16b f_tag_to_index(concptr str)
1901 /* Search for real index corresponding to this fake tag */
1902 for (i = 0; i < f_head.info_num; i++)
1904 if (streq(f_tag + f_info[i].tag, str))
1906 /* Return the index */
1917 * @brief 地形タグからIDを得る /
1918 * Search for real index corresponding to this fake tag
1919 * @param feat タグ文字列のオフセット
1920 * @return 地形ID。該当がないなら-1
1922 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1926 /* Don't convert non-fake tag */
1932 /* Search for real index corresponding to this fake tag */
1933 for (i = 0; i < f_head.info_num; i++)
1935 if (feat == f_info[i].tag)
1937 /* Record real index */
1943 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1949 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1950 * Retouch fake tags of f_info
1951 * @param head ヘッダ構造体
1954 void retouch_f_info(header *head)
1958 /* Convert fake tags to real feat indices */
1959 for (i = 0; i < head->info_num; i++)
1961 feature_type *f_ptr = &f_info[i];
1964 k = search_real_feat(f_ptr->mimic_tag);
1965 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1966 k = search_real_feat(f_ptr->destroyed_tag);
1967 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1968 for (j = 0; j < MAX_FEAT_STATES; j++)
1970 k = search_real_feat(f_ptr->state[j].result_tag);
1971 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1978 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1979 * Grab one flag in an object_kind from a textual string
1980 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1981 * @param what 参照元の文字列ポインタ
1984 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1989 for (i = 0; i < TR_FLAG_MAX; i++)
1991 if (streq(what, k_info_flags[i]))
1993 add_flag(k_ptr->flags, i);
1998 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2001 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2008 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2009 * Grab one activation index flag
2010 * @param what 参照元の文字列ポインタ
2013 static byte grab_one_activation_flag(concptr what)
2019 if (activation_info[i].flag == NULL) break;
2021 if (streq(what, activation_info[i].flag))
2023 return activation_info[i].index;
2033 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2041 * @brief ベースアイテム(k_info)のパース関数 /
2042 * Initialize the "k_info" array, by parsing an ascii "template" file
2044 * @param head ヘッダ構造体
2047 errr parse_k_info(char *buf, header *head)
2054 static object_kind *k_ptr = NULL;
2057 /* Process 'N' for "New/Number/Name" */
2064 /* Find the colon before the name */
2065 s = my_strchr(buf + 2, ':');
2067 /* Verify that colon */
2070 /* Nuke the colon, advance to the name */
2076 /* Verify information */
2077 if (i <= error_idx) return (4);
2079 /* Verify information */
2080 if (i >= head->info_num) return (2);
2082 /* Save the index */
2085 /* Point at the "info" */
2089 /* Paranoia -- require a name */
2090 if (!*s) return (1);
2092 /* Find the colon before the flavor */
2093 flavor = my_strchr(s, ':');
2095 /* Verify that colon */
2098 /* Nuke the colon, advance to the flavor */
2101 /* Store the flavor */
2102 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2105 /* Store the name */
2106 if (!add_name(&k_ptr->name, head, s)) return (7);
2110 /* There better be a current k_ptr */
2111 else if (!k_ptr) return (3);
2116 /* 'E' から始まる行は英語名としている */
2117 else if (buf[0] == 'E')
2122 else if (buf[0] == 'E')
2126 /* Acquire the name */
2129 /* Find the colon before the flavor */
2130 flavor = my_strchr(s, ':');
2132 /* Verify that colon */
2135 /* Nuke the colon, advance to the flavor */
2138 /* Store the flavor */
2139 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2142 /* Store the name */
2143 if (!add_name(&k_ptr->name, head, s)) return (7);
2147 /* Process 'D' for "Description" */
2148 else if (buf[0] == 'D')
2153 /* Acquire the text */
2158 /* Acquire the text */
2162 /* Store the text */
2163 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2166 /* Process 'G' for "Graphics" (one line only) */
2167 else if (buf[0] == 'G')
2171 if (buf[1] != ':') return (1);
2172 if (!buf[2]) return (1);
2173 if (buf[3] != ':') return (1);
2174 if (!buf[4]) return (1);
2176 /* Extract the char */
2179 /* Extract the attr */
2180 tmp = color_char_to_attr(buf[4]);
2181 if (tmp > 127) return (1);
2183 /* Save the values */
2184 k_ptr->d_attr = tmp;
2185 k_ptr->d_char = sym;
2188 /* Process 'I' for "Info" (one line only) */
2189 else if (buf[0] == 'I')
2191 int tval, sval, pval;
2193 /* Scan for the values */
2194 if (3 != sscanf(buf + 2, "%d:%d:%d",
2195 &tval, &sval, &pval)) return (1);
2197 /* Save the values */
2198 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2199 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2200 k_ptr->pval = (PARAMETER_VALUE)pval;
2203 /* Process 'W' for "More Info" (one line only) */
2204 else if (buf[0] == 'W')
2206 int level, extra, wgt;
2209 /* Scan for the values */
2210 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2211 &level, &extra, &wgt, &cost)) return (1);
2213 /* Save the values */
2214 k_ptr->level = (DEPTH)level;
2215 k_ptr->extra = (BIT_FLAGS8)extra;
2216 k_ptr->weight = (WEIGHT)wgt;
2217 k_ptr->cost = (PRICE)cost;
2220 /* Process 'A' for "Allocation" (one line only) */
2221 else if (buf[0] == 'A')
2224 /* Simply read each number following a colon */
2225 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2227 /* Default chance */
2228 k_ptr->chance[i] = 1;
2230 /* Store the attack damage index */
2231 k_ptr->locale[i] = atoi(s + 1);
2233 /* Find the slash */
2234 t = my_strchr(s + 1, '/');
2236 /* Find the next colon */
2237 s = my_strchr(s + 1, ':');
2239 /* If the slash is "nearby", use it */
2240 if (t && (!s || t < s))
2242 int chance = atoi(t + 1);
2243 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2248 /* Hack -- Process 'P' for "power" and such */
2249 else if (buf[0] == 'P')
2251 int ac, hd1, hd2, th, td, ta;
2253 /* Scan for the values */
2254 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2255 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2257 k_ptr->ac = (ARMOUR_CLASS)ac;
2258 k_ptr->dd = (DICE_NUMBER)hd1;
2259 k_ptr->ds = (DICE_SID)hd2;
2260 k_ptr->to_h = (HIT_PROB)th;
2261 k_ptr->to_d = (HIT_POINT)td;
2262 k_ptr->to_a = (ARMOUR_CLASS)ta;
2265 /* Hack -- Process 'U' for activation index */
2266 else if (buf[0] == 'U')
2269 n = grab_one_activation_flag(buf + 2);
2280 /* Hack -- Process 'F' for flags */
2281 else if (buf[0] == 'F')
2283 /* Parse every entry textually */
2284 for (s = buf + 2; *s; )
2286 /* Find the end of this entry */
2287 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2289 /* Nuke and skip any dividers */
2293 while (*t == ' ' || *t == '|') t++;
2296 /* Parse this entry */
2297 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2299 /* Start the next entry */
2313 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2314 * Grab one activation index flag
2315 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2316 * @param what 参照元の文字列ポインタ
2317 * @return エラーがあった場合1、エラーがない場合0を返す
2319 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2324 for (i = 0; i < TR_FLAG_MAX; i++)
2326 if (streq(what, k_info_flags[i]))
2328 add_flag(a_ptr->flags, i);
2333 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2336 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2344 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2345 * Initialize the "a_info" array, by parsing an ascii "template" file
2347 * @param head ヘッダ構造体
2350 errr parse_a_info(char *buf, header *head)
2357 static artifact_type *a_ptr = NULL;
2360 /* Process 'N' for "New/Number/Name" */
2363 /* Find the colon before the name */
2364 s = my_strchr(buf + 2, ':');
2366 /* Verify that colon */
2369 /* Nuke the colon, advance to the name */
2372 /* Paranoia -- require a name */
2373 if (!*s) return (1);
2378 /* Verify information */
2379 if (i < error_idx) return (4);
2381 /* Verify information */
2382 if (i >= head->info_num) return (2);
2384 /* Save the index */
2387 /* Point at the "info" */
2390 /* Ignore everything */
2391 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2392 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2393 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2394 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2396 /* Store the name */
2397 if (!add_name(&a_ptr->name, head, s)) return (7);
2401 /* There better be a current a_ptr */
2402 else if (!a_ptr) return (3);
2407 /* 'E' から始まる行は英語名としている */
2408 else if (buf[0] == 'E')
2413 else if (buf[0] == 'E')
2415 /* Acquire the Text */
2418 /* Store the name */
2419 if (!add_name(&a_ptr->name, head, s)) return (7);
2423 /* Process 'D' for "Description" */
2424 else if (buf[0] == 'D')
2429 /* Acquire the text */
2434 /* Acquire the text */
2438 /* Store the text */
2439 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2443 /* Process 'I' for "Info" (one line only) */
2444 else if (buf[0] == 'I')
2446 int tval, sval, pval;
2448 /* Scan for the values */
2449 if (3 != sscanf(buf + 2, "%d:%d:%d",
2450 &tval, &sval, &pval)) return (1);
2452 /* Save the values */
2453 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2454 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2455 a_ptr->pval = (PARAMETER_VALUE)pval;
2458 /* Process 'W' for "More Info" (one line only) */
2459 else if (buf[0] == 'W')
2461 int level, rarity, wgt;
2464 /* Scan for the values */
2465 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2466 &level, &rarity, &wgt, &cost)) return (1);
2468 /* Save the values */
2469 a_ptr->level = (DEPTH)level;
2470 a_ptr->rarity = (RARITY)rarity;
2471 a_ptr->weight = (WEIGHT)wgt;
2472 a_ptr->cost = (PRICE)cost;
2475 /* Hack -- Process 'P' for "power" and such */
2476 else if (buf[0] == 'P')
2478 int ac, hd1, hd2, th, td, ta;
2480 /* Scan for the values */
2481 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2482 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2484 a_ptr->ac = (ARMOUR_CLASS)ac;
2485 a_ptr->dd = (DICE_NUMBER)hd1;
2486 a_ptr->ds = (DICE_SID)hd2;
2487 a_ptr->to_h = (HIT_PROB)th;
2488 a_ptr->to_d = (HIT_POINT)td;
2489 a_ptr->to_a = (ARMOUR_CLASS)ta;
2492 /* Hack -- Process 'U' for activation index */
2493 else if (buf[0] == 'U')
2496 n = grab_one_activation_flag(buf + 2);
2507 /* Hack -- Process 'F' for flags */
2508 else if (buf[0] == 'F')
2510 /* Parse every entry textually */
2511 for (s = buf + 2; *s; )
2513 /* Find the end of this entry */
2514 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2516 /* Nuke and skip any dividers */
2520 while ((*t == ' ') || (*t == '|')) t++;
2523 /* Parse this entry */
2524 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2526 /* Start the next entry */
2541 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2542 * Grab one flag in a ego-item_type from a textual string
2543 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2544 * @param what 参照元の文字列ポインタ
2545 * @return エラーがあった場合1、エラーがない場合0を返す
2547 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2552 for (i = 0; i < TR_FLAG_MAX; i++)
2554 if (streq(what, k_info_flags[i]))
2556 add_flag(e_ptr->flags, i);
2561 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2564 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2572 * @brief アイテムエゴ情報(e_info)のパース関数 /
2573 * Initialize the "e_info" array, by parsing an ascii "template" file
2575 * @param head ヘッダ構造体
2578 errr parse_e_info(char *buf, header *head)
2584 static ego_item_type *e_ptr = NULL;
2586 /* Just before the first record */
2589 /* Just before the first line */
2592 /* Process 'N' for "New/Number/Name" */
2595 /* Find the colon before the name */
2596 s = my_strchr(buf + 2, ':');
2598 /* Verify that colon */
2601 /* Nuke the colon, advance to the name */
2604 /* Paranoia -- require a name */
2605 if (!*s) return (1);
2610 /* Verify information */
2611 if (i < error_idx) return (4);
2613 /* Verify information */
2614 if (i >= head->info_num) return (2);
2616 /* Save the index */
2619 /* Point at the "info" */
2622 /* Store the name */
2623 if (!add_name(&e_ptr->name, head, s)) return (7);
2627 /* There better be a current e_ptr */
2628 else if (!e_ptr) return (3);
2633 /* 'E' から始まる行は英語名 */
2634 else if (buf[0] == 'E')
2639 else if (buf[0] == 'E')
2641 /* Acquire the Text */
2644 /* Store the name */
2645 if (!add_name(&e_ptr->name, head, s)) return (7);
2650 /* Process 'D' for "Description" */
2651 else if (buf[0] == 'D')
2653 /* Acquire the text */
2656 /* Store the text */
2657 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2662 /* Process 'X' for "Xtra" (one line only) */
2663 else if (buf[0] == 'X')
2667 /* Scan for the values */
2668 if (2 != sscanf(buf + 2, "%d:%d",
2669 &slot, &rating)) return (1);
2671 /* Save the values */
2672 e_ptr->slot = (INVENTORY_IDX)slot;
2673 e_ptr->rating = (PRICE)rating;
2676 /* Process 'W' for "More Info" (one line only) */
2677 else if (buf[0] == 'W')
2679 int level, rarity, pad2;
2682 /* Scan for the values */
2683 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2684 &level, &rarity, &pad2, &cost)) return (1);
2686 /* Save the values */
2687 e_ptr->level = level;
2688 e_ptr->rarity = (RARITY)rarity;
2689 /* e_ptr->weight = wgt; */
2693 /* Hack -- Process 'C' for "creation" */
2694 else if (buf[0] == 'C')
2696 int th, td, ta, pval;
2698 /* Scan for the values */
2699 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2700 &th, &td, &ta, &pval)) return (1);
2702 e_ptr->max_to_h = (HIT_PROB)th;
2703 e_ptr->max_to_d = (HIT_POINT)td;
2704 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2705 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2708 /* Hack -- Process 'U' for activation index */
2709 else if (buf[0] == 'U')
2712 n = grab_one_activation_flag(buf + 2);
2723 /* Hack -- Process 'F' for flags */
2724 else if (buf[0] == 'F')
2726 /* Parse every entry textually */
2727 for (s = buf + 2; *s; )
2729 /* Find the end of this entry */
2730 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2732 /* Nuke and skip any dividers */
2736 while ((*t == ' ') || (*t == '|')) t++;
2739 /* Parse this entry */
2740 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2742 /* Start the next entry */
2755 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2756 * Grab one (basic) flag in a monster_race from a textual string
2757 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2758 * @param what 参照元の文字列ポインタ
2761 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2763 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2766 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2769 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2772 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2775 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2778 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2781 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2784 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2792 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2793 * Grab one (spell) flag in a monster_race from a textual string
2794 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2795 * @param what 参照元の文字列ポインタ
2798 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2800 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2803 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2806 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2809 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2817 * @brief モンスター種族情報(r_info)のパース関数 /
2818 * Initialize the "r_info" array, by parsing an ascii "template" file
2820 * @param head ヘッダ構造体
2823 errr parse_r_info(char *buf, header *head)
2829 static monster_race *r_ptr = NULL;
2832 /* Process 'N' for "New/Number/Name" */
2835 /* Find the colon before the name */
2836 s = my_strchr(buf + 2, ':');
2838 /* Verify that colon */
2841 /* Nuke the colon, advance to the name */
2844 /* Paranoia -- require a name */
2845 if (!*s) return (1);
2850 /* Verify information */
2851 if (i < error_idx) return (4);
2853 /* Verify information */
2854 if (i >= head->info_num) return (2);
2856 /* Save the index */
2859 /* Point at the "info" */
2862 /* Store the name */
2863 if (!add_name(&r_ptr->name, head, s)) return (7);
2867 /* There better be a current r_ptr */
2868 else if (!r_ptr) return (3);
2873 /* 'E' から始まる行は英語名 */
2874 else if (buf[0] == 'E')
2876 /* Acquire the Text */
2879 /* Store the name */
2880 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2883 else if (buf[0] == 'E')
2885 /* Acquire the Text */
2888 /* Store the name */
2889 if (!add_name(&r_ptr->name, head, s)) return (7);
2892 /* Process 'D' for "Description" */
2893 else if (buf[0] == 'D')
2898 /* Acquire the text */
2903 /* Acquire the text */
2907 /* Store the text */
2908 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2911 /* Process 'G' for "Graphics" (one line only) */
2912 else if (buf[0] == 'G')
2916 if (buf[1] != ':') return (1);
2917 if (!buf[2]) return (1);
2918 if (buf[3] != ':') return (1);
2919 if (!buf[4]) return (1);
2921 /* Extract the char */
2924 /* Extract the attr */
2925 tmp = color_char_to_attr(buf[4]);
2926 if (tmp > 127) return (1);
2928 /* Save the values */
2929 r_ptr->d_char = sym;
2930 r_ptr->d_attr = tmp;
2933 /* Process 'I' for "Info" (one line only) */
2934 else if (buf[0] == 'I')
2936 int spd, hp1, hp2, aaf, ac, slp;
2938 /* Scan for the other values */
2939 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2940 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2942 /* Save the values */
2943 r_ptr->speed = (SPEED)spd;
2944 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2945 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2946 r_ptr->aaf = (POSITION)aaf;
2947 r_ptr->ac = (ARMOUR_CLASS)ac;
2948 r_ptr->sleep = (SLEEP_DEGREE)slp;
2951 /* Process 'W' for "More Info" (one line only) */
2952 else if (buf[0] == 'W')
2959 /* Scan for the values */
2960 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2961 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2963 /* Save the values */
2964 r_ptr->level = (DEPTH)lev;
2965 r_ptr->rarity = (RARITY)rar;
2966 r_ptr->extra = (BIT_FLAGS16)pad;
2967 r_ptr->mexp = (EXP)exp;
2968 r_ptr->next_exp = (EXP)nextexp;
2969 r_ptr->next_r_idx = (IDX)nextmon;
2972 /* Process 'R' for "Reinforcement" (up to six lines) */
2973 else if (buf[0] == 'R')
2976 /* Find the next empty blow slot (if any) */
2977 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2979 /* Oops, no more slots */
2980 if (i == 6) return (1);
2982 /* Scan for the values */
2983 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2984 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2985 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2986 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2989 /* Process 'B' for "Blows" (up to four lines) */
2990 else if (buf[0] == 'B')
2994 /* Find the next empty blow slot (if any) */
2995 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2997 /* Oops, no more slots */
2998 if (i == 4) return (1);
3000 /* Analyze the first field */
3001 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3003 /* Terminate the field (if necessary) */
3004 if (*t == ':') *t++ = '\0';
3006 /* Analyze the method */
3007 for (n1 = 0; r_info_blow_method[n1]; n1++)
3009 if (streq(s, r_info_blow_method[n1])) break;
3012 /* Invalid method */
3013 if (!r_info_blow_method[n1]) return (1);
3015 /* Analyze the second field */
3016 for (s = t; *t && (*t != ':'); t++) /* loop */;
3018 /* Terminate the field (if necessary) */
3019 if (*t == ':') *t++ = '\0';
3021 /* Analyze effect */
3022 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3024 if (streq(s, r_info_blow_effect[n2])) break;
3027 /* Invalid effect */
3028 if (!r_info_blow_effect[n2]) return (1);
3030 /* Analyze the third field */
3031 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3033 /* Terminate the field (if necessary) */
3034 if (*t == 'd') *t++ = '\0';
3036 /* Save the method */
3037 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3039 /* Save the effect */
3040 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3042 /* Extract the damage dice and sides */
3043 r_ptr->blow[i].d_dice = atoi(s);
3044 r_ptr->blow[i].d_side = atoi(t);
3047 /* Process 'F' for "Basic Flags" (multiple lines) */
3048 else if (buf[0] == 'F')
3050 /* Parse every entry */
3051 for (s = buf + 2; *s; )
3053 /* Find the end of this entry */
3054 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3056 /* Nuke and skip any dividers */
3060 while (*t == ' ' || *t == '|') t++;
3063 /* Parse this entry */
3064 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3066 /* Start the next entry */
3071 /* Process 'S' for "Spell Flags" (multiple lines) */
3072 else if (buf[0] == 'S')
3074 /* Parse every entry */
3075 for (s = buf + 2; *s; )
3077 /* Find the end of this entry */
3078 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3080 /* Nuke and skip any dividers */
3084 while ((*t == ' ') || (*t == '|')) t++;
3087 /* Hack -- Read spell frequency */
3088 if (1 == sscanf(s, "1_IN_%d", &i))
3090 /* Extract a "frequency" */
3091 r_ptr->freq_spell = 100 / i;
3093 /* Start at next entry */
3098 /* Parse this entry */
3099 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3101 /* Start the next entry */
3106 /* Process 'A' for "Artifact Flags" (multiple lines) */
3107 else if (buf[0] == 'A')
3109 int id, per, rarity;
3111 /* Find the next empty blow slot (if any) */
3112 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3114 /* Oops, no more slots */
3115 if (i == 4) return (1);
3117 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3118 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3119 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3120 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3123 /* Process 'V' for "Arena power value ratio" */
3124 else if (buf[0] == 'V')
3127 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3128 r_ptr->arena_ratio = (PERCENTAGE)val;
3140 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3141 * Grab one flag for a dungeon type from a textual string
3142 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3143 * @param what 参照元の文字列ポインタ
3146 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3148 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3151 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3158 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3159 * Grab one (basic) flag in a monster_race from a textual string
3160 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3161 * @param what 参照元の文字列ポインタ
3164 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3166 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3169 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3172 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3175 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3178 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3181 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3184 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3187 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3194 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3195 * Grab one (spell) flag in a monster_race from a textual string
3196 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3197 * @param what 参照元の文字列ポインタ
3200 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3202 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3205 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3208 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3211 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3218 * @brief ダンジョン情報(d_info)のパース関数 /
3219 * Initialize the "d_info" array, by parsing an ascii "template" file
3221 * @param head ヘッダ構造体
3224 errr parse_d_info(char *buf, header *head)
3230 static dungeon_type *d_ptr = NULL;
3232 /* Process 'N' for "New/Number/Name" */
3235 /* Find the colon before the name */
3236 s = my_strchr(buf + 2, ':');
3238 /* Verify that colon */
3241 /* Nuke the colon, advance to the name */
3244 /* Paranoia -- require a name */
3245 if (!*s) return (1);
3250 /* Verify information */
3251 if (i < error_idx) return (4);
3253 /* Verify information */
3254 if (i >= head->info_num) return (2);
3256 /* Save the index */
3259 /* Point at the "info" */
3262 /* Store the name */
3263 if (!add_name(&d_ptr->name, head, s)) return (7);
3268 else if (buf[0] == 'E') return (0);
3270 else if (buf[0] == 'E')
3272 /* Acquire the Text */
3275 /* Store the name */
3276 if (!add_name(&d_ptr->name, head, s)) return (7);
3280 /* Process 'D' for "Description */
3281 else if (buf[0] == 'D')
3286 /* Acquire the text */
3291 /* Acquire the text */
3295 /* Store the text */
3296 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3299 /* Process 'W' for "More Info" (one line only) */
3300 else if (buf[0] == 'W')
3302 int min_lev, max_lev;
3304 int min_alloc, max_chance;
3305 int obj_good, obj_great;
3308 /* Scan for the values */
3309 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3310 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3312 /* Save the values */
3313 d_ptr->mindepth = (DEPTH)min_lev;
3314 d_ptr->maxdepth = (DEPTH)max_lev;
3315 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3316 d_ptr->mode = (BIT_FLAGS8)mode;
3317 d_ptr->min_m_alloc_level = min_alloc;
3318 d_ptr->max_m_alloc_chance = max_chance;
3319 d_ptr->obj_good = obj_good;
3320 d_ptr->obj_great = obj_great;
3321 d_ptr->pit = (BIT_FLAGS16)pit;
3322 d_ptr->nest = (BIT_FLAGS16)nest;
3325 /* Process 'P' for "Place Info" */
3326 else if (buf[0] == 'P')
3330 /* Scan for the values */
3331 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3333 /* Save the values */
3338 /* Process 'L' for "fLoor type" (one line only) */
3339 else if (buf[0] == 'L')
3343 /* Scan for the values */
3344 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3346 /* Save the values */
3347 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3349 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3350 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3352 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3354 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3357 /* Process 'A' for "wAll type" (one line only) */
3358 else if (buf[0] == 'A')
3362 /* Scan for the values */
3363 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3365 /* Save the values */
3366 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3368 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3369 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3371 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3374 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3375 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3377 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3378 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3380 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3381 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3383 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3384 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3387 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3388 else if (buf[0] == 'F')
3390 int artif = 0, monst = 0;
3392 /* Parse every entry */
3393 for (s = buf + 2; *s; )
3395 /* Find the end of this entry */
3396 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3398 /* Nuke and skip any dividers */
3402 while (*t == ' ' || *t == '|') t++;
3405 /* Hack -- Read Final Artifact */
3406 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3408 /* Extract a "Final Artifact" */
3409 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3411 /* Start at next entry */
3416 /* Hack -- Read Final Object */
3417 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3419 /* Extract a "Final Artifact" */
3420 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3422 /* Start at next entry */
3427 /* Hack -- Read Artifact Guardian */
3428 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3430 /* Extract a "Artifact Guardian" */
3431 d_ptr->final_guardian = (MONRACE_IDX)monst;
3433 /* Start at next entry */
3438 /* Hack -- Read Special Percentage */
3439 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3441 /* Extract a "Special %" */
3442 d_ptr->special_div = (PROB)monst;
3444 /* Start at next entry */
3449 /* Parse this entry */
3450 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3452 /* Start the next entry */
3457 /* Process 'M' for "Basic Flags" (multiple lines) */
3458 else if (buf[0] == 'M')
3460 /* Parse every entry */
3461 for (s = buf + 2; *s; )
3463 /* Find the end of this entry */
3464 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3466 /* Nuke and skip any dividers */
3470 while (*t == ' ' || *t == '|') t++;
3473 /* Hack -- Read monster symbols */
3474 if (!strncmp(s, "R_CHAR_", 7))
3476 /* Skip "R_CHAR_" */
3480 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3482 /* Start at next entry */
3487 /* Parse this entry */
3488 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3490 /* Start the next entry */
3495 /* Process 'S' for "Spell Flags" (multiple lines) */
3496 else if (buf[0] == 'S')
3498 /* Parse every entry */
3499 for (s = buf + 2; *s; )
3501 /* Find the end of this entry */
3502 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3504 /* Nuke and skip any dividers */
3508 while ((*t == ' ') || (*t == '|')) t++;
3511 /* Hack -- Read spell frequency */
3512 if (1 == sscanf(s, "1_IN_%d", &i))
3514 /* Start at next entry */
3519 /* Parse this entry */
3520 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3522 /* Start the next entry */
3534 #else /* ALLOW_TEMPLATES */
3540 #endif /* ALLOW_TEMPLATES */
3544 * @brief 地形情報の「F:」情報をパースする
3545 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3549 static errr parse_line_feature(char *buf)
3554 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3556 /* Tokenize the line */
3557 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3559 /* Letter to assign */
3560 int index = zz[0][0];
3562 /* Reset the info for the letter */
3563 letter[index].feature = feat_none;
3564 letter[index].monster = 0;
3565 letter[index].object = 0;
3566 letter[index].ego = 0;
3567 letter[index].artifact = 0;
3568 letter[index].trap = feat_none;
3569 letter[index].cave_info = 0;
3570 letter[index].special = 0;
3571 letter[index].random = RANDOM_NONE;
3577 letter[index].special = (s16b)atoi(zz[8]);
3581 if ((zz[7][0] == '*') && !zz[7][1])
3583 letter[index].random |= RANDOM_TRAP;
3587 letter[index].trap = f_tag_to_index(zz[7]);
3588 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3593 if (zz[6][0] == '*')
3595 letter[index].random |= RANDOM_ARTIFACT;
3596 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3598 else if (zz[6][0] == '!')
3600 if (p_ptr->inside_quest)
3602 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3607 letter[index].artifact = (IDX)atoi(zz[6]);
3612 if (zz[5][0] == '*')
3614 letter[index].random |= RANDOM_EGO;
3615 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3619 letter[index].ego = (IDX)atoi(zz[5]);
3624 if (zz[4][0] == '*')
3626 letter[index].random |= RANDOM_OBJECT;
3627 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3629 else if (zz[4][0] == '!')
3631 if (p_ptr->inside_quest)
3633 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3636 artifact_type *a_ptr = &a_info[a_idx];
3637 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3639 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3646 letter[index].object = (IDX)atoi(zz[4]);
3651 if (zz[3][0] == '*')
3653 letter[index].random |= RANDOM_MONSTER;
3654 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3656 else if (zz[3][0] == 'c')
3658 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3659 letter[index].monster = -atoi(zz[3] + 1);
3663 letter[index].monster = (IDX)atoi(zz[3]);
3668 letter[index].cave_info = atoi(zz[2]);
3672 if ((zz[1][0] == '*') && !zz[1][1])
3674 letter[index].random |= RANDOM_FEATURE;
3678 letter[index].feature = f_tag_to_index(zz[1]);
3679 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3692 * @brief 地形情報の「B:」情報をパースする
3693 * Process "B:<Index>:<Command>:..." -- Building definition
3697 static errr parse_line_building(char *buf)
3713 /* Get the building number */
3716 /* Find the colon after the building number */
3717 s = my_strchr(s, ':');
3719 /* Verify that colon */
3722 /* Nuke the colon, advance to the sub-index */
3725 /* Paranoia -- require a sub-index */
3726 if (!*s) return (1);
3728 /* Building definition sub-index */
3731 /* Building name, owner, race */
3734 if (tokenize(s + 2, 3, zz, 0) == 3)
3736 /* Name of the building */
3737 strcpy(building[index].name, zz[0]);
3739 /* Name of the owner */
3740 strcpy(building[index].owner_name, zz[1]);
3742 /* Race of the owner */
3743 strcpy(building[index].owner_race, zz[2]);
3748 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3751 /* Building Action */
3754 if (tokenize(s + 2, 8, zz, 0) >= 7)
3756 /* Index of the action */
3757 int action_index = atoi(zz[0]);
3759 /* Name of the action */
3760 strcpy(building[index].act_names[action_index], zz[1]);
3762 /* Cost of the action for members */
3763 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3765 /* Cost of the action for non-members */
3766 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3768 /* Letter assigned to the action */
3769 building[index].letters[action_index] = zz[4][0];
3772 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3774 /* Action restriction */
3775 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3780 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3783 /* Building Classes */
3787 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3788 for (i = 0; i < MAX_CLASS; i++)
3790 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3795 /* Building Races */
3799 n = tokenize(s + 2, MAX_RACES, zz, 0);
3800 for (i = 0; i < MAX_RACES; i++)
3802 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3807 /* Building Realms */
3811 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3812 for (i = 0; i < MAX_MAGIC; i++)
3814 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3821 /* Ignore scripts */
3827 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3836 * @brief フロアの所定のマスにオブジェクトを配置する
3837 * Place the object j_ptr to a grid
3838 * @param j_ptr オブジェクト構造体の参照ポインタ
3843 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3845 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3848 OBJECT_IDX o_idx = o_pop();
3850 /* Access new object */
3851 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3853 /* Structure copy */
3854 object_copy(o_ptr, j_ptr);
3861 o_ptr->held_m_idx = 0;
3864 o_ptr->next_o_idx = g_ptr->o_idx;
3866 g_ptr->o_idx = o_idx;
3870 * @brief クエスト用固定ダンジョンをフロアに生成する
3871 * Parse a sub-file of the "extra info"
3881 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3886 /* Skip "empty" lines */
3887 if (!buf[0]) return (0);
3889 /* Skip "blank" lines */
3890 if (iswspace(buf[0])) return (0);
3893 if (buf[0] == '#') return (0);
3895 /* Require "?:*" format */
3896 if (buf[1] != ':') return (1);
3899 /* Process "%:<fname>" */
3902 /* Attempt to Process the given file */
3903 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3906 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3909 return parse_line_feature(buf);
3912 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3913 else if (buf[0] == 'D')
3915 object_type object_type_body;
3917 /* Acquire the text */
3920 /* Length of the text */
3921 int len = strlen(s);
3923 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3925 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3927 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3931 OBJECT_IDX object_index = letter[idx].object;
3932 MONSTER_IDX monster_index = letter[idx].monster;
3933 int random = letter[idx].random;
3934 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3936 /* Lay down a floor */
3937 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3939 /* Only the features */
3940 if (init_flags & INIT_ONLY_FEATURES) continue;
3943 g_ptr->info = letter[idx].cave_info;
3945 /* Create a monster */
3946 if (random & RANDOM_MONSTER)
3948 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3950 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3952 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3954 else if (monster_index)
3956 int old_cur_num, old_max_num;
3959 if (monster_index < 0)
3961 monster_index = -monster_index;
3964 old_cur_num = r_info[monster_index].cur_num;
3965 old_max_num = r_info[monster_index].max_num;
3967 /* Make alive again */
3968 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3970 r_info[monster_index].cur_num = 0;
3971 r_info[monster_index].max_num = 1;
3974 /* Make alive again */
3975 /* Hack -- Non-unique Nazguls are semi-unique */
3976 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3978 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3980 r_info[monster_index].max_num++;
3985 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3989 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3991 /* Make alive again for real unique monster */
3992 r_info[monster_index].cur_num = old_cur_num;
3993 r_info[monster_index].max_num = old_max_num;
3997 /* Object (and possible trap) */
3998 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4000 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4003 * Random trap and random treasure defined
4004 * 25% chance for trap and 75% chance for object
4006 if (randint0(100) < 75)
4008 place_object(*y, *x, 0L);
4015 current_floor_ptr->object_level = current_floor_ptr->base_level;
4017 else if (random & RANDOM_OBJECT)
4019 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4021 /* Create an out of deep object */
4022 if (randint0(100) < 75)
4023 place_object(*y, *x, 0L);
4024 else if (randint0(100) < 80)
4025 place_object(*y, *x, AM_GOOD);
4027 place_object(*y, *x, AM_GOOD | AM_GREAT);
4029 current_floor_ptr->object_level = current_floor_ptr->base_level;
4032 else if (random & RANDOM_TRAP)
4036 /* Hidden trap (or door) */
4037 else if (letter[idx].trap)
4039 g_ptr->mimic = g_ptr->feat;
4040 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4042 else if (object_index)
4044 object_type *o_ptr = &object_type_body;
4045 object_prep(o_ptr, object_index);
4047 if (o_ptr->tval == TV_GOLD)
4049 coin_type = object_index - OBJ_GOLD_LIST;
4054 /* Apply magic (no messages, no artifacts) */
4055 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4057 drop_here(o_ptr, *y, *x);
4063 if (a_info[artifact_index].cur_num)
4065 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4067 object_type *q_ptr = &forge;
4069 object_prep(q_ptr, k_idx);
4070 drop_here(q_ptr, *y, *x);
4074 if (create_named_art(artifact_index, *y, *x))
4075 a_info[artifact_index].cur_num = 1;
4079 /* Terrain special */
4080 g_ptr->special = letter[idx].special;
4088 /* Process "Q:<number>:<command>:... -- quest info */
4089 else if (buf[0] == 'Q')
4096 num = tokenize(buf + 2, 33, zz, 0);
4100 num = tokenize(buf + 3, 33, zz, 0);
4103 /* Have we enough parameters? */
4104 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4107 q_ptr = &(quest[atoi(zz[0])]);
4109 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4110 if (zz[1][0] == 'Q')
4112 if (init_flags & INIT_ASSIGN)
4114 monster_race *r_ptr;
4115 artifact_type *a_ptr;
4117 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4119 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4120 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4121 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4122 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4123 q_ptr->level = (DEPTH)atoi(zz[6]);
4124 q_ptr->r_idx = (IDX)atoi(zz[7]);
4125 q_ptr->k_idx = (IDX)atoi(zz[8]);
4126 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4128 if (num > 10) q_ptr->flags = atoi(zz[10]);
4130 r_ptr = &r_info[q_ptr->r_idx];
4131 if (r_ptr->flags1 & RF1_UNIQUE)
4132 r_ptr->flags1 |= RF1_QUESTOR;
4134 a_ptr = &a_info[q_ptr->k_idx];
4135 a_ptr->gen_flags |= TRG_QUESTITEM;
4140 else if (zz[1][0] == 'R')
4142 if (init_flags & INIT_ASSIGN)
4145 IDX idx, reward_idx = 0;
4147 for (idx = 2; idx < num; idx++)
4149 IDX a_idx = (IDX)atoi(zz[idx]);
4150 if (a_idx < 1) continue;
4151 if (a_info[a_idx].cur_num > 0) continue;
4153 if (one_in_(count)) reward_idx = a_idx;
4158 /* Set quest's rewarding artifact */
4159 q_ptr->k_idx = reward_idx;
4160 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4164 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4165 q_ptr->type = QUEST_TYPE_KILL_ALL;
4172 /* Process "Q:<q_index>:N:<name>" -- quest name */
4173 else if (zz[1][0] == 'N')
4175 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4177 strcpy(q_ptr->name, zz[2]);
4183 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4184 else if (zz[1][0] == 'T')
4186 if (init_flags & INIT_SHOW_TEXT)
4188 strcpy(quest_text[quest_text_line], zz[2]);
4196 /* Process "W:<command>: ..." -- info for the wilderness */
4197 else if (buf[0] == 'W')
4199 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4202 /* Process "P:<y>:<x>" -- player position */
4203 else if (buf[0] == 'P')
4205 if (init_flags & INIT_CREATE_DUNGEON)
4207 if (tokenize(buf + 2, 2, zz, 0) == 2)
4209 int panels_x, panels_y;
4211 /* Hack - Set the dungeon size */
4212 panels_y = (*y / SCREEN_HGT);
4213 if (*y % SCREEN_HGT) panels_y++;
4214 current_floor_ptr->height = panels_y * SCREEN_HGT;
4216 panels_x = (*x / SCREEN_WID);
4217 if (*x % SCREEN_WID) panels_x++;
4218 current_floor_ptr->width = panels_x * SCREEN_WID;
4220 /* Assume illegal panel */
4221 panel_row_min = current_floor_ptr->height;
4222 panel_col_min = current_floor_ptr->width;
4224 /* Place player in a quest level */
4225 if (p_ptr->inside_quest)
4229 /* Delete the monster (if any) */
4230 delete_monster(p_ptr->y, p_ptr->x);
4238 /* Place player in the town */
4239 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4241 p_ptr->oldpy = atoi(zz[0]);
4242 p_ptr->oldpx = atoi(zz[1]);
4250 /* Process "B:<Index>:<Command>:..." -- Building definition */
4251 else if (buf[0] == 'B')
4253 return parse_line_building(buf);
4256 /* Process "M:<type>:<maximum>" -- set maximum values */
4257 else if (buf[0] == 'M')
4259 if (tokenize(buf + 2, 2, zz, 0) == 2)
4262 if (zz[0][0] == 'T')
4264 max_towns = (TOWN_IDX)atoi(zz[1]);
4267 /* Maximum quests */
4268 else if (zz[0][0] == 'Q')
4270 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4274 else if (zz[0][0] == 'R')
4276 max_r_idx = (IDX)atoi(zz[1]);
4280 else if (zz[0][0] == 'K')
4282 max_k_idx = (IDX)atoi(zz[1]);
4286 else if (zz[0][0] == 'V')
4288 max_v_idx = (IDX)atoi(zz[1]);
4292 else if (zz[0][0] == 'F')
4294 max_f_idx = (IDX)atoi(zz[1]);
4298 else if (zz[0][0] == 'A')
4300 max_a_idx = (IDX)atoi(zz[1]);
4304 else if (zz[0][0] == 'E')
4306 max_e_idx = (IDX)atoi(zz[1]);
4310 else if (zz[0][0] == 'D')
4312 max_d_idx = (IDX)atoi(zz[1]);
4316 else if (zz[0][0] == 'O')
4318 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4322 else if (zz[0][0] == 'M')
4324 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4327 /* Wilderness size */
4328 else if (zz[0][0] == 'W')
4330 /* Maximum wild_x_size */
4331 if (zz[0][1] == 'X')
4332 current_world_ptr->max_wild_x = atoi(zz[1]);
4333 /* Maximum wild_y_size */
4334 if (zz[0][1] == 'Y')
4335 current_world_ptr->max_wild_y = atoi(zz[1]);
4349 static concptr variant = "ZANGBAND";
4353 * @brief クエスト用固定ダンジョン生成時の分岐処理
4354 * Helper function for "process_dungeon_file()"
4359 static concptr process_dungeon_file_expr(char **sp, char *fp)
4375 while (iswspace(*s)) s++;
4393 t = process_dungeon_file_expr(&s, &f);
4401 else if (streq(t, "IOR"))
4404 while (*s && (f != b2))
4406 t = process_dungeon_file_expr(&s, &f);
4407 if (*t && !streq(t, "0")) v = "1";
4412 else if (streq(t, "AND"))
4415 while (*s && (f != b2))
4417 t = process_dungeon_file_expr(&s, &f);
4418 if (*t && streq(t, "0")) v = "0";
4423 else if (streq(t, "NOT"))
4426 while (*s && (f != b2))
4428 t = process_dungeon_file_expr(&s, &f);
4429 if (*t && streq(t, "1")) v = "0";
4434 else if (streq(t, "EQU"))
4437 if (*s && (f != b2))
4439 t = process_dungeon_file_expr(&s, &f);
4441 while (*s && (f != b2))
4443 p = process_dungeon_file_expr(&s, &f);
4444 if (streq(t, p)) v = "1";
4449 else if (streq(t, "LEQ"))
4452 if (*s && (f != b2))
4454 t = process_dungeon_file_expr(&s, &f);
4456 while (*s && (f != b2))
4459 t = process_dungeon_file_expr(&s, &f);
4460 if (*t && atoi(p) > atoi(t)) v = "0";
4465 else if (streq(t, "GEQ"))
4468 if (*s && (f != b2))
4470 t = process_dungeon_file_expr(&s, &f);
4472 while (*s && (f != b2))
4475 t = process_dungeon_file_expr(&s, &f);
4477 /* Compare two numbers instead of string */
4478 if (*t && atoi(p) < atoi(t)) v = "0";
4484 while (*s && (f != b2))
4486 t = process_dungeon_file_expr(&s, &f);
4491 if (f != b2) v = "?x?x?";
4493 /* Extract final and Terminate */
4494 if ((f = *s) != '\0') *s++ = '\0';
4500 /* Accept all printables except spaces and brackets */
4502 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4504 if (iskanji(*s)) s++;
4508 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4511 /* Extract final and Terminate */
4512 if ((f = *s) != '\0') *s++ = '\0';
4518 if (streq(b + 1, "SYS"))
4524 else if (streq(b + 1, "GRAF"))
4529 else if (streq(b + 1, "MONOCHROME"))
4538 else if (streq(b + 1, "RACE"))
4540 v = _(rp_ptr->E_title, rp_ptr->title);
4544 else if (streq(b + 1, "CLASS"))
4546 v = _(cp_ptr->E_title, cp_ptr->title);
4550 else if (streq(b + 1, "REALM1"))
4552 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4556 else if (streq(b + 1, "REALM2"))
4558 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4562 else if (streq(b + 1, "PLAYER"))
4564 static char tmp_player_name[32];
4566 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4576 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4579 v = tmp_player_name;
4583 else if (streq(b + 1, "TOWN"))
4585 sprintf(tmp, "%d", p_ptr->town_num);
4590 else if (streq(b + 1, "LEVEL"))
4592 sprintf(tmp, "%d", p_ptr->lev);
4596 /* Current quest number */
4597 else if (streq(b + 1, "QUEST_NUMBER"))
4599 sprintf(tmp, "%d", p_ptr->inside_quest);
4603 /* Number of last quest */
4604 else if (streq(b + 1, "LEAVING_QUEST"))
4606 sprintf(tmp, "%d", leaving_quest);
4611 else if (prefix(b + 1, "QUEST_TYPE"))
4613 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4614 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4619 else if (prefix(b + 1, "QUEST"))
4621 /* "QUEST" uses a special parameter to determine the number of the quest */
4622 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4627 else if (prefix(b + 1, "RANDOM"))
4629 /* "RANDOM" uses a special parameter to determine the number of the quest */
4630 sprintf(tmp, "%d", (int)(seed_town%atoi(b + 7)));
4635 else if (streq(b + 1, "VARIANT"))
4641 else if (streq(b + 1, "WILDERNESS"))
4644 sprintf(tmp, "NONE");
4646 sprintf(tmp, "LITE");
4648 sprintf(tmp, "NORMAL");
4667 void write_r_info_txt(void)
4669 int i, j, z, fc, bc;
4672 concptr flags[32 * 10];
4677 monster_race *r_ptr;
4679 monster_blow *b_ptr;
4681 FILE *fff = fopen("output.txt", "wt");
4685 BIT_FLAGS mode = -1;
4689 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4691 fprintf(fff, "# Version stamp (required)\n\n");
4694 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4697 fprintf(fff, "##### The Player #####\n\n");
4699 for (z = -1; z < alloc_race_size; z++)
4701 /* Output the monsters in order */
4702 i = (z >= 0) ? alloc_race_table[z].index : 0;
4704 /* Acquire the monster */
4707 /* Ignore empty monsters */
4708 if (!strlen(r_name + r_ptr->name)) continue;
4710 /* Ignore useless monsters */
4711 if (i && !r_ptr->speed) continue;
4713 /* Write a note if necessary */
4714 if (i && (!r_ptr->level != !mode))
4719 fprintf(fff, "\n##### Town monsters #####\n\n");
4721 /* Note the dungeon */
4724 fprintf(fff, "\n##### Normal monsters #####\n\n");
4727 /* Record the change */
4728 mode = r_ptr->level;
4731 /* Acquire the flags */
4732 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4733 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4734 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4735 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4736 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4737 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4738 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4739 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4740 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4741 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4743 /* Write New/Number/Name */
4744 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4747 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4749 /* Write Information */
4750 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4751 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4753 /* Write more information */
4754 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4757 for (j = 0; j < 4; j++)
4759 b_ptr = &(r_ptr->blow[j]);
4761 /* Stop when done */
4762 if (!b_ptr->method) break;
4764 /* Write the blows */
4765 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4766 r_info_blow_effect[b_ptr->effect],
4767 b_ptr->d_dice, b_ptr->d_side);
4769 for (fc = 0, j = 0; j < 32 * 3; j++)
4771 /* Check this flag */
4772 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4775 /* Extract the extra flags */
4776 for (j = 32 * 6; j < 32 * 10; j++)
4778 /* Check this flag */
4779 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4782 /* Write the flags */
4783 for (j = 0; j < fc;)
4787 /* Start the line */
4790 for (bc = 0; (bc < 60) && (j < fc); j++)
4794 /* Format the flag */
4795 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4797 /* Add it to the buffer */
4800 /* Note the length */
4804 /* Done with this line; write it */
4805 fprintf(fff, "%s\n", buf);
4808 /* Write Spells if applicable */
4809 if (r_ptr->freq_spell)
4811 /* Write the frequency */
4812 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4814 /* Extract the spell flags */
4815 for (fc = 0, j = 96; j < 192; j++)
4817 /* Check this flag */
4818 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4821 /* Write the flags */
4822 for (j = 0; j < fc;)
4826 /* Start the line */
4829 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4833 /* Format the flag */
4834 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4838 /* Note the length */
4845 /* Done with this line; write it */
4846 fprintf(fff, "%s\n", buf);
4850 /* Acquire the description */
4851 desc = r_text + r_ptr->text;
4852 dlen = strlen(desc);
4854 /* Write Description */
4855 for (j = 0; j < dlen;)
4859 /* Start the line */
4862 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4870 /* Done with this line; write it */
4871 fprintf(fff, "%s\n", buf);
4874 /* Space between entries */
4885 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4886 * Helper function for "process_dungeon_file()"
4894 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4900 bool bypass = FALSE;
4901 int x = xmin, y = ymin;
4904 /* Build the filename */
4905 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4908 fp = my_fopen(buf, "r");
4911 if (!fp) return (-1);
4914 /* Process the file */
4915 while (0 == my_fgets(fp, buf, sizeof(buf)))
4921 /* Skip "empty" lines */
4922 if (!buf[0]) continue;
4924 /* Skip "blank" lines */
4925 if (iswspace(buf[0])) continue;
4928 if (buf[0] == '#') continue;
4931 /* Process "?:<expr>" */
4932 if ((buf[0] == '?') && (buf[1] == ':'))
4941 /* Parse the expr */
4942 v = process_dungeon_file_expr(&s, &f);
4945 bypass = (streq(v, "0") ? TRUE : FALSE);
4949 /* Apply conditionals */
4950 if (bypass) continue;
4952 /* Process the line */
4953 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4964 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4966 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4967 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);