5 #include "dungeon-file.h"
11 #include "player-skill.h"
17 dungeon_grid letter[255];
21 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
25 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
26 * This software may be copied and distributed for educational, research,
27 * and not for profit purposes provided that this copyright and statement
28 * are included in all such copies. Other copyrights may also apply.
29 * 2014 Deskull rearranged comment for Doxygen.\n
33 * This file is used to initialize various variables and arrays for the
34 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
35 * the common limitation of "read()" and "write()" to only 32767 bytes
37 * Several of the arrays for Angband are built from "template" files in
38 * the "lib/file" directory, from which quick-load binary "image" files
39 * are constructed whenever they are not present in the "lib/data"
40 * directory, or if those files become obsolete, if we are allowed.
41 * Warning -- the "ascii" file parsers use a minor hack to collect the
42 * name and text information in a single pass. Thus, the game will not
43 * be able to load any template file with more than 20K of names or 60K
44 * of text, even though technically, up to 64K should be legal.
46 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
47 * in this file is compiled out, and the game will not run unless valid
48 * "binary template files" already exist in "lib/data". Thus, one can
49 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
50 * "*.raw" files in "lib/data", and then quit, and recompile without
51 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
52 * from changing the ascii template files in potentially dangerous ways.
53 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
54 * このファイルのコードの多くはコンパイル出力され、本ゲームは
55 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
56 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
57 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
58 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
59 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
60 * テンプレートファイルを変更することを妨げることができる。
61 * The code could actually be removed and placed into a "stand-alone"
62 * program, but that feels a little silly, especially considering some
63 * of the platforms that we currently support.
68 #include "dungeon-file.h"
73 #include "cmd-activate.h"
77 #include "view-mainwindow.h"
81 #ifdef ALLOW_TEMPLATES
86 /*** Helper arrays for parsing ascii template files ***/
90 * Monster Blow Methods
92 static concptr r_info_blow_method[] =
125 * モンスターの打撃属性トークンの定義 /
126 * Monster Blow Effects
128 static concptr r_info_blow_effect[] =
173 static concptr f_info_flags[] =
298 static concptr r_info_flags1[] =
338 static concptr r_info_flags2[] =
378 static concptr r_info_flags3[] =
418 static concptr r_info_flags4[] =
455 * モンスター特性トークン(発動型能力1) /
458 static concptr r_a_ability_flags1[] =
495 * モンスター特性トークン(発動型能力2) /
498 static concptr r_a_ability_flags2[] =
515 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
536 * モンスター特性トークン(発動型能力3) /
539 static concptr r_a_ability_flags3[] =
578 * モンスター特性トークン(発動型能力4) /
581 static concptr r_a_ability_flags4[] =
623 static concptr r_info_flags7[] =
663 static concptr r_info_flags8[] =
695 "WILD_SWAMP", /* ToDo: Implement Swamp */
704 static concptr r_info_flags9[] =
743 * モンスター特性トークンの定義R(耐性) /
746 static concptr r_info_flagsr[] =
784 * オブジェクト基本特性トークンの定義 /
787 static concptr k_info_flags[] =
884 "XXX3", /* Fake flag for Smith */
885 "XXX4", /* Fake flag for Smith */
935 * オブジェクト生成特性トークンの定義 /
938 static concptr k_info_gen_flags[] =
978 static concptr d_info_flags1[] =
1016 * @brief データの可変文字列情報をテキストとして保管する /
1017 * Add a text to the text-storage and store offset to it.
1018 * @param offset 文字列保管ポインタからのオフセット
1019 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1021 * @param normal_text テキストの正規化を行う
1024 * Returns FALSE when there isn't enough space available to store
1027 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
1029 /* Hack -- Verify space */
1030 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1036 /* Advance and save the text index */
1037 *offset = ++head->text_size;
1040 /* Additional text */
1041 else if (normal_text)
1044 * If neither the end of the last line nor
1045 * the beginning of current line is not a space,
1046 * fill up a space as a correct separator of two words.
1048 if (head->text_size > 0 &&
1050 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1051 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1052 (buf[0] != ' ') && !iskanji(buf[0])
1054 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1059 /* Append a space */
1060 *(head->text_ptr + head->text_size) = ' ';
1062 /* Advance the index */
1067 /* Append chars to the text */
1068 strcpy(head->text_ptr + head->text_size, buf);
1070 /* Advance the index */
1071 head->text_size += strlen(buf);
1079 * @brief データの可変文字列情報を名前として保管する /
1080 * Add a name to the name-storage and return an offset to it.
1081 * @param offset 文字列保管ポインタからのオフセット
1082 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1086 * Returns FALSE when there isn't enough space available to store
1089 static bool add_name(u32b *offset, header *head, concptr buf)
1091 /* Hack -- Verify space */
1092 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1098 /* Advance and save the name index */
1099 *offset = ++head->name_size;
1102 /* Append chars to the names */
1103 strcpy(head->name_ptr + head->name_size, buf);
1105 /* Advance the index */
1106 head->name_size += strlen(buf);
1114 * @brief データの可変文字列情報をタグとして保管する /
1115 * Add a tag to the tag-storage and return an offset to it.
1116 * @param offset 文字列保管ポインタからのオフセット
1117 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1121 * Returns FALSE when there isn't enough space available to store
1124 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1128 /* Search for an existing (fake) tag */
1129 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1132 if (streq(&head->tag_ptr[i], buf)) break;
1135 /* There was no existing tag */
1136 if (i >= head->tag_size)
1138 /* Hack -- Verify space */
1139 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1142 /* Append chars to the tags */
1143 strcpy(head->tag_ptr + head->tag_size, buf);
1145 /* Point the new tag */
1148 /* Advance the index */
1149 head->tag_size += strlen(buf) + 1;
1152 /* Return offset of the tag */
1160 /*** Initialize from ascii template files ***/
1164 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1165 * Initialize an "*_info" array, by parsing an ascii "template" file
1166 * @param fp 読み取りに使うファイルポインタ
1167 * @param buf 読み取りに使うバッファ領域
1168 * @param head ヘッダ構造体
1169 * @param parse_info_txt_line パース関数
1172 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1176 /* Just before the first record */
1179 /* Just before the first line */
1183 /* Prepare the "fake" stuff */
1184 head->name_size = 0;
1185 head->text_size = 0;
1189 while (0 == my_fgets(fp, buf, 1024))
1191 /* Advance the line number */
1194 /* Skip comments and blank lines */
1195 if (!buf[0] || (buf[0] == '#')) continue;
1197 /* Verify correct "colon" format */
1198 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1201 /* Hack -- Process 'V' for "Version" */
1208 /* Mega Hack -- Calculate Check Sum */
1209 if (buf[0] != 'N' && buf[0] != 'D')
1212 for (i = 0; buf[i]; i++)
1214 head->v_extra += (byte)buf[i];
1215 head->v_extra ^= (1 << (i % 8));
1219 /* Parse the line */
1220 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1225 /* Complete the "name" and "text" sizes */
1226 if (head->name_size) head->name_size++;
1227 if (head->text_size) head->text_size++;
1235 * @brief Vault情報(v_info)のパース関数 /
1236 * Initialize the "v_info" array, by parsing an ascii "template" file
1238 * @param head ヘッダ構造体
1241 errr parse_v_info(char *buf, header *head)
1247 static vault_type *v_ptr = NULL;
1249 /* Process 'N' for "New/Number/Name" */
1252 /* Find the colon before the name */
1253 s = my_strchr(buf + 2, ':');
1255 /* Verify that colon */
1258 /* Nuke the colon, advance to the name */
1261 /* Paranoia -- require a name */
1262 if (!*s) return (1);
1267 /* Verify information */
1268 if (i <= error_idx) return (4);
1270 /* Verify information */
1271 if (i >= head->info_num) return (2);
1273 /* Save the index */
1276 /* Point at the "info" */
1279 /* Store the name */
1280 if (!add_name(&v_ptr->name, head, s)) return (7);
1283 /* There better be a current v_ptr */
1284 else if (!v_ptr) return (3);
1286 /* Process 'D' for "Description" */
1287 else if (buf[0] == 'D')
1289 /* Acquire the text */
1292 /* Store the text */
1293 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1296 /* Process 'X' for "Extra info" (one line only) */
1297 else if (buf[0] == 'X')
1299 EFFECT_ID typ, rat, hgt, wid;
1301 /* Scan for the values */
1302 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1303 &typ, &rat, &hgt, &wid)) return (1);
1305 /* Save the values */
1306 v_ptr->typ = (ROOM_IDX)typ;
1307 v_ptr->rat = (PROB)rat;
1308 v_ptr->hgt = (POSITION)hgt;
1309 v_ptr->wid = (POSITION)wid;
1320 * @brief 職業技能情報(s_info)のパース関数 /
1321 * Initialize the "s_info" array, by parsing an ascii "template" file
1323 * @param head ヘッダ構造体
1326 errr parse_s_info(char *buf, header *head)
1331 static skill_table *s_ptr = NULL;
1334 /* Process 'N' for "New/Number/Name" */
1340 /* Verify information */
1341 if (i <= error_idx) return (4);
1343 /* Verify information */
1344 if (i >= head->info_num) return (2);
1346 /* Save the index */
1349 /* Point at the "info" */
1353 /* There better be a current s_ptr */
1354 else if (!s_ptr) return (3);
1356 /* Process 'W' for "Weapon exp" */
1357 else if (buf[0] == 'W')
1359 int tval, sval, start, max;
1360 const s16b exp_conv_table[] =
1362 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1363 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1366 /* Scan for the values */
1367 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1368 &tval, &sval, &start, &max)) return (1);
1370 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1371 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1373 /* Save the values */
1374 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1375 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1378 /* Process 'S' for "Skill exp" */
1379 else if (buf[0] == 'S')
1381 int num, start, max;
1383 /* Scan for the values */
1384 if (3 != sscanf(buf + 2, "%d:%d:%d",
1385 &num, &start, &max)) return (1);
1387 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1388 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1390 /* Save the values */
1391 s_ptr->s_start[num] = (SUB_EXP)start;
1392 s_ptr->s_max[num] = (SUB_EXP)max;
1404 * @brief 職業魔法情報(m_info)のパース関数 /
1405 * Initialize the "m_info" array, by parsing an ascii "template" file
1407 * @param head ヘッダ構造体
1410 errr parse_m_info(char *buf, header *head)
1417 static player_magic *m_ptr = NULL;
1420 static int realm, magic_idx = 0, readable = 0;
1423 /* Process 'N' for "New/Number/Name" */
1429 /* Verify information */
1430 if (i <= error_idx) return (4);
1432 /* Verify information */
1433 if (i >= head->info_num) return (2);
1435 /* Save the index */
1438 /* Point at the "info" */
1442 /* There better be a current m_ptr */
1443 else if (!m_ptr) return (3);
1445 /* Process 'I' for "Info" (one line only) */
1446 else if (buf[0] == 'I')
1449 int xtra, type, first, weight;
1451 /* Find the colon before the name */
1452 s = my_strchr(buf + 2, ':');
1454 /* Verify that colon */
1457 /* Nuke the colon, advance to the name */
1462 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1463 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1464 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1465 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1466 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1471 /* Find the colon before the name */
1472 s = my_strchr(s, ':');
1474 /* Verify that colon */
1477 /* Nuke the colon, advance to the name */
1480 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1481 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1482 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1483 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1484 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1485 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1489 /* Scan for the values */
1490 if (4 != sscanf(s, "%x:%d:%d:%d",
1491 (uint *)&xtra, &type, &first, &weight)) return (1);
1493 m_ptr->spell_xtra = xtra;
1494 m_ptr->spell_type = type;
1495 m_ptr->spell_first = first;
1496 m_ptr->spell_weight = weight;
1500 /* Process 'R' for "Realm" (one line only) */
1501 else if (buf[0] == 'R')
1503 /* Scan for the values */
1504 if (2 != sscanf(buf + 2, "%d:%d",
1505 &realm, &readable)) return (1);
1510 else if (buf[0] == 'T')
1512 int level, mana, fail, exp;
1514 if (!readable) return (1);
1515 /* Scan for the values */
1516 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1517 &level, &mana, &fail, &exp)) return (1);
1519 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1520 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1521 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1522 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1535 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1536 * Grab one flag from a textual string
1537 * @param flags ビットフラグを追加する先の参照ポインタ
1538 * @param names トークン定義配列
1539 * @param what 参照元の文字列ポインタ
1542 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1547 for (i = 0; i < 32; i++)
1549 if (streq(what, names[i]))
1551 *flags |= (1L << i);
1561 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1562 * Grab one flag in an feature_type from a textual string
1563 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1564 * @param what 参照元の文字列ポインタ
1567 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1572 for (i = 0; i < FF_FLAG_MAX; i++)
1574 if (streq(what, f_info_flags[i]))
1576 add_flag(f_ptr->flags, i);
1581 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1584 return PARSE_ERROR_GENERIC;
1589 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1590 * Grab an action in an feature_type from a textual string
1591 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1592 * @param what 参照元の文字列ポインタ
1593 * @param count ステートの保存先ID
1596 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1601 for (i = 0; i < FF_FLAG_MAX; i++)
1603 if (streq(what, f_info_flags[i]))
1605 f_ptr->state[count].action = i;
1610 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1613 return PARSE_ERROR_GENERIC;
1618 * @brief 地形情報(f_info)のパース関数 /
1619 * Initialize the "f_info" array, by parsing an ascii "template" file
1621 * @param head ヘッダ構造体
1624 errr parse_f_info(char *buf, header *head)
1631 static feature_type *f_ptr = NULL;
1634 /* Process 'N' for "New/Number/Name" */
1637 /* Find the colon before the name */
1638 s = my_strchr(buf + 2, ':');
1642 /* Nuke the colon, advance to the name */
1649 /* Verify information */
1650 if (i <= error_idx) return (4);
1652 /* Verify information */
1653 if (i >= head->info_num) return (2);
1655 /* Save the index */
1658 /* Point at the "info" */
1661 /* Tag name is given */
1665 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1668 /* Default "mimic" */
1669 f_ptr->mimic = (FEAT_IDX)i;
1671 /* Default "destroyed state" -- if not specified */
1672 f_ptr->destroyed = (FEAT_IDX)i;
1674 /* Default "states" */
1675 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1678 /* There better be a current f_ptr */
1679 else if (!f_ptr) return (3);
1682 else if (buf[0] == 'J')
1684 /* Store the name */
1685 if (!add_name(&f_ptr->name, head, buf + 2)) return (7);
1688 else if (buf[0] == 'E')
1690 /* Ignore english name */
1693 else if (buf[0] == 'J')
1695 /* Ignore Japanese name */
1698 else if (buf[0] == 'E')
1700 /* Acquire the Text */
1703 /* Store the name */
1704 if (!add_name(&f_ptr->name, head, s)) return (7);
1709 /* Process 'M' for "Mimic" (one line only) */
1710 else if (buf[0] == 'M')
1714 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1716 /* Record a fake tag index */
1717 f_ptr->mimic_tag = offset;
1721 /* Process 'G' for "Graphics" (one line only) */
1722 else if (buf[0] == 'G')
1726 char char_tmp[F_LIT_MAX];
1727 if (buf[1] != ':') return (1);
1728 if (!buf[2]) return (1);
1729 if (buf[3] != ':') return (1);
1730 if (!buf[4]) return (1);
1732 /* Extract the char */
1733 char_tmp[F_LIT_STANDARD] = buf[2];
1735 /* Extract the color */
1736 s_attr = color_char_to_attr(buf[4]);
1737 if (s_attr > 127) return (1);
1739 /* Save the standard values */
1740 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1741 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1743 /* Is this feature supports lighting? */
1746 /* G:c:a:LIT (default) */
1747 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1749 /* G:c:a:lc:la:dc:da */
1750 if (!streq(buf + 6, "LIT"))
1752 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1754 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1755 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1756 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1757 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1759 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1761 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1764 /* Use default lighting */
1767 /* No lighting support */
1768 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1771 /* Extract the color */
1772 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1773 if (f_ptr->d_attr[j] > 127) return 1;
1776 f_ptr->d_char[j] = char_tmp[j];
1782 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1784 f_ptr->d_attr[j] = s_attr;
1785 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1791 /* Hack -- Process 'F' for flags */
1792 else if (buf[0] == 'F')
1794 /* Parse every entry textually */
1795 for (s = buf + 2; *s; )
1797 /* Find the end of this entry */
1798 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1800 /* Nuke and skip any dividers */
1804 while (*t == ' ' || *t == '|') t++;
1807 /* Hack -- Read feature subtype */
1808 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1810 /* Extract a "subtype" */
1811 f_ptr->subtype = (FEAT_SUBTYPE)i;
1813 /* Start at next entry */
1819 /* Hack -- Read feature power */
1820 if (1 == sscanf(s, "POWER_%d", &i))
1822 /* Extract a "power" */
1823 f_ptr->power = (FEAT_POWER)i;
1825 /* Start at next entry */
1830 /* Parse this entry */
1831 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1833 /* Start the next entry */
1838 /* Process 'W' for "More Info" (one line only) */
1839 else if (buf[0] == 'W')
1843 /* Scan for the value */
1844 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1846 /* Save the value */
1847 f_ptr->priority = (FEAT_PRIORITY)priority;
1850 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1851 else if (buf[0] == 'K')
1855 /* Find the next empty state slot (if any) */
1856 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1858 /* Oops, no more slots */
1859 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1861 /* Analyze the first field */
1862 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1864 /* Terminate the field (if necessary) */
1865 if (*t == ':') *t++ = '\0';
1867 /* Is this default entry? */
1868 if (streq(s, "DESTROYED"))
1870 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1872 /* Record a fake tag index */
1873 f_ptr->destroyed_tag = offset;
1878 f_ptr->state[i].action = 0;
1880 /* Parse this entry */
1881 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1883 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1885 /* Record a fake tag index */
1886 f_ptr->state[i].result_tag = offset;
1898 * @brief 地形タグからIDを得る /
1899 * Convert a fake tag to a real feat index
1903 s16b f_tag_to_index(concptr str)
1907 /* Search for real index corresponding to this fake tag */
1908 for (i = 0; i < f_head.info_num; i++)
1910 if (streq(f_tag + f_info[i].tag, str))
1912 /* Return the index */
1923 * @brief 地形タグからIDを得る /
1924 * Search for real index corresponding to this fake tag
1925 * @param feat タグ文字列のオフセット
1926 * @return 地形ID。該当がないなら-1
1928 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1932 /* Don't convert non-fake tag */
1938 /* Search for real index corresponding to this fake tag */
1939 for (i = 0; i < f_head.info_num; i++)
1941 if (feat == f_info[i].tag)
1943 /* Record real index */
1949 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1955 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1956 * Retouch fake tags of f_info
1957 * @param head ヘッダ構造体
1960 void retouch_f_info(header *head)
1964 /* Convert fake tags to real feat indices */
1965 for (i = 0; i < head->info_num; i++)
1967 feature_type *f_ptr = &f_info[i];
1970 k = search_real_feat(f_ptr->mimic_tag);
1971 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1972 k = search_real_feat(f_ptr->destroyed_tag);
1973 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1974 for (j = 0; j < MAX_FEAT_STATES; j++)
1976 k = search_real_feat(f_ptr->state[j].result_tag);
1977 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1984 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1985 * Grab one flag in an object_kind from a textual string
1986 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1987 * @param what 参照元の文字列ポインタ
1990 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1995 for (i = 0; i < TR_FLAG_MAX; i++)
1997 if (streq(what, k_info_flags[i]))
1999 add_flag(k_ptr->flags, i);
2004 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2007 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2014 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2015 * Grab one activation index flag
2016 * @param what 参照元の文字列ポインタ
2019 static byte grab_one_activation_flag(concptr what)
2025 if (activation_info[i].flag == NULL) break;
2027 if (streq(what, activation_info[i].flag))
2029 return activation_info[i].index;
2039 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2047 * @brief ベースアイテム(k_info)のパース関数 /
2048 * Initialize the "k_info" array, by parsing an ascii "template" file
2050 * @param head ヘッダ構造体
2053 errr parse_k_info(char *buf, header *head)
2060 static object_kind *k_ptr = NULL;
2063 /* Process 'N' for "New/Number/Name" */
2070 /* Find the colon before the name */
2071 s = my_strchr(buf + 2, ':');
2073 /* Verify that colon */
2076 /* Nuke the colon, advance to the name */
2082 /* Verify information */
2083 if (i <= error_idx) return (4);
2085 /* Verify information */
2086 if (i >= head->info_num) return (2);
2088 /* Save the index */
2091 /* Point at the "info" */
2095 /* Paranoia -- require a name */
2096 if (!*s) return (1);
2098 /* Find the colon before the flavor */
2099 flavor = my_strchr(s, ':');
2101 /* Verify that colon */
2104 /* Nuke the colon, advance to the flavor */
2107 /* Store the flavor */
2108 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2111 /* Store the name */
2112 if (!add_name(&k_ptr->name, head, s)) return (7);
2116 /* There better be a current k_ptr */
2117 else if (!k_ptr) return (3);
2122 /* 'E' から始まる行は英語名としている */
2123 else if (buf[0] == 'E')
2128 else if (buf[0] == 'E')
2132 /* Acquire the name */
2135 /* Find the colon before the flavor */
2136 flavor = my_strchr(s, ':');
2138 /* Verify that colon */
2141 /* Nuke the colon, advance to the flavor */
2144 /* Store the flavor */
2145 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2148 /* Store the name */
2149 if (!add_name(&k_ptr->name, head, s)) return (7);
2153 /* Process 'D' for "Description" */
2154 else if (buf[0] == 'D')
2159 /* Acquire the text */
2164 /* Acquire the text */
2168 /* Store the text */
2169 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2172 /* Process 'G' for "Graphics" (one line only) */
2173 else if (buf[0] == 'G')
2177 if (buf[1] != ':') return (1);
2178 if (!buf[2]) return (1);
2179 if (buf[3] != ':') return (1);
2180 if (!buf[4]) return (1);
2182 /* Extract the char */
2185 /* Extract the attr */
2186 tmp = color_char_to_attr(buf[4]);
2187 if (tmp > 127) return (1);
2189 /* Save the values */
2190 k_ptr->d_attr = tmp;
2191 k_ptr->d_char = sym;
2194 /* Process 'I' for "Info" (one line only) */
2195 else if (buf[0] == 'I')
2197 int tval, sval, pval;
2199 /* Scan for the values */
2200 if (3 != sscanf(buf + 2, "%d:%d:%d",
2201 &tval, &sval, &pval)) return (1);
2203 /* Save the values */
2204 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2205 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2206 k_ptr->pval = (PARAMETER_VALUE)pval;
2209 /* Process 'W' for "More Info" (one line only) */
2210 else if (buf[0] == 'W')
2212 int level, extra, wgt;
2215 /* Scan for the values */
2216 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2217 &level, &extra, &wgt, &cost)) return (1);
2219 /* Save the values */
2220 k_ptr->level = (DEPTH)level;
2221 k_ptr->extra = (BIT_FLAGS8)extra;
2222 k_ptr->weight = (WEIGHT)wgt;
2223 k_ptr->cost = (PRICE)cost;
2226 /* Process 'A' for "Allocation" (one line only) */
2227 else if (buf[0] == 'A')
2230 /* Simply read each number following a colon */
2231 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2233 /* Default chance */
2234 k_ptr->chance[i] = 1;
2236 /* Store the attack damage index */
2237 k_ptr->locale[i] = atoi(s + 1);
2239 /* Find the slash */
2240 t = my_strchr(s + 1, '/');
2242 /* Find the next colon */
2243 s = my_strchr(s + 1, ':');
2245 /* If the slash is "nearby", use it */
2246 if (t && (!s || t < s))
2248 int chance = atoi(t + 1);
2249 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2254 /* Hack -- Process 'P' for "power" and such */
2255 else if (buf[0] == 'P')
2257 int ac, hd1, hd2, th, td, ta;
2259 /* Scan for the values */
2260 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2261 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2263 k_ptr->ac = (ARMOUR_CLASS)ac;
2264 k_ptr->dd = (DICE_NUMBER)hd1;
2265 k_ptr->ds = (DICE_SID)hd2;
2266 k_ptr->to_h = (HIT_PROB)th;
2267 k_ptr->to_d = (HIT_POINT)td;
2268 k_ptr->to_a = (ARMOUR_CLASS)ta;
2271 /* Hack -- Process 'U' for activation index */
2272 else if (buf[0] == 'U')
2275 n = grab_one_activation_flag(buf + 2);
2286 /* Hack -- Process 'F' for flags */
2287 else if (buf[0] == 'F')
2289 /* Parse every entry textually */
2290 for (s = buf + 2; *s; )
2292 /* Find the end of this entry */
2293 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2295 /* Nuke and skip any dividers */
2299 while (*t == ' ' || *t == '|') t++;
2302 /* Parse this entry */
2303 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2305 /* Start the next entry */
2319 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2320 * Grab one activation index flag
2321 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2322 * @param what 参照元の文字列ポインタ
2323 * @return エラーがあった場合1、エラーがない場合0を返す
2325 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2330 for (i = 0; i < TR_FLAG_MAX; i++)
2332 if (streq(what, k_info_flags[i]))
2334 add_flag(a_ptr->flags, i);
2339 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2342 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2350 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2351 * Initialize the "a_info" array, by parsing an ascii "template" file
2353 * @param head ヘッダ構造体
2356 errr parse_a_info(char *buf, header *head)
2363 static artifact_type *a_ptr = NULL;
2366 /* Process 'N' for "New/Number/Name" */
2369 /* Find the colon before the name */
2370 s = my_strchr(buf + 2, ':');
2372 /* Verify that colon */
2375 /* Nuke the colon, advance to the name */
2378 /* Paranoia -- require a name */
2379 if (!*s) return (1);
2384 /* Verify information */
2385 if (i < error_idx) return (4);
2387 /* Verify information */
2388 if (i >= head->info_num) return (2);
2390 /* Save the index */
2393 /* Point at the "info" */
2396 /* Ignore everything */
2397 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2398 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2399 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2400 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2402 /* Store the name */
2403 if (!add_name(&a_ptr->name, head, s)) return (7);
2407 /* There better be a current a_ptr */
2408 else if (!a_ptr) return (3);
2413 /* 'E' から始まる行は英語名としている */
2414 else if (buf[0] == 'E')
2419 else if (buf[0] == 'E')
2421 /* Acquire the Text */
2424 /* Store the name */
2425 if (!add_name(&a_ptr->name, head, s)) return (7);
2429 /* Process 'D' for "Description" */
2430 else if (buf[0] == 'D')
2435 /* Acquire the text */
2440 /* Acquire the text */
2444 /* Store the text */
2445 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2449 /* Process 'I' for "Info" (one line only) */
2450 else if (buf[0] == 'I')
2452 int tval, sval, pval;
2454 /* Scan for the values */
2455 if (3 != sscanf(buf + 2, "%d:%d:%d",
2456 &tval, &sval, &pval)) return (1);
2458 /* Save the values */
2459 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2460 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2461 a_ptr->pval = (PARAMETER_VALUE)pval;
2464 /* Process 'W' for "More Info" (one line only) */
2465 else if (buf[0] == 'W')
2467 int level, rarity, wgt;
2470 /* Scan for the values */
2471 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2472 &level, &rarity, &wgt, &cost)) return (1);
2474 /* Save the values */
2475 a_ptr->level = (DEPTH)level;
2476 a_ptr->rarity = (RARITY)rarity;
2477 a_ptr->weight = (WEIGHT)wgt;
2478 a_ptr->cost = (PRICE)cost;
2481 /* Hack -- Process 'P' for "power" and such */
2482 else if (buf[0] == 'P')
2484 int ac, hd1, hd2, th, td, ta;
2486 /* Scan for the values */
2487 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2488 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2490 a_ptr->ac = (ARMOUR_CLASS)ac;
2491 a_ptr->dd = (DICE_NUMBER)hd1;
2492 a_ptr->ds = (DICE_SID)hd2;
2493 a_ptr->to_h = (HIT_PROB)th;
2494 a_ptr->to_d = (HIT_POINT)td;
2495 a_ptr->to_a = (ARMOUR_CLASS)ta;
2498 /* Hack -- Process 'U' for activation index */
2499 else if (buf[0] == 'U')
2502 n = grab_one_activation_flag(buf + 2);
2513 /* Hack -- Process 'F' for flags */
2514 else if (buf[0] == 'F')
2516 /* Parse every entry textually */
2517 for (s = buf + 2; *s; )
2519 /* Find the end of this entry */
2520 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2522 /* Nuke and skip any dividers */
2526 while ((*t == ' ') || (*t == '|')) t++;
2529 /* Parse this entry */
2530 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2532 /* Start the next entry */
2547 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2548 * Grab one flag in a ego-item_type from a textual string
2549 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2550 * @param what 参照元の文字列ポインタ
2551 * @return エラーがあった場合1、エラーがない場合0を返す
2553 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2558 for (i = 0; i < TR_FLAG_MAX; i++)
2560 if (streq(what, k_info_flags[i]))
2562 add_flag(e_ptr->flags, i);
2567 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2570 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2578 * @brief アイテムエゴ情報(e_info)のパース関数 /
2579 * Initialize the "e_info" array, by parsing an ascii "template" file
2581 * @param head ヘッダ構造体
2584 errr parse_e_info(char *buf, header *head)
2590 static ego_item_type *e_ptr = NULL;
2592 /* Just before the first record */
2595 /* Just before the first line */
2598 /* Process 'N' for "New/Number/Name" */
2601 /* Find the colon before the name */
2602 s = my_strchr(buf + 2, ':');
2604 /* Verify that colon */
2607 /* Nuke the colon, advance to the name */
2610 /* Paranoia -- require a name */
2611 if (!*s) return (1);
2616 /* Verify information */
2617 if (i < error_idx) return (4);
2619 /* Verify information */
2620 if (i >= head->info_num) return (2);
2622 /* Save the index */
2625 /* Point at the "info" */
2628 /* Store the name */
2629 if (!add_name(&e_ptr->name, head, s)) return (7);
2633 /* There better be a current e_ptr */
2634 else if (!e_ptr) return (3);
2639 /* 'E' から始まる行は英語名 */
2640 else if (buf[0] == 'E')
2645 else if (buf[0] == 'E')
2647 /* Acquire the Text */
2650 /* Store the name */
2651 if (!add_name(&e_ptr->name, head, s)) return (7);
2656 /* Process 'D' for "Description" */
2657 else if (buf[0] == 'D')
2659 /* Acquire the text */
2662 /* Store the text */
2663 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2668 /* Process 'X' for "Xtra" (one line only) */
2669 else if (buf[0] == 'X')
2673 /* Scan for the values */
2674 if (2 != sscanf(buf + 2, "%d:%d",
2675 &slot, &rating)) return (1);
2677 /* Save the values */
2678 e_ptr->slot = (INVENTORY_IDX)slot;
2679 e_ptr->rating = (PRICE)rating;
2682 /* Process 'W' for "More Info" (one line only) */
2683 else if (buf[0] == 'W')
2685 int level, rarity, pad2;
2688 /* Scan for the values */
2689 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2690 &level, &rarity, &pad2, &cost)) return (1);
2692 /* Save the values */
2693 e_ptr->level = level;
2694 e_ptr->rarity = (RARITY)rarity;
2695 /* e_ptr->weight = wgt; */
2699 /* Hack -- Process 'C' for "creation" */
2700 else if (buf[0] == 'C')
2702 int th, td, ta, pval;
2704 /* Scan for the values */
2705 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2706 &th, &td, &ta, &pval)) return (1);
2708 e_ptr->max_to_h = (HIT_PROB)th;
2709 e_ptr->max_to_d = (HIT_POINT)td;
2710 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2711 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2714 /* Hack -- Process 'U' for activation index */
2715 else if (buf[0] == 'U')
2718 n = grab_one_activation_flag(buf + 2);
2729 /* Hack -- Process 'F' for flags */
2730 else if (buf[0] == 'F')
2732 /* Parse every entry textually */
2733 for (s = buf + 2; *s; )
2735 /* Find the end of this entry */
2736 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2738 /* Nuke and skip any dividers */
2742 while ((*t == ' ') || (*t == '|')) t++;
2745 /* Parse this entry */
2746 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2748 /* Start the next entry */
2761 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2762 * Grab one (basic) flag in a monster_race from a textual string
2763 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2764 * @param what 参照元の文字列ポインタ
2767 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2769 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2772 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2775 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2778 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2781 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2784 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2787 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2790 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2798 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2799 * Grab one (spell) flag in a monster_race from a textual string
2800 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2801 * @param what 参照元の文字列ポインタ
2804 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2806 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2809 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2812 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2815 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2823 * @brief モンスター種族情報(r_info)のパース関数 /
2824 * Initialize the "r_info" array, by parsing an ascii "template" file
2826 * @param head ヘッダ構造体
2829 errr parse_r_info(char *buf, header *head)
2835 static monster_race *r_ptr = NULL;
2838 /* Process 'N' for "New/Number/Name" */
2841 /* Find the colon before the name */
2842 s = my_strchr(buf + 2, ':');
2844 /* Verify that colon */
2847 /* Nuke the colon, advance to the name */
2850 /* Paranoia -- require a name */
2851 if (!*s) return (1);
2856 /* Verify information */
2857 if (i < error_idx) return (4);
2859 /* Verify information */
2860 if (i >= head->info_num) return (2);
2862 /* Save the index */
2865 /* Point at the "info" */
2868 /* Store the name */
2869 if (!add_name(&r_ptr->name, head, s)) return (7);
2873 /* There better be a current r_ptr */
2874 else if (!r_ptr) return (3);
2879 /* 'E' から始まる行は英語名 */
2880 else if (buf[0] == 'E')
2882 /* Acquire the Text */
2885 /* Store the name */
2886 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2889 else if (buf[0] == 'E')
2891 /* Acquire the Text */
2894 /* Store the name */
2895 if (!add_name(&r_ptr->name, head, s)) return (7);
2898 /* Process 'D' for "Description" */
2899 else if (buf[0] == 'D')
2904 /* Acquire the text */
2909 /* Acquire the text */
2913 /* Store the text */
2914 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2917 /* Process 'G' for "Graphics" (one line only) */
2918 else if (buf[0] == 'G')
2922 if (buf[1] != ':') return (1);
2923 if (!buf[2]) return (1);
2924 if (buf[3] != ':') return (1);
2925 if (!buf[4]) return (1);
2927 /* Extract the char */
2930 /* Extract the attr */
2931 tmp = color_char_to_attr(buf[4]);
2932 if (tmp > 127) return (1);
2934 /* Save the values */
2935 r_ptr->d_char = sym;
2936 r_ptr->d_attr = tmp;
2939 /* Process 'I' for "Info" (one line only) */
2940 else if (buf[0] == 'I')
2942 int spd, hp1, hp2, aaf, ac, slp;
2944 /* Scan for the other values */
2945 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2946 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2948 /* Save the values */
2949 r_ptr->speed = (SPEED)spd;
2950 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2951 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2952 r_ptr->aaf = (POSITION)aaf;
2953 r_ptr->ac = (ARMOUR_CLASS)ac;
2954 r_ptr->sleep = (SLEEP_DEGREE)slp;
2957 /* Process 'W' for "More Info" (one line only) */
2958 else if (buf[0] == 'W')
2965 /* Scan for the values */
2966 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2967 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2969 /* Save the values */
2970 r_ptr->level = (DEPTH)lev;
2971 r_ptr->rarity = (RARITY)rar;
2972 r_ptr->extra = (BIT_FLAGS16)pad;
2973 r_ptr->mexp = (EXP)exp;
2974 r_ptr->next_exp = (EXP)nextexp;
2975 r_ptr->next_r_idx = (IDX)nextmon;
2978 /* Process 'R' for "Reinforcement" (up to six lines) */
2979 else if (buf[0] == 'R')
2982 /* Find the next empty blow slot (if any) */
2983 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2985 /* Oops, no more slots */
2986 if (i == 6) return (1);
2988 /* Scan for the values */
2989 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2990 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2991 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2992 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2995 /* Process 'B' for "Blows" (up to four lines) */
2996 else if (buf[0] == 'B')
3000 /* Find the next empty blow slot (if any) */
3001 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3003 /* Oops, no more slots */
3004 if (i == 4) return (1);
3006 /* Analyze the first field */
3007 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
3009 /* Terminate the field (if necessary) */
3010 if (*t == ':') *t++ = '\0';
3012 /* Analyze the method */
3013 for (n1 = 0; r_info_blow_method[n1]; n1++)
3015 if (streq(s, r_info_blow_method[n1])) break;
3018 /* Invalid method */
3019 if (!r_info_blow_method[n1]) return (1);
3021 /* Analyze the second field */
3022 for (s = t; *t && (*t != ':'); t++) /* loop */;
3024 /* Terminate the field (if necessary) */
3025 if (*t == ':') *t++ = '\0';
3027 /* Analyze effect */
3028 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3030 if (streq(s, r_info_blow_effect[n2])) break;
3033 /* Invalid effect */
3034 if (!r_info_blow_effect[n2]) return (1);
3036 /* Analyze the third field */
3037 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3039 /* Terminate the field (if necessary) */
3040 if (*t == 'd') *t++ = '\0';
3042 /* Save the method */
3043 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3045 /* Save the effect */
3046 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3048 /* Extract the damage dice and sides */
3049 r_ptr->blow[i].d_dice = atoi(s);
3050 r_ptr->blow[i].d_side = atoi(t);
3053 /* Process 'F' for "Basic Flags" (multiple lines) */
3054 else if (buf[0] == 'F')
3056 /* Parse every entry */
3057 for (s = buf + 2; *s; )
3059 /* Find the end of this entry */
3060 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3062 /* Nuke and skip any dividers */
3066 while (*t == ' ' || *t == '|') t++;
3069 /* Parse this entry */
3070 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3072 /* Start the next entry */
3077 /* Process 'S' for "Spell Flags" (multiple lines) */
3078 else if (buf[0] == 'S')
3080 /* Parse every entry */
3081 for (s = buf + 2; *s; )
3083 /* Find the end of this entry */
3084 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3086 /* Nuke and skip any dividers */
3090 while ((*t == ' ') || (*t == '|')) t++;
3093 /* Hack -- Read spell frequency */
3094 if (1 == sscanf(s, "1_IN_%d", &i))
3096 /* Extract a "frequency" */
3097 r_ptr->freq_spell = 100 / i;
3099 /* Start at next entry */
3104 /* Parse this entry */
3105 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3107 /* Start the next entry */
3112 /* Process 'A' for "Artifact Flags" (multiple lines) */
3113 else if (buf[0] == 'A')
3115 int id, per, rarity;
3117 /* Find the next empty blow slot (if any) */
3118 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3120 /* Oops, no more slots */
3121 if (i == 4) return (1);
3123 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3124 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3125 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3126 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3129 /* Process 'V' for "Arena power value ratio" */
3130 else if (buf[0] == 'V')
3133 if (3 != sscanf(buf + 2, "%d", &val)) return (1);
3134 r_ptr->arena_ratio = (PERCENTAGE)val;
3146 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3147 * Grab one flag for a dungeon type from a textual string
3148 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3149 * @param what 参照元の文字列ポインタ
3152 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
3154 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3157 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3164 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3165 * Grab one (basic) flag in a monster_race from a textual string
3166 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3167 * @param what 参照元の文字列ポインタ
3170 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3172 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3175 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3178 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3181 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3184 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3187 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3190 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3193 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3200 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3201 * Grab one (spell) flag in a monster_race from a textual string
3202 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3203 * @param what 参照元の文字列ポインタ
3206 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3208 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3211 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3214 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3217 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3224 * @brief ダンジョン情報(d_info)のパース関数 /
3225 * Initialize the "d_info" array, by parsing an ascii "template" file
3227 * @param head ヘッダ構造体
3230 errr parse_d_info(char *buf, header *head)
3236 static dungeon_type *d_ptr = NULL;
3238 /* Process 'N' for "New/Number/Name" */
3241 /* Find the colon before the name */
3242 s = my_strchr(buf + 2, ':');
3244 /* Verify that colon */
3247 /* Nuke the colon, advance to the name */
3250 /* Paranoia -- require a name */
3251 if (!*s) return (1);
3256 /* Verify information */
3257 if (i < error_idx) return (4);
3259 /* Verify information */
3260 if (i >= head->info_num) return (2);
3262 /* Save the index */
3265 /* Point at the "info" */
3268 /* Store the name */
3269 if (!add_name(&d_ptr->name, head, s)) return (7);
3274 else if (buf[0] == 'E') return (0);
3276 else if (buf[0] == 'E')
3278 /* Acquire the Text */
3281 /* Store the name */
3282 if (!add_name(&d_ptr->name, head, s)) return (7);
3286 /* Process 'D' for "Description */
3287 else if (buf[0] == 'D')
3292 /* Acquire the text */
3297 /* Acquire the text */
3301 /* Store the text */
3302 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3305 /* Process 'W' for "More Info" (one line only) */
3306 else if (buf[0] == 'W')
3308 int min_lev, max_lev;
3310 int min_alloc, max_chance;
3311 int obj_good, obj_great;
3314 /* Scan for the values */
3315 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3316 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3318 /* Save the values */
3319 d_ptr->mindepth = (DEPTH)min_lev;
3320 d_ptr->maxdepth = (DEPTH)max_lev;
3321 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3322 d_ptr->mode = (BIT_FLAGS8)mode;
3323 d_ptr->min_m_alloc_level = min_alloc;
3324 d_ptr->max_m_alloc_chance = max_chance;
3325 d_ptr->obj_good = obj_good;
3326 d_ptr->obj_great = obj_great;
3327 d_ptr->pit = (BIT_FLAGS16)pit;
3328 d_ptr->nest = (BIT_FLAGS16)nest;
3331 /* Process 'P' for "Place Info" */
3332 else if (buf[0] == 'P')
3336 /* Scan for the values */
3337 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return (1);
3339 /* Save the values */
3344 /* Process 'L' for "fLoor type" (one line only) */
3345 else if (buf[0] == 'L')
3349 /* Scan for the values */
3350 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3352 /* Save the values */
3353 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3355 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3356 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3358 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3360 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3363 /* Process 'A' for "wAll type" (one line only) */
3364 else if (buf[0] == 'A')
3368 /* Scan for the values */
3369 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3371 /* Save the values */
3372 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3374 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3375 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3377 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3380 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3381 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3383 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3384 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3386 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3387 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3389 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3390 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3393 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3394 else if (buf[0] == 'F')
3396 int artif = 0, monst = 0;
3398 /* Parse every entry */
3399 for (s = buf + 2; *s; )
3401 /* Find the end of this entry */
3402 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3404 /* Nuke and skip any dividers */
3408 while (*t == ' ' || *t == '|') t++;
3411 /* Hack -- Read Final Artifact */
3412 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3414 /* Extract a "Final Artifact" */
3415 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3417 /* Start at next entry */
3422 /* Hack -- Read Final Object */
3423 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3425 /* Extract a "Final Artifact" */
3426 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3428 /* Start at next entry */
3433 /* Hack -- Read Artifact Guardian */
3434 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3436 /* Extract a "Artifact Guardian" */
3437 d_ptr->final_guardian = (MONRACE_IDX)monst;
3439 /* Start at next entry */
3444 /* Hack -- Read Special Percentage */
3445 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3447 /* Extract a "Special %" */
3448 d_ptr->special_div = (PROB)monst;
3450 /* Start at next entry */
3455 /* Parse this entry */
3456 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3458 /* Start the next entry */
3463 /* Process 'M' for "Basic Flags" (multiple lines) */
3464 else if (buf[0] == 'M')
3466 /* Parse every entry */
3467 for (s = buf + 2; *s; )
3469 /* Find the end of this entry */
3470 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3472 /* Nuke and skip any dividers */
3476 while (*t == ' ' || *t == '|') t++;
3479 /* Hack -- Read monster symbols */
3480 if (!strncmp(s, "R_CHAR_", 7))
3482 /* Skip "R_CHAR_" */
3486 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3488 /* Start at next entry */
3493 /* Parse this entry */
3494 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3496 /* Start the next entry */
3501 /* Process 'S' for "Spell Flags" (multiple lines) */
3502 else if (buf[0] == 'S')
3504 /* Parse every entry */
3505 for (s = buf + 2; *s; )
3507 /* Find the end of this entry */
3508 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3510 /* Nuke and skip any dividers */
3514 while ((*t == ' ') || (*t == '|')) t++;
3517 /* Hack -- Read spell frequency */
3518 if (1 == sscanf(s, "1_IN_%d", &i))
3520 /* Start at next entry */
3525 /* Parse this entry */
3526 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3528 /* Start the next entry */
3540 #else /* ALLOW_TEMPLATES */
3546 #endif /* ALLOW_TEMPLATES */
3550 * @brief 地形情報の「F:」情報をパースする
3551 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3555 static errr parse_line_feature(char *buf)
3560 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3562 /* Tokenize the line */
3563 if ((num = tokenize(buf + 2, 9, zz, 0)) > 1)
3565 /* Letter to assign */
3566 int index = zz[0][0];
3568 /* Reset the info for the letter */
3569 letter[index].feature = feat_none;
3570 letter[index].monster = 0;
3571 letter[index].object = 0;
3572 letter[index].ego = 0;
3573 letter[index].artifact = 0;
3574 letter[index].trap = feat_none;
3575 letter[index].cave_info = 0;
3576 letter[index].special = 0;
3577 letter[index].random = RANDOM_NONE;
3583 letter[index].special = (s16b)atoi(zz[8]);
3587 if ((zz[7][0] == '*') && !zz[7][1])
3589 letter[index].random |= RANDOM_TRAP;
3593 letter[index].trap = f_tag_to_index(zz[7]);
3594 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3599 if (zz[6][0] == '*')
3601 letter[index].random |= RANDOM_ARTIFACT;
3602 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3604 else if (zz[6][0] == '!')
3606 if (p_ptr->inside_quest)
3608 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3613 letter[index].artifact = (IDX)atoi(zz[6]);
3618 if (zz[5][0] == '*')
3620 letter[index].random |= RANDOM_EGO;
3621 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3625 letter[index].ego = (IDX)atoi(zz[5]);
3630 if (zz[4][0] == '*')
3632 letter[index].random |= RANDOM_OBJECT;
3633 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3635 else if (zz[4][0] == '!')
3637 if (p_ptr->inside_quest)
3639 ARTIFACT_IDX a_idx = quest[p_ptr->inside_quest].k_idx;
3642 artifact_type *a_ptr = &a_info[a_idx];
3643 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3645 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3652 letter[index].object = (IDX)atoi(zz[4]);
3657 if (zz[3][0] == '*')
3659 letter[index].random |= RANDOM_MONSTER;
3660 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3662 else if (zz[3][0] == 'c')
3664 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3665 letter[index].monster = -atoi(zz[3] + 1);
3669 letter[index].monster = (IDX)atoi(zz[3]);
3674 letter[index].cave_info = atoi(zz[2]);
3678 if ((zz[1][0] == '*') && !zz[1][1])
3680 letter[index].random |= RANDOM_FEATURE;
3684 letter[index].feature = f_tag_to_index(zz[1]);
3685 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3698 * @brief 地形情報の「B:」情報をパースする
3699 * Process "B:<Index>:<Command>:..." -- Building definition
3703 static errr parse_line_building(char *buf)
3719 /* Get the building number */
3722 /* Find the colon after the building number */
3723 s = my_strchr(s, ':');
3725 /* Verify that colon */
3728 /* Nuke the colon, advance to the sub-index */
3731 /* Paranoia -- require a sub-index */
3732 if (!*s) return (1);
3734 /* Building definition sub-index */
3737 /* Building name, owner, race */
3740 if (tokenize(s + 2, 3, zz, 0) == 3)
3742 /* Name of the building */
3743 strcpy(building[index].name, zz[0]);
3745 /* Name of the owner */
3746 strcpy(building[index].owner_name, zz[1]);
3748 /* Race of the owner */
3749 strcpy(building[index].owner_race, zz[2]);
3754 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3757 /* Building Action */
3760 if (tokenize(s + 2, 8, zz, 0) >= 7)
3762 /* Index of the action */
3763 int action_index = atoi(zz[0]);
3765 /* Name of the action */
3766 strcpy(building[index].act_names[action_index], zz[1]);
3768 /* Cost of the action for members */
3769 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3771 /* Cost of the action for non-members */
3772 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3774 /* Letter assigned to the action */
3775 building[index].letters[action_index] = zz[4][0];
3778 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3780 /* Action restriction */
3781 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3786 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3789 /* Building Classes */
3793 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3794 for (i = 0; i < MAX_CLASS; i++)
3796 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3801 /* Building Races */
3805 n = tokenize(s + 2, MAX_RACES, zz, 0);
3806 for (i = 0; i < MAX_RACES; i++)
3808 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3813 /* Building Realms */
3817 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3818 for (i = 0; i < MAX_MAGIC; i++)
3820 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3827 /* Ignore scripts */
3833 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3842 * @brief フロアの所定のマスにオブジェクトを配置する
3843 * Place the object j_ptr to a grid
3844 * @param j_ptr オブジェクト構造体の参照ポインタ
3849 static void drop_here(object_type *j_ptr, POSITION y, POSITION x)
3851 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
3854 OBJECT_IDX o_idx = o_pop();
3856 /* Access new object */
3857 o_ptr = ¤t_floor_ptr->o_list[o_idx];
3859 /* Structure copy */
3860 object_copy(o_ptr, j_ptr);
3867 o_ptr->held_m_idx = 0;
3870 o_ptr->next_o_idx = g_ptr->o_idx;
3872 g_ptr->o_idx = o_idx;
3876 * @brief クエスト用固定ダンジョンをフロアに生成する
3877 * Parse a sub-file of the "extra info"
3887 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3892 /* Skip "empty" lines */
3893 if (!buf[0]) return (0);
3895 /* Skip "blank" lines */
3896 if (iswspace(buf[0])) return (0);
3899 if (buf[0] == '#') return (0);
3901 /* Require "?:*" format */
3902 if (buf[1] != ':') return (1);
3905 /* Process "%:<fname>" */
3908 /* Attempt to Process the given file */
3909 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3912 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3915 return parse_line_feature(buf);
3918 /* Process "D:<dungeon>" -- info for the current_floor_ptr->grid_array grids */
3919 else if (buf[0] == 'D')
3921 object_type object_type_body;
3923 /* Acquire the text */
3926 /* Length of the text */
3927 int len = strlen(s);
3929 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3931 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3933 grid_type *g_ptr = ¤t_floor_ptr->grid_array[*y][*x];
3937 OBJECT_IDX object_index = letter[idx].object;
3938 MONSTER_IDX monster_index = letter[idx].monster;
3939 int random = letter[idx].random;
3940 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3942 /* Lay down a floor */
3943 g_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3945 /* Only the features */
3946 if (init_flags & INIT_ONLY_FEATURES) continue;
3949 g_ptr->info = letter[idx].cave_info;
3951 /* Create a monster */
3952 if (random & RANDOM_MONSTER)
3954 current_floor_ptr->monster_level = current_floor_ptr->base_level + monster_index;
3956 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3958 current_floor_ptr->monster_level = current_floor_ptr->base_level;
3960 else if (monster_index)
3962 int old_cur_num, old_max_num;
3965 if (monster_index < 0)
3967 monster_index = -monster_index;
3970 old_cur_num = r_info[monster_index].cur_num;
3971 old_max_num = r_info[monster_index].max_num;
3973 /* Make alive again */
3974 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3976 r_info[monster_index].cur_num = 0;
3977 r_info[monster_index].max_num = 1;
3980 /* Make alive again */
3981 /* Hack -- Non-unique Nazguls are semi-unique */
3982 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3984 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3986 r_info[monster_index].max_num++;
3991 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3995 current_floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3997 /* Make alive again for real unique monster */
3998 r_info[monster_index].cur_num = old_cur_num;
3999 r_info[monster_index].max_num = old_max_num;
4003 /* Object (and possible trap) */
4004 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4006 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4009 * Random trap and random treasure defined
4010 * 25% chance for trap and 75% chance for object
4012 if (randint0(100) < 75)
4014 place_object(*y, *x, 0L);
4021 current_floor_ptr->object_level = current_floor_ptr->base_level;
4023 else if (random & RANDOM_OBJECT)
4025 current_floor_ptr->object_level = current_floor_ptr->base_level + object_index;
4027 /* Create an out of deep object */
4028 if (randint0(100) < 75)
4029 place_object(*y, *x, 0L);
4030 else if (randint0(100) < 80)
4031 place_object(*y, *x, AM_GOOD);
4033 place_object(*y, *x, AM_GOOD | AM_GREAT);
4035 current_floor_ptr->object_level = current_floor_ptr->base_level;
4038 else if (random & RANDOM_TRAP)
4042 /* Hidden trap (or door) */
4043 else if (letter[idx].trap)
4045 g_ptr->mimic = g_ptr->feat;
4046 g_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4048 else if (object_index)
4050 object_type *o_ptr = &object_type_body;
4051 object_prep(o_ptr, object_index);
4053 if (o_ptr->tval == TV_GOLD)
4055 coin_type = object_index - OBJ_GOLD_LIST;
4060 /* Apply magic (no messages, no artifacts) */
4061 apply_magic(o_ptr, current_floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
4063 drop_here(o_ptr, *y, *x);
4069 if (a_info[artifact_index].cur_num)
4071 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4073 object_type *q_ptr = &forge;
4075 object_prep(q_ptr, k_idx);
4076 drop_here(q_ptr, *y, *x);
4080 if (create_named_art(artifact_index, *y, *x))
4081 a_info[artifact_index].cur_num = 1;
4085 /* Terrain special */
4086 g_ptr->special = letter[idx].special;
4094 /* Process "Q:<number>:<command>:... -- quest info */
4095 else if (buf[0] == 'Q')
4102 num = tokenize(buf + 2, 33, zz, 0);
4106 num = tokenize(buf + 3, 33, zz, 0);
4109 /* Have we enough parameters? */
4110 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4113 q_ptr = &(quest[atoi(zz[0])]);
4115 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4116 if (zz[1][0] == 'Q')
4118 if (init_flags & INIT_ASSIGN)
4120 monster_race *r_ptr;
4121 artifact_type *a_ptr;
4123 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4125 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4126 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4127 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4128 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4129 q_ptr->level = (DEPTH)atoi(zz[6]);
4130 q_ptr->r_idx = (IDX)atoi(zz[7]);
4131 q_ptr->k_idx = (IDX)atoi(zz[8]);
4132 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4134 if (num > 10) q_ptr->flags = atoi(zz[10]);
4136 r_ptr = &r_info[q_ptr->r_idx];
4137 if (r_ptr->flags1 & RF1_UNIQUE)
4138 r_ptr->flags1 |= RF1_QUESTOR;
4140 a_ptr = &a_info[q_ptr->k_idx];
4141 a_ptr->gen_flags |= TRG_QUESTITEM;
4146 else if (zz[1][0] == 'R')
4148 if (init_flags & INIT_ASSIGN)
4151 IDX idx, reward_idx = 0;
4153 for (idx = 2; idx < num; idx++)
4155 IDX a_idx = (IDX)atoi(zz[idx]);
4156 if (a_idx < 1) continue;
4157 if (a_info[a_idx].cur_num > 0) continue;
4159 if (one_in_(count)) reward_idx = a_idx;
4164 /* Set quest's rewarding artifact */
4165 q_ptr->k_idx = reward_idx;
4166 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4170 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4171 q_ptr->type = QUEST_TYPE_KILL_ALL;
4178 /* Process "Q:<q_index>:N:<name>" -- quest name */
4179 else if (zz[1][0] == 'N')
4181 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4183 strcpy(q_ptr->name, zz[2]);
4189 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4190 else if (zz[1][0] == 'T')
4192 if (init_flags & INIT_SHOW_TEXT)
4194 strcpy(quest_text[quest_text_line], zz[2]);
4202 /* Process "W:<command>: ..." -- info for the wilderness */
4203 else if (buf[0] == 'W')
4205 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4208 /* Process "P:<y>:<x>" -- player position */
4209 else if (buf[0] == 'P')
4211 if (init_flags & INIT_CREATE_DUNGEON)
4213 if (tokenize(buf + 2, 2, zz, 0) == 2)
4215 int panels_x, panels_y;
4217 /* Hack - Set the dungeon size */
4218 panels_y = (*y / SCREEN_HGT);
4219 if (*y % SCREEN_HGT) panels_y++;
4220 current_floor_ptr->height = panels_y * SCREEN_HGT;
4222 panels_x = (*x / SCREEN_WID);
4223 if (*x % SCREEN_WID) panels_x++;
4224 current_floor_ptr->width = panels_x * SCREEN_WID;
4226 /* Assume illegal panel */
4227 panel_row_min = current_floor_ptr->height;
4228 panel_col_min = current_floor_ptr->width;
4230 /* Place player in a quest level */
4231 if (p_ptr->inside_quest)
4235 /* Delete the monster (if any) */
4236 delete_monster(p_ptr->y, p_ptr->x);
4244 /* Place player in the town */
4245 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4247 p_ptr->oldpy = atoi(zz[0]);
4248 p_ptr->oldpx = atoi(zz[1]);
4256 /* Process "B:<Index>:<Command>:..." -- Building definition */
4257 else if (buf[0] == 'B')
4259 return parse_line_building(buf);
4262 /* Process "M:<type>:<maximum>" -- set maximum values */
4263 else if (buf[0] == 'M')
4265 if (tokenize(buf + 2, 2, zz, 0) == 2)
4268 if (zz[0][0] == 'T')
4270 max_towns = (TOWN_IDX)atoi(zz[1]);
4273 /* Maximum quests */
4274 else if (zz[0][0] == 'Q')
4276 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4280 else if (zz[0][0] == 'R')
4282 max_r_idx = (IDX)atoi(zz[1]);
4286 else if (zz[0][0] == 'K')
4288 max_k_idx = (IDX)atoi(zz[1]);
4292 else if (zz[0][0] == 'V')
4294 max_v_idx = (IDX)atoi(zz[1]);
4298 else if (zz[0][0] == 'F')
4300 max_f_idx = (IDX)atoi(zz[1]);
4304 else if (zz[0][0] == 'A')
4306 max_a_idx = (IDX)atoi(zz[1]);
4310 else if (zz[0][0] == 'E')
4312 max_e_idx = (IDX)atoi(zz[1]);
4316 else if (zz[0][0] == 'D')
4318 max_d_idx = (IDX)atoi(zz[1]);
4322 else if (zz[0][0] == 'O')
4324 current_floor_ptr->max_o_idx = (IDX)atoi(zz[1]);
4328 else if (zz[0][0] == 'M')
4330 current_floor_ptr->max_m_idx = (IDX)atoi(zz[1]);
4333 /* Wilderness size */
4334 else if (zz[0][0] == 'W')
4336 /* Maximum wild_x_size */
4337 if (zz[0][1] == 'X')
4338 current_world_ptr->max_wild_x = atoi(zz[1]);
4339 /* Maximum wild_y_size */
4340 if (zz[0][1] == 'Y')
4341 current_world_ptr->max_wild_y = atoi(zz[1]);
4355 static concptr variant = "ZANGBAND";
4359 * @brief クエスト用固定ダンジョン生成時の分岐処理
4360 * Helper function for "process_dungeon_file()"
4365 static concptr process_dungeon_file_expr(char **sp, char *fp)
4381 while (iswspace(*s)) s++;
4399 t = process_dungeon_file_expr(&s, &f);
4407 else if (streq(t, "IOR"))
4410 while (*s && (f != b2))
4412 t = process_dungeon_file_expr(&s, &f);
4413 if (*t && !streq(t, "0")) v = "1";
4418 else if (streq(t, "AND"))
4421 while (*s && (f != b2))
4423 t = process_dungeon_file_expr(&s, &f);
4424 if (*t && streq(t, "0")) v = "0";
4429 else if (streq(t, "NOT"))
4432 while (*s && (f != b2))
4434 t = process_dungeon_file_expr(&s, &f);
4435 if (*t && streq(t, "1")) v = "0";
4440 else if (streq(t, "EQU"))
4443 if (*s && (f != b2))
4445 t = process_dungeon_file_expr(&s, &f);
4447 while (*s && (f != b2))
4449 p = process_dungeon_file_expr(&s, &f);
4450 if (streq(t, p)) v = "1";
4455 else if (streq(t, "LEQ"))
4458 if (*s && (f != b2))
4460 t = process_dungeon_file_expr(&s, &f);
4462 while (*s && (f != b2))
4465 t = process_dungeon_file_expr(&s, &f);
4466 if (*t && atoi(p) > atoi(t)) v = "0";
4471 else if (streq(t, "GEQ"))
4474 if (*s && (f != b2))
4476 t = process_dungeon_file_expr(&s, &f);
4478 while (*s && (f != b2))
4481 t = process_dungeon_file_expr(&s, &f);
4483 /* Compare two numbers instead of string */
4484 if (*t && atoi(p) < atoi(t)) v = "0";
4490 while (*s && (f != b2))
4492 t = process_dungeon_file_expr(&s, &f);
4497 if (f != b2) v = "?x?x?";
4499 /* Extract final and Terminate */
4500 if ((f = *s) != '\0') *s++ = '\0';
4506 /* Accept all printables except spaces and brackets */
4508 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4510 if (iskanji(*s)) s++;
4514 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4517 /* Extract final and Terminate */
4518 if ((f = *s) != '\0') *s++ = '\0';
4524 if (streq(b + 1, "SYS"))
4530 else if (streq(b + 1, "GRAF"))
4535 else if (streq(b + 1, "MONOCHROME"))
4544 else if (streq(b + 1, "RACE"))
4546 v = _(rp_ptr->E_title, rp_ptr->title);
4550 else if (streq(b + 1, "CLASS"))
4552 v = _(cp_ptr->E_title, cp_ptr->title);
4556 else if (streq(b + 1, "REALM1"))
4558 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4562 else if (streq(b + 1, "REALM2"))
4564 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4568 else if (streq(b + 1, "PLAYER"))
4570 static char tmp_player_name[32];
4572 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4582 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4585 v = tmp_player_name;
4589 else if (streq(b + 1, "TOWN"))
4591 sprintf(tmp, "%d", p_ptr->town_num);
4596 else if (streq(b + 1, "LEVEL"))
4598 sprintf(tmp, "%d", p_ptr->lev);
4602 /* Current quest number */
4603 else if (streq(b + 1, "QUEST_NUMBER"))
4605 sprintf(tmp, "%d", p_ptr->inside_quest);
4609 /* Number of last quest */
4610 else if (streq(b + 1, "LEAVING_QUEST"))
4612 sprintf(tmp, "%d", leaving_quest);
4617 else if (prefix(b + 1, "QUEST_TYPE"))
4619 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4620 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4625 else if (prefix(b + 1, "QUEST"))
4627 /* "QUEST" uses a special parameter to determine the number of the quest */
4628 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4633 else if (prefix(b + 1, "RANDOM"))
4635 /* "RANDOM" uses a special parameter to determine the number of the quest */
4636 sprintf(tmp, "%d", (int)(seed_town%atoi(b + 7)));
4641 else if (streq(b + 1, "VARIANT"))
4647 else if (streq(b + 1, "WILDERNESS"))
4650 sprintf(tmp, "NONE");
4652 sprintf(tmp, "LITE");
4654 sprintf(tmp, "NORMAL");
4673 void write_r_info_txt(void)
4675 int i, j, z, fc, bc;
4678 concptr flags[32 * 10];
4683 monster_race *r_ptr;
4685 monster_blow *b_ptr;
4687 FILE *fff = fopen("output.txt", "wt");
4691 BIT_FLAGS mode = -1;
4695 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4697 fprintf(fff, "# Version stamp (required)\n\n");
4700 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4703 fprintf(fff, "##### The Player #####\n\n");
4705 for (z = -1; z < alloc_race_size; z++)
4707 /* Output the monsters in order */
4708 i = (z >= 0) ? alloc_race_table[z].index : 0;
4710 /* Acquire the monster */
4713 /* Ignore empty monsters */
4714 if (!strlen(r_name + r_ptr->name)) continue;
4716 /* Ignore useless monsters */
4717 if (i && !r_ptr->speed) continue;
4719 /* Write a note if necessary */
4720 if (i && (!r_ptr->level != !mode))
4725 fprintf(fff, "\n##### Town monsters #####\n\n");
4727 /* Note the dungeon */
4730 fprintf(fff, "\n##### Normal monsters #####\n\n");
4733 /* Record the change */
4734 mode = r_ptr->level;
4737 /* Acquire the flags */
4738 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4739 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4740 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4741 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4742 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4743 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4744 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4745 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4746 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4747 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4749 /* Write New/Number/Name */
4750 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4753 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4755 /* Write Information */
4756 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4757 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4759 /* Write more information */
4760 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4763 for (j = 0; j < 4; j++)
4765 b_ptr = &(r_ptr->blow[j]);
4767 /* Stop when done */
4768 if (!b_ptr->method) break;
4770 /* Write the blows */
4771 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4772 r_info_blow_effect[b_ptr->effect],
4773 b_ptr->d_dice, b_ptr->d_side);
4775 for (fc = 0, j = 0; j < 32 * 3; j++)
4777 /* Check this flag */
4778 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4781 /* Extract the extra flags */
4782 for (j = 32 * 6; j < 32 * 10; j++)
4784 /* Check this flag */
4785 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4788 /* Write the flags */
4789 for (j = 0; j < fc;)
4793 /* Start the line */
4796 for (bc = 0; (bc < 60) && (j < fc); j++)
4800 /* Format the flag */
4801 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4803 /* Add it to the buffer */
4806 /* Note the length */
4810 /* Done with this line; write it */
4811 fprintf(fff, "%s\n", buf);
4814 /* Write Spells if applicable */
4815 if (r_ptr->freq_spell)
4817 /* Write the frequency */
4818 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4820 /* Extract the spell flags */
4821 for (fc = 0, j = 96; j < 192; j++)
4823 /* Check this flag */
4824 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4827 /* Write the flags */
4828 for (j = 0; j < fc;)
4832 /* Start the line */
4835 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4839 /* Format the flag */
4840 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4844 /* Note the length */
4851 /* Done with this line; write it */
4852 fprintf(fff, "%s\n", buf);
4856 /* Acquire the description */
4857 desc = r_text + r_ptr->text;
4858 dlen = strlen(desc);
4860 /* Write Description */
4861 for (j = 0; j < dlen;)
4865 /* Start the line */
4868 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
4876 /* Done with this line; write it */
4877 fprintf(fff, "%s\n", buf);
4880 /* Space between entries */
4891 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4892 * Helper function for "process_dungeon_file()"
4900 errr process_dungeon_file(concptr name, int ymin, int xmin, int ymax, int xmax)
4906 bool bypass = FALSE;
4907 int x = xmin, y = ymin;
4910 /* Build the filename */
4911 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4914 fp = my_fopen(buf, "r");
4917 if (!fp) return (-1);
4920 /* Process the file */
4921 while (0 == my_fgets(fp, buf, sizeof(buf)))
4927 /* Skip "empty" lines */
4928 if (!buf[0]) continue;
4930 /* Skip "blank" lines */
4931 if (iswspace(buf[0])) continue;
4934 if (buf[0] == '#') continue;
4937 /* Process "?:<expr>" */
4938 if ((buf[0] == '?') && (buf[1] == ':'))
4947 /* Parse the expr */
4948 v = process_dungeon_file_expr(&s, &f);
4951 bypass = (streq(v, "0") ? TRUE : FALSE);
4955 /* Apply conditionals */
4956 if (bypass) continue;
4958 /* Process the line */
4959 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4970 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4972 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4973 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);