3 * @brief ゲームデータ初期化1 / Initialization (part 1) -BEN-
7 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 * This software may be copied and distributed for educational, research,
9 * and not for profit purposes provided that this copyright and statement
10 * are included in all such copies. Other copyrights may also apply.
11 * 2014 Deskull rearranged comment for Doxygen.\n
15 * This file is used to initialize various variables and arrays for the
16 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
17 * the common limitation of "read()" and "write()" to only 32767 bytes
19 * Several of the arrays for Angband are built from "template" files in
20 * the "lib/file" directory, from which quick-load binary "image" files
21 * are constructed whenever they are not present in the "lib/data"
22 * directory, or if those files become obsolete, if we are allowed.
23 * Warning -- the "ascii" file parsers use a minor hack to collect the
24 * name and text information in a single pass. Thus, the game will not
25 * be able to load any template file with more than 20K of names or 60K
26 * of text, even though technically, up to 64K should be legal.
28 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
29 * in this file is compiled out, and the game will not run unless valid
30 * "binary template files" already exist in "lib/data". Thus, one can
31 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
32 * "*.raw" files in "lib/data", and then quit, and recompile without
33 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
34 * from changing the ascii template files in potentially dangerous ways.
35 * ノートとして記録:ALLOW_TEMPLATESが定義されていない場合、
36 * このファイルのコードの多くはコンパイル出力され、本ゲームは
37 * 正規の「バイナリテンプレートファイル」がlib/dataファイル内に
38 * 存在しない限り起動しなくなる。一方ALLOW_TEMPLATESが定義されている
39 * ならば1度ゲームが起動するごとに*.rawファイル群が作成され、終了時には
40 * ALLOW_TEMPLATEの定義に関係なくリコンパイルされる。これにより20K(バイト?)
41 * のデータが保存され、プレイヤーが潜在的に危険な方法でascii文字の
42 * テンプレートファイルを変更することを妨げることができる。
43 * The code could actually be removed and placed into a "stand-alone"
44 * program, but that feels a little silly, especially considering some
45 * of the platforms that we currently support.
53 #ifdef ALLOW_TEMPLATES
58 /*** Helper arrays for parsing ascii template files ***/
62 * Monster Blow Methods
64 static cptr r_info_blow_method[] =
98 * Monster Blow Effects
100 static cptr r_info_blow_effect[] =
145 static cptr f_info_flags[] =
270 static cptr r_info_flags1[] =
310 static cptr r_info_flags2[] =
350 static cptr r_info_flags3[] =
390 static cptr r_info_flags4[] =
427 * モンスター特性トークン(発動型能力1) /
430 static cptr r_a_ability_flags1[] =
467 * モンスター特性トークン(発動型能力2) /
470 static cptr r_a_ability_flags2[] =
487 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
507 * モンスター特性トークン(発動型能力3) /
510 static cptr r_a_ability_flags3[] =
547 * モンスター特性トークン(発動型能力4) /
550 static cptr r_a_ability_flags4[] =
591 static cptr r_info_flags7[] =
631 static cptr r_info_flags8[] =
663 "WILD_SWAMP", /* ToDo: Implement Swamp */
672 static cptr r_info_flags9[] =
711 * モンスター特性トークンの定義R(耐性) /
714 static cptr r_info_flagsr[] =
752 * オブジェクト基本特性トークンの定義 /
755 static cptr k_info_flags[] =
852 "XXX3", /* Fake flag for Smith */
853 "XXX4", /* Fake flag for Smith */
903 * オブジェクト生成特性トークンの定義 /
906 static cptr k_info_gen_flags[] =
946 static cptr d_info_flags1[] =
984 * @brief データの可変文字列情報をテキストとして保管する /
985 * Add a text to the text-storage and store offset to it.
986 * @param offset 文字列保管ポインタからのオフセット
987 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
989 * @param normal_text テキストの正規化を行う
992 * Returns FALSE when there isn't enough space available to store
995 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
997 /* Hack -- Verify space */
998 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1004 /* Advance and save the text index */
1005 *offset = ++head->text_size;
1008 /* Additional text */
1009 else if (normal_text)
1012 * If neither the end of the last line nor
1013 * the beginning of current line is not a space,
1014 * fill up a space as a correct separator of two words.
1016 if (head->text_size > 0 &&
1018 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1019 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1020 (buf[0] != ' ') && !iskanji(buf[0])
1022 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1027 /* Append a space */
1028 *(head->text_ptr + head->text_size) = ' ';
1030 /* Advance the index */
1035 /* Append chars to the text */
1036 strcpy(head->text_ptr + head->text_size, buf);
1038 /* Advance the index */
1039 head->text_size += strlen(buf);
1047 * @brief データの可変文字列情報を名前として保管する /
1048 * Add a name to the name-storage and return an offset to it.
1049 * @param offset 文字列保管ポインタからのオフセット
1050 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1054 * Returns FALSE when there isn't enough space available to store
1057 static bool add_name(u32b *offset, header *head, cptr buf)
1059 /* Hack -- Verify space */
1060 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1066 /* Advance and save the name index */
1067 *offset = ++head->name_size;
1070 /* Append chars to the names */
1071 strcpy(head->name_ptr + head->name_size, buf);
1073 /* Advance the index */
1074 head->name_size += strlen(buf);
1082 * @brief データの可変文字列情報をタグとして保管する /
1083 * Add a tag to the tag-storage and return an offset to it.
1084 * @param offset 文字列保管ポインタからのオフセット
1085 * @param head テキスト保管ヘッダ情報の構造体参照ポインタ
1089 * Returns FALSE when there isn't enough space available to store
1092 static bool add_tag(STR_OFFSET *offset, header *head, cptr buf)
1096 /* Search for an existing (fake) tag */
1097 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1100 if (streq(&head->tag_ptr[i], buf)) break;
1103 /* There was no existing tag */
1104 if (i >= head->tag_size)
1106 /* Hack -- Verify space */
1107 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1110 /* Append chars to the tags */
1111 strcpy(head->tag_ptr + head->tag_size, buf);
1113 /* Point the new tag */
1116 /* Advance the index */
1117 head->tag_size += strlen(buf) + 1;
1120 /* Return offset of the tag */
1129 * @brief シンボル1文字をカラーIDに変更する /
1130 * Convert a "color letter" into an "actual" color
1131 * The colors are: dwsorgbuDWvyRGBU, as shown below
1135 byte color_char_to_attr(char c)
1139 case 'd': return (TERM_DARK);
1140 case 'w': return (TERM_WHITE);
1141 case 's': return (TERM_SLATE);
1142 case 'o': return (TERM_ORANGE);
1143 case 'r': return (TERM_RED);
1144 case 'g': return (TERM_GREEN);
1145 case 'b': return (TERM_BLUE);
1146 case 'u': return (TERM_UMBER);
1148 case 'D': return (TERM_L_DARK);
1149 case 'W': return (TERM_L_WHITE);
1150 case 'v': return (TERM_VIOLET);
1151 case 'y': return (TERM_YELLOW);
1152 case 'R': return (TERM_L_RED);
1153 case 'G': return (TERM_L_GREEN);
1154 case 'B': return (TERM_L_BLUE);
1155 case 'U': return (TERM_L_UMBER);
1163 /*** Initialize from ascii template files ***/
1167 * @brief パース関数に基づいてデータファイルからデータを読み取る /
1168 * Initialize an "*_info" array, by parsing an ascii "template" file
1169 * @param fp 読み取りに使うファイルポインタ
1170 * @param buf 読み取りに使うバッファ領域
1171 * @param head ヘッダ構造体
1172 * @param parse_info_txt_line パース関数
1175 errr init_info_txt(FILE *fp, char *buf, header *head,
1176 parse_info_txt_func parse_info_txt_line)
1180 /* Just before the first record */
1183 /* Just before the first line */
1187 /* Prepare the "fake" stuff */
1188 head->name_size = 0;
1189 head->text_size = 0;
1193 while (0 == my_fgets(fp, buf, 1024))
1195 /* Advance the line number */
1198 /* Skip comments and blank lines */
1199 if (!buf[0] || (buf[0] == '#')) continue;
1201 /* Verify correct "colon" format */
1202 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1205 /* Hack -- Process 'V' for "Version" */
1212 /* Mega Hack -- Calculate Check Sum */
1213 if (buf[0] != 'N' && buf[0] != 'D')
1216 for (i = 0; buf[i]; i++)
1218 head->v_extra += (byte)buf[i];
1219 head->v_extra ^= (1 << (i % 8));
1223 /* Parse the line */
1224 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1229 /* Complete the "name" and "text" sizes */
1230 if (head->name_size) head->name_size++;
1231 if (head->text_size) head->text_size++;
1239 * @brief Vault情報(v_info)のパース関数 /
1240 * Initialize the "v_info" array, by parsing an ascii "template" file
1242 * @param head ヘッダ構造体
1245 errr parse_v_info(char *buf, header *head)
1251 static vault_type *v_ptr = NULL;
1253 /* Process 'N' for "New/Number/Name" */
1256 /* Find the colon before the name */
1257 s = my_strchr(buf+2, ':');
1259 /* Verify that colon */
1262 /* Nuke the colon, advance to the name */
1265 /* Paranoia -- require a name */
1266 if (!*s) return (1);
1271 /* Verify information */
1272 if (i <= error_idx) return (4);
1274 /* Verify information */
1275 if (i >= head->info_num) return (2);
1277 /* Save the index */
1280 /* Point at the "info" */
1283 /* Store the name */
1284 if (!add_name(&v_ptr->name, head, s)) return (7);
1287 /* There better be a current v_ptr */
1288 else if (!v_ptr) return (3);
1290 /* Process 'D' for "Description" */
1291 else if (buf[0] == 'D')
1293 /* Acquire the text */
1296 /* Store the text */
1297 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1300 /* Process 'X' for "Extra info" (one line only) */
1301 else if (buf[0] == 'X')
1303 int typ, rat, hgt, wid;
1305 /* Scan for the values */
1306 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1307 &typ, &rat, &hgt, &wid)) return (1);
1309 /* Save the values */
1310 v_ptr->typ = (ROOM_IDX)typ;
1311 v_ptr->rat = (PROB)rat;
1312 v_ptr->hgt = (POSITION)hgt;
1313 v_ptr->wid = (POSITION)wid;
1325 * @brief 職業技能情報(s_info)のパース関数 /
1326 * Initialize the "s_info" array, by parsing an ascii "template" file
1328 * @param head ヘッダ構造体
1331 errr parse_s_info(char *buf, header *head)
1336 static skill_table *s_ptr = NULL;
1339 /* Process 'N' for "New/Number/Name" */
1345 /* Verify information */
1346 if (i <= error_idx) return (4);
1348 /* Verify information */
1349 if (i >= head->info_num) return (2);
1351 /* Save the index */
1354 /* Point at the "info" */
1358 /* There better be a current s_ptr */
1359 else if (!s_ptr) return (3);
1361 /* Process 'W' for "Weapon exp" */
1362 else if (buf[0] == 'W')
1364 int tval, sval, start, max;
1365 const s16b exp_conv_table[] =
1367 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1368 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1371 /* Scan for the values */
1372 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1373 &tval, &sval, &start, &max)) return (1);
1375 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1376 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1378 /* Save the values */
1379 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1380 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1383 /* Process 'S' for "Skill exp" */
1384 else if (buf[0] == 'S')
1386 int num, start, max;
1388 /* Scan for the values */
1389 if (3 != sscanf(buf+2, "%d:%d:%d",
1390 &num, &start, &max)) return (1);
1392 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1393 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1395 /* Save the values */
1396 s_ptr->s_start[num] = (SUB_EXP)start;
1397 s_ptr->s_max[num] = (SUB_EXP)max;
1410 * @brief 職業魔法情報(m_info)のパース関数 /
1411 * Initialize the "m_info" array, by parsing an ascii "template" file
1413 * @param head ヘッダ構造体
1416 errr parse_m_info(char *buf, header *head)
1423 static player_magic *m_ptr = NULL;
1426 static int realm, magic_idx = 0, readable = 0;
1429 /* Process 'N' for "New/Number/Name" */
1435 /* Verify information */
1436 if (i <= error_idx) return (4);
1438 /* Verify information */
1439 if (i >= head->info_num) return (2);
1441 /* Save the index */
1444 /* Point at the "info" */
1448 /* There better be a current m_ptr */
1449 else if (!m_ptr) return (3);
1451 /* Process 'I' for "Info" (one line only) */
1452 else if (buf[0] == 'I')
1455 int xtra, type, first, weight;
1457 /* Find the colon before the name */
1458 s = my_strchr(buf+2, ':');
1460 /* Verify that colon */
1463 /* Nuke the colon, advance to the name */
1468 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1469 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1470 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1471 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1472 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1477 /* Find the colon before the name */
1478 s = my_strchr(s, ':');
1480 /* Verify that colon */
1483 /* Nuke the colon, advance to the name */
1486 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1487 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1488 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1489 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1490 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1491 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1495 /* Scan for the values */
1496 if (4 != sscanf(s, "%x:%d:%d:%d",
1497 (uint *)&xtra, &type, &first, &weight)) return (1);
1499 m_ptr->spell_xtra = xtra;
1500 m_ptr->spell_type = type;
1501 m_ptr->spell_first = first;
1502 m_ptr->spell_weight = weight;
1506 /* Process 'R' for "Realm" (one line only) */
1507 else if (buf[0] == 'R')
1509 /* Scan for the values */
1510 if (2 != sscanf(buf+2, "%d:%d",
1511 &realm, &readable)) return (1);
1516 else if (buf[0] == 'T')
1518 int level, mana, fail, exp;
1520 if (!readable) return (1);
1521 /* Scan for the values */
1522 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1523 &level, &mana, &fail, &exp)) return (1);
1525 m_ptr->info[realm][magic_idx].slevel = (PLAYER_LEVEL)level;
1526 m_ptr->info[realm][magic_idx].smana = (MANA_POINT)mana;
1527 m_ptr->info[realm][magic_idx].sfail = (PERCENTAGE)fail;
1528 m_ptr->info[realm][magic_idx].sexp = (EXP)exp;
1542 * @brief テキストトークンを走査してフラグを一つ得る(汎用) /
1543 * Grab one flag from a textual string
1544 * @param flags ビットフラグを追加する先の参照ポインタ
1545 * @param names トークン定義配列
1546 * @param what 参照元の文字列ポインタ
1549 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1554 for (i = 0; i < 32; i++)
1556 if (streq(what, names[i]))
1558 *flags |= (1L << i);
1568 * @brief テキストトークンを走査してフラグを一つ得る(地形情報向け) /
1569 * Grab one flag in an feature_type from a textual string
1570 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1571 * @param what 参照元の文字列ポインタ
1574 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1579 for (i = 0; i < FF_FLAG_MAX; i++)
1581 if (streq(what, f_info_flags[i]))
1583 add_flag(f_ptr->flags, i);
1589 msg_format(_("未知の地形フラグ '%s'。", "Unknown feature flag '%s'."), what);
1592 return PARSE_ERROR_GENERIC;
1597 * @brief テキストトークンを走査してフラグ(ステート)を一つ得る(地形情報向け2) /
1598 * Grab an action in an feature_type from a textual string
1599 * @param f_ptr 地形情報を保管する先の構造体参照ポインタ
1600 * @param what 参照元の文字列ポインタ
1601 * @param count ステートの保存先ID
1604 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1609 for (i = 0; i < FF_FLAG_MAX; i++)
1611 if (streq(what, f_info_flags[i]))
1613 f_ptr->state[count].action = i;
1619 msg_format(_("未知の地形アクション '%s'。", "Unknown feature action '%s'."), what);
1622 return PARSE_ERROR_GENERIC;
1627 * @brief 地形情報(f_info)のパース関数 /
1628 * Initialize the "f_info" array, by parsing an ascii "template" file
1630 * @param head ヘッダ構造体
1633 errr parse_f_info(char *buf, header *head)
1640 static feature_type *f_ptr = NULL;
1643 /* Process 'N' for "New/Number/Name" */
1646 /* Find the colon before the name */
1647 s = my_strchr(buf+2, ':');
1651 /* Nuke the colon, advance to the name */
1658 /* Verify information */
1659 if (i <= error_idx) return (4);
1661 /* Verify information */
1662 if (i >= head->info_num) return (2);
1664 /* Save the index */
1667 /* Point at the "info" */
1670 /* Tag name is given */
1674 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1677 /* Default "mimic" */
1678 f_ptr->mimic = (FEAT_IDX)i;
1680 /* Default "destroyed state" -- if not specified */
1681 f_ptr->destroyed = (FEAT_IDX)i;
1683 /* Default "states" */
1684 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1687 /* There better be a current f_ptr */
1688 else if (!f_ptr) return (3);
1691 else if (buf[0] == 'J')
1693 /* Store the name */
1694 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1697 else if (buf[0] == 'E')
1699 /* Ignore english name */
1702 else if (buf[0] == 'J')
1704 /* Ignore Japanese name */
1707 else if (buf[0] == 'E')
1709 /* Acquire the Text */
1712 /* Store the name */
1713 if (!add_name(&f_ptr->name, head, s)) return (7);
1718 /* Process 'M' for "Mimic" (one line only) */
1719 else if (buf[0] == 'M')
1723 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1725 /* Record a fake tag index */
1726 f_ptr->mimic_tag = offset;
1730 /* Process 'G' for "Graphics" (one line only) */
1731 else if (buf[0] == 'G')
1735 char char_tmp[F_LIT_MAX];
1738 if (buf[1] != ':') return (1);
1739 if (!buf[2]) return (1);
1740 if (buf[3] != ':') return (1);
1741 if (!buf[4]) return (1);
1743 /* Extract the char */
1744 char_tmp[F_LIT_STANDARD] = buf[2];
1746 /* Extract the color */
1747 s_attr = color_char_to_attr(buf[4]);
1750 if (s_attr > 127) return (1);
1752 /* Save the standard values */
1753 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1754 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1756 /* Is this feature supports lighting? */
1759 /* G:c:a:LIT (default) */
1760 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1762 /* G:c:a:lc:la:dc:da */
1763 if (!streq(buf + 6, "LIT"))
1765 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1767 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1768 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1769 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1770 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1772 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1774 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1777 /* Use default lighting */
1780 /* No lighting support */
1781 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1784 /* Extract the color */
1785 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1786 if (f_ptr->d_attr[j] > 127) return 1;
1789 f_ptr->d_char[j] = char_tmp[j];
1795 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1797 f_ptr->d_attr[j] = s_attr;
1798 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1804 /* Hack -- Process 'F' for flags */
1805 else if (buf[0] == 'F')
1807 /* Parse every entry textually */
1808 for (s = buf + 2; *s; )
1810 /* Find the end of this entry */
1811 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1813 /* Nuke and skip any dividers */
1817 while (*t == ' ' || *t == '|') t++;
1820 /* XXX XXX XXX Hack -- Read feature subtype */
1821 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1823 /* Extract a "subtype" */
1826 /* Start at next entry */
1833 /* XXX XXX XXX Hack -- Read feature power */
1834 if (1 == sscanf(s, "POWER_%d", &i))
1836 /* Extract a "power" */
1837 f_ptr->power = (FEAT_POWER)i;
1839 /* Start at next entry */
1846 /* Parse this entry */
1847 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1849 /* Start the next entry */
1854 /* Process 'W' for "More Info" (one line only) */
1855 else if (buf[0] == 'W')
1859 /* Scan for the value */
1860 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1862 /* Save the value */
1863 f_ptr->priority = priority;
1866 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1867 else if (buf[0] == 'K')
1871 /* Find the next empty state slot (if any) */
1872 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1874 /* Oops, no more slots */
1875 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1877 /* Analyze the first field */
1878 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1880 /* Terminate the field (if necessary) */
1881 if (*t == ':') *t++ = '\0';
1883 /* Is this default entry? */
1884 if (streq(s, "DESTROYED"))
1886 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1888 /* Record a fake tag index */
1889 f_ptr->destroyed_tag = offset;
1894 f_ptr->state[i].action = 0;
1896 /* Parse this entry */
1897 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1899 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1901 /* Record a fake tag index */
1902 f_ptr->state[i].result_tag = offset;
1915 * @brief 地形タグからIDを得る /
1916 * Convert a fake tag to a real feat index
1920 s16b f_tag_to_index(cptr str)
1924 /* Search for real index corresponding to this fake tag */
1925 for (i = 0; i < f_head.info_num; i++)
1927 if (streq(f_tag + f_info[i].tag, str))
1929 /* Return the index */
1940 * @brief 地形タグからIDを得る /
1941 * Search for real index corresponding to this fake tag
1942 * @param feat タグ文字列のオフセット
1943 * @return 地形ID。該当がないなら-1
1945 static FEAT_IDX search_real_feat(STR_OFFSET feat)
1949 /* Don't convert non-fake tag */
1955 /* Search for real index corresponding to this fake tag */
1956 for (i = 0; i < f_head.info_num; i++)
1958 if (feat == f_info[i].tag)
1960 /* Record real index */
1966 msg_format(_("未定義のタグ '%s'。", "%s is undefined."), f_tag + feat);
1972 * @brief 地形情報の各種タグからIDへ変換して結果を収める /
1973 * Retouch fake tags of f_info
1974 * @param head ヘッダ構造体
1977 void retouch_f_info(header *head)
1981 /* Convert fake tags to real feat indices */
1982 for (i = 0; i < head->info_num; i++)
1984 feature_type *f_ptr = &f_info[i];
1987 k = search_real_feat(f_ptr->mimic_tag);
1988 f_ptr->mimic = k < 0 ? f_ptr->mimic : k;
1989 k = search_real_feat(f_ptr->destroyed_tag);
1990 f_ptr->destroyed = k < 0 ? f_ptr->destroyed : k;
1991 for (j = 0; j < MAX_FEAT_STATES; j++)
1993 k = search_real_feat(f_ptr->state[j].result_tag);
1994 f_ptr->state[j].result = k < 0 ? f_ptr->state[j].result : k;
2001 * @brief テキストトークンを走査してフラグを一つ得る(ベースアイテム用) /
2002 * Grab one flag in an object_kind from a textual string
2003 * @param k_ptr 保管先のベースアイテム構造体参照ポインタ
2004 * @param what 参照元の文字列ポインタ
2007 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
2012 for (i = 0; i < TR_FLAG_MAX; i++)
2014 if (streq(what, k_info_flags[i]))
2016 add_flag(k_ptr->flags, i);
2021 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
2025 msg_format(_("未知のアイテム・フラグ '%s'。", "Unknown object flag '%s'."), what);
2032 * @brief テキストトークンを走査してフラグを一つ得る(発動能力用) /
2033 * Grab one activation index flag
2034 * @param what 参照元の文字列ポインタ
2037 static byte grab_one_activation_flag(cptr what)
2043 if (activation_info[i].flag == NULL) break;
2045 if (streq(what, activation_info[i].flag))
2047 return activation_info[i].index;
2058 msg_format(_("未知の発動・フラグ '%s'。", "Unknown activation flag '%s'."), what);
2066 * @brief ベースアイテム(k_info)のパース関数 /
2067 * Initialize the "k_info" array, by parsing an ascii "template" file
2069 * @param head ヘッダ構造体
2072 errr parse_k_info(char *buf, header *head)
2079 static object_kind *k_ptr = NULL;
2082 /* Process 'N' for "New/Number/Name" */
2089 /* Find the colon before the name */
2090 s = my_strchr(buf+2, ':');
2092 /* Verify that colon */
2095 /* Nuke the colon, advance to the name */
2101 /* Verify information */
2102 if (i <= error_idx) return (4);
2104 /* Verify information */
2105 if (i >= head->info_num) return (2);
2107 /* Save the index */
2110 /* Point at the "info" */
2114 /* Paranoia -- require a name */
2115 if (!*s) return (1);
2117 /* Find the colon before the flavor */
2118 flavor = my_strchr(s, ':');
2120 /* Verify that colon */
2123 /* Nuke the colon, advance to the flavor */
2126 /* Store the flavor */
2127 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2130 /* Store the name */
2131 if (!add_name(&k_ptr->name, head, s)) return (7);
2135 /* There better be a current k_ptr */
2136 else if (!k_ptr) return (3);
2141 /* 'E' から始まる行は英語名としている */
2142 else if (buf[0] == 'E')
2147 else if (buf[0] == 'E')
2151 /* Acquire the name */
2154 /* Find the colon before the flavor */
2155 flavor = my_strchr(s, ':');
2157 /* Verify that colon */
2160 /* Nuke the colon, advance to the flavor */
2163 /* Store the flavor */
2164 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2167 /* Store the name */
2168 if (!add_name(&k_ptr->name, head, s)) return (7);
2172 /* Process 'D' for "Description" */
2173 else if (buf[0] == 'D')
2178 /* Acquire the text */
2183 /* Acquire the text */
2187 /* Store the text */
2188 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2191 /* Process 'G' for "Graphics" (one line only) */
2192 else if (buf[0] == 'G')
2198 if (buf[1] != ':') return (1);
2199 if (!buf[2]) return (1);
2200 if (buf[3] != ':') return (1);
2201 if (!buf[4]) return (1);
2203 /* Extract the char */
2206 /* Extract the attr */
2207 tmp = color_char_to_attr(buf[4]);
2210 if (tmp > 127) return (1);
2212 /* Save the values */
2213 k_ptr->d_attr = tmp;
2214 k_ptr->d_char = sym;
2217 /* Process 'I' for "Info" (one line only) */
2218 else if (buf[0] == 'I')
2220 int tval, sval, pval;
2222 /* Scan for the values */
2223 if (3 != sscanf(buf+2, "%d:%d:%d",
2224 &tval, &sval, &pval)) return (1);
2226 /* Save the values */
2227 k_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2228 k_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2229 k_ptr->pval = (PARAMETER_VALUE)pval;
2232 /* Process 'W' for "More Info" (one line only) */
2233 else if (buf[0] == 'W')
2235 int level, extra, wgt;
2238 /* Scan for the values */
2239 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2240 &level, &extra, &wgt, &cost)) return (1);
2242 /* Save the values */
2243 k_ptr->level = (DEPTH)level;
2244 k_ptr->extra = (BIT_FLAGS8)extra;
2245 k_ptr->weight = (WEIGHT)wgt;
2246 k_ptr->cost = (PRICE)cost;
2249 /* Process 'A' for "Allocation" (one line only) */
2250 else if (buf[0] == 'A')
2253 /* XXX XXX XXX Simply read each number following a colon */
2254 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2256 /* Default chance */
2257 k_ptr->chance[i] = 1;
2259 /* Store the attack damage index */
2260 k_ptr->locale[i] = atoi(s+1);
2262 /* Find the slash */
2263 t = my_strchr(s+1, '/');
2265 /* Find the next colon */
2266 s = my_strchr(s+1, ':');
2268 /* If the slash is "nearby", use it */
2269 if (t && (!s || t < s))
2271 int chance = atoi(t+1);
2272 if (chance > 0) k_ptr->chance[i] = (PROB)chance;
2277 /* Hack -- Process 'P' for "power" and such */
2278 else if (buf[0] == 'P')
2280 int ac, hd1, hd2, th, td, ta;
2282 /* Scan for the values */
2283 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2284 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2286 k_ptr->ac = (ARMOUR_CLASS)ac;
2287 k_ptr->dd = (DICE_NUMBER)hd1;
2288 k_ptr->ds = (DICE_SID)hd2;
2289 k_ptr->to_h = (HIT_PROB)th;
2290 k_ptr->to_d = (HIT_POINT)td;
2291 k_ptr->to_a = (ARMOUR_CLASS)ta;
2294 /* Hack -- Process 'U' for activation index */
2295 else if (buf[0] == 'U')
2298 n = grab_one_activation_flag(buf + 2);
2309 /* Hack -- Process 'F' for flags */
2310 else if (buf[0] == 'F')
2312 /* Parse every entry textually */
2313 for (s = buf + 2; *s; )
2315 /* Find the end of this entry */
2316 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2318 /* Nuke and skip any dividers */
2322 while (*t == ' ' || *t == '|') t++;
2325 /* Parse this entry */
2326 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2328 /* Start the next entry */
2343 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2344 * Grab one activation index flag
2345 * @param a_ptr 保管先のアーティファクト構造体参照ポインタ
2346 * @param what 参照元の文字列ポインタ
2347 * @return エラーがあった場合1、エラーがない場合0を返す
2349 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2354 for (i = 0; i < TR_FLAG_MAX; i++)
2356 if (streq(what, k_info_flags[i]))
2358 add_flag(a_ptr->flags, i);
2363 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2367 msg_format(_("未知の伝説のアイテム・フラグ '%s'。", "Unknown artifact flag '%s'."), what);
2375 * @brief 固定アーティファクト情報(a_info)のパース関数 /
2376 * Initialize the "a_info" array, by parsing an ascii "template" file
2378 * @param head ヘッダ構造体
2381 errr parse_a_info(char *buf, header *head)
2388 static artifact_type *a_ptr = NULL;
2391 /* Process 'N' for "New/Number/Name" */
2394 /* Find the colon before the name */
2395 s = my_strchr(buf+2, ':');
2397 /* Verify that colon */
2400 /* Nuke the colon, advance to the name */
2403 /* Paranoia -- require a name */
2404 if (!*s) return (1);
2409 /* Verify information */
2410 if (i < error_idx) return (4);
2412 /* Verify information */
2413 if (i >= head->info_num) return (2);
2415 /* Save the index */
2418 /* Point at the "info" */
2421 /* Ignore everything */
2422 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2423 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2424 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2425 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2427 /* Store the name */
2428 if (!add_name(&a_ptr->name, head, s)) return (7);
2432 /* There better be a current a_ptr */
2433 else if (!a_ptr) return (3);
2438 /* 'E' から始まる行は英語名としている */
2439 else if (buf[0] == 'E')
2444 else if (buf[0] == 'E')
2446 /* Acquire the Text */
2449 /* Store the name */
2450 if (!add_name(&a_ptr->name, head, s)) return (7);
2454 /* Process 'D' for "Description" */
2455 else if (buf[0] == 'D')
2460 /* Acquire the text */
2465 /* Acquire the text */
2469 /* Store the text */
2470 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2474 /* Process 'I' for "Info" (one line only) */
2475 else if (buf[0] == 'I')
2477 int tval, sval, pval;
2479 /* Scan for the values */
2480 if (3 != sscanf(buf+2, "%d:%d:%d",
2481 &tval, &sval, &pval)) return (1);
2483 /* Save the values */
2484 a_ptr->tval = (OBJECT_TYPE_VALUE)tval;
2485 a_ptr->sval = (OBJECT_SUBTYPE_VALUE)sval;
2486 a_ptr->pval = (PARAMETER_VALUE)pval;
2489 /* Process 'W' for "More Info" (one line only) */
2490 else if (buf[0] == 'W')
2492 int level, rarity, wgt;
2495 /* Scan for the values */
2496 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2497 &level, &rarity, &wgt, &cost)) return (1);
2499 /* Save the values */
2500 a_ptr->level = (DEPTH)level;
2501 a_ptr->rarity = (RARITY)rarity;
2502 a_ptr->weight = (WEIGHT)wgt;
2503 a_ptr->cost = (PRICE)cost;
2506 /* Hack -- Process 'P' for "power" and such */
2507 else if (buf[0] == 'P')
2509 int ac, hd1, hd2, th, td, ta;
2511 /* Scan for the values */
2512 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2513 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2515 a_ptr->ac = (ARMOUR_CLASS)ac;
2516 a_ptr->dd = (DICE_NUMBER)hd1;
2517 a_ptr->ds = (DICE_SID)hd2;
2518 a_ptr->to_h = (HIT_PROB)th;
2519 a_ptr->to_d = (HIT_POINT)td;
2520 a_ptr->to_a = (ARMOUR_CLASS)ta;
2523 /* Hack -- Process 'U' for activation index */
2524 else if (buf[0] == 'U')
2527 n = grab_one_activation_flag(buf + 2);
2538 /* Hack -- Process 'F' for flags */
2539 else if (buf[0] == 'F')
2541 /* Parse every entry textually */
2542 for (s = buf + 2; *s; )
2544 /* Find the end of this entry */
2545 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2547 /* Nuke and skip any dividers */
2551 while ((*t == ' ') || (*t == '|')) t++;
2554 /* Parse this entry */
2555 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2557 /* Start the next entry */
2573 * @brief テキストトークンを走査してフラグを一つ得る(アーティファクト用) /
2574 * Grab one flag in a ego-item_type from a textual string
2575 * @param e_ptr 保管先のエゴ構造体参照ポインタ
2576 * @param what 参照元の文字列ポインタ
2577 * @return エラーがあった場合1、エラーがない場合0を返す
2579 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2584 for (i = 0; i < TR_FLAG_MAX; i++)
2586 if (streq(what, k_info_flags[i]))
2588 add_flag(e_ptr->flags, i);
2593 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2597 msg_format(_("未知の名のあるアイテム・フラグ '%s'。", "Unknown ego-item flag '%s'."), what);
2605 * @brief アイテムエゴ情報(e_info)のパース関数 /
2606 * Initialize the "e_info" array, by parsing an ascii "template" file
2608 * @param head ヘッダ構造体
2611 errr parse_e_info(char *buf, header *head)
2618 static ego_item_type *e_ptr = NULL;
2621 /* Just before the first record */
2624 /* Just before the first line */
2628 /* Process 'N' for "New/Number/Name" */
2631 /* Find the colon before the name */
2632 s = my_strchr(buf+2, ':');
2634 /* Verify that colon */
2637 /* Nuke the colon, advance to the name */
2640 /* Paranoia -- require a name */
2641 if (!*s) return (1);
2646 /* Verify information */
2647 if (i < error_idx) return (4);
2649 /* Verify information */
2650 if (i >= head->info_num) return (2);
2652 /* Save the index */
2655 /* Point at the "info" */
2658 /* Store the name */
2659 if (!add_name(&e_ptr->name, head, s)) return (7);
2663 /* There better be a current e_ptr */
2664 else if (!e_ptr) return (3);
2669 /* 'E' から始まる行は英語名 */
2670 else if (buf[0] == 'E')
2675 else if (buf[0] == 'E')
2677 /* Acquire the Text */
2680 /* Store the name */
2681 if (!add_name(&e_ptr->name, head, s)) return (7);
2686 /* Process 'D' for "Description" */
2687 else if (buf[0] == 'D')
2689 /* Acquire the text */
2692 /* Store the text */
2693 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2698 /* Process 'X' for "Xtra" (one line only) */
2699 else if (buf[0] == 'X')
2703 /* Scan for the values */
2704 if (2 != sscanf(buf+2, "%d:%d",
2705 &slot, &rating)) return (1);
2707 /* Save the values */
2708 e_ptr->slot = (INVENTORY_IDX)slot;
2709 e_ptr->rating = (PRICE)rating;
2712 /* Process 'W' for "More Info" (one line only) */
2713 else if (buf[0] == 'W')
2715 int level, rarity, pad2;
2718 /* Scan for the values */
2719 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2720 &level, &rarity, &pad2, &cost)) return (1);
2722 /* Save the values */
2723 e_ptr->level = level;
2724 e_ptr->rarity = (RARITY)rarity;
2725 /* e_ptr->weight = wgt; */
2729 /* Hack -- Process 'C' for "creation" */
2730 else if (buf[0] == 'C')
2732 int th, td, ta, pval;
2734 /* Scan for the values */
2735 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2736 &th, &td, &ta, &pval)) return (1);
2738 e_ptr->max_to_h = (HIT_PROB)th;
2739 e_ptr->max_to_d = (HIT_POINT)td;
2740 e_ptr->max_to_a = (ARMOUR_CLASS)ta;
2741 e_ptr->max_pval = (PARAMETER_VALUE)pval;
2744 /* Hack -- Process 'U' for activation index */
2745 else if (buf[0] == 'U')
2748 n = grab_one_activation_flag(buf + 2);
2759 /* Hack -- Process 'F' for flags */
2760 else if (buf[0] == 'F')
2762 /* Parse every entry textually */
2763 for (s = buf + 2; *s; )
2765 /* Find the end of this entry */
2766 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2768 /* Nuke and skip any dividers */
2772 while ((*t == ' ') || (*t == '|')) t++;
2775 /* Parse this entry */
2776 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2778 /* Start the next entry */
2792 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用1) /
2793 * Grab one (basic) flag in a monster_race from a textual string
2794 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2795 * @param what 参照元の文字列ポインタ
2798 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2800 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2803 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2806 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2809 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2812 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2815 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2818 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2822 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2830 * @brief テキストトークンを走査してフラグを一つ得る(モンスター用2) /
2831 * Grab one (spell) flag in a monster_race from a textual string
2832 * @param r_ptr 保管先のモンスター種族構造体参照ポインタ
2833 * @param what 参照元の文字列ポインタ
2836 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2838 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2841 if (grab_one_flag(&r_ptr->a_ability_flags1, r_a_ability_flags1, what) == 0)
2844 if (grab_one_flag(&r_ptr->a_ability_flags2, r_a_ability_flags2, what) == 0)
2848 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
2856 * @brief モンスター種族情報(r_info)のパース関数 /
2857 * Initialize the "r_info" array, by parsing an ascii "template" file
2859 * @param head ヘッダ構造体
2862 errr parse_r_info(char *buf, header *head)
2869 static monster_race *r_ptr = NULL;
2872 /* Process 'N' for "New/Number/Name" */
2875 /* Find the colon before the name */
2876 s = my_strchr(buf+2, ':');
2878 /* Verify that colon */
2881 /* Nuke the colon, advance to the name */
2884 /* Paranoia -- require a name */
2885 if (!*s) return (1);
2890 /* Verify information */
2891 if (i < error_idx) return (4);
2893 /* Verify information */
2894 if (i >= head->info_num) return (2);
2896 /* Save the index */
2899 /* Point at the "info" */
2902 /* Store the name */
2903 if (!add_name(&r_ptr->name, head, s)) return (7);
2907 /* There better be a current r_ptr */
2908 else if (!r_ptr) return (3);
2913 /* 'E' から始まる行は英語名 */
2914 else if (buf[0] == 'E')
2916 /* Acquire the Text */
2919 /* Store the name */
2920 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2923 else if (buf[0] == 'E')
2925 /* Acquire the Text */
2928 /* Store the name */
2929 if (!add_name(&r_ptr->name, head, s)) return (7);
2932 /* Process 'D' for "Description" */
2933 else if (buf[0] == 'D')
2938 /* Acquire the text */
2943 /* Acquire the text */
2947 /* Store the text */
2948 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2951 /* Process 'G' for "Graphics" (one line only) */
2952 else if (buf[0] == 'G')
2958 if (buf[1] != ':') return (1);
2959 if (!buf[2]) return (1);
2960 if (buf[3] != ':') return (1);
2961 if (!buf[4]) return (1);
2963 /* Extract the char */
2966 /* Extract the attr */
2967 tmp = color_char_to_attr(buf[4]);
2970 if (tmp > 127) return (1);
2972 /* Save the values */
2973 r_ptr->d_char = sym;
2974 r_ptr->d_attr = tmp;
2977 /* Process 'I' for "Info" (one line only) */
2978 else if (buf[0] == 'I')
2980 int spd, hp1, hp2, aaf, ac, slp;
2982 /* Scan for the other values */
2983 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2984 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2986 /* Save the values */
2987 r_ptr->speed = (SPEED)spd;
2988 r_ptr->hdice = (DICE_NUMBER)MAX(hp1, 1);
2989 r_ptr->hside = (DICE_SID)MAX(hp2, 1);
2990 r_ptr->aaf = (POSITION)aaf;
2991 r_ptr->ac = (ARMOUR_CLASS)ac;
2992 r_ptr->sleep = (SLEEP_DEGREE)slp;
2995 /* Process 'W' for "More Info" (one line only) */
2996 else if (buf[0] == 'W')
3003 /* Scan for the values */
3004 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
3005 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
3007 /* Save the values */
3008 r_ptr->level = (DEPTH)lev;
3009 r_ptr->rarity = (RARITY)rar;
3010 r_ptr->extra = (BIT_FLAGS16)pad;
3011 r_ptr->mexp = (EXP)exp;
3012 r_ptr->next_exp = (EXP)nextexp;
3013 r_ptr->next_r_idx = (IDX)nextmon;
3016 /* Process 'R' for "Reinforcement" (up to six lines) */
3017 else if (buf[0] == 'R')
3020 /* Find the next empty blow slot (if any) */
3021 for (i = 0; i < 6; i++) if (r_ptr->reinforce_id[i] == 0) break;
3023 /* Oops, no more slots */
3024 if (i == 6) return (1);
3026 /* Scan for the values */
3027 if (3 != sscanf(buf+2, "%d:%dd%d", &id, &dd, &ds)) return (1);
3028 r_ptr->reinforce_id[i] = (MONRACE_IDX)id;
3029 r_ptr->reinforce_dd[i] = (DICE_NUMBER)dd;
3030 r_ptr->reinforce_ds[i] = (DICE_SID)ds;
3033 /* Process 'B' for "Blows" (up to four lines) */
3034 else if (buf[0] == 'B')
3038 /* Find the next empty blow slot (if any) */
3039 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
3041 /* Oops, no more slots */
3042 if (i == 4) return (1);
3044 /* Analyze the first field */
3045 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
3047 /* Terminate the field (if necessary) */
3048 if (*t == ':') *t++ = '\0';
3050 /* Analyze the method */
3051 for (n1 = 0; r_info_blow_method[n1]; n1++)
3053 if (streq(s, r_info_blow_method[n1])) break;
3056 /* Invalid method */
3057 if (!r_info_blow_method[n1]) return (1);
3059 /* Analyze the second field */
3060 for (s = t; *t && (*t != ':'); t++) /* loop */;
3062 /* Terminate the field (if necessary) */
3063 if (*t == ':') *t++ = '\0';
3065 /* Analyze effect */
3066 for (n2 = 0; r_info_blow_effect[n2]; n2++)
3068 if (streq(s, r_info_blow_effect[n2])) break;
3071 /* Invalid effect */
3072 if (!r_info_blow_effect[n2]) return (1);
3074 /* Analyze the third field */
3075 for (s = t; *t && (*t != 'd'); t++) /* loop */;
3077 /* Terminate the field (if necessary) */
3078 if (*t == 'd') *t++ = '\0';
3080 /* Save the method */
3081 r_ptr->blow[i].method = (BLOW_METHOD)n1;
3083 /* Save the effect */
3084 r_ptr->blow[i].effect = (BLOW_EFFECT)n2;
3086 /* Extract the damage dice and sides */
3087 r_ptr->blow[i].d_dice = atoi(s);
3088 r_ptr->blow[i].d_side = atoi(t);
3091 /* Process 'F' for "Basic Flags" (multiple lines) */
3092 else if (buf[0] == 'F')
3094 /* Parse every entry */
3095 for (s = buf + 2; *s; )
3097 /* Find the end of this entry */
3098 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3100 /* Nuke and skip any dividers */
3104 while (*t == ' ' || *t == '|') t++;
3107 /* Parse this entry */
3108 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3110 /* Start the next entry */
3115 /* Process 'S' for "Spell Flags" (multiple lines) */
3116 else if (buf[0] == 'S')
3118 /* Parse every entry */
3119 for (s = buf + 2; *s; )
3121 /* Find the end of this entry */
3122 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3124 /* Nuke and skip any dividers */
3128 while ((*t == ' ') || (*t == '|')) t++;
3131 /* XXX XXX XXX Hack -- Read spell frequency */
3132 if (1 == sscanf(s, "1_IN_%d", &i))
3134 /* Extract a "frequency" */
3135 r_ptr->freq_spell = 100 / i;
3137 /* Start at next entry */
3144 /* Parse this entry */
3145 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3147 /* Start the next entry */
3152 /* Process 'A' for "Artifact Flags" (multiple lines) */
3153 else if (buf[0] == 'A')
3155 int id, per, rarity;
3157 /* Find the next empty blow slot (if any) */
3158 for (i = 0; i < 4; i++) if (!r_ptr->artifact_id[i]) break;
3160 /* Oops, no more slots */
3161 if (i == 4) return (1);
3163 if (3 != sscanf(buf+2, "%d:%d:%d", &id, &rarity, &per)) return (1);
3164 r_ptr->artifact_id[i] = (ARTIFACT_IDX)id;
3165 r_ptr->artifact_rarity[i] = (RARITY)rarity;
3166 r_ptr->artifact_percent[i] = (PERCENTAGE)per;
3169 /* Process 'V' for "Arena power value ratio" */
3170 else if (buf[0] == 'V')
3173 if (3 != sscanf(buf+2, "%d", &val)) return (1);
3174 r_ptr->arena_ratio = (PERCENTAGE)val;
3187 * @brief テキストトークンを走査してフラグを一つ得る(ダンジョン用) /
3188 * Grab one flag for a dungeon type from a textual string
3189 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3190 * @param what 参照元の文字列ポインタ
3193 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3195 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3199 msg_format(_("未知のダンジョン・フラグ '%s'。", "Unknown dungeon type flag '%s'."), what);
3206 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用1) /
3207 * Grab one (basic) flag in a monster_race from a textual string
3208 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3209 * @param what 参照元の文字列ポインタ
3212 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3214 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3217 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3220 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3223 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3226 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3229 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3232 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3236 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3243 * @brief テキストトークンを走査してフラグを一つ得る(モンスターのダンジョン出現条件用2) /
3244 * Grab one (spell) flag in a monster_race from a textual string
3245 * @param d_ptr 保管先のダンジョン構造体参照ポインタ
3246 * @param what 参照元の文字列ポインタ
3249 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3251 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3254 if (grab_one_flag(&d_ptr->m_a_ability_flags1, r_a_ability_flags1, what) == 0)
3257 if (grab_one_flag(&d_ptr->m_a_ability_flags2, r_a_ability_flags2, what) == 0)
3261 msg_format(_("未知のモンスター・フラグ '%s'。", "Unknown monster flag '%s'."), what);
3268 * @brief ダンジョン情報(d_info)のパース関数 /
3269 * Initialize the "d_info" array, by parsing an ascii "template" file
3271 * @param head ヘッダ構造体
3274 errr parse_d_info(char *buf, header *head)
3281 static dungeon_info_type *d_ptr = NULL;
3284 /* Process 'N' for "New/Number/Name" */
3287 /* Find the colon before the name */
3288 s = my_strchr(buf+2, ':');
3290 /* Verify that colon */
3293 /* Nuke the colon, advance to the name */
3296 /* Paranoia -- require a name */
3297 if (!*s) return (1);
3302 /* Verify information */
3303 if (i < error_idx) return (4);
3305 /* Verify information */
3306 if (i >= head->info_num) return (2);
3308 /* Save the index */
3311 /* Point at the "info" */
3314 /* Store the name */
3315 if (!add_name(&d_ptr->name, head, s)) return (7);
3320 else if (buf[0] == 'E') return (0);
3322 else if (buf[0] == 'E')
3324 /* Acquire the Text */
3327 /* Store the name */
3328 if (!add_name(&d_ptr->name, head, s)) return (7);
3332 /* Process 'D' for "Description */
3333 else if (buf[0] == 'D')
3338 /* Acquire the text */
3343 /* Acquire the text */
3347 /* Store the text */
3348 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3351 /* Process 'W' for "More Info" (one line only) */
3352 else if (buf[0] == 'W')
3354 int min_lev, max_lev;
3356 int min_alloc, max_chance;
3357 int obj_good, obj_great;
3360 /* Scan for the values */
3361 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3362 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3364 /* Save the values */
3365 d_ptr->mindepth = (DEPTH)min_lev;
3366 d_ptr->maxdepth = (DEPTH)max_lev;
3367 d_ptr->min_plev = (PLAYER_LEVEL)min_plev;
3368 d_ptr->mode = (BIT_FLAGS8)mode;
3369 d_ptr->min_m_alloc_level = min_alloc;
3370 d_ptr->max_m_alloc_chance = max_chance;
3371 d_ptr->obj_good = obj_good;
3372 d_ptr->obj_great = obj_great;
3373 d_ptr->pit = (BIT_FLAGS16)pit;
3374 d_ptr->nest = (BIT_FLAGS16)nest;
3377 /* Process 'P' for "Place Info" */
3378 else if (buf[0] == 'P')
3382 /* Scan for the values */
3383 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3385 /* Save the values */
3390 /* Process 'L' for "fLoor type" (one line only) */
3391 else if (buf[0] == 'L')
3395 /* Scan for the values */
3396 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3398 /* Save the values */
3399 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3401 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3402 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3404 d_ptr->floor[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3406 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3409 /* Process 'A' for "wAll type" (one line only) */
3410 else if (buf[0] == 'A')
3414 /* Scan for the values */
3415 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3417 /* Save the values */
3418 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3420 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3421 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3423 d_ptr->fill[i].percent = (PERCENTAGE)atoi(zz[i * 2 + 1]);
3426 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3427 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3429 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3430 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3432 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3433 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3435 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3436 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3439 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3440 else if (buf[0] == 'F')
3442 int artif = 0, monst = 0;
3444 /* Parse every entry */
3445 for (s = buf + 2; *s; )
3447 /* Find the end of this entry */
3448 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3450 /* Nuke and skip any dividers */
3454 while (*t == ' ' || *t == '|') t++;
3457 /* XXX XXX XXX Hack -- Read Final Artifact */
3458 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3460 /* Extract a "Final Artifact" */
3461 d_ptr->final_artifact = (ARTIFACT_IDX)artif;
3463 /* Start at next entry */
3470 /* XXX XXX XXX Hack -- Read Final Object */
3471 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3473 /* Extract a "Final Artifact" */
3474 d_ptr->final_object = (KIND_OBJECT_IDX)artif;
3476 /* Start at next entry */
3483 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3484 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3486 /* Extract a "Artifact Guardian" */
3487 d_ptr->final_guardian = (MONRACE_IDX)monst;
3489 /* Start at next entry */
3496 /* XXX XXX XXX Hack -- Read Special Percentage */
3497 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3499 /* Extract a "Special %" */
3500 d_ptr->special_div = monst;
3502 /* Start at next entry */
3509 /* Parse this entry */
3510 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3512 /* Start the next entry */
3517 /* Process 'M' for "Basic Flags" (multiple lines) */
3518 else if (buf[0] == 'M')
3520 /* Parse every entry */
3521 for (s = buf + 2; *s; )
3523 /* Find the end of this entry */
3524 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3526 /* Nuke and skip any dividers */
3530 while (*t == ' ' || *t == '|') t++;
3533 /* Hack -- Read monster symbols */
3534 if (!strncmp(s, "R_CHAR_", 7))
3536 /* Skip "R_CHAR_" */
3540 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3542 /* Start at next entry */
3549 /* Parse this entry */
3550 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3552 /* Start the next entry */
3557 /* Process 'S' for "Spell Flags" (multiple lines) */
3558 else if (buf[0] == 'S')
3560 /* Parse every entry */
3561 for (s = buf + 2; *s; )
3563 /* Find the end of this entry */
3564 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3566 /* Nuke and skip any dividers */
3570 while ((*t == ' ') || (*t == '|')) t++;
3573 /* XXX XXX XXX Hack -- Read spell frequency */
3574 if (1 == sscanf(s, "1_IN_%d", &i))
3576 /* Start at next entry */
3583 /* Parse this entry */
3584 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3586 /* Start the next entry */
3599 #else /* ALLOW_TEMPLATES */
3605 #endif /* ALLOW_TEMPLATES */
3608 /* Random dungeon grid effects */
3609 #define RANDOM_NONE 0x00000000
3610 #define RANDOM_FEATURE 0x00000001
3611 #define RANDOM_MONSTER 0x00000002
3612 #define RANDOM_OBJECT 0x00000004
3613 #define RANDOM_EGO 0x00000008
3614 #define RANDOM_ARTIFACT 0x00000010
3615 #define RANDOM_TRAP 0x00000020
3618 typedef struct dungeon_grid dungeon_grid;
3622 IDX feature; /* Terrain feature */
3623 IDX monster; /* Monster */
3624 IDX object; /* Object */
3625 IDX ego; /* Ego-Item */
3626 IDX artifact; /* Artifact */
3627 IDX trap; /* Trap */
3628 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3629 int special; /* Reserved for special terrain info */
3630 int random; /* Number of the random effect */
3634 static dungeon_grid letter[255];
3638 * @brief 地形情報の「F:」情報をパースする
3639 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3643 static errr parse_line_feature(char *buf)
3649 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3651 /* Tokenize the line */
3652 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3654 /* Letter to assign */
3655 int index = zz[0][0];
3657 /* Reset the info for the letter */
3658 letter[index].feature = feat_none;
3659 letter[index].monster = 0;
3660 letter[index].object = 0;
3661 letter[index].ego = 0;
3662 letter[index].artifact = 0;
3663 letter[index].trap = feat_none;
3664 letter[index].cave_info = 0;
3665 letter[index].special = 0;
3666 letter[index].random = RANDOM_NONE;
3672 letter[index].special = atoi(zz[8]);
3676 if ((zz[7][0] == '*') && !zz[7][1])
3678 letter[index].random |= RANDOM_TRAP;
3682 letter[index].trap = f_tag_to_index(zz[7]);
3683 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3688 if (zz[6][0] == '*')
3690 letter[index].random |= RANDOM_ARTIFACT;
3691 if (zz[6][1]) letter[index].artifact = (IDX)atoi(zz[6] + 1);
3693 else if (zz[6][0] == '!')
3695 if (p_ptr->inside_quest)
3697 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3702 letter[index].artifact = (IDX)atoi(zz[6]);
3707 if (zz[5][0] == '*')
3709 letter[index].random |= RANDOM_EGO;
3710 if (zz[5][1]) letter[index].ego = (IDX)atoi(zz[5] + 1);
3714 letter[index].ego = (IDX)atoi(zz[5]);
3719 if (zz[4][0] == '*')
3721 letter[index].random |= RANDOM_OBJECT;
3722 if (zz[4][1]) letter[index].object = (IDX)atoi(zz[4] + 1);
3724 else if (zz[4][0] == '!')
3726 if (p_ptr->inside_quest)
3728 int a_idx = quest[p_ptr->inside_quest].k_idx;
3731 artifact_type *a_ptr = &a_info[a_idx];
3732 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3734 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3741 letter[index].object = (IDX)atoi(zz[4]);
3746 if (zz[3][0] == '*')
3748 letter[index].random |= RANDOM_MONSTER;
3749 if (zz[3][1]) letter[index].monster = (IDX)atoi(zz[3] + 1);
3751 else if (zz[3][0] == 'c')
3753 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3754 letter[index].monster = - atoi(zz[3] + 1);
3758 letter[index].monster = (IDX)atoi(zz[3]);
3763 letter[index].cave_info = atoi(zz[2]);
3767 if ((zz[1][0] == '*') && !zz[1][1])
3769 letter[index].random |= RANDOM_FEATURE;
3773 letter[index].feature = f_tag_to_index(zz[1]);
3774 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3787 * @brief 地形情報の「B:」情報をパースする
3788 * Process "B:<Index>:<Command>:..." -- Building definition
3792 static errr parse_line_building(char *buf)
3808 /* Get the building number */
3811 /* Find the colon after the building number */
3812 s = my_strchr(s, ':');
3814 /* Verify that colon */
3817 /* Nuke the colon, advance to the sub-index */
3820 /* Paranoia -- require a sub-index */
3821 if (!*s) return (1);
3823 /* Building definition sub-index */
3826 /* Building name, owner, race */
3829 if (tokenize(s + 2, 3, zz, 0) == 3)
3831 /* Name of the building */
3832 strcpy(building[index].name, zz[0]);
3834 /* Name of the owner */
3835 strcpy(building[index].owner_name, zz[1]);
3837 /* Race of the owner */
3838 strcpy(building[index].owner_race, zz[2]);
3843 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3846 /* Building Action */
3849 if (tokenize(s + 2, 8, zz, 0) >= 7)
3851 /* Index of the action */
3852 int action_index = atoi(zz[0]);
3854 /* Name of the action */
3855 strcpy(building[index].act_names[action_index], zz[1]);
3857 /* Cost of the action for members */
3858 building[index].member_costs[action_index] = (PRICE)atoi(zz[2]);
3860 /* Cost of the action for non-members */
3861 building[index].other_costs[action_index] = (PRICE)atoi(zz[3]);
3863 /* Letter assigned to the action */
3864 building[index].letters[action_index] = zz[4][0];
3867 building[index].actions[action_index] = atoi(zz[5]);
3869 /* Action restriction */
3870 building[index].action_restr[action_index] = atoi(zz[6]);
3875 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3878 /* Building Classes */
3881 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3883 for (i = 0; i < MAX_CLASS; i++)
3885 building[index].member_class[i] = (CLASS_IDX)atoi(zz[i]);
3891 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3894 /* Building Races */
3897 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3899 for (i = 0; i < MAX_RACES; i++)
3901 building[index].member_race[i] = (RACE_IDX)atoi(zz[i]);
3907 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3910 /* Building Realms */
3913 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3915 for (i = 0; i < MAX_MAGIC; i++)
3917 building[index].member_realm[i+1] = (REALM_IDX)atoi(zz[i]);
3923 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3928 /* Ignore scripts */
3934 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3943 * @brief フロアの所定のマスにオブジェクトを配置する
3944 * Place the object j_ptr to a grid
3945 * @param j_ptr オブジェクト構造体の参照ポインタ
3950 static void drop_here(object_type *j_ptr, int y, int x)
3952 cave_type *c_ptr = &cave[y][x];
3955 /* Get new object */
3956 s16b o_idx = o_pop();
3958 /* Access new object */
3959 o_ptr = &o_list[o_idx];
3961 /* Structure copy */
3962 object_copy(o_ptr, j_ptr);
3970 o_ptr->held_m_idx = 0;
3973 o_ptr->next_o_idx = c_ptr->o_idx;
3975 /* Place the object */
3976 c_ptr->o_idx = o_idx;
3981 * @brief クエスト用固定ダンジョンをフロアに生成する
3982 * Parse a sub-file of the "extra info"
3992 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3999 /* Skip "empty" lines */
4000 if (!buf[0]) return (0);
4002 /* Skip "blank" lines */
4003 if (iswspace(buf[0])) return (0);
4006 if (buf[0] == '#') return (0);
4008 /* Require "?:*" format */
4009 if (buf[1] != ':') return (1);
4012 /* Process "%:<fname>" */
4015 /* Attempt to Process the given file */
4016 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
4019 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
4022 return parse_line_feature(buf);
4025 /* Process "D:<dungeon>" -- info for the cave grids */
4026 else if (buf[0] == 'D')
4028 object_type object_type_body;
4030 /* Acquire the text */
4033 /* Length of the text */
4034 int len = strlen(s);
4036 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
4038 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
4040 /* Access the grid */
4041 cave_type *c_ptr = &cave[*y][*x];
4045 IDX object_index = letter[idx].object;
4046 IDX monster_index = letter[idx].monster;
4047 int random = letter[idx].random;
4048 IDX artifact_index = letter[idx].artifact;
4050 /* Lay down a floor */
4051 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
4053 /* Only the features */
4054 if (init_flags & INIT_ONLY_FEATURES) continue;
4057 c_ptr->info = letter[idx].cave_info;
4059 /* Create a monster */
4060 if (random & RANDOM_MONSTER)
4062 monster_level = base_level + monster_index;
4064 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
4066 monster_level = base_level;
4068 else if (monster_index)
4070 int old_cur_num, old_max_num;
4073 if (monster_index < 0)
4075 monster_index = -monster_index;
4078 old_cur_num = r_info[monster_index].cur_num;
4079 old_max_num = r_info[monster_index].max_num;
4081 /* Make alive again */
4082 if (r_info[monster_index].flags1 & RF1_UNIQUE)
4084 r_info[monster_index].cur_num = 0;
4085 r_info[monster_index].max_num = 1;
4088 /* Make alive again */
4089 /* Hack -- Non-unique Nazguls are semi-unique */
4090 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
4092 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
4094 r_info[monster_index].max_num++;
4099 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
4103 m_list[hack_m_idx_ii].smart |= SM_CLONED;
4105 /* Make alive again for real unique monster */
4106 r_info[monster_index].cur_num = old_cur_num;
4107 r_info[monster_index].max_num = old_max_num;
4111 /* Object (and possible trap) */
4112 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
4114 object_level = base_level + object_index;
4117 * Random trap and random treasure defined
4118 * 25% chance for trap and 75% chance for object
4120 if (randint0(100) < 75)
4122 place_object(*y, *x, 0L);
4129 object_level = base_level;
4131 else if (random & RANDOM_OBJECT)
4133 object_level = base_level + object_index;
4135 /* Create an out of deep object */
4136 if (randint0(100) < 75)
4137 place_object(*y, *x, 0L);
4138 else if (randint0(100) < 80)
4139 place_object(*y, *x, AM_GOOD);
4141 place_object(*y, *x, AM_GOOD | AM_GREAT);
4143 object_level = base_level;
4146 else if (random & RANDOM_TRAP)
4150 /* Hidden trap (or door) */
4151 else if (letter[idx].trap)
4153 c_ptr->mimic = c_ptr->feat;
4154 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4156 else if (object_index)
4158 /* Get local object */
4159 object_type *o_ptr = &object_type_body;
4161 /* Create the item */
4162 object_prep(o_ptr, object_index);
4164 if (o_ptr->tval == TV_GOLD)
4166 coin_type = object_index - OBJ_GOLD_LIST;
4171 /* Apply magic (no messages, no artifacts) */
4172 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4174 drop_here(o_ptr, *y, *x);
4180 if (a_info[artifact_index].cur_num)
4182 IDX k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4184 object_type *q_ptr = &forge;
4186 object_prep(q_ptr, k_idx);
4188 /* Drop it in the dungeon */
4189 drop_here(q_ptr, *y, *x);
4193 /* Create the artifact */
4194 if (create_named_art(artifact_index, *y, *x))
4195 a_info[artifact_index].cur_num = 1;
4199 /* Terrain special */
4200 c_ptr->special = letter[idx].special;
4208 /* Process "Q:<number>:<command>:... -- quest info */
4209 else if (buf[0] == 'Q')
4216 num = tokenize(buf + 2, 33, zz, 0);
4220 num = tokenize(buf + 3, 33, zz, 0);
4223 /* Have we enough parameters? */
4224 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4227 q_ptr = &(quest[atoi(zz[0])]);
4229 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4230 if (zz[1][0] == 'Q')
4232 if (init_flags & INIT_ASSIGN)
4234 monster_race *r_ptr;
4235 artifact_type *a_ptr;
4237 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4239 q_ptr->type = (QUEST_TYPE)atoi(zz[2]);
4240 q_ptr->num_mon = (MONSTER_NUMBER)atoi(zz[3]);
4241 q_ptr->cur_num = (MONSTER_NUMBER)atoi(zz[4]);
4242 q_ptr->max_num = (MONSTER_NUMBER)atoi(zz[5]);
4243 q_ptr->level = (DEPTH)atoi(zz[6]);
4244 q_ptr->r_idx = (IDX)atoi(zz[7]);
4245 q_ptr->k_idx = (IDX)atoi(zz[8]);
4246 q_ptr->dungeon = (DUNGEON_IDX)atoi(zz[9]);
4248 if (num > 10) q_ptr->flags = atoi(zz[10]);
4250 r_ptr = &r_info[q_ptr->r_idx];
4251 if (r_ptr->flags1 & RF1_UNIQUE)
4252 r_ptr->flags1 |= RF1_QUESTOR;
4254 a_ptr = &a_info[q_ptr->k_idx];
4255 a_ptr->gen_flags |= TRG_QUESTITEM;
4260 else if (zz[1][0] == 'R')
4262 if (init_flags & INIT_ASSIGN)
4265 IDX idx, reward_idx = 0;
4267 for (idx = 2; idx < num; idx++)
4269 IDX a_idx = (IDX)atoi(zz[idx]);
4270 if (a_idx < 1) continue;
4271 if (a_info[a_idx].cur_num > 0) continue;
4273 if (one_in_(count)) reward_idx = a_idx;
4278 /* Set quest's rewarding artifact */
4279 q_ptr->k_idx = reward_idx;
4280 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4284 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4285 q_ptr->type = QUEST_TYPE_KILL_ALL;
4292 /* Process "Q:<q_index>:N:<name>" -- quest name */
4293 else if (zz[1][0] == 'N')
4295 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4297 strcpy(q_ptr->name, zz[2]);
4303 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4304 else if (zz[1][0] == 'T')
4306 if (init_flags & INIT_SHOW_TEXT)
4308 strcpy(quest_text[quest_text_line], zz[2]);
4316 /* Process "W:<command>: ..." -- info for the wilderness */
4317 else if (buf[0] == 'W')
4319 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4322 /* Process "P:<y>:<x>" -- player position */
4323 else if (buf[0] == 'P')
4325 if (init_flags & INIT_CREATE_DUNGEON)
4327 if (tokenize(buf + 2, 2, zz, 0) == 2)
4329 int panels_x, panels_y;
4331 /* Hack - Set the dungeon size */
4332 panels_y = (*y / SCREEN_HGT);
4333 if (*y % SCREEN_HGT) panels_y++;
4334 cur_hgt = panels_y * SCREEN_HGT;
4336 panels_x = (*x / SCREEN_WID);
4337 if (*x % SCREEN_WID) panels_x++;
4338 cur_wid = panels_x * SCREEN_WID;
4340 /* Assume illegal panel */
4341 panel_row_min = cur_hgt;
4342 panel_col_min = cur_wid;
4344 /* Place player in a quest level */
4345 if (p_ptr->inside_quest)
4349 /* Delete the monster (if any) */
4350 delete_monster(p_ptr->y, p_ptr->x);
4358 /* Place player in the town */
4359 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4361 p_ptr->oldpy = atoi(zz[0]);
4362 p_ptr->oldpx = atoi(zz[1]);
4370 /* Process "B:<Index>:<Command>:..." -- Building definition */
4371 else if (buf[0] == 'B')
4373 return parse_line_building(buf);
4376 /* Process "M:<type>:<maximum>" -- set maximum values */
4377 else if (buf[0] == 'M')
4379 if (tokenize(buf+2, 2, zz, 0) == 2)
4382 if (zz[0][0] == 'T')
4384 max_towns = (IDX)atoi(zz[1]);
4387 /* Maximum quests */
4388 else if (zz[0][0] == 'Q')
4390 max_quests = (IDX)atoi(zz[1]);
4394 else if (zz[0][0] == 'R')
4396 max_r_idx = (IDX)atoi(zz[1]);
4400 else if (zz[0][0] == 'K')
4402 max_k_idx = (IDX)atoi(zz[1]);
4406 else if (zz[0][0] == 'V')
4408 max_v_idx = (IDX)atoi(zz[1]);
4412 else if (zz[0][0] == 'F')
4414 max_f_idx = (IDX)atoi(zz[1]);
4418 else if (zz[0][0] == 'A')
4420 max_a_idx = (IDX)atoi(zz[1]);
4424 else if (zz[0][0] == 'E')
4426 max_e_idx = (IDX)atoi(zz[1]);
4430 else if (zz[0][0] == 'D')
4432 max_d_idx = (IDX)atoi(zz[1]);
4436 else if (zz[0][0] == 'O')
4438 max_o_idx = (IDX)atoi(zz[1]);
4442 else if (zz[0][0] == 'M')
4444 max_m_idx = (IDX)atoi(zz[1]);
4447 /* Wilderness size */
4448 else if (zz[0][0] == 'W')
4450 /* Maximum wild_x_size */
4451 if (zz[0][1] == 'X')
4452 max_wild_x = atoi(zz[1]);
4453 /* Maximum wild_y_size */
4454 if (zz[0][1] == 'Y')
4455 max_wild_y = atoi(zz[1]);
4469 static cptr variant = "ZANGBAND";
4473 * @brief クエスト用固定ダンジョン生成時の分岐処理
4474 * Helper function for "process_dungeon_file()"
4479 static cptr process_dungeon_file_expr(char **sp, char *fp)
4495 while (iswspace(*s)) s++;
4513 t = process_dungeon_file_expr(&s, &f);
4522 else if (streq(t, "IOR"))
4525 while (*s && (f != b2))
4527 t = process_dungeon_file_expr(&s, &f);
4528 if (*t && !streq(t, "0")) v = "1";
4533 else if (streq(t, "AND"))
4536 while (*s && (f != b2))
4538 t = process_dungeon_file_expr(&s, &f);
4539 if (*t && streq(t, "0")) v = "0";
4544 else if (streq(t, "NOT"))
4547 while (*s && (f != b2))
4549 t = process_dungeon_file_expr(&s, &f);
4550 if (*t && streq(t, "1")) v = "0";
4555 else if (streq(t, "EQU"))
4558 if (*s && (f != b2))
4560 t = process_dungeon_file_expr(&s, &f);
4562 while (*s && (f != b2))
4564 p = process_dungeon_file_expr(&s, &f);
4565 if (streq(t, p)) v = "1";
4570 else if (streq(t, "LEQ"))
4573 if (*s && (f != b2))
4575 t = process_dungeon_file_expr(&s, &f);
4577 while (*s && (f != b2))
4580 t = process_dungeon_file_expr(&s, &f);
4581 if (*t && atoi(p) > atoi(t)) v = "0";
4586 else if (streq(t, "GEQ"))
4589 if (*s && (f != b2))
4591 t = process_dungeon_file_expr(&s, &f);
4593 while (*s && (f != b2))
4596 t = process_dungeon_file_expr(&s, &f);
4598 /* Compare two numbers instead of string */
4599 if (*t && atoi(p) < atoi(t)) v = "0";
4606 while (*s && (f != b2))
4608 t = process_dungeon_file_expr(&s, &f);
4613 if (f != b2) v = "?x?x?";
4615 /* Extract final and Terminate */
4616 if ((f = *s) != '\0') *s++ = '\0';
4622 /* Accept all printables except spaces and brackets */
4624 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4626 if (iskanji(*s)) s++;
4630 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4633 /* Extract final and Terminate */
4634 if ((f = *s) != '\0') *s++ = '\0';
4640 if (streq(b+1, "SYS"))
4646 else if (streq(b+1, "GRAF"))
4651 else if (streq(b+1, "MONOCHROME"))
4660 else if (streq(b+1, "RACE"))
4662 v = _(rp_ptr->E_title, rp_ptr->title);
4666 else if (streq(b+1, "CLASS"))
4668 v = _(cp_ptr->E_title, cp_ptr->title);
4672 else if (streq(b+1, "REALM1"))
4674 v = _(E_realm_names[p_ptr->realm1], realm_names[p_ptr->realm1]);
4678 else if (streq(b+1, "REALM2"))
4680 v = _(E_realm_names[p_ptr->realm2], realm_names[p_ptr->realm2]);
4684 else if (streq(b+1, "PLAYER"))
4686 static char tmp_player_name[32];
4688 for (pn = p_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++)
4698 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4701 v = tmp_player_name;
4705 else if (streq(b+1, "TOWN"))
4707 sprintf(tmp, "%d", p_ptr->town_num);
4712 else if (streq(b+1, "LEVEL"))
4714 sprintf(tmp, "%d", p_ptr->lev);
4718 /* Current quest number */
4719 else if (streq(b+1, "QUEST_NUMBER"))
4721 sprintf(tmp, "%d", p_ptr->inside_quest);
4725 /* Number of last quest */
4726 else if (streq(b+1, "LEAVING_QUEST"))
4728 sprintf(tmp, "%d", leaving_quest);
4733 else if (prefix(b+1, "QUEST_TYPE"))
4735 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4736 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4741 else if (prefix(b+1, "QUEST"))
4743 /* "QUEST" uses a special parameter to determine the number of the quest */
4744 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4749 else if (prefix(b+1, "RANDOM"))
4751 /* "RANDOM" uses a special parameter to determine the number of the quest */
4752 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4757 else if (streq(b+1, "VARIANT"))
4763 else if (streq(b+1, "WILDERNESS"))
4766 sprintf(tmp, "NONE");
4768 sprintf(tmp, "LITE");
4770 sprintf(tmp, "NORMAL");
4794 * @brief クエスト用固定ダンジョン生成時のメインルーチン
4795 * Helper function for "process_dungeon_file()"
4803 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4813 bool bypass = FALSE;
4815 int x = xmin, y = ymin;
4818 /* Build the filename */
4819 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4822 fp = my_fopen(buf, "r");
4825 if (!fp) return (-1);
4828 /* Process the file */
4829 while (0 == my_fgets(fp, buf, sizeof(buf)))
4835 /* Skip "empty" lines */
4836 if (!buf[0]) continue;
4838 /* Skip "blank" lines */
4839 if (iswspace(buf[0])) continue;
4842 if (buf[0] == '#') continue;
4845 /* Process "?:<expr>" */
4846 if ((buf[0] == '?') && (buf[1] == ':'))
4855 /* Parse the expr */
4856 v = process_dungeon_file_expr(&s, &f);
4859 bypass = (streq(v, "0") ? TRUE : FALSE);
4865 /* Apply conditionals */
4866 if (bypass) continue;
4868 /* Process the line */
4869 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4881 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4884 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4885 msg_format(_("'%s'を解析中。", "Parsing '%s'."), buf);
4891 /* Close the file */
4901 void write_r_info_txt(void)
4903 int i, j, z, fc, bc;
4906 cptr flags[32 * 10];
4911 monster_race *r_ptr;
4913 monster_blow *b_ptr;
4915 FILE *fff = fopen("output.txt", "wt");
4919 BIT_FLAGS mode = -1;
4923 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4925 fprintf(fff, "# Version stamp (required)\n\n");
4928 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4931 fprintf(fff, "##### The Player #####\n\n");
4933 for (z = -1; z < alloc_race_size; z++)
4935 /* Output the monsters in order */
4936 i = (z >= 0) ? alloc_race_table[z].index : 0;
4938 /* Acquire the monster */
4941 /* Ignore empty monsters */
4942 if (!strlen(r_name + r_ptr->name)) continue;
4944 /* Ignore useless monsters */
4945 if (i && !r_ptr->speed) continue;
4947 /* Write a note if necessary */
4948 if (i && (!r_ptr->level != !mode))
4953 fprintf(fff, "\n##### Town monsters #####\n\n");
4955 /* Note the dungeon */
4958 fprintf(fff, "\n##### Normal monsters #####\n\n");
4961 /* Record the change */
4962 mode = r_ptr->level;
4965 /* Acquire the flags */
4966 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4967 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4968 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4969 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4970 f_ptr[4] = r_ptr->a_ability_flags1; n_ptr[4] = r_a_ability_flags1;
4971 f_ptr[5] = r_ptr->a_ability_flags2; n_ptr[5] = r_a_ability_flags2;
4972 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4973 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4974 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4975 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4977 /* Write New/Number/Name */
4978 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4981 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4983 /* Write Information */
4984 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4985 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4987 /* Write more information */
4988 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4991 for(j = 0; j < 4; j++)
4993 b_ptr = &(r_ptr->blow[j]);
4995 /* Stop when done */
4996 if (!b_ptr->method) break;
4998 /* Write the blows */
4999 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
5000 r_info_blow_effect[b_ptr->effect],
5001 b_ptr->d_dice, b_ptr->d_side);
5004 /* Extract the flags */
5005 for (fc = 0, j = 0; j < 32 * 3; j++)
5007 /* Check this flag */
5008 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5011 /* Extract the extra flags */
5012 for (j = 32 * 6; j < 32 * 10; j++)
5014 /* Check this flag */
5015 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5018 /* Write the flags */
5019 for (j = 0; j < fc;)
5023 /* Start the line */
5026 for (bc = 0; (bc < 60) && (j < fc); j++)
5030 /* Format the flag */
5031 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
5033 /* Add it to the buffer */
5036 /* Note the length */
5040 /* Done with this line; write it */
5041 fprintf(fff, "%s\n", buf);
5044 /* Write Spells if applicable */
5045 if (r_ptr->freq_spell)
5047 /* Write the frequency */
5048 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
5050 /* Extract the spell flags */
5051 for (fc = 0, j = 96; j < 192; j++)
5053 /* Check this flag */
5054 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
5057 /* Write the flags */
5058 for (j = 0; j < fc;)
5062 /* Start the line */
5065 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
5069 /* Format the flag */
5070 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
5074 /* Note the length */
5081 /* Done with this line; write it */
5082 fprintf(fff, "%s\n", buf);
5086 /* Acquire the description */
5087 desc = r_text + r_ptr->text;
5088 dlen = strlen(desc);
5090 /* Write Description */
5091 for (j = 0; j < dlen;)
5095 /* Start the line */
5098 for (bc = 0, t = buf + 2; ((bc < 60) || !iswspace(desc[j])) && (j < dlen); j++, bc++, t++)
5106 /* Done with this line; write it */
5107 fprintf(fff, "%s\n", buf);
5110 /* Space between entries */