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 },
858 { "BIZARRE", ACT_BIZARRE },
859 { "CAST_BA_STAR", ACT_CAST_BA_STAR },
860 { "BLADETURNER", ACT_BLADETURNER },
862 { "CONFUSE", ACT_CONFUSE },
863 { "SLEEP", ACT_SLEEP },
864 { "QUAKE", ACT_QUAKE },
865 { "TERROR", ACT_TERROR },
866 { "TELE_AWAY", ACT_TELE_AWAY },
867 { "BANISH_EVIL", ACT_BANISH_EVIL },
868 { "GENOCIDE", ACT_GENOCIDE },
869 { "MASS_GENO", ACT_MASS_GENO },
871 { "CHARM_ANIMAL", ACT_CHARM_ANIMAL },
872 { "CHARM_UNDEAD", ACT_CHARM_UNDEAD },
873 { "CHARM_OTHER", ACT_CHARM_OTHER },
874 { "CHARM_ANIMALS", ACT_CHARM_ANIMALS },
875 { "CHARM_OTHERS", ACT_CHARM_OTHERS },
876 { "SUMMON_ANIMAL", ACT_SUMMON_ANIMAL },
877 { "SUMMON_PHANTOM", ACT_SUMMON_PHANTOM },
878 { "SUMMON_ELEMENTAL", ACT_SUMMON_ELEMENTAL },
879 { "SUMMON_DEMON", ACT_SUMMON_DEMON },
880 { "SUMMON_UNDEAD", ACT_SUMMON_UNDEAD },
881 { "SUMMON_HOUND", ACT_SUMMON_HOUND },
882 { "SUMMON_DAWN", ACT_SUMMON_DAWN },
883 { "SUMMON_OCTOPUS", ACT_SUMMON_OCTOPUS },
885 { "CHOIR_SINGS", ACT_CHOIR_SINGS },
886 { "CURE_LW", ACT_CURE_LW },
887 { "CURE_MW", ACT_CURE_MW },
888 { "CURE_POISON", ACT_CURE_POISON },
889 { "REST_LIFE", ACT_REST_LIFE },
890 { "REST_ALL", ACT_REST_ALL },
891 { "CURE_700", ACT_CURE_700 },
892 { "CURE_1000", ACT_CURE_1000 },
893 { "CURING", ACT_CURING },
894 { "CURE_MANA_FULL", ACT_CURE_MANA_FULL },
897 { "BERSERK", ACT_BERSERK },
898 { "PROT_EVIL", ACT_PROT_EVIL },
899 { "RESIST_ALL", ACT_RESIST_ALL },
900 { "SPEED", ACT_SPEED },
901 { "XTRA_SPEED", ACT_XTRA_SPEED },
902 { "WRAITH", ACT_WRAITH },
903 { "INVULN", ACT_INVULN },
904 { "HELO", ACT_HELO },
905 { "HELO_SPEED", ACT_HELO_SPEED },
906 { "RESIST_ACID", ACT_RESIST_ACID },
907 { "RESIST_FIRE", ACT_RESIST_ACID },
908 { "RESIST_COLD", ACT_RESIST_ACID },
909 { "RESIST_ELEC", ACT_RESIST_ACID },
910 { "RESIST_POIS", ACT_RESIST_ACID },
912 { "LIGHT", ACT_LIGHT },
913 { "MAP_LIGHT", ACT_MAP_LIGHT },
914 { "DETECT_ALL", ACT_DETECT_ALL },
915 { "DETECT_XTRA", ACT_DETECT_XTRA },
916 { "ID_FULL", ACT_ID_FULL },
917 { "ID_PLAIN", ACT_ID_PLAIN },
918 { "RUNE_EXPLO", ACT_RUNE_EXPLO },
919 { "RUNE_PROT", ACT_RUNE_PROT },
920 { "SATIATE", ACT_SATIATE },
921 { "DEST_DOOR", ACT_DEST_DOOR },
922 { "STONE_MUD", ACT_STONE_MUD },
923 { "RECHARGE", ACT_RECHARGE },
924 { "ALCHEMY", ACT_ALCHEMY },
925 { "DIM_DOOR", ACT_DIM_DOOR },
926 { "TELEPORT", ACT_TELEPORT },
927 { "RECALL", ACT_RECALL },
928 { "JUDGE", ACT_JUDGE },
929 { "TELEKINESIS", ACT_TELEKINESIS },
930 { "DETECT_UNIQUE", ACT_DETECT_UNIQUE },
931 { "ESCAPE", ACT_ESCAPE },
932 { "DISP_CURSE_XTRA", ACT_DISP_CURSE_XTRA },
933 { "BRAND_FIRE_BOLTS", ACT_BRAND_FIRE_BOLTS },
934 { "RECHARGE_XTRA", ACT_RECHARGE_XTRA },
935 { "LORE", ACT_LORE },
936 { "SHIKOFUMI", ACT_SHIKOFUMI },
938 { "FISHING", ACT_FISHING },
946 static cptr d_info_flags1[] =
984 * Add a text to the text-storage and store offset to it.
986 * Returns FALSE when there isn't enough space available to store
989 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
991 /* Hack -- Verify space */
992 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
998 /* Advance and save the text index */
999 *offset = ++head->text_size;
1002 /* Additional text */
1003 else if (normal_text)
1006 * If neither the end of the last line nor
1007 * the beginning of current line is not a space,
1008 * fill up a space as a correct separator of two words.
1010 if (head->text_size > 0 &&
1012 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1013 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1014 (buf[0] != ' ') && !iskanji(buf[0])
1016 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1021 /* Append a space */
1022 *(head->text_ptr + head->text_size) = ' ';
1024 /* Advance the index */
1029 /* Append chars to the text */
1030 strcpy(head->text_ptr + head->text_size, buf);
1032 /* Advance the index */
1033 head->text_size += strlen(buf);
1041 * Add a name to the name-storage and return an offset to it.
1043 * Returns FALSE when there isn't enough space available to store
1046 static bool add_name(u32b *offset, header *head, cptr buf)
1048 /* Hack -- Verify space */
1049 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1055 /* Advance and save the name index */
1056 *offset = ++head->name_size;
1059 /* Append chars to the names */
1060 strcpy(head->name_ptr + head->name_size, buf);
1062 /* Advance the index */
1063 head->name_size += strlen(buf);
1071 * Add a tag to the tag-storage and return an offset to it.
1073 * Returns FALSE when there isn't enough space available to store
1076 static bool add_tag(s16b *offset, header *head, cptr buf)
1080 /* Search for an existing (fake) tag */
1081 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1084 if (streq(&head->tag_ptr[i], buf)) break;
1087 /* There was no existing tag */
1088 if (i >= head->tag_size)
1090 /* Hack -- Verify space */
1091 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1094 /* Append chars to the tags */
1095 strcpy(head->tag_ptr + head->tag_size, buf);
1097 /* Point the new tag */
1100 /* Advance the index */
1101 head->tag_size += strlen(buf) + 1;
1104 /* Return offset of the tag */
1113 * Convert a "color letter" into an "actual" color
1114 * The colors are: dwsorgbuDWvyRGBU, as shown below
1116 byte color_char_to_attr(char c)
1120 case 'd': return (TERM_DARK);
1121 case 'w': return (TERM_WHITE);
1122 case 's': return (TERM_SLATE);
1123 case 'o': return (TERM_ORANGE);
1124 case 'r': return (TERM_RED);
1125 case 'g': return (TERM_GREEN);
1126 case 'b': return (TERM_BLUE);
1127 case 'u': return (TERM_UMBER);
1129 case 'D': return (TERM_L_DARK);
1130 case 'W': return (TERM_L_WHITE);
1131 case 'v': return (TERM_VIOLET);
1132 case 'y': return (TERM_YELLOW);
1133 case 'R': return (TERM_L_RED);
1134 case 'G': return (TERM_L_GREEN);
1135 case 'B': return (TERM_L_BLUE);
1136 case 'U': return (TERM_L_UMBER);
1144 /*** Initialize from ascii template files ***/
1148 * Initialize an "*_info" array, by parsing an ascii "template" file
1150 errr init_info_txt(FILE *fp, char *buf, header *head,
1151 parse_info_txt_func parse_info_txt_line)
1155 /* Just before the first record */
1158 /* Just before the first line */
1162 /* Prepare the "fake" stuff */
1163 head->name_size = 0;
1164 head->text_size = 0;
1168 while (0 == my_fgets(fp, buf, 1024))
1170 /* Advance the line number */
1173 /* Skip comments and blank lines */
1174 if (!buf[0] || (buf[0] == '#')) continue;
1176 /* Verify correct "colon" format */
1177 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1180 /* Hack -- Process 'V' for "Version" */
1187 /* Mega Hack -- Calculate Check Sum */
1188 if (buf[0] != 'N' && buf[0] != 'D')
1191 for (i = 0; buf[i]; i++)
1193 head->v_extra += (byte)buf[i];
1194 head->v_extra ^= (1 << (i % 8));
1198 /* Parse the line */
1199 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1204 /* Complete the "name" and "text" sizes */
1205 if (head->name_size) head->name_size++;
1206 if (head->text_size) head->text_size++;
1214 * Initialize the "v_info" array, by parsing an ascii "template" file
1216 errr parse_v_info(char *buf, header *head)
1222 static vault_type *v_ptr = NULL;
1224 /* Process 'N' for "New/Number/Name" */
1227 /* Find the colon before the name */
1228 s = my_strchr(buf+2, ':');
1230 /* Verify that colon */
1233 /* Nuke the colon, advance to the name */
1236 /* Paranoia -- require a name */
1237 if (!*s) return (1);
1242 /* Verify information */
1243 if (i <= error_idx) return (4);
1245 /* Verify information */
1246 if (i >= head->info_num) return (2);
1248 /* Save the index */
1251 /* Point at the "info" */
1254 /* Store the name */
1255 if (!add_name(&v_ptr->name, head, s)) return (7);
1258 /* There better be a current v_ptr */
1259 else if (!v_ptr) return (3);
1261 /* Process 'D' for "Description" */
1262 else if (buf[0] == 'D')
1264 /* Acquire the text */
1267 /* Store the text */
1268 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1271 /* Process 'X' for "Extra info" (one line only) */
1272 else if (buf[0] == 'X')
1274 int typ, rat, hgt, wid;
1276 /* Scan for the values */
1277 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1278 &typ, &rat, &hgt, &wid)) return (1);
1280 /* Save the values */
1297 * Initialize the "s_info" array, by parsing an ascii "template" file
1299 errr parse_s_info(char *buf, header *head)
1304 static skill_table *s_ptr = NULL;
1307 /* Process 'N' for "New/Number/Name" */
1313 /* Verify information */
1314 if (i <= error_idx) return (4);
1316 /* Verify information */
1317 if (i >= head->info_num) return (2);
1319 /* Save the index */
1322 /* Point at the "info" */
1326 /* There better be a current s_ptr */
1327 else if (!s_ptr) return (3);
1329 /* Process 'W' for "Weapon exp" */
1330 else if (buf[0] == 'W')
1332 int tval, sval, start, max;
1333 const s16b exp_conv_table[] =
1335 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1336 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1339 /* Scan for the values */
1340 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1341 &tval, &sval, &start, &max)) return (1);
1343 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1344 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1346 /* Save the values */
1347 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1348 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1351 /* Process 'S' for "Skill exp" */
1352 else if (buf[0] == 'S')
1354 int num, start, max;
1356 /* Scan for the values */
1357 if (3 != sscanf(buf+2, "%d:%d:%d",
1358 &num, &start, &max)) return (1);
1360 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1361 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1363 /* Save the values */
1364 s_ptr->s_start[num] = start;
1365 s_ptr->s_max[num] = max;
1378 * Initialize the "m_info" array, by parsing an ascii "template" file
1380 errr parse_m_info(char *buf, header *head)
1387 static player_magic *m_ptr = NULL;
1390 static int realm, magic_idx = 0, readable = 0;
1393 /* Process 'N' for "New/Number/Name" */
1399 /* Verify information */
1400 if (i <= error_idx) return (4);
1402 /* Verify information */
1403 if (i >= head->info_num) return (2);
1405 /* Save the index */
1408 /* Point at the "info" */
1412 /* There better be a current m_ptr */
1413 else if (!m_ptr) return (3);
1415 /* Process 'I' for "Info" (one line only) */
1416 else if (buf[0] == 'I')
1419 int xtra, type, first, weight;
1421 /* Find the colon before the name */
1422 s = my_strchr(buf+2, ':');
1424 /* Verify that colon */
1427 /* Nuke the colon, advance to the name */
1432 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1433 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1434 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1435 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1436 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1441 /* Find the colon before the name */
1442 s = my_strchr(s, ':');
1444 /* Verify that colon */
1447 /* Nuke the colon, advance to the name */
1450 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1451 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1452 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1453 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1454 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1455 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1459 /* Scan for the values */
1460 if (4 != sscanf(s, "%x:%d:%d:%d",
1461 (uint *)&xtra, &type, &first, &weight)) return (1);
1463 m_ptr->spell_xtra = xtra;
1464 m_ptr->spell_type = type;
1465 m_ptr->spell_first = first;
1466 m_ptr->spell_weight = weight;
1470 /* Process 'R' for "Realm" (one line only) */
1471 else if (buf[0] == 'R')
1473 /* Scan for the values */
1474 if (2 != sscanf(buf+2, "%d:%d",
1475 &realm, &readable)) return (1);
1480 else if (buf[0] == 'T')
1482 int level, mana, fail, exp;
1484 if (!readable) return (1);
1485 /* Scan for the values */
1486 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1487 &level, &mana, &fail, &exp)) return (1);
1489 m_ptr->info[realm][magic_idx].slevel = level;
1490 m_ptr->info[realm][magic_idx].smana = mana;
1491 m_ptr->info[realm][magic_idx].sfail = fail;
1492 m_ptr->info[realm][magic_idx].sexp = exp;
1506 * Grab one flag from a textual string
1508 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1513 for (i = 0; i < 32; i++)
1515 if (streq(what, names[i]))
1517 *flags |= (1L << i);
1527 * Grab one flag in an feature_type from a textual string
1529 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1534 for (i = 0; i < FF_FLAG_MAX; i++)
1536 if (streq(what, f_info_flags[i]))
1538 add_flag(f_ptr->flags, i);
1545 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1547 msg_format("Unknown feature flag '%s'.", what);
1551 return PARSE_ERROR_GENERIC;
1556 * Grab an action in an feature_type from a textual string
1558 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1563 for (i = 0; i < FF_FLAG_MAX; i++)
1565 if (streq(what, f_info_flags[i]))
1567 f_ptr->state[count].action = i;
1574 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1576 msg_format("Unknown feature action '%s'.", what);
1580 return PARSE_ERROR_GENERIC;
1585 * Initialize the "f_info" array, by parsing an ascii "template" file
1587 errr parse_f_info(char *buf, header *head)
1594 static feature_type *f_ptr = NULL;
1597 /* Process 'N' for "New/Number/Name" */
1600 /* Find the colon before the name */
1601 s = my_strchr(buf+2, ':');
1605 /* Nuke the colon, advance to the name */
1612 /* Verify information */
1613 if (i <= error_idx) return (4);
1615 /* Verify information */
1616 if (i >= head->info_num) return (2);
1618 /* Save the index */
1621 /* Point at the "info" */
1624 /* Tag name is given */
1628 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1631 /* Default "mimic" */
1634 /* Default "destroyed state" -- if not specified */
1635 f_ptr->destroyed = i;
1637 /* Default "states" */
1638 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1641 /* There better be a current f_ptr */
1642 else if (!f_ptr) return (3);
1645 else if (buf[0] == 'J')
1647 /* Store the name */
1648 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1651 else if (buf[0] == 'E')
1653 /* Ignore english name */
1656 else if (buf[0] == 'J')
1658 /* Ignore Japanese name */
1661 else if (buf[0] == 'E')
1663 /* Acquire the Text */
1666 /* Store the name */
1667 if (!add_name(&f_ptr->name, head, s)) return (7);
1672 /* Process 'M' for "Mimic" (one line only) */
1673 else if (buf[0] == 'M')
1677 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1679 /* Record a fake tag index */
1680 f_ptr->mimic = -offset;
1684 /* Process 'G' for "Graphics" (one line only) */
1685 else if (buf[0] == 'G')
1689 char char_tmp[F_LIT_MAX];
1692 if (buf[1] != ':') return (1);
1693 if (!buf[2]) return (1);
1694 if (buf[3] != ':') return (1);
1695 if (!buf[4]) return (1);
1697 /* Extract the char */
1698 char_tmp[F_LIT_STANDARD] = buf[2];
1700 /* Extract the color */
1701 s_attr = color_char_to_attr(buf[4]);
1704 if (s_attr > 127) return (1);
1706 /* Save the standard values */
1707 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1708 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1710 /* Is this feature supports lighting? */
1713 /* G:c:a:LIT (default) */
1714 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1716 /* G:c:a:lc:la:dc:da */
1717 if (!streq(buf + 6, "LIT"))
1719 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1721 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1722 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1723 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1724 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1726 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1728 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1731 /* Use default lighting */
1734 /* No lighting support */
1735 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1738 /* Extract the color */
1739 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1740 if (f_ptr->d_attr[j] > 127) return 1;
1743 f_ptr->d_char[j] = char_tmp[j];
1749 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1751 f_ptr->d_attr[j] = s_attr;
1752 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1758 /* Hack -- Process 'F' for flags */
1759 else if (buf[0] == 'F')
1761 /* Parse every entry textually */
1762 for (s = buf + 2; *s; )
1764 /* Find the end of this entry */
1765 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1767 /* Nuke and skip any dividers */
1771 while (*t == ' ' || *t == '|') t++;
1774 /* XXX XXX XXX Hack -- Read feature subtype */
1775 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1777 /* Extract a "subtype" */
1780 /* Start at next entry */
1787 /* XXX XXX XXX Hack -- Read feature power */
1788 if (1 == sscanf(s, "POWER_%d", &i))
1790 /* Extract a "power" */
1793 /* Start at next entry */
1800 /* Parse this entry */
1801 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1803 /* Start the next entry */
1808 /* Process 'W' for "More Info" (one line only) */
1809 else if (buf[0] == 'W')
1813 /* Scan for the value */
1814 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1816 /* Save the value */
1817 f_ptr->priority = priority;
1820 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1821 else if (buf[0] == 'K')
1825 /* Find the next empty state slot (if any) */
1826 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1828 /* Oops, no more slots */
1829 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1831 /* Analyze the first field */
1832 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1834 /* Terminate the field (if necessary) */
1835 if (*t == ':') *t++ = '\0';
1837 /* Is this default entry? */
1838 if (streq(s, "DESTROYED"))
1840 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1842 /* Record a fake tag index */
1843 f_ptr->destroyed = -offset;
1848 f_ptr->state[i].action = 0;
1850 /* Parse this entry */
1851 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1853 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1855 /* Record a fake tag index */
1856 f_ptr->state[i].result = -offset;
1869 * Convert a fake tag to a real feat index
1871 s16b f_tag_to_index(cptr str)
1875 /* Search for real index corresponding to this fake tag */
1876 for (i = 0; i < f_head.info_num; i++)
1878 if (streq(f_tag + f_info[i].tag, str))
1880 /* Return the index */
1891 * Search for real index corresponding to this fake tag
1893 static void search_real_feat(s16b *feat)
1897 /* Don't convert non-fake tag */
1898 if (*feat >= 0) return;
1900 /* Search for real index corresponding to this fake tag */
1901 for (i = 0; i < f_head.info_num; i++)
1903 if ((-(*feat)) == f_info[i].tag)
1905 /* Record real index */
1913 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1915 msg_format("%s is undefined.", f_tag + (-(*feat)));
1921 * Retouch fake tags of f_info
1923 void retouch_f_info(header *head)
1927 /* Convert fake tags to real feat indices */
1928 for (i = 0; i < head->info_num; i++)
1930 feature_type *f_ptr = &f_info[i];
1933 search_real_feat(&f_ptr->mimic);
1935 search_real_feat(&f_ptr->destroyed);
1937 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1943 * Grab one flag in an object_kind from a textual string
1945 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1950 for (i = 0; i < TR_FLAG_MAX; i++)
1952 if (streq(what, k_info_flags[i]))
1954 add_flag(k_ptr->flags, i);
1959 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1964 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1966 msg_format("Unknown object flag '%s'.", what);
1976 * Initialize the "k_info" array, by parsing an ascii "template" file
1978 errr parse_k_info(char *buf, header *head)
1985 static object_kind *k_ptr = NULL;
1988 /* Process 'N' for "New/Number/Name" */
1995 /* Find the colon before the name */
1996 s = my_strchr(buf+2, ':');
1998 /* Verify that colon */
2001 /* Nuke the colon, advance to the name */
2007 /* Verify information */
2008 if (i <= error_idx) return (4);
2010 /* Verify information */
2011 if (i >= head->info_num) return (2);
2013 /* Save the index */
2016 /* Point at the "info" */
2020 /* Paranoia -- require a name */
2021 if (!*s) return (1);
2023 /* Find the colon before the flavor */
2024 flavor = my_strchr(s, ':');
2026 /* Verify that colon */
2029 /* Nuke the colon, advance to the flavor */
2032 /* Store the flavor */
2033 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2036 /* Store the name */
2037 if (!add_name(&k_ptr->name, head, s)) return (7);
2041 /* There better be a current k_ptr */
2042 else if (!k_ptr) return (3);
2046 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2047 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2048 else if (buf[0] == 'E')
2053 else if (buf[0] == 'E')
2057 /* Acquire the name */
2060 /* Find the colon before the flavor */
2061 flavor = my_strchr(s, ':');
2063 /* Verify that colon */
2066 /* Nuke the colon, advance to the flavor */
2069 /* Store the flavor */
2070 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2073 /* Store the name */
2074 if (!add_name(&k_ptr->name, head, s)) return (7);
2078 /* Process 'D' for "Description" */
2079 else if (buf[0] == 'D')
2084 /* Acquire the text */
2089 /* Acquire the text */
2093 /* Store the text */
2094 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2097 /* Process 'G' for "Graphics" (one line only) */
2098 else if (buf[0] == 'G')
2104 if (buf[1] != ':') return (1);
2105 if (!buf[2]) return (1);
2106 if (buf[3] != ':') return (1);
2107 if (!buf[4]) return (1);
2109 /* Extract the char */
2112 /* Extract the attr */
2113 tmp = color_char_to_attr(buf[4]);
2116 if (tmp > 127) return (1);
2118 /* Save the values */
2119 k_ptr->d_attr = tmp;
2120 k_ptr->d_char = sym;
2123 /* Process 'I' for "Info" (one line only) */
2124 else if (buf[0] == 'I')
2126 int tval, sval, pval;
2128 /* Scan for the values */
2129 if (3 != sscanf(buf+2, "%d:%d:%d",
2130 &tval, &sval, &pval)) return (1);
2132 /* Save the values */
2138 /* Process 'W' for "More Info" (one line only) */
2139 else if (buf[0] == 'W')
2141 int level, extra, wgt;
2144 /* Scan for the values */
2145 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2146 &level, &extra, &wgt, &cost)) return (1);
2148 /* Save the values */
2149 k_ptr->level = level;
2150 k_ptr->extra = extra;
2151 k_ptr->weight = wgt;
2155 /* Process 'A' for "Allocation" (one line only) */
2156 else if (buf[0] == 'A')
2160 /* XXX XXX XXX Simply read each number following a colon */
2161 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2163 /* Default chance */
2164 k_ptr->chance[i] = 1;
2166 /* Store the attack damage index */
2167 k_ptr->locale[i] = atoi(s+1);
2169 /* Find the slash */
2170 t = my_strchr(s+1, '/');
2172 /* Find the next colon */
2173 s = my_strchr(s+1, ':');
2175 /* If the slash is "nearby", use it */
2176 if (t && (!s || t < s))
2178 int chance = atoi(t+1);
2179 if (chance > 0) k_ptr->chance[i] = chance;
2184 /* Hack -- Process 'P' for "power" and such */
2185 else if (buf[0] == 'P')
2187 int ac, hd1, hd2, th, td, ta;
2189 /* Scan for the values */
2190 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2191 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2201 /* Hack -- Process 'F' for flags */
2202 else if (buf[0] == 'F')
2204 /* Parse every entry textually */
2205 for (s = buf + 2; *s; )
2207 /* Find the end of this entry */
2208 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2210 /* Nuke and skip any dividers */
2214 while (*t == ' ' || *t == '|') t++;
2217 /* Parse this entry */
2218 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2220 /* Start the next entry */
2236 * Grab one flag in an artifact_type from a textual string
2238 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2243 for (i = 0; i < TR_FLAG_MAX; i++)
2245 if (streq(what, k_info_flags[i]))
2247 add_flag(a_ptr->flags, i);
2252 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2257 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2259 msg_format("Unknown artifact flag '%s'.", what);
2268 * Grab one activation index flag
2270 static byte grab_one_activation_flag(cptr what)
2276 if (k_info_activation_flags[i].flag == NULL) break;
2278 if (streq(what, k_info_activation_flags[i].flag))
2280 return k_info_activation_flags[i].index;
2292 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
2294 msg_format("Unknown activation flag '%s'.", what);
2303 * Initialize the "a_info" array, by parsing an ascii "template" file
2305 errr parse_a_info(char *buf, header *head)
2312 static artifact_type *a_ptr = NULL;
2315 /* Process 'N' for "New/Number/Name" */
2318 /* Find the colon before the name */
2319 s = my_strchr(buf+2, ':');
2321 /* Verify that colon */
2324 /* Nuke the colon, advance to the name */
2327 /* Paranoia -- require a name */
2328 if (!*s) return (1);
2333 /* Verify information */
2334 if (i < error_idx) return (4);
2336 /* Verify information */
2337 if (i >= head->info_num) return (2);
2339 /* Save the index */
2342 /* Point at the "info" */
2345 /* Ignore everything */
2346 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2347 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2348 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2349 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2351 /* Store the name */
2352 if (!add_name(&a_ptr->name, head, s)) return (7);
2356 /* There better be a current a_ptr */
2357 else if (!a_ptr) return (3);
2361 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2362 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2363 else if (buf[0] == 'E')
2368 else if (buf[0] == 'E')
2370 /* Acquire the Text */
2373 /* Store the name */
2374 if (!add_name(&a_ptr->name, head, s)) return (7);
2378 /* Process 'D' for "Description" */
2379 else if (buf[0] == 'D')
2384 /* Acquire the text */
2389 /* Acquire the text */
2393 /* Store the text */
2394 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2398 /* Process 'I' for "Info" (one line only) */
2399 else if (buf[0] == 'I')
2401 int tval, sval, pval;
2403 /* Scan for the values */
2404 if (3 != sscanf(buf+2, "%d:%d:%d",
2405 &tval, &sval, &pval)) return (1);
2407 /* Save the values */
2413 /* Process 'W' for "More Info" (one line only) */
2414 else if (buf[0] == 'W')
2416 int level, rarity, wgt;
2419 /* Scan for the values */
2420 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2421 &level, &rarity, &wgt, &cost)) return (1);
2423 /* Save the values */
2424 a_ptr->level = level;
2425 a_ptr->rarity = rarity;
2426 a_ptr->weight = wgt;
2430 /* Hack -- Process 'P' for "power" and such */
2431 else if (buf[0] == 'P')
2433 int ac, hd1, hd2, th, td, ta;
2435 /* Scan for the values */
2436 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2437 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2447 /* Hack -- Process 'U' for activation index */
2448 else if (buf[0] == 'U')
2451 n = grab_one_activation_flag(buf + 2);
2462 /* Hack -- Process 'F' for flags */
2463 else if (buf[0] == 'F')
2465 /* Parse every entry textually */
2466 for (s = buf + 2; *s; )
2468 /* Find the end of this entry */
2469 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2471 /* Nuke and skip any dividers */
2475 while ((*t == ' ') || (*t == '|')) t++;
2478 /* Parse this entry */
2479 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2481 /* Start the next entry */
2497 * Grab one flag in a ego-item_type from a textual string
2499 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2504 for (i = 0; i < TR_FLAG_MAX; i++)
2506 if (streq(what, k_info_flags[i]))
2508 add_flag(e_ptr->flags, i);
2513 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2518 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2520 msg_format("Unknown ego-item flag '%s'.", what);
2532 * Initialize the "e_info" array, by parsing an ascii "template" file
2534 errr parse_e_info(char *buf, header *head)
2541 static ego_item_type *e_ptr = NULL;
2544 /* Just before the first record */
2547 /* Just before the first line */
2551 /* Process 'N' for "New/Number/Name" */
2554 /* Find the colon before the name */
2555 s = my_strchr(buf+2, ':');
2557 /* Verify that colon */
2560 /* Nuke the colon, advance to the name */
2563 /* Paranoia -- require a name */
2564 if (!*s) return (1);
2569 /* Verify information */
2570 if (i < error_idx) return (4);
2572 /* Verify information */
2573 if (i >= head->info_num) return (2);
2575 /* Save the index */
2578 /* Point at the "info" */
2581 /* Store the name */
2582 if (!add_name(&e_ptr->name, head, s)) return (7);
2586 /* There better be a current e_ptr */
2587 else if (!e_ptr) return (3);
2591 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2592 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2593 else if (buf[0] == 'E')
2598 else if (buf[0] == 'E')
2600 /* Acquire the Text */
2603 /* Store the name */
2604 if (!add_name(&e_ptr->name, head, s)) return (7);
2609 /* Process 'D' for "Description" */
2610 else if (buf[0] == 'D')
2612 /* Acquire the text */
2615 /* Store the text */
2616 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2621 /* Process 'X' for "Xtra" (one line only) */
2622 else if (buf[0] == 'X')
2626 /* Scan for the values */
2627 if (2 != sscanf(buf+2, "%d:%d",
2628 &slot, &rating)) return (1);
2630 /* Save the values */
2632 e_ptr->rating = rating;
2635 /* Process 'W' for "More Info" (one line only) */
2636 else if (buf[0] == 'W')
2638 int level, rarity, pad2;
2641 /* Scan for the values */
2642 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2643 &level, &rarity, &pad2, &cost)) return (1);
2645 /* Save the values */
2646 e_ptr->level = level;
2647 e_ptr->rarity = rarity;
2648 /* e_ptr->weight = wgt; */
2652 /* Hack -- Process 'C' for "creation" */
2653 else if (buf[0] == 'C')
2657 /* Scan for the values */
2658 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2659 &th, &td, &ta, &pv)) return (1);
2661 e_ptr->max_to_h = th;
2662 e_ptr->max_to_d = td;
2663 e_ptr->max_to_a = ta;
2664 e_ptr->max_pval = pv;
2667 /* Hack -- Process 'F' for flags */
2668 else if (buf[0] == 'F')
2670 /* Parse every entry textually */
2671 for (s = buf + 2; *s; )
2673 /* Find the end of this entry */
2674 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2676 /* Nuke and skip any dividers */
2680 while ((*t == ' ') || (*t == '|')) t++;
2683 /* Parse this entry */
2684 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2686 /* Start the next entry */
2700 * Grab one (basic) flag in a monster_race from a textual string
2702 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2704 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2707 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2710 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2713 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2716 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2719 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2722 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2727 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2729 msg_format("Unknown monster flag '%s'.", what);
2739 * Grab one (spell) flag in a monster_race from a textual string
2741 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2743 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2746 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2749 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2754 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2756 msg_format("Unknown monster flag '%s'.", what);
2768 * Initialize the "r_info" array, by parsing an ascii "template" file
2770 errr parse_r_info(char *buf, header *head)
2777 static monster_race *r_ptr = NULL;
2780 /* Process 'N' for "New/Number/Name" */
2783 /* Find the colon before the name */
2784 s = my_strchr(buf+2, ':');
2786 /* Verify that colon */
2789 /* Nuke the colon, advance to the name */
2792 /* Paranoia -- require a name */
2793 if (!*s) return (1);
2798 /* Verify information */
2799 if (i < error_idx) return (4);
2801 /* Verify information */
2802 if (i >= head->info_num) return (2);
2804 /* Save the index */
2807 /* Point at the "info" */
2810 /* Store the name */
2811 if (!add_name(&r_ptr->name, head, s)) return (7);
2815 /* There better be a current r_ptr */
2816 else if (!r_ptr) return (3);
2820 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2821 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2822 else if (buf[0] == 'E')
2824 /* Acquire the Text */
2827 /* Store the name */
2828 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2831 else if (buf[0] == 'E')
2833 /* Acquire the Text */
2836 /* Store the name */
2837 if (!add_name(&r_ptr->name, head, s)) return (7);
2840 /* Process 'D' for "Description" */
2841 else if (buf[0] == 'D')
2846 /* Acquire the text */
2851 /* Acquire the text */
2855 /* Store the text */
2856 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2859 /* Process 'G' for "Graphics" (one line only) */
2860 else if (buf[0] == 'G')
2866 if (buf[1] != ':') return (1);
2867 if (!buf[2]) return (1);
2868 if (buf[3] != ':') return (1);
2869 if (!buf[4]) return (1);
2871 /* Extract the char */
2874 /* Extract the attr */
2875 tmp = color_char_to_attr(buf[4]);
2878 if (tmp > 127) return (1);
2880 /* Save the values */
2881 r_ptr->d_char = sym;
2882 r_ptr->d_attr = tmp;
2885 /* Process 'I' for "Info" (one line only) */
2886 else if (buf[0] == 'I')
2888 int spd, hp1, hp2, aaf, ac, slp;
2890 /* Scan for the other values */
2891 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2892 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2894 /* Save the values */
2896 r_ptr->hdice = MAX(hp1, 1);
2897 r_ptr->hside = MAX(hp2, 1);
2903 /* Process 'W' for "More Info" (one line only) */
2904 else if (buf[0] == 'W')
2911 /* Scan for the values */
2912 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2913 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2915 /* Save the values */
2917 r_ptr->rarity = rar;
2920 r_ptr->next_exp = nextexp;
2921 r_ptr->next_r_idx = nextmon;
2924 /* Process 'B' for "Blows" (up to four lines) */
2925 else if (buf[0] == 'B')
2929 /* Find the next empty blow slot (if any) */
2930 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2932 /* Oops, no more slots */
2933 if (i == 4) return (1);
2935 /* Analyze the first field */
2936 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2938 /* Terminate the field (if necessary) */
2939 if (*t == ':') *t++ = '\0';
2941 /* Analyze the method */
2942 for (n1 = 0; r_info_blow_method[n1]; n1++)
2944 if (streq(s, r_info_blow_method[n1])) break;
2947 /* Invalid method */
2948 if (!r_info_blow_method[n1]) return (1);
2950 /* Analyze the second field */
2951 for (s = t; *t && (*t != ':'); t++) /* loop */;
2953 /* Terminate the field (if necessary) */
2954 if (*t == ':') *t++ = '\0';
2956 /* Analyze effect */
2957 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2959 if (streq(s, r_info_blow_effect[n2])) break;
2962 /* Invalid effect */
2963 if (!r_info_blow_effect[n2]) return (1);
2965 /* Analyze the third field */
2966 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2968 /* Terminate the field (if necessary) */
2969 if (*t == 'd') *t++ = '\0';
2971 /* Save the method */
2972 r_ptr->blow[i].method = n1;
2974 /* Save the effect */
2975 r_ptr->blow[i].effect = n2;
2977 /* Extract the damage dice and sides */
2978 r_ptr->blow[i].d_dice = atoi(s);
2979 r_ptr->blow[i].d_side = atoi(t);
2982 /* Process 'F' for "Basic Flags" (multiple lines) */
2983 else if (buf[0] == 'F')
2985 /* Parse every entry */
2986 for (s = buf + 2; *s; )
2988 /* Find the end of this entry */
2989 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2991 /* Nuke and skip any dividers */
2995 while (*t == ' ' || *t == '|') t++;
2998 /* Parse this entry */
2999 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3001 /* Start the next entry */
3006 /* Process 'S' for "Spell Flags" (multiple lines) */
3007 else if (buf[0] == 'S')
3009 /* Parse every entry */
3010 for (s = buf + 2; *s; )
3012 /* Find the end of this entry */
3013 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3015 /* Nuke and skip any dividers */
3019 while ((*t == ' ') || (*t == '|')) t++;
3022 /* XXX XXX XXX Hack -- Read spell frequency */
3023 if (1 == sscanf(s, "1_IN_%d", &i))
3025 /* Extract a "frequency" */
3026 r_ptr->freq_spell = 100 / i;
3028 /* Start at next entry */
3035 /* Parse this entry */
3036 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3038 /* Start the next entry */
3053 * Grab one flag for a dungeon type from a textual string
3055 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3057 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3062 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3064 msg_format("Unknown dungeon type flag '%s'.", what);
3072 * Grab one (basic) flag in a monster_race from a textual string
3074 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3076 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3079 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3082 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3085 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3088 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3091 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3094 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3099 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3101 msg_format("Unknown monster flag '%s'.", what);
3109 * Grab one (spell) flag in a monster_race from a textual string
3111 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3113 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3116 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3119 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3124 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3126 msg_format("Unknown monster flag '%s'.", what);
3134 * Initialize the "d_info" array, by parsing an ascii "template" file
3136 errr parse_d_info(char *buf, header *head)
3143 static dungeon_info_type *d_ptr = NULL;
3146 /* Process 'N' for "New/Number/Name" */
3149 /* Find the colon before the name */
3150 s = my_strchr(buf+2, ':');
3152 /* Verify that colon */
3155 /* Nuke the colon, advance to the name */
3158 /* Paranoia -- require a name */
3159 if (!*s) return (1);
3164 /* Verify information */
3165 if (i < error_idx) return (4);
3167 /* Verify information */
3168 if (i >= head->info_num) return (2);
3170 /* Save the index */
3173 /* Point at the "info" */
3176 /* Store the name */
3177 if (!add_name(&d_ptr->name, head, s)) return (7);
3182 else if (buf[0] == 'E') return (0);
3184 else if (buf[0] == 'E')
3186 /* Acquire the Text */
3189 /* Store the name */
3190 if (!add_name(&d_ptr->name, head, s)) return (7);
3194 /* Process 'D' for "Description */
3195 else if (buf[0] == 'D')
3200 /* Acquire the text */
3205 /* Acquire the text */
3209 /* Store the text */
3210 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3213 /* Process 'W' for "More Info" (one line only) */
3214 else if (buf[0] == 'W')
3216 int min_lev, max_lev;
3218 int min_alloc, max_chance;
3219 int obj_good, obj_great;
3222 /* Scan for the values */
3223 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3224 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3226 /* Save the values */
3227 d_ptr->mindepth = min_lev;
3228 d_ptr->maxdepth = max_lev;
3229 d_ptr->min_plev = min_plev;
3231 d_ptr->min_m_alloc_level = min_alloc;
3232 d_ptr->max_m_alloc_chance = max_chance;
3233 d_ptr->obj_good = obj_good;
3234 d_ptr->obj_great = obj_great;
3239 /* Process 'P' for "Place Info" */
3240 else if (buf[0] == 'P')
3244 /* Scan for the values */
3245 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3247 /* Save the values */
3252 /* Process 'L' for "fLoor type" (one line only) */
3253 else if (buf[0] == 'L')
3257 /* Scan for the values */
3258 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3260 /* Save the values */
3261 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3263 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3264 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3266 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3268 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3271 /* Process 'A' for "wAll type" (one line only) */
3272 else if (buf[0] == 'A')
3276 /* Scan for the values */
3277 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3279 /* Save the values */
3280 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3282 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3283 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3285 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3288 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3289 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3291 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3292 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3294 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3295 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3297 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3298 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3301 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3302 else if (buf[0] == 'F')
3304 int artif = 0, monst = 0;
3306 /* Parse every entry */
3307 for (s = buf + 2; *s; )
3309 /* Find the end of this entry */
3310 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3312 /* Nuke and skip any dividers */
3316 while (*t == ' ' || *t == '|') t++;
3319 /* XXX XXX XXX Hack -- Read Final Artifact */
3320 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3322 /* Extract a "Final Artifact" */
3323 d_ptr->final_artifact = artif;
3325 /* Start at next entry */
3332 /* XXX XXX XXX Hack -- Read Final Object */
3333 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3335 /* Extract a "Final Artifact" */
3336 d_ptr->final_object = artif;
3338 /* Start at next entry */
3345 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3346 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3348 /* Extract a "Artifact Guardian" */
3349 d_ptr->final_guardian = monst;
3351 /* Start at next entry */
3358 /* XXX XXX XXX Hack -- Read Special Percentage */
3359 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3361 /* Extract a "Special %" */
3362 d_ptr->special_div = monst;
3364 /* Start at next entry */
3371 /* Parse this entry */
3372 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3374 /* Start the next entry */
3379 /* Process 'M' for "Basic Flags" (multiple lines) */
3380 else if (buf[0] == 'M')
3382 /* Parse every entry */
3383 for (s = buf + 2; *s; )
3385 /* Find the end of this entry */
3386 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3388 /* Nuke and skip any dividers */
3392 while (*t == ' ' || *t == '|') t++;
3395 /* Hack -- Read monster symbols */
3396 if (!strncmp(s, "R_CHAR_", 7))
3398 /* Skip "R_CHAR_" */
3402 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3404 /* Start at next entry */
3411 /* Parse this entry */
3412 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3414 /* Start the next entry */
3419 /* Process 'S' for "Spell Flags" (multiple lines) */
3420 else if (buf[0] == 'S')
3422 /* Parse every entry */
3423 for (s = buf + 2; *s; )
3425 /* Find the end of this entry */
3426 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3428 /* Nuke and skip any dividers */
3432 while ((*t == ' ') || (*t == '|')) t++;
3435 /* XXX XXX XXX Hack -- Read spell frequency */
3436 if (1 == sscanf(s, "1_IN_%d", &i))
3438 /* Start at next entry */
3445 /* Parse this entry */
3446 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3448 /* Start the next entry */
3461 #else /* ALLOW_TEMPLATES */
3467 #endif /* ALLOW_TEMPLATES */
3470 /* Random dungeon grid effects */
3471 #define RANDOM_NONE 0x00000000
3472 #define RANDOM_FEATURE 0x00000001
3473 #define RANDOM_MONSTER 0x00000002
3474 #define RANDOM_OBJECT 0x00000004
3475 #define RANDOM_EGO 0x00000008
3476 #define RANDOM_ARTIFACT 0x00000010
3477 #define RANDOM_TRAP 0x00000020
3480 typedef struct dungeon_grid dungeon_grid;
3484 int feature; /* Terrain feature */
3485 int monster; /* Monster */
3486 int object; /* Object */
3487 int ego; /* Ego-Item */
3488 int artifact; /* Artifact */
3489 int trap; /* Trap */
3490 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3491 int special; /* Reserved for special terrain info */
3492 int random; /* Number of the random effect */
3496 static dungeon_grid letter[255];
3500 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3502 static errr parse_line_feature(char *buf)
3508 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3510 /* Tokenize the line */
3511 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3513 /* Letter to assign */
3514 int index = zz[0][0];
3516 /* Reset the info for the letter */
3517 letter[index].feature = feat_none;
3518 letter[index].monster = 0;
3519 letter[index].object = 0;
3520 letter[index].ego = 0;
3521 letter[index].artifact = 0;
3522 letter[index].trap = feat_none;
3523 letter[index].cave_info = 0;
3524 letter[index].special = 0;
3525 letter[index].random = RANDOM_NONE;
3531 letter[index].special = atoi(zz[8]);
3535 if ((zz[7][0] == '*') && !zz[7][1])
3537 letter[index].random |= RANDOM_TRAP;
3541 letter[index].trap = f_tag_to_index(zz[7]);
3542 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3547 if (zz[6][0] == '*')
3549 letter[index].random |= RANDOM_ARTIFACT;
3550 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3552 else if (zz[6][0] == '!')
3554 if (p_ptr->inside_quest)
3556 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3561 letter[index].artifact = atoi(zz[6]);
3566 if (zz[5][0] == '*')
3568 letter[index].random |= RANDOM_EGO;
3569 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3573 letter[index].ego = atoi(zz[5]);
3578 if (zz[4][0] == '*')
3580 letter[index].random |= RANDOM_OBJECT;
3581 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3583 else if (zz[4][0] == '!')
3585 if (p_ptr->inside_quest)
3587 int a_idx = quest[p_ptr->inside_quest].k_idx;
3590 artifact_type *a_ptr = &a_info[a_idx];
3591 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3593 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3600 letter[index].object = atoi(zz[4]);
3605 if (zz[3][0] == '*')
3607 letter[index].random |= RANDOM_MONSTER;
3608 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3610 else if (zz[3][0] == 'c')
3612 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3613 letter[index].monster = - atoi(zz[3] + 1);
3617 letter[index].monster = atoi(zz[3]);
3622 letter[index].cave_info = atoi(zz[2]);
3626 if ((zz[1][0] == '*') && !zz[1][1])
3628 letter[index].random |= RANDOM_FEATURE;
3632 letter[index].feature = f_tag_to_index(zz[1]);
3633 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3646 * Process "B:<Index>:<Command>:..." -- Building definition
3648 static errr parse_line_building(char *buf)
3664 /* Get the building number */
3667 /* Find the colon after the building number */
3668 s = my_strchr(s, ':');
3670 /* Verify that colon */
3673 /* Nuke the colon, advance to the sub-index */
3676 /* Paranoia -- require a sub-index */
3677 if (!*s) return (1);
3679 /* Building definition sub-index */
3682 /* Building name, owner, race */
3685 if (tokenize(s + 2, 3, zz, 0) == 3)
3687 /* Name of the building */
3688 strcpy(building[index].name, zz[0]);
3690 /* Name of the owner */
3691 strcpy(building[index].owner_name, zz[1]);
3693 /* Race of the owner */
3694 strcpy(building[index].owner_race, zz[2]);
3699 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3702 /* Building Action */
3705 if (tokenize(s + 2, 8, zz, 0) >= 7)
3707 /* Index of the action */
3708 int action_index = atoi(zz[0]);
3710 /* Name of the action */
3711 strcpy(building[index].act_names[action_index], zz[1]);
3713 /* Cost of the action for members */
3714 building[index].member_costs[action_index] = atoi(zz[2]);
3716 /* Cost of the action for non-members */
3717 building[index].other_costs[action_index] = atoi(zz[3]);
3719 /* Letter assigned to the action */
3720 building[index].letters[action_index] = zz[4][0];
3723 building[index].actions[action_index] = atoi(zz[5]);
3725 /* Action restriction */
3726 building[index].action_restr[action_index] = atoi(zz[6]);
3731 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3734 /* Building Classes */
3737 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3739 for (i = 0; i < MAX_CLASS; i++)
3741 building[index].member_class[i] = atoi(zz[i]);
3747 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3750 /* Building Races */
3753 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3755 for (i = 0; i < MAX_RACES; i++)
3757 building[index].member_race[i] = atoi(zz[i]);
3763 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3766 /* Building Realms */
3769 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3771 for (i = 0; i < MAX_MAGIC; i++)
3773 building[index].member_realm[i+1] = atoi(zz[i]);
3779 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3784 /* Ignore scripts */
3790 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3799 * Place the object j_ptr to a grid
3801 static void drop_here(object_type *j_ptr, int y, int x)
3803 cave_type *c_ptr = &cave[y][x];
3806 /* Get new object */
3807 s16b o_idx = o_pop();
3809 /* Access new object */
3810 o_ptr = &o_list[o_idx];
3812 /* Structure copy */
3813 object_copy(o_ptr, j_ptr);
3821 o_ptr->held_m_idx = 0;
3824 o_ptr->next_o_idx = c_ptr->o_idx;
3826 /* Place the object */
3827 c_ptr->o_idx = o_idx;
3832 * Parse a sub-file of the "extra info"
3834 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3841 /* Skip "empty" lines */
3842 if (!buf[0]) return (0);
3844 /* Skip "blank" lines */
3845 if (isspace(buf[0])) return (0);
3848 if (buf[0] == '#') return (0);
3850 /* Require "?:*" format */
3851 if (buf[1] != ':') return (1);
3854 /* Process "%:<fname>" */
3857 /* Attempt to Process the given file */
3858 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3861 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3864 return parse_line_feature(buf);
3867 /* Process "D:<dungeon>" -- info for the cave grids */
3868 else if (buf[0] == 'D')
3870 object_type object_type_body;
3872 /* Acquire the text */
3875 /* Length of the text */
3876 int len = strlen(s);
3878 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3880 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3882 /* Access the grid */
3883 cave_type *c_ptr = &cave[*y][*x];
3887 int object_index = letter[idx].object;
3888 int monster_index = letter[idx].monster;
3889 int random = letter[idx].random;
3890 int artifact_index = letter[idx].artifact;
3892 /* Lay down a floor */
3893 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3895 /* Only the features */
3896 if (init_flags & INIT_ONLY_FEATURES) continue;
3899 c_ptr->info = letter[idx].cave_info;
3901 /* Create a monster */
3902 if (random & RANDOM_MONSTER)
3904 monster_level = base_level + monster_index;
3906 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3908 monster_level = base_level;
3910 else if (monster_index)
3912 int old_cur_num, old_max_num;
3915 if (monster_index < 0)
3917 monster_index = -monster_index;
3920 old_cur_num = r_info[monster_index].cur_num;
3921 old_max_num = r_info[monster_index].max_num;
3923 /* Make alive again */
3924 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3926 r_info[monster_index].cur_num = 0;
3927 r_info[monster_index].max_num = 1;
3930 /* Make alive again */
3931 /* Hack -- Non-unique Nazguls are semi-unique */
3932 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3934 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3936 r_info[monster_index].max_num++;
3941 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3945 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3947 /* Make alive again for real unique monster */
3948 r_info[monster_index].cur_num = old_cur_num;
3949 r_info[monster_index].max_num = old_max_num;
3953 /* Object (and possible trap) */
3954 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3956 object_level = base_level + object_index;
3959 * Random trap and random treasure defined
3960 * 25% chance for trap and 75% chance for object
3962 if (randint0(100) < 75)
3964 place_object(*y, *x, 0L);
3971 object_level = base_level;
3973 else if (random & RANDOM_OBJECT)
3975 object_level = base_level + object_index;
3977 /* Create an out of deep object */
3978 if (randint0(100) < 75)
3979 place_object(*y, *x, 0L);
3980 else if (randint0(100) < 80)
3981 place_object(*y, *x, AM_GOOD);
3983 place_object(*y, *x, AM_GOOD | AM_GREAT);
3985 object_level = base_level;
3988 else if (random & RANDOM_TRAP)
3992 /* Hidden trap (or door) */
3993 else if (letter[idx].trap)
3995 c_ptr->mimic = c_ptr->feat;
3996 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
3998 else if (object_index)
4000 /* Get local object */
4001 object_type *o_ptr = &object_type_body;
4003 /* Create the item */
4004 object_prep(o_ptr, object_index);
4006 if (o_ptr->tval == TV_GOLD)
4008 coin_type = object_index - OBJ_GOLD_LIST;
4013 /* Apply magic (no messages, no artifacts) */
4014 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4016 drop_here(o_ptr, *y, *x);
4022 if (a_info[artifact_index].cur_num)
4024 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4026 object_type *q_ptr = &forge;
4028 object_prep(q_ptr, k_idx);
4030 /* Drop it in the dungeon */
4031 drop_here(q_ptr, *y, *x);
4035 /* Create the artifact */
4036 if (create_named_art(artifact_index, *y, *x))
4037 a_info[artifact_index].cur_num = 1;
4041 /* Terrain special */
4042 c_ptr->special = letter[idx].special;
4050 /* Process "Q:<number>:<command>:... -- quest info */
4051 else if (buf[0] == 'Q')
4058 num = tokenize(buf + 2, 33, zz, 0);
4062 num = tokenize(buf + 3, 33, zz, 0);
4065 /* Have we enough parameters? */
4066 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4069 q_ptr = &(quest[atoi(zz[0])]);
4071 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4072 if (zz[1][0] == 'Q')
4074 if (init_flags & INIT_ASSIGN)
4076 monster_race *r_ptr;
4077 artifact_type *a_ptr;
4079 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4081 q_ptr->type = atoi(zz[2]);
4082 q_ptr->num_mon = atoi(zz[3]);
4083 q_ptr->cur_num = atoi(zz[4]);
4084 q_ptr->max_num = atoi(zz[5]);
4085 q_ptr->level = atoi(zz[6]);
4086 q_ptr->r_idx = atoi(zz[7]);
4087 q_ptr->k_idx = atoi(zz[8]);
4088 q_ptr->dungeon = atoi(zz[9]);
4091 q_ptr->flags = atoi(zz[10]);
4093 r_ptr = &r_info[q_ptr->r_idx];
4094 if (r_ptr->flags1 & RF1_UNIQUE)
4095 r_ptr->flags1 |= RF1_QUESTOR;
4097 a_ptr = &a_info[q_ptr->k_idx];
4098 a_ptr->gen_flags |= TRG_QUESTITEM;
4103 else if (zz[1][0] == 'R')
4105 if (init_flags & INIT_ASSIGN)
4110 for (idx = 2; idx < num; idx++)
4112 int a_idx = atoi(zz[idx]);
4113 if (a_idx < 1) continue;
4114 if (a_info[a_idx].cur_num > 0) continue;
4116 if (one_in_(count)) reward_idx = a_idx;
4121 /* Set quest's rewarding artifact */
4122 q_ptr->k_idx = reward_idx;
4123 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4127 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4128 q_ptr->type = QUEST_TYPE_KILL_ALL;
4135 /* Process "Q:<q_index>:N:<name>" -- quest name */
4136 else if (zz[1][0] == 'N')
4138 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4140 strcpy(q_ptr->name, zz[2]);
4146 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4147 else if (zz[1][0] == 'T')
4149 if (init_flags & INIT_SHOW_TEXT)
4151 strcpy(quest_text[quest_text_line], zz[2]);
4159 /* Process "W:<command>: ..." -- info for the wilderness */
4160 else if (buf[0] == 'W')
4162 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4165 /* Process "P:<y>:<x>" -- player position */
4166 else if (buf[0] == 'P')
4168 if (init_flags & INIT_CREATE_DUNGEON)
4170 if (tokenize(buf + 2, 2, zz, 0) == 2)
4172 int panels_x, panels_y;
4174 /* Hack - Set the dungeon size */
4175 panels_y = (*y / SCREEN_HGT);
4176 if (*y % SCREEN_HGT) panels_y++;
4177 cur_hgt = panels_y * SCREEN_HGT;
4179 panels_x = (*x / SCREEN_WID);
4180 if (*x % SCREEN_WID) panels_x++;
4181 cur_wid = panels_x * SCREEN_WID;
4183 /* Assume illegal panel */
4184 panel_row_min = cur_hgt;
4185 panel_col_min = cur_wid;
4187 /* Place player in a quest level */
4188 if (p_ptr->inside_quest)
4192 /* Delete the monster (if any) */
4193 delete_monster(py, px);
4201 /* Place player in the town */
4202 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4204 p_ptr->oldpy = atoi(zz[0]);
4205 p_ptr->oldpx = atoi(zz[1]);
4213 /* Process "B:<Index>:<Command>:..." -- Building definition */
4214 else if (buf[0] == 'B')
4216 return parse_line_building(buf);
4219 /* Process "M:<type>:<maximum>" -- set maximum values */
4220 else if (buf[0] == 'M')
4222 if (tokenize(buf+2, 2, zz, 0) == 2)
4225 if (zz[0][0] == 'T')
4227 max_towns = atoi(zz[1]);
4230 /* Maximum quests */
4231 else if (zz[0][0] == 'Q')
4233 max_quests = atoi(zz[1]);
4237 else if (zz[0][0] == 'R')
4239 max_r_idx = atoi(zz[1]);
4243 else if (zz[0][0] == 'K')
4245 max_k_idx = atoi(zz[1]);
4249 else if (zz[0][0] == 'V')
4251 max_v_idx = atoi(zz[1]);
4255 else if (zz[0][0] == 'F')
4257 max_f_idx = atoi(zz[1]);
4261 else if (zz[0][0] == 'A')
4263 max_a_idx = atoi(zz[1]);
4267 else if (zz[0][0] == 'E')
4269 max_e_idx = atoi(zz[1]);
4273 else if (zz[0][0] == 'D')
4275 max_d_idx = atoi(zz[1]);
4279 else if (zz[0][0] == 'O')
4281 max_o_idx = atoi(zz[1]);
4285 else if (zz[0][0] == 'M')
4287 max_m_idx = atoi(zz[1]);
4290 /* Wilderness size */
4291 else if (zz[0][0] == 'W')
4293 /* Maximum wild_x_size */
4294 if (zz[0][1] == 'X')
4295 max_wild_x = atoi(zz[1]);
4296 /* Maximum wild_y_size */
4297 if (zz[0][1] == 'Y')
4298 max_wild_y = atoi(zz[1]);
4312 static cptr variant = "ZANGBAND";
4316 * Helper function for "process_dungeon_file()"
4318 static cptr process_dungeon_file_expr(char **sp, char *fp)
4334 while (isspace(*s)) s++;
4352 t = process_dungeon_file_expr(&s, &f);
4361 else if (streq(t, "IOR"))
4364 while (*s && (f != b2))
4366 t = process_dungeon_file_expr(&s, &f);
4367 if (*t && !streq(t, "0")) v = "1";
4372 else if (streq(t, "AND"))
4375 while (*s && (f != b2))
4377 t = process_dungeon_file_expr(&s, &f);
4378 if (*t && streq(t, "0")) v = "0";
4383 else if (streq(t, "NOT"))
4386 while (*s && (f != b2))
4388 t = process_dungeon_file_expr(&s, &f);
4389 if (*t && streq(t, "1")) v = "0";
4394 else if (streq(t, "EQU"))
4397 if (*s && (f != b2))
4399 t = process_dungeon_file_expr(&s, &f);
4401 while (*s && (f != b2))
4403 p = process_dungeon_file_expr(&s, &f);
4404 if (streq(t, p)) v = "1";
4409 else if (streq(t, "LEQ"))
4412 if (*s && (f != b2))
4414 t = process_dungeon_file_expr(&s, &f);
4416 while (*s && (f != b2))
4419 t = process_dungeon_file_expr(&s, &f);
4420 if (*t && atoi(p) > atoi(t)) v = "0";
4425 else if (streq(t, "GEQ"))
4428 if (*s && (f != b2))
4430 t = process_dungeon_file_expr(&s, &f);
4432 while (*s && (f != b2))
4435 t = process_dungeon_file_expr(&s, &f);
4437 /* Compare two numbers instead of string */
4438 if (*t && atoi(p) < atoi(t)) v = "0";
4445 while (*s && (f != b2))
4447 t = process_dungeon_file_expr(&s, &f);
4452 if (f != b2) v = "?x?x?";
4454 /* Extract final and Terminate */
4455 if ((f = *s) != '\0') *s++ = '\0';
4461 /* Accept all printables except spaces and brackets */
4463 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4465 if (iskanji(*s)) s++;
4469 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4472 /* Extract final and Terminate */
4473 if ((f = *s) != '\0') *s++ = '\0';
4479 if (streq(b+1, "SYS"))
4485 else if (streq(b+1, "GRAF"))
4490 else if (streq(b+1, "MONOCHROME"))
4499 else if (streq(b+1, "RACE"))
4502 v = rp_ptr->E_title;
4509 else if (streq(b+1, "CLASS"))
4512 v = cp_ptr->E_title;
4519 else if (streq(b+1, "REALM1"))
4522 v = E_realm_names[p_ptr->realm1];
4524 v = realm_names[p_ptr->realm1];
4529 else if (streq(b+1, "REALM2"))
4532 v = E_realm_names[p_ptr->realm2];
4534 v = realm_names[p_ptr->realm2];
4539 else if (streq(b+1, "PLAYER"))
4541 static char tmp_player_name[32];
4543 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4553 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4556 v = tmp_player_name;
4560 else if (streq(b+1, "TOWN"))
4562 sprintf(tmp, "%d", p_ptr->town_num);
4567 else if (streq(b+1, "LEVEL"))
4569 sprintf(tmp, "%d", p_ptr->lev);
4573 /* Current quest number */
4574 else if (streq(b+1, "QUEST_NUMBER"))
4576 sprintf(tmp, "%d", p_ptr->inside_quest);
4580 /* Number of last quest */
4581 else if (streq(b+1, "LEAVING_QUEST"))
4583 sprintf(tmp, "%d", leaving_quest);
4588 else if (prefix(b+1, "QUEST_TYPE"))
4590 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4591 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4596 else if (prefix(b+1, "QUEST"))
4598 /* "QUEST" uses a special parameter to determine the number of the quest */
4599 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4604 else if (prefix(b+1, "RANDOM"))
4606 /* "RANDOM" uses a special parameter to determine the number of the quest */
4607 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4612 else if (streq(b+1, "VARIANT"))
4618 else if (streq(b+1, "WILDERNESS"))
4621 sprintf(tmp, "NONE");
4623 sprintf(tmp, "LITE");
4625 sprintf(tmp, "NORMAL");
4648 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4658 bool bypass = FALSE;
4660 int x = xmin, y = ymin;
4663 /* Build the filename */
4664 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4667 fp = my_fopen(buf, "r");
4670 if (!fp) return (-1);
4673 /* Process the file */
4674 while (0 == my_fgets(fp, buf, sizeof(buf)))
4680 /* Skip "empty" lines */
4681 if (!buf[0]) continue;
4683 /* Skip "blank" lines */
4684 if (isspace(buf[0])) continue;
4687 if (buf[0] == '#') continue;
4690 /* Process "?:<expr>" */
4691 if ((buf[0] == '?') && (buf[1] == ':'))
4700 /* Parse the expr */
4701 v = process_dungeon_file_expr(&s, &f);
4704 bypass = (streq(v, "0") ? TRUE : FALSE);
4710 /* Apply conditionals */
4711 if (bypass) continue;
4713 /* Process the line */
4714 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4726 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4729 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4731 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4733 msg_format("Parsing '%s'.", buf);
4740 /* Close the file */
4750 void write_r_info_txt(void)
4752 int i, j, z, fc, bc;
4755 cptr flags[32 * 10];
4760 monster_race *r_ptr;
4762 monster_blow *b_ptr;
4764 FILE *fff = fopen("output.txt", "wt");
4772 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4774 fprintf(fff, "# Version stamp (required)\n\n");
4777 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4780 fprintf(fff, "##### The Player #####\n\n");
4782 for (z = -1; z < alloc_race_size; z++)
4784 /* Output the monsters in order */
4785 i = (z >= 0) ? alloc_race_table[z].index : 0;
4787 /* Acquire the monster */
4790 /* Ignore empty monsters */
4791 if (!strlen(r_name + r_ptr->name)) continue;
4793 /* Ignore useless monsters */
4794 if (i && !r_ptr->speed) continue;
4796 /* Write a note if necessary */
4797 if (i && (!r_ptr->level != !mode))
4802 fprintf(fff, "\n##### Town monsters #####\n\n");
4804 /* Note the dungeon */
4807 fprintf(fff, "\n##### Normal monsters #####\n\n");
4810 /* Record the change */
4811 mode = r_ptr->level;
4814 /* Acquire the flags */
4815 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4816 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4817 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4818 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4819 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4820 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4821 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4822 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4823 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4824 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4826 /* Write New/Number/Name */
4827 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4830 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4832 /* Write Information */
4833 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4834 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4836 /* Write more information */
4837 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4840 for(j = 0; j < 4; j++)
4842 b_ptr = &(r_ptr->blow[j]);
4844 /* Stop when done */
4845 if (!b_ptr->method) break;
4847 /* Write the blows */
4848 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4849 r_info_blow_effect[b_ptr->effect],
4850 b_ptr->d_dice, b_ptr->d_side);
4853 /* Extract the flags */
4854 for (fc = 0, j = 0; j < 32 * 3; j++)
4856 /* Check this flag */
4857 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4860 /* Extract the extra flags */
4861 for (j = 32 * 6; j < 32 * 10; j++)
4863 /* Check this flag */
4864 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4867 /* Write the flags */
4868 for (j = 0; j < fc;)
4872 /* Start the line */
4875 for (bc = 0; (bc < 60) && (j < fc); j++)
4879 /* Format the flag */
4880 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4882 /* Add it to the buffer */
4885 /* Note the length */
4889 /* Done with this line; write it */
4890 fprintf(fff, "%s\n", buf);
4893 /* Write Spells if applicable */
4894 if (r_ptr->freq_spell)
4896 /* Write the frequency */
4897 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4899 /* Extract the spell flags */
4900 for (fc = 0, j = 96; j < 192; j++)
4902 /* Check this flag */
4903 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4906 /* Write the flags */
4907 for (j = 0; j < fc;)
4911 /* Start the line */
4914 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4918 /* Format the flag */
4919 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4923 /* Note the length */
4930 /* Done with this line; write it */
4931 fprintf(fff, "%s\n", buf);
4935 /* Acquire the description */
4936 desc = r_text + r_ptr->text;
4937 dlen = strlen(desc);
4939 /* Write Description */
4940 for (j = 0; j < dlen;)
4944 /* Start the line */
4947 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4955 /* Done with this line; write it */
4956 fprintf(fff, "%s\n", buf);
4959 /* Space between entries */