3 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file is used to initialize various variables and arrays for the
16 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
17 * the common limitation of "read()" and "write()" to only 32767 bytes
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
28 * The code could actually be removed and placed into a "stand-alone"
29 * program, but that feels a little silly, especially considering some
30 * of the platforms that we currently support.
39 #include "dungeon-file.h"
40 #include "rooms-vault.h"
46 #include "player-skill.h"
47 #include "player-race.h"
52 #include "rooms-vault.h"
53 #include "objectkind.h"
54 #include "object-ego.h"
55 #include "monsterrace.h"
56 #include "floor-town.h"
61 #include "cmd-activate.h"
64 #include "view-mainwindow.h"
65 #include "player-class.h"
69 dungeon_grid letter[255];
71 /*** Helper arrays for parsing ascii template files ***/
75 * Monster Blow Methods
77 static concptr r_info_blow_method[] =
109 * モンスターの打撃属性トークンの定義 /
110 * Monster Blow Effects
112 static concptr r_info_blow_effect[] =
157 static concptr f_info_flags[] =
281 static concptr r_info_flags1[] =
321 static concptr r_info_flags2[] =
361 static concptr r_info_flags3[] =
401 static concptr r_info_flags4[] =
438 * モンスター特性トークン(発動型能力1) /
441 static concptr r_a_ability_flags1[] =
478 * モンスター特性トークン(発動型能力2) /
481 static concptr r_a_ability_flags2[] =
498 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
521 static concptr r_info_flags7[] =
561 static concptr r_info_flags8[] =
593 "WILD_SWAMP", /* ToDo: Implement Swamp */
601 static concptr r_info_flags9[] =
639 * モンスター特性トークンの定義R(耐性) /
642 static concptr r_info_flagsr[] =
679 * オブジェクト基本特性トークンの定義 /
682 static concptr k_info_flags[] =
779 "XXX3", /* Fake flag for Smith */
780 "XXX4", /* Fake flag for Smith */
830 * オブジェクト生成特性トークンの定義 /
833 static concptr k_info_gen_flags[] =
873 static concptr d_info_flags1[] =
910 * @brief データの可変文字列情報をテキストとして保管する /
911 * Add a text to the text-storage and store offset to it.
912 * @param offset 文字列保管ポインタからのオフセット
913 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
915 * @param normal_text テキストの正規化を行う
918 * Returns FALSE when there isn't enough space available to store
921 static bool add_text(u32b *offset, header *head, concptr buf, bool normal_text)
923 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
928 *offset = ++head->text_size;
930 else if (normal_text)
933 * If neither the end of the last line nor
934 * the beginning of current line is not a space,
935 * fill up a space as a correct separator of two words.
937 if (head->text_size > 0 &&
939 (*(head->text_ptr + head->text_size - 1) != ' ') &&
940 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
941 (buf[0] != ' ') && !iskanji(buf[0])
943 (*(head->text_ptr + head->text_size - 1) != ' ') &&
948 *(head->text_ptr + head->text_size) = ' ';
953 strcpy(head->text_ptr + head->text_size, buf);
954 head->text_size += strlen(buf);
960 * @brief データの可変文字列情報を名前として保管する /
961 * Add a name to the name-storage and return an offset to it.
962 * @param offset 文字列保管ポインタからのオフセット
963 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
967 * Returns FALSE when there isn't enough space available to store
970 static bool add_name(u32b *offset, header *head, concptr buf)
972 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
977 *offset = ++head->name_size;
980 strcpy(head->name_ptr + head->name_size, buf);
981 head->name_size += strlen(buf);
987 * @brief データの可変文字列情報をタグとして保管する /
988 * Add a tag to the tag-storage and return an offset to it.
989 * @param offset 文字列保管ポインタからのオフセット
990 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
994 * Returns FALSE when there isn't enough space available to store
997 static bool add_tag(STR_OFFSET *offset, header *head, concptr buf)
1000 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1002 if (streq(&head->tag_ptr[i], buf)) break;
1005 if (i >= head->tag_size)
1007 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1010 strcpy(head->tag_ptr + head->tag_size, buf);
1012 head->tag_size += strlen(buf) + 1;
1021 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1022 * Initialize an "*_info" array, by parsing an ascii "template" file
1023 * @param fp 読み取りに使うファイルポインタ
1024 * @param buf 読み取りに使うバッファ領域
1025 * @param head ヘッダ構造体
1026 * @param parse_info_txt_line パース関数
1029 errr init_info_txt(FILE *fp, char *buf, header *head, parse_info_txt_func parse_info_txt_line)
1034 head->name_size = 0;
1035 head->text_size = 0;
1039 while (my_fgets(fp, buf, 1024) == 0)
1042 if (!buf[0] || (buf[0] == '#')) continue;
1044 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1051 if (buf[0] != 'N' && buf[0] != 'D')
1054 for (i = 0; buf[i]; i++)
1056 head->v_extra += (byte)buf[i];
1057 head->v_extra ^= (1 << (i % 8));
1061 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1065 if (head->name_size) head->name_size++;
1066 if (head->text_size) head->text_size++;
1073 * @brief Vault情報(v_info)のパース関数 /
1074 * Initialize the "v_info" array, by parsing an ascii "template" file
1076 * @param head ヘッダ構造体
1079 errr parse_v_info(char *buf, header *head)
1082 static vault_type *v_ptr = NULL;
1086 s = my_strchr(buf + 2, ':');
1092 int i = atoi(buf + 2);
1093 if (i <= error_idx) return 4;
1094 if (i >= head->info_num) return 2;
1098 if (!add_name(&v_ptr->name, head, s)) return 7;
1100 else if (!v_ptr) return 3;
1101 else if (buf[0] == 'D')
1104 if (!add_text(&v_ptr->text, head, s, FALSE)) return 7;
1106 else if (buf[0] == 'X')
1108 EFFECT_ID typ, rat, hgt, wid;
1109 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1110 &typ, &rat, &hgt, &wid)) return 1;
1112 v_ptr->typ = (ROOM_IDX)typ;
1113 v_ptr->rat = (PROB)rat;
1114 v_ptr->hgt = (POSITION)hgt;
1115 v_ptr->wid = (POSITION)wid;
1125 * @brief 職業技能情報(s_info)のパース関数 /
1126 * Initialize the "s_info" array, by parsing an ascii "template" file
1128 * @param head ヘッダ構造体
1131 errr parse_s_info(char *buf, header *head)
1133 static skill_table *s_ptr = NULL;
1136 int i = atoi(buf + 2);
1137 if (i <= error_idx) return 4;
1138 if (i >= head->info_num) return 2;
1147 else if (buf[0] == 'W')
1149 int tval, sval, start, max;
1150 const s16b exp_conv_table[] =
1152 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1153 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1156 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1157 &tval, &sval, &start, &max)) return 1;
1159 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1160 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return 8;
1162 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1163 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1165 else if (buf[0] == 'S')
1167 int num, start, max;
1168 if (3 != sscanf(buf + 2, "%d:%d:%d",
1169 &num, &start, &max)) return 1;
1171 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1172 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return 8;
1174 s_ptr->s_start[num] = (SUB_EXP)start;
1175 s_ptr->s_max[num] = (SUB_EXP)max;
1185 * @brief 職業魔法情報(m_info)のパース関数 /
1186 * Initialize the "m_info" array, by parsing an ascii "template" file
1188 * @param head ヘッダ構造体
1191 errr parse_m_info(char *buf, header *head)
1193 static player_magic *m_ptr = NULL;
1194 static int realm, magic_idx = 0, readable = 0;
1198 int i = atoi(buf + 2);
1200 if (i <= error_idx) return 4;
1201 if (i >= head->info_num) return 2;
1210 else if (buf[0] == 'I')
1213 int xtra, type, first, weight;
1215 s = my_strchr(buf + 2, ':');
1217 /* Verify that colon */
1220 /* Nuke the colon, advance to the name */
1225 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1226 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1227 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1228 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1229 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1233 s = my_strchr(s, ':');
1237 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1238 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1239 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1240 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1241 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1242 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1245 if (4 != sscanf(s, "%x:%d:%d:%d",
1246 (uint *)&xtra, &type, &first, &weight)) return 1;
1248 m_ptr->spell_xtra = xtra;
1249 m_ptr->spell_type = type;
1250 m_ptr->spell_first = first;
1251 m_ptr->spell_weight = weight;
1253 else if (buf[0] == 'R')
1255 if (2 != sscanf(buf + 2, "%d:%d",
1256 &realm, &readable)) return 1;
1260 else if (buf[0] == 'T')
1262 int level, mana, fail, exp;
1264 if (!readable) return 1;
1265 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
1266 &level, &mana, &fail, &exp)) return 1;
1268 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1269 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1270 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1271 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1282 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1283 * Grab one flag from a textual string
1284 * @param flags ビットフラグを追加する先の参照ポインタ
1285 * @param names トークン定義配列
1286 * @param what 参照元の文字列ポインタ
1289 static errr grab_one_flag(u32b *flags, concptr names[], concptr what)
1291 for (int i = 0; i < 32; i++)
1293 if (streq(what, names[i]))
1295 *flags |= (1L << i);
1305 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1306 * Grab one flag in an feature_type from a textual string
1307 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1308 * @param what 参照元の文字列ポインタ
1311 static errr grab_one_feat_flag(feature_type *f_ptr, concptr what)
1313 for (int i = 0; i < FF_FLAG_MAX; i++)
1315 if (streq(what, f_info_flags[i]))
1317 add_flag(f_ptr->flags, i);
1322 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1323 return PARSE_ERROR_GENERIC;
1328 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1329 * Grab an action in an feature_type from a textual string
1330 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1331 * @param what 参照元の文字列ポインタ
1332 * @param count ステートの保存先ID
1335 static errr grab_one_feat_action(feature_type *f_ptr, concptr what, int count)
1337 for (FF_FLAGS_IDX i = 0; i < FF_FLAG_MAX; i++)
1339 if (streq(what, f_info_flags[i]))
1341 f_ptr->state[count].action = i;
1346 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1347 return PARSE_ERROR_GENERIC;
1352 * @brief 地形情報(f_info)のパース関数 /
1353 * Initialize the "f_info" array, by parsing an ascii "template" file
1355 * @param head ヘッダ構造体
1358 errr parse_f_info(char *buf, header *head)
1360 static feature_type *f_ptr = NULL;
1365 s = my_strchr(buf + 2, ':');
1373 if (i <= error_idx) return 4;
1374 if (i >= head->info_num) return 2;
1380 if (!add_tag(&f_ptr->tag, head, s)) return 7;
1383 f_ptr->mimic = (FEAT_IDX)i;
1384 f_ptr->destroyed = (FEAT_IDX)i;
1385 for (i = 0; i < MAX_FEAT_STATES; i++)
1386 f_ptr->state[i].action = FF_FLAG_MAX;
1393 else if (buf[0] == 'J')
1395 if (!add_name(&f_ptr->name, head, buf + 2)) return 7;
1397 else if (buf[0] == 'E')
1401 else if (buf[0] == 'J')
1404 else if (buf[0] == 'E')
1407 if (!add_name(&f_ptr->name, head, s)) return 7;
1410 else if (buf[0] == 'M')
1413 if (!add_tag(&offset, head, buf + 2))
1414 return PARSE_ERROR_OUT_OF_MEMORY;
1416 f_ptr->mimic_tag = offset;
1418 else if (buf[0] == 'G')
1422 char char_tmp[F_LIT_MAX];
1423 if (buf[1] != ':') return 1;
1424 if (!buf[2]) return 1;
1425 if (buf[3] != ':') return 1;
1426 if (!buf[4]) return 1;
1428 char_tmp[F_LIT_STANDARD] = buf[2];
1429 s_attr = color_char_to_attr(buf[4]);
1430 if (s_attr > 127) return 1;
1432 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1433 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1436 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1437 if (!streq(buf + 6, "LIT"))
1439 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1441 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1442 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1443 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1444 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1446 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1448 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1451 /* Use default lighting */
1454 /* No lighting support */
1455 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1458 /* Extract the color */
1459 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1460 if (f_ptr->d_attr[j] > 127) return 1;
1463 f_ptr->d_char[j] = char_tmp[j];
1469 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1471 f_ptr->d_attr[j] = s_attr;
1472 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1477 else if (buf[0] == 'F')
1479 for (s = buf + 2; *s; )
1482 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
1487 while (*t == ' ' || *t == '|') t++;
1490 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1492 f_ptr->subtype = (FEAT_SUBTYPE)i;
1498 if (1 == sscanf(s, "POWER_%d", &i))
1500 f_ptr->power = (FEAT_POWER)i;
1505 if (0 != grab_one_feat_flag(f_ptr, s))
1506 return (PARSE_ERROR_INVALID_FLAG);
1511 else if (buf[0] == 'W')
1514 if (1 != sscanf(buf + 2, "%d", &priority))
1515 return (PARSE_ERROR_GENERIC);
1516 f_ptr->priority = (FEAT_PRIORITY)priority;
1518 else if (buf[0] == 'K')
1521 for (i = 0; i < MAX_FEAT_STATES; i++)
1522 if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1524 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1527 for (s = t = buf + 2; *t && (*t != ':'); t++);
1529 if (*t == ':') *t++ = '\0';
1531 if (streq(s, "DESTROYED"))
1533 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1535 f_ptr->destroyed_tag = offset;
1539 f_ptr->state[i].action = 0;
1540 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1541 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1543 f_ptr->state[i].result_tag = offset;
1556 * @brief 地形タグからIDを得る /
1557 * Convert a fake tag to a real feat index
1561 s16b f_tag_to_index(concptr str)
1563 for (u16b i = 0; i < f_head.info_num; i++)
1565 if (streq(f_tag + f_info[i].tag, str))
1576 * @brief 地形タグからIDを得る /
1577 * Search for real index corresponding to this fake tag
1578 * @param feat タグ文字列のオフセット
1579 * @return 地形ID。該当がないなら-1
1581 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1588 for (FEAT_IDX i = 0; i < f_head.info_num; i++)
1590 if (feat == f_info[i].tag)
1596 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1602 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1603 * Retouch fake tags of f_info
1604 * @param head ヘッダ構造体
1607 void retouch_f_info(header *head)
1609 for (int i = 0; i < head->info_num; i++)
1611 feature_type *f_ptr = &f_info[i];
1612 FEAT_IDX k = search_real_feat(f_ptr->mimic_tag);
1613 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1614 k = search_real_feat(f_ptr->destroyed_tag);
1615 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1616 for (FEAT_IDX j = 0; j < MAX_FEAT_STATES; j++)
1618 k = search_real_feat(f_ptr->state[j].result_tag);
1619 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
1626 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1627 * Grab one flag in an object_kind from a textual string
1628 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1629 * @param what 参照元の文字列ポインタ
1632 static errr grab_one_kind_flag(object_kind *k_ptr, concptr what)
1634 for (int i = 0; i < TR_FLAG_MAX; i++)
1636 if (streq(what, k_info_flags[i]))
1638 add_flag(k_ptr->flags, i);
1643 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1646 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
1652 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
1653 * Grab one activation index flag
1654 * @param what 参照元の文字列ポインタ
1657 static byte grab_one_activation_flag(concptr what)
1659 for (int i = 0; ; i++)
1661 if (activation_info[i].flag == NULL) break;
1663 if (streq(what, activation_info[i].flag))
1665 return activation_info[i].index;
1675 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
1681 * @brief ベースアイテム(k_info)のパース関数 /
1682 * Initialize the "k_info" array, by parsing an ascii "template" file
1684 * @param head ヘッダ構造体
1687 errr parse_k_info(char *buf, header *head)
1689 static object_kind *k_ptr = NULL;
1697 s = my_strchr(buf + 2, ':');
1701 int i = atoi(buf + 2);
1703 if (i <= error_idx) return 4;
1704 if (i >= head->info_num) return 2;
1712 flavor = my_strchr(s, ':');
1716 if (!add_name(&k_ptr->flavor_name, head, flavor)) return 7;
1719 if (!add_name(&k_ptr->name, head, s)) return 7;
1728 /* 'E' から始まる行は英語名としている */
1729 else if (buf[0] == 'E')
1734 else if (buf[0] == 'E')
1738 flavor = my_strchr(s, ':');
1742 if (!add_name(&k_ptr->flavor_name, head, flavor)) return 7;
1745 if (!add_name(&k_ptr->name, head, s)) return 7;
1748 else if (buf[0] == 'D')
1759 if (!add_text(&k_ptr->text, head, s, TRUE)) return 7;
1761 else if (buf[0] == 'G')
1765 if (buf[1] != ':') return 1;
1766 if (!buf[2]) return 1;
1767 if (buf[3] != ':') return 1;
1768 if (!buf[4]) return 1;
1771 tmp = color_char_to_attr(buf[4]);
1772 if (tmp > 127) return 1;
1774 k_ptr->d_attr = tmp;
1775 k_ptr->d_char = sym;
1777 else if (buf[0] == 'I')
1779 int tval, sval, pval;
1780 if (3 != sscanf(buf + 2, "%d:%d:%d",
1781 &tval, &sval, &pval)) return 1;
1783 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
1784 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
1785 k_ptr->pval = (PARAMETER_VALUE)pval;
1787 else if (buf[0] == 'W')
1789 int level, extra, wgt;
1791 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
1792 &level, &extra, &wgt, &cost)) return 1;
1794 k_ptr->level = (DEPTH)level;
1795 k_ptr->extra = (BIT_FLAGS8)extra;
1796 k_ptr->weight = (WEIGHT)wgt;
1797 k_ptr->cost = (PRICE)cost;
1799 else if (buf[0] == 'A')
1802 for (s = buf + 1; s && (s[0] == ':') && s[1]; ++i)
1804 k_ptr->chance[i] = 1;
1805 k_ptr->locale[i] = atoi(s + 1);
1806 t = my_strchr(s + 1, '/');
1807 s = my_strchr(s + 1, ':');
1808 if (t && (!s || t < s))
1810 int chance = atoi(t + 1);
1811 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
1815 else if (buf[0] == 'P')
1817 int ac, hd1, hd2, th, td, ta;
1818 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
1819 &ac, &hd1, &hd2, &th, &td, &ta)) return 1;
1821 k_ptr->ac = (ARMOUR_CLASS)ac;
1822 k_ptr->dd = (DICE_NUMBER)hd1;
1823 k_ptr->ds = (DICE_SID)hd2;
1824 k_ptr->to_h = (HIT_PROB)th;
1825 k_ptr->to_d = (HIT_POINT)td;
1826 k_ptr->to_a = (ARMOUR_CLASS)ta;
1828 else if (buf[0] == 'U')
1831 n = grab_one_activation_flag(buf + 2);
1841 else if (buf[0] == 'F')
1843 for (s = buf + 2; *s; )
1846 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
1851 while (*t == ' ' || *t == '|') t++;
1854 if (0 != grab_one_kind_flag(k_ptr, s)) return 5;
1868 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
1869 * Grab one activation index flag
1870 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
1871 * @param what 参照元の文字列ポインタ
1872 * @return エラーがあった場合1、エラーがない場合0を返す
1874 static errr grab_one_artifact_flag(artifact_type *a_ptr, concptr what)
1876 for (int i = 0; i < TR_FLAG_MAX; i++)
1878 if (streq(what, k_info_flags[i]))
1880 add_flag(a_ptr->flags, i);
1885 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
1888 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
1894 * @brief 固定アーティファクト情報(a_info)のパース関数 /
1895 * Initialize the "a_info" array, by parsing an ascii "template" file
1897 * @param head ヘッダ構造体
1900 errr parse_a_info(char *buf, header *head)
1902 static artifact_type *a_ptr = NULL;
1906 s = my_strchr(buf + 2, ':');
1913 int i = atoi(buf + 2);
1914 if (i < error_idx) return 4;
1915 if (i >= head->info_num) return 2;
1919 add_flag(a_ptr->flags, TR_IGNORE_ACID);
1920 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
1921 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
1922 add_flag(a_ptr->flags, TR_IGNORE_COLD);
1924 if (!add_name(&a_ptr->name, head, s)) return 7;
1933 /* 'E' から始まる行は英語名としている */
1934 else if (buf[0] == 'E')
1939 else if (buf[0] == 'E')
1942 if (!add_name(&a_ptr->name, head, s)) return 7;
1945 else if (buf[0] == 'D')
1956 if (!add_text(&a_ptr->text, head, s, TRUE)) return 7;
1958 else if (buf[0] == 'I')
1960 int tval, sval, pval;
1961 if (3 != sscanf(buf + 2, "%d:%d:%d",
1962 &tval, &sval, &pval)) return 1;
1964 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
1965 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
1966 a_ptr->pval = (PARAMETER_VALUE)pval;
1968 else if (buf[0] == 'W')
1970 int level, rarity, wgt;
1972 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
1973 &level, &rarity, &wgt, &cost)) return 1;
1975 a_ptr->level = (DEPTH)level;
1976 a_ptr->rarity = (RARITY)rarity;
1977 a_ptr->weight = (WEIGHT)wgt;
1978 a_ptr->cost = (PRICE)cost;
1980 else if (buf[0] == 'P')
1982 int ac, hd1, hd2, th, td, ta;
1983 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
1984 &ac, &hd1, &hd2, &th, &td, &ta)) return 1;
1986 a_ptr->ac = (ARMOUR_CLASS)ac;
1987 a_ptr->dd = (DICE_NUMBER)hd1;
1988 a_ptr->ds = (DICE_SID)hd2;
1989 a_ptr->to_h = (HIT_PROB)th;
1990 a_ptr->to_d = (HIT_POINT)td;
1991 a_ptr->to_a = (ARMOUR_CLASS)ta;
1993 else if (buf[0] == 'U')
1996 n = grab_one_activation_flag(buf + 2);
2006 else if (buf[0] == 'F')
2008 for (s = buf + 2; *s; )
2011 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2016 while ((*t == ' ') || (*t == '|')) t++;
2019 if (0 != grab_one_artifact_flag(a_ptr, s)) return 5;
2034 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2035 * Grab one flag in a ego-item_type from a textual string
2036 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2037 * @param what 参照元の文字列ポインタ
2038 * @return エラーがあった場合1、エラーがない場合0を返す
2040 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, concptr what)
2042 for (int i = 0; i < TR_FLAG_MAX; i++)
2044 if (streq(what, k_info_flags[i]))
2046 add_flag(e_ptr->flags, i);
2051 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2054 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2060 * @brief アイテムエゴ情報(e_info)のパース関数 /
2061 * Initialize the "e_info" array, by parsing an ascii "template" file
2063 * @param head ヘッダ構造体
2066 errr parse_e_info(char *buf, header *head)
2068 static ego_item_type *e_ptr = NULL;
2074 s = my_strchr(buf + 2, ':');
2081 int i = atoi(buf + 2);
2082 if (i < error_idx) return 4;
2083 if (i >= head->info_num) return 2;
2088 if (!add_name(&e_ptr->name, head, s)) return 7;
2097 /* 'E' から始まる行は英語名 */
2098 else if (buf[0] == 'E')
2103 else if (buf[0] == 'E')
2106 if (!add_name(&e_ptr->name, head, s)) return 7;
2109 else if (buf[0] == 'X')
2112 if (2 != sscanf(buf + 2, "%d:%d",
2113 &slot, &rating)) return 1;
2115 e_ptr->slot = (INVENTORY_IDX)slot;
2116 e_ptr->rating = (PRICE)rating;
2118 else if (buf[0] == 'W')
2120 int level, rarity, pad2;
2123 if (4 != sscanf(buf + 2, "%d:%d:%d:%ld",
2124 &level, &rarity, &pad2, &cost)) return 1;
2126 e_ptr->level = level;
2127 e_ptr->rarity = (RARITY)rarity;
2130 else if (buf[0] == 'C')
2132 int th, td, ta, pval;
2134 if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
2135 &th, &td, &ta, &pval)) return 1;
2137 e_ptr->max_to_h = (HIT_PROB)th;
2138 e_ptr->max_to_d = (HIT_POINT)td;
2139 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2140 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2142 else if (buf[0] == 'U')
2145 n = grab_one_activation_flag(buf + 2);
2155 else if (buf[0] == 'F')
2157 for (s = buf + 2; *s; )
2160 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2165 while ((*t == ' ') || (*t == '|')) t++;
2168 if (0 != grab_one_ego_item_flag(e_ptr, s)) return 5;
2183 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2184 * Grab one (basic) flag in a monster_race from a textual string
2185 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2186 * @param what 参照元の文字列ポインタ
2189 static errr grab_one_basic_flag(monster_race *r_ptr, concptr what)
2191 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2194 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2197 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2200 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2203 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2206 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2209 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2212 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2218 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2219 * Grab one (spell) flag in a monster_race from a textual string
2220 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2221 * @param what 参照元の文字列ポインタ
2224 static errr grab_one_spell_flag(monster_race *r_ptr, concptr what)
2226 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2229 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2232 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2235 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2241 * @brief モンスター種族情報(r_info)のパース関数 /
2242 * Initialize the "r_info" array, by parsing an ascii "template" file
2244 * @param head ヘッダ構造体
2247 errr parse_r_info(char *buf, header *head)
2249 static monster_race *r_ptr = NULL;
2253 s = my_strchr(buf + 2, ':');
2261 int i = atoi(buf + 2);
2262 if (i < error_idx) return 4;
2263 if (i >= head->info_num) return 2;
2268 if (!add_name(&r_ptr->name, head, s)) return 7;
2277 /* 'E' から始まる行は英語名 */
2278 else if (buf[0] == 'E')
2281 if (!add_name(&r_ptr->E_name, head, s)) return 7;
2284 else if (buf[0] == 'E')
2287 if (!add_name(&r_ptr->name, head, s)) return 7;
2290 else if (buf[0] == 'D')
2301 if (!add_text(&r_ptr->text, head, s, TRUE)) return 7;
2303 else if (buf[0] == 'G')
2305 if (buf[1] != ':') return 1;
2306 if (!buf[2]) return 1;
2307 if (buf[3] != ':') return 1;
2308 if (!buf[4]) return 1;
2311 byte tmp = color_char_to_attr(buf[4]);
2312 if (tmp > 127) return 1;
2314 r_ptr->d_char = sym;
2315 r_ptr->d_attr = tmp;
2317 else if (buf[0] == 'I')
2319 int spd, hp1, hp2, aaf, ac, slp;
2321 if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d",
2322 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return 1;
2324 r_ptr->speed = (SPEED)spd;
2325 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2326 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2327 r_ptr->aaf = (POSITION)aaf;
2328 r_ptr->ac = (ARMOUR_CLASS)ac;
2329 r_ptr->sleep = (SLEEP_DEGREE)slp;
2331 else if (buf[0] == 'W')
2337 if (6 != sscanf(buf + 2, "%d:%d:%d:%ld:%ld:%d",
2338 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return 1;
2340 r_ptr->level = (DEPTH)lev;
2341 r_ptr->rarity = (RARITY)rar;
2342 r_ptr->extra = (BIT_FLAGS16)pad;
2343 r_ptr->mexp = (EXP)exp;
2344 r_ptr->next_exp = (EXP)nextexp;
2345 r_ptr->next_r_idx = (MONRACE_IDX)nextmon;
2347 else if (buf[0] == 'R')
2351 for (; i < A_MAX; i++) if (r_ptr->reinforce_id[i] == 0) break;
2353 if (i == 6) return 1;
2355 if (3 != sscanf(buf + 2, "%d:%dd%d", &id, &dd, &ds)) return 1;
2356 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
2357 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
2358 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
2360 else if (buf[0] == 'B')
2364 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2366 if (i == 4) return 1;
2369 for (s = t = buf + 2; *t && (*t != ':'); t++);
2371 if (*t == ':') *t++ = '\0';
2373 for (n1 = 0; r_info_blow_method[n1]; n1++)
2375 if (streq(s, r_info_blow_method[n1])) break;
2378 if (!r_info_blow_method[n1]) return 1;
2381 for (s = t; *t && (*t != ':'); t++);
2383 if (*t == ':') *t++ = '\0';
2385 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2387 if (streq(s, r_info_blow_effect[n2])) break;
2390 if (!r_info_blow_effect[n2]) return 1;
2393 for (s = t; *t && (*t != 'd'); t++);
2395 if (*t == 'd') *t++ = '\0';
2397 r_ptr->blow[i].method = (BLOW_METHOD)n1;
2398 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
2399 r_ptr->blow[i].d_dice = atoi(s);
2400 r_ptr->blow[i].d_side = atoi(t);
2402 else if (buf[0] == 'F')
2404 for (s = buf + 2; *s; )
2407 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2412 while (*t == ' ' || *t == '|') t++;
2415 if (0 != grab_one_basic_flag(r_ptr, s)) return 5;
2420 else if (buf[0] == 'S')
2422 for (s = buf + 2; *s; )
2426 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2431 while ((*t == ' ') || (*t == '|')) t++;
2435 if (1 == sscanf(s, "1_IN_%d", &i))
2437 r_ptr->freq_spell = 100 / i;
2442 if (0 != grab_one_spell_flag(r_ptr, s)) return 5;
2447 else if (buf[0] == 'A')
2449 int id, per, rarity;
2451 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
2453 if (i == 4) return 1;
2455 if (3 != sscanf(buf + 2, "%d:%d:%d", &id, &rarity, &per)) return 1;
2456 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
2457 r_ptr->artifact_rarity[i] = (RARITY)rarity;
2458 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
2460 else if (buf[0] == 'V')
2463 if (3 != sscanf(buf + 2, "%d", &val)) return 1;
2464 r_ptr->arena_ratio = (PERCENTAGE)val;
2476 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
2477 * Grab one flag for a dungeon type from a textual string
2478 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
2479 * @param what 参照元の文字列ポインタ
2482 static errr grab_one_dungeon_flag(dungeon_type *d_ptr, concptr what)
2484 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
2487 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
2493 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
2494 * Grab one (basic) flag in a monster_race from a textual string
2495 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
2496 * @param what 参照元の文字列ポインタ
2499 static errr grab_one_basic_monster_flag(dungeon_type *d_ptr, concptr what)
2501 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
2504 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
2507 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
2510 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
2513 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
2516 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
2519 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
2522 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2528 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
2529 * Grab one (spell) flag in a monster_race from a textual string
2530 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
2531 * @param what 参照元の文字列ポインタ
2534 static errr grab_one_spell_monster_flag(dungeon_type *d_ptr, concptr what)
2536 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
2539 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
2542 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
2545 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2551 * @brief ダンジョン情報(d_info)のパース関数 /
2552 * Initialize the "d_info" array, by parsing an ascii "template" file
2554 * @param head ヘッダ構造体
2557 errr parse_d_info(char *buf, header *head)
2559 static dungeon_type *d_ptr = NULL;
2563 s = my_strchr(buf + 2, ':');
2571 int i = atoi(buf + 2);
2572 if (i < error_idx) return 4;
2573 if (i >= head->info_num) return 2;
2578 if (!add_name(&d_ptr->name, head, s)) return 7;
2582 else if (buf[0] == 'E') return 0;
2584 else if (buf[0] == 'E')
2586 /* Acquire the Text */
2589 /* Store the name */
2590 if (!add_name(&d_ptr->name, head, s)) return 7;
2593 else if (buf[0] == 'D')
2604 if (!add_text(&d_ptr->text, head, s, TRUE)) return 7;
2606 else if (buf[0] == 'W')
2608 int min_lev, max_lev;
2610 int min_alloc, max_chance;
2611 int obj_good, obj_great;
2614 if (10 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2615 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return 1;
2617 d_ptr->mindepth = (DEPTH)min_lev;
2618 d_ptr->maxdepth = (DEPTH)max_lev;
2619 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
2620 d_ptr->mode = (BIT_FLAGS8)mode;
2621 d_ptr->min_m_alloc_level = min_alloc;
2622 d_ptr->max_m_alloc_chance = max_chance;
2623 d_ptr->obj_good = obj_good;
2624 d_ptr->obj_great = obj_great;
2625 d_ptr->pit = (BIT_FLAGS16)pit;
2626 d_ptr->nest = (BIT_FLAGS16)nest;
2628 else if (buf[0] == 'P')
2631 if (2 != sscanf(buf + 2, "%d:%d", &dy, &dx)) return 1;
2636 else if (buf[0] == 'L')
2639 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return 1;
2641 for (int i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
2643 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
2644 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2646 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
2649 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
2651 else if (buf[0] == 'A')
2654 if (tokenize(buf + 2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return 1;
2656 for (int i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
2658 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
2659 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2661 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
2664 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
2665 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2667 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
2668 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2670 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
2671 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2673 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
2674 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2676 else if (buf[0] == 'F')
2678 int artif = 0, monst = 0;
2680 for (s = buf + 2; *s; )
2683 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2688 while (*t == ' ' || *t == '|') t++;
2691 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
2693 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
2698 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
2700 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
2705 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
2707 d_ptr->final_guardian = (MONRACE_IDX)monst;
2712 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
2714 d_ptr->special_div = (PROB)monst;
2719 if (0 != grab_one_dungeon_flag(d_ptr, s)) return 5;
2724 else if (buf[0] == 'M')
2726 for (s = buf + 2; *s; )
2729 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2734 while (*t == ' ' || *t == '|') t++;
2737 if (!strncmp(s, "R_CHAR_", 7))
2740 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
2745 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return 5;
2750 else if (buf[0] == 'S')
2752 for (s = buf + 2; *s; )
2755 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t);
2760 while ((*t == ' ') || (*t == '|')) t++;
2764 if (1 == sscanf(s, "1_IN_%d", &i))
2770 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return 5;
2785 * @brief 地形情報の「F:」情報をパースする
2786 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
2787 * @param floor_ptr 現在フロアへの参照ポインタ
2791 static errr parse_line_feature(floor_type *floor_ptr, char *buf)
2793 if (init_flags & INIT_ONLY_BUILDINGS) return 0;
2796 int num = tokenize(buf + 2, 9, zz, 0);
2797 if (num <= 1) return 1;
2799 int index = zz[0][0];
2800 letter[index].feature = feat_none;
2801 letter[index].monster = 0;
2802 letter[index].object = 0;
2803 letter[index].ego = 0;
2804 letter[index].artifact = 0;
2805 letter[index].trap = feat_none;
2806 letter[index].cave_info = 0;
2807 letter[index].special = 0;
2808 letter[index].random = RANDOM_NONE;
2814 letter[index].special = (s16b)atoi(zz[8]);
2816 if ((zz[7][0] == '*') && !zz[7][1])
2818 letter[index].random |= RANDOM_TRAP;
2822 letter[index].trap = f_tag_to_index(zz[7]);
2823 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2826 if (zz[6][0] == '*')
2828 letter[index].random |= RANDOM_ARTIFACT;
2829 if (zz[6][1]) letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6] + 1);
2831 else if (zz[6][0] == '!')
2833 if (floor_ptr->inside_quest)
2835 letter[index].artifact = quest[floor_ptr->inside_quest].k_idx;
2840 letter[index].artifact = (ARTIFACT_IDX)atoi(zz[6]);
2843 if (zz[5][0] == '*')
2845 letter[index].random |= RANDOM_EGO;
2846 if (zz[5][1]) letter[index].ego = (EGO_IDX)atoi(zz[5] + 1);
2850 letter[index].ego = (EGO_IDX)atoi(zz[5]);
2853 if (zz[4][0] == '*')
2855 letter[index].random |= RANDOM_OBJECT;
2856 if (zz[4][1]) letter[index].object = (OBJECT_IDX)atoi(zz[4] + 1);
2858 else if (zz[4][0] == '!')
2860 if (floor_ptr->inside_quest)
2862 ARTIFACT_IDX a_idx = quest[floor_ptr->inside_quest].k_idx;
2865 artifact_type *a_ptr = &a_info[a_idx];
2866 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
2868 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
2875 letter[index].object = (IDX)atoi(zz[4]);
2878 if (zz[3][0] == '*')
2880 letter[index].random |= RANDOM_MONSTER;
2881 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
2883 else if (zz[3][0] == 'c')
2885 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
2886 letter[index].monster = -atoi(zz[3] + 1);
2890 letter[index].monster = (IDX)atoi(zz[3]);
2893 letter[index].cave_info = atoi(zz[2]);
2895 if ((zz[1][0] == '*') && !zz[1][1])
2897 letter[index].random |= RANDOM_FEATURE;
2901 letter[index].feature = f_tag_to_index(zz[1]);
2902 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
2913 * @brief 地形情報の「B:」情報をパースする
2914 * Process "B:<Index>:<Command>:..." -- Building definition
2918 static errr parse_line_building(char *buf)
2932 int index = atoi(s);
2933 s = my_strchr(s, ':');
2943 if (tokenize(s + 2, 3, zz, 0) == 3)
2945 strcpy(building[index].name, zz[0]);
2946 strcpy(building[index].owner_name, zz[1]);
2947 strcpy(building[index].owner_race, zz[2]);
2951 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
2955 if (tokenize(s + 2, 8, zz, 0) >= 7)
2957 int action_index = atoi(zz[0]);
2958 strcpy(building[index].act_names[action_index], zz[1]);
2959 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
2960 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
2961 building[index].letters[action_index] = zz[4][0];
2962 building[index].actions[action_index] = (BACT_IDX)atoi(zz[5]);
2963 building[index].action_restr[action_index] = (BACT_RESTRICT_IDX)atoi(zz[6]);
2967 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
2972 n = tokenize(s + 2, MAX_CLASS, zz, 0);
2973 for (int i = 0; i < MAX_CLASS; i++)
2975 building[index].member_class[i] = ((i < n) ? (CLASS_IDX)atoi(zz[i]) : 1);
2983 n = tokenize(s + 2, MAX_RACES, zz, 0);
2984 for (int i = 0; i < MAX_RACES; i++)
2986 building[index].member_race[i] = ((i < n) ? (RACE_IDX)atoi(zz[i]) : 1);
2994 n = tokenize(s + 2, MAX_MAGIC, zz, 0);
2995 for (int i = 0; i < MAX_MAGIC; i++)
2997 building[index].member_realm[i + 1] = ((i < n) ? (REALM_IDX)atoi(zz[i]) : 1);
3008 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3017 * @brief フロアの所定のマスにオブジェクトを配置する
3018 * Place the object j_ptr to a grid
3019 * @param floor_ptr 現在フロアへの参照ポインタ
3020 * @param j_ptr オブジェクト構造体の参照ポインタ
3025 static void drop_here(floor_type *floor_ptr, object_type *j_ptr, POSITION y, POSITION x)
3027 OBJECT_IDX o_idx = o_pop(floor_ptr);
3029 o_ptr = &floor_ptr->o_list[o_idx];
3030 object_copy(o_ptr, j_ptr);
3033 o_ptr->held_m_idx = 0;
3034 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
3035 o_ptr->next_o_idx = g_ptr->o_idx;
3036 g_ptr->o_idx = o_idx;
3041 * todo yminとymaxは本当に使われているのか?
3042 * @brief クエスト用固定ダンジョンをフロアに生成する
3043 * Parse a sub-file of the "extra info"
3044 * @param player_ptr プレーヤーへの参照ポインタ
3054 static errr process_dungeon_file_aux(player_type *player_ptr, char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3058 if (!buf[0]) return 0;
3059 if (iswspace(buf[0])) return 0;
3060 if (buf[0] == '#') return 0;
3061 if (buf[1] != ':') return 1;
3065 return process_dungeon_file(player_ptr, buf + 2, ymin, xmin, ymax, xmax);
3068 floor_type *floor_ptr = player_ptr->current_floor_ptr;
3069 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3072 return parse_line_feature(player_ptr->current_floor_ptr, buf);
3074 else if (buf[0] == 'D')
3076 object_type object_type_body;
3078 int len = strlen(s);
3079 if (init_flags & INIT_ONLY_BUILDINGS) return 0;
3082 for (int i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3084 grid_type *g_ptr = &floor_ptr->grid_array[*y][*x];
3086 OBJECT_IDX object_index = letter[idx].object;
3087 MONSTER_IDX monster_index = letter[idx].monster;
3088 int random = letter[idx].random;
3089 ARTIFACT_IDX artifact_index = letter[idx].artifact;
3090 g_ptr->feat = conv_dungeon_feat(floor_ptr, letter[idx].feature);
3091 if (init_flags & INIT_ONLY_FEATURES) continue;
3093 g_ptr->info = letter[idx].cave_info;
3094 if (random & RANDOM_MONSTER)
3096 floor_ptr->monster_level = floor_ptr->base_level + monster_index;
3098 place_monster(player_ptr, *y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3100 floor_ptr->monster_level = floor_ptr->base_level;
3102 else if (monster_index)
3104 int old_cur_num, old_max_num;
3107 if (monster_index < 0)
3109 monster_index = -monster_index;
3113 old_cur_num = r_info[monster_index].cur_num;
3114 old_max_num = r_info[monster_index].max_num;
3116 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3118 r_info[monster_index].cur_num = 0;
3119 r_info[monster_index].max_num = 1;
3121 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3123 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3125 r_info[monster_index].max_num++;
3129 place_monster_aux(player_ptr, 0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3132 floor_ptr->m_list[hack_m_idx_ii].smart |= SM_CLONED;
3133 r_info[monster_index].cur_num = old_cur_num;
3134 r_info[monster_index].max_num = old_max_num;
3138 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3140 floor_ptr->object_level = floor_ptr->base_level + object_index;
3143 * Random trap and random treasure defined
3144 * 25% chance for trap and 75% chance for object
3146 if (randint0(100) < 75)
3148 place_object(player_ptr, *y, *x, 0L);
3152 place_trap(player_ptr, *y, *x);
3155 floor_ptr->object_level = floor_ptr->base_level;
3157 else if (random & RANDOM_OBJECT)
3159 floor_ptr->object_level = floor_ptr->base_level + object_index;
3160 if (randint0(100) < 75)
3161 place_object(player_ptr, *y, *x, 0L);
3162 else if (randint0(100) < 80)
3163 place_object(player_ptr, *y, *x, AM_GOOD);
3165 place_object(player_ptr, *y, *x, AM_GOOD | AM_GREAT);
3167 floor_ptr->object_level = floor_ptr->base_level;
3169 else if (random & RANDOM_TRAP)
3171 place_trap(player_ptr, *y, *x);
3173 else if (letter[idx].trap)
3175 g_ptr->mimic = g_ptr->feat;
3176 g_ptr->feat = conv_dungeon_feat(floor_ptr, letter[idx].trap);
3178 else if (object_index)
3180 object_type *o_ptr = &object_type_body;
3181 object_prep(o_ptr, object_index);
3182 if (o_ptr->tval == TV_GOLD)
3184 coin_type = object_index - OBJ_GOLD_LIST;
3185 make_gold(floor_ptr, o_ptr);
3189 apply_magic(player_ptr, o_ptr, floor_ptr->base_level, AM_NO_FIXED_ART | AM_GOOD);
3190 drop_here(floor_ptr, o_ptr, *y, *x);
3195 if (a_info[artifact_index].cur_num)
3197 KIND_OBJECT_IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
3199 object_type *q_ptr = &forge;
3201 object_prep(q_ptr, k_idx);
3202 drop_here(floor_ptr, q_ptr, *y, *x);
3206 if (create_named_art(player_ptr, artifact_index, *y, *x))
3207 a_info[artifact_index].cur_num = 1;
3211 g_ptr->special = letter[idx].special;
3217 else if (buf[0] == 'Q')
3224 num = tokenize(buf + 2, 33, zz, 0);
3228 num = tokenize(buf + 3, 33, zz, 0);
3231 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3233 q_ptr = &(quest[atoi(zz[0])]);
3234 if (zz[1][0] == 'Q')
3236 if (init_flags & INIT_ASSIGN)
3238 monster_race *r_ptr;
3239 artifact_type *a_ptr;
3241 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3243 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
3244 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
3245 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
3246 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
3247 q_ptr->level = (DEPTH)atoi(zz[6]);
3248 q_ptr->r_idx = (IDX)atoi(zz[7]);
3249 q_ptr->k_idx = (IDX)atoi(zz[8]);
3250 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
3252 if (num > 10) q_ptr->flags = atoi(zz[10]);
3254 r_ptr = &r_info[q_ptr->r_idx];
3255 if (r_ptr->flags1 & RF1_UNIQUE)
3256 r_ptr->flags1 |= RF1_QUESTOR;
3258 a_ptr = &a_info[q_ptr->k_idx];
3259 a_ptr->gen_flags |= TRG_QUESTITEM;
3264 else if (zz[1][0] == 'R')
3266 if (init_flags & INIT_ASSIGN)
3269 IDX idx, reward_idx = 0;
3271 for (idx = 2; idx < num; idx++)
3273 IDX a_idx = (IDX)atoi(zz[idx]);
3274 if (a_idx < 1) continue;
3275 if (a_info[a_idx].cur_num > 0) continue;
3277 if (one_in_(count)) reward_idx = a_idx;
3282 q_ptr->k_idx = reward_idx;
3283 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
3287 q_ptr->type = QUEST_TYPE_KILL_ALL;
3293 else if (zz[1][0] == 'N')
3295 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
3297 strcpy(q_ptr->name, zz[2]);
3302 else if (zz[1][0] == 'T')
3304 if (init_flags & INIT_SHOW_TEXT)
3306 strcpy(quest_text[quest_text_line], zz[2]);
3313 else if (buf[0] == 'W')
3315 return parse_line_wilderness(player_ptr, buf, xmin, xmax, y, x);
3317 else if (buf[0] == 'P')
3319 if (init_flags & INIT_CREATE_DUNGEON)
3321 if (tokenize(buf + 2, 2, zz, 0) == 2)
3323 int panels_x, panels_y;
3325 panels_y = (*y / SCREEN_HGT);
3326 if (*y % SCREEN_HGT) panels_y++;
3327 floor_ptr->height = panels_y * SCREEN_HGT;
3329 panels_x = (*x / SCREEN_WID);
3330 if (*x % SCREEN_WID) panels_x++;
3331 floor_ptr->width = panels_x * SCREEN_WID;
3333 panel_row_min = floor_ptr->height;
3334 panel_col_min = floor_ptr->width;
3336 if (floor_ptr->inside_quest)
3338 delete_monster(player_ptr, player_ptr->y, player_ptr->x);
3340 POSITION py = atoi(zz[0]);
3341 POSITION px = atoi(zz[1]);
3346 else if (!player_ptr->oldpx && !player_ptr->oldpy)
3348 player_ptr->oldpy = atoi(zz[0]);
3349 player_ptr->oldpx = atoi(zz[1]);
3356 else if (buf[0] == 'B')
3358 return parse_line_building(buf);
3360 else if (buf[0] == 'M')
3362 if (tokenize(buf + 2, 2, zz, 0) == 2)
3364 if (zz[0][0] == 'T')
3366 max_towns = (TOWN_IDX)atoi(zz[1]);
3368 else if (zz[0][0] == 'Q')
3370 max_q_idx = (QUEST_IDX)atoi(zz[1]);
3372 else if (zz[0][0] == 'R')
3374 max_r_idx = (RACE_IDX)atoi(zz[1]);
3376 else if (zz[0][0] == 'K')
3378 max_k_idx = (KIND_OBJECT_IDX)atoi(zz[1]);
3380 else if (zz[0][0] == 'V')
3382 max_v_idx = (VAULT_IDX)atoi(zz[1]);
3384 else if (zz[0][0] == 'F')
3386 max_f_idx = (FEAT_IDX)atoi(zz[1]);
3388 else if (zz[0][0] == 'A')
3390 max_a_idx = (ARTIFACT_IDX)atoi(zz[1]);
3392 else if (zz[0][0] == 'E')
3394 max_e_idx = (EGO_IDX)atoi(zz[1]);
3396 else if (zz[0][0] == 'D')
3398 current_world_ptr->max_d_idx = (DUNGEON_IDX)atoi(zz[1]);
3400 else if (zz[0][0] == 'O')
3402 current_world_ptr->max_o_idx = (OBJECT_IDX)atoi(zz[1]);
3404 else if (zz[0][0] == 'M')
3406 current_world_ptr->max_m_idx = (MONSTER_IDX)atoi(zz[1]);
3408 else if (zz[0][0] == 'W')
3410 if (zz[0][1] == 'X')
3411 current_world_ptr->max_wild_x = (POSITION)atoi(zz[1]);
3413 if (zz[0][1] == 'Y')
3414 current_world_ptr->max_wild_y = (POSITION)atoi(zz[1]);
3425 * todo ここから先頭に移すとコンパイル警告が出る……
3428 static concptr variant = "ZANGBAND";
3431 * @brief クエスト用固定ダンジョン生成時の分岐処理
3432 * Helper function for "process_dungeon_file()"
3433 * @param player_ptr プレーヤーへの参照ポインタ
3438 static concptr process_dungeon_file_expr(player_type *player_ptr, char **sp, char *fp)
3448 while (iswspace(*s)) s++;
3452 concptr v = "?o?o?";
3458 t = process_dungeon_file_expr(player_ptr, &s, &f);
3463 else if (streq(t, "IOR"))
3466 while (*s && (f != b2))
3468 t = process_dungeon_file_expr(player_ptr, &s, &f);
3469 if (*t && !streq(t, "0")) v = "1";
3472 else if (streq(t, "AND"))
3475 while (*s && (f != b2))
3477 t = process_dungeon_file_expr(player_ptr, &s, &f);
3478 if (*t && streq(t, "0")) v = "0";
3481 else if (streq(t, "NOT"))
3484 while (*s && (f != b2))
3486 t = process_dungeon_file_expr(player_ptr, &s, &f);
3487 if (*t && streq(t, "1")) v = "0";
3490 else if (streq(t, "EQU"))
3493 if (*s && (f != b2))
3495 t = process_dungeon_file_expr(player_ptr, &s, &f);
3498 while (*s && (f != b2))
3500 p = process_dungeon_file_expr(player_ptr, &s, &f);
3501 if (streq(t, p)) v = "1";
3504 else if (streq(t, "LEQ"))
3507 if (*s && (f != b2))
3509 t = process_dungeon_file_expr(player_ptr, &s, &f);
3512 while (*s && (f != b2))
3515 t = process_dungeon_file_expr(player_ptr, &s, &f);
3516 if (*t && atoi(p) > atoi(t)) v = "0";
3519 else if (streq(t, "GEQ"))
3522 if (*s && (f != b2))
3524 t = process_dungeon_file_expr(player_ptr, &s, &f);
3527 while (*s && (f != b2))
3530 t = process_dungeon_file_expr(player_ptr, &s, &f);
3531 if (*t && atoi(p) < atoi(t)) v = "0";
3536 while (*s && (f != b2))
3538 t = process_dungeon_file_expr(player_ptr, &s, &f);
3542 if (f != b2) v = "?x?x?";
3543 if ((f = *s) != '\0') *s++ = '\0';
3551 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
3553 if (iskanji(*s)) s++;
3557 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
3559 if ((f = *s) != '\0') *s++ = '\0';
3569 if (streq(b + 1, "SYS"))
3573 else if (streq(b + 1, "GRAF"))
3577 else if (streq(b + 1, "MONOCHROME"))
3584 else if (streq(b + 1, "RACE"))
3586 v = _(rp_ptr->E_title, rp_ptr->title);
3588 else if (streq(b + 1, "CLASS"))
3590 v = _(cp_ptr->E_title, cp_ptr->title);
3592 else if (streq(b + 1, "REALM1"))
3594 v = _(E_realm_names[player_ptr->realm1], realm_names[player_ptr->realm1]);
3596 else if (streq(b + 1, "REALM2"))
3598 v = _(E_realm_names[player_ptr->realm2], realm_names[player_ptr->realm2]);
3600 else if (streq(b + 1, "PLAYER"))
3602 static char tmp_player_name[32];
3604 for (pn = player_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
3614 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
3618 v = tmp_player_name;
3620 else if (streq(b + 1, "TOWN"))
3622 sprintf(tmp, "%d", player_ptr->town_num);
3625 else if (streq(b + 1, "LEVEL"))
3627 sprintf(tmp, "%d", player_ptr->lev);
3630 else if (streq(b + 1, "QUEST_NUMBER"))
3632 sprintf(tmp, "%d", player_ptr->current_floor_ptr->inside_quest);
3635 else if (streq(b + 1, "LEAVING_QUEST"))
3637 sprintf(tmp, "%d", leaving_quest);
3640 else if (prefix(b + 1, "QUEST_TYPE"))
3642 sprintf(tmp, "%d", quest[atoi(b + 11)].type);
3645 else if (prefix(b + 1, "QUEST"))
3647 sprintf(tmp, "%d", quest[atoi(b + 6)].status);
3650 else if (prefix(b + 1, "RANDOM"))
3652 sprintf(tmp, "%d", (int)(current_world_ptr->seed_town%atoi(b + 7)));
3655 else if (streq(b + 1, "VARIANT"))
3659 else if (streq(b + 1, "WILDERNESS"))
3662 sprintf(tmp, "NONE");
3664 sprintf(tmp, "LITE");
3666 sprintf(tmp, "NORMAL");
3677 * @brief クエスト用固定ダンジョン生成時のメインルーチン
3678 * Helper function for "process_dungeon_file()"
3679 * @param player_ptr プレーヤーへの参照ポインタ
3687 errr process_dungeon_file(player_type *player_ptr, concptr name, int ymin, int xmin, int ymax, int xmax)
3690 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
3692 fp = my_fopen(buf, "r");
3698 bool bypass = FALSE;
3699 int x = xmin, y = ymin;
3700 while (my_fgets(fp, buf, sizeof(buf)) == 0)
3703 if (!buf[0]) continue;
3704 if (iswspace(buf[0])) continue;
3705 if (buf[0] == '#') continue;
3706 if ((buf[0] == '?') && (buf[1] == ':'))
3711 concptr v = process_dungeon_file_expr(player_ptr, &s, &f);
3712 bypass = (streq(v, "0") ? TRUE : FALSE);
3716 if (bypass) continue;
3718 err = process_dungeon_file_aux(player_ptr, buf, ymin, xmin, ymax, xmax, &y, &x);
3724 concptr oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
3725 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
3726 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);