3 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file is used to initialize various variables and arrays for the
16 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
17 * the common limitation of "read()" and "write()" to only 32767 bytes
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
28 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
29 * in this file is compiled out, and the game will not run unless valid
30 * "binary template files" already exist in "lib/data". Thus, one can
31 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
32 * "*.raw" files in "lib/data", and then quit, and recompile without
33 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
34 * from changing the ascii template files in potentially dangerous ways.
35 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
36 * このファイルのコードの多くはコンパイル出力され、本ゲームは
37 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
38 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
39 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
40 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
41 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
42 * テンプレートファイルを変更することを妨げることができる。
43 * The code could actually be removed and placed into a "stand-alone"
44 * program, but that feels a little silly, especially considering some
45 * of the platforms that we currently support.
53 #ifdef ALLOW_TEMPLATES
58 /*** Helper arrays for parsing ascii template files ***/
62 * Monster Blow Methods
64 static cptr r_info_blow_method[] =
98 * Monster Blow Effects
100 static cptr r_info_blow_effect[] =
145 static cptr f_info_flags[] =
270 static cptr r_info_flags1[] =
310 static cptr r_info_flags2[] =
350 static cptr r_info_flags3[] =
390 static cptr r_info_flags4[] =
430 static cptr r_info_flags5[] =
470 static cptr r_info_flags6[] =
487 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
511 static cptr r_info_flags7[] =
551 static cptr r_info_flags8[] =
583 "WILD_SWAMP", /* ToDo: Implement Swamp */
592 static cptr r_info_flags9[] =
631 * モンスター特性トークンの定義R(耐性) /
634 static cptr r_info_flagsr[] =
672 * オブジェクト基本特性トークンの定義 /
675 static cptr k_info_flags[] =
772 "XXX3", /* Fake flag for Smith */
773 "XXX4", /* Fake flag for Smith */
823 * オブジェクト生成特性トークンの定義 /
826 static cptr k_info_gen_flags[] =
866 static cptr d_info_flags1[] =
904 * @brief データの可変文字列情報をテキストとして保管する /
905 * Add a text to the text-storage and store offset to it.
906 * @param offset 文字列保管ポインタからのオフセット
907 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
909 * @param normal_text テキストの正規化を行う
912 * Returns FALSE when there isn't enough space available to store
915 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
917 /* Hack -- Verify space */
918 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
924 /* Advance and save the text index */
925 *offset = ++head->text_size;
928 /* Additional text */
929 else if (normal_text)
932 * If neither the end of the last line nor
933 * the beginning of current line is not a space,
934 * fill up a space as a correct separator of two words.
936 if (head->text_size > 0 &&
938 (*(head->text_ptr + head->text_size - 1) != ' ') &&
939 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
940 (buf[0] != ' ') && !iskanji(buf[0])
942 (*(head->text_ptr + head->text_size - 1) != ' ') &&
948 *(head->text_ptr + head->text_size) = ' ';
950 /* Advance the index */
955 /* Append chars to the text */
956 strcpy(head->text_ptr + head->text_size, buf);
958 /* Advance the index */
959 head->text_size += strlen(buf);
967 * @brief データの可変文字列情報を名前として保管する /
968 * Add a name to the name-storage and return an offset to it.
969 * @param offset 文字列保管ポインタからのオフセット
970 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
974 * Returns FALSE when there isn't enough space available to store
977 static bool add_name(u32b *offset, header *head, cptr buf)
979 /* Hack -- Verify space */
980 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
986 /* Advance and save the name index */
987 *offset = ++head->name_size;
990 /* Append chars to the names */
991 strcpy(head->name_ptr + head->name_size, buf);
993 /* Advance the index */
994 head->name_size += strlen(buf);
1002 * @brief データの可変文字列情報をタグとして保管する /
1003 * Add a tag to the tag-storage and return an offset to it.
1004 * @param offset 文字列保管ポインタからのオフセット
1005 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1009 * Returns FALSE when there isn't enough space available to store
1012 static bool add_tag(s16b *offset, header *head, cptr buf)
1016 /* Search for an existing (fake) tag */
1017 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1020 if (streq(&head->tag_ptr[i], buf)) break;
1023 /* There was no existing tag */
1024 if (i >= head->tag_size)
1026 /* Hack -- Verify space */
1027 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1030 /* Append chars to the tags */
1031 strcpy(head->tag_ptr + head->tag_size, buf);
1033 /* Point the new tag */
1036 /* Advance the index */
1037 head->tag_size += strlen(buf) + 1;
1040 /* Return offset of the tag */
1049 * @brief シンボル1文字をカラーIDに変更する /
1050 * Convert a "color letter" into an "actual" color
1051 * The colors are: dwsorgbuDWvyRGBU, as shown below
1055 byte color_char_to_attr(char c)
1059 case 'd': return (TERM_DARK);
1060 case 'w': return (TERM_WHITE);
1061 case 's': return (TERM_SLATE);
1062 case 'o': return (TERM_ORANGE);
1063 case 'r': return (TERM_RED);
1064 case 'g': return (TERM_GREEN);
1065 case 'b': return (TERM_BLUE);
1066 case 'u': return (TERM_UMBER);
1068 case 'D': return (TERM_L_DARK);
1069 case 'W': return (TERM_L_WHITE);
1070 case 'v': return (TERM_VIOLET);
1071 case 'y': return (TERM_YELLOW);
1072 case 'R': return (TERM_L_RED);
1073 case 'G': return (TERM_L_GREEN);
1074 case 'B': return (TERM_L_BLUE);
1075 case 'U': return (TERM_L_UMBER);
1083 /*** Initialize from ascii template files ***/
1087 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1088 * Initialize an "*_info" array, by parsing an ascii "template" file
1089 * @param fp 読み取りに使うファイルポインタ
1090 * @param buf 読み取りに使うバッファ領域
1091 * @param head ヘッダ構造体
1092 * @param parse_info_txt_line パース関数
1095 errr init_info_txt(FILE *fp, char *buf, header *head,
1096 parse_info_txt_func parse_info_txt_line)
1100 /* Just before the first record */
1103 /* Just before the first line */
1107 /* Prepare the "fake" stuff */
1108 head->name_size = 0;
1109 head->text_size = 0;
1113 while (0 == my_fgets(fp, buf, 1024))
1115 /* Advance the line number */
1118 /* Skip comments and blank lines */
1119 if (!buf[0] || (buf[0] == '#')) continue;
1121 /* Verify correct "colon" format */
1122 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1125 /* Hack -- Process 'V' for "Version" */
1132 /* Mega Hack -- Calculate Check Sum */
1133 if (buf[0] != 'N' && buf[0] != 'D')
1136 for (i = 0; buf[i]; i++)
1138 head->v_extra += (byte)buf[i];
1139 head->v_extra ^= (1 << (i % 8));
1143 /* Parse the line */
1144 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1149 /* Complete the "name" and "text" sizes */
1150 if (head->name_size) head->name_size++;
1151 if (head->text_size) head->text_size++;
1159 * @brief Vault情報(v_info)のパース関数 /
1160 * Initialize the "v_info" array, by parsing an ascii "template" file
1162 * @param head ヘッダ構造体
1165 errr parse_v_info(char *buf, header *head)
1171 static vault_type *v_ptr = NULL;
1173 /* Process 'N' for "New/Number/Name" */
1176 /* Find the colon before the name */
1177 s = my_strchr(buf+2, ':');
1179 /* Verify that colon */
1182 /* Nuke the colon, advance to the name */
1185 /* Paranoia -- require a name */
1186 if (!*s) return (1);
1191 /* Verify information */
1192 if (i <= error_idx) return (4);
1194 /* Verify information */
1195 if (i >= head->info_num) return (2);
1197 /* Save the index */
1200 /* Point at the "info" */
1203 /* Store the name */
1204 if (!add_name(&v_ptr->name, head, s)) return (7);
1207 /* There better be a current v_ptr */
1208 else if (!v_ptr) return (3);
1210 /* Process 'D' for "Description" */
1211 else if (buf[0] == 'D')
1213 /* Acquire the text */
1216 /* Store the text */
1217 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1220 /* Process 'X' for "Extra info" (one line only) */
1221 else if (buf[0] == 'X')
1223 int typ, rat, hgt, wid;
1225 /* Scan for the values */
1226 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1227 &typ, &rat, &hgt, &wid)) return (1);
1229 /* Save the values */
1245 * @brief 職業技能情報(s_info)のパース関数 /
1246 * Initialize the "s_info" array, by parsing an ascii "template" file
1248 * @param head ヘッダ構造体
1251 errr parse_s_info(char *buf, header *head)
1256 static skill_table *s_ptr = NULL;
1259 /* Process 'N' for "New/Number/Name" */
1265 /* Verify information */
1266 if (i <= error_idx) return (4);
1268 /* Verify information */
1269 if (i >= head->info_num) return (2);
1271 /* Save the index */
1274 /* Point at the "info" */
1278 /* There better be a current s_ptr */
1279 else if (!s_ptr) return (3);
1281 /* Process 'W' for "Weapon exp" */
1282 else if (buf[0] == 'W')
1284 int tval, sval, start, max;
1285 const s16b exp_conv_table[] =
1287 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1288 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1291 /* Scan for the values */
1292 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1293 &tval, &sval, &start, &max)) return (1);
1295 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1296 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1298 /* Save the values */
1299 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1300 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1303 /* Process 'S' for "Skill exp" */
1304 else if (buf[0] == 'S')
1306 int num, start, max;
1308 /* Scan for the values */
1309 if (3 != sscanf(buf+2, "%d:%d:%d",
1310 &num, &start, &max)) return (1);
1312 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1313 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1315 /* Save the values */
1316 s_ptr->s_start[num] = start;
1317 s_ptr->s_max[num] = max;
1330 * @brief 職業魔法情報(m_info)のパース関数 /
1331 * Initialize the "m_info" array, by parsing an ascii "template" file
1333 * @param head ヘッダ構造体
1336 errr parse_m_info(char *buf, header *head)
1343 static player_magic *m_ptr = NULL;
1346 static int realm, magic_idx = 0, readable = 0;
1349 /* Process 'N' for "New/Number/Name" */
1355 /* Verify information */
1356 if (i <= error_idx) return (4);
1358 /* Verify information */
1359 if (i >= head->info_num) return (2);
1361 /* Save the index */
1364 /* Point at the "info" */
1368 /* There better be a current m_ptr */
1369 else if (!m_ptr) return (3);
1371 /* Process 'I' for "Info" (one line only) */
1372 else if (buf[0] == 'I')
1375 int xtra, type, first, weight;
1377 /* Find the colon before the name */
1378 s = my_strchr(buf+2, ':');
1380 /* Verify that colon */
1383 /* Nuke the colon, advance to the name */
1388 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1389 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1390 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1391 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1392 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1397 /* Find the colon before the name */
1398 s = my_strchr(s, ':');
1400 /* Verify that colon */
1403 /* Nuke the colon, advance to the name */
1406 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1407 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1408 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1409 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1410 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1411 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1415 /* Scan for the values */
1416 if (4 != sscanf(s, "%x:%d:%d:%d",
1417 (uint *)&xtra, &type, &first, &weight)) return (1);
1419 m_ptr->spell_xtra = xtra;
1420 m_ptr->spell_type = type;
1421 m_ptr->spell_first = first;
1422 m_ptr->spell_weight = weight;
1426 /* Process 'R' for "Realm" (one line only) */
1427 else if (buf[0] == 'R')
1429 /* Scan for the values */
1430 if (2 != sscanf(buf+2, "%d:%d",
1431 &realm, &readable)) return (1);
1436 else if (buf[0] == 'T')
1438 int level, mana, fail, exp;
1440 if (!readable) return (1);
1441 /* Scan for the values */
1442 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1443 &level, &mana, &fail, &exp)) return (1);
1445 m_ptr->info[realm][magic_idx].slevel = level;
1446 m_ptr->info[realm][magic_idx].smana = mana;
1447 m_ptr->info[realm][magic_idx].sfail = fail;
1448 m_ptr->info[realm][magic_idx].sexp = exp;
1462 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1463 * Grab one flag from a textual string
1464 * @param flags ビットフラグを追加する先の参照ポインタ
1465 * @param names トークン定義配列
1466 * @param what 参照元の文字列ポインタ
1469 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1474 for (i = 0; i < 32; i++)
1476 if (streq(what, names[i]))
1478 *flags |= (1L << i);
1488 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1489 * Grab one flag in an feature_type from a textual string
1490 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1491 * @param what 参照元の文字列ポインタ
1494 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1499 for (i = 0; i < FF_FLAG_MAX; i++)
1501 if (streq(what, f_info_flags[i]))
1503 add_flag(f_ptr->flags, i);
1509 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1512 return PARSE_ERROR_GENERIC;
1517 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1518 * Grab an action in an feature_type from a textual string
1519 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1520 * @param what 参照元の文字列ポインタ
1521 * @param count ステートの保存先ID
1524 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1529 for (i = 0; i < FF_FLAG_MAX; i++)
1531 if (streq(what, f_info_flags[i]))
1533 f_ptr->state[count].action = i;
1539 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1542 return PARSE_ERROR_GENERIC;
1547 * @brief 地形情報(f_info)のパース関数 /
1548 * Initialize the "f_info" array, by parsing an ascii "template" file
1550 * @param head ヘッダ構造体
1553 errr parse_f_info(char *buf, header *head)
1560 static feature_type *f_ptr = NULL;
1563 /* Process 'N' for "New/Number/Name" */
1566 /* Find the colon before the name */
1567 s = my_strchr(buf+2, ':');
1571 /* Nuke the colon, advance to the name */
1578 /* Verify information */
1579 if (i <= error_idx) return (4);
1581 /* Verify information */
1582 if (i >= head->info_num) return (2);
1584 /* Save the index */
1587 /* Point at the "info" */
1590 /* Tag name is given */
1594 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1597 /* Default "mimic" */
1600 /* Default "destroyed state" -- if not specified */
1601 f_ptr->destroyed = i;
1603 /* Default "states" */
1604 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1607 /* There better be a current f_ptr */
1608 else if (!f_ptr) return (3);
1611 else if (buf[0] == 'J')
1613 /* Store the name */
1614 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1617 else if (buf[0] == 'E')
1619 /* Ignore english name */
1622 else if (buf[0] == 'J')
1624 /* Ignore Japanese name */
1627 else if (buf[0] == 'E')
1629 /* Acquire the Text */
1632 /* Store the name */
1633 if (!add_name(&f_ptr->name, head, s)) return (7);
1638 /* Process 'M' for "Mimic" (one line only) */
1639 else if (buf[0] == 'M')
1643 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1645 /* Record a fake tag index */
1646 f_ptr->mimic = -offset;
1650 /* Process 'G' for "Graphics" (one line only) */
1651 else if (buf[0] == 'G')
1655 char char_tmp[F_LIT_MAX];
1658 if (buf[1] != ':') return (1);
1659 if (!buf[2]) return (1);
1660 if (buf[3] != ':') return (1);
1661 if (!buf[4]) return (1);
1663 /* Extract the char */
1664 char_tmp[F_LIT_STANDARD] = buf[2];
1666 /* Extract the color */
1667 s_attr = color_char_to_attr(buf[4]);
1670 if (s_attr > 127) return (1);
1672 /* Save the standard values */
1673 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1674 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1676 /* Is this feature supports lighting? */
1679 /* G:c:a:LIT (default) */
1680 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1682 /* G:c:a:lc:la:dc:da */
1683 if (!streq(buf + 6, "LIT"))
1685 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1687 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1688 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1689 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1690 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1692 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1694 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1697 /* Use default lighting */
1700 /* No lighting support */
1701 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1704 /* Extract the color */
1705 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1706 if (f_ptr->d_attr[j] > 127) return 1;
1709 f_ptr->d_char[j] = char_tmp[j];
1715 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1717 f_ptr->d_attr[j] = s_attr;
1718 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1724 /* Hack -- Process 'F' for flags */
1725 else if (buf[0] == 'F')
1727 /* Parse every entry textually */
1728 for (s = buf + 2; *s; )
1730 /* Find the end of this entry */
1731 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1733 /* Nuke and skip any dividers */
1737 while (*t == ' ' || *t == '|') t++;
1740 /* XXX XXX XXX Hack -- Read feature subtype */
1741 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1743 /* Extract a "subtype" */
1746 /* Start at next entry */
1753 /* XXX XXX XXX Hack -- Read feature power */
1754 if (1 == sscanf(s, "POWER_%d", &i))
1756 /* Extract a "power" */
1759 /* Start at next entry */
1766 /* Parse this entry */
1767 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1769 /* Start the next entry */
1774 /* Process 'W' for "More Info" (one line only) */
1775 else if (buf[0] == 'W')
1779 /* Scan for the value */
1780 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1782 /* Save the value */
1783 f_ptr->priority = priority;
1786 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1787 else if (buf[0] == 'K')
1791 /* Find the next empty state slot (if any) */
1792 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1794 /* Oops, no more slots */
1795 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1797 /* Analyze the first field */
1798 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1800 /* Terminate the field (if necessary) */
1801 if (*t == ':') *t++ = '\0';
1803 /* Is this default entry? */
1804 if (streq(s, "DESTROYED"))
1806 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1808 /* Record a fake tag index */
1809 f_ptr->destroyed = -offset;
1814 f_ptr->state[i].action = 0;
1816 /* Parse this entry */
1817 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1819 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1821 /* Record a fake tag index */
1822 f_ptr->state[i].result = -offset;
1835 * @brief 地形タグからIDを得る /
1836 * Convert a fake tag to a real feat index
1840 s16b f_tag_to_index(cptr str)
1844 /* Search for real index corresponding to this fake tag */
1845 for (i = 0; i < f_head.info_num; i++)
1847 if (streq(f_tag + f_info[i].tag, str))
1849 /* Return the index */
1860 * @brief 地形タグからIDを得る /
1861 * Search for real index corresponding to this fake tag
1865 static void search_real_feat(s16b *feat)
1869 /* Don't convert non-fake tag */
1870 if (*feat >= 0) return;
1872 /* Search for real index corresponding to this fake tag */
1873 for (i = 0; i < f_head.info_num; i++)
1875 if ((-(*feat)) == f_info[i].tag)
1877 /* Record real index */
1884 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + (-(*feat)));
1889 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1890 * Retouch fake tags of f_info
1891 * @param head ヘッダ構造体
1894 void retouch_f_info(header *head)
1898 /* Convert fake tags to real feat indices */
1899 for (i = 0; i < head->info_num; i++)
1901 feature_type *f_ptr = &f_info[i];
1904 search_real_feat(&f_ptr->mimic);
1906 search_real_feat(&f_ptr->destroyed);
1908 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1914 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
1915 * Grab one flag in an object_kind from a textual string
1916 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
1917 * @param what 参照元の文字列ポインタ
1920 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1925 for (i = 0; i < TR_FLAG_MAX; i++)
1927 if (streq(what, k_info_flags[i]))
1929 add_flag(k_ptr->flags, i);
1934 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1938 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
1945 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
1946 * Grab one activation index flag
1947 * @param what 参照元の文字列ポインタ
1950 static byte grab_one_activation_flag(cptr what)
1956 if (activation_info[i].flag == NULL) break;
1958 if (streq(what, activation_info[i].flag))
1960 return activation_info[i].index;
1971 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
1979 * @brief ベースアイテム(k_info)のパース関数 /
1980 * Initialize the "k_info" array, by parsing an ascii "template" file
1982 * @param head ヘッダ構造体
1985 errr parse_k_info(char *buf, header *head)
1992 static object_kind *k_ptr = NULL;
1995 /* Process 'N' for "New/Number/Name" */
2002 /* Find the colon before the name */
2003 s = my_strchr(buf+2, ':');
2005 /* Verify that colon */
2008 /* Nuke the colon, advance to the name */
2014 /* Verify information */
2015 if (i <= error_idx) return (4);
2017 /* Verify information */
2018 if (i >= head->info_num) return (2);
2020 /* Save the index */
2023 /* Point at the "info" */
2027 /* Paranoia -- require a name */
2028 if (!*s) return (1);
2030 /* Find the colon before the flavor */
2031 flavor = my_strchr(s, ':');
2033 /* Verify that colon */
2036 /* Nuke the colon, advance to the flavor */
2039 /* Store the flavor */
2040 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2043 /* Store the name */
2044 if (!add_name(&k_ptr->name, head, s)) return (7);
2048 /* There better be a current k_ptr */
2049 else if (!k_ptr) return (3);
2054 /* 'E' から始まる行は英語名としている */
2055 else if (buf[0] == 'E')
2060 else if (buf[0] == 'E')
2064 /* Acquire the name */
2067 /* Find the colon before the flavor */
2068 flavor = my_strchr(s, ':');
2070 /* Verify that colon */
2073 /* Nuke the colon, advance to the flavor */
2076 /* Store the flavor */
2077 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2080 /* Store the name */
2081 if (!add_name(&k_ptr->name, head, s)) return (7);
2085 /* Process 'D' for "Description" */
2086 else if (buf[0] == 'D')
2091 /* Acquire the text */
2096 /* Acquire the text */
2100 /* Store the text */
2101 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2104 /* Process 'G' for "Graphics" (one line only) */
2105 else if (buf[0] == 'G')
2111 if (buf[1] != ':') return (1);
2112 if (!buf[2]) return (1);
2113 if (buf[3] != ':') return (1);
2114 if (!buf[4]) return (1);
2116 /* Extract the char */
2119 /* Extract the attr */
2120 tmp = color_char_to_attr(buf[4]);
2123 if (tmp > 127) return (1);
2125 /* Save the values */
2126 k_ptr->d_attr = tmp;
2127 k_ptr->d_char = sym;
2130 /* Process 'I' for "Info" (one line only) */
2131 else if (buf[0] == 'I')
2133 int tval, sval, pval;
2135 /* Scan for the values */
2136 if (3 != sscanf(buf+2, "%d:%d:%d",
2137 &tval, &sval, &pval)) return (1);
2139 /* Save the values */
2145 /* Process 'W' for "More Info" (one line only) */
2146 else if (buf[0] == 'W')
2148 int level, extra, wgt;
2151 /* Scan for the values */
2152 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2153 &level, &extra, &wgt, &cost)) return (1);
2155 /* Save the values */
2156 k_ptr->level = level;
2157 k_ptr->extra = extra;
2158 k_ptr->weight = wgt;
2162 /* Process 'A' for "Allocation" (one line only) */
2163 else if (buf[0] == 'A')
2167 /* XXX XXX XXX Simply read each number following a colon */
2168 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2170 /* Default chance */
2171 k_ptr->chance[i] = 1;
2173 /* Store the attack damage index */
2174 k_ptr->locale[i] = atoi(s+1);
2176 /* Find the slash */
2177 t = my_strchr(s+1, '/');
2179 /* Find the next colon */
2180 s = my_strchr(s+1, ':');
2182 /* If the slash is "nearby", use it */
2183 if (t && (!s || t < s))
2185 int chance = atoi(t+1);
2186 if (chance > 0) k_ptr->chance[i] = chance;
2191 /* Hack -- Process 'P' for "power" and such */
2192 else if (buf[0] == 'P')
2194 int ac, hd1, hd2, th, td, ta;
2196 /* Scan for the values */
2197 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2198 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2208 /* Hack -- Process 'U' for activation index */
2209 else if (buf[0] == 'U')
2212 n = grab_one_activation_flag(buf + 2);
2223 /* Hack -- Process 'F' for flags */
2224 else if (buf[0] == 'F')
2226 /* Parse every entry textually */
2227 for (s = buf + 2; *s; )
2229 /* Find the end of this entry */
2230 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2232 /* Nuke and skip any dividers */
2236 while (*t == ' ' || *t == '|') t++;
2239 /* Parse this entry */
2240 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2242 /* Start the next entry */
2257 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2258 * Grab one activation index flag
2259 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2260 * @param what 参照元の文字列ポインタ
2261 * @return エラーがあった場合1、エラーがない場合0を返す
2263 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2268 for (i = 0; i < TR_FLAG_MAX; i++)
2270 if (streq(what, k_info_flags[i]))
2272 add_flag(a_ptr->flags, i);
2277 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2281 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2289 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2290 * Initialize the "a_info" array, by parsing an ascii "template" file
2292 * @param head ヘッダ構造体
2295 errr parse_a_info(char *buf, header *head)
2302 static artifact_type *a_ptr = NULL;
2305 /* Process 'N' for "New/Number/Name" */
2308 /* Find the colon before the name */
2309 s = my_strchr(buf+2, ':');
2311 /* Verify that colon */
2314 /* Nuke the colon, advance to the name */
2317 /* Paranoia -- require a name */
2318 if (!*s) return (1);
2323 /* Verify information */
2324 if (i < error_idx) return (4);
2326 /* Verify information */
2327 if (i >= head->info_num) return (2);
2329 /* Save the index */
2332 /* Point at the "info" */
2335 /* Ignore everything */
2336 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2337 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2338 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2339 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2341 /* Store the name */
2342 if (!add_name(&a_ptr->name, head, s)) return (7);
2346 /* There better be a current a_ptr */
2347 else if (!a_ptr) return (3);
2352 /* 'E' から始まる行は英語名としている */
2353 else if (buf[0] == 'E')
2358 else if (buf[0] == 'E')
2360 /* Acquire the Text */
2363 /* Store the name */
2364 if (!add_name(&a_ptr->name, head, s)) return (7);
2368 /* Process 'D' for "Description" */
2369 else if (buf[0] == 'D')
2374 /* Acquire the text */
2379 /* Acquire the text */
2383 /* Store the text */
2384 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2388 /* Process 'I' for "Info" (one line only) */
2389 else if (buf[0] == 'I')
2391 int tval, sval, pval;
2393 /* Scan for the values */
2394 if (3 != sscanf(buf+2, "%d:%d:%d",
2395 &tval, &sval, &pval)) return (1);
2397 /* Save the values */
2403 /* Process 'W' for "More Info" (one line only) */
2404 else if (buf[0] == 'W')
2406 int level, rarity, wgt;
2409 /* Scan for the values */
2410 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2411 &level, &rarity, &wgt, &cost)) return (1);
2413 /* Save the values */
2414 a_ptr->level = level;
2415 a_ptr->rarity = rarity;
2416 a_ptr->weight = wgt;
2420 /* Hack -- Process 'P' for "power" and such */
2421 else if (buf[0] == 'P')
2423 int ac, hd1, hd2, th, td, ta;
2425 /* Scan for the values */
2426 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2427 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2437 /* Hack -- Process 'U' for activation index */
2438 else if (buf[0] == 'U')
2441 n = grab_one_activation_flag(buf + 2);
2452 /* Hack -- Process 'F' for flags */
2453 else if (buf[0] == 'F')
2455 /* Parse every entry textually */
2456 for (s = buf + 2; *s; )
2458 /* Find the end of this entry */
2459 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2461 /* Nuke and skip any dividers */
2465 while ((*t == ' ') || (*t == '|')) t++;
2468 /* Parse this entry */
2469 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2471 /* Start the next entry */
2487 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2488 * Grab one flag in a ego-item_type from a textual string
2489 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2490 * @param what 参照元の文字列ポインタ
2491 * @return エラーがあった場合1、エラーがない場合0を返す
2493 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2498 for (i = 0; i < TR_FLAG_MAX; i++)
2500 if (streq(what, k_info_flags[i]))
2502 add_flag(e_ptr->flags, i);
2507 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2511 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2519 * @brief アイテムエゴ情報(e_info)のパース関数 /
2520 * Initialize the "e_info" array, by parsing an ascii "template" file
2522 * @param head ヘッダ構造体
2525 errr parse_e_info(char *buf, header *head)
2532 static ego_item_type *e_ptr = NULL;
2535 /* Just before the first record */
2538 /* Just before the first line */
2542 /* Process 'N' for "New/Number/Name" */
2545 /* Find the colon before the name */
2546 s = my_strchr(buf+2, ':');
2548 /* Verify that colon */
2551 /* Nuke the colon, advance to the name */
2554 /* Paranoia -- require a name */
2555 if (!*s) return (1);
2560 /* Verify information */
2561 if (i < error_idx) return (4);
2563 /* Verify information */
2564 if (i >= head->info_num) return (2);
2566 /* Save the index */
2569 /* Point at the "info" */
2572 /* Store the name */
2573 if (!add_name(&e_ptr->name, head, s)) return (7);
2577 /* There better be a current e_ptr */
2578 else if (!e_ptr) return (3);
2583 /* 'E' から始まる行は英語名 */
2584 else if (buf[0] == 'E')
2589 else if (buf[0] == 'E')
2591 /* Acquire the Text */
2594 /* Store the name */
2595 if (!add_name(&e_ptr->name, head, s)) return (7);
2600 /* Process 'D' for "Description" */
2601 else if (buf[0] == 'D')
2603 /* Acquire the text */
2606 /* Store the text */
2607 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2612 /* Process 'X' for "Xtra" (one line only) */
2613 else if (buf[0] == 'X')
2617 /* Scan for the values */
2618 if (2 != sscanf(buf+2, "%d:%d",
2619 &slot, &rating)) return (1);
2621 /* Save the values */
2623 e_ptr->rating = rating;
2626 /* Process 'W' for "More Info" (one line only) */
2627 else if (buf[0] == 'W')
2629 int level, rarity, pad2;
2632 /* Scan for the values */
2633 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2634 &level, &rarity, &pad2, &cost)) return (1);
2636 /* Save the values */
2637 e_ptr->level = level;
2638 e_ptr->rarity = rarity;
2639 /* e_ptr->weight = wgt; */
2643 /* Hack -- Process 'C' for "creation" */
2644 else if (buf[0] == 'C')
2648 /* Scan for the values */
2649 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2650 &th, &td, &ta, &pv)) return (1);
2652 e_ptr->max_to_h = th;
2653 e_ptr->max_to_d = td;
2654 e_ptr->max_to_a = ta;
2655 e_ptr->max_pval = pv;
2658 /* Hack -- Process 'U' for activation index */
2659 else if (buf[0] == 'U')
2662 n = grab_one_activation_flag(buf + 2);
2673 /* Hack -- Process 'F' for flags */
2674 else if (buf[0] == 'F')
2676 /* Parse every entry textually */
2677 for (s = buf + 2; *s; )
2679 /* Find the end of this entry */
2680 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2682 /* Nuke and skip any dividers */
2686 while ((*t == ' ') || (*t == '|')) t++;
2689 /* Parse this entry */
2690 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2692 /* Start the next entry */
2706 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2707 * Grab one (basic) flag in a monster_race from a textual string
2708 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2709 * @param what 参照元の文字列ポインタ
2712 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2714 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2717 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2720 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2723 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2726 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2729 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2732 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2736 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2744 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2745 * Grab one (spell) flag in a monster_race from a textual string
2746 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2747 * @param what 参照元の文字列ポインタ
2750 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2752 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2755 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2758 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2762 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2770 * @brief モンスター種族情報(r_info)のパース関数 /
2771 * Initialize the "r_info" array, by parsing an ascii "template" file
2773 * @param head ヘッダ構造体
2776 errr parse_r_info(char *buf, header *head)
2783 static monster_race *r_ptr = NULL;
2786 /* Process 'N' for "New/Number/Name" */
2789 /* Find the colon before the name */
2790 s = my_strchr(buf+2, ':');
2792 /* Verify that colon */
2795 /* Nuke the colon, advance to the name */
2798 /* Paranoia -- require a name */
2799 if (!*s) return (1);
2804 /* Verify information */
2805 if (i < error_idx) return (4);
2807 /* Verify information */
2808 if (i >= head->info_num) return (2);
2810 /* Save the index */
2813 /* Point at the "info" */
2816 /* Store the name */
2817 if (!add_name(&r_ptr->name, head, s)) return (7);
2821 /* There better be a current r_ptr */
2822 else if (!r_ptr) return (3);
2827 /* 'E' から始まる行は英語名 */
2828 else if (buf[0] == 'E')
2830 /* Acquire the Text */
2833 /* Store the name */
2834 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2837 else if (buf[0] == 'E')
2839 /* Acquire the Text */
2842 /* Store the name */
2843 if (!add_name(&r_ptr->name, head, s)) return (7);
2846 /* Process 'D' for "Description" */
2847 else if (buf[0] == 'D')
2852 /* Acquire the text */
2857 /* Acquire the text */
2861 /* Store the text */
2862 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2865 /* Process 'G' for "Graphics" (one line only) */
2866 else if (buf[0] == 'G')
2872 if (buf[1] != ':') return (1);
2873 if (!buf[2]) return (1);
2874 if (buf[3] != ':') return (1);
2875 if (!buf[4]) return (1);
2877 /* Extract the char */
2880 /* Extract the attr */
2881 tmp = color_char_to_attr(buf[4]);
2884 if (tmp > 127) return (1);
2886 /* Save the values */
2887 r_ptr->d_char = sym;
2888 r_ptr->d_attr = tmp;
2891 /* Process 'I' for "Info" (one line only) */
2892 else if (buf[0] == 'I')
2894 int spd, hp1, hp2, aaf, ac, slp;
2896 /* Scan for the other values */
2897 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2898 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2900 /* Save the values */
2902 r_ptr->hdice = MAX(hp1, 1);
2903 r_ptr->hside = MAX(hp2, 1);
2909 /* Process 'W' for "More Info" (one line only) */
2910 else if (buf[0] == 'W')
2917 /* Scan for the values */
2918 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2919 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2921 /* Save the values */
2923 r_ptr->rarity = rar;
2926 r_ptr->next_exp = nextexp;
2927 r_ptr->next_r_idx = nextmon;
2930 /* Process 'R' for "Reinforcement" (up to six lines) */
2931 else if (buf[0] == 'R')
2934 /* Find the next empty blow slot (if any) */
2935 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
2937 /* Oops, no more slots */
2938 if (i == 6) return (1);
2940 /* Scan for the values */
2941 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
2942 r_ptr->reinforce_id[i] = id;
2943 r_ptr->reinforce_dd[i] = dd;
2944 r_ptr->reinforce_ds[i] = ds;
2947 /* Process 'B' for "Blows" (up to four lines) */
2948 else if (buf[0] == 'B')
2952 /* Find the next empty blow slot (if any) */
2953 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2955 /* Oops, no more slots */
2956 if (i == 4) return (1);
2958 /* Analyze the first field */
2959 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2961 /* Terminate the field (if necessary) */
2962 if (*t == ':') *t++ = '\0';
2964 /* Analyze the method */
2965 for (n1 = 0; r_info_blow_method[n1]; n1++)
2967 if (streq(s, r_info_blow_method[n1])) break;
2970 /* Invalid method */
2971 if (!r_info_blow_method[n1]) return (1);
2973 /* Analyze the second field */
2974 for (s = t; *t && (*t != ':'); t++) /* loop */;
2976 /* Terminate the field (if necessary) */
2977 if (*t == ':') *t++ = '\0';
2979 /* Analyze effect */
2980 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2982 if (streq(s, r_info_blow_effect[n2])) break;
2985 /* Invalid effect */
2986 if (!r_info_blow_effect[n2]) return (1);
2988 /* Analyze the third field */
2989 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2991 /* Terminate the field (if necessary) */
2992 if (*t == 'd') *t++ = '\0';
2994 /* Save the method */
2995 r_ptr->blow[i].method = n1;
2997 /* Save the effect */
2998 r_ptr->blow[i].effect = n2;
3000 /* Extract the damage dice and sides */
3001 r_ptr->blow[i].d_dice = atoi(s);
3002 r_ptr->blow[i].d_side = atoi(t);
3005 /* Process 'F' for "Basic Flags" (multiple lines) */
3006 else if (buf[0] == 'F')
3008 /* Parse every entry */
3009 for (s = buf + 2; *s; )
3011 /* Find the end of this entry */
3012 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3014 /* Nuke and skip any dividers */
3018 while (*t == ' ' || *t == '|') t++;
3021 /* Parse this entry */
3022 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3024 /* Start the next entry */
3029 /* Process 'S' for "Spell Flags" (multiple lines) */
3030 else if (buf[0] == 'S')
3032 /* Parse every entry */
3033 for (s = buf + 2; *s; )
3035 /* Find the end of this entry */
3036 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3038 /* Nuke and skip any dividers */
3042 while ((*t == ' ') || (*t == '|')) t++;
3045 /* XXX XXX XXX Hack -- Read spell frequency */
3046 if (1 == sscanf(s, "1_IN_%d", &i))
3048 /* Extract a "frequency" */
3049 r_ptr->freq_spell = 100 / i;
3051 /* Start at next entry */
3058 /* Parse this entry */
3059 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3061 /* Start the next entry */
3066 /* Process 'A' for "Artifact Flags" (multiple lines) */
3067 else if (buf[0] == 'A')
3069 int id, per, rarity;
3071 /* Find the next empty blow slot (if any) */
3072 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3074 /* Oops, no more slots */
3075 if (i == 4) return (1);
3077 if (3 != sscanf(buf+2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3078 r_ptr->artifact_id[i] = id;
3079 r_ptr->artifact_rarity[i] = rarity;
3080 r_ptr->artifact_percent[i] = per;
3083 /* Process 'V' for "Arena power value ratio" */
3084 else if (buf[0] == 'V')
3087 if (3 != sscanf(buf+2, "%d", &val)) return (1);
3088 r_ptr->arena_ratio = val;
3101 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3102 * Grab one flag for a dungeon type from a textual string
3103 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3104 * @param what 参照元の文字列ポインタ
3107 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3109 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3113 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3120 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3121 * Grab one (basic) flag in a monster_race from a textual string
3122 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3123 * @param what 参照元の文字列ポインタ
3126 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3128 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3131 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3134 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3137 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3140 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3143 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3146 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3150 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3157 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3158 * Grab one (spell) flag in a monster_race from a textual string
3159 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3160 * @param what 参照元の文字列ポインタ
3163 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3165 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3168 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3171 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3175 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3182 * @brief ダンジョン情報(d_info)のパース関数 /
3183 * Initialize the "d_info" array, by parsing an ascii "template" file
3185 * @param head ヘッダ構造体
3188 errr parse_d_info(char *buf, header *head)
3195 static dungeon_info_type *d_ptr = NULL;
3198 /* Process 'N' for "New/Number/Name" */
3201 /* Find the colon before the name */
3202 s = my_strchr(buf+2, ':');
3204 /* Verify that colon */
3207 /* Nuke the colon, advance to the name */
3210 /* Paranoia -- require a name */
3211 if (!*s) return (1);
3216 /* Verify information */
3217 if (i < error_idx) return (4);
3219 /* Verify information */
3220 if (i >= head->info_num) return (2);
3222 /* Save the index */
3225 /* Point at the "info" */
3228 /* Store the name */
3229 if (!add_name(&d_ptr->name, head, s)) return (7);
3234 else if (buf[0] == 'E') return (0);
3236 else if (buf[0] == 'E')
3238 /* Acquire the Text */
3241 /* Store the name */
3242 if (!add_name(&d_ptr->name, head, s)) return (7);
3246 /* Process 'D' for "Description */
3247 else if (buf[0] == 'D')
3252 /* Acquire the text */
3257 /* Acquire the text */
3261 /* Store the text */
3262 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3265 /* Process 'W' for "More Info" (one line only) */
3266 else if (buf[0] == 'W')
3268 int min_lev, max_lev;
3270 int min_alloc, max_chance;
3271 int obj_good, obj_great;
3274 /* Scan for the values */
3275 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3276 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3278 /* Save the values */
3279 d_ptr->mindepth = min_lev;
3280 d_ptr->maxdepth = max_lev;
3281 d_ptr->min_plev = min_plev;
3283 d_ptr->min_m_alloc_level = min_alloc;
3284 d_ptr->max_m_alloc_chance = max_chance;
3285 d_ptr->obj_good = obj_good;
3286 d_ptr->obj_great = obj_great;
3291 /* Process 'P' for "Place Info" */
3292 else if (buf[0] == 'P')
3296 /* Scan for the values */
3297 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3299 /* Save the values */
3304 /* Process 'L' for "fLoor type" (one line only) */
3305 else if (buf[0] == 'L')
3309 /* Scan for the values */
3310 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3312 /* Save the values */
3313 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3315 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3316 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3318 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3320 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3323 /* Process 'A' for "wAll type" (one line only) */
3324 else if (buf[0] == 'A')
3328 /* Scan for the values */
3329 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3331 /* Save the values */
3332 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3334 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3335 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3337 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3340 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3341 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3343 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3344 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3346 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3347 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3349 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3350 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3353 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3354 else if (buf[0] == 'F')
3356 int artif = 0, monst = 0;
3358 /* Parse every entry */
3359 for (s = buf + 2; *s; )
3361 /* Find the end of this entry */
3362 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3364 /* Nuke and skip any dividers */
3368 while (*t == ' ' || *t == '|') t++;
3371 /* XXX XXX XXX Hack -- Read Final Artifact */
3372 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3374 /* Extract a "Final Artifact" */
3375 d_ptr->final_artifact = artif;
3377 /* Start at next entry */
3384 /* XXX XXX XXX Hack -- Read Final Object */
3385 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3387 /* Extract a "Final Artifact" */
3388 d_ptr->final_object = artif;
3390 /* Start at next entry */
3397 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3398 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3400 /* Extract a "Artifact Guardian" */
3401 d_ptr->final_guardian = monst;
3403 /* Start at next entry */
3410 /* XXX XXX XXX Hack -- Read Special Percentage */
3411 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3413 /* Extract a "Special %" */
3414 d_ptr->special_div = monst;
3416 /* Start at next entry */
3423 /* Parse this entry */
3424 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3426 /* Start the next entry */
3431 /* Process 'M' for "Basic Flags" (multiple lines) */
3432 else if (buf[0] == 'M')
3434 /* Parse every entry */
3435 for (s = buf + 2; *s; )
3437 /* Find the end of this entry */
3438 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3440 /* Nuke and skip any dividers */
3444 while (*t == ' ' || *t == '|') t++;
3447 /* Hack -- Read monster symbols */
3448 if (!strncmp(s, "R_CHAR_", 7))
3450 /* Skip "R_CHAR_" */
3454 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3456 /* Start at next entry */
3463 /* Parse this entry */
3464 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3466 /* Start the next entry */
3471 /* Process 'S' for "Spell Flags" (multiple lines) */
3472 else if (buf[0] == 'S')
3474 /* Parse every entry */
3475 for (s = buf + 2; *s; )
3477 /* Find the end of this entry */
3478 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3480 /* Nuke and skip any dividers */
3484 while ((*t == ' ') || (*t == '|')) t++;
3487 /* XXX XXX XXX Hack -- Read spell frequency */
3488 if (1 == sscanf(s, "1_IN_%d", &i))
3490 /* Start at next entry */
3497 /* Parse this entry */
3498 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3500 /* Start the next entry */
3513 #else /* ALLOW_TEMPLATES */
3519 #endif /* ALLOW_TEMPLATES */
3522 /* Random dungeon grid effects */
3523 #define RANDOM_NONE 0x00000000
3524 #define RANDOM_FEATURE 0x00000001
3525 #define RANDOM_MONSTER 0x00000002
3526 #define RANDOM_OBJECT 0x00000004
3527 #define RANDOM_EGO 0x00000008
3528 #define RANDOM_ARTIFACT 0x00000010
3529 #define RANDOM_TRAP 0x00000020
3532 typedef struct dungeon_grid dungeon_grid;
3536 int feature; /* Terrain feature */
3537 int monster; /* Monster */
3538 int object; /* Object */
3539 int ego; /* Ego-Item */
3540 int artifact; /* Artifact */
3541 int trap; /* Trap */
3542 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3543 int special; /* Reserved for special terrain info */
3544 int random; /* Number of the random effect */
3548 static dungeon_grid letter[255];
3552 * @brief 地形情報の「F:」情報をパースする
3553 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3557 static errr parse_line_feature(char *buf)
3563 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3565 /* Tokenize the line */
3566 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3568 /* Letter to assign */
3569 int index = zz[0][0];
3571 /* Reset the info for the letter */
3572 letter[index].feature = feat_none;
3573 letter[index].monster = 0;
3574 letter[index].object = 0;
3575 letter[index].ego = 0;
3576 letter[index].artifact = 0;
3577 letter[index].trap = feat_none;
3578 letter[index].cave_info = 0;
3579 letter[index].special = 0;
3580 letter[index].random = RANDOM_NONE;
3586 letter[index].special = atoi(zz[8]);
3590 if ((zz[7][0] == '*') && !zz[7][1])
3592 letter[index].random |= RANDOM_TRAP;
3596 letter[index].trap = f_tag_to_index(zz[7]);
3597 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3602 if (zz[6][0] == '*')
3604 letter[index].random |= RANDOM_ARTIFACT;
3605 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3607 else if (zz[6][0] == '!')
3609 if (p_ptr->inside_quest)
3611 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3616 letter[index].artifact = atoi(zz[6]);
3621 if (zz[5][0] == '*')
3623 letter[index].random |= RANDOM_EGO;
3624 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3628 letter[index].ego = atoi(zz[5]);
3633 if (zz[4][0] == '*')
3635 letter[index].random |= RANDOM_OBJECT;
3636 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3638 else if (zz[4][0] == '!')
3640 if (p_ptr->inside_quest)
3642 int a_idx = quest[p_ptr->inside_quest].k_idx;
3645 artifact_type *a_ptr = &a_info[a_idx];
3646 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3648 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3655 letter[index].object = atoi(zz[4]);
3660 if (zz[3][0] == '*')
3662 letter[index].random |= RANDOM_MONSTER;
3663 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3665 else if (zz[3][0] == 'c')
3667 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3668 letter[index].monster = - atoi(zz[3] + 1);
3672 letter[index].monster = atoi(zz[3]);
3677 letter[index].cave_info = atoi(zz[2]);
3681 if ((zz[1][0] == '*') && !zz[1][1])
3683 letter[index].random |= RANDOM_FEATURE;
3687 letter[index].feature = f_tag_to_index(zz[1]);
3688 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3701 * @brief 地形情報の「B:」情報をパースする
3702 * Process "B:<Index>:<Command>:..." -- Building definition
3706 static errr parse_line_building(char *buf)
3722 /* Get the building number */
3725 /* Find the colon after the building number */
3726 s = my_strchr(s, ':');
3728 /* Verify that colon */
3731 /* Nuke the colon, advance to the sub-index */
3734 /* Paranoia -- require a sub-index */
3735 if (!*s) return (1);
3737 /* Building definition sub-index */
3740 /* Building name, owner, race */
3743 if (tokenize(s + 2, 3, zz, 0) == 3)
3745 /* Name of the building */
3746 strcpy(building[index].name, zz[0]);
3748 /* Name of the owner */
3749 strcpy(building[index].owner_name, zz[1]);
3751 /* Race of the owner */
3752 strcpy(building[index].owner_race, zz[2]);
3757 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3760 /* Building Action */
3763 if (tokenize(s + 2, 8, zz, 0) >= 7)
3765 /* Index of the action */
3766 int action_index = atoi(zz[0]);
3768 /* Name of the action */
3769 strcpy(building[index].act_names[action_index], zz[1]);
3771 /* Cost of the action for members */
3772 building[index].member_costs[action_index] = atoi(zz[2]);
3774 /* Cost of the action for non-members */
3775 building[index].other_costs[action_index] = atoi(zz[3]);
3777 /* Letter assigned to the action */
3778 building[index].letters[action_index] = zz[4][0];
3781 building[index].actions[action_index] = atoi(zz[5]);
3783 /* Action restriction */
3784 building[index].action_restr[action_index] = atoi(zz[6]);
3789 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3792 /* Building Classes */
3795 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3797 for (i = 0; i < MAX_CLASS; i++)
3799 building[index].member_class[i] = atoi(zz[i]);
3805 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3808 /* Building Races */
3811 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3813 for (i = 0; i < MAX_RACES; i++)
3815 building[index].member_race[i] = atoi(zz[i]);
3821 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3824 /* Building Realms */
3827 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3829 for (i = 0; i < MAX_MAGIC; i++)
3831 building[index].member_realm[i+1] = atoi(zz[i]);
3837 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3842 /* Ignore scripts */
3848 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3857 * @brief フロアの所定のマスにオブジェクトを配置する
3858 * Place the object j_ptr to a grid
3859 * @param j_ptr オブジェクト構造体の参照ポインタ
3864 static void drop_here(object_type *j_ptr, int y, int x)
3866 cave_type *c_ptr = &cave[y][x];
3869 /* Get new object */
3870 s16b o_idx = o_pop();
3872 /* Access new object */
3873 o_ptr = &o_list[o_idx];
3875 /* Structure copy */
3876 object_copy(o_ptr, j_ptr);
3884 o_ptr->held_m_idx = 0;
3887 o_ptr->next_o_idx = c_ptr->o_idx;
3889 /* Place the object */
3890 c_ptr->o_idx = o_idx;
3895 * @brief クエスト用固定ダンジョンをフロアに生成する
3896 * Parse a sub-file of the "extra info"
3906 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3913 /* Skip "empty" lines */
3914 if (!buf[0]) return (0);
3916 /* Skip "blank" lines */
3917 if (iswspace(buf[0])) return (0);
3920 if (buf[0] == '#') return (0);
3922 /* Require "?:*" format */
3923 if (buf[1] != ':') return (1);
3926 /* Process "%:<fname>" */
3929 /* Attempt to Process the given file */
3930 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3933 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3936 return parse_line_feature(buf);
3939 /* Process "D:<dungeon>" -- info for the cave grids */
3940 else if (buf[0] == 'D')
3942 object_type object_type_body;
3944 /* Acquire the text */
3947 /* Length of the text */
3948 int len = strlen(s);
3950 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3952 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3954 /* Access the grid */
3955 cave_type *c_ptr = &cave[*y][*x];
3959 int object_index = letter[idx].object;
3960 int monster_index = letter[idx].monster;
3961 int random = letter[idx].random;
3962 int artifact_index = letter[idx].artifact;
3964 /* Lay down a floor */
3965 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3967 /* Only the features */
3968 if (init_flags & INIT_ONLY_FEATURES) continue;
3971 c_ptr->info = letter[idx].cave_info;
3973 /* Create a monster */
3974 if (random & RANDOM_MONSTER)
3976 monster_level = base_level + monster_index;
3978 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3980 monster_level = base_level;
3982 else if (monster_index)
3984 int old_cur_num, old_max_num;
3987 if (monster_index < 0)
3989 monster_index = -monster_index;
3992 old_cur_num = r_info[monster_index].cur_num;
3993 old_max_num = r_info[monster_index].max_num;
3995 /* Make alive again */
3996 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3998 r_info[monster_index].cur_num = 0;
3999 r_info[monster_index].max_num = 1;
4002 /* Make alive again */
4003 /* Hack -- Non-unique Nazguls are semi-unique */
4004 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
4006 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
4008 r_info[monster_index].max_num++;
4013 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4017 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4019 /* Make alive again for real unique monster */
4020 r_info[monster_index].cur_num = old_cur_num;
4021 r_info[monster_index].max_num = old_max_num;
4025 /* Object (and possible trap) */
4026 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4028 object_level = base_level + object_index;
4031 * Random trap and random treasure defined
4032 * 25% chance for trap and 75% chance for object
4034 if (randint0(100) < 75)
4036 place_object(*y, *x, 0L);
4043 object_level = base_level;
4045 else if (random & RANDOM_OBJECT)
4047 object_level = base_level + object_index;
4049 /* Create an out of deep object */
4050 if (randint0(100) < 75)
4051 place_object(*y, *x, 0L);
4052 else if (randint0(100) < 80)
4053 place_object(*y, *x, AM_GOOD);
4055 place_object(*y, *x, AM_GOOD | AM_GREAT);
4057 object_level = base_level;
4060 else if (random & RANDOM_TRAP)
4064 /* Hidden trap (or door) */
4065 else if (letter[idx].trap)
4067 c_ptr->mimic = c_ptr->feat;
4068 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4070 else if (object_index)
4072 /* Get local object */
4073 object_type *o_ptr = &object_type_body;
4075 /* Create the item */
4076 object_prep(o_ptr, object_index);
4078 if (o_ptr->tval == TV_GOLD)
4080 coin_type = object_index - OBJ_GOLD_LIST;
4085 /* Apply magic (no messages, no artifacts) */
4086 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4088 drop_here(o_ptr, *y, *x);
4094 if (a_info[artifact_index].cur_num)
4096 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4098 object_type *q_ptr = &forge;
4100 object_prep(q_ptr, k_idx);
4102 /* Drop it in the dungeon */
4103 drop_here(q_ptr, *y, *x);
4107 /* Create the artifact */
4108 if (create_named_art(artifact_index, *y, *x))
4109 a_info[artifact_index].cur_num = 1;
4113 /* Terrain special */
4114 c_ptr->special = letter[idx].special;
4122 /* Process "Q:<number>:<command>:... -- quest info */
4123 else if (buf[0] == 'Q')
4130 num = tokenize(buf + 2, 33, zz, 0);
4134 num = tokenize(buf + 3, 33, zz, 0);
4137 /* Have we enough parameters? */
4138 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4141 q_ptr = &(quest[atoi(zz[0])]);
4143 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4144 if (zz[1][0] == 'Q')
4146 if (init_flags & INIT_ASSIGN)
4148 monster_race *r_ptr;
4149 artifact_type *a_ptr;
4151 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4153 q_ptr->type = atoi(zz[2]);
4154 q_ptr->num_mon = atoi(zz[3]);
4155 q_ptr->cur_num = atoi(zz[4]);
4156 q_ptr->max_num = atoi(zz[5]);
4157 q_ptr->level = atoi(zz[6]);
4158 q_ptr->r_idx = atoi(zz[7]);
4159 q_ptr->k_idx = atoi(zz[8]);
4160 q_ptr->dungeon = atoi(zz[9]);
4163 q_ptr->flags = atoi(zz[10]);
4165 r_ptr = &r_info[q_ptr->r_idx];
4166 if (r_ptr->flags1 & RF1_UNIQUE)
4167 r_ptr->flags1 |= RF1_QUESTOR;
4169 a_ptr = &a_info[q_ptr->k_idx];
4170 a_ptr->gen_flags |= TRG_QUESTITEM;
4175 else if (zz[1][0] == 'R')
4177 if (init_flags & INIT_ASSIGN)
4182 for (idx = 2; idx < num; idx++)
4184 int a_idx = atoi(zz[idx]);
4185 if (a_idx < 1) continue;
4186 if (a_info[a_idx].cur_num > 0) continue;
4188 if (one_in_(count)) reward_idx = a_idx;
4193 /* Set quest's rewarding artifact */
4194 q_ptr->k_idx = reward_idx;
4195 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4199 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4200 q_ptr->type = QUEST_TYPE_KILL_ALL;
4207 /* Process "Q:<q_index>:N:<name>" -- quest name */
4208 else if (zz[1][0] == 'N')
4210 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4212 strcpy(q_ptr->name, zz[2]);
4218 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4219 else if (zz[1][0] == 'T')
4221 if (init_flags & INIT_SHOW_TEXT)
4223 strcpy(quest_text[quest_text_line], zz[2]);
4231 /* Process "W:<command>: ..." -- info for the wilderness */
4232 else if (buf[0] == 'W')
4234 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4237 /* Process "P:<y>:<x>" -- player position */
4238 else if (buf[0] == 'P')
4240 if (init_flags & INIT_CREATE_DUNGEON)
4242 if (tokenize(buf + 2, 2, zz, 0) == 2)
4244 int panels_x, panels_y;
4246 /* Hack - Set the dungeon size */
4247 panels_y = (*y / SCREEN_HGT);
4248 if (*y % SCREEN_HGT) panels_y++;
4249 cur_hgt = panels_y * SCREEN_HGT;
4251 panels_x = (*x / SCREEN_WID);
4252 if (*x % SCREEN_WID) panels_x++;
4253 cur_wid = panels_x * SCREEN_WID;
4255 /* Assume illegal panel */
4256 panel_row_min = cur_hgt;
4257 panel_col_min = cur_wid;
4259 /* Place player in a quest level */
4260 if (p_ptr->inside_quest)
4264 /* Delete the monster (if any) */
4265 delete_monster(p_ptr->y, p_ptr->x);
4273 /* Place player in the town */
4274 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4276 p_ptr->oldpy = atoi(zz[0]);
4277 p_ptr->oldpx = atoi(zz[1]);
4285 /* Process "B:<Index>:<Command>:..." -- Building definition */
4286 else if (buf[0] == 'B')
4288 return parse_line_building(buf);
4291 /* Process "M:<type>:<maximum>" -- set maximum values */
4292 else if (buf[0] == 'M')
4294 if (tokenize(buf+2, 2, zz, 0) == 2)
4297 if (zz[0][0] == 'T')
4299 max_towns = atoi(zz[1]);
4302 /* Maximum quests */
4303 else if (zz[0][0] == 'Q')
4305 max_quests = atoi(zz[1]);
4309 else if (zz[0][0] == 'R')
4311 max_r_idx = atoi(zz[1]);
4315 else if (zz[0][0] == 'K')
4317 max_k_idx = atoi(zz[1]);
4321 else if (zz[0][0] == 'V')
4323 max_v_idx = atoi(zz[1]);
4327 else if (zz[0][0] == 'F')
4329 max_f_idx = atoi(zz[1]);
4333 else if (zz[0][0] == 'A')
4335 max_a_idx = atoi(zz[1]);
4339 else if (zz[0][0] == 'E')
4341 max_e_idx = atoi(zz[1]);
4345 else if (zz[0][0] == 'D')
4347 max_d_idx = atoi(zz[1]);
4351 else if (zz[0][0] == 'O')
4353 max_o_idx = atoi(zz[1]);
4357 else if (zz[0][0] == 'M')
4359 max_m_idx = atoi(zz[1]);
4362 /* Wilderness size */
4363 else if (zz[0][0] == 'W')
4365 /* Maximum wild_x_size */
4366 if (zz[0][1] == 'X')
4367 max_wild_x = atoi(zz[1]);
4368 /* Maximum wild_y_size */
4369 if (zz[0][1] == 'Y')
4370 max_wild_y = atoi(zz[1]);
4384 static cptr variant = "ZANGBAND";
4388 * @brief クエスト用固定ダンジョン生成時の分岐処理
4389 * Helper function for "process_dungeon_file()"
4394 static cptr process_dungeon_file_expr(char **sp, char *fp)
4410 while (iswspace(*s)) s++;
4428 t = process_dungeon_file_expr(&s, &f);
4437 else if (streq(t, "IOR"))
4440 while (*s && (f != b2))
4442 t = process_dungeon_file_expr(&s, &f);
4443 if (*t && !streq(t, "0")) v = "1";
4448 else if (streq(t, "AND"))
4451 while (*s && (f != b2))
4453 t = process_dungeon_file_expr(&s, &f);
4454 if (*t && streq(t, "0")) v = "0";
4459 else if (streq(t, "NOT"))
4462 while (*s && (f != b2))
4464 t = process_dungeon_file_expr(&s, &f);
4465 if (*t && streq(t, "1")) v = "0";
4470 else if (streq(t, "EQU"))
4473 if (*s && (f != b2))
4475 t = process_dungeon_file_expr(&s, &f);
4477 while (*s && (f != b2))
4479 p = process_dungeon_file_expr(&s, &f);
4480 if (streq(t, p)) v = "1";
4485 else if (streq(t, "LEQ"))
4488 if (*s && (f != b2))
4490 t = process_dungeon_file_expr(&s, &f);
4492 while (*s && (f != b2))
4495 t = process_dungeon_file_expr(&s, &f);
4496 if (*t && atoi(p) > atoi(t)) v = "0";
4501 else if (streq(t, "GEQ"))
4504 if (*s && (f != b2))
4506 t = process_dungeon_file_expr(&s, &f);
4508 while (*s && (f != b2))
4511 t = process_dungeon_file_expr(&s, &f);
4513 /* Compare two numbers instead of string */
4514 if (*t && atoi(p) < atoi(t)) v = "0";
4521 while (*s && (f != b2))
4523 t = process_dungeon_file_expr(&s, &f);
4528 if (f != b2) v = "?x?x?";
4530 /* Extract final and Terminate */
4531 if ((f = *s) != '\0') *s++ = '\0';
4537 /* Accept all printables except spaces and brackets */
4539 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4541 if (iskanji(*s)) s++;
4545 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4548 /* Extract final and Terminate */
4549 if ((f = *s) != '\0') *s++ = '\0';
4555 if (streq(b+1, "SYS"))
4561 else if (streq(b+1, "GRAF"))
4566 else if (streq(b+1, "MONOCHROME"))
4575 else if (streq(b+1, "RACE"))
4577 v = _(rp_ptr->E_title, rp_ptr->title);
4581 else if (streq(b+1, "CLASS"))
4583 v = _(cp_ptr->E_title, cp_ptr->title);
4587 else if (streq(b+1, "REALM1"))
4589 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4593 else if (streq(b+1, "REALM2"))
4595 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4599 else if (streq(b+1, "PLAYER"))
4601 static char tmp_player_name[32];
4603 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4613 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4616 v = tmp_player_name;
4620 else if (streq(b+1, "TOWN"))
4622 sprintf(tmp, "%d", p_ptr->town_num);
4627 else if (streq(b+1, "LEVEL"))
4629 sprintf(tmp, "%d", p_ptr->lev);
4633 /* Current quest number */
4634 else if (streq(b+1, "QUEST_NUMBER"))
4636 sprintf(tmp, "%d", p_ptr->inside_quest);
4640 /* Number of last quest */
4641 else if (streq(b+1, "LEAVING_QUEST"))
4643 sprintf(tmp, "%d", leaving_quest);
4648 else if (prefix(b+1, "QUEST_TYPE"))
4650 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4651 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4656 else if (prefix(b+1, "QUEST"))
4658 /* "QUEST" uses a special parameter to determine the number of the quest */
4659 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4664 else if (prefix(b+1, "RANDOM"))
4666 /* "RANDOM" uses a special parameter to determine the number of the quest */
4667 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4672 else if (streq(b+1, "VARIANT"))
4678 else if (streq(b+1, "WILDERNESS"))
4681 sprintf(tmp, "NONE");
4683 sprintf(tmp, "LITE");
4685 sprintf(tmp, "NORMAL");
4709 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4710 * Helper function for "process_dungeon_file()"
4718 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4728 bool bypass = FALSE;
4730 int x = xmin, y = ymin;
4733 /* Build the filename */
4734 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4737 fp = my_fopen(buf, "r");
4740 if (!fp) return (-1);
4743 /* Process the file */
4744 while (0 == my_fgets(fp, buf, sizeof(buf)))
4750 /* Skip "empty" lines */
4751 if (!buf[0]) continue;
4753 /* Skip "blank" lines */
4754 if (iswspace(buf[0])) continue;
4757 if (buf[0] == '#') continue;
4760 /* Process "?:<expr>" */
4761 if ((buf[0] == '?') && (buf[1] == ':'))
4770 /* Parse the expr */
4771 v = process_dungeon_file_expr(&s, &f);
4774 bypass = (streq(v, "0") ? TRUE : FALSE);
4780 /* Apply conditionals */
4781 if (bypass) continue;
4783 /* Process the line */
4784 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4796 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4799 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4800 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);
4806 /* Close the file */
4816 void write_r_info_txt(void)
4818 int i, j, z, fc, bc;
4821 cptr flags[32 * 10];
4826 monster_race *r_ptr;
4828 monster_blow *b_ptr;
4830 FILE *fff = fopen("output.txt", "wt");
4838 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4840 fprintf(fff, "# Version stamp (required)\n\n");
4843 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4846 fprintf(fff, "##### The Player #####\n\n");
4848 for (z = -1; z < alloc_race_size; z++)
4850 /* Output the monsters in order */
4851 i = (z >= 0) ? alloc_race_table[z].index : 0;
4853 /* Acquire the monster */
4856 /* Ignore empty monsters */
4857 if (!strlen(r_name + r_ptr->name)) continue;
4859 /* Ignore useless monsters */
4860 if (i && !r_ptr->speed) continue;
4862 /* Write a note if necessary */
4863 if (i && (!r_ptr->level != !mode))
4868 fprintf(fff, "\n##### Town monsters #####\n\n");
4870 /* Note the dungeon */
4873 fprintf(fff, "\n##### Normal monsters #####\n\n");
4876 /* Record the change */
4877 mode = r_ptr->level;
4880 /* Acquire the flags */
4881 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4882 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4883 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4884 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4885 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4886 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4887 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4888 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4889 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4890 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4892 /* Write New/Number/Name */
4893 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4896 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4898 /* Write Information */
4899 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4900 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4902 /* Write more information */
4903 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4906 for(j = 0; j < 4; j++)
4908 b_ptr = &(r_ptr->blow[j]);
4910 /* Stop when done */
4911 if (!b_ptr->method) break;
4913 /* Write the blows */
4914 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4915 r_info_blow_effect[b_ptr->effect],
4916 b_ptr->d_dice, b_ptr->d_side);
4919 /* Extract the flags */
4920 for (fc = 0, j = 0; j < 32 * 3; j++)
4922 /* Check this flag */
4923 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4926 /* Extract the extra flags */
4927 for (j = 32 * 6; j < 32 * 10; j++)
4929 /* Check this flag */
4930 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4933 /* Write the flags */
4934 for (j = 0; j < fc;)
4938 /* Start the line */
4941 for (bc = 0; (bc < 60) && (j < fc); j++)
4945 /* Format the flag */
4946 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4948 /* Add it to the buffer */
4951 /* Note the length */
4955 /* Done with this line; write it */
4956 fprintf(fff, "%s\n", buf);
4959 /* Write Spells if applicable */
4960 if (r_ptr->freq_spell)
4962 /* Write the frequency */
4963 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4965 /* Extract the spell flags */
4966 for (fc = 0, j = 96; j < 192; j++)
4968 /* Check this flag */
4969 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4972 /* Write the flags */
4973 for (j = 0; j < fc;)
4977 /* Start the line */
4980 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4984 /* Format the flag */
4985 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4989 /* Note the length */
4996 /* Done with this line; write it */
4997 fprintf(fff, "%s\n", buf);
5001 /* Acquire the description */
5002 desc = r_text + r_ptr->text;
5003 dlen = strlen(desc);
5005 /* Write Description */
5006 for (j = 0; j < dlen;)
5010 /* Start the line */
5013 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
5021 /* Done with this line; write it */
5022 fprintf(fff, "%s\n", buf);
5025 /* Space between entries */