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 },
870 { "SCARE_AREA", ACT_SCARE_AREA },
871 { "AGGRAVATE", ACT_AGGRAVATE },
873 { "CHARM_ANIMAL", ACT_CHARM_ANIMAL },
874 { "CHARM_UNDEAD", ACT_CHARM_UNDEAD },
875 { "CHARM_OTHER", ACT_CHARM_OTHER },
876 { "CHARM_ANIMALS", ACT_CHARM_ANIMALS },
877 { "CHARM_OTHERS", ACT_CHARM_OTHERS },
878 { "SUMMON_ANIMAL", ACT_SUMMON_ANIMAL },
879 { "SUMMON_PHANTOM", ACT_SUMMON_PHANTOM },
880 { "SUMMON_ELEMENTAL", ACT_SUMMON_ELEMENTAL },
881 { "SUMMON_DEMON", ACT_SUMMON_DEMON },
882 { "SUMMON_UNDEAD", ACT_SUMMON_UNDEAD },
883 { "SUMMON_HOUND", ACT_SUMMON_HOUND },
884 { "SUMMON_DAWN", ACT_SUMMON_DAWN },
885 { "SUMMON_OCTOPUS", ACT_SUMMON_OCTOPUS },
887 { "CHOIR_SINGS", ACT_CHOIR_SINGS },
888 { "CURE_LW", ACT_CURE_LW },
889 { "CURE_MW", ACT_CURE_MW },
890 { "CURE_POISON", ACT_CURE_POISON },
891 { "REST_LIFE", ACT_REST_LIFE },
892 { "REST_ALL", ACT_REST_ALL },
893 { "CURE_700", ACT_CURE_700 },
894 { "CURE_1000", ACT_CURE_1000 },
895 { "CURING", ACT_CURING },
896 { "CURE_MANA_FULL", ACT_CURE_MANA_FULL },
899 { "BERSERK", ACT_BERSERK },
900 { "PROT_EVIL", ACT_PROT_EVIL },
901 { "RESIST_ALL", ACT_RESIST_ALL },
902 { "SPEED", ACT_SPEED },
903 { "XTRA_SPEED", ACT_XTRA_SPEED },
904 { "WRAITH", ACT_WRAITH },
905 { "INVULN", ACT_INVULN },
906 { "HELO", ACT_HELO },
907 { "HELO_SPEED", ACT_HELO_SPEED },
908 { "RESIST_ACID", ACT_RESIST_ACID },
909 { "RESIST_FIRE", ACT_RESIST_ACID },
910 { "RESIST_COLD", ACT_RESIST_ACID },
911 { "RESIST_ELEC", ACT_RESIST_ACID },
912 { "RESIST_POIS", ACT_RESIST_ACID },
914 { "LIGHT", ACT_LIGHT },
915 { "MAP_LIGHT", ACT_MAP_LIGHT },
916 { "DETECT_ALL", ACT_DETECT_ALL },
917 { "DETECT_XTRA", ACT_DETECT_XTRA },
918 { "ID_FULL", ACT_ID_FULL },
919 { "ID_PLAIN", ACT_ID_PLAIN },
920 { "RUNE_EXPLO", ACT_RUNE_EXPLO },
921 { "RUNE_PROT", ACT_RUNE_PROT },
922 { "SATIATE", ACT_SATIATE },
923 { "DEST_DOOR", ACT_DEST_DOOR },
924 { "STONE_MUD", ACT_STONE_MUD },
925 { "RECHARGE", ACT_RECHARGE },
926 { "ALCHEMY", ACT_ALCHEMY },
927 { "DIM_DOOR", ACT_DIM_DOOR },
928 { "TELEPORT", ACT_TELEPORT },
929 { "RECALL", ACT_RECALL },
930 { "JUDGE", ACT_JUDGE },
931 { "TELEKINESIS", ACT_TELEKINESIS },
932 { "DETECT_UNIQUE", ACT_DETECT_UNIQUE },
933 { "ESCAPE", ACT_ESCAPE },
934 { "DISP_CURSE_XTRA", ACT_DISP_CURSE_XTRA },
935 { "BRAND_FIRE_BOLTS", ACT_BRAND_FIRE_BOLTS },
936 { "RECHARGE_XTRA", ACT_RECHARGE_XTRA },
937 { "LORE", ACT_LORE },
938 { "SHIKOFUMI", ACT_SHIKOFUMI },
940 { "FISHING", ACT_FISHING },
941 { "INROU", ACT_INROU },
942 { "MURAMASA", ACT_MURAMASA },
943 { "BLOODY_MOON", ACT_BLOODY_MOON },
944 { "CRIMSON", ACT_CRIMSON },
952 static cptr d_info_flags1[] =
990 * Add a text to the text-storage and store offset to it.
992 * Returns FALSE when there isn't enough space available to store
995 static bool add_text(u32b *offset, header *head, cptr buf, bool normal_text)
997 /* Hack -- Verify space */
998 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
1004 /* Advance and save the text index */
1005 *offset = ++head->text_size;
1008 /* Additional text */
1009 else if (normal_text)
1012 * If neither the end of the last line nor
1013 * the beginning of current line is not a space,
1014 * fill up a space as a correct separator of two words.
1016 if (head->text_size > 0 &&
1018 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1019 ((head->text_size == 1) || !iskanji(*(head->text_ptr + head->text_size - 2))) &&
1020 (buf[0] != ' ') && !iskanji(buf[0])
1022 (*(head->text_ptr + head->text_size - 1) != ' ') &&
1027 /* Append a space */
1028 *(head->text_ptr + head->text_size) = ' ';
1030 /* Advance the index */
1035 /* Append chars to the text */
1036 strcpy(head->text_ptr + head->text_size, buf);
1038 /* Advance the index */
1039 head->text_size += strlen(buf);
1047 * Add a name to the name-storage and return an offset to it.
1049 * Returns FALSE when there isn't enough space available to store
1052 static bool add_name(u32b *offset, header *head, cptr buf)
1054 /* Hack -- Verify space */
1055 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
1061 /* Advance and save the name index */
1062 *offset = ++head->name_size;
1065 /* Append chars to the names */
1066 strcpy(head->name_ptr + head->name_size, buf);
1068 /* Advance the index */
1069 head->name_size += strlen(buf);
1077 * Add a tag to the tag-storage and return an offset to it.
1079 * Returns FALSE when there isn't enough space available to store
1082 static bool add_tag(s16b *offset, header *head, cptr buf)
1086 /* Search for an existing (fake) tag */
1087 for (i = 1; i < head->tag_size; i += strlen(&head->tag_ptr[i]) + 1)
1090 if (streq(&head->tag_ptr[i], buf)) break;
1093 /* There was no existing tag */
1094 if (i >= head->tag_size)
1096 /* Hack -- Verify space */
1097 if (head->tag_size + strlen(buf) + 8 > FAKE_TAG_SIZE)
1100 /* Append chars to the tags */
1101 strcpy(head->tag_ptr + head->tag_size, buf);
1103 /* Point the new tag */
1106 /* Advance the index */
1107 head->tag_size += strlen(buf) + 1;
1110 /* Return offset of the tag */
1119 * Convert a "color letter" into an "actual" color
1120 * The colors are: dwsorgbuDWvyRGBU, as shown below
1122 byte color_char_to_attr(char c)
1126 case 'd': return (TERM_DARK);
1127 case 'w': return (TERM_WHITE);
1128 case 's': return (TERM_SLATE);
1129 case 'o': return (TERM_ORANGE);
1130 case 'r': return (TERM_RED);
1131 case 'g': return (TERM_GREEN);
1132 case 'b': return (TERM_BLUE);
1133 case 'u': return (TERM_UMBER);
1135 case 'D': return (TERM_L_DARK);
1136 case 'W': return (TERM_L_WHITE);
1137 case 'v': return (TERM_VIOLET);
1138 case 'y': return (TERM_YELLOW);
1139 case 'R': return (TERM_L_RED);
1140 case 'G': return (TERM_L_GREEN);
1141 case 'B': return (TERM_L_BLUE);
1142 case 'U': return (TERM_L_UMBER);
1150 /*** Initialize from ascii template files ***/
1154 * Initialize an "*_info" array, by parsing an ascii "template" file
1156 errr init_info_txt(FILE *fp, char *buf, header *head,
1157 parse_info_txt_func parse_info_txt_line)
1161 /* Just before the first record */
1164 /* Just before the first line */
1168 /* Prepare the "fake" stuff */
1169 head->name_size = 0;
1170 head->text_size = 0;
1174 while (0 == my_fgets(fp, buf, 1024))
1176 /* Advance the line number */
1179 /* Skip comments and blank lines */
1180 if (!buf[0] || (buf[0] == '#')) continue;
1182 /* Verify correct "colon" format */
1183 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
1186 /* Hack -- Process 'V' for "Version" */
1193 /* Mega Hack -- Calculate Check Sum */
1194 if (buf[0] != 'N' && buf[0] != 'D')
1197 for (i = 0; buf[i]; i++)
1199 head->v_extra += (byte)buf[i];
1200 head->v_extra ^= (1 << (i % 8));
1204 /* Parse the line */
1205 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
1210 /* Complete the "name" and "text" sizes */
1211 if (head->name_size) head->name_size++;
1212 if (head->text_size) head->text_size++;
1220 * Initialize the "v_info" array, by parsing an ascii "template" file
1222 errr parse_v_info(char *buf, header *head)
1228 static vault_type *v_ptr = NULL;
1230 /* Process 'N' for "New/Number/Name" */
1233 /* Find the colon before the name */
1234 s = my_strchr(buf+2, ':');
1236 /* Verify that colon */
1239 /* Nuke the colon, advance to the name */
1242 /* Paranoia -- require a name */
1243 if (!*s) return (1);
1248 /* Verify information */
1249 if (i <= error_idx) return (4);
1251 /* Verify information */
1252 if (i >= head->info_num) return (2);
1254 /* Save the index */
1257 /* Point at the "info" */
1260 /* Store the name */
1261 if (!add_name(&v_ptr->name, head, s)) return (7);
1264 /* There better be a current v_ptr */
1265 else if (!v_ptr) return (3);
1267 /* Process 'D' for "Description" */
1268 else if (buf[0] == 'D')
1270 /* Acquire the text */
1273 /* Store the text */
1274 if (!add_text(&v_ptr->text, head, s, FALSE)) return (7);
1277 /* Process 'X' for "Extra info" (one line only) */
1278 else if (buf[0] == 'X')
1280 int typ, rat, hgt, wid;
1282 /* Scan for the values */
1283 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1284 &typ, &rat, &hgt, &wid)) return (1);
1286 /* Save the values */
1303 * Initialize the "s_info" array, by parsing an ascii "template" file
1305 errr parse_s_info(char *buf, header *head)
1310 static skill_table *s_ptr = NULL;
1313 /* Process 'N' for "New/Number/Name" */
1319 /* Verify information */
1320 if (i <= error_idx) return (4);
1322 /* Verify information */
1323 if (i >= head->info_num) return (2);
1325 /* Save the index */
1328 /* Point at the "info" */
1332 /* There better be a current s_ptr */
1333 else if (!s_ptr) return (3);
1335 /* Process 'W' for "Weapon exp" */
1336 else if (buf[0] == 'W')
1338 int tval, sval, start, max;
1339 const s16b exp_conv_table[] =
1341 WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
1342 WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
1345 /* Scan for the values */
1346 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1347 &tval, &sval, &start, &max)) return (1);
1349 if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
1350 || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
1352 /* Save the values */
1353 s_ptr->w_start[tval][sval] = exp_conv_table[start];
1354 s_ptr->w_max[tval][sval] = exp_conv_table[max];
1357 /* Process 'S' for "Skill exp" */
1358 else if (buf[0] == 'S')
1360 int num, start, max;
1362 /* Scan for the values */
1363 if (3 != sscanf(buf+2, "%d:%d:%d",
1364 &num, &start, &max)) return (1);
1366 if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
1367 || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
1369 /* Save the values */
1370 s_ptr->s_start[num] = start;
1371 s_ptr->s_max[num] = max;
1384 * Initialize the "m_info" array, by parsing an ascii "template" file
1386 errr parse_m_info(char *buf, header *head)
1393 static player_magic *m_ptr = NULL;
1396 static int realm, magic_idx = 0, readable = 0;
1399 /* Process 'N' for "New/Number/Name" */
1405 /* Verify information */
1406 if (i <= error_idx) return (4);
1408 /* Verify information */
1409 if (i >= head->info_num) return (2);
1411 /* Save the index */
1414 /* Point at the "info" */
1418 /* There better be a current m_ptr */
1419 else if (!m_ptr) return (3);
1421 /* Process 'I' for "Info" (one line only) */
1422 else if (buf[0] == 'I')
1425 int xtra, type, first, weight;
1427 /* Find the colon before the name */
1428 s = my_strchr(buf+2, ':');
1430 /* Verify that colon */
1433 /* Nuke the colon, advance to the name */
1438 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1439 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1440 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1441 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1442 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1447 /* Find the colon before the name */
1448 s = my_strchr(s, ':');
1450 /* Verify that colon */
1453 /* Nuke the colon, advance to the name */
1456 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1457 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1458 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1459 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1460 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1461 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1465 /* Scan for the values */
1466 if (4 != sscanf(s, "%x:%d:%d:%d",
1467 (uint *)&xtra, &type, &first, &weight)) return (1);
1469 m_ptr->spell_xtra = xtra;
1470 m_ptr->spell_type = type;
1471 m_ptr->spell_first = first;
1472 m_ptr->spell_weight = weight;
1476 /* Process 'R' for "Realm" (one line only) */
1477 else if (buf[0] == 'R')
1479 /* Scan for the values */
1480 if (2 != sscanf(buf+2, "%d:%d",
1481 &realm, &readable)) return (1);
1486 else if (buf[0] == 'T')
1488 int level, mana, fail, exp;
1490 if (!readable) return (1);
1491 /* Scan for the values */
1492 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1493 &level, &mana, &fail, &exp)) return (1);
1495 m_ptr->info[realm][magic_idx].slevel = level;
1496 m_ptr->info[realm][magic_idx].smana = mana;
1497 m_ptr->info[realm][magic_idx].sfail = fail;
1498 m_ptr->info[realm][magic_idx].sexp = exp;
1512 * Grab one flag from a textual string
1514 static errr grab_one_flag(u32b *flags, cptr names[], cptr what)
1519 for (i = 0; i < 32; i++)
1521 if (streq(what, names[i]))
1523 *flags |= (1L << i);
1533 * Grab one flag in an feature_type from a textual string
1535 static errr grab_one_feat_flag(feature_type *f_ptr, cptr what)
1540 for (i = 0; i < FF_FLAG_MAX; i++)
1542 if (streq(what, f_info_flags[i]))
1544 add_flag(f_ptr->flags, i);
1551 msg_format("̤ÃΤÎÃÏ·Á¥Õ¥é¥° '%s'¡£", what);
1553 msg_format("Unknown feature flag '%s'.", what);
1557 return PARSE_ERROR_GENERIC;
1562 * Grab an action in an feature_type from a textual string
1564 static errr grab_one_feat_action(feature_type *f_ptr, cptr what, int count)
1569 for (i = 0; i < FF_FLAG_MAX; i++)
1571 if (streq(what, f_info_flags[i]))
1573 f_ptr->state[count].action = i;
1580 msg_format("̤ÃΤÎÃÏ·Á¥¢¥¯¥·¥ç¥ó '%s'¡£", what);
1582 msg_format("Unknown feature action '%s'.", what);
1586 return PARSE_ERROR_GENERIC;
1591 * Initialize the "f_info" array, by parsing an ascii "template" file
1593 errr parse_f_info(char *buf, header *head)
1600 static feature_type *f_ptr = NULL;
1603 /* Process 'N' for "New/Number/Name" */
1606 /* Find the colon before the name */
1607 s = my_strchr(buf+2, ':');
1611 /* Nuke the colon, advance to the name */
1618 /* Verify information */
1619 if (i <= error_idx) return (4);
1621 /* Verify information */
1622 if (i >= head->info_num) return (2);
1624 /* Save the index */
1627 /* Point at the "info" */
1630 /* Tag name is given */
1634 if (!add_tag(&f_ptr->tag, head, s)) return (7);
1637 /* Default "mimic" */
1640 /* Default "destroyed state" -- if not specified */
1641 f_ptr->destroyed = i;
1643 /* Default "states" */
1644 for (i = 0; i < MAX_FEAT_STATES; i++) f_ptr->state[i].action = FF_FLAG_MAX;
1647 /* There better be a current f_ptr */
1648 else if (!f_ptr) return (3);
1651 else if (buf[0] == 'J')
1653 /* Store the name */
1654 if (!add_name(&f_ptr->name, head, buf+2)) return (7);
1657 else if (buf[0] == 'E')
1659 /* Ignore english name */
1662 else if (buf[0] == 'J')
1664 /* Ignore Japanese name */
1667 else if (buf[0] == 'E')
1669 /* Acquire the Text */
1672 /* Store the name */
1673 if (!add_name(&f_ptr->name, head, s)) return (7);
1678 /* Process 'M' for "Mimic" (one line only) */
1679 else if (buf[0] == 'M')
1683 if (!add_tag(&offset, head, buf + 2)) return PARSE_ERROR_OUT_OF_MEMORY;
1685 /* Record a fake tag index */
1686 f_ptr->mimic = -offset;
1690 /* Process 'G' for "Graphics" (one line only) */
1691 else if (buf[0] == 'G')
1695 char char_tmp[F_LIT_MAX];
1698 if (buf[1] != ':') return (1);
1699 if (!buf[2]) return (1);
1700 if (buf[3] != ':') return (1);
1701 if (!buf[4]) return (1);
1703 /* Extract the char */
1704 char_tmp[F_LIT_STANDARD] = buf[2];
1706 /* Extract the color */
1707 s_attr = color_char_to_attr(buf[4]);
1710 if (s_attr > 127) return (1);
1712 /* Save the standard values */
1713 f_ptr->d_attr[F_LIT_STANDARD] = s_attr;
1714 f_ptr->d_char[F_LIT_STANDARD] = char_tmp[F_LIT_STANDARD];
1716 /* Is this feature supports lighting? */
1719 /* G:c:a:LIT (default) */
1720 apply_default_feat_lighting(f_ptr->d_attr, f_ptr->d_char);
1722 /* G:c:a:lc:la:dc:da */
1723 if (!streq(buf + 6, "LIT"))
1725 char attr_lite_tmp[F_LIT_MAX - F_LIT_NS_BEGIN];
1727 if ((F_LIT_MAX - F_LIT_NS_BEGIN) * 2 != sscanf(buf + 6, "%c:%c:%c:%c",
1728 &char_tmp[F_LIT_LITE], &attr_lite_tmp[F_LIT_LITE - F_LIT_NS_BEGIN],
1729 &char_tmp[F_LIT_DARK], &attr_lite_tmp[F_LIT_DARK - F_LIT_NS_BEGIN])) return 1;
1730 if (buf[F_LIT_MAX * 4 + 1]) return 1;
1732 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1734 switch (attr_lite_tmp[j - F_LIT_NS_BEGIN])
1737 /* Use default lighting */
1740 /* No lighting support */
1741 f_ptr->d_attr[j] = f_ptr->d_attr[F_LIT_STANDARD];
1744 /* Extract the color */
1745 f_ptr->d_attr[j] = color_char_to_attr(attr_lite_tmp[j - F_LIT_NS_BEGIN]);
1746 if (f_ptr->d_attr[j] > 127) return 1;
1749 f_ptr->d_char[j] = char_tmp[j];
1755 for (j = F_LIT_NS_BEGIN; j < F_LIT_MAX; j++)
1757 f_ptr->d_attr[j] = s_attr;
1758 f_ptr->d_char[j] = char_tmp[F_LIT_STANDARD];
1764 /* Hack -- Process 'F' for flags */
1765 else if (buf[0] == 'F')
1767 /* Parse every entry textually */
1768 for (s = buf + 2; *s; )
1770 /* Find the end of this entry */
1771 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1773 /* Nuke and skip any dividers */
1777 while (*t == ' ' || *t == '|') t++;
1780 /* XXX XXX XXX Hack -- Read feature subtype */
1781 if (1 == sscanf(s, "SUBTYPE_%d", &i))
1783 /* Extract a "subtype" */
1786 /* Start at next entry */
1793 /* XXX XXX XXX Hack -- Read feature power */
1794 if (1 == sscanf(s, "POWER_%d", &i))
1796 /* Extract a "power" */
1799 /* Start at next entry */
1806 /* Parse this entry */
1807 if (0 != grab_one_feat_flag(f_ptr, s)) return (PARSE_ERROR_INVALID_FLAG);
1809 /* Start the next entry */
1814 /* Process 'W' for "More Info" (one line only) */
1815 else if (buf[0] == 'W')
1819 /* Scan for the value */
1820 if (1 != sscanf(buf+2, "%d", &priority)) return (PARSE_ERROR_GENERIC);
1822 /* Save the value */
1823 f_ptr->priority = priority;
1826 /* Process 'K' for "States" (up to four lines + default (which cannot be last)) */
1827 else if (buf[0] == 'K')
1831 /* Find the next empty state slot (if any) */
1832 for (i = 0; i < MAX_FEAT_STATES; i++) if (f_ptr->state[i].action == FF_FLAG_MAX) break;
1834 /* Oops, no more slots */
1835 if (i == MAX_FEAT_STATES) return PARSE_ERROR_GENERIC;
1837 /* Analyze the first field */
1838 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
1840 /* Terminate the field (if necessary) */
1841 if (*t == ':') *t++ = '\0';
1843 /* Is this default entry? */
1844 if (streq(s, "DESTROYED"))
1846 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1848 /* Record a fake tag index */
1849 f_ptr->destroyed = -offset;
1854 f_ptr->state[i].action = 0;
1856 /* Parse this entry */
1857 if (0 != grab_one_feat_action(f_ptr, s, i)) return PARSE_ERROR_INVALID_FLAG;
1859 if (!add_tag(&offset, head, t)) return PARSE_ERROR_OUT_OF_MEMORY;
1861 /* Record a fake tag index */
1862 f_ptr->state[i].result = -offset;
1875 * Convert a fake tag to a real feat index
1877 s16b f_tag_to_index(cptr str)
1881 /* Search for real index corresponding to this fake tag */
1882 for (i = 0; i < f_head.info_num; i++)
1884 if (streq(f_tag + f_info[i].tag, str))
1886 /* Return the index */
1897 * Search for real index corresponding to this fake tag
1899 static void search_real_feat(s16b *feat)
1903 /* Don't convert non-fake tag */
1904 if (*feat >= 0) return;
1906 /* Search for real index corresponding to this fake tag */
1907 for (i = 0; i < f_head.info_num; i++)
1909 if ((-(*feat)) == f_info[i].tag)
1911 /* Record real index */
1919 msg_format("̤ÄêµÁ¤Î¥¿¥° '%s'¡£", f_tag + (-(*feat)));
1921 msg_format("%s is undefined.", f_tag + (-(*feat)));
1927 * Retouch fake tags of f_info
1929 void retouch_f_info(header *head)
1933 /* Convert fake tags to real feat indices */
1934 for (i = 0; i < head->info_num; i++)
1936 feature_type *f_ptr = &f_info[i];
1939 search_real_feat(&f_ptr->mimic);
1941 search_real_feat(&f_ptr->destroyed);
1943 for (j = 0; j < MAX_FEAT_STATES; j++) search_real_feat(&f_ptr->state[j].result);
1949 * Grab one flag in an object_kind from a textual string
1951 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1956 for (i = 0; i < TR_FLAG_MAX; i++)
1958 if (streq(what, k_info_flags[i]))
1960 add_flag(k_ptr->flags, i);
1965 if (grab_one_flag(&k_ptr->gen_flags, k_info_gen_flags, what) == 0)
1970 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1972 msg_format("Unknown object flag '%s'.", what);
1982 * Initialize the "k_info" array, by parsing an ascii "template" file
1984 errr parse_k_info(char *buf, header *head)
1991 static object_kind *k_ptr = NULL;
1994 /* Process 'N' for "New/Number/Name" */
2001 /* Find the colon before the name */
2002 s = my_strchr(buf+2, ':');
2004 /* Verify that colon */
2007 /* Nuke the colon, advance to the name */
2013 /* Verify information */
2014 if (i <= error_idx) return (4);
2016 /* Verify information */
2017 if (i >= head->info_num) return (2);
2019 /* Save the index */
2022 /* Point at the "info" */
2026 /* Paranoia -- require a name */
2027 if (!*s) return (1);
2029 /* Find the colon before the flavor */
2030 flavor = my_strchr(s, ':');
2032 /* Verify that colon */
2035 /* Nuke the colon, advance to the flavor */
2038 /* Store the flavor */
2039 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2042 /* Store the name */
2043 if (!add_name(&k_ptr->name, head, s)) return (7);
2047 /* There better be a current k_ptr */
2048 else if (!k_ptr) return (3);
2052 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2053 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2054 else if (buf[0] == 'E')
2059 else if (buf[0] == 'E')
2063 /* Acquire the name */
2066 /* Find the colon before the flavor */
2067 flavor = my_strchr(s, ':');
2069 /* Verify that colon */
2072 /* Nuke the colon, advance to the flavor */
2075 /* Store the flavor */
2076 if (!add_name(&k_ptr->flavor_name, head, flavor)) return (7);
2079 /* Store the name */
2080 if (!add_name(&k_ptr->name, head, s)) return (7);
2084 /* Process 'D' for "Description" */
2085 else if (buf[0] == 'D')
2090 /* Acquire the text */
2095 /* Acquire the text */
2099 /* Store the text */
2100 if (!add_text(&k_ptr->text, head, s, TRUE)) return (7);
2103 /* Process 'G' for "Graphics" (one line only) */
2104 else if (buf[0] == 'G')
2110 if (buf[1] != ':') return (1);
2111 if (!buf[2]) return (1);
2112 if (buf[3] != ':') return (1);
2113 if (!buf[4]) return (1);
2115 /* Extract the char */
2118 /* Extract the attr */
2119 tmp = color_char_to_attr(buf[4]);
2122 if (tmp > 127) return (1);
2124 /* Save the values */
2125 k_ptr->d_attr = tmp;
2126 k_ptr->d_char = sym;
2129 /* Process 'I' for "Info" (one line only) */
2130 else if (buf[0] == 'I')
2132 int tval, sval, pval;
2134 /* Scan for the values */
2135 if (3 != sscanf(buf+2, "%d:%d:%d",
2136 &tval, &sval, &pval)) return (1);
2138 /* Save the values */
2144 /* Process 'W' for "More Info" (one line only) */
2145 else if (buf[0] == 'W')
2147 int level, extra, wgt;
2150 /* Scan for the values */
2151 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2152 &level, &extra, &wgt, &cost)) return (1);
2154 /* Save the values */
2155 k_ptr->level = level;
2156 k_ptr->extra = extra;
2157 k_ptr->weight = wgt;
2161 /* Process 'A' for "Allocation" (one line only) */
2162 else if (buf[0] == 'A')
2166 /* XXX XXX XXX Simply read each number following a colon */
2167 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
2169 /* Default chance */
2170 k_ptr->chance[i] = 1;
2172 /* Store the attack damage index */
2173 k_ptr->locale[i] = atoi(s+1);
2175 /* Find the slash */
2176 t = my_strchr(s+1, '/');
2178 /* Find the next colon */
2179 s = my_strchr(s+1, ':');
2181 /* If the slash is "nearby", use it */
2182 if (t && (!s || t < s))
2184 int chance = atoi(t+1);
2185 if (chance > 0) k_ptr->chance[i] = chance;
2190 /* Hack -- Process 'P' for "power" and such */
2191 else if (buf[0] == 'P')
2193 int ac, hd1, hd2, th, td, ta;
2195 /* Scan for the values */
2196 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2197 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2207 /* Hack -- Process 'F' for flags */
2208 else if (buf[0] == 'F')
2210 /* Parse every entry textually */
2211 for (s = buf + 2; *s; )
2213 /* Find the end of this entry */
2214 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2216 /* Nuke and skip any dividers */
2220 while (*t == ' ' || *t == '|') t++;
2223 /* Parse this entry */
2224 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
2226 /* Start the next entry */
2242 * Grab one flag in an artifact_type from a textual string
2244 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
2249 for (i = 0; i < TR_FLAG_MAX; i++)
2251 if (streq(what, k_info_flags[i]))
2253 add_flag(a_ptr->flags, i);
2258 if (grab_one_flag(&a_ptr->gen_flags, k_info_gen_flags, what) == 0)
2263 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2265 msg_format("Unknown artifact flag '%s'.", what);
2274 * Grab one activation index flag
2276 static byte grab_one_activation_flag(cptr what)
2282 if (k_info_activation_flags[i].flag == NULL) break;
2284 if (streq(what, k_info_activation_flags[i].flag))
2286 return k_info_activation_flags[i].index;
2298 msg_format("̤ÃΤÎȯư¡¦¥Õ¥é¥° '%s'¡£", what);
2300 msg_format("Unknown activation flag '%s'.", what);
2309 * Initialize the "a_info" array, by parsing an ascii "template" file
2311 errr parse_a_info(char *buf, header *head)
2318 static artifact_type *a_ptr = NULL;
2321 /* Process 'N' for "New/Number/Name" */
2324 /* Find the colon before the name */
2325 s = my_strchr(buf+2, ':');
2327 /* Verify that colon */
2330 /* Nuke the colon, advance to the name */
2333 /* Paranoia -- require a name */
2334 if (!*s) return (1);
2339 /* Verify information */
2340 if (i < error_idx) return (4);
2342 /* Verify information */
2343 if (i >= head->info_num) return (2);
2345 /* Save the index */
2348 /* Point at the "info" */
2351 /* Ignore everything */
2352 add_flag(a_ptr->flags, TR_IGNORE_ACID);
2353 add_flag(a_ptr->flags, TR_IGNORE_ELEC);
2354 add_flag(a_ptr->flags, TR_IGNORE_FIRE);
2355 add_flag(a_ptr->flags, TR_IGNORE_COLD);
2357 /* Store the name */
2358 if (!add_name(&a_ptr->name, head, s)) return (7);
2362 /* There better be a current a_ptr */
2363 else if (!a_ptr) return (3);
2367 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2368 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
2369 else if (buf[0] == 'E')
2374 else if (buf[0] == 'E')
2376 /* Acquire the Text */
2379 /* Store the name */
2380 if (!add_name(&a_ptr->name, head, s)) return (7);
2384 /* Process 'D' for "Description" */
2385 else if (buf[0] == 'D')
2390 /* Acquire the text */
2395 /* Acquire the text */
2399 /* Store the text */
2400 if (!add_text(&a_ptr->text, head, s, TRUE)) return (7);
2404 /* Process 'I' for "Info" (one line only) */
2405 else if (buf[0] == 'I')
2407 int tval, sval, pval;
2409 /* Scan for the values */
2410 if (3 != sscanf(buf+2, "%d:%d:%d",
2411 &tval, &sval, &pval)) return (1);
2413 /* Save the values */
2419 /* Process 'W' for "More Info" (one line only) */
2420 else if (buf[0] == 'W')
2422 int level, rarity, wgt;
2425 /* Scan for the values */
2426 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2427 &level, &rarity, &wgt, &cost)) return (1);
2429 /* Save the values */
2430 a_ptr->level = level;
2431 a_ptr->rarity = rarity;
2432 a_ptr->weight = wgt;
2436 /* Hack -- Process 'P' for "power" and such */
2437 else if (buf[0] == 'P')
2439 int ac, hd1, hd2, th, td, ta;
2441 /* Scan for the values */
2442 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2443 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
2453 /* Hack -- Process 'U' for activation index */
2454 else if (buf[0] == 'U')
2457 n = grab_one_activation_flag(buf + 2);
2468 /* Hack -- Process 'F' for flags */
2469 else if (buf[0] == 'F')
2471 /* Parse every entry textually */
2472 for (s = buf + 2; *s; )
2474 /* Find the end of this entry */
2475 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2477 /* Nuke and skip any dividers */
2481 while ((*t == ' ') || (*t == '|')) t++;
2484 /* Parse this entry */
2485 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
2487 /* Start the next entry */
2503 * Grab one flag in a ego-item_type from a textual string
2505 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
2510 for (i = 0; i < TR_FLAG_MAX; i++)
2512 if (streq(what, k_info_flags[i]))
2514 add_flag(e_ptr->flags, i);
2519 if (grab_one_flag(&e_ptr->gen_flags, k_info_gen_flags, what) == 0)
2524 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
2526 msg_format("Unknown ego-item flag '%s'.", what);
2538 * Initialize the "e_info" array, by parsing an ascii "template" file
2540 errr parse_e_info(char *buf, header *head)
2547 static ego_item_type *e_ptr = NULL;
2550 /* Just before the first record */
2553 /* Just before the first line */
2557 /* Process 'N' for "New/Number/Name" */
2560 /* Find the colon before the name */
2561 s = my_strchr(buf+2, ':');
2563 /* Verify that colon */
2566 /* Nuke the colon, advance to the name */
2569 /* Paranoia -- require a name */
2570 if (!*s) return (1);
2575 /* Verify information */
2576 if (i < error_idx) return (4);
2578 /* Verify information */
2579 if (i >= head->info_num) return (2);
2581 /* Save the index */
2584 /* Point at the "info" */
2587 /* Store the name */
2588 if (!add_name(&e_ptr->name, head, s)) return (7);
2592 /* There better be a current e_ptr */
2593 else if (!e_ptr) return (3);
2597 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2598 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2599 else if (buf[0] == 'E')
2604 else if (buf[0] == 'E')
2606 /* Acquire the Text */
2609 /* Store the name */
2610 if (!add_name(&e_ptr->name, head, s)) return (7);
2615 /* Process 'D' for "Description" */
2616 else if (buf[0] == 'D')
2618 /* Acquire the text */
2621 /* Store the text */
2622 if (!add_text(&e_ptr->text, head, s, TRUE)) return (7);
2627 /* Process 'X' for "Xtra" (one line only) */
2628 else if (buf[0] == 'X')
2632 /* Scan for the values */
2633 if (2 != sscanf(buf+2, "%d:%d",
2634 &slot, &rating)) return (1);
2636 /* Save the values */
2638 e_ptr->rating = rating;
2641 /* Process 'W' for "More Info" (one line only) */
2642 else if (buf[0] == 'W')
2644 int level, rarity, pad2;
2647 /* Scan for the values */
2648 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
2649 &level, &rarity, &pad2, &cost)) return (1);
2651 /* Save the values */
2652 e_ptr->level = level;
2653 e_ptr->rarity = rarity;
2654 /* e_ptr->weight = wgt; */
2658 /* Hack -- Process 'C' for "creation" */
2659 else if (buf[0] == 'C')
2663 /* Scan for the values */
2664 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
2665 &th, &td, &ta, &pv)) return (1);
2667 e_ptr->max_to_h = th;
2668 e_ptr->max_to_d = td;
2669 e_ptr->max_to_a = ta;
2670 e_ptr->max_pval = pv;
2673 /* Hack -- Process 'F' for flags */
2674 else if (buf[0] == 'F')
2676 /* Parse every entry textually */
2677 for (s = buf + 2; *s; )
2679 /* Find the end of this entry */
2680 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2682 /* Nuke and skip any dividers */
2686 while ((*t == ' ') || (*t == '|')) t++;
2689 /* Parse this entry */
2690 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
2692 /* Start the next entry */
2706 * Grab one (basic) flag in a monster_race from a textual string
2708 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
2710 if (grab_one_flag(&r_ptr->flags1, r_info_flags1, what) == 0)
2713 if (grab_one_flag(&r_ptr->flags2, r_info_flags2, what) == 0)
2716 if (grab_one_flag(&r_ptr->flags3, r_info_flags3, what) == 0)
2719 if (grab_one_flag(&r_ptr->flags7, r_info_flags7, what) == 0)
2722 if (grab_one_flag(&r_ptr->flags8, r_info_flags8, what) == 0)
2725 if (grab_one_flag(&r_ptr->flags9, r_info_flags9, what) == 0)
2728 if (grab_one_flag(&r_ptr->flagsr, r_info_flagsr, what) == 0)
2733 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2735 msg_format("Unknown monster flag '%s'.", what);
2745 * Grab one (spell) flag in a monster_race from a textual string
2747 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2749 if (grab_one_flag(&r_ptr->flags4, r_info_flags4, what) == 0)
2752 if (grab_one_flag(&r_ptr->flags5, r_info_flags5, what) == 0)
2755 if (grab_one_flag(&r_ptr->flags6, r_info_flags6, what) == 0)
2760 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2762 msg_format("Unknown monster flag '%s'.", what);
2774 * Initialize the "r_info" array, by parsing an ascii "template" file
2776 errr parse_r_info(char *buf, header *head)
2783 static monster_race *r_ptr = NULL;
2786 /* Process 'N' for "New/Number/Name" */
2789 /* Find the colon before the name */
2790 s = my_strchr(buf+2, ':');
2792 /* Verify that colon */
2795 /* Nuke the colon, advance to the name */
2798 /* Paranoia -- require a name */
2799 if (!*s) return (1);
2804 /* Verify information */
2805 if (i < error_idx) return (4);
2807 /* Verify information */
2808 if (i >= head->info_num) return (2);
2810 /* Save the index */
2813 /* Point at the "info" */
2816 /* Store the name */
2817 if (!add_name(&r_ptr->name, head, s)) return (7);
2821 /* There better be a current r_ptr */
2822 else if (!r_ptr) return (3);
2826 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2827 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2828 else if (buf[0] == 'E')
2830 /* Acquire the Text */
2833 /* Store the name */
2834 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2837 else if (buf[0] == 'E')
2839 /* Acquire the Text */
2842 /* Store the name */
2843 if (!add_name(&r_ptr->name, head, s)) return (7);
2846 /* Process 'D' for "Description" */
2847 else if (buf[0] == 'D')
2852 /* Acquire the text */
2857 /* Acquire the text */
2861 /* Store the text */
2862 if (!add_text(&r_ptr->text, head, s, TRUE)) return (7);
2865 /* Process 'G' for "Graphics" (one line only) */
2866 else if (buf[0] == 'G')
2872 if (buf[1] != ':') return (1);
2873 if (!buf[2]) return (1);
2874 if (buf[3] != ':') return (1);
2875 if (!buf[4]) return (1);
2877 /* Extract the char */
2880 /* Extract the attr */
2881 tmp = color_char_to_attr(buf[4]);
2884 if (tmp > 127) return (1);
2886 /* Save the values */
2887 r_ptr->d_char = sym;
2888 r_ptr->d_attr = tmp;
2891 /* Process 'I' for "Info" (one line only) */
2892 else if (buf[0] == 'I')
2894 int spd, hp1, hp2, aaf, ac, slp;
2896 /* Scan for the other values */
2897 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2898 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2900 /* Save the values */
2902 r_ptr->hdice = MAX(hp1, 1);
2903 r_ptr->hside = MAX(hp2, 1);
2909 /* Process 'W' for "More Info" (one line only) */
2910 else if (buf[0] == 'W')
2917 /* Scan for the values */
2918 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2919 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2921 /* Save the values */
2923 r_ptr->rarity = rar;
2926 r_ptr->next_exp = nextexp;
2927 r_ptr->next_r_idx = nextmon;
2930 /* Process 'B' for "Blows" (up to four lines) */
2931 else if (buf[0] == 'B')
2935 /* Find the next empty blow slot (if any) */
2936 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2938 /* Oops, no more slots */
2939 if (i == 4) return (1);
2941 /* Analyze the first field */
2942 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2944 /* Terminate the field (if necessary) */
2945 if (*t == ':') *t++ = '\0';
2947 /* Analyze the method */
2948 for (n1 = 0; r_info_blow_method[n1]; n1++)
2950 if (streq(s, r_info_blow_method[n1])) break;
2953 /* Invalid method */
2954 if (!r_info_blow_method[n1]) return (1);
2956 /* Analyze the second field */
2957 for (s = t; *t && (*t != ':'); t++) /* loop */;
2959 /* Terminate the field (if necessary) */
2960 if (*t == ':') *t++ = '\0';
2962 /* Analyze effect */
2963 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2965 if (streq(s, r_info_blow_effect[n2])) break;
2968 /* Invalid effect */
2969 if (!r_info_blow_effect[n2]) return (1);
2971 /* Analyze the third field */
2972 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2974 /* Terminate the field (if necessary) */
2975 if (*t == 'd') *t++ = '\0';
2977 /* Save the method */
2978 r_ptr->blow[i].method = n1;
2980 /* Save the effect */
2981 r_ptr->blow[i].effect = n2;
2983 /* Extract the damage dice and sides */
2984 r_ptr->blow[i].d_dice = atoi(s);
2985 r_ptr->blow[i].d_side = atoi(t);
2988 /* Process 'F' for "Basic Flags" (multiple lines) */
2989 else if (buf[0] == 'F')
2991 /* Parse every entry */
2992 for (s = buf + 2; *s; )
2994 /* Find the end of this entry */
2995 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2997 /* Nuke and skip any dividers */
3001 while (*t == ' ' || *t == '|') t++;
3004 /* Parse this entry */
3005 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
3007 /* Start the next entry */
3012 /* Process 'S' for "Spell Flags" (multiple lines) */
3013 else if (buf[0] == 'S')
3015 /* Parse every entry */
3016 for (s = buf + 2; *s; )
3018 /* Find the end of this entry */
3019 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3021 /* Nuke and skip any dividers */
3025 while ((*t == ' ') || (*t == '|')) t++;
3028 /* XXX XXX XXX Hack -- Read spell frequency */
3029 if (1 == sscanf(s, "1_IN_%d", &i))
3031 /* Extract a "frequency" */
3032 r_ptr->freq_spell = 100 / i;
3034 /* Start at next entry */
3041 /* Parse this entry */
3042 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
3044 /* Start the next entry */
3059 * Grab one flag for a dungeon type from a textual string
3061 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
3063 if (grab_one_flag(&d_ptr->flags1, d_info_flags1, what) == 0)
3068 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
3070 msg_format("Unknown dungeon type flag '%s'.", what);
3078 * Grab one (basic) flag in a monster_race from a textual string
3080 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
3082 if (grab_one_flag(&d_ptr->mflags1, r_info_flags1, what) == 0)
3085 if (grab_one_flag(&d_ptr->mflags2, r_info_flags2, what) == 0)
3088 if (grab_one_flag(&d_ptr->mflags3, r_info_flags3, what) == 0)
3091 if (grab_one_flag(&d_ptr->mflags7, r_info_flags7, what) == 0)
3094 if (grab_one_flag(&d_ptr->mflags8, r_info_flags8, what) == 0)
3097 if (grab_one_flag(&d_ptr->mflags9, r_info_flags9, what) == 0)
3100 if (grab_one_flag(&d_ptr->mflagsr, r_info_flagsr, what) == 0)
3105 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3107 msg_format("Unknown monster flag '%s'.", what);
3115 * Grab one (spell) flag in a monster_race from a textual string
3117 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
3119 if (grab_one_flag(&d_ptr->mflags4, r_info_flags4, what) == 0)
3122 if (grab_one_flag(&d_ptr->mflags5, r_info_flags5, what) == 0)
3125 if (grab_one_flag(&d_ptr->mflags6, r_info_flags6, what) == 0)
3130 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
3132 msg_format("Unknown monster flag '%s'.", what);
3140 * Initialize the "d_info" array, by parsing an ascii "template" file
3142 errr parse_d_info(char *buf, header *head)
3149 static dungeon_info_type *d_ptr = NULL;
3152 /* Process 'N' for "New/Number/Name" */
3155 /* Find the colon before the name */
3156 s = my_strchr(buf+2, ':');
3158 /* Verify that colon */
3161 /* Nuke the colon, advance to the name */
3164 /* Paranoia -- require a name */
3165 if (!*s) return (1);
3170 /* Verify information */
3171 if (i < error_idx) return (4);
3173 /* Verify information */
3174 if (i >= head->info_num) return (2);
3176 /* Save the index */
3179 /* Point at the "info" */
3182 /* Store the name */
3183 if (!add_name(&d_ptr->name, head, s)) return (7);
3188 else if (buf[0] == 'E') return (0);
3190 else if (buf[0] == 'E')
3192 /* Acquire the Text */
3195 /* Store the name */
3196 if (!add_name(&d_ptr->name, head, s)) return (7);
3200 /* Process 'D' for "Description */
3201 else if (buf[0] == 'D')
3206 /* Acquire the text */
3211 /* Acquire the text */
3215 /* Store the text */
3216 if (!add_text(&d_ptr->text, head, s, TRUE)) return (7);
3219 /* Process 'W' for "More Info" (one line only) */
3220 else if (buf[0] == 'W')
3222 int min_lev, max_lev;
3224 int min_alloc, max_chance;
3225 int obj_good, obj_great;
3228 /* Scan for the values */
3229 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
3230 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
3232 /* Save the values */
3233 d_ptr->mindepth = min_lev;
3234 d_ptr->maxdepth = max_lev;
3235 d_ptr->min_plev = min_plev;
3237 d_ptr->min_m_alloc_level = min_alloc;
3238 d_ptr->max_m_alloc_chance = max_chance;
3239 d_ptr->obj_good = obj_good;
3240 d_ptr->obj_great = obj_great;
3245 /* Process 'P' for "Place Info" */
3246 else if (buf[0] == 'P')
3250 /* Scan for the values */
3251 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
3253 /* Save the values */
3258 /* Process 'L' for "fLoor type" (one line only) */
3259 else if (buf[0] == 'L')
3263 /* Scan for the values */
3264 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 1, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 1)) return (1);
3266 /* Save the values */
3267 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3269 d_ptr->floor[i].feat = f_tag_to_index(zz[i * 2]);
3270 if (d_ptr->floor[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3272 d_ptr->floor[i].percent = atoi(zz[i * 2 + 1]);
3274 d_ptr->tunnel_percent = atoi(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3277 /* Process 'A' for "wAll type" (one line only) */
3278 else if (buf[0] == 'A')
3282 /* Scan for the values */
3283 if (tokenize(buf+2, DUNGEON_FEAT_PROB_NUM * 2 + 4, zz, 0) != (DUNGEON_FEAT_PROB_NUM * 2 + 4)) return (1);
3285 /* Save the values */
3286 for (i = 0; i < DUNGEON_FEAT_PROB_NUM; i++)
3288 d_ptr->fill[i].feat = f_tag_to_index(zz[i * 2]);
3289 if (d_ptr->fill[i].feat < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3291 d_ptr->fill[i].percent = atoi(zz[i * 2 + 1]);
3294 d_ptr->outer_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2]);
3295 if (d_ptr->outer_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3297 d_ptr->inner_wall = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 1]);
3298 if (d_ptr->inner_wall < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3300 d_ptr->stream1 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 2]);
3301 if (d_ptr->stream1 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3303 d_ptr->stream2 = f_tag_to_index(zz[DUNGEON_FEAT_PROB_NUM * 2 + 3]);
3304 if (d_ptr->stream2 < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3307 /* Process 'F' for "Dungeon Flags" (multiple lines) */
3308 else if (buf[0] == 'F')
3310 int artif = 0, monst = 0;
3312 /* Parse every entry */
3313 for (s = buf + 2; *s; )
3315 /* Find the end of this entry */
3316 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3318 /* Nuke and skip any dividers */
3322 while (*t == ' ' || *t == '|') t++;
3325 /* XXX XXX XXX Hack -- Read Final Artifact */
3326 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
3328 /* Extract a "Final Artifact" */
3329 d_ptr->final_artifact = artif;
3331 /* Start at next entry */
3338 /* XXX XXX XXX Hack -- Read Final Object */
3339 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
3341 /* Extract a "Final Artifact" */
3342 d_ptr->final_object = artif;
3344 /* Start at next entry */
3351 /* XXX XXX XXX Hack -- Read Artifact Guardian */
3352 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
3354 /* Extract a "Artifact Guardian" */
3355 d_ptr->final_guardian = monst;
3357 /* Start at next entry */
3364 /* XXX XXX XXX Hack -- Read Special Percentage */
3365 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
3367 /* Extract a "Special %" */
3368 d_ptr->special_div = monst;
3370 /* Start at next entry */
3377 /* Parse this entry */
3378 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
3380 /* Start the next entry */
3385 /* Process 'M' for "Basic Flags" (multiple lines) */
3386 else if (buf[0] == 'M')
3388 /* Parse every entry */
3389 for (s = buf + 2; *s; )
3391 /* Find the end of this entry */
3392 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3394 /* Nuke and skip any dividers */
3398 while (*t == ' ' || *t == '|') t++;
3401 /* Hack -- Read monster symbols */
3402 if (!strncmp(s, "R_CHAR_", 7))
3404 /* Skip "R_CHAR_" */
3408 strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
3410 /* Start at next entry */
3417 /* Parse this entry */
3418 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
3420 /* Start the next entry */
3425 /* Process 'S' for "Spell Flags" (multiple lines) */
3426 else if (buf[0] == 'S')
3428 /* Parse every entry */
3429 for (s = buf + 2; *s; )
3431 /* Find the end of this entry */
3432 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
3434 /* Nuke and skip any dividers */
3438 while ((*t == ' ') || (*t == '|')) t++;
3441 /* XXX XXX XXX Hack -- Read spell frequency */
3442 if (1 == sscanf(s, "1_IN_%d", &i))
3444 /* Start at next entry */
3451 /* Parse this entry */
3452 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
3454 /* Start the next entry */
3467 #else /* ALLOW_TEMPLATES */
3473 #endif /* ALLOW_TEMPLATES */
3476 /* Random dungeon grid effects */
3477 #define RANDOM_NONE 0x00000000
3478 #define RANDOM_FEATURE 0x00000001
3479 #define RANDOM_MONSTER 0x00000002
3480 #define RANDOM_OBJECT 0x00000004
3481 #define RANDOM_EGO 0x00000008
3482 #define RANDOM_ARTIFACT 0x00000010
3483 #define RANDOM_TRAP 0x00000020
3486 typedef struct dungeon_grid dungeon_grid;
3490 int feature; /* Terrain feature */
3491 int monster; /* Monster */
3492 int object; /* Object */
3493 int ego; /* Ego-Item */
3494 int artifact; /* Artifact */
3495 int trap; /* Trap */
3496 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
3497 int special; /* Reserved for special terrain info */
3498 int random; /* Number of the random effect */
3502 static dungeon_grid letter[255];
3506 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3508 static errr parse_line_feature(char *buf)
3514 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3516 /* Tokenize the line */
3517 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
3519 /* Letter to assign */
3520 int index = zz[0][0];
3522 /* Reset the info for the letter */
3523 letter[index].feature = feat_none;
3524 letter[index].monster = 0;
3525 letter[index].object = 0;
3526 letter[index].ego = 0;
3527 letter[index].artifact = 0;
3528 letter[index].trap = feat_none;
3529 letter[index].cave_info = 0;
3530 letter[index].special = 0;
3531 letter[index].random = RANDOM_NONE;
3537 letter[index].special = atoi(zz[8]);
3541 if ((zz[7][0] == '*') && !zz[7][1])
3543 letter[index].random |= RANDOM_TRAP;
3547 letter[index].trap = f_tag_to_index(zz[7]);
3548 if (letter[index].trap < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3553 if (zz[6][0] == '*')
3555 letter[index].random |= RANDOM_ARTIFACT;
3556 if (zz[6][1]) letter[index].artifact = atoi(zz[6] + 1);
3558 else if (zz[6][0] == '!')
3560 if (p_ptr->inside_quest)
3562 letter[index].artifact = quest[p_ptr->inside_quest].k_idx;
3567 letter[index].artifact = atoi(zz[6]);
3572 if (zz[5][0] == '*')
3574 letter[index].random |= RANDOM_EGO;
3575 if (zz[5][1]) letter[index].ego = atoi(zz[5] + 1);
3579 letter[index].ego = atoi(zz[5]);
3584 if (zz[4][0] == '*')
3586 letter[index].random |= RANDOM_OBJECT;
3587 if (zz[4][1]) letter[index].object = atoi(zz[4] + 1);
3589 else if (zz[4][0] == '!')
3591 if (p_ptr->inside_quest)
3593 int a_idx = quest[p_ptr->inside_quest].k_idx;
3596 artifact_type *a_ptr = &a_info[a_idx];
3597 if (!(a_ptr->gen_flags & TRG_INSTA_ART))
3599 letter[index].object = lookup_kind(a_ptr->tval, a_ptr->sval);
3606 letter[index].object = atoi(zz[4]);
3611 if (zz[3][0] == '*')
3613 letter[index].random |= RANDOM_MONSTER;
3614 if (zz[3][1]) letter[index].monster = atoi(zz[3] + 1);
3616 else if (zz[3][0] == 'c')
3618 if (!zz[3][1]) return PARSE_ERROR_GENERIC;
3619 letter[index].monster = - atoi(zz[3] + 1);
3623 letter[index].monster = atoi(zz[3]);
3628 letter[index].cave_info = atoi(zz[2]);
3632 if ((zz[1][0] == '*') && !zz[1][1])
3634 letter[index].random |= RANDOM_FEATURE;
3638 letter[index].feature = f_tag_to_index(zz[1]);
3639 if (letter[index].feature < 0) return PARSE_ERROR_UNDEFINED_TERRAIN_TAG;
3652 * Process "B:<Index>:<Command>:..." -- Building definition
3654 static errr parse_line_building(char *buf)
3670 /* Get the building number */
3673 /* Find the colon after the building number */
3674 s = my_strchr(s, ':');
3676 /* Verify that colon */
3679 /* Nuke the colon, advance to the sub-index */
3682 /* Paranoia -- require a sub-index */
3683 if (!*s) return (1);
3685 /* Building definition sub-index */
3688 /* Building name, owner, race */
3691 if (tokenize(s + 2, 3, zz, 0) == 3)
3693 /* Name of the building */
3694 strcpy(building[index].name, zz[0]);
3696 /* Name of the owner */
3697 strcpy(building[index].owner_name, zz[1]);
3699 /* Race of the owner */
3700 strcpy(building[index].owner_race, zz[2]);
3705 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3708 /* Building Action */
3711 if (tokenize(s + 2, 8, zz, 0) >= 7)
3713 /* Index of the action */
3714 int action_index = atoi(zz[0]);
3716 /* Name of the action */
3717 strcpy(building[index].act_names[action_index], zz[1]);
3719 /* Cost of the action for members */
3720 building[index].member_costs[action_index] = atoi(zz[2]);
3722 /* Cost of the action for non-members */
3723 building[index].other_costs[action_index] = atoi(zz[3]);
3725 /* Letter assigned to the action */
3726 building[index].letters[action_index] = zz[4][0];
3729 building[index].actions[action_index] = atoi(zz[5]);
3731 /* Action restriction */
3732 building[index].action_restr[action_index] = atoi(zz[6]);
3737 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3740 /* Building Classes */
3743 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3745 for (i = 0; i < MAX_CLASS; i++)
3747 building[index].member_class[i] = atoi(zz[i]);
3753 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3756 /* Building Races */
3759 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3761 for (i = 0; i < MAX_RACES; i++)
3763 building[index].member_race[i] = atoi(zz[i]);
3769 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3772 /* Building Realms */
3775 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3777 for (i = 0; i < MAX_MAGIC; i++)
3779 building[index].member_realm[i+1] = atoi(zz[i]);
3785 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3790 /* Ignore scripts */
3796 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3805 * Place the object j_ptr to a grid
3807 static void drop_here(object_type *j_ptr, int y, int x)
3809 cave_type *c_ptr = &cave[y][x];
3812 /* Get new object */
3813 s16b o_idx = o_pop();
3815 /* Access new object */
3816 o_ptr = &o_list[o_idx];
3818 /* Structure copy */
3819 object_copy(o_ptr, j_ptr);
3827 o_ptr->held_m_idx = 0;
3830 o_ptr->next_o_idx = c_ptr->o_idx;
3832 /* Place the object */
3833 c_ptr->o_idx = o_idx;
3838 * Parse a sub-file of the "extra info"
3840 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3847 /* Skip "empty" lines */
3848 if (!buf[0]) return (0);
3850 /* Skip "blank" lines */
3851 if (isspace(buf[0])) return (0);
3854 if (buf[0] == '#') return (0);
3856 /* Require "?:*" format */
3857 if (buf[1] != ':') return (1);
3860 /* Process "%:<fname>" */
3863 /* Attempt to Process the given file */
3864 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3867 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3870 return parse_line_feature(buf);
3873 /* Process "D:<dungeon>" -- info for the cave grids */
3874 else if (buf[0] == 'D')
3876 object_type object_type_body;
3878 /* Acquire the text */
3881 /* Length of the text */
3882 int len = strlen(s);
3884 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3886 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3888 /* Access the grid */
3889 cave_type *c_ptr = &cave[*y][*x];
3893 int object_index = letter[idx].object;
3894 int monster_index = letter[idx].monster;
3895 int random = letter[idx].random;
3896 int artifact_index = letter[idx].artifact;
3898 /* Lay down a floor */
3899 c_ptr->feat = conv_dungeon_feat(letter[idx].feature);
3901 /* Only the features */
3902 if (init_flags & INIT_ONLY_FEATURES) continue;
3905 c_ptr->info = letter[idx].cave_info;
3907 /* Create a monster */
3908 if (random & RANDOM_MONSTER)
3910 monster_level = base_level + monster_index;
3912 place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
3914 monster_level = base_level;
3916 else if (monster_index)
3918 int old_cur_num, old_max_num;
3921 if (monster_index < 0)
3923 monster_index = -monster_index;
3926 old_cur_num = r_info[monster_index].cur_num;
3927 old_max_num = r_info[monster_index].max_num;
3929 /* Make alive again */
3930 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3932 r_info[monster_index].cur_num = 0;
3933 r_info[monster_index].max_num = 1;
3936 /* Make alive again */
3937 /* Hack -- Non-unique Nazguls are semi-unique */
3938 else if (r_info[monster_index].flags7 & RF7_NAZGUL)
3940 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3942 r_info[monster_index].max_num++;
3947 place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
3951 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3953 /* Make alive again for real unique monster */
3954 r_info[monster_index].cur_num = old_cur_num;
3955 r_info[monster_index].max_num = old_max_num;
3959 /* Object (and possible trap) */
3960 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3962 object_level = base_level + object_index;
3965 * Random trap and random treasure defined
3966 * 25% chance for trap and 75% chance for object
3968 if (randint0(100) < 75)
3970 place_object(*y, *x, 0L);
3977 object_level = base_level;
3979 else if (random & RANDOM_OBJECT)
3981 object_level = base_level + object_index;
3983 /* Create an out of deep object */
3984 if (randint0(100) < 75)
3985 place_object(*y, *x, 0L);
3986 else if (randint0(100) < 80)
3987 place_object(*y, *x, AM_GOOD);
3989 place_object(*y, *x, AM_GOOD | AM_GREAT);
3991 object_level = base_level;
3994 else if (random & RANDOM_TRAP)
3998 /* Hidden trap (or door) */
3999 else if (letter[idx].trap)
4001 c_ptr->mimic = c_ptr->feat;
4002 c_ptr->feat = conv_dungeon_feat(letter[idx].trap);
4004 else if (object_index)
4006 /* Get local object */
4007 object_type *o_ptr = &object_type_body;
4009 /* Create the item */
4010 object_prep(o_ptr, object_index);
4012 if (o_ptr->tval == TV_GOLD)
4014 coin_type = object_index - OBJ_GOLD_LIST;
4019 /* Apply magic (no messages, no artifacts) */
4020 apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
4022 drop_here(o_ptr, *y, *x);
4028 if (a_info[artifact_index].cur_num)
4030 int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
4032 object_type *q_ptr = &forge;
4034 object_prep(q_ptr, k_idx);
4036 /* Drop it in the dungeon */
4037 drop_here(q_ptr, *y, *x);
4041 /* Create the artifact */
4042 if (create_named_art(artifact_index, *y, *x))
4043 a_info[artifact_index].cur_num = 1;
4047 /* Terrain special */
4048 c_ptr->special = letter[idx].special;
4056 /* Process "Q:<number>:<command>:... -- quest info */
4057 else if (buf[0] == 'Q')
4064 num = tokenize(buf + 2, 33, zz, 0);
4068 num = tokenize(buf + 3, 33, zz, 0);
4071 /* Have we enough parameters? */
4072 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4075 q_ptr = &(quest[atoi(zz[0])]);
4077 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
4078 if (zz[1][0] == 'Q')
4080 if (init_flags & INIT_ASSIGN)
4082 monster_race *r_ptr;
4083 artifact_type *a_ptr;
4085 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
4087 q_ptr->type = atoi(zz[2]);
4088 q_ptr->num_mon = atoi(zz[3]);
4089 q_ptr->cur_num = atoi(zz[4]);
4090 q_ptr->max_num = atoi(zz[5]);
4091 q_ptr->level = atoi(zz[6]);
4092 q_ptr->r_idx = atoi(zz[7]);
4093 q_ptr->k_idx = atoi(zz[8]);
4094 q_ptr->dungeon = atoi(zz[9]);
4097 q_ptr->flags = atoi(zz[10]);
4099 r_ptr = &r_info[q_ptr->r_idx];
4100 if (r_ptr->flags1 & RF1_UNIQUE)
4101 r_ptr->flags1 |= RF1_QUESTOR;
4103 a_ptr = &a_info[q_ptr->k_idx];
4104 a_ptr->gen_flags |= TRG_QUESTITEM;
4109 else if (zz[1][0] == 'R')
4111 if (init_flags & INIT_ASSIGN)
4116 for (idx = 2; idx < num; idx++)
4118 int a_idx = atoi(zz[idx]);
4119 if (a_idx < 1) continue;
4120 if (a_info[a_idx].cur_num > 0) continue;
4122 if (one_in_(count)) reward_idx = a_idx;
4127 /* Set quest's rewarding artifact */
4128 q_ptr->k_idx = reward_idx;
4129 a_info[reward_idx].gen_flags |= TRG_QUESTITEM;
4133 /* Change a quest type to KILL_ALL when all artifact of reward list are got */
4134 q_ptr->type = QUEST_TYPE_KILL_ALL;
4141 /* Process "Q:<q_index>:N:<name>" -- quest name */
4142 else if (zz[1][0] == 'N')
4144 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT | INIT_NAME_ONLY))
4146 strcpy(q_ptr->name, zz[2]);
4152 /* Process "Q:<q_index>:T:<text>" -- quest description line */
4153 else if (zz[1][0] == 'T')
4155 if (init_flags & INIT_SHOW_TEXT)
4157 strcpy(quest_text[quest_text_line], zz[2]);
4165 /* Process "W:<command>: ..." -- info for the wilderness */
4166 else if (buf[0] == 'W')
4168 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
4171 /* Process "P:<y>:<x>" -- player position */
4172 else if (buf[0] == 'P')
4174 if (init_flags & INIT_CREATE_DUNGEON)
4176 if (tokenize(buf + 2, 2, zz, 0) == 2)
4178 int panels_x, panels_y;
4180 /* Hack - Set the dungeon size */
4181 panels_y = (*y / SCREEN_HGT);
4182 if (*y % SCREEN_HGT) panels_y++;
4183 cur_hgt = panels_y * SCREEN_HGT;
4185 panels_x = (*x / SCREEN_WID);
4186 if (*x % SCREEN_WID) panels_x++;
4187 cur_wid = panels_x * SCREEN_WID;
4189 /* Assume illegal panel */
4190 panel_row_min = cur_hgt;
4191 panel_col_min = cur_wid;
4193 /* Place player in a quest level */
4194 if (p_ptr->inside_quest)
4198 /* Delete the monster (if any) */
4199 delete_monster(py, px);
4207 /* Place player in the town */
4208 else if (!p_ptr->oldpx && !p_ptr->oldpy)
4210 p_ptr->oldpy = atoi(zz[0]);
4211 p_ptr->oldpx = atoi(zz[1]);
4219 /* Process "B:<Index>:<Command>:..." -- Building definition */
4220 else if (buf[0] == 'B')
4222 return parse_line_building(buf);
4225 /* Process "M:<type>:<maximum>" -- set maximum values */
4226 else if (buf[0] == 'M')
4228 if (tokenize(buf+2, 2, zz, 0) == 2)
4231 if (zz[0][0] == 'T')
4233 max_towns = atoi(zz[1]);
4236 /* Maximum quests */
4237 else if (zz[0][0] == 'Q')
4239 max_quests = atoi(zz[1]);
4243 else if (zz[0][0] == 'R')
4245 max_r_idx = atoi(zz[1]);
4249 else if (zz[0][0] == 'K')
4251 max_k_idx = atoi(zz[1]);
4255 else if (zz[0][0] == 'V')
4257 max_v_idx = atoi(zz[1]);
4261 else if (zz[0][0] == 'F')
4263 max_f_idx = atoi(zz[1]);
4267 else if (zz[0][0] == 'A')
4269 max_a_idx = atoi(zz[1]);
4273 else if (zz[0][0] == 'E')
4275 max_e_idx = atoi(zz[1]);
4279 else if (zz[0][0] == 'D')
4281 max_d_idx = atoi(zz[1]);
4285 else if (zz[0][0] == 'O')
4287 max_o_idx = atoi(zz[1]);
4291 else if (zz[0][0] == 'M')
4293 max_m_idx = atoi(zz[1]);
4296 /* Wilderness size */
4297 else if (zz[0][0] == 'W')
4299 /* Maximum wild_x_size */
4300 if (zz[0][1] == 'X')
4301 max_wild_x = atoi(zz[1]);
4302 /* Maximum wild_y_size */
4303 if (zz[0][1] == 'Y')
4304 max_wild_y = atoi(zz[1]);
4318 static cptr variant = "ZANGBAND";
4322 * Helper function for "process_dungeon_file()"
4324 static cptr process_dungeon_file_expr(char **sp, char *fp)
4340 while (isspace(*s)) s++;
4358 t = process_dungeon_file_expr(&s, &f);
4367 else if (streq(t, "IOR"))
4370 while (*s && (f != b2))
4372 t = process_dungeon_file_expr(&s, &f);
4373 if (*t && !streq(t, "0")) v = "1";
4378 else if (streq(t, "AND"))
4381 while (*s && (f != b2))
4383 t = process_dungeon_file_expr(&s, &f);
4384 if (*t && streq(t, "0")) v = "0";
4389 else if (streq(t, "NOT"))
4392 while (*s && (f != b2))
4394 t = process_dungeon_file_expr(&s, &f);
4395 if (*t && streq(t, "1")) v = "0";
4400 else if (streq(t, "EQU"))
4403 if (*s && (f != b2))
4405 t = process_dungeon_file_expr(&s, &f);
4407 while (*s && (f != b2))
4409 p = process_dungeon_file_expr(&s, &f);
4410 if (streq(t, p)) v = "1";
4415 else if (streq(t, "LEQ"))
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);
4426 if (*t && atoi(p) > atoi(t)) v = "0";
4431 else if (streq(t, "GEQ"))
4434 if (*s && (f != b2))
4436 t = process_dungeon_file_expr(&s, &f);
4438 while (*s && (f != b2))
4441 t = process_dungeon_file_expr(&s, &f);
4443 /* Compare two numbers instead of string */
4444 if (*t && atoi(p) < atoi(t)) v = "0";
4451 while (*s && (f != b2))
4453 t = process_dungeon_file_expr(&s, &f);
4458 if (f != b2) v = "?x?x?";
4460 /* Extract final and Terminate */
4461 if ((f = *s) != '\0') *s++ = '\0';
4467 /* Accept all printables except spaces and brackets */
4469 while (iskanji(*s) || (isprint(*s) && !my_strchr(" []", *s)))
4471 if (iskanji(*s)) s++;
4475 while (isprint(*s) && !my_strchr(" []", *s)) ++s;
4478 /* Extract final and Terminate */
4479 if ((f = *s) != '\0') *s++ = '\0';
4485 if (streq(b+1, "SYS"))
4491 else if (streq(b+1, "GRAF"))
4496 else if (streq(b+1, "MONOCHROME"))
4505 else if (streq(b+1, "RACE"))
4508 v = rp_ptr->E_title;
4515 else if (streq(b+1, "CLASS"))
4518 v = cp_ptr->E_title;
4525 else if (streq(b+1, "REALM1"))
4528 v = E_realm_names[p_ptr->realm1];
4530 v = realm_names[p_ptr->realm1];
4535 else if (streq(b+1, "REALM2"))
4538 v = E_realm_names[p_ptr->realm2];
4540 v = realm_names[p_ptr->realm2];
4545 else if (streq(b+1, "PLAYER"))
4547 static char tmp_player_name[32];
4549 for (pn = player_name, tpn = tmp_player_name; *pn; pn++, tpn++)
4559 *tpn = my_strchr(" []", *pn) ? '_' : *pn;
4562 v = tmp_player_name;
4566 else if (streq(b+1, "TOWN"))
4568 sprintf(tmp, "%d", p_ptr->town_num);
4573 else if (streq(b+1, "LEVEL"))
4575 sprintf(tmp, "%d", p_ptr->lev);
4579 /* Current quest number */
4580 else if (streq(b+1, "QUEST_NUMBER"))
4582 sprintf(tmp, "%d", p_ptr->inside_quest);
4586 /* Number of last quest */
4587 else if (streq(b+1, "LEAVING_QUEST"))
4589 sprintf(tmp, "%d", leaving_quest);
4594 else if (prefix(b+1, "QUEST_TYPE"))
4596 /* "QUEST_TYPE" uses a special parameter to determine the type of the quest */
4597 sprintf(tmp, "%d", quest[atoi(b+11)].type);
4602 else if (prefix(b+1, "QUEST"))
4604 /* "QUEST" uses a special parameter to determine the number of the quest */
4605 sprintf(tmp, "%d", quest[atoi(b+6)].status);
4610 else if (prefix(b+1, "RANDOM"))
4612 /* "RANDOM" uses a special parameter to determine the number of the quest */
4613 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
4618 else if (streq(b+1, "VARIANT"))
4624 else if (streq(b+1, "WILDERNESS"))
4627 sprintf(tmp, "NONE");
4629 sprintf(tmp, "LITE");
4631 sprintf(tmp, "NORMAL");
4654 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
4664 bool bypass = FALSE;
4666 int x = xmin, y = ymin;
4669 /* Build the filename */
4670 path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
4673 fp = my_fopen(buf, "r");
4676 if (!fp) return (-1);
4679 /* Process the file */
4680 while (0 == my_fgets(fp, buf, sizeof(buf)))
4686 /* Skip "empty" lines */
4687 if (!buf[0]) continue;
4689 /* Skip "blank" lines */
4690 if (isspace(buf[0])) continue;
4693 if (buf[0] == '#') continue;
4696 /* Process "?:<expr>" */
4697 if ((buf[0] == '?') && (buf[1] == ':'))
4706 /* Parse the expr */
4707 v = process_dungeon_file_expr(&s, &f);
4710 bypass = (streq(v, "0") ? TRUE : FALSE);
4716 /* Apply conditionals */
4717 if (bypass) continue;
4719 /* Process the line */
4720 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4732 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4735 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4737 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4739 msg_format("Parsing '%s'.", buf);
4746 /* Close the file */
4756 void write_r_info_txt(void)
4758 int i, j, z, fc, bc;
4761 cptr flags[32 * 10];
4766 monster_race *r_ptr;
4768 monster_blow *b_ptr;
4770 FILE *fff = fopen("output.txt", "wt");
4778 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4780 fprintf(fff, "# Version stamp (required)\n\n");
4783 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4786 fprintf(fff, "##### The Player #####\n\n");
4788 for (z = -1; z < alloc_race_size; z++)
4790 /* Output the monsters in order */
4791 i = (z >= 0) ? alloc_race_table[z].index : 0;
4793 /* Acquire the monster */
4796 /* Ignore empty monsters */
4797 if (!strlen(r_name + r_ptr->name)) continue;
4799 /* Ignore useless monsters */
4800 if (i && !r_ptr->speed) continue;
4802 /* Write a note if necessary */
4803 if (i && (!r_ptr->level != !mode))
4808 fprintf(fff, "\n##### Town monsters #####\n\n");
4810 /* Note the dungeon */
4813 fprintf(fff, "\n##### Normal monsters #####\n\n");
4816 /* Record the change */
4817 mode = r_ptr->level;
4820 /* Acquire the flags */
4821 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4822 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4823 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4824 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4825 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4826 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4827 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4828 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4829 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4830 f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
4832 /* Write New/Number/Name */
4833 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4836 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4838 /* Write Information */
4839 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4840 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4842 /* Write more information */
4843 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4846 for(j = 0; j < 4; j++)
4848 b_ptr = &(r_ptr->blow[j]);
4850 /* Stop when done */
4851 if (!b_ptr->method) break;
4853 /* Write the blows */
4854 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4855 r_info_blow_effect[b_ptr->effect],
4856 b_ptr->d_dice, b_ptr->d_side);
4859 /* Extract the flags */
4860 for (fc = 0, j = 0; j < 32 * 3; j++)
4862 /* Check this flag */
4863 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4866 /* Extract the extra flags */
4867 for (j = 32 * 6; j < 32 * 10; j++)
4869 /* Check this flag */
4870 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4873 /* Write the flags */
4874 for (j = 0; j < fc;)
4878 /* Start the line */
4881 for (bc = 0; (bc < 60) && (j < fc); j++)
4885 /* Format the flag */
4886 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4888 /* Add it to the buffer */
4891 /* Note the length */
4895 /* Done with this line; write it */
4896 fprintf(fff, "%s\n", buf);
4899 /* Write Spells if applicable */
4900 if (r_ptr->freq_spell)
4902 /* Write the frequency */
4903 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4905 /* Extract the spell flags */
4906 for (fc = 0, j = 96; j < 192; j++)
4908 /* Check this flag */
4909 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4912 /* Write the flags */
4913 for (j = 0; j < fc;)
4917 /* Start the line */
4920 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4924 /* Format the flag */
4925 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4929 /* Note the length */
4936 /* Done with this line; write it */
4937 fprintf(fff, "%s\n", buf);
4941 /* Acquire the description */
4942 desc = r_text + r_ptr->text;
4943 dlen = strlen(desc);
4945 /* Write Description */
4946 for (j = 0; j < dlen;)
4950 /* Start the line */
4953 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4961 /* Done with this line; write it */
4962 fprintf(fff, "%s\n", buf);
4965 /* Space between entries */