4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies. Other copyrights may also apply.
11 /* Purpose: Initialization (part 1) -BEN- */
17 * This file is used to initialize various variables and arrays for the
18 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
19 * the common limitation of "read()" and "write()" to only 32767 bytes
22 * Several of the arrays for Angband are built from "template" files in
23 * the "lib/file" directory, from which quick-load binary "image" files
24 * are constructed whenever they are not present in the "lib/data"
25 * directory, or if those files become obsolete, if we are allowed.
27 * Warning -- the "ascii" file parsers use a minor hack to collect the
28 * name and text information in a single pass. Thus, the game will not
29 * be able to load any template file with more than 20K of names or 60K
30 * of text, even though technically, up to 64K should be legal.
32 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
33 * in this file is compiled out, and the game will not run unless valid
34 * "binary template files" already exist in "lib/data". Thus, one can
35 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
36 * "*.raw" files in "lib/data", and then quit, and recompile without
37 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
38 * from changing the ascii template files in potentially dangerous ways.
40 * The code could actually be removed and placed into a "stand-alone"
41 * program, but that feels a little silly, especially considering some
42 * of the platforms that we currently support.
45 #ifdef ALLOW_TEMPLATES
50 /*** Helper arrays for parsing ascii template files ***/
53 * Monster Blow Methods
55 static cptr r_info_blow_method[] =
88 * Monster Blow Effects
90 static cptr r_info_blow_effect[] =
135 static cptr f_info_flags[] =
259 static cptr r_info_flags1[] =
298 static cptr r_info_flags2[] =
337 static cptr r_info_flags3[] =
376 static cptr r_info_flags4[] =
415 static cptr r_info_flags5[] =
454 static cptr r_info_flags6[] =
471 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
494 static cptr r_info_flags7[] =
533 static cptr r_info_flags8[] =
565 "WILD_SWAMP", /* ToDo: Implement Swamp */
571 * Monster race flags - Drops
573 static cptr r_info_flags9[] =
612 * Monster race flags - Resistances
614 static cptr r_info_flagsr[] =
654 static cptr k_info_flags[] =
780 static cptr k_info_gen_flags[] =
819 struct k_info_activation_flag
823 } k_info_activation_flags[] =
825 { "SUNLIGHT", ACT_SUNLIGHT },
826 { "BO_MISS_1", ACT_BO_MISS_1 },
827 { "BA_POIS_1", ACT_BA_POIS_1 },
828 { "BO_ELEC_1", ACT_BO_ELEC_1 },
829 { "BO_ACID_1", ACT_BO_ACID_1 },
830 { "BO_COLD_1", ACT_BO_COLD_1 },
831 { "BO_FIRE_1", ACT_BO_FIRE_1 },
832 { "BA_COLD_1", ACT_BA_COLD_1 },
833 { "BA_FIRE_1", ACT_BA_FIRE_1 },
834 { "DRAIN_1", ACT_DRAIN_1 },
835 { "BA_COLD_2", ACT_BA_COLD_2 },
836 { "BA_ELEC_2", ACT_BA_ELEC_2 },
837 { "DRAIN_2", ACT_DRAIN_2 },
838 { "VAMPIRE_1", ACT_VAMPIRE_1 },
839 { "BO_MISS_2", ACT_BO_MISS_2 },
840 { "BA_FIRE_3", ACT_BA_FIRE_3 },
841 { "BA_COLD_3", ACT_BA_COLD_3 },
842 { "BA_ELEC_3", ACT_BA_ELEC_3 },
843 { "WHIRLWIND", ACT_WHIRLWIND },
844 { "VAMPIRE_2", ACT_VAMPIRE_2 },
845 { "CALL_CHAOS", ACT_CALL_CHAOS },
846 { "ROCKET", ACT_ROCKET },
847 { "DISP_EVIL", ACT_DISP_EVIL },
848 { "BA_MISS_3", ACT_BA_MISS_3 },
849 { "DISP_GOOD", ACT_DISP_GOOD },
850 { "BO_MANA", ACT_BO_MANA },
851 { "BA_FIRE_2", ACT_BA_FIRE_2 },
852 { "BA_WATER", ACT_BA_WATER },
853 { "BA_STAR", ACT_BA_STAR },
854 { "BA_DARK", ACT_BA_DARK },
855 { "BA_MANA", ACT_BA_MANA },
856 { "PESTICIDE", ACT_PESTICIDE },
857 { "BLINDING_LIGHT", ACT_BLINDING_LIGHT },
859 { "CONFUSE", ACT_CONFUSE },
860 { "SLEEP", ACT_SLEEP },
861 { "QUAKE", ACT_QUAKE },
862 { "TERROR", ACT_TERROR },
863 { "TELE_AWAY", ACT_TELE_AWAY },
864 { "BANISH_EVIL", ACT_BANISH_EVIL },
865 { "GENOCIDE", ACT_GENOCIDE },
866 { "MASS_GENO", ACT_MASS_GENO },
868 { "CHARM_ANIMAL", ACT_CHARM_ANIMAL },
869 { "CHARM_UNDEAD", ACT_CHARM_UNDEAD },
870 { "CHARM_OTHER", ACT_CHARM_OTHER },
871 { "CHARM_ANIMALS", ACT_CHARM_ANIMALS },
872 { "CHARM_OTHERS", ACT_CHARM_OTHERS },
873 { "SUMMON_ANIMAL", ACT_SUMMON_ANIMAL },
874 { "SUMMON_PHANTOM", ACT_SUMMON_PHANTOM },
875 { "SUMMON_ELEMENTAL", ACT_SUMMON_ELEMENTAL },
876 { "SUMMON_DEMON", ACT_SUMMON_DEMON },
877 { "SUMMON_UNDEAD", ACT_SUMMON_UNDEAD },
878 { "SUMMON_HOUND", ACT_SUMMON_HOUND },
880 { "CHOIR_SINGS", ACT_CHOIR_SINGS },
881 { "CURE_LW", ACT_CURE_LW },
882 { "CURE_MW", ACT_CURE_MW },
883 { "CURE_POISON", ACT_CURE_POISON },
884 { "REST_LIFE", ACT_REST_LIFE },
885 { "REST_ALL", ACT_REST_ALL },
886 { "CURE_700", ACT_CURE_700 },
887 { "CURE_1000", ACT_CURE_1000 },
888 { "CURING", ACT_CURING },
889 { "CURE_MANA_FULL", ACT_CURE_MANA_FULL },
892 { "BERSERK", ACT_BERSERK },
893 { "PROT_EVIL", ACT_PROT_EVIL },
894 { "RESIST_ALL", ACT_RESIST_ALL },
895 { "SPEED", ACT_SPEED },
896 { "XTRA_SPEED", ACT_XTRA_SPEED },
897 { "WRAITH", ACT_WRAITH },
898 { "INVULN", ACT_INVULN },
899 { "HELO", ACT_HELO },
900 { "HELO_SPEED", ACT_HELO_SPEED },
901 { "RESIST_ACID", ACT_RESIST_ACID },
902 { "RESIST_FIRE", ACT_RESIST_ACID },
903 { "RESIST_COLD", ACT_RESIST_ACID },
904 { "RESIST_ELEC", ACT_RESIST_ACID },
905 { "RESIST_POIS", ACT_RESIST_ACID },
907 { "LIGHT", ACT_LIGHT },
908 { "MAP_LIGHT", ACT_MAP_LIGHT },
909 { "DETECT_ALL", ACT_DETECT_ALL },
910 { "DETECT_XTRA", ACT_DETECT_XTRA },
911 { "ID_FULL", ACT_ID_FULL },
912 { "ID_PLAIN", ACT_ID_PLAIN },
913 { "RUNE_EXPLO", ACT_RUNE_EXPLO },
914 { "RUNE_PROT", ACT_RUNE_PROT },
915 { "SATIATE", ACT_SATIATE },
916 { "DEST_DOOR", ACT_DEST_DOOR },
917 { "STONE_MUD", ACT_STONE_MUD },
918 { "RECHARGE", ACT_RECHARGE },
919 { "ALCHEMY", ACT_ALCHEMY },
920 { "DIM_DOOR", ACT_DIM_DOOR },
921 { "TELEPORT", ACT_TELEPORT },
922 { "RECALL", ACT_RECALL },
923 { "TELEKINESIS", ACT_TELEKINESIS },
924 { "DETECT_UNIQUE", ACT_DETECT_UNIQUE },
926 { "BRAND_FIRE_BOLTS", ACT_BRAND_FIRE_BOLTS },
927 { "JUDGE", ACT_JUDGE },
928 { "BIZARRE", ACT_BIZARRE },
936 static cptr d_info_flags1[] =
974 * Add a text to the text-storage and store offset to it.
976 * Returns FALSE when there isn't enough space available to store
979 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
981 /* Hack -- Verify space */
982 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
988 /* Advance and save the text index */
989 *offset = ++head->text_size;
992 /* Additional text */
993 else if (normal_text)
996 * If neither the end of the last line nor
997 * the beginning of current line is not a space,
998 * fill up a space as a correct separator of two words.
1000 if (head->text_size > 0 &&
1002 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1003 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1004 (buf[0] != ' ') && !iskanji(buf[0])
1006 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1011 /* Append a space */
1012 *(head->text_ptr + head->text_size) = ' ';
1014 /* Advance the index */
1019 /* Append chars to the text */
1020 strcpy(head->text_ptr + head->text_size, buf);
1022 /* Advance the index */
1023 head->text_size += strlen(buf);
1031 * Add a name to the name-storage and return an offset to it.
1033 * Returns FALSE when there isn't enough space available to store
1036 static bool add_name(u32b *offset, header *head, cptr buf)
1038 /* Hack -- Verify space */
1039 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1045 /* Advance and save the name index */
1046 *offset = ++head->name_size;
1049 /* Append chars to the names */
1050 strcpy(head->name_ptr + head->name_size, buf);
1052 /* Advance the index */
1053 head->name_size += strlen(buf);
1061 * Add a tag to the tag-storage and return an offset to it.
1063 * Returns FALSE when there isn't enough space available to store
1066 static bool add_tag(s16b *offset, header *head, cptr buf)
1070 /* Search for an existing (fake) tag */
1071 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1074 if (streq(&head->tag_ptr[i], buf)) break;
1077 /* There was no existing tag */
1078 if (i >= head->tag_size)
1080 /* Hack -- Verify space */
1081 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1084 /* Append chars to the tags */
1085 strcpy(head->tag_ptr + head->tag_size, buf);
1087 /* Point the new tag */
1090 /* Advance the index */
1091 head->tag_size += strlen(buf) + 1;
1094 /* Return offset of the tag */
1103 * Convert a "color letter" into an "actual" color
1104 * The colors are: dwsorgbuDWvyRGBU, as shown below
1106 byte color_char_to_attr(char c)
1110 case 'd': return (TERM_DARK);
1111 case 'w': return (TERM_WHITE);
1112 case 's': return (TERM_SLATE);
1113 case 'o': return (TERM_ORANGE);
1114 case 'r': return (TERM_RED);
1115 case 'g': return (TERM_GREEN);
1116 case 'b': return (TERM_BLUE);
1117 case 'u': return (TERM_UMBER);
1119 case 'D': return (TERM_L_DARK);
1120 case 'W': return (TERM_L_WHITE);
1121 case 'v': return (TERM_VIOLET);
1122 case 'y': return (TERM_YELLOW);
1123 case 'R': return (TERM_L_RED);
1124 case 'G': return (TERM_L_GREEN);
1125 case 'B': return (TERM_L_BLUE);
1126 case 'U': return (TERM_L_UMBER);
1134 /*** Initialize from ascii template files ***/
1138 * Initialize an "*_info" array, by parsing an ascii "template" file
1140 errr init_info_txt(FILE *fp, char *buf, header *head,
1141 parse_info_txt_func parse_info_txt_line)
1145 /* Just before the first record */
1148 /* Just before the first line */
1152 /* Prepare the "fake" stuff */
1153 head->name_size = 0;
1154 head->text_size = 0;
1158 while (0 == my_fgets(fp, buf, 1024))
1160 /* Advance the line number */
1163 /* Skip comments and blank lines */
1164 if (!buf[0] || (buf[0] == '#')) continue;
1166 /* Verify correct "colon" format */
1167 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1170 /* Hack -- Process 'V' for "Version" */
1177 /* Mega Hack -- Calculate Check Sum */
1178 if (buf[0] != 'N' && buf[0] != 'D')
1181 for (i = 0; buf[i]; i++)
1183 head->v_extra += (byte)buf[i];
1184 head->v_extra ^= (1 << (i % 8));
1188 /* Parse the line */
1189 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1194 /* Complete the "name" and "text" sizes */
1195 if (head->name_size) head->name_size++;
1196 if (head->text_size) head->text_size++;
1204 * Initialize the "v_info" array, by parsing an ascii "template" file
1206 errr parse_v_info(char *buf, header *head)
1212 static vault_type *v_ptr = NULL;
1214 /* Process 'N' for "New/Number/Name" */
1217 /* Find the colon before the name */
1218 s = my_strchr(buf+2, ':');
1220 /* Verify that colon */
1223 /* Nuke the colon, advance to the name */
1226 /* Paranoia -- require a name */
1227 if (!*s) return (1);
1232 /* Verify information */
1233 if (i <= error_idx) return (4);
1235 /* Verify information */
1236 if (i >= head->info_num) return (2);
1238 /* Save the index */
1241 /* Point at the "info" */
1244 /* Store the name */
1245 if (!add_name(&v_ptr->name, head, s)) return (7);
1248 /* There better be a current v_ptr */
1249 else if (!v_ptr) return (3);
1251 /* Process 'D' for "Description" */
1252 else if (buf[0] == 'D')
1254 /* Acquire the text */
1257 /* Store the text */
1258 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1261 /* Process 'X' for "Extra info" (one line only) */
1262 else if (buf[0] == 'X')
1264 int typ, rat, hgt, wid;
1266 /* Scan for the values */
1267 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1268 &typ, &rat, &hgt, &wid)) return (1);
1270 /* Save the values */
1287 * Initialize the "s_info" array, by parsing an ascii "template" file
1289 errr parse_s_info(char *buf, header *head)
1294 static skill_table *s_ptr = NULL;
1297 /* Process 'N' for "New/Number/Name" */
1303 /* Verify information */
1304 if (i <= error_idx) return (4);
1306 /* Verify information */
1307 if (i >= head->info_num) return (2);
1309 /* Save the index */
1312 /* Point at the "info" */
1316 /* There better be a current s_ptr */
1317 else if (!s_ptr) return (3);
1319 /* Process 'W' for "Weapon exp" */
1320 else if (buf[0] == 'W')
1322 int tval, sval, start, max;
1323 const s16b exp_conv_table[] =
1325 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1326 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1329 /* Scan for the values */
1330 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1331 &tval, &sval, &start, &max)) return (1);
1333 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1334 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1336 /* Save the values */
1337 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1338 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1341 /* Process 'S' for "Skill exp" */
1342 else if (buf[0] == 'S')
1344 int num, start, max;
1346 /* Scan for the values */
1347 if (3 != sscanf(buf+2, "%d:%d:%d",
1348 &num, &start, &max)) return (1);
1350 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1351 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1353 /* Save the values */
1354 s_ptr->s_start[num] = start;
1355 s_ptr->s_max[num] = max;
1368 * Initialize the "m_info" array, by parsing an ascii "template" file
1370 errr parse_m_info(char *buf, header *head)
1377 static player_magic *m_ptr = NULL;
1380 static int realm, magic_idx = 0, readable = 0;
1383 /* Process 'N' for "New/Number/Name" */
1389 /* Verify information */
1390 if (i <= error_idx) return (4);
1392 /* Verify information */
1393 if (i >= head->info_num) return (2);
1395 /* Save the index */
1398 /* Point at the "info" */
1402 /* There better be a current m_ptr */
1403 else if (!m_ptr) return (3);
1405 /* Process 'I' for "Info" (one line only) */
1406 else if (buf[0] == 'I')
1409 int xtra, type, first, weight;
1411 /* Find the colon before the name */
1412 s = my_strchr(buf+2, ':');
1414 /* Verify that colon */
1417 /* Nuke the colon, advance to the name */
1422 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1423 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1424 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1425 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1426 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1431 /* Find the colon before the name */
1432 s = my_strchr(s, ':');
1434 /* Verify that colon */
1437 /* Nuke the colon, advance to the name */
1440 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1441 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1442 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1443 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1444 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1445 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1449 /* Scan for the values */
1450 if (4 != sscanf(s, "%x:%d:%d:%d",
1451 (uint *)&xtra, &type, &first, &weight)) return (1);
1453 m_ptr->spell_xtra = xtra;
1454 m_ptr->spell_type = type;
1455 m_ptr->spell_first = first;
1456 m_ptr->spell_weight = weight;
1460 /* Process 'R' for "Realm" (one line only) */
1461 else if (buf[0] == 'R')
1463 /* Scan for the values */
1464 if (2 != sscanf(buf+2, "%d:%d",
1465 &realm, &readable)) return (1);
1470 else if (buf[0] == 'T')
1472 int level, mana, fail, exp;
1474 if (!readable) return (1);
1475 /* Scan for the values */
1476 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1477 &level, &mana, &fail, &exp)) return (1);
1479 m_ptr->info[realm][magic_idx].slevel = level;
1480 m_ptr->info[realm][magic_idx].smana = mana;
1481 m_ptr->info[realm][magic_idx].sfail = fail;
1482 m_ptr->info[realm][magic_idx].sexp = exp;
1496 * Grab one flag from a textual string
1498 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1503 for (i = 0; i < 32; i++)
1505 if (streq(what, names[i]))
1507 *flags |= (1L << i);
1517 * Grab one flag in an feature_type from a textual string
1519 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1524 for (i = 0; i < FF_FLAG_MAX; i++)
1526 if (streq(what, f_info_flags[i]))
1528 add_flag(f_ptr->flags, i);
1535 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1537 msg_format("Unknown feature flag '%s'.", what);
1541 return PARSE_ERROR_GENERIC;
1546 * Grab an action in an feature_type from a textual string
1548 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1553 for (i = 0; i < FF_FLAG_MAX; i++)
1555 if (streq(what, f_info_flags[i]))
1557 f_ptr->state[count].action = i;
1564 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1566 msg_format("Unknown feature action '%s'.", what);
1570 return PARSE_ERROR_GENERIC;
1575 * Initialize the "f_info" array, by parsing an ascii "template" file
1577 errr parse_f_info(char *buf, header *head)
1584 static feature_type *f_ptr = NULL;
1587 /* Process 'N' for "New/Number/Name" */
1590 /* Find the colon before the name */
1591 s = my_strchr(buf+2, ':');
1595 /* Nuke the colon, advance to the name */
1602 /* Verify information */
1603 if (i <= error_idx) return (4);
1605 /* Verify information */
1606 if (i >= head->info_num) return (2);
1608 /* Save the index */
1611 /* Point at the "info" */
1614 /* Tag name is given */
1618 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1621 /* Default "mimic" */
1624 /* Default "destroyed state" -- if not specified */
1625 f_ptr->destroyed = i;
1627 /* Default "states" */
1628 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1631 /* There better be a current f_ptr */
1632 else if (!f_ptr) return (3);
1635 else if (buf[0] == 'J')
1637 /* Store the name */
1638 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1641 else if (buf[0] == 'E')
1643 /* Ignore english name */
1646 else if (buf[0] == 'J')
1648 /* Ignore Japanese name */
1651 else if (buf[0] == 'E')
1653 /* Acquire the Text */
1656 /* Store the name */
1657 if (!add_name(&f_ptr->name, head, s)) return (7);
1662 /* Process 'M' for "Mimic" (one line only) */
1663 else if (buf[0] == 'M')
1667 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1669 /* Record a fake tag index */
1670 f_ptr->mimic = -offset;
1674 /* Process 'G' for "Graphics" (one line only) */
1675 else if (buf[0] == 'G')
1679 char char_tmp[F_LIT_MAX];
1682 if (buf[1] != ':') return (1);
1683 if (!buf[2]) return (1);
1684 if (buf[3] != ':') return (1);
1685 if (!buf[4]) return (1);
1687 /* Extract the char */
1688 char_tmp[F_LIT_STANDARD] = buf[2];
1690 /* Extract the color */
1691 s_attr = color_char_to_attr(buf[4]);
1694 if (s_attr > 127) return (1);
1696 /* Save the standard values */
1697 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1698 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1700 /* Is this feature supports lighting? */
1703 /* G:c:a:LIT (default) */
1704 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1706 /* G:c:a:lc:la:dc:da */
1707 if (!streq(buf + 6, "LIT"))
1709 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1711 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1712 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1713 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1714 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1716 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1718 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1721 /* Use default lighting */
1724 /* No lighting support */
1725 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1728 /* Extract the color */
1729 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1730 if (f_ptr->d_attr[j] > 127) return 1;
1733 f_ptr->d_char[j] = char_tmp[j];
1739 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1741 f_ptr->d_attr[j] = s_attr;
1742 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1748 /* Hack -- Process 'F' for flags */
1749 else if (buf[0] == 'F')
1751 /* Parse every entry textually */
1752 for (s = buf + 2; *s; )
1754 /* Find the end of this entry */
1755 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1757 /* Nuke and skip any dividers */
1761 while (*t == ' ' || *t == '|') t++;
1764 /* XXX XXX XXX Hack -- Read feature subtype */
1765 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1767 /* Extract a "subtype" */
1770 /* Start at next entry */
1777 /* XXX XXX XXX Hack -- Read feature power */
1778 if (1 == sscanf(s, "POWER_%d", &i))
1780 /* Extract a "power" */
1783 /* Start at next entry */
1790 /* Parse this entry */
1791 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1793 /* Start the next entry */
1798 /* Process 'W' for "More Info" (one line only) */
1799 else if (buf[0] == 'W')
1803 /* Scan for the value */
1804 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1806 /* Save the value */
1807 f_ptr->priority = priority;
1810 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1811 else if (buf[0] == 'K')
1815 /* Find the next empty state slot (if any) */
1816 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1818 /* Oops, no more slots */
1819 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1821 /* Analyze the first field */
1822 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1824 /* Terminate the field (if necessary) */
1825 if (*t == ':') *t++ = '\0';
1827 /* Is this default entry? */
1828 if (streq(s, "DESTROYED"))
1830 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1832 /* Record a fake tag index */
1833 f_ptr->destroyed = -offset;
1838 f_ptr->state[i].action = 0;
1840 /* Parse this entry */
1841 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1843 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1845 /* Record a fake tag index */
1846 f_ptr->state[i].result = -offset;
1859 * Convert a fake tag to a real feat index
1861 s16b f_tag_to_index(cptr str)
1865 /* Search for real index corresponding to this fake tag */
1866 for (i = 0; i < f_head.info_num; i++)
1868 if (streq(f_tag + f_info[i].tag, str))
1870 /* Return the index */
1881 * Search for real index corresponding to this fake tag
1883 static void search_real_feat(s16b *feat)
1887 /* Don't convert non-fake tag */
1888 if (*feat >= 0) return;
1890 /* Search for real index corresponding to this fake tag */
1891 for (i = 0; i < f_head.info_num; i++)
1893 if ((-(*feat)) == f_info[i].tag)
1895 /* Record real index */
1903 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1905 msg_format("%s is undefined.", f_tag + (-(*feat)));
1911 * Retouch fake tags of f_info
1913 void retouch_f_info(header *head)
1917 /* Convert fake tags to real feat indices */
1918 for (i = 0; i < head->info_num; i++)
1920 feature_type *f_ptr = &f_info[i];
1923 search_real_feat(&f_ptr->mimic);
1925 search_real_feat(&f_ptr->destroyed);
1927 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1933 * Grab one flag in an object_kind from a textual string
1935 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1940 for (i = 0; i < TR_FLAG_MAX; i++)
1942 if (streq(what, k_info_flags[i]))
1944 add_flag(k_ptr->flags, i);
1949 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1954 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1956 msg_format("Unknown object flag '%s'.", what);
1966 * Initialize the "k_info" array, by parsing an ascii "template" file
1968 errr parse_k_info(char *buf, header *head)
1975 static object_kind *k_ptr = NULL;
1978 /* Process 'N' for "New/Number/Name" */
1985 /* Find the colon before the name */
1986 s = my_strchr(buf+2, ':');
1988 /* Verify that colon */
1991 /* Nuke the colon, advance to the name */
1997 /* Verify information */
1998 if (i <= error_idx) return (4);
2000 /* Verify information */
2001 if (i >= head->info_num) return (2);
2003 /* Save the index */
2006 /* Point at the "info" */
2010 /* Paranoia -- require a name */
2011 if (!*s) return (1);
2013 /* Find the colon before the flavor */
2014 flavor = my_strchr(s, ':');
2016 /* Verify that colon */
2019 /* Nuke the colon, advance to the flavor */
2022 /* Store the flavor */
2023 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2026 /* Store the name */
2027 if (!add_name(&k_ptr->name, head, s)) return (7);
2031 /* There better be a current k_ptr */
2032 else if (!k_ptr) return (3);
2036 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2037 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2038 else if (buf[0] == 'E')
2043 else if (buf[0] == 'E')
2047 /* Acquire the name */
2050 /* Find the colon before the flavor */
2051 flavor = my_strchr(s, ':');
2053 /* Verify that colon */
2056 /* Nuke the colon, advance to the flavor */
2059 /* Store the flavor */
2060 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2063 /* Store the name */
2064 if (!add_name(&k_ptr->name, head, s)) return (7);
2068 /* Process 'D' for "Description" */
2069 else if (buf[0] == 'D')
2074 /* Acquire the text */
2079 /* Acquire the text */
2083 /* Store the text */
2084 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2087 /* Process 'G' for "Graphics" (one line only) */
2088 else if (buf[0] == 'G')
2094 if (buf[1] != ':') return (1);
2095 if (!buf[2]) return (1);
2096 if (buf[3] != ':') return (1);
2097 if (!buf[4]) return (1);
2099 /* Extract the char */
2102 /* Extract the attr */
2103 tmp = color_char_to_attr(buf[4]);
2106 if (tmp > 127) return (1);
2108 /* Save the values */
2109 k_ptr->d_attr = tmp;
2110 k_ptr->d_char = sym;
2113 /* Process 'I' for "Info" (one line only) */
2114 else if (buf[0] == 'I')
2116 int tval, sval, pval;
2118 /* Scan for the values */
2119 if (3 != sscanf(buf+2, "%d:%d:%d",
2120 &tval, &sval, &pval)) return (1);
2122 /* Save the values */
2128 /* Process 'W' for "More Info" (one line only) */
2129 else if (buf[0] == 'W')
2131 int level, extra, wgt;
2134 /* Scan for the values */
2135 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2136 &level, &extra, &wgt, &cost)) return (1);
2138 /* Save the values */
2139 k_ptr->level = level;
2140 k_ptr->extra = extra;
2141 k_ptr->weight = wgt;
2145 /* Process 'A' for "Allocation" (one line only) */
2146 else if (buf[0] == 'A')
2150 /* XXX XXX XXX Simply read each number following a colon */
2151 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2153 /* Default chance */
2154 k_ptr->chance[i] = 1;
2156 /* Store the attack damage index */
2157 k_ptr->locale[i] = atoi(s+1);
2159 /* Find the slash */
2160 t = my_strchr(s+1, '/');
2162 /* Find the next colon */
2163 s = my_strchr(s+1, ':');
2165 /* If the slash is "nearby", use it */
2166 if (t && (!s || t < s))
2168 int chance = atoi(t+1);
2169 if (chance > 0) k_ptr->chance[i] = chance;
2174 /* Hack -- Process 'P' for "power" and such */
2175 else if (buf[0] == 'P')
2177 int ac, hd1, hd2, th, td, ta;
2179 /* Scan for the values */
2180 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2181 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2191 /* Hack -- Process 'F' for flags */
2192 else if (buf[0] == 'F')
2194 /* Parse every entry textually */
2195 for (s = buf + 2; *s; )
2197 /* Find the end of this entry */
2198 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2200 /* Nuke and skip any dividers */
2204 while (*t == ' ' || *t == '|') t++;
2207 /* Parse this entry */
2208 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2210 /* Start the next entry */
2226 * Grab one flag in an artifact_type from a textual string
2228 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2233 for (i = 0; i < TR_FLAG_MAX; i++)
2235 if (streq(what, k_info_flags[i]))
2237 add_flag(a_ptr->flags, i);
2242 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2247 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2249 msg_format("Unknown artifact flag '%s'.", what);
2258 * Grab one activation index flag
2260 static byte grab_one_activation_flag(cptr what)
2266 if (k_info_activation_flags[i].flag == NULL) break;
2268 if (streq(what, k_info_activation_flags[i].flag))
2270 return k_info_activation_flags[i].index;
2282 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
2284 msg_format("Unknown activation flag '%s'.", what);
2293 * Initialize the "a_info" array, by parsing an ascii "template" file
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);
2351 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
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 * Grab one flag in a ego-item_type from a textual string
2489 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2494 for (i = 0; i < TR_FLAG_MAX; i++)
2496 if (streq(what, k_info_flags[i]))
2498 add_flag(e_ptr->flags, i);
2503 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2508 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2510 msg_format("Unknown ego-item flag '%s'.", what);
2522 * Initialize the "e_info" array, by parsing an ascii "template" file
2524 errr parse_e_info(char *buf, header *head)
2531 static ego_item_type *e_ptr = NULL;
2534 /* Just before the first record */
2537 /* Just before the first line */
2541 /* Process 'N' for "New/Number/Name" */
2544 /* Find the colon before the name */
2545 s = my_strchr(buf+2, ':');
2547 /* Verify that colon */
2550 /* Nuke the colon, advance to the name */
2553 /* Paranoia -- require a name */
2554 if (!*s) return (1);
2559 /* Verify information */
2560 if (i < error_idx) return (4);
2562 /* Verify information */
2563 if (i >= head->info_num) return (2);
2565 /* Save the index */
2568 /* Point at the "info" */
2571 /* Store the name */
2572 if (!add_name(&e_ptr->name, head, s)) return (7);
2576 /* There better be a current e_ptr */
2577 else if (!e_ptr) return (3);
2581 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2582 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2583 else if (buf[0] == 'E')
2588 else if (buf[0] == 'E')
2590 /* Acquire the Text */
2593 /* Store the name */
2594 if (!add_name(&e_ptr->name, head, s)) return (7);
2599 /* Process 'D' for "Description" */
2600 else if (buf[0] == 'D')
2602 /* Acquire the text */
2605 /* Store the text */
2606 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2611 /* Process 'X' for "Xtra" (one line only) */
2612 else if (buf[0] == 'X')
2616 /* Scan for the values */
2617 if (2 != sscanf(buf+2, "%d:%d",
2618 &slot, &rating)) return (1);
2620 /* Save the values */
2622 e_ptr->rating = rating;
2625 /* Process 'W' for "More Info" (one line only) */
2626 else if (buf[0] == 'W')
2628 int level, rarity, pad2;
2631 /* Scan for the values */
2632 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2633 &level, &rarity, &pad2, &cost)) return (1);
2635 /* Save the values */
2636 e_ptr->level = level;
2637 e_ptr->rarity = rarity;
2638 /* e_ptr->weight = wgt; */
2642 /* Hack -- Process 'C' for "creation" */
2643 else if (buf[0] == 'C')
2647 /* Scan for the values */
2648 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2649 &th, &td, &ta, &pv)) return (1);
2651 e_ptr->max_to_h = th;
2652 e_ptr->max_to_d = td;
2653 e_ptr->max_to_a = ta;
2654 e_ptr->max_pval = pv;
2657 /* Hack -- Process 'F' for flags */
2658 else if (buf[0] == 'F')
2660 /* Parse every entry textually */
2661 for (s = buf + 2; *s; )
2663 /* Find the end of this entry */
2664 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2666 /* Nuke and skip any dividers */
2670 while ((*t == ' ') || (*t == '|')) t++;
2673 /* Parse this entry */
2674 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2676 /* Start the next entry */
2690 * Grab one (basic) flag in a monster_race from a textual string
2692 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2694 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2697 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2700 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2703 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2706 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2709 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2712 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2717 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2719 msg_format("Unknown monster flag '%s'.", what);
2729 * Grab one (spell) flag in a monster_race from a textual string
2731 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2733 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2736 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2739 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2744 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2746 msg_format("Unknown monster flag '%s'.", what);
2758 * Initialize the "r_info" array, by parsing an ascii "template" file
2760 errr parse_r_info(char *buf, header *head)
2767 static monster_race *r_ptr = NULL;
2770 /* Process 'N' for "New/Number/Name" */
2773 /* Find the colon before the name */
2774 s = my_strchr(buf+2, ':');
2776 /* Verify that colon */
2779 /* Nuke the colon, advance to the name */
2782 /* Paranoia -- require a name */
2783 if (!*s) return (1);
2788 /* Verify information */
2789 if (i < error_idx) return (4);
2791 /* Verify information */
2792 if (i >= head->info_num) return (2);
2794 /* Save the index */
2797 /* Point at the "info" */
2800 /* Store the name */
2801 if (!add_name(&r_ptr->name, head, s)) return (7);
2805 /* There better be a current r_ptr */
2806 else if (!r_ptr) return (3);
2810 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2811 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2812 else if (buf[0] == 'E')
2814 /* Acquire the Text */
2817 /* Store the name */
2818 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2821 else if (buf[0] == 'E')
2823 /* Acquire the Text */
2826 /* Store the name */
2827 if (!add_name(&r_ptr->name, head, s)) return (7);
2830 /* Process 'D' for "Description" */
2831 else if (buf[0] == 'D')
2836 /* Acquire the text */
2841 /* Acquire the text */
2845 /* Store the text */
2846 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2849 /* Process 'G' for "Graphics" (one line only) */
2850 else if (buf[0] == 'G')
2856 if (buf[1] != ':') return (1);
2857 if (!buf[2]) return (1);
2858 if (buf[3] != ':') return (1);
2859 if (!buf[4]) return (1);
2861 /* Extract the char */
2864 /* Extract the attr */
2865 tmp = color_char_to_attr(buf[4]);
2868 if (tmp > 127) return (1);
2870 /* Save the values */
2871 r_ptr->d_char = sym;
2872 r_ptr->d_attr = tmp;
2875 /* Process 'I' for "Info" (one line only) */
2876 else if (buf[0] == 'I')
2878 int spd, hp1, hp2, aaf, ac, slp;
2880 /* Scan for the other values */
2881 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2882 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2884 /* Save the values */
2886 r_ptr->hdice = MAX(hp1, 1);
2887 r_ptr->hside = MAX(hp2, 1);
2893 /* Process 'W' for "More Info" (one line only) */
2894 else if (buf[0] == 'W')
2901 /* Scan for the values */
2902 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2903 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2905 /* Save the values */
2907 r_ptr->rarity = rar;
2910 r_ptr->next_exp = nextexp;
2911 r_ptr->next_r_idx = nextmon;
2914 /* Process 'B' for "Blows" (up to four lines) */
2915 else if (buf[0] == 'B')
2919 /* Find the next empty blow slot (if any) */
2920 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2922 /* Oops, no more slots */
2923 if (i == 4) return (1);
2925 /* Analyze the first field */
2926 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2928 /* Terminate the field (if necessary) */
2929 if (*t == ':') *t++ = '\0';
2931 /* Analyze the method */
2932 for (n1 = 0; r_info_blow_method[n1]; n1++)
2934 if (streq(s, r_info_blow_method[n1])) break;
2937 /* Invalid method */
2938 if (!r_info_blow_method[n1]) return (1);
2940 /* Analyze the second field */
2941 for (s = t; *t && (*t != ':'); t++) /* loop */;
2943 /* Terminate the field (if necessary) */
2944 if (*t == ':') *t++ = '\0';
2946 /* Analyze effect */
2947 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2949 if (streq(s, r_info_blow_effect[n2])) break;
2952 /* Invalid effect */
2953 if (!r_info_blow_effect[n2]) return (1);
2955 /* Analyze the third field */
2956 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2958 /* Terminate the field (if necessary) */
2959 if (*t == 'd') *t++ = '\0';
2961 /* Save the method */
2962 r_ptr->blow[i].method = n1;
2964 /* Save the effect */
2965 r_ptr->blow[i].effect = n2;
2967 /* Extract the damage dice and sides */
2968 r_ptr->blow[i].d_dice = atoi(s);
2969 r_ptr->blow[i].d_side = atoi(t);
2972 /* Process 'F' for "Basic Flags" (multiple lines) */
2973 else if (buf[0] == 'F')
2975 /* Parse every entry */
2976 for (s = buf + 2; *s; )
2978 /* Find the end of this entry */
2979 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2981 /* Nuke and skip any dividers */
2985 while (*t == ' ' || *t == '|') t++;
2988 /* Parse this entry */
2989 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2991 /* Start the next entry */
2996 /* Process 'S' for "Spell Flags" (multiple lines) */
2997 else if (buf[0] == 'S')
2999 /* Parse every entry */
3000 for (s = buf + 2; *s; )
3002 /* Find the end of this entry */
3003 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3005 /* Nuke and skip any dividers */
3009 while ((*t == ' ') || (*t == '|')) t++;
3012 /* XXX XXX XXX Hack -- Read spell frequency */
3013 if (1 == sscanf(s, "1_IN_%d", &i))
3015 /* Extract a "frequency" */
3016 r_ptr->freq_spell = 100 / i;
3018 /* Start at next entry */
3025 /* Parse this entry */
3026 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3028 /* Start the next entry */
3043 * Grab one flag for a dungeon type from a textual string
3045 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3047 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3052 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3054 msg_format("Unknown dungeon type flag '%s'.", what);
3062 * Grab one (basic) flag in a monster_race from a textual string
3064 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3066 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3069 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3072 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3075 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3078 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3081 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3084 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3089 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3091 msg_format("Unknown monster flag '%s'.", what);
3099 * Grab one (spell) flag in a monster_race from a textual string
3101 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3103 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3106 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3109 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3114 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3116 msg_format("Unknown monster flag '%s'.", what);
3124 * Initialize the "d_info" array, by parsing an ascii "template" file
3126 errr parse_d_info(char *buf, header *head)
3133 static dungeon_info_type *d_ptr = NULL;
3136 /* Process 'N' for "New/Number/Name" */
3139 /* Find the colon before the name */
3140 s = my_strchr(buf+2, ':');
3142 /* Verify that colon */
3145 /* Nuke the colon, advance to the name */
3148 /* Paranoia -- require a name */
3149 if (!*s) return (1);
3154 /* Verify information */
3155 if (i < error_idx) return (4);
3157 /* Verify information */
3158 if (i >= head->info_num) return (2);
3160 /* Save the index */
3163 /* Point at the "info" */
3166 /* Store the name */
3167 if (!add_name(&d_ptr->name, head, s)) return (7);
3172 else if (buf[0] == 'E') return (0);
3174 else if (buf[0] == 'E')
3176 /* Acquire the Text */
3179 /* Store the name */
3180 if (!add_name(&d_ptr->name, head, s)) return (7);
3184 /* Process 'D' for "Description */
3185 else if (buf[0] == 'D')
3190 /* Acquire the text */
3195 /* Acquire the text */
3199 /* Store the text */
3200 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3203 /* Process 'W' for "More Info" (one line only) */
3204 else if (buf[0] == 'W')
3206 int min_lev, max_lev;
3208 int min_alloc, max_chance;
3209 int obj_good, obj_great;
3212 /* Scan for the values */
3213 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3214 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3216 /* Save the values */
3217 d_ptr->mindepth = min_lev;
3218 d_ptr->maxdepth = max_lev;
3219 d_ptr->min_plev = min_plev;
3221 d_ptr->min_m_alloc_level = min_alloc;
3222 d_ptr->max_m_alloc_chance = max_chance;
3223 d_ptr->obj_good = obj_good;
3224 d_ptr->obj_great = obj_great;
3229 /* Process 'P' for "Place Info" */
3230 else if (buf[0] == 'P')
3234 /* Scan for the values */
3235 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3237 /* Save the values */
3242 /* Process 'L' for "fLoor type" (one line only) */
3243 else if (buf[0] == 'L')
3247 /* Scan for the values */
3248 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3250 /* Save the values */
3251 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3253 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3254 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3256 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3258 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3261 /* Process 'A' for "wAll type" (one line only) */
3262 else if (buf[0] == 'A')
3266 /* Scan for the values */
3267 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3269 /* Save the values */
3270 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3272 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3273 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3275 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3278 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3279 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3281 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3282 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3284 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3285 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3287 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3288 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3291 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3292 else if (buf[0] == 'F')
3294 int artif = 0, monst = 0;
3296 /* Parse every entry */
3297 for (s = buf + 2; *s; )
3299 /* Find the end of this entry */
3300 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3302 /* Nuke and skip any dividers */
3306 while (*t == ' ' || *t == '|') t++;
3309 /* XXX XXX XXX Hack -- Read Final Artifact */
3310 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3312 /* Extract a "Final Artifact" */
3313 d_ptr->final_artifact = artif;
3315 /* Start at next entry */
3322 /* XXX XXX XXX Hack -- Read Final Object */
3323 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3325 /* Extract a "Final Artifact" */
3326 d_ptr->final_object = artif;
3328 /* Start at next entry */
3335 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3336 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3338 /* Extract a "Artifact Guardian" */
3339 d_ptr->final_guardian = monst;
3341 /* Start at next entry */
3348 /* XXX XXX XXX Hack -- Read Special Percentage */
3349 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3351 /* Extract a "Special %" */
3352 d_ptr->special_div = monst;
3354 /* Start at next entry */
3361 /* Parse this entry */
3362 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3364 /* Start the next entry */
3369 /* Process 'M' for "Basic Flags" (multiple lines) */
3370 else if (buf[0] == 'M')
3372 /* Parse every entry */
3373 for (s = buf + 2; *s; )
3375 /* Find the end of this entry */
3376 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3378 /* Nuke and skip any dividers */
3382 while (*t == ' ' || *t == '|') t++;
3385 /* Hack -- Read monster symbols */
3386 if (!strncmp(s, "R_CHAR_", 7))
3388 /* Skip "R_CHAR_" */
3392 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3394 /* Start at next entry */
3401 /* Parse this entry */
3402 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3404 /* Start the next entry */
3409 /* Process 'S' for "Spell Flags" (multiple lines) */
3410 else if (buf[0] == 'S')
3412 /* Parse every entry */
3413 for (s = buf + 2; *s; )
3415 /* Find the end of this entry */
3416 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3418 /* Nuke and skip any dividers */
3422 while ((*t == ' ') || (*t == '|')) t++;
3425 /* XXX XXX XXX Hack -- Read spell frequency */
3426 if (1 == sscanf(s, "1_IN_%d", &i))
3428 /* Start at next entry */
3435 /* Parse this entry */
3436 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3438 /* Start the next entry */
3451 #else /* ALLOW_TEMPLATES */
3457 #endif /* ALLOW_TEMPLATES */
3460 /* Random dungeon grid effects */
3461 #define RANDOM_NONE 0x00000000
3462 #define RANDOM_FEATURE 0x00000001
3463 #define RANDOM_MONSTER 0x00000002
3464 #define RANDOM_OBJECT 0x00000004
3465 #define RANDOM_EGO 0x00000008
3466 #define RANDOM_ARTIFACT 0x00000010
3467 #define RANDOM_TRAP 0x00000020
3470 typedef struct dungeon_grid dungeon_grid;
3474 int feature; /* Terrain feature */
3475 int monster; /* Monster */
3476 int object; /* Object */
3477 int ego; /* Ego-Item */
3478 int artifact; /* Artifact */
3479 int trap; /* Trap */
3480 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3481 int special; /* Reserved for special terrain info */
3482 int random; /* Number of the random effect */
3486 static dungeon_grid letter[255];
3490 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3492 static errr parse_line_feature(char *buf)
3498 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3500 /* Tokenize the line */
3501 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3503 /* Letter to assign */
3504 int index = zz[0][0];
3506 /* Reset the info for the letter */
3507 letter[index].feature = feat_none;
3508 letter[index].monster = 0;
3509 letter[index].object = 0;
3510 letter[index].ego = 0;
3511 letter[index].artifact = 0;
3512 letter[index].trap = feat_none;
3513 letter[index].cave_info = 0;
3514 letter[index].special = 0;
3515 letter[index].random = RANDOM_NONE;
3521 letter[index].special = atoi(zz[8]);
3525 if ((zz[7][0] == '*') && !zz[7][1])
3527 letter[index].random |= RANDOM_TRAP;
3531 letter[index].trap = f_tag_to_index(zz[7]);
3532 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3537 if (zz[6][0] == '*')
3539 letter[index].random |= RANDOM_ARTIFACT;
3540 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3542 else if (zz[6][0] == '!')
3544 if (p_ptr->inside_quest)
3546 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3551 letter[index].artifact = atoi(zz[6]);
3556 if (zz[5][0] == '*')
3558 letter[index].random |= RANDOM_EGO;
3559 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3563 letter[index].ego = atoi(zz[5]);
3568 if (zz[4][0] == '*')
3570 letter[index].random |= RANDOM_OBJECT;
3571 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3573 else if (zz[4][0] == '!')
3575 if (p_ptr->inside_quest)
3577 int a_idx = quest[p_ptr->inside_quest].k_idx;
3580 artifact_type *a_ptr = &a_info[a_idx];
3581 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3583 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3590 letter[index].object = atoi(zz[4]);
3595 if (zz[3][0] == '*')
3597 letter[index].random |= RANDOM_MONSTER;
3598 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3600 else if (zz[3][0] == 'c')
3602 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3603 letter[index].monster = - atoi(zz[3] + 1);
3607 letter[index].monster = atoi(zz[3]);
3612 letter[index].cave_info = atoi(zz[2]);
3616 if ((zz[1][0] == '*') && !zz[1][1])
3618 letter[index].random |= RANDOM_FEATURE;
3622 letter[index].feature = f_tag_to_index(zz[1]);
3623 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3636 * Process "B:<Index>:<Command>:..." -- Building definition
3638 static errr parse_line_building(char *buf)
3654 /* Get the building number */
3657 /* Find the colon after the building number */
3658 s = my_strchr(s, ':');
3660 /* Verify that colon */
3663 /* Nuke the colon, advance to the sub-index */
3666 /* Paranoia -- require a sub-index */
3667 if (!*s) return (1);
3669 /* Building definition sub-index */
3672 /* Building name, owner, race */
3675 if (tokenize(s + 2, 3, zz, 0) == 3)
3677 /* Name of the building */
3678 strcpy(building[index].name, zz[0]);
3680 /* Name of the owner */
3681 strcpy(building[index].owner_name, zz[1]);
3683 /* Race of the owner */
3684 strcpy(building[index].owner_race, zz[2]);
3689 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3692 /* Building Action */
3695 if (tokenize(s + 2, 8, zz, 0) >= 7)
3697 /* Index of the action */
3698 int action_index = atoi(zz[0]);
3700 /* Name of the action */
3701 strcpy(building[index].act_names[action_index], zz[1]);
3703 /* Cost of the action for members */
3704 building[index].member_costs[action_index] = atoi(zz[2]);
3706 /* Cost of the action for non-members */
3707 building[index].other_costs[action_index] = atoi(zz[3]);
3709 /* Letter assigned to the action */
3710 building[index].letters[action_index] = zz[4][0];
3713 building[index].actions[action_index] = atoi(zz[5]);
3715 /* Action restriction */
3716 building[index].action_restr[action_index] = atoi(zz[6]);
3721 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3724 /* Building Classes */
3727 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3729 for (i = 0; i < MAX_CLASS; i++)
3731 building[index].member_class[i] = atoi(zz[i]);
3737 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3740 /* Building Races */
3743 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3745 for (i = 0; i < MAX_RACES; i++)
3747 building[index].member_race[i] = atoi(zz[i]);
3753 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3756 /* Building Realms */
3759 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3761 for (i = 0; i < MAX_MAGIC; i++)
3763 building[index].member_realm[i+1] = atoi(zz[i]);
3769 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3774 /* Ignore scripts */
3780 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3789 * Place the object j_ptr to a grid
3791 static void drop_here(object_type *j_ptr, int y, int x)
3793 cave_type *c_ptr = &cave[y][x];
3796 /* Get new object */
3797 s16b o_idx = o_pop();
3799 /* Access new object */
3800 o_ptr = &o_list[o_idx];
3802 /* Structure copy */
3803 object_copy(o_ptr, j_ptr);
3811 o_ptr->held_m_idx = 0;
3814 o_ptr->next_o_idx = c_ptr->o_idx;
3816 /* Place the object */
3817 c_ptr->o_idx = o_idx;
3822 * Parse a sub-file of the "extra info"
3824 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3831 /* Skip "empty" lines */
3832 if (!buf[0]) return (0);
3834 /* Skip "blank" lines */
3835 if (isspace(buf[0])) return (0);
3838 if (buf[0] == '#') return (0);
3840 /* Require "?:*" format */
3841 if (buf[1] != ':') return (1);
3844 /* Process "%:<fname>" */
3847 /* Attempt to Process the given file */
3848 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3851 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3854 return parse_line_feature(buf);
3857 /* Process "D:<dungeon>" -- info for the cave grids */
3858 else if (buf[0] == 'D')
3860 object_type object_type_body;
3862 /* Acquire the text */
3865 /* Length of the text */
3866 int len = strlen(s);
3868 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3870 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3872 /* Access the grid */
3873 cave_type *c_ptr = &cave[*y][*x];
3877 int object_index = letter[idx].object;
3878 int monster_index = letter[idx].monster;
3879 int random = letter[idx].random;
3880 int artifact_index = letter[idx].artifact;
3882 /* Lay down a floor */
3883 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3885 /* Only the features */
3886 if (init_flags & INIT_ONLY_FEATURES) continue;
3889 c_ptr->info = letter[idx].cave_info;
3891 /* Create a monster */
3892 if (random & RANDOM_MONSTER)
3894 monster_level = base_level + monster_index;
3896 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3898 monster_level = base_level;
3900 else if (monster_index)
3902 int old_cur_num, old_max_num;
3905 if (monster_index < 0)
3907 monster_index = -monster_index;
3910 old_cur_num = r_info[monster_index].cur_num;
3911 old_max_num = r_info[monster_index].max_num;
3913 /* Make alive again */
3914 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3916 r_info[monster_index].cur_num = 0;
3917 r_info[monster_index].max_num = 1;
3920 /* Make alive again */
3921 /* Hack -- Non-unique Nazguls are semi-unique */
3922 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3924 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3926 r_info[monster_index].max_num++;
3931 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3935 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3937 /* Make alive again for real unique monster */
3938 r_info[monster_index].cur_num = old_cur_num;
3939 r_info[monster_index].max_num = old_max_num;
3943 /* Object (and possible trap) */
3944 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3946 object_level = base_level + object_index;
3949 * Random trap and random treasure defined
3950 * 25% chance for trap and 75% chance for object
3952 if (randint0(100) < 75)
3954 place_object(*y, *x, 0L);
3961 object_level = base_level;
3963 else if (random & RANDOM_OBJECT)
3965 object_level = base_level + object_index;
3967 /* Create an out of deep object */
3968 if (randint0(100) < 75)
3969 place_object(*y, *x, 0L);
3970 else if (randint0(100) < 80)
3971 place_object(*y, *x, AM_GOOD);
3973 place_object(*y, *x, AM_GOOD | AM_GREAT);
3975 object_level = base_level;
3978 else if (random & RANDOM_TRAP)
3982 /* Hidden trap (or door) */
3983 else if (letter[idx].trap)
3985 c_ptr->mimic = c_ptr->feat;
3986 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3988 else if (object_index)
3990 /* Get local object */
3991 object_type *o_ptr = &object_type_body;
3993 /* Create the item */
3994 object_prep(o_ptr, object_index);
3996 if (o_ptr->tval == TV_GOLD)
3998 coin_type = object_index - OBJ_GOLD_LIST;
4003 /* Apply magic (no messages, no artifacts) */
4004 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4006 drop_here(o_ptr, *y, *x);
4012 if (a_info[artifact_index].cur_num)
4014 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4016 object_type *q_ptr = &forge;
4018 object_prep(q_ptr, k_idx);
4020 /* Drop it in the dungeon */
4021 drop_here(q_ptr, *y, *x);
4025 /* Create the artifact */
4026 if (create_named_art(artifact_index, *y, *x))
4027 a_info[artifact_index].cur_num = 1;
4031 /* Terrain special */
4032 c_ptr->special = letter[idx].special;
4040 /* Process "Q:<number>:<command>:... -- quest info */
4041 else if (buf[0] == 'Q')
4048 num = tokenize(buf + 2, 33, zz, 0);
4052 num = tokenize(buf + 3, 33, zz, 0);
4055 /* Have we enough parameters? */
4056 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4059 q_ptr = &(quest[atoi(zz[0])]);
4061 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4062 if (zz[1][0] == 'Q')
4064 if (init_flags & INIT_ASSIGN)
4066 monster_race *r_ptr;
4067 artifact_type *a_ptr;
4069 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4071 q_ptr->type = atoi(zz[2]);
4072 q_ptr->num_mon = atoi(zz[3]);
4073 q_ptr->cur_num = atoi(zz[4]);
4074 q_ptr->max_num = atoi(zz[5]);
4075 q_ptr->level = atoi(zz[6]);
4076 q_ptr->r_idx = atoi(zz[7]);
4077 q_ptr->k_idx = atoi(zz[8]);
4078 q_ptr->dungeon = atoi(zz[9]);
4081 q_ptr->flags = atoi(zz[10]);
4083 r_ptr = &r_info[q_ptr->r_idx];
4084 if (r_ptr->flags1 & RF1_UNIQUE)
4085 r_ptr->flags1 |= RF1_QUESTOR;
4087 a_ptr = &a_info[q_ptr->k_idx];
4088 a_ptr->gen_flags |= TRG_QUESTITEM;
4093 else if (zz[1][0] == 'R')
4095 if (init_flags & INIT_ASSIGN)
4100 for (idx = 2; idx < num; idx++)
4102 int a_idx = atoi(zz[idx]);
4103 if (a_idx < 1) continue;
4104 if (a_info[a_idx].cur_num > 0) continue;
4106 if (one_in_(count)) reward_idx = a_idx;
4111 /* Set quest's rewarding artifact */
4112 q_ptr->k_idx = reward_idx;
4113 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4117 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4118 q_ptr->type = QUEST_TYPE_KILL_ALL;
4125 /* Process "Q:<q_index>:N:<name>" -- quest name */
4126 else if (zz[1][0] == 'N')
4128 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4130 strcpy(q_ptr->name, zz[2]);
4136 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4137 else if (zz[1][0] == 'T')
4139 if (init_flags & INIT_SHOW_TEXT)
4141 strcpy(quest_text[quest_text_line], zz[2]);
4149 /* Process "W:<command>: ..." -- info for the wilderness */
4150 else if (buf[0] == 'W')
4152 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4155 /* Process "P:<y>:<x>" -- player position */
4156 else if (buf[0] == 'P')
4158 if (init_flags & INIT_CREATE_DUNGEON)
4160 if (tokenize(buf + 2, 2, zz, 0) == 2)
4162 int panels_x, panels_y;
4164 /* Hack - Set the dungeon size */
4165 panels_y = (*y / SCREEN_HGT);
4166 if (*y % SCREEN_HGT) panels_y++;
4167 cur_hgt = panels_y * SCREEN_HGT;
4169 panels_x = (*x / SCREEN_WID);
4170 if (*x % SCREEN_WID) panels_x++;
4171 cur_wid = panels_x * SCREEN_WID;
4173 /* Assume illegal panel */
4174 panel_row_min = cur_hgt;
4175 panel_col_min = cur_wid;
4177 /* Place player in a quest level */
4178 if (p_ptr->inside_quest)
4182 /* Delete the monster (if any) */
4183 delete_monster(py, px);
4191 /* Place player in the town */
4192 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4194 p_ptr->oldpy = atoi(zz[0]);
4195 p_ptr->oldpx = atoi(zz[1]);
4203 /* Process "B:<Index>:<Command>:..." -- Building definition */
4204 else if (buf[0] == 'B')
4206 return parse_line_building(buf);
4209 /* Process "M:<type>:<maximum>" -- set maximum values */
4210 else if (buf[0] == 'M')
4212 if (tokenize(buf+2, 2, zz, 0) == 2)
4215 if (zz[0][0] == 'T')
4217 max_towns = atoi(zz[1]);
4220 /* Maximum quests */
4221 else if (zz[0][0] == 'Q')
4223 max_quests = atoi(zz[1]);
4227 else if (zz[0][0] == 'R')
4229 max_r_idx = atoi(zz[1]);
4233 else if (zz[0][0] == 'K')
4235 max_k_idx = atoi(zz[1]);
4239 else if (zz[0][0] == 'V')
4241 max_v_idx = atoi(zz[1]);
4245 else if (zz[0][0] == 'F')
4247 max_f_idx = atoi(zz[1]);
4251 else if (zz[0][0] == 'A')
4253 max_a_idx = atoi(zz[1]);
4257 else if (zz[0][0] == 'E')
4259 max_e_idx = atoi(zz[1]);
4263 else if (zz[0][0] == 'D')
4265 max_d_idx = atoi(zz[1]);
4269 else if (zz[0][0] == 'O')
4271 max_o_idx = atoi(zz[1]);
4275 else if (zz[0][0] == 'M')
4277 max_m_idx = atoi(zz[1]);
4280 /* Wilderness size */
4281 else if (zz[0][0] == 'W')
4283 /* Maximum wild_x_size */
4284 if (zz[0][1] == 'X')
4285 max_wild_x = atoi(zz[1]);
4286 /* Maximum wild_y_size */
4287 if (zz[0][1] == 'Y')
4288 max_wild_y = atoi(zz[1]);
4302 static cptr variant = "ZANGBAND";
4306 * Helper function for "process_dungeon_file()"
4308 static cptr process_dungeon_file_expr(char **sp, char *fp)
4324 while (isspace(*s)) s++;
4342 t = process_dungeon_file_expr(&s, &f);
4351 else if (streq(t, "IOR"))
4354 while (*s && (f != b2))
4356 t = process_dungeon_file_expr(&s, &f);
4357 if (*t && !streq(t, "0")) v = "1";
4362 else if (streq(t, "AND"))
4365 while (*s && (f != b2))
4367 t = process_dungeon_file_expr(&s, &f);
4368 if (*t && streq(t, "0")) v = "0";
4373 else if (streq(t, "NOT"))
4376 while (*s && (f != b2))
4378 t = process_dungeon_file_expr(&s, &f);
4379 if (*t && streq(t, "1")) v = "0";
4384 else if (streq(t, "EQU"))
4387 if (*s && (f != b2))
4389 t = process_dungeon_file_expr(&s, &f);
4391 while (*s && (f != b2))
4393 p = process_dungeon_file_expr(&s, &f);
4394 if (streq(t, p)) v = "1";
4399 else if (streq(t, "LEQ"))
4402 if (*s && (f != b2))
4404 t = process_dungeon_file_expr(&s, &f);
4406 while (*s && (f != b2))
4409 t = process_dungeon_file_expr(&s, &f);
4410 if (*t && atoi(p) > atoi(t)) v = "0";
4415 else if (streq(t, "GEQ"))
4418 if (*s && (f != b2))
4420 t = process_dungeon_file_expr(&s, &f);
4422 while (*s && (f != b2))
4425 t = process_dungeon_file_expr(&s, &f);
4427 /* Compare two numbers instead of string */
4428 if (*t && atoi(p) < atoi(t)) v = "0";
4435 while (*s && (f != b2))
4437 t = process_dungeon_file_expr(&s, &f);
4442 if (f != b2) v = "?x?x?";
4444 /* Extract final and Terminate */
4445 if ((f = *s) != '\0') *s++ = '\0';
4451 /* Accept all printables except spaces and brackets */
4453 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4455 if (iskanji(*s)) s++;
4459 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4462 /* Extract final and Terminate */
4463 if ((f = *s) != '\0') *s++ = '\0';
4469 if (streq(b+1, "SYS"))
4475 else if (streq(b+1, "GRAF"))
4480 else if (streq(b+1, "MONOCHROME"))
4489 else if (streq(b+1, "RACE"))
4492 v = rp_ptr->E_title;
4499 else if (streq(b+1, "CLASS"))
4502 v = cp_ptr->E_title;
4509 else if (streq(b+1, "REALM1"))
4512 v = E_realm_names[p_ptr->realm1];
4514 v = realm_names[p_ptr->realm1];
4519 else if (streq(b+1, "REALM2"))
4522 v = E_realm_names[p_ptr->realm2];
4524 v = realm_names[p_ptr->realm2];
4529 else if (streq(b+1, "PLAYER"))
4531 static char tmp_player_name[32];
4533 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4543 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4546 v = tmp_player_name;
4550 else if (streq(b+1, "TOWN"))
4552 sprintf(tmp, "%d", p_ptr->town_num);
4557 else if (streq(b+1, "LEVEL"))
4559 sprintf(tmp, "%d", p_ptr->lev);
4563 /* Current quest number */
4564 else if (streq(b+1, "QUEST_NUMBER"))
4566 sprintf(tmp, "%d", p_ptr->inside_quest);
4570 /* Number of last quest */
4571 else if (streq(b+1, "LEAVING_QUEST"))
4573 sprintf(tmp, "%d", leaving_quest);
4578 else if (prefix(b+1, "QUEST_TYPE"))
4580 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4581 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4586 else if (prefix(b+1, "QUEST"))
4588 /* "QUEST" uses a special parameter to determine the number of the quest */
4589 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4594 else if (prefix(b+1, "RANDOM"))
4596 /* "RANDOM" uses a special parameter to determine the number of the quest */
4597 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4602 else if (streq(b+1, "VARIANT"))
4608 else if (streq(b+1, "WILDERNESS"))
4611 sprintf(tmp, "NONE");
4613 sprintf(tmp, "LITE");
4615 sprintf(tmp, "NORMAL");
4638 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4648 bool bypass = FALSE;
4650 int x = xmin, y = ymin;
4653 /* Build the filename */
4654 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4657 fp = my_fopen(buf, "r");
4660 if (!fp) return (-1);
4663 /* Process the file */
4664 while (0 == my_fgets(fp, buf, sizeof(buf)))
4670 /* Skip "empty" lines */
4671 if (!buf[0]) continue;
4673 /* Skip "blank" lines */
4674 if (isspace(buf[0])) continue;
4677 if (buf[0] == '#') continue;
4680 /* Process "?:<expr>" */
4681 if ((buf[0] == '?') && (buf[1] == ':'))
4690 /* Parse the expr */
4691 v = process_dungeon_file_expr(&s, &f);
4694 bypass = (streq(v, "0") ? TRUE : FALSE);
4700 /* Apply conditionals */
4701 if (bypass) continue;
4703 /* Process the line */
4704 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4716 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4719 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4721 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4723 msg_format("Parsing '%s'.", buf);
4730 /* Close the file */
4740 void write_r_info_txt(void)
4742 int i, j, z, fc, bc;
4745 cptr flags[32 * 10];
4750 monster_race *r_ptr;
4752 monster_blow *b_ptr;
4754 FILE *fff = fopen("output.txt", "wt");
4762 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4764 fprintf(fff, "# Version stamp (required)\n\n");
4767 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4770 fprintf(fff, "##### The Player #####\n\n");
4772 for (z = -1; z < alloc_race_size; z++)
4774 /* Output the monsters in order */
4775 i = (z >= 0) ? alloc_race_table[z].index : 0;
4777 /* Acquire the monster */
4780 /* Ignore empty monsters */
4781 if (!strlen(r_name + r_ptr->name)) continue;
4783 /* Ignore useless monsters */
4784 if (i && !r_ptr->speed) continue;
4786 /* Write a note if necessary */
4787 if (i && (!r_ptr->level != !mode))
4792 fprintf(fff, "\n##### Town monsters #####\n\n");
4794 /* Note the dungeon */
4797 fprintf(fff, "\n##### Normal monsters #####\n\n");
4800 /* Record the change */
4801 mode = r_ptr->level;
4804 /* Acquire the flags */
4805 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4806 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4807 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4808 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4809 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4810 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4811 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4812 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4813 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4814 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4816 /* Write New/Number/Name */
4817 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4820 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4822 /* Write Information */
4823 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4824 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4826 /* Write more information */
4827 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4830 for(j = 0; j < 4; j++)
4832 b_ptr = &(r_ptr->blow[j]);
4834 /* Stop when done */
4835 if (!b_ptr->method) break;
4837 /* Write the blows */
4838 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4839 r_info_blow_effect[b_ptr->effect],
4840 b_ptr->d_dice, b_ptr->d_side);
4843 /* Extract the flags */
4844 for (fc = 0, j = 0; j < 32 * 3; j++)
4846 /* Check this flag */
4847 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4850 /* Extract the extra flags */
4851 for (j = 32 * 6; j < 32 * 10; j++)
4853 /* Check this flag */
4854 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4857 /* Write the flags */
4858 for (j = 0; j < fc;)
4862 /* Start the line */
4865 for (bc = 0; (bc < 60) && (j < fc); j++)
4869 /* Format the flag */
4870 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4872 /* Add it to the buffer */
4875 /* Note the length */
4879 /* Done with this line; write it */
4880 fprintf(fff, "%s\n", buf);
4883 /* Write Spells if applicable */
4884 if (r_ptr->freq_spell)
4886 /* Write the frequency */
4887 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4889 /* Extract the spell flags */
4890 for (fc = 0, j = 96; j < 192; j++)
4892 /* Check this flag */
4893 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4896 /* Write the flags */
4897 for (j = 0; j < fc;)
4901 /* Start the line */
4904 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4908 /* Format the flag */
4909 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4913 /* Note the length */
4920 /* Done with this line; write it */
4921 fprintf(fff, "%s\n", buf);
4925 /* Acquire the description */
4926 desc = r_text + r_ptr->text;
4927 dlen = strlen(desc);
4929 /* Write Description */
4930 for (j = 0; j < dlen;)
4934 /* Start the line */
4937 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4945 /* Done with this line; write it */
4946 fprintf(fff, "%s\n", buf);
4949 /* Space between entries */