3 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file is used to initialize various variables and arrays for the
16 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
17 * the common limitation of "read()" and "write()" to only 32767 bytes
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
28 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
29 * in this file is compiled out, and the game will not run unless valid
30 * "binary template files" already exist in "lib/data". Thus, one can
31 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
32 * "*.raw" files in "lib/data", and then quit, and recompile without
33 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
34 * from changing the ascii template files in potentially dangerous ways.
35 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
36 * このファイルのコードの多くはコンパイル出力され、本ゲームは
37 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
38 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
39 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
40 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
41 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
42 * テンプレートファイルを変更することを妨げることができる。
43 * The code could actually be removed and placed into a "stand-alone"
44 * program, but that feels a little silly, especially considering some
45 * of the platforms that we currently support.
53 #ifdef ALLOW_TEMPLATES
58 /*** Helper arrays for parsing ascii template files ***/
62 * Monster Blow Methods
64 static cptr r_info_blow_method[] =
98 * Monster Blow Effects
100 static cptr r_info_blow_effect[] =
145 static cptr f_info_flags[] =
270 static cptr r_info_flags1[] =
310 static cptr r_info_flags2[] =
350 static cptr r_info_flags3[] =
390 static cptr r_info_flags4[] =
427 * モンスター特性トークン(発動型能力1) /
430 static cptr r_a_ability_flags1[] =
467 * モンスター特性トークン(発動型能力2) /
470 static cptr r_a_ability_flags2[] =
487 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
507 * モンスター特性トークン(発動型能力3) /
510 static cptr r_a_ability_flags3[] =
547 * モンスター特性トークン(発動型能力4) /
550 static cptr r_a_ability_flags4[] =
591 static cptr r_info_flags7[] =
631 static cptr r_info_flags8[] =
663 "WILD_SWAMP", /* ToDo: Implement Swamp */
672 static cptr r_info_flags9[] =
711 * モンスター特性トークンの定義R(耐性) /
714 static cptr r_info_flagsr[] =
752 * オブジェクト基本特性トークンの定義 /
755 static cptr k_info_flags[] =
852 "XXX3", /* Fake flag for Smith */
853 "XXX4", /* Fake flag for Smith */
903 * オブジェクト生成特性トークンの定義 /
906 static cptr k_info_gen_flags[] =
946 static cptr d_info_flags1[] =
984 * @brief データの可変文字列情報をテキストとして保管する /
985 * Add a text to the text-storage and store offset to it.
986 * @param offset 文字列保管ポインタからのオフセット
987 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
989 * @param normal_text テキストの正規化を行う
992 * Returns FALSE when there isn't enough space available to store
995 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
997 /* Hack -- Verify space */
998 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1004 /* Advance and save the text index */
1005 *offset = ++head->text_size;
1008 /* Additional text */
1009 else if (normal_text)
1012 * If neither the end of the last line nor
1013 * the beginning of current line is not a space,
1014 * fill up a space as a correct separator of two words.
1016 if (head->text_size > 0 &&
1018 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1019 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1020 (buf[0] != ' ') && !iskanji(buf[0])
1022 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1027 /* Append a space */
1028 *(head->text_ptr + head->text_size) = ' ';
1030 /* Advance the index */
1035 /* Append chars to the text */
1036 strcpy(head->text_ptr + head->text_size, buf);
1038 /* Advance the index */
1039 head->text_size += strlen(buf);
1047 * @brief データの可変文字列情報を名前として保管する /
1048 * Add a name to the name-storage and return an offset to it.
1049 * @param offset 文字列保管ポインタからのオフセット
1050 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1054 * Returns FALSE when there isn't enough space available to store
1057 static bool add_name(u32b *offset, header *head, cptr buf)
1059 /* Hack -- Verify space */
1060 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1066 /* Advance and save the name index */
1067 *offset = ++head->name_size;
1070 /* Append chars to the names */
1071 strcpy(head->name_ptr + head->name_size, buf);
1073 /* Advance the index */
1074 head->name_size += strlen(buf);
1082 * @brief データの可変文字列情報をタグとして保管する /
1083 * Add a tag to the tag-storage and return an offset to it.
1084 * @param offset 文字列保管ポインタからのオフセット
1085 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1089 * Returns FALSE when there isn't enough space available to store
1092 static bool add_tag(s16b *offset, header *head, cptr buf)
1096 /* Search for an existing (fake) tag */
1097 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1100 if (streq(&head->tag_ptr[i], buf)) break;
1103 /* There was no existing tag */
1104 if (i >= head->tag_size)
1106 /* Hack -- Verify space */
1107 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1110 /* Append chars to the tags */
1111 strcpy(head->tag_ptr + head->tag_size, buf);
1113 /* Point the new tag */
1116 /* Advance the index */
1117 head->tag_size += strlen(buf) + 1;
1120 /* Return offset of the tag */
1129 * @brief シンボル1文字をカラーIDに変更する /
1130 * Convert a "color letter" into an "actual" color
1131 * The colors are: dwsorgbuDWvyRGBU, as shown below
1135 byte color_char_to_attr(char c)
1139 case 'd': return (TERM_DARK);
1140 case 'w': return (TERM_WHITE);
1141 case 's': return (TERM_SLATE);
1142 case 'o': return (TERM_ORANGE);
1143 case 'r': return (TERM_RED);
1144 case 'g': return (TERM_GREEN);
1145 case 'b': return (TERM_BLUE);
1146 case 'u': return (TERM_UMBER);
1148 case 'D': return (TERM_L_DARK);
1149 case 'W': return (TERM_L_WHITE);
1150 case 'v': return (TERM_VIOLET);
1151 case 'y': return (TERM_YELLOW);
1152 case 'R': return (TERM_L_RED);
1153 case 'G': return (TERM_L_GREEN);
1154 case 'B': return (TERM_L_BLUE);
1155 case 'U': return (TERM_L_UMBER);
1163 /*** Initialize from ascii template files ***/
1167 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1168 * Initialize an "*_info" array, by parsing an ascii "template" file
1169 * @param fp 読み取りに使うファイルポインタ
1170 * @param buf 読み取りに使うバッファ領域
1171 * @param head ヘッダ構造体
1172 * @param parse_info_txt_line パース関数
1175 errr init_info_txt(FILE *fp, char *buf, header *head,
1176 parse_info_txt_func parse_info_txt_line)
1180 /* Just before the first record */
1183 /* Just before the first line */
1187 /* Prepare the "fake" stuff */
1188 head->name_size = 0;
1189 head->text_size = 0;
1193 while (0 == my_fgets(fp, buf, 1024))
1195 /* Advance the line number */
1198 /* Skip comments and blank lines */
1199 if (!buf[0] || (buf[0] == '#')) continue;
1201 /* Verify correct "colon" format */
1202 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1205 /* Hack -- Process 'V' for "Version" */
1212 /* Mega Hack -- Calculate Check Sum */
1213 if (buf[0] != 'N' && buf[0] != 'D')
1216 for (i = 0; buf[i]; i++)
1218 head->v_extra += (byte)buf[i];
1219 head->v_extra ^= (1 << (i % 8));
1223 /* Parse the line */
1224 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1229 /* Complete the "name" and "text" sizes */
1230 if (head->name_size) head->name_size++;
1231 if (head->text_size) head->text_size++;
1239 * @brief Vault情報(v_info)のパース関数 /
1240 * Initialize the "v_info" array, by parsing an ascii "template" file
1242 * @param head ヘッダ構造体
1245 errr parse_v_info(char *buf, header *head)
1251 static vault_type *v_ptr = NULL;
1253 /* Process 'N' for "New/Number/Name" */
1256 /* Find the colon before the name */
1257 s = my_strchr(buf+2, ':');
1259 /* Verify that colon */
1262 /* Nuke the colon, advance to the name */
1265 /* Paranoia -- require a name */
1266 if (!*s) return (1);
1271 /* Verify information */
1272 if (i <= error_idx) return (4);
1274 /* Verify information */
1275 if (i >= head->info_num) return (2);
1277 /* Save the index */
1280 /* Point at the "info" */
1283 /* Store the name */
1284 if (!add_name(&v_ptr->name, head, s)) return (7);
1287 /* There better be a current v_ptr */
1288 else if (!v_ptr) return (3);
1290 /* Process 'D' for "Description" */
1291 else if (buf[0] == 'D')
1293 /* Acquire the text */
1296 /* Store the text */
1297 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1300 /* Process 'X' for "Extra info" (one line only) */
1301 else if (buf[0] == 'X')
1303 int typ, rat, hgt, wid;
1305 /* Scan for the values */
1306 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1307 &typ, &rat, &hgt, &wid)) return (1);
1309 /* Save the values */
1325 * @brief 職業技能情報(s_info)のパース関数 /
1326 * Initialize the "s_info" array, by parsing an ascii "template" file
1328 * @param head ヘッダ構造体
1331 errr parse_s_info(char *buf, header *head)
1336 static skill_table *s_ptr = NULL;
1339 /* Process 'N' for "New/Number/Name" */
1345 /* Verify information */
1346 if (i <= error_idx) return (4);
1348 /* Verify information */
1349 if (i >= head->info_num) return (2);
1351 /* Save the index */
1354 /* Point at the "info" */
1358 /* There better be a current s_ptr */
1359 else if (!s_ptr) return (3);
1361 /* Process 'W' for "Weapon exp" */
1362 else if (buf[0] == 'W')
1364 int tval, sval, start, max;
1365 const s16b exp_conv_table[] =
1367 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1368 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1371 /* Scan for the values */
1372 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1373 &tval, &sval, &start, &max)) return (1);
1375 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1376 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1378 /* Save the values */
1379 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1380 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1383 /* Process 'S' for "Skill exp" */
1384 else if (buf[0] == 'S')
1386 int num, start, max;
1388 /* Scan for the values */
1389 if (3 != sscanf(buf+2, "%d:%d:%d",
1390 &num, &start, &max)) return (1);
1392 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1393 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1395 /* Save the values */
1396 s_ptr->s_start[num] = (SUB_EXP)start;
1397 s_ptr->s_max[num] = (SUB_EXP)max;
1410 * @brief 職業魔法情報(m_info)のパース関数 /
1411 * Initialize the "m_info" array, by parsing an ascii "template" file
1413 * @param head ヘッダ構造体
1416 errr parse_m_info(char *buf, header *head)
1423 static player_magic *m_ptr = NULL;
1426 static int realm, magic_idx = 0, readable = 0;
1429 /* Process 'N' for "New/Number/Name" */
1435 /* Verify information */
1436 if (i <= error_idx) return (4);
1438 /* Verify information */
1439 if (i >= head->info_num) return (2);
1441 /* Save the index */
1444 /* Point at the "info" */
1448 /* There better be a current m_ptr */
1449 else if (!m_ptr) return (3);
1451 /* Process 'I' for "Info" (one line only) */
1452 else if (buf[0] == 'I')
1455 int xtra, type, first, weight;
1457 /* Find the colon before the name */
1458 s = my_strchr(buf+2, ':');
1460 /* Verify that colon */
1463 /* Nuke the colon, advance to the name */
1468 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1469 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1470 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1471 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1472 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1477 /* Find the colon before the name */
1478 s = my_strchr(s, ':');
1480 /* Verify that colon */
1483 /* Nuke the colon, advance to the name */
1486 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1487 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1488 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1489 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1490 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1491 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1495 /* Scan for the values */
1496 if (4 != sscanf(s, "%x:%d:%d:%d",
1497 (uint *)&xtra, &type, &first, &weight)) return (1);
1499 m_ptr->spell_xtra = xtra;
1500 m_ptr->spell_type = type;
1501 m_ptr->spell_first = first;
1502 m_ptr->spell_weight = weight;
1506 /* Process 'R' for "Realm" (one line only) */
1507 else if (buf[0] == 'R')
1509 /* Scan for the values */
1510 if (2 != sscanf(buf+2, "%d:%d",
1511 &realm, &readable)) return (1);
1516 else if (buf[0] == 'T')
1518 int level, mana, fail, exp;
1520 if (!readable) return (1);
1521 /* Scan for the values */
1522 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1523 &level, &mana, &fail, &exp)) return (1);
1525 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1526 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1527 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1528 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1542 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1543 * Grab one flag from a textual string
1544 * @param flags ビットフラグを追加する先の参照ポインタ
1545 * @param names トークン定義配列
1546 * @param what 参照元の文字列ポインタ
1549 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1554 for (i = 0; i < 32; i++)
1556 if (streq(what, names[i]))
1558 *flags |= (1L << i);
1568 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1569 * Grab one flag in an feature_type from a textual string
1570 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1571 * @param what 参照元の文字列ポインタ
1574 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1579 for (i = 0; i < FF_FLAG_MAX; i++)
1581 if (streq(what, f_info_flags[i]))
1583 add_flag(f_ptr->flags, i);
1589 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1592 return PARSE_ERROR_GENERIC;
1597 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1598 * Grab an action in an feature_type from a textual string
1599 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1600 * @param what 参照元の文字列ポインタ
1601 * @param count ステートの保存先ID
1604 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1609 for (i = 0; i < FF_FLAG_MAX; i++)
1611 if (streq(what, f_info_flags[i]))
1613 f_ptr->state[count].action = i;
1619 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1622 return PARSE_ERROR_GENERIC;
1627 * @brief 地形情報(f_info)のパース関数 /
1628 * Initialize the "f_info" array, by parsing an ascii "template" file
1630 * @param head ヘッダ構造体
1633 errr parse_f_info(char *buf, header *head)
1640 static feature_type *f_ptr = NULL;
1643 /* Process 'N' for "New/Number/Name" */
1646 /* Find the colon before the name */
1647 s = my_strchr(buf+2, ':');
1651 /* Nuke the colon, advance to the name */
1658 /* Verify information */
1659 if (i <= error_idx) return (4);
1661 /* Verify information */
1662 if (i >= head->info_num) return (2);
1664 /* Save the index */
1667 /* Point at the "info" */
1670 /* Tag name is given */
1674 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1677 /* Default "mimic" */
1678 f_ptr->mimic = (IDX)i;
1680 /* Default "destroyed state" -- if not specified */
1681 f_ptr->destroyed = (IDX)i;
1683 /* Default "states" */
1684 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1687 /* There better be a current f_ptr */
1688 else if (!f_ptr) return (3);
1691 else if (buf[0] == 'J')
1693 /* Store the name */
1694 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1697 else if (buf[0] == 'E')
1699 /* Ignore english name */
1702 else if (buf[0] == 'J')
1704 /* Ignore Japanese name */
1707 else if (buf[0] == 'E')
1709 /* Acquire the Text */
1712 /* Store the name */
1713 if (!add_name(&f_ptr->name, head, s)) return (7);
1718 /* Process 'M' for "Mimic" (one line only) */
1719 else if (buf[0] == 'M')
1723 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1725 /* Record a fake tag index */
1726 f_ptr->mimic = -offset;
1730 /* Process 'G' for "Graphics" (one line only) */
1731 else if (buf[0] == 'G')
1735 char char_tmp[F_LIT_MAX];
1738 if (buf[1] != ':') return (1);
1739 if (!buf[2]) return (1);
1740 if (buf[3] != ':') return (1);
1741 if (!buf[4]) return (1);
1743 /* Extract the char */
1744 char_tmp[F_LIT_STANDARD] = buf[2];
1746 /* Extract the color */
1747 s_attr = color_char_to_attr(buf[4]);
1750 if (s_attr > 127) return (1);
1752 /* Save the standard values */
1753 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1754 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1756 /* Is this feature supports lighting? */
1759 /* G:c:a:LIT (default) */
1760 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1762 /* G:c:a:lc:la:dc:da */
1763 if (!streq(buf + 6, "LIT"))
1765 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1767 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1768 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1769 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1770 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1772 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1774 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1777 /* Use default lighting */
1780 /* No lighting support */
1781 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1784 /* Extract the color */
1785 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1786 if (f_ptr->d_attr[j] > 127) return 1;
1789 f_ptr->d_char[j] = char_tmp[j];
1795 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1797 f_ptr->d_attr[j] = s_attr;
1798 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1804 /* Hack -- Process 'F' for flags */
1805 else if (buf[0] == 'F')
1807 /* Parse every entry textually */
1808 for (s = buf + 2; *s; )
1810 /* Find the end of this entry */
1811 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1813 /* Nuke and skip any dividers */
1817 while (*t == ' ' || *t == '|') t++;
1820 /* XXX XXX XXX Hack -- Read feature subtype */
1821 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1823 /* Extract a "subtype" */
1826 /* Start at next entry */
1833 /* XXX XXX XXX Hack -- Read feature power */
1834 if (1 == sscanf(s, "POWER_%d", &i))
1836 /* Extract a "power" */
1839 /* Start at next entry */
1846 /* Parse this entry */
1847 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1849 /* Start the next entry */
1854 /* Process 'W' for "More Info" (one line only) */
1855 else if (buf[0] == 'W')
1859 /* Scan for the value */
1860 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1862 /* Save the value */
1863 f_ptr->priority = priority;
1866 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1867 else if (buf[0] == 'K')
1871 /* Find the next empty state slot (if any) */
1872 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1874 /* Oops, no more slots */
1875 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1877 /* Analyze the first field */
1878 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1880 /* Terminate the field (if necessary) */
1881 if (*t == ':') *t++ = '\0';
1883 /* Is this default entry? */
1884 if (streq(s, "DESTROYED"))
1886 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1888 /* Record a fake tag index */
1889 f_ptr->destroyed = -offset;
1894 f_ptr->state[i].action = 0;
1896 /* Parse this entry */
1897 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1899 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1901 /* Record a fake tag index */
1902 f_ptr->state[i].result = -offset;
1915 * @brief 地形タグからIDを得る /
1916 * Convert a fake tag to a real feat index
1920 s16b f_tag_to_index(cptr str)
1924 /* Search for real index corresponding to this fake tag */
1925 for (i = 0; i < f_head.info_num; i++)
1927 if (streq(f_tag + f_info[i].tag, str))
1929 /* Return the index */
1940 * @brief 地形タグからIDを得る /
1941 * Search for real index corresponding to this fake tag
1945 static void search_real_feat(s16b *feat)
1949 /* Don't convert non-fake tag */
1950 if (*feat >= 0) return;
1952 /* Search for real index corresponding to this fake tag */
1953 for (i = 0; i < f_head.info_num; i++)
1955 if ((-(*feat)) == f_info[i].tag)
1957 /* Record real index */
1964 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + (-(*feat)));
1969 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1970 * Retouch fake tags of f_info
1971 * @param head ヘッダ構造体
1974 void retouch_f_info(header *head)
1978 /* Convert fake tags to real feat indices */
1979 for (i = 0; i < head->info_num; i++)
1981 feature_type *f_ptr = &f_info[i];
1984 search_real_feat(&f_ptr->mimic);
1986 search_real_feat(&f_ptr->destroyed);
1988 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1994 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1995 * Grab one flag in an object_kind from a textual string
1996 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1997 * @param what 参照元の文字列ポインタ
2000 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
2005 for (i = 0; i < TR_FLAG_MAX; i++)
2007 if (streq(what, k_info_flags[i]))
2009 add_flag(k_ptr->flags, i);
2014 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2018 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2025 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2026 * Grab one activation index flag
2027 * @param what 参照元の文字列ポインタ
2030 static byte grab_one_activation_flag(cptr what)
2036 if (activation_info[i].flag == NULL) break;
2038 if (streq(what, activation_info[i].flag))
2040 return activation_info[i].index;
2051 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2059 * @brief ベースアイテム(k_info)のパース関数 /
2060 * Initialize the "k_info" array, by parsing an ascii "template" file
2062 * @param head ヘッダ構造体
2065 errr parse_k_info(char *buf, header *head)
2072 static object_kind *k_ptr = NULL;
2075 /* Process 'N' for "New/Number/Name" */
2082 /* Find the colon before the name */
2083 s = my_strchr(buf+2, ':');
2085 /* Verify that colon */
2088 /* Nuke the colon, advance to the name */
2094 /* Verify information */
2095 if (i <= error_idx) return (4);
2097 /* Verify information */
2098 if (i >= head->info_num) return (2);
2100 /* Save the index */
2103 /* Point at the "info" */
2107 /* Paranoia -- require a name */
2108 if (!*s) return (1);
2110 /* Find the colon before the flavor */
2111 flavor = my_strchr(s, ':');
2113 /* Verify that colon */
2116 /* Nuke the colon, advance to the flavor */
2119 /* Store the flavor */
2120 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2123 /* Store the name */
2124 if (!add_name(&k_ptr->name, head, s)) return (7);
2128 /* There better be a current k_ptr */
2129 else if (!k_ptr) return (3);
2134 /* 'E' から始まる行は英語名としている */
2135 else if (buf[0] == 'E')
2140 else if (buf[0] == 'E')
2144 /* Acquire the name */
2147 /* Find the colon before the flavor */
2148 flavor = my_strchr(s, ':');
2150 /* Verify that colon */
2153 /* Nuke the colon, advance to the flavor */
2156 /* Store the flavor */
2157 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2160 /* Store the name */
2161 if (!add_name(&k_ptr->name, head, s)) return (7);
2165 /* Process 'D' for "Description" */
2166 else if (buf[0] == 'D')
2171 /* Acquire the text */
2176 /* Acquire the text */
2180 /* Store the text */
2181 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2184 /* Process 'G' for "Graphics" (one line only) */
2185 else if (buf[0] == 'G')
2191 if (buf[1] != ':') return (1);
2192 if (!buf[2]) return (1);
2193 if (buf[3] != ':') return (1);
2194 if (!buf[4]) return (1);
2196 /* Extract the char */
2199 /* Extract the attr */
2200 tmp = color_char_to_attr(buf[4]);
2203 if (tmp > 127) return (1);
2205 /* Save the values */
2206 k_ptr->d_attr = tmp;
2207 k_ptr->d_char = sym;
2210 /* Process 'I' for "Info" (one line only) */
2211 else if (buf[0] == 'I')
2213 int tval, sval, pval;
2215 /* Scan for the values */
2216 if (3 != sscanf(buf+2, "%d:%d:%d",
2217 &tval, &sval, &pval)) return (1);
2219 /* Save the values */
2220 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2221 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2222 k_ptr->pval = (PARAMETER_VALUE)pval;
2225 /* Process 'W' for "More Info" (one line only) */
2226 else if (buf[0] == 'W')
2228 int level, extra, wgt;
2231 /* Scan for the values */
2232 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2233 &level, &extra, &wgt, &cost)) return (1);
2235 /* Save the values */
2236 k_ptr->level = level;
2237 k_ptr->extra = extra;
2238 k_ptr->weight = (WEIGHT)wgt;
2239 k_ptr->cost = (PRICE)cost;
2242 /* Process 'A' for "Allocation" (one line only) */
2243 else if (buf[0] == 'A')
2246 /* XXX XXX XXX Simply read each number following a colon */
2247 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2249 /* Default chance */
2250 k_ptr->chance[i] = 1;
2252 /* Store the attack damage index */
2253 k_ptr->locale[i] = atoi(s+1);
2255 /* Find the slash */
2256 t = my_strchr(s+1, '/');
2258 /* Find the next colon */
2259 s = my_strchr(s+1, ':');
2261 /* If the slash is "nearby", use it */
2262 if (t && (!s || t < s))
2264 int chance = atoi(t+1);
2265 if (chance > 0) k_ptr->chance[i] = chance;
2270 /* Hack -- Process 'P' for "power" and such */
2271 else if (buf[0] == 'P')
2273 int ac, hd1, hd2, th, td, ta;
2275 /* Scan for the values */
2276 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2277 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2279 k_ptr->ac = (ARMOUR_CLASS)ac;
2280 k_ptr->dd = (DICE_NUMBER)hd1;
2281 k_ptr->ds = (DICE_SID)hd2;
2282 k_ptr->to_h = (HIT_PROB)th;
2283 k_ptr->to_d = (HIT_POINT)td;
2284 k_ptr->to_a = (ARMOUR_CLASS)ta;
2287 /* Hack -- Process 'U' for activation index */
2288 else if (buf[0] == 'U')
2291 n = grab_one_activation_flag(buf + 2);
2302 /* Hack -- Process 'F' for flags */
2303 else if (buf[0] == 'F')
2305 /* Parse every entry textually */
2306 for (s = buf + 2; *s; )
2308 /* Find the end of this entry */
2309 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2311 /* Nuke and skip any dividers */
2315 while (*t == ' ' || *t == '|') t++;
2318 /* Parse this entry */
2319 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2321 /* Start the next entry */
2336 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2337 * Grab one activation index flag
2338 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2339 * @param what 参照元の文字列ポインタ
2340 * @return エラーがあった場合1、エラーがない場合0を返す
2342 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2347 for (i = 0; i < TR_FLAG_MAX; i++)
2349 if (streq(what, k_info_flags[i]))
2351 add_flag(a_ptr->flags, i);
2356 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2360 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2368 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2369 * Initialize the "a_info" array, by parsing an ascii "template" file
2371 * @param head ヘッダ構造体
2374 errr parse_a_info(char *buf, header *head)
2381 static artifact_type *a_ptr = NULL;
2384 /* Process 'N' for "New/Number/Name" */
2387 /* Find the colon before the name */
2388 s = my_strchr(buf+2, ':');
2390 /* Verify that colon */
2393 /* Nuke the colon, advance to the name */
2396 /* Paranoia -- require a name */
2397 if (!*s) return (1);
2402 /* Verify information */
2403 if (i < error_idx) return (4);
2405 /* Verify information */
2406 if (i >= head->info_num) return (2);
2408 /* Save the index */
2411 /* Point at the "info" */
2414 /* Ignore everything */
2415 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2416 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2417 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2418 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2420 /* Store the name */
2421 if (!add_name(&a_ptr->name, head, s)) return (7);
2425 /* There better be a current a_ptr */
2426 else if (!a_ptr) return (3);
2431 /* 'E' から始まる行は英語名としている */
2432 else if (buf[0] == 'E')
2437 else if (buf[0] == 'E')
2439 /* Acquire the Text */
2442 /* Store the name */
2443 if (!add_name(&a_ptr->name, head, s)) return (7);
2447 /* Process 'D' for "Description" */
2448 else if (buf[0] == 'D')
2453 /* Acquire the text */
2458 /* Acquire the text */
2462 /* Store the text */
2463 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2467 /* Process 'I' for "Info" (one line only) */
2468 else if (buf[0] == 'I')
2470 int tval, sval, pval;
2472 /* Scan for the values */
2473 if (3 != sscanf(buf+2, "%d:%d:%d",
2474 &tval, &sval, &pval)) return (1);
2476 /* Save the values */
2482 /* Process 'W' for "More Info" (one line only) */
2483 else if (buf[0] == 'W')
2485 int level, rarity, wgt;
2488 /* Scan for the values */
2489 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2490 &level, &rarity, &wgt, &cost)) return (1);
2492 /* Save the values */
2493 a_ptr->level = level;
2494 a_ptr->rarity = rarity;
2495 a_ptr->weight = wgt;
2499 /* Hack -- Process 'P' for "power" and such */
2500 else if (buf[0] == 'P')
2502 int ac, hd1, hd2, th, td, ta;
2504 /* Scan for the values */
2505 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2506 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2516 /* Hack -- Process 'U' for activation index */
2517 else if (buf[0] == 'U')
2520 n = grab_one_activation_flag(buf + 2);
2531 /* Hack -- Process 'F' for flags */
2532 else if (buf[0] == 'F')
2534 /* Parse every entry textually */
2535 for (s = buf + 2; *s; )
2537 /* Find the end of this entry */
2538 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2540 /* Nuke and skip any dividers */
2544 while ((*t == ' ') || (*t == '|')) t++;
2547 /* Parse this entry */
2548 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2550 /* Start the next entry */
2566 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2567 * Grab one flag in a ego-item_type from a textual string
2568 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2569 * @param what 参照元の文字列ポインタ
2570 * @return エラーがあった場合1、エラーがない場合0を返す
2572 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2577 for (i = 0; i < TR_FLAG_MAX; i++)
2579 if (streq(what, k_info_flags[i]))
2581 add_flag(e_ptr->flags, i);
2586 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2590 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2598 * @brief アイテムエゴ情報(e_info)のパース関数 /
2599 * Initialize the "e_info" array, by parsing an ascii "template" file
2601 * @param head ヘッダ構造体
2604 errr parse_e_info(char *buf, header *head)
2611 static ego_item_type *e_ptr = NULL;
2614 /* Just before the first record */
2617 /* Just before the first line */
2621 /* Process 'N' for "New/Number/Name" */
2624 /* Find the colon before the name */
2625 s = my_strchr(buf+2, ':');
2627 /* Verify that colon */
2630 /* Nuke the colon, advance to the name */
2633 /* Paranoia -- require a name */
2634 if (!*s) return (1);
2639 /* Verify information */
2640 if (i < error_idx) return (4);
2642 /* Verify information */
2643 if (i >= head->info_num) return (2);
2645 /* Save the index */
2648 /* Point at the "info" */
2651 /* Store the name */
2652 if (!add_name(&e_ptr->name, head, s)) return (7);
2656 /* There better be a current e_ptr */
2657 else if (!e_ptr) return (3);
2662 /* 'E' から始まる行は英語名 */
2663 else if (buf[0] == 'E')
2668 else if (buf[0] == 'E')
2670 /* Acquire the Text */
2673 /* Store the name */
2674 if (!add_name(&e_ptr->name, head, s)) return (7);
2679 /* Process 'D' for "Description" */
2680 else if (buf[0] == 'D')
2682 /* Acquire the text */
2685 /* Store the text */
2686 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2691 /* Process 'X' for "Xtra" (one line only) */
2692 else if (buf[0] == 'X')
2696 /* Scan for the values */
2697 if (2 != sscanf(buf+2, "%d:%d",
2698 &slot, &rating)) return (1);
2700 /* Save the values */
2702 e_ptr->rating = rating;
2705 /* Process 'W' for "More Info" (one line only) */
2706 else if (buf[0] == 'W')
2708 int level, rarity, pad2;
2711 /* Scan for the values */
2712 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2713 &level, &rarity, &pad2, &cost)) return (1);
2715 /* Save the values */
2716 e_ptr->level = level;
2717 e_ptr->rarity = (RARITY)rarity;
2718 /* e_ptr->weight = wgt; */
2722 /* Hack -- Process 'C' for "creation" */
2723 else if (buf[0] == 'C')
2725 int th, td, ta, pval;
2727 /* Scan for the values */
2728 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2729 &th, &td, &ta, &pval)) return (1);
2731 e_ptr->max_to_h = th;
2732 e_ptr->max_to_d = td;
2733 e_ptr->max_to_a = ta;
2734 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2737 /* Hack -- Process 'U' for activation index */
2738 else if (buf[0] == 'U')
2741 n = grab_one_activation_flag(buf + 2);
2752 /* Hack -- Process 'F' for flags */
2753 else if (buf[0] == 'F')
2755 /* Parse every entry textually */
2756 for (s = buf + 2; *s; )
2758 /* Find the end of this entry */
2759 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2761 /* Nuke and skip any dividers */
2765 while ((*t == ' ') || (*t == '|')) t++;
2768 /* Parse this entry */
2769 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2771 /* Start the next entry */
2785 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2786 * Grab one (basic) flag in a monster_race from a textual string
2787 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2788 * @param what 参照元の文字列ポインタ
2791 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2793 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2796 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2799 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2802 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2805 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2808 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2811 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2815 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2823 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2824 * Grab one (spell) flag in a monster_race from a textual string
2825 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2826 * @param what 参照元の文字列ポインタ
2829 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2831 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2834 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2837 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2841 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2849 * @brief モンスター種族情報(r_info)のパース関数 /
2850 * Initialize the "r_info" array, by parsing an ascii "template" file
2852 * @param head ヘッダ構造体
2855 errr parse_r_info(char *buf, header *head)
2862 static monster_race *r_ptr = NULL;
2865 /* Process 'N' for "New/Number/Name" */
2868 /* Find the colon before the name */
2869 s = my_strchr(buf+2, ':');
2871 /* Verify that colon */
2874 /* Nuke the colon, advance to the name */
2877 /* Paranoia -- require a name */
2878 if (!*s) return (1);
2883 /* Verify information */
2884 if (i < error_idx) return (4);
2886 /* Verify information */
2887 if (i >= head->info_num) return (2);
2889 /* Save the index */
2892 /* Point at the "info" */
2895 /* Store the name */
2896 if (!add_name(&r_ptr->name, head, s)) return (7);
2900 /* There better be a current r_ptr */
2901 else if (!r_ptr) return (3);
2906 /* 'E' から始まる行は英語名 */
2907 else if (buf[0] == 'E')
2909 /* Acquire the Text */
2912 /* Store the name */
2913 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2916 else if (buf[0] == 'E')
2918 /* Acquire the Text */
2921 /* Store the name */
2922 if (!add_name(&r_ptr->name, head, s)) return (7);
2925 /* Process 'D' for "Description" */
2926 else if (buf[0] == 'D')
2931 /* Acquire the text */
2936 /* Acquire the text */
2940 /* Store the text */
2941 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2944 /* Process 'G' for "Graphics" (one line only) */
2945 else if (buf[0] == 'G')
2951 if (buf[1] != ':') return (1);
2952 if (!buf[2]) return (1);
2953 if (buf[3] != ':') return (1);
2954 if (!buf[4]) return (1);
2956 /* Extract the char */
2959 /* Extract the attr */
2960 tmp = color_char_to_attr(buf[4]);
2963 if (tmp > 127) return (1);
2965 /* Save the values */
2966 r_ptr->d_char = sym;
2967 r_ptr->d_attr = tmp;
2970 /* Process 'I' for "Info" (one line only) */
2971 else if (buf[0] == 'I')
2973 int spd, hp1, hp2, aaf, ac, slp;
2975 /* Scan for the other values */
2976 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2977 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2979 /* Save the values */
2980 r_ptr->speed = (SPEED)spd;
2981 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2982 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2984 r_ptr->ac = (ARMOUR_CLASS)ac;
2988 /* Process 'W' for "More Info" (one line only) */
2989 else if (buf[0] == 'W')
2996 /* Scan for the values */
2997 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2998 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
3000 /* Save the values */
3001 r_ptr->level = (DEPTH)lev;
3002 r_ptr->rarity = (RARITY)rar;
3005 r_ptr->next_exp = nextexp;
3006 r_ptr->next_r_idx = (IDX)nextmon;
3009 /* Process 'R' for "Reinforcement" (up to six lines) */
3010 else if (buf[0] == 'R')
3013 /* Find the next empty blow slot (if any) */
3014 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
3016 /* Oops, no more slots */
3017 if (i == 6) return (1);
3019 /* Scan for the values */
3020 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
3021 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
3022 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
3023 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
3026 /* Process 'B' for "Blows" (up to four lines) */
3027 else if (buf[0] == 'B')
3031 /* Find the next empty blow slot (if any) */
3032 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3034 /* Oops, no more slots */
3035 if (i == 4) return (1);
3037 /* Analyze the first field */
3038 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
3040 /* Terminate the field (if necessary) */
3041 if (*t == ':') *t++ = '\0';
3043 /* Analyze the method */
3044 for (n1 = 0; r_info_blow_method[n1]; n1++)
3046 if (streq(s, r_info_blow_method[n1])) break;
3049 /* Invalid method */
3050 if (!r_info_blow_method[n1]) return (1);
3052 /* Analyze the second field */
3053 for (s = t; *t && (*t != ':'); t++) /* loop */;
3055 /* Terminate the field (if necessary) */
3056 if (*t == ':') *t++ = '\0';
3058 /* Analyze effect */
3059 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3061 if (streq(s, r_info_blow_effect[n2])) break;
3064 /* Invalid effect */
3065 if (!r_info_blow_effect[n2]) return (1);
3067 /* Analyze the third field */
3068 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3070 /* Terminate the field (if necessary) */
3071 if (*t == 'd') *t++ = '\0';
3073 /* Save the method */
3074 r_ptr->blow[i].method = n1;
3076 /* Save the effect */
3077 r_ptr->blow[i].effect = n2;
3079 /* Extract the damage dice and sides */
3080 r_ptr->blow[i].d_dice = atoi(s);
3081 r_ptr->blow[i].d_side = atoi(t);
3084 /* Process 'F' for "Basic Flags" (multiple lines) */
3085 else if (buf[0] == 'F')
3087 /* Parse every entry */
3088 for (s = buf + 2; *s; )
3090 /* Find the end of this entry */
3091 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3093 /* Nuke and skip any dividers */
3097 while (*t == ' ' || *t == '|') t++;
3100 /* Parse this entry */
3101 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3103 /* Start the next entry */
3108 /* Process 'S' for "Spell Flags" (multiple lines) */
3109 else if (buf[0] == 'S')
3111 /* Parse every entry */
3112 for (s = buf + 2; *s; )
3114 /* Find the end of this entry */
3115 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3117 /* Nuke and skip any dividers */
3121 while ((*t == ' ') || (*t == '|')) t++;
3124 /* XXX XXX XXX Hack -- Read spell frequency */
3125 if (1 == sscanf(s, "1_IN_%d", &i))
3127 /* Extract a "frequency" */
3128 r_ptr->freq_spell = 100 / i;
3130 /* Start at next entry */
3137 /* Parse this entry */
3138 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3140 /* Start the next entry */
3145 /* Process 'A' for "Artifact Flags" (multiple lines) */
3146 else if (buf[0] == 'A')
3148 int id, per, rarity;
3150 /* Find the next empty blow slot (if any) */
3151 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3153 /* Oops, no more slots */
3154 if (i == 4) return (1);
3156 if (3 != sscanf(buf+2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3157 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3158 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3159 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3162 /* Process 'V' for "Arena power value ratio" */
3163 else if (buf[0] == 'V')
3166 if (3 != sscanf(buf+2, "%d", &val)) return (1);
3167 r_ptr->arena_ratio = (PERCENTAGE)val;
3180 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3181 * Grab one flag for a dungeon type from a textual string
3182 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3183 * @param what 参照元の文字列ポインタ
3186 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3188 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3192 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3199 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3200 * Grab one (basic) flag in a monster_race from a textual string
3201 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3202 * @param what 参照元の文字列ポインタ
3205 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3207 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3210 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3213 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3216 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3219 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3222 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3225 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3229 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3236 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3237 * Grab one (spell) flag in a monster_race from a textual string
3238 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3239 * @param what 参照元の文字列ポインタ
3242 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3244 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3247 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3250 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3254 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3261 * @brief ダンジョン情報(d_info)のパース関数 /
3262 * Initialize the "d_info" array, by parsing an ascii "template" file
3264 * @param head ヘッダ構造体
3267 errr parse_d_info(char *buf, header *head)
3274 static dungeon_info_type *d_ptr = NULL;
3277 /* Process 'N' for "New/Number/Name" */
3280 /* Find the colon before the name */
3281 s = my_strchr(buf+2, ':');
3283 /* Verify that colon */
3286 /* Nuke the colon, advance to the name */
3289 /* Paranoia -- require a name */
3290 if (!*s) return (1);
3295 /* Verify information */
3296 if (i < error_idx) return (4);
3298 /* Verify information */
3299 if (i >= head->info_num) return (2);
3301 /* Save the index */
3304 /* Point at the "info" */
3307 /* Store the name */
3308 if (!add_name(&d_ptr->name, head, s)) return (7);
3313 else if (buf[0] == 'E') return (0);
3315 else if (buf[0] == 'E')
3317 /* Acquire the Text */
3320 /* Store the name */
3321 if (!add_name(&d_ptr->name, head, s)) return (7);
3325 /* Process 'D' for "Description */
3326 else if (buf[0] == 'D')
3331 /* Acquire the text */
3336 /* Acquire the text */
3340 /* Store the text */
3341 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3344 /* Process 'W' for "More Info" (one line only) */
3345 else if (buf[0] == 'W')
3347 int min_lev, max_lev;
3349 int min_alloc, max_chance;
3350 int obj_good, obj_great;
3353 /* Scan for the values */
3354 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3355 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3357 /* Save the values */
3358 d_ptr->mindepth = min_lev;
3359 d_ptr->maxdepth = max_lev;
3360 d_ptr->min_plev = min_plev;
3362 d_ptr->min_m_alloc_level = min_alloc;
3363 d_ptr->max_m_alloc_chance = max_chance;
3364 d_ptr->obj_good = obj_good;
3365 d_ptr->obj_great = obj_great;
3370 /* Process 'P' for "Place Info" */
3371 else if (buf[0] == 'P')
3375 /* Scan for the values */
3376 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3378 /* Save the values */
3383 /* Process 'L' for "fLoor type" (one line only) */
3384 else if (buf[0] == 'L')
3388 /* Scan for the values */
3389 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3391 /* Save the values */
3392 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3394 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3395 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3397 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3399 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3402 /* Process 'A' for "wAll type" (one line only) */
3403 else if (buf[0] == 'A')
3407 /* Scan for the values */
3408 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3410 /* Save the values */
3411 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3413 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3414 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3416 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3419 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3420 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3422 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3423 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3425 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3426 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3428 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3429 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3432 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3433 else if (buf[0] == 'F')
3435 int artif = 0, monst = 0;
3437 /* Parse every entry */
3438 for (s = buf + 2; *s; )
3440 /* Find the end of this entry */
3441 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3443 /* Nuke and skip any dividers */
3447 while (*t == ' ' || *t == '|') t++;
3450 /* XXX XXX XXX Hack -- Read Final Artifact */
3451 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3453 /* Extract a "Final Artifact" */
3454 d_ptr->final_artifact = artif;
3456 /* Start at next entry */
3463 /* XXX XXX XXX Hack -- Read Final Object */
3464 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3466 /* Extract a "Final Artifact" */
3467 d_ptr->final_object = artif;
3469 /* Start at next entry */
3476 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3477 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3479 /* Extract a "Artifact Guardian" */
3480 d_ptr->final_guardian = monst;
3482 /* Start at next entry */
3489 /* XXX XXX XXX Hack -- Read Special Percentage */
3490 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3492 /* Extract a "Special %" */
3493 d_ptr->special_div = monst;
3495 /* Start at next entry */
3502 /* Parse this entry */
3503 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3505 /* Start the next entry */
3510 /* Process 'M' for "Basic Flags" (multiple lines) */
3511 else if (buf[0] == 'M')
3513 /* Parse every entry */
3514 for (s = buf + 2; *s; )
3516 /* Find the end of this entry */
3517 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3519 /* Nuke and skip any dividers */
3523 while (*t == ' ' || *t == '|') t++;
3526 /* Hack -- Read monster symbols */
3527 if (!strncmp(s, "R_CHAR_", 7))
3529 /* Skip "R_CHAR_" */
3533 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3535 /* Start at next entry */
3542 /* Parse this entry */
3543 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3545 /* Start the next entry */
3550 /* Process 'S' for "Spell Flags" (multiple lines) */
3551 else if (buf[0] == 'S')
3553 /* Parse every entry */
3554 for (s = buf + 2; *s; )
3556 /* Find the end of this entry */
3557 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3559 /* Nuke and skip any dividers */
3563 while ((*t == ' ') || (*t == '|')) t++;
3566 /* XXX XXX XXX Hack -- Read spell frequency */
3567 if (1 == sscanf(s, "1_IN_%d", &i))
3569 /* Start at next entry */
3576 /* Parse this entry */
3577 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3579 /* Start the next entry */
3592 #else /* ALLOW_TEMPLATES */
3598 #endif /* ALLOW_TEMPLATES */
3601 /* Random dungeon grid effects */
3602 #define RANDOM_NONE 0x00000000
3603 #define RANDOM_FEATURE 0x00000001
3604 #define RANDOM_MONSTER 0x00000002
3605 #define RANDOM_OBJECT 0x00000004
3606 #define RANDOM_EGO 0x00000008
3607 #define RANDOM_ARTIFACT 0x00000010
3608 #define RANDOM_TRAP 0x00000020
3611 typedef struct dungeon_grid dungeon_grid;
3615 IDX feature; /* Terrain feature */
3616 IDX monster; /* Monster */
3617 IDX object; /* Object */
3618 IDX ego; /* Ego-Item */
3619 IDX artifact; /* Artifact */
3620 IDX trap; /* Trap */
3621 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3622 int special; /* Reserved for special terrain info */
3623 int random; /* Number of the random effect */
3627 static dungeon_grid letter[255];
3631 * @brief 地形情報の「F:」情報をパースする
3632 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3636 static errr parse_line_feature(char *buf)
3642 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3644 /* Tokenize the line */
3645 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3647 /* Letter to assign */
3648 int index = zz[0][0];
3650 /* Reset the info for the letter */
3651 letter[index].feature = feat_none;
3652 letter[index].monster = 0;
3653 letter[index].object = 0;
3654 letter[index].ego = 0;
3655 letter[index].artifact = 0;
3656 letter[index].trap = feat_none;
3657 letter[index].cave_info = 0;
3658 letter[index].special = 0;
3659 letter[index].random = RANDOM_NONE;
3665 letter[index].special = atoi(zz[8]);
3669 if ((zz[7][0] == '*') && !zz[7][1])
3671 letter[index].random |= RANDOM_TRAP;
3675 letter[index].trap = f_tag_to_index(zz[7]);
3676 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3681 if (zz[6][0] == '*')
3683 letter[index].random |= RANDOM_ARTIFACT;
3684 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3686 else if (zz[6][0] == '!')
3688 if (p_ptr->inside_quest)
3690 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3695 letter[index].artifact = (IDX)atoi(zz[6]);
3700 if (zz[5][0] == '*')
3702 letter[index].random |= RANDOM_EGO;
3703 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3707 letter[index].ego = (IDX)atoi(zz[5]);
3712 if (zz[4][0] == '*')
3714 letter[index].random |= RANDOM_OBJECT;
3715 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3717 else if (zz[4][0] == '!')
3719 if (p_ptr->inside_quest)
3721 int a_idx = quest[p_ptr->inside_quest].k_idx;
3724 artifact_type *a_ptr = &a_info[a_idx];
3725 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3727 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3734 letter[index].object = (IDX)atoi(zz[4]);
3739 if (zz[3][0] == '*')
3741 letter[index].random |= RANDOM_MONSTER;
3742 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3744 else if (zz[3][0] == 'c')
3746 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3747 letter[index].monster = - atoi(zz[3] + 1);
3751 letter[index].monster = (IDX)atoi(zz[3]);
3756 letter[index].cave_info = atoi(zz[2]);
3760 if ((zz[1][0] == '*') && !zz[1][1])
3762 letter[index].random |= RANDOM_FEATURE;
3766 letter[index].feature = f_tag_to_index(zz[1]);
3767 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3780 * @brief 地形情報の「B:」情報をパースする
3781 * Process "B:<Index>:<Command>:..." -- Building definition
3785 static errr parse_line_building(char *buf)
3801 /* Get the building number */
3804 /* Find the colon after the building number */
3805 s = my_strchr(s, ':');
3807 /* Verify that colon */
3810 /* Nuke the colon, advance to the sub-index */
3813 /* Paranoia -- require a sub-index */
3814 if (!*s) return (1);
3816 /* Building definition sub-index */
3819 /* Building name, owner, race */
3822 if (tokenize(s + 2, 3, zz, 0) == 3)
3824 /* Name of the building */
3825 strcpy(building[index].name, zz[0]);
3827 /* Name of the owner */
3828 strcpy(building[index].owner_name, zz[1]);
3830 /* Race of the owner */
3831 strcpy(building[index].owner_race, zz[2]);
3836 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3839 /* Building Action */
3842 if (tokenize(s + 2, 8, zz, 0) >= 7)
3844 /* Index of the action */
3845 int action_index = atoi(zz[0]);
3847 /* Name of the action */
3848 strcpy(building[index].act_names[action_index], zz[1]);
3850 /* Cost of the action for members */
3851 building[index].member_costs[action_index] = atoi(zz[2]);
3853 /* Cost of the action for non-members */
3854 building[index].other_costs[action_index] = atoi(zz[3]);
3856 /* Letter assigned to the action */
3857 building[index].letters[action_index] = zz[4][0];
3860 building[index].actions[action_index] = atoi(zz[5]);
3862 /* Action restriction */
3863 building[index].action_restr[action_index] = atoi(zz[6]);
3868 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3871 /* Building Classes */
3874 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3876 for (i = 0; i < MAX_CLASS; i++)
3878 building[index].member_class[i] = atoi(zz[i]);
3884 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3887 /* Building Races */
3890 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3892 for (i = 0; i < MAX_RACES; i++)
3894 building[index].member_race[i] = atoi(zz[i]);
3900 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3903 /* Building Realms */
3906 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3908 for (i = 0; i < MAX_MAGIC; i++)
3910 building[index].member_realm[i+1] = atoi(zz[i]);
3916 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3921 /* Ignore scripts */
3927 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3936 * @brief フロアの所定のマスにオブジェクトを配置する
3937 * Place the object j_ptr to a grid
3938 * @param j_ptr オブジェクト構造体の参照ポインタ
3943 static void drop_here(object_type *j_ptr, int y, int x)
3945 cave_type *c_ptr = &cave[y][x];
3948 /* Get new object */
3949 s16b o_idx = o_pop();
3951 /* Access new object */
3952 o_ptr = &o_list[o_idx];
3954 /* Structure copy */
3955 object_copy(o_ptr, j_ptr);
3963 o_ptr->held_m_idx = 0;
3966 o_ptr->next_o_idx = c_ptr->o_idx;
3968 /* Place the object */
3969 c_ptr->o_idx = o_idx;
3974 * @brief クエスト用固定ダンジョンをフロアに生成する
3975 * Parse a sub-file of the "extra info"
3985 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3992 /* Skip "empty" lines */
3993 if (!buf[0]) return (0);
3995 /* Skip "blank" lines */
3996 if (iswspace(buf[0])) return (0);
3999 if (buf[0] == '#') return (0);
4001 /* Require "?:*" format */
4002 if (buf[1] != ':') return (1);
4005 /* Process "%:<fname>" */
4008 /* Attempt to Process the given file */
4009 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
4012 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
4015 return parse_line_feature(buf);
4018 /* Process "D:<dungeon>" -- info for the cave grids */
4019 else if (buf[0] == 'D')
4021 object_type object_type_body;
4023 /* Acquire the text */
4026 /* Length of the text */
4027 int len = strlen(s);
4029 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
4031 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
4033 /* Access the grid */
4034 cave_type *c_ptr = &cave[*y][*x];
4038 IDX object_index = letter[idx].object;
4039 IDX monster_index = letter[idx].monster;
4040 int random = letter[idx].random;
4041 IDX artifact_index = letter[idx].artifact;
4043 /* Lay down a floor */
4044 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
4046 /* Only the features */
4047 if (init_flags & INIT_ONLY_FEATURES) continue;
4050 c_ptr->info = letter[idx].cave_info;
4052 /* Create a monster */
4053 if (random & RANDOM_MONSTER)
4055 monster_level = base_level + monster_index;
4057 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4059 monster_level = base_level;
4061 else if (monster_index)
4063 int old_cur_num, old_max_num;
4066 if (monster_index < 0)
4068 monster_index = -monster_index;
4071 old_cur_num = r_info[monster_index].cur_num;
4072 old_max_num = r_info[monster_index].max_num;
4074 /* Make alive again */
4075 if (r_info[monster_index].flags1 & RF1_UNIQUE)
4077 r_info[monster_index].cur_num = 0;
4078 r_info[monster_index].max_num = 1;
4081 /* Make alive again */
4082 /* Hack -- Non-unique Nazguls are semi-unique */
4083 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
4085 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
4087 r_info[monster_index].max_num++;
4092 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4096 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4098 /* Make alive again for real unique monster */
4099 r_info[monster_index].cur_num = old_cur_num;
4100 r_info[monster_index].max_num = old_max_num;
4104 /* Object (and possible trap) */
4105 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4107 object_level = base_level + object_index;
4110 * Random trap and random treasure defined
4111 * 25% chance for trap and 75% chance for object
4113 if (randint0(100) < 75)
4115 place_object(*y, *x, 0L);
4122 object_level = base_level;
4124 else if (random & RANDOM_OBJECT)
4126 object_level = base_level + object_index;
4128 /* Create an out of deep object */
4129 if (randint0(100) < 75)
4130 place_object(*y, *x, 0L);
4131 else if (randint0(100) < 80)
4132 place_object(*y, *x, AM_GOOD);
4134 place_object(*y, *x, AM_GOOD | AM_GREAT);
4136 object_level = base_level;
4139 else if (random & RANDOM_TRAP)
4143 /* Hidden trap (or door) */
4144 else if (letter[idx].trap)
4146 c_ptr->mimic = c_ptr->feat;
4147 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4149 else if (object_index)
4151 /* Get local object */
4152 object_type *o_ptr = &object_type_body;
4154 /* Create the item */
4155 object_prep(o_ptr, object_index);
4157 if (o_ptr->tval == TV_GOLD)
4159 coin_type = object_index - OBJ_GOLD_LIST;
4164 /* Apply magic (no messages, no artifacts) */
4165 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4167 drop_here(o_ptr, *y, *x);
4173 if (a_info[artifact_index].cur_num)
4175 IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4177 object_type *q_ptr = &forge;
4179 object_prep(q_ptr, k_idx);
4181 /* Drop it in the dungeon */
4182 drop_here(q_ptr, *y, *x);
4186 /* Create the artifact */
4187 if (create_named_art(artifact_index, *y, *x))
4188 a_info[artifact_index].cur_num = 1;
4192 /* Terrain special */
4193 c_ptr->special = letter[idx].special;
4201 /* Process "Q:<number>:<command>:... -- quest info */
4202 else if (buf[0] == 'Q')
4209 num = tokenize(buf + 2, 33, zz, 0);
4213 num = tokenize(buf + 3, 33, zz, 0);
4216 /* Have we enough parameters? */
4217 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4220 q_ptr = &(quest[atoi(zz[0])]);
4222 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4223 if (zz[1][0] == 'Q')
4225 if (init_flags & INIT_ASSIGN)
4227 monster_race *r_ptr;
4228 artifact_type *a_ptr;
4230 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4232 q_ptr->type = atoi(zz[2]);
4233 q_ptr->num_mon = atoi(zz[3]);
4234 q_ptr->cur_num = atoi(zz[4]);
4235 q_ptr->max_num = atoi(zz[5]);
4236 q_ptr->level = atoi(zz[6]);
4237 q_ptr->r_idx = (IDX)atoi(zz[7]);
4238 q_ptr->k_idx = (IDX)atoi(zz[8]);
4239 q_ptr->dungeon = atoi(zz[9]);
4242 q_ptr->flags = atoi(zz[10]);
4244 r_ptr = &r_info[q_ptr->r_idx];
4245 if (r_ptr->flags1 & RF1_UNIQUE)
4246 r_ptr->flags1 |= RF1_QUESTOR;
4248 a_ptr = &a_info[q_ptr->k_idx];
4249 a_ptr->gen_flags |= TRG_QUESTITEM;
4254 else if (zz[1][0] == 'R')
4256 if (init_flags & INIT_ASSIGN)
4259 IDX idx, reward_idx = 0;
4261 for (idx = 2; idx < num; idx++)
4263 IDX a_idx = (IDX)atoi(zz[idx]);
4264 if (a_idx < 1) continue;
4265 if (a_info[a_idx].cur_num > 0) continue;
4267 if (one_in_(count)) reward_idx = a_idx;
4272 /* Set quest's rewarding artifact */
4273 q_ptr->k_idx = reward_idx;
4274 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4278 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4279 q_ptr->type = QUEST_TYPE_KILL_ALL;
4286 /* Process "Q:<q_index>:N:<name>" -- quest name */
4287 else if (zz[1][0] == 'N')
4289 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4291 strcpy(q_ptr->name, zz[2]);
4297 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4298 else if (zz[1][0] == 'T')
4300 if (init_flags & INIT_SHOW_TEXT)
4302 strcpy(quest_text[quest_text_line], zz[2]);
4310 /* Process "W:<command>: ..." -- info for the wilderness */
4311 else if (buf[0] == 'W')
4313 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4316 /* Process "P:<y>:<x>" -- player position */
4317 else if (buf[0] == 'P')
4319 if (init_flags & INIT_CREATE_DUNGEON)
4321 if (tokenize(buf + 2, 2, zz, 0) == 2)
4323 int panels_x, panels_y;
4325 /* Hack - Set the dungeon size */
4326 panels_y = (*y / SCREEN_HGT);
4327 if (*y % SCREEN_HGT) panels_y++;
4328 cur_hgt = panels_y * SCREEN_HGT;
4330 panels_x = (*x / SCREEN_WID);
4331 if (*x % SCREEN_WID) panels_x++;
4332 cur_wid = panels_x * SCREEN_WID;
4334 /* Assume illegal panel */
4335 panel_row_min = cur_hgt;
4336 panel_col_min = cur_wid;
4338 /* Place player in a quest level */
4339 if (p_ptr->inside_quest)
4343 /* Delete the monster (if any) */
4344 delete_monster(p_ptr->y, p_ptr->x);
4352 /* Place player in the town */
4353 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4355 p_ptr->oldpy = atoi(zz[0]);
4356 p_ptr->oldpx = atoi(zz[1]);
4364 /* Process "B:<Index>:<Command>:..." -- Building definition */
4365 else if (buf[0] == 'B')
4367 return parse_line_building(buf);
4370 /* Process "M:<type>:<maximum>" -- set maximum values */
4371 else if (buf[0] == 'M')
4373 if (tokenize(buf+2, 2, zz, 0) == 2)
4376 if (zz[0][0] == 'T')
4378 max_towns = (IDX)atoi(zz[1]);
4381 /* Maximum quests */
4382 else if (zz[0][0] == 'Q')
4384 max_quests = (IDX)atoi(zz[1]);
4388 else if (zz[0][0] == 'R')
4390 max_r_idx = (IDX)atoi(zz[1]);
4394 else if (zz[0][0] == 'K')
4396 max_k_idx = (IDX)atoi(zz[1]);
4400 else if (zz[0][0] == 'V')
4402 max_v_idx = (IDX)atoi(zz[1]);
4406 else if (zz[0][0] == 'F')
4408 max_f_idx = (IDX)atoi(zz[1]);
4412 else if (zz[0][0] == 'A')
4414 max_a_idx = (IDX)atoi(zz[1]);
4418 else if (zz[0][0] == 'E')
4420 max_e_idx = (IDX)atoi(zz[1]);
4424 else if (zz[0][0] == 'D')
4426 max_d_idx = (IDX)atoi(zz[1]);
4430 else if (zz[0][0] == 'O')
4432 max_o_idx = (IDX)atoi(zz[1]);
4436 else if (zz[0][0] == 'M')
4438 max_m_idx = (IDX)atoi(zz[1]);
4441 /* Wilderness size */
4442 else if (zz[0][0] == 'W')
4444 /* Maximum wild_x_size */
4445 if (zz[0][1] == 'X')
4446 max_wild_x = atoi(zz[1]);
4447 /* Maximum wild_y_size */
4448 if (zz[0][1] == 'Y')
4449 max_wild_y = atoi(zz[1]);
4463 static cptr variant = "ZANGBAND";
4467 * @brief クエスト用固定ダンジョン生成時の分岐処理
4468 * Helper function for "process_dungeon_file()"
4473 static cptr process_dungeon_file_expr(char **sp, char *fp)
4489 while (iswspace(*s)) s++;
4507 t = process_dungeon_file_expr(&s, &f);
4516 else if (streq(t, "IOR"))
4519 while (*s && (f != b2))
4521 t = process_dungeon_file_expr(&s, &f);
4522 if (*t && !streq(t, "0")) v = "1";
4527 else if (streq(t, "AND"))
4530 while (*s && (f != b2))
4532 t = process_dungeon_file_expr(&s, &f);
4533 if (*t && streq(t, "0")) v = "0";
4538 else if (streq(t, "NOT"))
4541 while (*s && (f != b2))
4543 t = process_dungeon_file_expr(&s, &f);
4544 if (*t && streq(t, "1")) v = "0";
4549 else if (streq(t, "EQU"))
4552 if (*s && (f != b2))
4554 t = process_dungeon_file_expr(&s, &f);
4556 while (*s && (f != b2))
4558 p = process_dungeon_file_expr(&s, &f);
4559 if (streq(t, p)) v = "1";
4564 else if (streq(t, "LEQ"))
4567 if (*s && (f != b2))
4569 t = process_dungeon_file_expr(&s, &f);
4571 while (*s && (f != b2))
4574 t = process_dungeon_file_expr(&s, &f);
4575 if (*t && atoi(p) > atoi(t)) v = "0";
4580 else if (streq(t, "GEQ"))
4583 if (*s && (f != b2))
4585 t = process_dungeon_file_expr(&s, &f);
4587 while (*s && (f != b2))
4590 t = process_dungeon_file_expr(&s, &f);
4592 /* Compare two numbers instead of string */
4593 if (*t && atoi(p) < atoi(t)) v = "0";
4600 while (*s && (f != b2))
4602 t = process_dungeon_file_expr(&s, &f);
4607 if (f != b2) v = "?x?x?";
4609 /* Extract final and Terminate */
4610 if ((f = *s) != '\0') *s++ = '\0';
4616 /* Accept all printables except spaces and brackets */
4618 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4620 if (iskanji(*s)) s++;
4624 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4627 /* Extract final and Terminate */
4628 if ((f = *s) != '\0') *s++ = '\0';
4634 if (streq(b+1, "SYS"))
4640 else if (streq(b+1, "GRAF"))
4645 else if (streq(b+1, "MONOCHROME"))
4654 else if (streq(b+1, "RACE"))
4656 v = _(rp_ptr->E_title, rp_ptr->title);
4660 else if (streq(b+1, "CLASS"))
4662 v = _(cp_ptr->E_title, cp_ptr->title);
4666 else if (streq(b+1, "REALM1"))
4668 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4672 else if (streq(b+1, "REALM2"))
4674 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4678 else if (streq(b+1, "PLAYER"))
4680 static char tmp_player_name[32];
4682 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4692 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4695 v = tmp_player_name;
4699 else if (streq(b+1, "TOWN"))
4701 sprintf(tmp, "%d", p_ptr->town_num);
4706 else if (streq(b+1, "LEVEL"))
4708 sprintf(tmp, "%d", p_ptr->lev);
4712 /* Current quest number */
4713 else if (streq(b+1, "QUEST_NUMBER"))
4715 sprintf(tmp, "%d", p_ptr->inside_quest);
4719 /* Number of last quest */
4720 else if (streq(b+1, "LEAVING_QUEST"))
4722 sprintf(tmp, "%d", leaving_quest);
4727 else if (prefix(b+1, "QUEST_TYPE"))
4729 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4730 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4735 else if (prefix(b+1, "QUEST"))
4737 /* "QUEST" uses a special parameter to determine the number of the quest */
4738 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4743 else if (prefix(b+1, "RANDOM"))
4745 /* "RANDOM" uses a special parameter to determine the number of the quest */
4746 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4751 else if (streq(b+1, "VARIANT"))
4757 else if (streq(b+1, "WILDERNESS"))
4760 sprintf(tmp, "NONE");
4762 sprintf(tmp, "LITE");
4764 sprintf(tmp, "NORMAL");
4788 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4789 * Helper function for "process_dungeon_file()"
4797 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4807 bool bypass = FALSE;
4809 int x = xmin, y = ymin;
4812 /* Build the filename */
4813 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4816 fp = my_fopen(buf, "r");
4819 if (!fp) return (-1);
4822 /* Process the file */
4823 while (0 == my_fgets(fp, buf, sizeof(buf)))
4829 /* Skip "empty" lines */
4830 if (!buf[0]) continue;
4832 /* Skip "blank" lines */
4833 if (iswspace(buf[0])) continue;
4836 if (buf[0] == '#') continue;
4839 /* Process "?:<expr>" */
4840 if ((buf[0] == '?') && (buf[1] == ':'))
4849 /* Parse the expr */
4850 v = process_dungeon_file_expr(&s, &f);
4853 bypass = (streq(v, "0") ? TRUE : FALSE);
4859 /* Apply conditionals */
4860 if (bypass) continue;
4862 /* Process the line */
4863 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4875 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4878 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4879 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);
4885 /* Close the file */
4895 void write_r_info_txt(void)
4897 int i, j, z, fc, bc;
4900 cptr flags[32 * 10];
4905 monster_race *r_ptr;
4907 monster_blow *b_ptr;
4909 FILE *fff = fopen("output.txt", "wt");
4917 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4919 fprintf(fff, "# Version stamp (required)\n\n");
4922 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4925 fprintf(fff, "##### The Player #####\n\n");
4927 for (z = -1; z < alloc_race_size; z++)
4929 /* Output the monsters in order */
4930 i = (z >= 0) ? alloc_race_table[z].index : 0;
4932 /* Acquire the monster */
4935 /* Ignore empty monsters */
4936 if (!strlen(r_name + r_ptr->name)) continue;
4938 /* Ignore useless monsters */
4939 if (i && !r_ptr->speed) continue;
4941 /* Write a note if necessary */
4942 if (i && (!r_ptr->level != !mode))
4947 fprintf(fff, "\n##### Town monsters #####\n\n");
4949 /* Note the dungeon */
4952 fprintf(fff, "\n##### Normal monsters #####\n\n");
4955 /* Record the change */
4956 mode = r_ptr->level;
4959 /* Acquire the flags */
4960 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4961 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4962 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4963 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4964 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4965 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4966 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4967 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4968 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4969 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4971 /* Write New/Number/Name */
4972 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4975 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4977 /* Write Information */
4978 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4979 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4981 /* Write more information */
4982 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4985 for(j = 0; j < 4; j++)
4987 b_ptr = &(r_ptr->blow[j]);
4989 /* Stop when done */
4990 if (!b_ptr->method) break;
4992 /* Write the blows */
4993 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4994 r_info_blow_effect[b_ptr->effect],
4995 b_ptr->d_dice, b_ptr->d_side);
4998 /* Extract the flags */
4999 for (fc = 0, j = 0; j < 32 * 3; j++)
5001 /* Check this flag */
5002 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5005 /* Extract the extra flags */
5006 for (j = 32 * 6; j < 32 * 10; j++)
5008 /* Check this flag */
5009 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5012 /* Write the flags */
5013 for (j = 0; j < fc;)
5017 /* Start the line */
5020 for (bc = 0; (bc < 60) && (j < fc); j++)
5024 /* Format the flag */
5025 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
5027 /* Add it to the buffer */
5030 /* Note the length */
5034 /* Done with this line; write it */
5035 fprintf(fff, "%s\n", buf);
5038 /* Write Spells if applicable */
5039 if (r_ptr->freq_spell)
5041 /* Write the frequency */
5042 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
5044 /* Extract the spell flags */
5045 for (fc = 0, j = 96; j < 192; j++)
5047 /* Check this flag */
5048 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5051 /* Write the flags */
5052 for (j = 0; j < fc;)
5056 /* Start the line */
5059 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
5063 /* Format the flag */
5064 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
5068 /* Note the length */
5075 /* Done with this line; write it */
5076 fprintf(fff, "%s\n", buf);
5080 /* Acquire the description */
5081 desc = r_text + r_ptr->text;
5082 dlen = strlen(desc);
5084 /* Write Description */
5085 for (j = 0; j < dlen;)
5089 /* Start the line */
5092 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
5100 /* Done with this line; write it */
5101 fprintf(fff, "%s\n", buf);
5104 /* Space between entries */