7 #include "dungeon-file.h"
8 #include "rooms-vault.h"
14 #include "player-skill.h"
15 #include "player-race.h"
20 #include "rooms-vault.h"
21 #include "objectkind.h"
22 #include "object-ego.h"
23 #include "monsterrace.h"
24 #include "floor-town.h"
27 dungeon_grid letter[255];
31 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
35 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
36 * This software may be copied and distributed for educational, research,
37 * and not for profit purposes provided that this copyright and statement
38 * are included in all such copies. Other copyrights may also apply.
39 * 2014 Deskull rearranged comment for Doxygen.\n
43 * This file is used to initialize various variables and arrays for the
44 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
45 * the common limitation of "read()" and "write()" to only 32767 bytes
47 * Several of the arrays for Angband are built from "template" files in
48 * the "lib/file" directory, from which quick-load binary "image" files
49 * are constructed whenever they are not present in the "lib/data"
50 * directory, or if those files become obsolete, if we are allowed.
51 * Warning -- the "ascii" file parsers use a minor hack to collect the
52 * name and text information in a single pass. Thus, the game will not
53 * be able to load any template file with more than 20K of names or 60K
54 * of text, even though technically, up to 64K should be legal.
56 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
57 * in this file is compiled out, and the game will not run unless valid
58 * "binary template files" already exist in "lib/data". Thus, one can
59 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
60 * "*.raw" files in "lib/data", and then quit, and recompile without
61 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
62 * from changing the ascii template files in potentially dangerous ways.
63 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
64 * このファイルのコードの多くはコンパイル出力され、本ゲームは
65 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
66 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
67 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
68 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
69 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
70 * テンプレートファイルを変更することを妨げることができる。
71 * The code could actually be removed and placed into a "stand-alone"
72 * program, but that feels a little silly, especially considering some
73 * of the platforms that we currently support.
78 #include "dungeon-file.h"
83 #include "cmd-activate.h"
87 #include "view-mainwindow.h"
88 #include "player-class.h"
90 #ifdef ALLOW_TEMPLATES
94 /*** Helper arrays for parsing ascii template files ***/
98 * Monster Blow Methods
100 static concptr r_info_blow_method[] =
132 * モンスターの打撃属性トークンの定義 /
133 * Monster Blow Effects
135 static concptr r_info_blow_effect[] =
180 static concptr f_info_flags[] =
304 static concptr r_info_flags1[] =
344 static concptr r_info_flags2[] =
384 static concptr r_info_flags3[] =
424 static concptr r_info_flags4[] =
461 * モンスター特性トークン(発動型能力1) /
464 static concptr r_a_ability_flags1[] =
501 * モンスター特性トークン(発動型能力2) /
504 static concptr r_a_ability_flags2[] =
521 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
544 static concptr r_info_flags7[] =
584 static concptr r_info_flags8[] =
616 "WILD_SWAMP", /* ToDo: Implement Swamp */
624 static concptr r_info_flags9[] =
662 * モンスター特性トークンの定義R(耐性) /
665 static concptr r_info_flagsr[] =
702 * オブジェクト基本特性トークンの定義 /
705 static concptr k_info_flags[] =
802 "XXX3", /* Fake flag for Smith */
803 "XXX4", /* Fake flag for Smith */
853 * オブジェクト生成特性トークンの定義 /
856 static concptr k_info_gen_flags[] =
896 static concptr d_info_flags1[] =
933 * @brief データの可変文字列情報をテキストとして保管する /
934 * Add a text to the text-storage and store offset to it.
935 * @param offset 文字列保管ポインタからのオフセット
936 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
938 * @param normal_text テキストの正規化を行う
941 * Returns FALSE when there isn't enough space available to store
944 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
946 /* Hack -- Verify space */
947 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
953 /* Advance and save the text index */
954 *offset = ++head->text_size;
957 /* Additional text */
958 else if (normal_text)
961 * If neither the end of the last line nor
962 * the beginning of current line is not a space,
963 * fill up a space as a correct separator of two words.
965 if (head->text_size > 0 &&
967 (*(head->text_ptr + head->text_size - 1) != ' ') &&
968 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
969 (buf[0] != ' ') && !iskanji(buf[0])
971 (*(head->text_ptr + head->text_size - 1) != ' ') &&
977 *(head->text_ptr + head->text_size) = ' ';
979 /* Advance the index */
984 strcpy(head->text_ptr + head->text_size, buf);
985 head->text_size += strlen(buf);
991 * @brief データの可変文字列情報を名前として保管する /
992 * Add a name to the name-storage and return an offset to it.
993 * @param offset 文字列保管ポインタからのオフセット
994 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
998 * Returns FALSE when there isn't enough space available to store
1001 static bool add_name(u32b *offset, header *head, concptr buf)
1003 /* Hack -- Verify space */
1004 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1010 /* Advance and save the name index */
1011 *offset = ++head->name_size;
1014 /* Append chars to the names */
1015 strcpy(head->name_ptr + head->name_size, buf);
1017 /* Advance the index */
1018 head->name_size += strlen(buf);
1026 * @brief データの可変文字列情報をタグとして保管する /
1027 * Add a tag to the tag-storage and return an offset to it.
1028 * @param offset 文字列保管ポインタからのオフセット
1029 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1033 * Returns FALSE when there isn't enough space available to store
1036 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1040 /* Search for an existing (fake) tag */
1041 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1044 if (streq(&head->tag_ptr[i], buf)) break;
1047 /* There was no existing tag */
1048 if (i >= head->tag_size)
1050 /* Hack -- Verify space */
1051 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1054 /* Append chars to the tags */
1055 strcpy(head->tag_ptr + head->tag_size, buf);
1057 /* Point the new tag */
1060 /* Advance the index */
1061 head->tag_size += strlen(buf) + 1;
1069 /*** Initialize from ascii template files ***/
1073 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1074 * Initialize an "*_info" array, by parsing an ascii "template" file
1075 * @param fp 読み取りに使うファイルポインタ
1076 * @param buf 読み取りに使うバッファ領域
1077 * @param head ヘッダ構造体
1078 * @param parse_info_txt_line パース関数
1081 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1083 /* Just before the first record */
1086 /* Just before the first line */
1089 /* Prepare the "fake" stuff */
1090 head->name_size = 0;
1091 head->text_size = 0;
1096 while (my_fgets(fp, buf, 1024) == 0)
1098 /* Advance the line number */
1101 /* Skip comments and blank lines */
1102 if (!buf[0] || (buf[0] == '#')) continue;
1104 /* Verify correct "colon" format */
1105 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1108 /* Hack -- Process 'V' for "Version" */
1115 /* Mega Hack -- Calculate Check Sum */
1116 if (buf[0] != 'N' && buf[0] != 'D')
1119 for (i = 0; buf[i]; i++)
1121 head->v_extra += (byte)buf[i];
1122 head->v_extra ^= (1 << (i % 8));
1126 /* Parse the line */
1127 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1132 /* Complete the "name" and "text" sizes */
1133 if (head->name_size) head->name_size++;
1134 if (head->text_size) head->text_size++;
1142 * @brief Vault情報(v_info)のパース関数 /
1143 * Initialize the "v_info" array, by parsing an ascii "template" file
1145 * @param head ヘッダ構造体
1148 errr parse_v_info(char *buf, header *head)
1154 static vault_type *v_ptr = NULL;
1156 /* Process 'N' for "New/Number/Name" */
1159 /* Find the colon before the name */
1160 s = my_strchr(buf + 2, ':');
1162 /* Verify that colon */
1165 /* Nuke the colon, advance to the name */
1168 /* Paranoia -- require a name */
1174 /* Verify information */
1175 if (i <= error_idx) return 4;
1177 /* Verify information */
1178 if (i >= head->info_num) return 2;
1180 /* Save the index */
1183 /* Point at the "info" */
1186 /* Store the name */
1187 if (!add_name(&v_ptr->name, head, s)) return 7;
1190 /* There better be a current v_ptr */
1191 else if (!v_ptr) return 3;
1193 /* Process 'D' for "Description" */
1194 else if (buf[0] == 'D')
1196 /* Acquire the text */
1199 /* Store the text */
1200 if (!add_text(&v_ptr->text, head, s, FALSE)) return 7;
1203 /* Process 'X' for "Extra info" (one line only) */
1204 else if (buf[0] == 'X')
1206 EFFECT_ID typ, rat, hgt, wid;
1208 /* Scan for the values */
1209 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1210 &typ, &rat, &hgt, &wid)) return 1;
1212 /* Save the values */
1213 v_ptr->typ = (ROOM_IDX)typ;
1214 v_ptr->rat = (PROB)rat;
1215 v_ptr->hgt = (POSITION)hgt;
1216 v_ptr->wid = (POSITION)wid;
1227 * @brief 職業技能情報(s_info)のパース関数 /
1228 * Initialize the "s_info" array, by parsing an ascii "template" file
1230 * @param head ヘッダ構造体
1233 errr parse_s_info(char *buf, header *head)
1238 static skill_table *s_ptr = NULL;
1241 /* Process 'N' for "New/Number/Name" */
1247 /* Verify information */
1248 if (i <= error_idx) return 4;
1250 /* Verify information */
1251 if (i >= head->info_num) return 2;
1253 /* Save the index */
1256 /* Point at the "info" */
1260 /* There better be a current s_ptr */
1261 else if (!s_ptr) return 3;
1263 /* Process 'W' for "Weapon exp" */
1264 else if (buf[0] == 'W')
1266 int tval, sval, start, max;
1267 const s16b exp_conv_table[] =
1269 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1270 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1273 /* Scan for the values */
1274 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1275 &tval, &sval, &start, &max)) return 1;
1277 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1278 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return 8;
1280 /* Save the values */
1281 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1282 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1285 /* Process 'S' for "Skill exp" */
1286 else if (buf[0] == 'S')
1288 int num, start, max;
1290 /* Scan for the values */
1291 if (3 != sscanf(buf + 2, "%d:%d:%d",
1292 &num, &start, &max)) return 1;
1294 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1295 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return 8;
1297 /* Save the values */
1298 s_ptr->s_start[num] = (SUB_EXP)start;
1299 s_ptr->s_max[num] = (SUB_EXP)max;
1311 * @brief 職業魔法情報(m_info)のパース関数 /
1312 * Initialize the "m_info" array, by parsing an ascii "template" file
1314 * @param head ヘッダ構造体
1317 errr parse_m_info(char *buf, header *head)
1324 static player_magic *m_ptr = NULL;
1327 static int realm, magic_idx = 0, readable = 0;
1330 /* Process 'N' for "New/Number/Name" */
1336 /* Verify information */
1337 if (i <= error_idx) return 4;
1339 /* Verify information */
1340 if (i >= head->info_num) return 2;
1342 /* Save the index */
1345 /* Point at the "info" */
1349 /* There better be a current m_ptr */
1350 else if (!m_ptr) return 3;
1352 /* Process 'I' for "Info" (one line only) */
1353 else if (buf[0] == 'I')
1356 int xtra, type, first, weight;
1358 /* Find the colon before the name */
1359 s = my_strchr(buf + 2, ':');
1361 /* Verify that colon */
1364 /* Nuke the colon, advance to the name */
1369 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1370 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1371 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1372 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1373 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1378 /* Find the colon before the name */
1379 s = my_strchr(s, ':');
1381 /* Verify that colon */
1384 /* Nuke the colon, advance to the name */
1387 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1388 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1389 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1390 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1391 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1392 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1396 /* Scan for the values */
1397 if (4 != sscanf(s, "%x:%d:%d:%d",
1398 (uint *)&xtra, &type, &first, &weight)) return 1;
1400 m_ptr->spell_xtra = xtra;
1401 m_ptr->spell_type = type;
1402 m_ptr->spell_first = first;
1403 m_ptr->spell_weight = weight;
1407 /* Process 'R' for "Realm" (one line only) */
1408 else if (buf[0] == 'R')
1410 /* Scan for the values */
1411 if (2 != sscanf(buf + 2, "%d:%d",
1412 &realm, &readable)) return 1;
1417 else if (buf[0] == 'T')
1419 int level, mana, fail, exp;
1421 if (!readable) return 1;
1422 /* Scan for the values */
1423 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1424 &level, &mana, &fail, &exp)) return 1;
1426 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1427 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1428 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1429 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1439 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1440 * Grab one flag from a textual string
1441 * @param flags ビットフラグを追加する先の参照ポインタ
1442 * @param names トークン定義配列
1443 * @param what 参照元の文字列ポインタ
1446 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1448 for (int i = 0; i < 32; i++)
1450 if (streq(what, names[i]))
1452 *flags |= (1L << i);
1462 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1463 * Grab one flag in an feature_type from a textual string
1464 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1465 * @param what 参照元の文字列ポインタ
1468 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1471 for (int i = 0; i < FF_FLAG_MAX; i++)
1473 if (streq(what, f_info_flags[i]))
1475 add_flag(f_ptr->flags, i);
1480 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1481 return PARSE_ERROR_GENERIC;
1486 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1487 * Grab an action in an feature_type from a textual string
1488 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1489 * @param what 参照元の文字列ポインタ
1490 * @param count ステートの保存先ID
1493 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1496 for (FF_FLAGS_IDX i = 0; i < FF_FLAG_MAX; i++)
1498 if (streq(what, f_info_flags[i]))
1500 f_ptr->state[count].action = i;
1505 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1506 return PARSE_ERROR_GENERIC;
1511 * @brief 地形情報(f_info)のパース関数 /
1512 * Initialize the "f_info" array, by parsing an ascii "template" file
1514 * @param head ヘッダ構造体
1517 errr parse_f_info(char *buf, header *head)
1520 static feature_type *f_ptr = NULL;
1522 /* Process 'N' for "New/Number/Name" */
1527 /* Find the colon before the name */
1528 s = my_strchr(buf + 2, ':');
1532 /* Nuke the colon, advance to the name */
1539 /* Verify information */
1540 if (i <= error_idx) return 4;
1542 /* Verify information */
1543 if (i >= head->info_num) return 2;
1545 /* Save the index */
1548 /* Point at the "info" */
1551 /* Tag name is given */
1555 if (!add_tag(&f_ptr->tag, head, s)) return 7;
1558 /* Default "mimic" */
1559 f_ptr->mimic = (FEAT_IDX)i;
1561 /* Default "destroyed state" -- if not specified */
1562 f_ptr->destroyed = (FEAT_IDX)i;
1564 /* Default "states" */
1565 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1568 /* There better be a current f_ptr */
1569 else if (!f_ptr) return 3;
1572 else if (buf[0] == 'J')
1574 /* Store the name */
1575 if (!add_name(&f_ptr->name, head, buf + 2)) return 7;
1578 else if (buf[0] == 'E')
1580 /* Ignore english name */
1583 else if (buf[0] == 'J')
1585 /* Ignore Japanese name */
1588 else if (buf[0] == 'E')
1590 /* Acquire the Text */
1593 /* Store the name */
1594 if (!add_name(&f_ptr->name, head, s)) return 7;
1599 /* Process 'M' for "Mimic" (one line only) */
1600 else if (buf[0] == 'M')
1604 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1606 /* Record a fake tag index */
1607 f_ptr->mimic_tag = offset;
1611 /* Process 'G' for "Graphics" (one line only) */
1612 else if (buf[0] == 'G')
1616 char char_tmp[F_LIT_MAX];
1617 if (buf[1] != ':') return 1;
1618 if (!buf[2]) return 1;
1619 if (buf[3] != ':') return 1;
1620 if (!buf[4]) return 1;
1622 /* Extract the char */
1623 char_tmp[F_LIT_STANDARD] = buf[2];
1625 /* Extract the color */
1626 s_attr = color_char_to_attr(buf[4]);
1627 if (s_attr > 127) return 1;
1629 /* Save the standard values */
1630 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1631 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1633 /* Is this feature supports lighting? */
1636 /* G:c:a:LIT (default) */
1637 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1639 /* G:c:a:lc:la:dc:da */
1640 if (!streq(buf + 6, "LIT"))
1642 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1644 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1645 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1646 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1647 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1649 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1651 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1654 /* Use default lighting */
1657 /* No lighting support */
1658 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1661 /* Extract the color */
1662 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1663 if (f_ptr->d_attr[j] > 127) return 1;
1666 f_ptr->d_char[j] = char_tmp[j];
1672 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1674 f_ptr->d_attr[j] = s_attr;
1675 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1681 /* Hack -- Process 'F' for flags */
1682 else if (buf[0] == 'F')
1684 /* Parse every entry textually */
1685 for (s = buf + 2; *s; )
1687 /* Find the end of this entry */
1688 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1690 /* Nuke and skip any dividers */
1694 while (*t == ' ' || *t == '|') t++;
1697 /* Hack -- Read feature subtype */
1698 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1700 /* Extract a "subtype" */
1701 f_ptr->subtype = (FEAT_SUBTYPE)i;
1703 /* Start at next entry */
1709 /* Hack -- Read feature power */
1710 if (1 == sscanf(s, "POWER_%d", &i))
1712 /* Extract a "power" */
1713 f_ptr->power = (FEAT_POWER)i;
1715 /* Start at next entry */
1720 /* Parse this entry */
1721 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1723 /* Start the next entry */
1728 /* Process 'W' for "More Info" (one line only) */
1729 else if (buf[0] == 'W')
1733 /* Scan for the value */
1734 if (1 != sscanf(buf + 2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1736 /* Save the value */
1737 f_ptr->priority = (FEAT_PRIORITY)priority;
1740 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1741 else if (buf[0] == 'K')
1745 /* Find the next empty state slot (if any) */
1746 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1748 /* Oops, no more slots */
1749 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1751 /* Analyze the first field */
1752 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
1754 /* Terminate the field (if necessary) */
1755 if (*t == ':') *t++ = '\0';
1757 /* Is this default entry? */
1758 if (streq(s, "DESTROYED"))
1760 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1762 /* Record a fake tag index */
1763 f_ptr->destroyed_tag = offset;
1768 f_ptr->state[i].action = 0;
1770 /* Parse this entry */
1771 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1773 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1775 /* Record a fake tag index */
1776 f_ptr->state[i].result_tag = offset;
1786 * @brief 地形タグからIDを得る /
1787 * Convert a fake tag to a real feat index
1791 s16b f_tag_to_index(concptr str)
1795 /* Search for real index corresponding to this fake tag */
1796 for (i = 0; i < f_head.info_num; i++)
1798 if (streq(f_tag + f_info[i].tag, str))
1800 /* Return the index */
1811 * @brief 地形タグからIDを得る /
1812 * Search for real index corresponding to this fake tag
1813 * @param feat タグ文字列のオフセット
1814 * @return 地形ID。該当がないなら-1
1816 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1818 /* Don't convert non-fake tag */
1824 /* Search for real index corresponding to this fake tag */
1825 for (FEAT_IDX i = 0; i < f_head.info_num; i++)
1827 if (feat == f_info[i].tag)
1829 /* Record real index */
1835 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1841 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1842 * Retouch fake tags of f_info
1843 * @param head ヘッダ構造体
1846 void retouch_f_info(header *head)
1848 /* Convert fake tags to real feat indices */
1849 for (int i = 0; i < head->info_num; i++)
1851 feature_type *f_ptr = &f_info[i];
1854 k = search_real_feat(f_ptr->mimic_tag);
1855 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1856 k = search_real_feat(f_ptr->destroyed_tag);
1857 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1858 for (j = 0; j < MAX_FEAT_STATES; j++)
1860 k = search_real_feat(f_ptr->state[j].result_tag);
1861 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1868 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1869 * Grab one flag in an object_kind from a textual string
1870 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1871 * @param what 参照元の文字列ポインタ
1874 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1877 for (int i = 0; i < TR_FLAG_MAX; i++)
1879 if (streq(what, k_info_flags[i]))
1881 add_flag(k_ptr->flags, i);
1886 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1889 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
1895 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
1896 * Grab one activation index flag
1897 * @param what 参照元の文字列ポインタ
1900 static byte grab_one_activation_flag(concptr what)
1902 for (int i = 0; ; i++)
1904 if (activation_info[i].flag == NULL) break;
1906 if (streq(what, activation_info[i].flag))
1908 return activation_info[i].index;
1918 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
1924 * @brief ベースアイテム(k_info)のパース関数 /
1925 * Initialize the "k_info" array, by parsing an ascii "template" file
1927 * @param head ヘッダ構造体
1930 errr parse_k_info(char *buf, header *head)
1933 static object_kind *k_ptr = NULL;
1935 /* Process 'N' for "New/Number/Name" */
1944 /* Find the colon before the name */
1945 s = my_strchr(buf + 2, ':');
1947 /* Verify that colon */
1950 /* Nuke the colon, advance to the name */
1956 /* Verify information */
1957 if (i <= error_idx) return 4;
1959 /* Verify information */
1960 if (i >= head->info_num) return 2;
1962 /* Save the index */
1965 /* Point at the "info" */
1969 /* Paranoia -- require a name */
1972 /* Find the colon before the flavor */
1973 flavor = my_strchr(s, ':');
1975 /* Verify that colon */
1978 /* Nuke the colon, advance to the flavor */
1981 /* Store the flavor */
1982 if (!add_name(&k_ptr->flavor_name, head, flavor)) return 7;
1985 /* Store the name */
1986 if (!add_name(&k_ptr->name, head, s)) return 7;
1990 /* There better be a current k_ptr */
1991 else if (!k_ptr) return 3;
1996 /* 'E' から始まる行は英語名としている */
1997 else if (buf[0] == 'E')
2002 else if (buf[0] == 'E')
2006 /* Acquire the name */
2009 /* Find the colon before the flavor */
2010 flavor = my_strchr(s, ':');
2012 /* Verify that colon */
2015 /* Nuke the colon, advance to the flavor */
2018 /* Store the flavor */
2019 if (!add_name(&k_ptr->flavor_name, head, flavor)) return 7;
2022 /* Store the name */
2023 if (!add_name(&k_ptr->name, head, s)) return 7;
2027 /* Process 'D' for "Description" */
2028 else if (buf[0] == 'D')
2033 /* Acquire the text */
2038 /* Acquire the text */
2042 /* Store the text */
2043 if (!add_text(&k_ptr->text, head, s, TRUE)) return 7;
2046 /* Process 'G' for "Graphics" (one line only) */
2047 else if (buf[0] == 'G')
2051 if (buf[1] != ':') return 1;
2052 if (!buf[2]) return 1;
2053 if (buf[3] != ':') return 1;
2054 if (!buf[4]) return 1;
2056 /* Extract the char */
2059 /* Extract the attr */
2060 tmp = color_char_to_attr(buf[4]);
2061 if (tmp > 127) return 1;
2063 /* Save the values */
2064 k_ptr->d_attr = tmp;
2065 k_ptr->d_char = sym;
2068 /* Process 'I' for "Info" (one line only) */
2069 else if (buf[0] == 'I')
2071 int tval, sval, pval;
2073 /* Scan for the values */
2074 if (3 != sscanf(buf + 2, "%d:%d:%d",
2075 &tval, &sval, &pval)) return 1;
2077 /* Save the values */
2078 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2079 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2080 k_ptr->pval = (PARAMETER_VALUE)pval;
2083 /* Process 'W' for "More Info" (one line only) */
2084 else if (buf[0] == 'W')
2086 int level, extra, wgt;
2089 /* Scan for the values */
2090 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2091 &level, &extra, &wgt, &cost)) return 1;
2093 /* Save the values */
2094 k_ptr->level = (DEPTH)level;
2095 k_ptr->extra = (BIT_FLAGS8)extra;
2096 k_ptr->weight = (WEIGHT)wgt;
2097 k_ptr->cost = (PRICE)cost;
2100 /* Process 'A' for "Allocation" (one line only) */
2101 else if (buf[0] == 'A')
2104 /* Simply read each number following a colon */
2105 for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
2107 /* Default chance */
2108 k_ptr->chance[i] = 1;
2110 /* Store the attack damage index */
2111 k_ptr->locale[i] = atoi(s + 1);
2113 /* Find the slash */
2114 t = my_strchr(s + 1, '/');
2116 /* Find the next colon */
2117 s = my_strchr(s + 1, ':');
2119 /* If the slash is "nearby", use it */
2120 if (t && (!s || t < s))
2122 int chance = atoi(t + 1);
2123 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2128 /* Hack -- Process 'P' for "power" and such */
2129 else if (buf[0] == 'P')
2131 int ac, hd1, hd2, th, td, ta;
2133 /* Scan for the values */
2134 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2135 &ac, &hd1, &hd2, &th, &td, &ta)) return 1;
2137 k_ptr->ac = (ARMOUR_CLASS)ac;
2138 k_ptr->dd = (DICE_NUMBER)hd1;
2139 k_ptr->ds = (DICE_SID)hd2;
2140 k_ptr->to_h = (HIT_PROB)th;
2141 k_ptr->to_d = (HIT_POINT)td;
2142 k_ptr->to_a = (ARMOUR_CLASS)ta;
2145 /* Hack -- Process 'U' for activation index */
2146 else if (buf[0] == 'U')
2149 n = grab_one_activation_flag(buf + 2);
2160 /* Hack -- Process 'F' for flags */
2161 else if (buf[0] == 'F')
2163 /* Parse every entry textually */
2164 for (s = buf + 2; *s; )
2166 /* Find the end of this entry */
2167 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2169 /* Nuke and skip any dividers */
2173 while (*t == ' ' || *t == '|') t++;
2176 /* Parse this entry */
2177 if (0 != grab_one_kind_flag(k_ptr, s)) return 5;
2179 /* Start the next entry */
2190 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2191 * Grab one activation index flag
2192 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2193 * @param what 参照元の文字列ポインタ
2194 * @return エラーがあった場合1、エラーがない場合0を返す
2196 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
2199 for (int i = 0; i < TR_FLAG_MAX; i++)
2201 if (streq(what, k_info_flags[i]))
2203 add_flag(a_ptr->flags, i);
2208 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2211 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2217 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2218 * Initialize the "a_info" array, by parsing an ascii "template" file
2220 * @param head ヘッダ構造体
2223 errr parse_a_info(char *buf, header *head)
2226 static artifact_type *a_ptr = NULL;
2228 /* Process 'N' for "New/Number/Name" */
2233 /* Find the colon before the name */
2234 s = my_strchr(buf + 2, ':');
2236 /* Verify that colon */
2239 /* Nuke the colon, advance to the name */
2242 /* Paranoia -- require a name */
2248 /* Verify information */
2249 if (i < error_idx) return 4;
2251 /* Verify information */
2252 if (i >= head->info_num) return 2;
2254 /* Save the index */
2257 /* Point at the "info" */
2260 /* Ignore everything */
2261 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2262 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2263 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2264 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2266 /* Store the name */
2267 if (!add_name(&a_ptr->name, head, s)) return 7;
2271 /* There better be a current a_ptr */
2272 else if (!a_ptr) return 3;
2277 /* 'E' から始まる行は英語名としている */
2278 else if (buf[0] == 'E')
2283 else if (buf[0] == 'E')
2285 /* Acquire the Text */
2288 /* Store the name */
2289 if (!add_name(&a_ptr->name, head, s)) return 7;
2293 /* Process 'D' for "Description" */
2294 else if (buf[0] == 'D')
2299 /* Acquire the text */
2304 /* Acquire the text */
2308 /* Store the text */
2309 if (!add_text(&a_ptr->text, head, s, TRUE)) return 7;
2313 /* Process 'I' for "Info" (one line only) */
2314 else if (buf[0] == 'I')
2316 int tval, sval, pval;
2318 /* Scan for the values */
2319 if (3 != sscanf(buf + 2, "%d:%d:%d",
2320 &tval, &sval, &pval)) return 1;
2322 /* Save the values */
2323 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2324 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2325 a_ptr->pval = (PARAMETER_VALUE)pval;
2328 /* Process 'W' for "More Info" (one line only) */
2329 else if (buf[0] == 'W')
2331 int level, rarity, wgt;
2334 /* Scan for the values */
2335 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2336 &level, &rarity, &wgt, &cost)) return 1;
2338 /* Save the values */
2339 a_ptr->level = (DEPTH)level;
2340 a_ptr->rarity = (RARITY)rarity;
2341 a_ptr->weight = (WEIGHT)wgt;
2342 a_ptr->cost = (PRICE)cost;
2345 /* Hack -- Process 'P' for "power" and such */
2346 else if (buf[0] == 'P')
2348 int ac, hd1, hd2, th, td, ta;
2350 /* Scan for the values */
2351 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2352 &ac, &hd1, &hd2, &th, &td, &ta)) return 1;
2354 a_ptr->ac = (ARMOUR_CLASS)ac;
2355 a_ptr->dd = (DICE_NUMBER)hd1;
2356 a_ptr->ds = (DICE_SID)hd2;
2357 a_ptr->to_h = (HIT_PROB)th;
2358 a_ptr->to_d = (HIT_POINT)td;
2359 a_ptr->to_a = (ARMOUR_CLASS)ta;
2362 /* Hack -- Process 'U' for activation index */
2363 else if (buf[0] == 'U')
2366 n = grab_one_activation_flag(buf + 2);
2377 /* Hack -- Process 'F' for flags */
2378 else if (buf[0] == 'F')
2380 /* Parse every entry textually */
2381 for (s = buf + 2; *s; )
2383 /* Find the end of this entry */
2384 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2386 /* Nuke and skip any dividers */
2390 while ((*t == ' ') || (*t == '|')) t++;
2393 /* Parse this entry */
2394 if (0 != grab_one_artifact_flag(a_ptr, s)) return 5;
2396 /* Start the next entry */
2407 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2408 * Grab one flag in a ego-item_type from a textual string
2409 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2410 * @param what 参照元の文字列ポインタ
2411 * @return エラーがあった場合1、エラーがない場合0を返す
2413 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2416 for (int i = 0; i < TR_FLAG_MAX; i++)
2418 if (streq(what, k_info_flags[i]))
2420 add_flag(e_ptr->flags, i);
2425 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2428 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2434 * @brief アイテムエゴ情報(e_info)のパース関数 /
2435 * Initialize the "e_info" array, by parsing an ascii "template" file
2437 * @param head ヘッダ構造体
2440 errr parse_e_info(char *buf, header *head)
2443 static ego_item_type *e_ptr = NULL;
2445 /* Just before the first record */
2448 /* Just before the first line */
2451 /* Process 'N' for "New/Number/Name" */
2456 /* Find the colon before the name */
2457 s = my_strchr(buf + 2, ':');
2459 /* Verify that colon */
2462 /* Nuke the colon, advance to the name */
2465 /* Paranoia -- require a name */
2471 /* Verify information */
2472 if (i < error_idx) return 4;
2474 /* Verify information */
2475 if (i >= head->info_num) return 2;
2477 /* Save the index */
2480 /* Point at the "info" */
2483 /* Store the name */
2484 if (!add_name(&e_ptr->name, head, s)) return 7;
2488 /* There better be a current e_ptr */
2489 else if (!e_ptr) return 3;
2494 /* 'E' から始まる行は英語名 */
2495 else if (buf[0] == 'E')
2500 else if (buf[0] == 'E')
2502 /* Acquire the Text */
2505 /* Store the name */
2506 if (!add_name(&e_ptr->name, head, s)) return 7;
2509 /* Process 'X' for "Xtra" (one line only) */
2510 else if (buf[0] == 'X')
2514 /* Scan for the values */
2515 if (2 != sscanf(buf + 2, "%d:%d",
2516 &slot, &rating)) return 1;
2518 /* Save the values */
2519 e_ptr->slot = (INVENTORY_IDX)slot;
2520 e_ptr->rating = (PRICE)rating;
2523 /* Process 'W' for "More Info" (one line only) */
2524 else if (buf[0] == 'W')
2526 int level, rarity, pad2;
2529 /* Scan for the values */
2530 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2531 &level, &rarity, &pad2, &cost)) return 1;
2533 /* Save the values */
2534 e_ptr->level = level;
2535 e_ptr->rarity = (RARITY)rarity;
2536 /* e_ptr->weight = wgt; */
2540 /* Hack -- Process 'C' for "creation" */
2541 else if (buf[0] == 'C')
2543 int th, td, ta, pval;
2545 /* Scan for the values */
2546 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2547 &th, &td, &ta, &pval)) return 1;
2549 e_ptr->max_to_h = (HIT_PROB)th;
2550 e_ptr->max_to_d = (HIT_POINT)td;
2551 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2552 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2555 /* Hack -- Process 'U' for activation index */
2556 else if (buf[0] == 'U')
2559 n = grab_one_activation_flag(buf + 2);
2570 /* Hack -- Process 'F' for flags */
2571 else if (buf[0] == 'F')
2573 /* Parse every entry textually */
2574 for (s = buf + 2; *s; )
2576 /* Find the end of this entry */
2577 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2579 /* Nuke and skip any dividers */
2583 while ((*t == ' ') || (*t == '|')) t++;
2586 /* Parse this entry */
2587 if (0 != grab_one_ego_item_flag(e_ptr, s)) return 5;
2589 /* Start the next entry */
2600 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2601 * Grab one (basic) flag in a monster_race from a textual string
2602 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2603 * @param what 参照元の文字列ポインタ
2606 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2608 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2611 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2614 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2617 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2620 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2623 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2626 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2629 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2635 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2636 * Grab one (spell) flag in a monster_race from a textual string
2637 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2638 * @param what 参照元の文字列ポインタ
2641 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2643 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2646 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2649 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2652 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2658 * @brief モンスター種族情報(r_info)のパース関数 /
2659 * Initialize the "r_info" array, by parsing an ascii "template" file
2661 * @param head ヘッダ構造体
2664 errr parse_r_info(char *buf, header *head)
2667 static monster_race *r_ptr = NULL;
2669 /* Process 'N' for "New/Number/Name" */
2674 /* Find the colon before the name */
2675 s = my_strchr(buf + 2, ':');
2677 /* Verify that colon */
2680 /* Nuke the colon, advance to the name */
2683 /* Paranoia -- require a name */
2689 /* Verify information */
2690 if (i < error_idx) return 4;
2692 /* Verify information */
2693 if (i >= head->info_num) return 2;
2695 /* Save the index */
2698 /* Point at the "info" */
2701 /* Store the name */
2702 if (!add_name(&r_ptr->name, head, s)) return 7;
2706 /* There better be a current r_ptr */
2707 else if (!r_ptr) return 3;
2712 /* 'E' から始まる行は英語名 */
2713 else if (buf[0] == 'E')
2715 /* Acquire the Text */
2718 /* Store the name */
2719 if (!add_name(&r_ptr->E_name, head, s)) return 7;
2722 else if (buf[0] == 'E')
2724 /* Acquire the Text */
2727 /* Store the name */
2728 if (!add_name(&r_ptr->name, head, s)) return 7;
2731 /* Process 'D' for "Description" */
2732 else if (buf[0] == 'D')
2737 /* Acquire the text */
2742 /* Acquire the text */
2746 /* Store the text */
2747 if (!add_text(&r_ptr->text, head, s, TRUE)) return 7;
2750 /* Process 'G' for "Graphics" (one line only) */
2751 else if (buf[0] == 'G')
2755 if (buf[1] != ':') return 1;
2756 if (!buf[2]) return 1;
2757 if (buf[3] != ':') return 1;
2758 if (!buf[4]) return 1;
2760 /* Extract the char */
2763 /* Extract the attr */
2764 tmp = color_char_to_attr(buf[4]);
2765 if (tmp > 127) return 1;
2767 /* Save the values */
2768 r_ptr->d_char = sym;
2769 r_ptr->d_attr = tmp;
2772 /* Process 'I' for "Info" (one line only) */
2773 else if (buf[0] == 'I')
2775 int spd, hp1, hp2, aaf, ac, slp;
2777 /* Scan for the other values */
2778 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2779 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return 1;
2781 /* Save the values */
2782 r_ptr->speed = (SPEED)spd;
2783 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2784 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2785 r_ptr->aaf = (POSITION)aaf;
2786 r_ptr->ac = (ARMOUR_CLASS)ac;
2787 r_ptr->sleep = (SLEEP_DEGREE)slp;
2790 /* Process 'W' for "More Info" (one line only) */
2791 else if (buf[0] == 'W')
2798 /* Scan for the values */
2799 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2800 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return 1;
2802 /* Save the values */
2803 r_ptr->level = (DEPTH)lev;
2804 r_ptr->rarity = (RARITY)rar;
2805 r_ptr->extra = (BIT_FLAGS16)pad;
2806 r_ptr->mexp = (EXP)exp;
2807 r_ptr->next_exp = (EXP)nextexp;
2808 r_ptr->next_r_idx = (MONRACE_IDX)nextmon;
2811 /* Process 'R' for "Reinforcement" (up to six lines) */
2812 else if (buf[0] == 'R')
2815 /* Find the next empty blow slot (if any) */
2816 for (i = 0; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2818 /* Oops, no more slots */
2819 if (i == 6) return 1;
2821 /* Scan for the values */
2822 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return 1;
2823 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2824 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2825 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2828 /* Process 'B' for "Blows" (up to four lines) */
2829 else if (buf[0] == 'B')
2833 /* Find the next empty blow slot (if any) */
2834 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2836 /* Oops, no more slots */
2837 if (i == 4) return 1;
2839 /* Analyze the first field */
2840 for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */;
2842 /* Terminate the field (if necessary) */
2843 if (*t == ':') *t++ = '\0';
2845 /* Analyze the method */
2846 for (n1 = 0; r_info_blow_method[n1]; n1++)
2848 if (streq(s, r_info_blow_method[n1])) break;
2851 /* Invalid method */
2852 if (!r_info_blow_method[n1]) return 1;
2854 /* Analyze the second field */
2855 for (s = t; *t && (*t != ':'); t++) /* loop */;
2857 /* Terminate the field (if necessary) */
2858 if (*t == ':') *t++ = '\0';
2860 /* Analyze effect */
2861 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2863 if (streq(s, r_info_blow_effect[n2])) break;
2866 /* Invalid effect */
2867 if (!r_info_blow_effect[n2]) return 1;
2869 /* Analyze the third field */
2870 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2872 /* Terminate the field (if necessary) */
2873 if (*t == 'd') *t++ = '\0';
2875 /* Save the method */
2876 r_ptr->blow[i].method = (BLOW_METHOD)n1;
2878 /* Save the effect */
2879 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
2881 /* Extract the damage dice and sides */
2882 r_ptr->blow[i].d_dice = atoi(s);
2883 r_ptr->blow[i].d_side = atoi(t);
2886 /* Process 'F' for "Basic Flags" (multiple lines) */
2887 else if (buf[0] == 'F')
2889 /* Parse every entry */
2890 for (s = buf + 2; *s; )
2892 /* Find the end of this entry */
2893 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2895 /* Nuke and skip any dividers */
2899 while (*t == ' ' || *t == '|') t++;
2902 /* Parse this entry */
2903 if (0 != grab_one_basic_flag(r_ptr, s)) return 5;
2905 /* Start the next entry */
2910 /* Process 'S' for "Spell Flags" (multiple lines) */
2911 else if (buf[0] == 'S')
2913 /* Parse every entry */
2914 for (s = buf + 2; *s; )
2916 /* Find the end of this entry */
2917 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2919 /* Nuke and skip any dividers */
2923 while ((*t == ' ') || (*t == '|')) t++;
2926 /* Hack -- Read spell frequency */
2927 if (1 == sscanf(s, "1_IN_%d", &i))
2929 /* Extract a "frequency" */
2930 r_ptr->freq_spell = 100 / i;
2932 /* Start at next entry */
2937 /* Parse this entry */
2938 if (0 != grab_one_spell_flag(r_ptr, s)) return 5;
2940 /* Start the next entry */
2945 /* Process 'A' for "Artifact Flags" (multiple lines) */
2946 else if (buf[0] == 'A')
2948 int id, per, rarity;
2950 /* Find the next empty blow slot (if any) */
2951 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
2953 /* Oops, no more slots */
2954 if (i == 4) return 1;
2956 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return 1;
2957 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
2958 r_ptr->artifact_rarity[i] = (RARITY)rarity;
2959 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
2962 /* Process 'V' for "Arena power value ratio" */
2963 else if (buf[0] == 'V')
2966 if (3 != sscanf(buf + 2, "%d", &val)) return 1;
2967 r_ptr->arena_ratio = (PERCENTAGE)val;
2976 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
2977 * Grab one flag for a dungeon type from a textual string
2978 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
2979 * @param what 参照元の文字列ポインタ
2982 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
2984 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2987 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
2993 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
2994 * Grab one (basic) flag in a monster_race from a textual string
2995 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
2996 * @param what 参照元の文字列ポインタ
2999 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
3001 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3004 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3007 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3010 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3013 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3016 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3019 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3022 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3028 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3029 * Grab one (spell) flag in a monster_race from a textual string
3030 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3031 * @param what 参照元の文字列ポインタ
3034 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
3036 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3039 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3042 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3045 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3051 * @brief ダンジョン情報(d_info)のパース関数 /
3052 * Initialize the "d_info" array, by parsing an ascii "template" file
3054 * @param head ヘッダ構造体
3057 errr parse_d_info(char *buf, header *head)
3060 static dungeon_type *d_ptr = NULL;
3062 /* Process 'N' for "New/Number/Name" */
3067 /* Find the colon before the name */
3068 s = my_strchr(buf + 2, ':');
3070 /* Verify that colon */
3073 /* Nuke the colon, advance to the name */
3076 /* Paranoia -- require a name */
3082 /* Verify information */
3083 if (i < error_idx) return 4;
3085 /* Verify information */
3086 if (i >= head->info_num) return 2;
3088 /* Save the index */
3091 /* Point at the "info" */
3094 /* Store the name */
3095 if (!add_name(&d_ptr->name, head, s)) return 7;
3100 else if (buf[0] == 'E') return 0;
3102 else if (buf[0] == 'E')
3104 /* Acquire the Text */
3107 /* Store the name */
3108 if (!add_name(&d_ptr->name, head, s)) return 7;
3112 /* Process 'D' for "Description */
3113 else if (buf[0] == 'D')
3118 /* Acquire the text */
3123 /* Acquire the text */
3127 /* Store the text */
3128 if (!add_text(&d_ptr->text, head, s, TRUE)) return 7;
3131 /* Process 'W' for "More Info" (one line only) */
3132 else if (buf[0] == 'W')
3134 int min_lev, max_lev;
3136 int min_alloc, max_chance;
3137 int obj_good, obj_great;
3140 /* Scan for the values */
3141 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3142 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return 1;
3144 /* Save the values */
3145 d_ptr->mindepth = (DEPTH)min_lev;
3146 d_ptr->maxdepth = (DEPTH)max_lev;
3147 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3148 d_ptr->mode = (BIT_FLAGS8)mode;
3149 d_ptr->min_m_alloc_level = min_alloc;
3150 d_ptr->max_m_alloc_chance = max_chance;
3151 d_ptr->obj_good = obj_good;
3152 d_ptr->obj_great = obj_great;
3153 d_ptr->pit = (BIT_FLAGS16)pit;
3154 d_ptr->nest = (BIT_FLAGS16)nest;
3157 /* Process 'P' for "Place Info" */
3158 else if (buf[0] == 'P')
3162 /* Scan for the values */
3163 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return 1;
3165 /* Save the values */
3170 /* Process 'L' for "fLoor type" (one line only) */
3171 else if (buf[0] == 'L')
3175 /* Scan for the values */
3176 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return 1;
3178 /* Save the values */
3179 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3181 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3182 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3184 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3186 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3189 /* Process 'A' for "wAll type" (one line only) */
3190 else if (buf[0] == 'A')
3194 /* Scan for the values */
3195 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return 1;
3197 /* Save the values */
3198 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3200 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3201 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3203 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3206 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3207 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3209 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3210 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3212 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3213 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3215 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3216 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3219 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3220 else if (buf[0] == 'F')
3222 int artif = 0, monst = 0;
3224 /* Parse every entry */
3225 for (s = buf + 2; *s; )
3227 /* Find the end of this entry */
3228 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3230 /* Nuke and skip any dividers */
3234 while (*t == ' ' || *t == '|') t++;
3237 /* Hack -- Read Final Artifact */
3238 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3240 /* Extract a "Final Artifact" */
3241 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3243 /* Start at next entry */
3248 /* Hack -- Read Final Object */
3249 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3251 /* Extract a "Final Artifact" */
3252 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3254 /* Start at next entry */
3259 /* Hack -- Read Artifact Guardian */
3260 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3262 /* Extract a "Artifact Guardian" */
3263 d_ptr->final_guardian = (MONRACE_IDX)monst;
3265 /* Start at next entry */
3270 /* Hack -- Read Special Percentage */
3271 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3273 /* Extract a "Special %" */
3274 d_ptr->special_div = (PROB)monst;
3276 /* Start at next entry */
3281 /* Parse this entry */
3282 if (0 != grab_one_dungeon_flag(d_ptr, s)) return 5;
3284 /* Start the next entry */
3289 /* Process 'M' for "Basic Flags" (multiple lines) */
3290 else if (buf[0] == 'M')
3292 /* Parse every entry */
3293 for (s = buf + 2; *s; )
3295 /* Find the end of this entry */
3296 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3298 /* Nuke and skip any dividers */
3302 while (*t == ' ' || *t == '|') t++;
3305 /* Hack -- Read monster symbols */
3306 if (!strncmp(s, "R_CHAR_", 7))
3308 /* Skip "R_CHAR_" */
3312 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3314 /* Start at next entry */
3319 /* Parse this entry */
3320 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return 5;
3322 /* Start the next entry */
3327 /* Process 'S' for "Spell Flags" (multiple lines) */
3328 else if (buf[0] == 'S')
3330 /* Parse every entry */
3331 for (s = buf + 2; *s; )
3333 /* Find the end of this entry */
3334 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3336 /* Nuke and skip any dividers */
3340 while ((*t == ' ') || (*t == '|')) t++;
3343 /* Hack -- Read spell frequency */
3344 if (1 == sscanf(s, "1_IN_%d", &i))
3346 /* Start at next entry */
3351 /* Parse this entry */
3352 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return 5;
3354 /* Start the next entry */
3364 #else /* ALLOW_TEMPLATES */
3370 #endif /* ALLOW_TEMPLATES */
3374 * @brief 地形情報の「F:」情報をパースする
3375 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3376 * @param floor_ptr 現在フロアへの参照ポインタ
3380 static errr parse_line_feature(floor_type *floor_ptr, char *buf)
3382 if (init_flags & INIT_ONLY_BUILDINGS) return 0;
3384 /* Tokenize the line */
3386 int num = tokenize(buf + 2, 9, zz, 0);
3387 if (num <= 1) return 1;
3389 /* Letter to assign */
3390 int index = zz[0][0];
3392 /* Reset the info for the letter */
3393 letter[index].feature = feat_none;
3394 letter[index].monster = 0;
3395 letter[index].object = 0;
3396 letter[index].ego = 0;
3397 letter[index].artifact = 0;
3398 letter[index].trap = feat_none;
3399 letter[index].cave_info = 0;
3400 letter[index].special = 0;
3401 letter[index].random = RANDOM_NONE;
3407 letter[index].special = (s16b)atoi(zz[8]);
3411 if ((zz[7][0] == '*') && !zz[7][1])
3413 letter[index].random |= RANDOM_TRAP;
3417 letter[index].trap = f_tag_to_index(zz[7]);
3418 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3423 if (zz[6][0] == '*')
3425 letter[index].random |= RANDOM_ARTIFACT;
3426 if (zz[6][1]) letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6] + 1);
3428 else if (zz[6][0] == '!')
3430 if (floor_ptr->inside_quest)
3432 letter[index].artifact = quest[floor_ptr->inside_quest].k_idx;
3437 letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6]);
3442 if (zz[5][0] == '*')
3444 letter[index].random |= RANDOM_EGO;
3445 if (zz[5][1]) letter[index].ego = (EGO_IDX)atoi(zz[5] + 1);
3449 letter[index].ego = (EGO_IDX)atoi(zz[5]);
3454 if (zz[4][0] == '*')
3456 letter[index].random |= RANDOM_OBJECT;
3457 if (zz[4][1]) letter[index].object = (OBJECT_IDX)atoi(zz[4] + 1);
3459 else if (zz[4][0] == '!')
3461 if (floor_ptr->inside_quest)
3463 ARTIFACT_IDX a_idx = quest[floor_ptr->inside_quest].k_idx;
3466 artifact_type *a_ptr = &a_info[a_idx];
3467 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3469 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3476 letter[index].object = (IDX)atoi(zz[4]);
3481 if (zz[3][0] == '*')
3483 letter[index].random |= RANDOM_MONSTER;
3484 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3486 else if (zz[3][0] == 'c')
3488 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3489 letter[index].monster = -atoi(zz[3] + 1);
3493 letter[index].monster = (IDX)atoi(zz[3]);
3498 letter[index].cave_info = atoi(zz[2]);
3502 if ((zz[1][0] == '*') && !zz[1][1])
3504 letter[index].random |= RANDOM_FEATURE;
3508 letter[index].feature = f_tag_to_index(zz[1]);
3509 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3519 * @brief 地形情報の「B:」情報をパースする
3520 * Process "B:<Index>:<Command>:..." -- Building definition
3524 static errr parse_line_building(char *buf)
3540 /* Get the building number */
3543 /* Find the colon after the building number */
3544 s = my_strchr(s, ':');
3546 /* Verify that colon */
3549 /* Nuke the colon, advance to the sub-index */
3552 /* Paranoia -- require a sub-index */
3555 /* Building definition sub-index */
3558 /* Building name, owner, race */
3561 if (tokenize(s + 2, 3, zz, 0) == 3)
3563 /* Name of the building */
3564 strcpy(building[index].name, zz[0]);
3566 /* Name of the owner */
3567 strcpy(building[index].owner_name, zz[1]);
3569 /* Race of the owner */
3570 strcpy(building[index].owner_race, zz[2]);
3575 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3578 /* Building Action */
3581 if (tokenize(s + 2, 8, zz, 0) >= 7)
3583 /* Index of the action */
3584 int action_index = atoi(zz[0]);
3586 /* Name of the action */
3587 strcpy(building[index].act_names[action_index], zz[1]);
3589 /* Cost of the action for members */
3590 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3592 /* Cost of the action for non-members */
3593 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3595 /* Letter assigned to the action */
3596 building[index].letters[action_index] = zz[4][0];
3599 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
3601 /* Action restriction */
3602 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
3607 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3610 /* Building Classes */
3614 n = tokenize(s + 2, MAX_CLASS, zz, 0);
3615 for (i = 0; i < MAX_CLASS; i++)
3617 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
3622 /* Building Races */
3626 n = tokenize(s + 2, MAX_RACES, zz, 0);
3627 for (i = 0; i < MAX_RACES; i++)
3629 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
3634 /* Building Realms */
3638 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
3639 for (i = 0; i < MAX_MAGIC; i++)
3641 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3648 /* Ignore scripts */
3654 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3663 * @brief フロアの所定のマスにオブジェクトを配置する
3664 * Place the object j_ptr to a grid
3665 * @param floor_ptr 現在フロアへの参照ポインタ
3666 * @param j_ptr オブジェクト構造体の参照ポインタ
3671 static void drop_here(floor_type *floor_ptr, object_type *j_ptr, POSITION y, POSITION x)
3673 OBJECT_IDX o_idx = o_pop(floor_ptr);
3675 o_ptr = &floor_ptr->o_list[o_idx];
3676 object_copy(o_ptr, j_ptr);
3679 o_ptr->held_m_idx = 0;
3680 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
3681 o_ptr->next_o_idx = g_ptr->o_idx;
3682 g_ptr->o_idx = o_idx;
3687 * todo yminとymaxは本当に使われているのか?
3688 * @brief クエスト用固定ダンジョンをフロアに生成する
3689 * Parse a sub-file of the "extra info"
3690 * @param player_ptr プレーヤーへの参照ポインタ
3700 static errr process_dungeon_file_aux(player_type *player_ptr, char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3705 /* Skip "empty" lines */
3706 if (!buf[0]) return 0;
3708 /* Skip "blank" lines */
3709 if (iswspace(buf[0])) return 0;
3712 if (buf[0] == '#') return 0;
3714 /* Require "?:*" format */
3715 if (buf[1] != ':') return 1;
3718 /* Process "%:<fname>" */
3721 /* Attempt to Process the given file */
3722 return process_dungeon_file(player_ptr, buf + 2, ymin, xmin, ymax, xmax);
3725 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3726 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3729 return parse_line_feature(player_ptr->current_floor_ptr, buf);
3732 /* Process "D:<dungeon>" -- info for the floor grids */
3733 else if (buf[0] == 'D')
3735 object_type object_type_body;
3737 /* Acquire the text */
3740 /* Length of the text */
3741 int len = strlen(s);
3743 if (init_flags & INIT_ONLY_BUILDINGS) return 0;
3745 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3747 grid_type *g_ptr = &floor_ptr->grid_array[*y][*x];
3751 OBJECT_IDX object_index = letter[idx].object;
3752 MONSTER_IDX monster_index = letter[idx].monster;
3753 int random = letter[idx].random;
3754 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3756 /* Lay down a floor */
3757 g_ptr->feat = conv_dungeon_feat(floor_ptr, letter[idx].feature);
3759 /* Only the features */
3760 if (init_flags & INIT_ONLY_FEATURES) continue;
3763 g_ptr->info = letter[idx].cave_info;
3765 /* Create a monster */
3766 if (random & RANDOM_MONSTER)
3768 floor_ptr->monster_level = floor_ptr->base_level + monster_index;
3770 place_monster(player_ptr, *y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3772 floor_ptr->monster_level = floor_ptr->base_level;
3774 else if (monster_index)
3776 int old_cur_num, old_max_num;
3779 if (monster_index < 0)
3781 monster_index = -monster_index;
3784 old_cur_num = r_info[monster_index].cur_num;
3785 old_max_num = r_info[monster_index].max_num;
3787 /* Make alive again */
3788 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3790 r_info[monster_index].cur_num = 0;
3791 r_info[monster_index].max_num = 1;
3794 /* Make alive again */
3795 /* Hack -- Non-unique Nazguls are semi-unique */
3796 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3798 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3800 r_info[monster_index].max_num++;
3805 place_monster_aux(player_ptr, 0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3809 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3811 /* Make alive again for real unique monster */
3812 r_info[monster_index].cur_num = old_cur_num;
3813 r_info[monster_index].max_num = old_max_num;
3817 /* Object (and possible trap) */
3818 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3820 floor_ptr->object_level = floor_ptr->base_level + object_index;
3823 * Random trap and random treasure defined
3824 * 25% chance for trap and 75% chance for object
3826 if (randint0(100) < 75)
3828 place_object(player_ptr, *y, *x, 0L);
3832 place_trap(player_ptr, *y, *x);
3835 floor_ptr->object_level = floor_ptr->base_level;
3837 else if (random & RANDOM_OBJECT)
3839 floor_ptr->object_level = floor_ptr->base_level + object_index;
3841 /* Create an out of deep object */
3842 if (randint0(100) < 75)
3843 place_object(player_ptr, *y, *x, 0L);
3844 else if (randint0(100) < 80)
3845 place_object(player_ptr, *y, *x, AM_GOOD);
3847 place_object(player_ptr, *y, *x, AM_GOOD | AM_GREAT);
3849 floor_ptr->object_level = floor_ptr->base_level;
3852 else if (random & RANDOM_TRAP)
3854 place_trap(player_ptr, *y, *x);
3856 /* Hidden trap (or door) */
3857 else if (letter[idx].trap)
3859 g_ptr->mimic = g_ptr->feat;
3860 g_ptr->feat = conv_dungeon_feat(floor_ptr, letter[idx].trap);
3862 else if (object_index)
3864 object_type *o_ptr = &object_type_body;
3865 object_prep(o_ptr, object_index);
3867 if (o_ptr->tval == TV_GOLD)
3869 coin_type = object_index - OBJ_GOLD_LIST;
3870 make_gold(floor_ptr, o_ptr);
3874 /* Apply magic (no messages, no artifacts) */
3875 apply_magic(player_ptr, o_ptr, floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
3877 drop_here(floor_ptr, o_ptr, *y, *x);
3883 if (a_info[artifact_index].cur_num)
3885 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3887 object_type *q_ptr = &forge;
3889 object_prep(q_ptr, k_idx);
3890 drop_here(floor_ptr, q_ptr, *y, *x);
3894 if (create_named_art(player_ptr, artifact_index, *y, *x))
3895 a_info[artifact_index].cur_num = 1;
3899 /* Terrain special */
3900 g_ptr->special = letter[idx].special;
3908 /* Process "Q:<number>:<command>:... -- quest info */
3909 else if (buf[0] == 'Q')
3916 num = tokenize(buf + 2, 33, zz, 0);
3920 num = tokenize(buf + 3, 33, zz, 0);
3923 /* Have we enough parameters? */
3924 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3927 q_ptr = &(quest[atoi(zz[0])]);
3929 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3930 if (zz[1][0] == 'Q')
3932 if (init_flags & INIT_ASSIGN)
3934 monster_race *r_ptr;
3935 artifact_type *a_ptr;
3937 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3939 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
3940 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
3941 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
3942 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
3943 q_ptr->level = (DEPTH)atoi(zz[6]);
3944 q_ptr->r_idx = (IDX)atoi(zz[7]);
3945 q_ptr->k_idx = (IDX)atoi(zz[8]);
3946 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
3948 if (num > 10) q_ptr->flags = atoi(zz[10]);
3950 r_ptr = &r_info[q_ptr->r_idx];
3951 if (r_ptr->flags1 & RF1_UNIQUE)
3952 r_ptr->flags1 |= RF1_QUESTOR;
3954 a_ptr = &a_info[q_ptr->k_idx];
3955 a_ptr->gen_flags |= TRG_QUESTITEM;
3960 else if (zz[1][0] == 'R')
3962 if (init_flags & INIT_ASSIGN)
3965 IDX idx, reward_idx = 0;
3967 for (idx = 2; idx < num; idx++)
3969 IDX a_idx = (IDX)atoi(zz[idx]);
3970 if (a_idx < 1) continue;
3971 if (a_info[a_idx].cur_num > 0) continue;
3973 if (one_in_(count)) reward_idx = a_idx;
3978 /* Set quest's rewarding artifact */
3979 q_ptr->k_idx = reward_idx;
3980 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
3984 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
3985 q_ptr->type = QUEST_TYPE_KILL_ALL;
3992 /* Process "Q:<q_index>:N:<name>" -- quest name */
3993 else if (zz[1][0] == 'N')
3995 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
3997 strcpy(q_ptr->name, zz[2]);
4003 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4004 else if (zz[1][0] == 'T')
4006 if (init_flags & INIT_SHOW_TEXT)
4008 strcpy(quest_text[quest_text_line], zz[2]);
4016 /* Process "W:<command>: ..." -- info for the wilderness */
4017 else if (buf[0] == 'W')
4019 return parse_line_wilderness(player_ptr, buf, xmin, xmax, y, x);
4022 /* Process "P:<y>:<x>" -- player position */
4023 else if (buf[0] == 'P')
4025 if (init_flags & INIT_CREATE_DUNGEON)
4027 if (tokenize(buf + 2, 2, zz, 0) == 2)
4029 int panels_x, panels_y;
4031 /* Hack - Set the dungeon size */
4032 panels_y = (*y / SCREEN_HGT);
4033 if (*y % SCREEN_HGT) panels_y++;
4034 floor_ptr->height = panels_y * SCREEN_HGT;
4036 panels_x = (*x / SCREEN_WID);
4037 if (*x % SCREEN_WID) panels_x++;
4038 floor_ptr->width = panels_x * SCREEN_WID;
4040 /* Assume illegal panel */
4041 panel_row_min = floor_ptr->height;
4042 panel_col_min = floor_ptr->width;
4044 /* Place player in a quest level */
4045 if (floor_ptr->inside_quest)
4049 /* Delete the monster (if any) */
4050 delete_monster(player_ptr->current_floor_ptr, player_ptr->y, player_ptr->x);
4058 /* Place player in the town */
4059 else if (!player_ptr->oldpx && !player_ptr->oldpy)
4061 player_ptr->oldpy = atoi(zz[0]);
4062 player_ptr->oldpx = atoi(zz[1]);
4070 /* Process "B:<Index>:<Command>:..." -- Building definition */
4071 else if (buf[0] == 'B')
4073 return parse_line_building(buf);
4076 /* Process "M:<type>:<maximum>" -- set maximum values */
4077 else if (buf[0] == 'M')
4079 if (tokenize(buf + 2, 2, zz, 0) == 2)
4082 if (zz[0][0] == 'T')
4084 max_towns = (TOWN_IDX)atoi(zz[1]);
4087 /* Maximum quests */
4088 else if (zz[0][0] == 'Q')
4090 max_q_idx = (QUEST_IDX)atoi(zz[1]);
4094 else if (zz[0][0] == 'R')
4096 max_r_idx = (RACE_IDX)atoi(zz[1]);
4100 else if (zz[0][0] == 'K')
4102 max_k_idx = (KIND_OBJECT_IDX)atoi(zz[1]);
4106 else if (zz[0][0] == 'V')
4108 max_v_idx = (VAULT_IDX)atoi(zz[1]);
4112 else if (zz[0][0] == 'F')
4114 max_f_idx = (FEAT_IDX)atoi(zz[1]);
4118 else if (zz[0][0] == 'A')
4120 max_a_idx = (ARTIFACT_IDX)atoi(zz[1]);
4124 else if (zz[0][0] == 'E')
4126 max_e_idx = (EGO_IDX)atoi(zz[1]);
4130 else if (zz[0][0] == 'D')
4132 current_world_ptr->max_d_idx = (DUNGEON_IDX)atoi(zz[1]);
4136 else if (zz[0][0] == 'O')
4138 current_world_ptr->max_o_idx = (OBJECT_IDX)atoi(zz[1]);
4142 else if (zz[0][0] == 'M')
4144 current_world_ptr->max_m_idx = (MONSTER_IDX)atoi(zz[1]);
4147 /* Wilderness size */
4148 else if (zz[0][0] == 'W')
4150 /* Maximum wild_x_size */
4151 if (zz[0][1] == 'X')
4152 current_world_ptr->max_wild_x = (POSITION)atoi(zz[1]);
4153 /* Maximum wild_y_size */
4154 if (zz[0][1] == 'Y')
4155 current_world_ptr->max_wild_y = (POSITION)atoi(zz[1]);
4166 * todo ここから先頭に移すとコンパイル警告が出る……
4169 static concptr variant = "ZANGBAND";
4172 * @brief クエスト用固定ダンジョン生成時の分岐処理
4173 * Helper function for "process_dungeon_file()"
4174 * @param player_ptr プレーヤーへの参照ポインタ
4179 static concptr process_dungeon_file_expr(player_type *player_ptr, char **sp, char *fp)
4190 while (iswspace(*s)) s++;
4197 concptr v = "?o?o?";
4209 t = process_dungeon_file_expr(player_ptr, &s, &f);
4217 else if (streq(t, "IOR"))
4220 while (*s && (f != b2))
4222 t = process_dungeon_file_expr(player_ptr, &s, &f);
4223 if (*t && !streq(t, "0")) v = "1";
4228 else if (streq(t, "AND"))
4231 while (*s && (f != b2))
4233 t = process_dungeon_file_expr(player_ptr, &s, &f);
4234 if (*t && streq(t, "0")) v = "0";
4239 else if (streq(t, "NOT"))
4242 while (*s && (f != b2))
4244 t = process_dungeon_file_expr(player_ptr, &s, &f);
4245 if (*t && streq(t, "1")) v = "0";
4250 else if (streq(t, "EQU"))
4253 if (*s && (f != b2))
4255 t = process_dungeon_file_expr(player_ptr, &s, &f);
4257 while (*s && (f != b2))
4259 p = process_dungeon_file_expr(player_ptr, &s, &f);
4260 if (streq(t, p)) v = "1";
4265 else if (streq(t, "LEQ"))
4268 if (*s && (f != b2))
4270 t = process_dungeon_file_expr(player_ptr, &s, &f);
4272 while (*s && (f != b2))
4275 t = process_dungeon_file_expr(player_ptr, &s, &f);
4276 if (*t && atoi(p) > atoi(t)) v = "0";
4281 else if (streq(t, "GEQ"))
4284 if (*s && (f != b2))
4286 t = process_dungeon_file_expr(player_ptr, &s, &f);
4288 while (*s && (f != b2))
4291 t = process_dungeon_file_expr(player_ptr, &s, &f);
4293 /* Compare two numbers instead of string */
4294 if (*t && atoi(p) < atoi(t)) v = "0";
4300 while (*s && (f != b2))
4302 t = process_dungeon_file_expr(player_ptr, &s, &f);
4307 if (f != b2) v = "?x?x?";
4309 /* Extract final and Terminate */
4310 if ((f = *s) != '\0') *s++ = '\0';
4317 /* Accept all printables except spaces and brackets */
4319 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4321 if (iskanji(*s)) s++;
4325 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4328 /* Extract final and Terminate */
4329 if ((f = *s) != '\0') *s++ = '\0';
4341 if (streq(b + 1, "SYS"))
4347 else if (streq(b + 1, "GRAF"))
4352 else if (streq(b + 1, "MONOCHROME"))
4361 else if (streq(b + 1, "RACE"))
4363 v = _(rp_ptr->E_title, rp_ptr->title);
4367 else if (streq(b + 1, "CLASS"))
4369 v = _(cp_ptr->E_title, cp_ptr->title);
4373 else if (streq(b + 1, "REALM1"))
4375 v = _(E_realm_names[player_ptr->realm1], realm_names[player_ptr->realm1]);
4379 else if (streq(b + 1, "REALM2"))
4381 v = _(E_realm_names[player_ptr->realm2], realm_names[player_ptr->realm2]);
4385 else if (streq(b + 1, "PLAYER"))
4387 static char tmp_player_name[32];
4389 for (pn = player_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4399 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4402 v = tmp_player_name;
4406 else if (streq(b + 1, "TOWN"))
4408 sprintf(tmp, "%d", player_ptr->town_num);
4413 else if (streq(b + 1, "LEVEL"))
4415 sprintf(tmp, "%d", player_ptr->lev);
4419 /* Current quest number */
4420 else if (streq(b + 1, "QUEST_NUMBER"))
4422 sprintf(tmp, "%d", player_ptr->current_floor_ptr->inside_quest);
4426 /* Number of last quest */
4427 else if (streq(b + 1, "LEAVING_QUEST"))
4429 sprintf(tmp, "%d", leaving_quest);
4434 else if (prefix(b + 1, "QUEST_TYPE"))
4436 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4437 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
4442 else if (prefix(b + 1, "QUEST"))
4444 /* "QUEST" uses a special parameter to determine the number of the quest */
4445 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
4450 else if (prefix(b + 1, "RANDOM"))
4452 /* "RANDOM" uses a special parameter to determine the number of the quest */
4453 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
4458 else if (streq(b + 1, "VARIANT"))
4464 else if (streq(b + 1, "WILDERNESS"))
4467 sprintf(tmp, "NONE");
4469 sprintf(tmp, "LITE");
4471 sprintf(tmp, "NORMAL");
4482 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4483 * Helper function for "process_dungeon_file()"
4484 * @param player_ptr プレーヤーへの参照ポインタ
4492 errr process_dungeon_file(player_type *player_ptr, concptr name, int ymin, int xmin, int ymax, int xmax)
4495 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4497 fp = my_fopen(buf, "r");
4502 /* Process the file */
4505 bool bypass = FALSE;
4506 int x = xmin, y = ymin;
4507 while (my_fgets(fp, buf, sizeof(buf)) == 0)
4513 /* Skip "empty" lines */
4514 if (!buf[0]) continue;
4516 /* Skip "blank" lines */
4517 if (iswspace(buf[0])) continue;
4520 if (buf[0] == '#') continue;
4523 /* Process "?:<expr>" */
4524 if ((buf[0] == '?') && (buf[1] == ':'))
4533 /* Parse the expr */
4534 v = process_dungeon_file_expr(player_ptr, &s, &f);
4537 bypass = (streq(v, "0") ? TRUE : FALSE);
4541 /* Apply conditionals */
4542 if (bypass) continue;
4544 /* Process the line */
4545 err = process_dungeon_file_aux(player_ptr, buf, ymin, xmin, ymax, xmax, &y, &x);
4552 concptr oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4553 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4554 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);