3 /* Purpose: Initialization (part 1) -BEN- */
10 char* _strchr(char* ptr, char ch)
12 for ( ; *ptr != '\0'; ++ptr)
14 if (*ptr == ch) return ptr;
15 if (iskanji(*ptr)) ++ptr;
20 #define strchr _strchr
23 * This file is used to initialize various variables and arrays for the
24 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
25 * the common limitation of "read()" and "write()" to only 32767 bytes
28 * Several of the arrays for Angband are built from "template" files in
29 * the "lib/file" directory, from which quick-load binary "image" files
30 * are constructed whenever they are not present in the "lib/data"
31 * directory, or if those files become obsolete, if we are allowed.
33 * Warning -- the "ascii" file parsers use a minor hack to collect the
34 * name and text information in a single pass. Thus, the game will not
35 * be able to load any template file with more than 20K of names or 60K
36 * of text, even though technically, up to 64K should be legal.
38 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
39 * in this file is compiled out, and the game will not run unless valid
40 * "binary template files" already exist in "lib/data". Thus, one can
41 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
42 * "*.raw" files in "lib/data", and then quit, and recompile without
43 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
44 * from changing the ascii template files in potentially dangerous ways.
46 * The code could actually be removed and placed into a "stand-alone"
47 * program, but that feels a little silly, especially considering some
48 * of the platforms that we currently support.
51 #ifdef ALLOW_TEMPLATES
56 /*** Helper arrays for parsing ascii template files ***/
59 * Monster Blow Methods
61 static cptr r_info_blow_method[] =
94 * Monster Blow Effects
96 static cptr r_info_blow_effect[] =
139 static cptr r_info_flags1[] =
178 static cptr r_info_flags2[] =
217 static cptr r_info_flags3[] =
256 static cptr r_info_flags4[] =
295 static cptr r_info_flags5[] =
334 static cptr r_info_flags6[] =
351 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
374 static cptr r_info_flags7[] =
413 static cptr r_info_flags8[] =
445 "WILD_SWAMP", /* ToDo: Implement Swamp */
451 * Monster race flags - Drops
453 static cptr r_info_flags9[] =
494 static cptr k_info_flags1[] =
533 static cptr k_info_flags2[] =
572 static cptr k_info_flags3[] =
612 static cptr d_info_flags1[] =
650 * Add a text to the text-storage and store offset to it.
652 * Returns FALSE when there isn't enough space available to store
655 static bool add_text(u32b *offset, header *head, cptr buf)
657 /* Hack -- Verify space */
658 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
664 /* Advance and save the text index */
665 *offset = ++head->text_size;
668 /* Append chars to the text */
669 strcpy(head->text_ptr + head->text_size, buf);
671 /* Advance the index */
672 head->text_size += strlen(buf);
680 * Add a name to the name-storage and return an offset to it.
682 * Returns FALSE when there isn't enough space available to store
685 static bool add_name(u32b *offset, header *head, cptr buf)
687 /* Hack -- Verify space */
688 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
694 /* Advance and save the name index */
695 *offset = ++head->name_size;
698 /* Append chars to the names */
699 strcpy(head->name_ptr + head->name_size, buf);
701 /* Advance the index */
702 head->name_size += strlen(buf);
710 * Convert a "color letter" into an "actual" color
711 * The colors are: dwsorgbuDWvyRGBU, as shown below
713 static int color_char_to_attr(char c)
717 case 'd': return (TERM_DARK);
718 case 'w': return (TERM_WHITE);
719 case 's': return (TERM_SLATE);
720 case 'o': return (TERM_ORANGE);
721 case 'r': return (TERM_RED);
722 case 'g': return (TERM_GREEN);
723 case 'b': return (TERM_BLUE);
724 case 'u': return (TERM_UMBER);
726 case 'D': return (TERM_L_DARK);
727 case 'W': return (TERM_L_WHITE);
728 case 'v': return (TERM_VIOLET);
729 case 'y': return (TERM_YELLOW);
730 case 'R': return (TERM_L_RED);
731 case 'G': return (TERM_L_GREEN);
732 case 'B': return (TERM_L_BLUE);
733 case 'U': return (TERM_L_UMBER);
741 /*** Initialize from ascii template files ***/
745 * Initialize an "*_info" array, by parsing an ascii "template" file
747 errr init_info_txt(FILE *fp, char *buf, header *head,
748 parse_info_txt_func parse_info_txt_line)
752 /* Just before the first record */
755 /* Just before the first line */
759 /* Prepare the "fake" stuff */
764 while (0 == my_fgets(fp, buf, 1024))
766 /* Advance the line number */
769 /* Skip comments and blank lines */
770 if (!buf[0] || (buf[0] == '#')) continue;
772 /* Verify correct "colon" format */
773 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
776 /* Hack -- Process 'V' for "Version" */
784 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
789 /* Complete the "name" and "text" sizes */
790 if (head->name_size) head->name_size++;
791 if (head->text_size) head->text_size++;
799 * Initialize the "v_info" array, by parsing an ascii "template" file
801 errr parse_v_info(char *buf, header *head)
807 static vault_type *v_ptr = NULL;
809 /* Process 'N' for "New/Number/Name" */
812 /* Find the colon before the name */
813 s = strchr(buf+2, ':');
815 /* Verify that colon */
818 /* Nuke the colon, advance to the name */
821 /* Paranoia -- require a name */
827 /* Verify information */
828 if (i <= error_idx) return (4);
830 /* Verify information */
831 if (i >= head->info_num) return (2);
836 /* Point at the "info" */
840 if (!add_name(&v_ptr->name, head, s)) return (7);
843 /* There better be a current v_ptr */
844 else if (!v_ptr) return (3);
846 /* Process 'D' for "Description" */
847 else if (buf[0] == 'D')
849 /* Acquire the text */
853 if (!add_text(&v_ptr->text, head, s)) return (7);
856 /* Process 'X' for "Extra info" (one line only) */
857 else if (buf[0] == 'X')
859 int typ, rat, hgt, wid;
861 /* Scan for the values */
862 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
863 &typ, &rat, &hgt, &wid)) return (1);
865 /* Save the values */
882 * Initialize the "s_info" array, by parsing an ascii "template" file
884 errr parse_s_info(char *buf, header *head)
889 static skill_table *s_ptr = NULL;
892 /* Process 'N' for "New/Number/Name" */
898 /* Verify information */
899 if (i <= error_idx) return (4);
901 /* Verify information */
902 if (i >= head->info_num) return (2);
907 /* Point at the "info" */
911 /* There better be a current s_ptr */
912 else if (!s_ptr) return (3);
914 /* Process 'W' for "Weapon exp" */
915 else if (buf[0] == 'W')
917 int tval, sval, start, max;
918 const s16b exp_conv_table[] = { 0, 4000, 6000, 7000, 8000 };
920 /* Scan for the values */
921 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
922 &tval, &sval, &start, &max)) return (1);
924 if (start < 0 || start > 4 || max < 0 || max > 4) return (8);
926 /* Save the values */
927 s_ptr->w_start[tval][sval] = exp_conv_table[start];
928 s_ptr->w_max[tval][sval] = exp_conv_table[max];
931 /* Process 'S' for "Skill exp" */
932 else if (buf[0] == 'S')
936 /* Scan for the values */
937 if (3 != sscanf(buf+2, "%d:%d:%d",
938 &num, &start, &max)) return (1);
940 if (start < 0 || start > 8000 || max < 0 || max > 8000) return (8);
942 /* Save the values */
943 s_ptr->s_start[num] = start;
944 s_ptr->s_max[num] = max;
957 * Initialize the "m_info" array, by parsing an ascii "template" file
959 errr parse_m_info(char *buf, header *head)
966 static player_magic *m_ptr = NULL;
969 static int realm, magic_idx = 0, readable = 0;
972 /* Process 'N' for "New/Number/Name" */
978 /* Verify information */
979 if (i <= error_idx) return (4);
981 /* Verify information */
982 if (i >= head->info_num) return (2);
987 /* Point at the "info" */
991 /* There better be a current m_ptr */
992 else if (!m_ptr) return (3);
994 /* Process 'I' for "Info" (one line only) */
995 else if (buf[0] == 'I')
998 int xtra, type, first, weight;
1000 /* Find the colon before the name */
1001 s = strchr(buf+2, ':');
1003 /* Verify that colon */
1006 /* Nuke the colon, advance to the name */
1011 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1012 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1013 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1014 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1015 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1020 /* Find the colon before the name */
1023 /* Verify that colon */
1026 /* Nuke the colon, advance to the name */
1029 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1030 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1031 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1032 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1033 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1034 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1038 /* Scan for the values */
1039 if (4 != sscanf(s, "%x:%d:%d:%d",
1040 &xtra, &type, &first, &weight)) return (1);
1042 m_ptr->spell_xtra = xtra;
1043 m_ptr->spell_type = type;
1044 m_ptr->spell_first = first;
1045 m_ptr->spell_weight = weight;
1049 /* Process 'R' for "Realm" (one line only) */
1050 else if (buf[0] == 'R')
1052 /* Scan for the values */
1053 if (2 != sscanf(buf+2, "%d:%d",
1054 &realm, &readable)) return (1);
1059 else if (buf[0] == 'T')
1061 int level, mana, fail, exp;
1063 if (!readable) return (1);
1064 /* Scan for the values */
1065 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1066 &level, &mana, &fail, &exp)) return (1);
1068 m_ptr->info[realm][magic_idx].slevel = level;
1069 m_ptr->info[realm][magic_idx].smana = mana;
1070 m_ptr->info[realm][magic_idx].sfail = fail;
1071 m_ptr->info[realm][magic_idx].sexp = exp;
1085 * Initialize the "f_info" array, by parsing an ascii "template" file
1087 errr parse_f_info(char *buf, header *head)
1094 static feature_type *f_ptr = NULL;
1097 /* Process 'N' for "New/Number/Name" */
1100 /* Find the colon before the name */
1101 s = strchr(buf+2, ':');
1103 /* Verify that colon */
1106 /* Nuke the colon, advance to the name */
1110 /* Paranoia -- require a name */
1111 if (!*s) return (1);
1117 /* Verify information */
1118 if (i <= error_idx) return (4);
1120 /* Verify information */
1121 if (i >= head->info_num) return (2);
1123 /* Save the index */
1126 /* Point at the "info" */
1130 /* Store the name */
1131 if (!add_name(&f_ptr->name, head, s)) return (7);
1133 /* Default "mimic" */
1137 /* There better be a current f_ptr */
1138 else if (!f_ptr) return (3);
1141 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1142 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1143 else if (buf[0] == 'E')
1148 else if (buf[0] == 'E')
1150 /* Acquire the Text */
1153 /* Store the name */
1154 if (!add_name(&f_ptr->name, head, s)) return (7);
1160 /* Process 'D' for "Description" */
1161 else if (buf[0] == 'D')
1163 /* Acquire the text */
1166 /* Store the text */
1167 if (!add_text(&f_ptr->text, head, s)) return (7);
1173 /* Process 'M' for "Mimic" (one line only) */
1174 else if (buf[0] == 'M')
1178 /* Scan for the values */
1179 if (1 != sscanf(buf+2, "%d",
1180 &mimic)) return (1);
1182 /* Save the values */
1183 f_ptr->mimic = mimic;
1188 /* Process 'G' for "Graphics" (one line only) */
1189 else if (buf[0] == 'G')
1194 if (!buf[2]) return (1);
1195 if (!buf[3]) return (1);
1196 if (!buf[4]) return (1);
1198 /* Extract the color */
1199 tmp = color_char_to_attr(buf[4]);
1202 if (tmp < 0) return (1);
1204 /* Save the values */
1205 f_ptr->d_attr = tmp;
1206 f_ptr->d_char = buf[2];
1219 * Grab one flag in an object_kind from a textual string
1221 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1226 for (i = 0; i < 32; i++)
1228 if (streq(what, k_info_flags1[i]))
1230 k_ptr->flags1 |= (1L << i);
1236 for (i = 0; i < 32; i++)
1238 if (streq(what, k_info_flags2[i]))
1240 k_ptr->flags2 |= (1L << i);
1246 for (i = 0; i < 32; i++)
1248 if (streq(what, k_info_flags3[i]))
1250 k_ptr->flags3 |= (1L << i);
1257 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1259 msg_format("Unknown object flag '%s'.", what);
1269 * Initialize the "k_info" array, by parsing an ascii "template" file
1271 errr parse_k_info(char *buf, header *head)
1278 static object_kind *k_ptr = NULL;
1281 /* Process 'N' for "New/Number/Name" */
1284 /* Find the colon before the name */
1285 s = strchr(buf+2, ':');
1287 /* Verify that colon */
1290 /* Nuke the colon, advance to the name */
1294 /* Paranoia -- require a name */
1295 if (!*s) return (1);
1300 /* Verify information */
1301 if (i <= error_idx) return (4);
1303 /* Verify information */
1304 if (i >= head->info_num) return (2);
1306 /* Save the index */
1309 /* Point at the "info" */
1313 /* Store the name */
1314 if (!add_name(&k_ptr->name, head, s)) return (7);
1318 /* There better be a current k_ptr */
1319 else if (!k_ptr) return (3);
1323 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1324 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1325 else if (buf[0] == 'E')
1330 else if (buf[0] == 'E')
1332 /* Acquire the Text */
1335 /* Store the name */
1336 if (!add_name(&k_ptr->name, head, s)) return (7);
1341 /* Process 'D' for "Description" */
1342 else if (buf[0] == 'D')
1344 /* Acquire the text */
1347 /* Store the text */
1348 if (!add_text(&k_ptr->text, head, s)) return (7);
1354 /* Process 'G' for "Graphics" (one line only) */
1355 else if (buf[0] == 'G')
1361 if (!buf[2]) return (1);
1362 if (!buf[3]) return (1);
1363 if (!buf[4]) return (1);
1365 /* Extract the char */
1368 /* Extract the attr */
1369 tmp = color_char_to_attr(buf[4]);
1372 if (tmp < 0) return (1);
1374 /* Save the values */
1375 k_ptr->d_attr = tmp;
1376 k_ptr->d_char = sym;
1379 /* Process 'I' for "Info" (one line only) */
1380 else if (buf[0] == 'I')
1382 int tval, sval, pval;
1384 /* Scan for the values */
1385 if (3 != sscanf(buf+2, "%d:%d:%d",
1386 &tval, &sval, &pval)) return (1);
1388 /* Save the values */
1394 /* Process 'W' for "More Info" (one line only) */
1395 else if (buf[0] == 'W')
1397 int level, extra, wgt;
1400 /* Scan for the values */
1401 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1402 &level, &extra, &wgt, &cost)) return (1);
1404 /* Save the values */
1405 k_ptr->level = level;
1406 k_ptr->extra = extra;
1407 k_ptr->weight = wgt;
1411 /* Process 'A' for "Allocation" (one line only) */
1412 else if (buf[0] == 'A')
1416 /* XXX XXX XXX Simply read each number following a colon */
1417 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1419 /* Default chance */
1420 k_ptr->chance[i] = 1;
1422 /* Store the attack damage index */
1423 k_ptr->locale[i] = atoi(s+1);
1425 /* Find the slash */
1426 t = strchr(s+1, '/');
1428 /* Find the next colon */
1429 s = strchr(s+1, ':');
1431 /* If the slash is "nearby", use it */
1432 if (t && (!s || t < s))
1434 int chance = atoi(t+1);
1435 if (chance > 0) k_ptr->chance[i] = chance;
1440 /* Hack -- Process 'P' for "power" and such */
1441 else if (buf[0] == 'P')
1443 int ac, hd1, hd2, th, td, ta;
1445 /* Scan for the values */
1446 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1447 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1457 /* Hack -- Process 'F' for flags */
1458 else if (buf[0] == 'F')
1460 /* Parse every entry textually */
1461 for (s = buf + 2; *s; )
1463 /* Find the end of this entry */
1464 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1466 /* Nuke and skip any dividers */
1470 while (*t == ' ' || *t == '|') t++;
1473 /* Parse this entry */
1474 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
1476 /* Start the next entry */
1492 * Grab one flag in an artifact_type from a textual string
1494 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
1499 for (i = 0; i < 32; i++)
1501 if (streq(what, k_info_flags1[i]))
1503 a_ptr->flags1 |= (1L << i);
1509 for (i = 0; i < 32; i++)
1511 if (streq(what, k_info_flags2[i]))
1513 a_ptr->flags2 |= (1L << i);
1519 for (i = 0; i < 32; i++)
1521 if (streq(what, k_info_flags3[i]))
1523 a_ptr->flags3 |= (1L << i);
1530 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1532 msg_format("Unknown artifact flag '%s'.", what);
1544 * Initialize the "a_info" array, by parsing an ascii "template" file
1546 errr parse_a_info(char *buf, header *head)
1553 static artifact_type *a_ptr = NULL;
1556 /* Process 'N' for "New/Number/Name" */
1559 /* Find the colon before the name */
1560 s = strchr(buf+2, ':');
1562 /* Verify that colon */
1565 /* Nuke the colon, advance to the name */
1568 /* Paranoia -- require a name */
1569 if (!*s) return (1);
1574 /* Verify information */
1575 if (i < error_idx) return (4);
1577 /* Verify information */
1578 if (i >= head->info_num) return (2);
1580 /* Save the index */
1583 /* Point at the "info" */
1586 /* Ignore everything */
1587 a_ptr->flags3 |= (TR3_IGNORE_ACID);
1588 a_ptr->flags3 |= (TR3_IGNORE_ELEC);
1589 a_ptr->flags3 |= (TR3_IGNORE_FIRE);
1590 a_ptr->flags3 |= (TR3_IGNORE_COLD);
1592 /* Store the name */
1593 if (!add_name(&a_ptr->name, head, s)) return (7);
1597 /* There better be a current a_ptr */
1598 else if (!a_ptr) return (3);
1602 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1603 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1604 else if (buf[0] == 'E')
1609 else if (buf[0] == 'E')
1611 /* Acquire the Text */
1614 /* Store the name */
1615 if (!add_name(&a_ptr->name, head, s)) return (7);
1619 /* Process 'D' for "Description" */
1620 else if (buf[0] == 'D')
1625 /* Acquire the text */
1630 /* Acquire the text */
1634 /* Store the text */
1635 if (!add_text(&a_ptr->text, head, s)) return (7);
1639 /* Process 'I' for "Info" (one line only) */
1640 else if (buf[0] == 'I')
1642 int tval, sval, pval;
1644 /* Scan for the values */
1645 if (3 != sscanf(buf+2, "%d:%d:%d",
1646 &tval, &sval, &pval)) return (1);
1648 /* Save the values */
1654 /* Process 'W' for "More Info" (one line only) */
1655 else if (buf[0] == 'W')
1657 int level, rarity, wgt;
1660 /* Scan for the values */
1661 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1662 &level, &rarity, &wgt, &cost)) return (1);
1664 /* Save the values */
1665 a_ptr->level = level;
1666 a_ptr->rarity = rarity;
1667 a_ptr->weight = wgt;
1671 /* Hack -- Process 'P' for "power" and such */
1672 else if (buf[0] == 'P')
1674 int ac, hd1, hd2, th, td, ta;
1676 /* Scan for the values */
1677 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1678 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1688 /* Hack -- Process 'F' for flags */
1689 else if (buf[0] == 'F')
1691 /* Parse every entry textually */
1692 for (s = buf + 2; *s; )
1694 /* Find the end of this entry */
1695 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1697 /* Nuke and skip any dividers */
1701 while ((*t == ' ') || (*t == '|')) t++;
1704 /* Parse this entry */
1705 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
1707 /* Start the next entry */
1723 * Grab one flag in a ego-item_type from a textual string
1725 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
1730 for (i = 0; i < 32; i++)
1732 if (streq(what, k_info_flags1[i]))
1734 e_ptr->flags1 |= (1L << i);
1740 for (i = 0; i < 32; i++)
1742 if (streq(what, k_info_flags2[i]))
1744 e_ptr->flags2 |= (1L << i);
1750 for (i = 0; i < 32; i++)
1752 if (streq(what, k_info_flags3[i]))
1754 e_ptr->flags3 |= (1L << i);
1761 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1763 msg_format("Unknown ego-item flag '%s'.", what);
1775 * Initialize the "e_info" array, by parsing an ascii "template" file
1777 errr parse_e_info(char *buf, header *head)
1784 static ego_item_type *e_ptr = NULL;
1787 /* Just before the first record */
1790 /* Just before the first line */
1794 /* Process 'N' for "New/Number/Name" */
1797 /* Find the colon before the name */
1798 s = strchr(buf+2, ':');
1800 /* Verify that colon */
1803 /* Nuke the colon, advance to the name */
1806 /* Paranoia -- require a name */
1807 if (!*s) return (1);
1812 /* Verify information */
1813 if (i < error_idx) return (4);
1815 /* Verify information */
1816 if (i >= head->info_num) return (2);
1818 /* Save the index */
1821 /* Point at the "info" */
1824 /* Store the name */
1825 if (!add_name(&e_ptr->name, head, s)) return (7);
1829 /* There better be a current e_ptr */
1830 else if (!e_ptr) return (3);
1834 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1835 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
1836 else if (buf[0] == 'E')
1841 else if (buf[0] == 'E')
1843 /* Acquire the Text */
1846 /* Store the name */
1847 if (!add_name(&e_ptr->name, head, s)) return (7);
1852 /* Process 'D' for "Description" */
1853 else if (buf[0] == 'D')
1855 /* Acquire the text */
1858 /* Store the text */
1859 if (!add_text(&e_ptr->text, head, s)) return (7);
1864 /* Process 'X' for "Xtra" (one line only) */
1865 else if (buf[0] == 'X')
1869 /* Scan for the values */
1870 if (2 != sscanf(buf+2, "%d:%d",
1871 &slot, &rating)) return (1);
1873 /* Save the values */
1875 e_ptr->rating = rating;
1878 /* Process 'W' for "More Info" (one line only) */
1879 else if (buf[0] == 'W')
1881 int level, rarity, pad2;
1884 /* Scan for the values */
1885 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1886 &level, &rarity, &pad2, &cost)) return (1);
1888 /* Save the values */
1889 e_ptr->level = level;
1890 e_ptr->rarity = rarity;
1891 /* e_ptr->weight = wgt; */
1895 /* Hack -- Process 'C' for "creation" */
1896 else if (buf[0] == 'C')
1900 /* Scan for the values */
1901 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1902 &th, &td, &ta, &pv)) return (1);
1904 e_ptr->max_to_h = th;
1905 e_ptr->max_to_d = td;
1906 e_ptr->max_to_a = ta;
1907 e_ptr->max_pval = pv;
1910 /* Hack -- Process 'F' for flags */
1911 else if (buf[0] == 'F')
1913 /* Parse every entry textually */
1914 for (s = buf + 2; *s; )
1916 /* Find the end of this entry */
1917 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1919 /* Nuke and skip any dividers */
1923 while ((*t == ' ') || (*t == '|')) t++;
1926 /* Parse this entry */
1927 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
1929 /* Start the next entry */
1943 * Grab one (basic) flag in a monster_race from a textual string
1945 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
1950 for (i = 0; i < 32; i++)
1952 if (streq(what, r_info_flags1[i]))
1954 r_ptr->flags1 |= (1L << i);
1960 for (i = 0; i < 32; i++)
1962 if (streq(what, r_info_flags2[i]))
1964 r_ptr->flags2 |= (1L << i);
1970 for (i = 0; i < 32; i++)
1972 if (streq(what, r_info_flags3[i]))
1974 r_ptr->flags3 |= (1L << i);
1980 for (i = 0; i < 32; i++)
1982 if (streq(what, r_info_flags7[i]))
1984 r_ptr->flags7 |= (1L << i);
1990 for (i = 0; i < 32; i++)
1992 if (streq(what, r_info_flags8[i]))
1994 r_ptr->flags8 |= (1L << i);
2000 for (i = 0; i < 32; i++)
2002 if (streq(what, r_info_flags9[i]))
2004 r_ptr->flags9 |= (1L << i);
2011 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2013 msg_format("Unknown monster flag '%s'.", what);
2023 * Grab one (spell) flag in a monster_race from a textual string
2025 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2030 for (i = 0; i < 32; i++)
2032 if (streq(what, r_info_flags4[i]))
2034 r_ptr->flags4 |= (1L << i);
2040 for (i = 0; i < 32; i++)
2042 if (streq(what, r_info_flags5[i]))
2044 r_ptr->flags5 |= (1L << i);
2050 for (i = 0; i < 32; i++)
2052 if (streq(what, r_info_flags6[i]))
2054 r_ptr->flags6 |= (1L << i);
2061 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2063 msg_format("Unknown monster flag '%s'.", what);
2075 * Initialize the "r_info" array, by parsing an ascii "template" file
2077 errr parse_r_info(char *buf, header *head)
2084 static monster_race *r_ptr = NULL;
2087 /* Process 'N' for "New/Number/Name" */
2090 /* Find the colon before the name */
2091 s = strchr(buf+2, ':');
2093 /* Verify that colon */
2096 /* Nuke the colon, advance to the name */
2099 /* Paranoia -- require a name */
2100 if (!*s) return (1);
2105 /* Verify information */
2106 if (i < error_idx) return (4);
2108 /* Verify information */
2109 if (i >= head->info_num) return (2);
2111 /* Save the index */
2114 /* Point at the "info" */
2117 /* Store the name */
2118 if (!add_name(&r_ptr->name, head, s)) return (7);
2122 /* There better be a current r_ptr */
2123 else if (!r_ptr) return (3);
2127 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2128 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2129 else if (buf[0] == 'E')
2131 /* Acquire the Text */
2134 /* Store the name */
2135 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2138 else if (buf[0] == 'E')
2140 /* Acquire the Text */
2143 /* Store the name */
2144 if (!add_name(&r_ptr->name, head, s)) return (7);
2147 /* Process 'D' for "Description" */
2148 else if (buf[0] == 'D')
2153 /* Acquire the text */
2158 /* Acquire the text */
2162 /* Store the text */
2163 if (!add_text(&r_ptr->text, head, s)) return (7);
2166 /* Process 'G' for "Graphics" (one line only) */
2167 else if (buf[0] == 'G')
2173 if (!buf[2]) return (1);
2174 if (!buf[3]) return (1);
2175 if (!buf[4]) return (1);
2177 /* Extract the char */
2180 /* Extract the attr */
2181 tmp = color_char_to_attr(buf[4]);
2184 if (tmp < 0) return (1);
2186 /* Save the values */
2187 r_ptr->d_char = sym;
2188 r_ptr->d_attr = tmp;
2191 /* Process 'I' for "Info" (one line only) */
2192 else if (buf[0] == 'I')
2194 int spd, hp1, hp2, aaf, ac, slp;
2196 /* Scan for the other values */
2197 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2198 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2200 /* Save the values */
2209 /* Process 'W' for "More Info" (one line only) */
2210 else if (buf[0] == 'W')
2217 /* Scan for the values */
2218 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2219 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2221 /* Save the values */
2223 r_ptr->rarity = rar;
2226 r_ptr->next_exp = nextexp;
2227 r_ptr->next_r_idx = nextmon;
2230 /* Process 'B' for "Blows" (up to four lines) */
2231 else if (buf[0] == 'B')
2235 /* Find the next empty blow slot (if any) */
2236 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2238 /* Oops, no more slots */
2239 if (i == 4) return (1);
2241 /* Analyze the first field */
2242 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2244 /* Terminate the field (if necessary) */
2245 if (*t == ':') *t++ = '\0';
2247 /* Analyze the method */
2248 for (n1 = 0; r_info_blow_method[n1]; n1++)
2250 if (streq(s, r_info_blow_method[n1])) break;
2253 /* Invalid method */
2254 if (!r_info_blow_method[n1]) return (1);
2256 /* Analyze the second field */
2257 for (s = t; *t && (*t != ':'); t++) /* loop */;
2259 /* Terminate the field (if necessary) */
2260 if (*t == ':') *t++ = '\0';
2262 /* Analyze effect */
2263 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2265 if (streq(s, r_info_blow_effect[n2])) break;
2268 /* Invalid effect */
2269 if (!r_info_blow_effect[n2]) return (1);
2271 /* Analyze the third field */
2272 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2274 /* Terminate the field (if necessary) */
2275 if (*t == 'd') *t++ = '\0';
2277 /* Save the method */
2278 r_ptr->blow[i].method = n1;
2280 /* Save the effect */
2281 r_ptr->blow[i].effect = n2;
2283 /* Extract the damage dice and sides */
2284 r_ptr->blow[i].d_dice = atoi(s);
2285 r_ptr->blow[i].d_side = atoi(t);
2288 /* Process 'F' for "Basic Flags" (multiple lines) */
2289 else if (buf[0] == 'F')
2291 /* Parse every entry */
2292 for (s = buf + 2; *s; )
2294 /* Find the end of this entry */
2295 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2297 /* Nuke and skip any dividers */
2301 while (*t == ' ' || *t == '|') t++;
2304 /* Parse this entry */
2305 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2307 /* Start the next entry */
2312 /* Process 'S' for "Spell Flags" (multiple lines) */
2313 else if (buf[0] == 'S')
2315 /* Parse every entry */
2316 for (s = buf + 2; *s; )
2318 /* Find the end of this entry */
2319 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2321 /* Nuke and skip any dividers */
2325 while ((*t == ' ') || (*t == '|')) t++;
2328 /* XXX XXX XXX Hack -- Read spell frequency */
2329 if (1 == sscanf(s, "1_IN_%d", &i))
2331 /* Extract a "frequency" */
2332 r_ptr->freq_spell = r_ptr->freq_inate = 100 / i;
2334 /* Start at next entry */
2341 /* Parse this entry */
2342 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2344 /* Start the next entry */
2359 * Grab one flag for a dungeon type from a textual string
2361 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2366 for (i = 0; i < 32; i++)
2368 if (streq(what, d_info_flags1[i]))
2370 d_ptr->flags1 |= (1L << i);
2377 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2379 msg_format("Unknown dungeon type flag '%s'.", what);
2387 * Grab one (basic) flag in a monster_race from a textual string
2389 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2394 for (i = 0; i < 32; i++)
2396 if (streq(what, r_info_flags1[i]))
2398 d_ptr->mflags1 |= (1L << i);
2404 for (i = 0; i < 32; i++)
2406 if (streq(what, r_info_flags2[i]))
2408 d_ptr->mflags2 |= (1L << i);
2414 for (i = 0; i < 32; i++)
2416 if (streq(what, r_info_flags3[i]))
2418 d_ptr->mflags3 |= (1L << i);
2424 for (i = 0; i < 32; i++)
2426 if (streq(what, r_info_flags7[i]))
2428 d_ptr->mflags7 |= (1L << i);
2434 for (i = 0; i < 32; i++)
2436 if (streq(what, r_info_flags8[i]))
2438 d_ptr->mflags8 |= (1L << i);
2444 for (i = 0; i < 32; i++)
2446 if (streq(what, r_info_flags9[i]))
2448 d_ptr->mflags9 |= (1L << i);
2455 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2457 msg_format("Unknown monster flag '%s'.", what);
2465 * Grab one (spell) flag in a monster_race from a textual string
2467 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2472 for (i = 0; i < 32; i++)
2474 if (streq(what, r_info_flags4[i]))
2476 d_ptr->mflags4 |= (1L << i);
2482 for (i = 0; i < 32; i++)
2484 if (streq(what, r_info_flags5[i]))
2486 d_ptr->mflags5 |= (1L << i);
2492 for (i = 0; i < 32; i++)
2494 if (streq(what, r_info_flags6[i]))
2496 d_ptr->mflags6 |= (1L << i);
2503 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2505 msg_format("Unknown monster flag '%s'.", what);
2513 * Initialize the "d_info" array, by parsing an ascii "template" file
2515 errr parse_d_info(char *buf, header *head)
2522 static dungeon_info_type *d_ptr = NULL;
2525 /* Process 'N' for "New/Number/Name" */
2528 /* Find the colon before the name */
2529 s = strchr(buf+2, ':');
2531 /* Verify that colon */
2534 /* Nuke the colon, advance to the name */
2537 /* Paranoia -- require a name */
2538 if (!*s) return (1);
2543 /* Verify information */
2544 if (i < error_idx) return (4);
2546 /* Verify information */
2547 if (i >= head->info_num) return (2);
2549 /* Save the index */
2552 /* Point at the "info" */
2555 /* Store the name */
2556 if (!add_name(&d_ptr->name, head, s)) return (7);
2561 else if (buf[0] == 'E') return (0);
2563 else if (buf[0] == 'E')
2565 /* Acquire the Text */
2568 /* Store the name */
2569 if (!add_name(&d_ptr->name, head, s)) return (7);
2573 /* Process 'D' for "Description */
2574 else if (buf[0] == 'D')
2579 /* Acquire the text */
2584 /* Acquire the text */
2588 /* Store the text */
2589 if (!add_text(&d_ptr->text, head, s)) return (7);
2592 /* Process 'W' for "More Info" (one line only) */
2593 else if (buf[0] == 'W')
2595 int min_lev, max_lev;
2597 int min_alloc, max_chance;
2598 int obj_good, obj_great;
2601 /* Scan for the values */
2602 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2603 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2605 /* Save the values */
2606 d_ptr->mindepth = min_lev;
2607 d_ptr->maxdepth = max_lev;
2608 d_ptr->min_plev = min_plev;
2610 d_ptr->min_m_alloc_level = min_alloc;
2611 d_ptr->max_m_alloc_chance = max_chance;
2612 d_ptr->obj_good = obj_good;
2613 d_ptr->obj_great = obj_great;
2618 /* Process 'P' for "Place Info" */
2619 else if (buf[0] == 'P')
2623 /* Scan for the values */
2624 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
2626 /* Save the values */
2631 /* Process 'L' for "fLoor type" (one line only) */
2632 else if (buf[0] == 'L')
2638 /* Scan for the values */
2639 if (7 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d",
2640 &f1, &p1, &f2, &p2, &f3, &p3, &tunnel)) return (1);
2642 /* Save the values */
2644 d_ptr->floor_percent1 = p1;
2646 d_ptr->floor_percent2 = p2;
2648 d_ptr->floor_percent3 = p3;
2649 d_ptr->tunnel_percent = tunnel;
2652 /* Process 'A' for "wAll type" (one line only) */
2653 else if (buf[0] == 'A')
2655 int w1, w2, w3, outer, inner, stream1, stream2;
2658 /* Scan for the values */
2659 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
2660 &w1, &p1, &w2, &p2, &w3, &p3, &outer, &inner, &stream1, &stream2)) return (1);
2662 /* Save the values */
2663 d_ptr->fill_type1 = w1;
2664 d_ptr->fill_percent1 = p1;
2665 d_ptr->fill_type2 = w2;
2666 d_ptr->fill_percent2 = p2;
2667 d_ptr->fill_type3 = w3;
2668 d_ptr->fill_percent3 = p3;
2669 d_ptr->outer_wall = outer;
2670 d_ptr->inner_wall = inner;
2671 d_ptr->stream1 = stream1;
2672 d_ptr->stream2 = stream2;
2675 /* Process 'F' for "Dungeon Flags" (multiple lines) */
2676 else if (buf[0] == 'F')
2678 int artif = 0, monst = 0;
2680 /* Parse every entry */
2681 for (s = buf + 2; *s; )
2683 /* Find the end of this entry */
2684 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2686 /* Nuke and skip any dividers */
2690 while (*t == ' ' || *t == '|') t++;
2693 /* XXX XXX XXX Hack -- Read Final Artifact */
2694 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
2696 /* Extract a "Final Artifact" */
2697 d_ptr->final_artifact = artif;
2699 /* Start at next entry */
2706 /* XXX XXX XXX Hack -- Read Final Object */
2707 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
2709 /* Extract a "Final Artifact" */
2710 d_ptr->final_object = artif;
2712 /* Start at next entry */
2719 /* XXX XXX XXX Hack -- Read Artifact Guardian */
2720 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
2722 /* Extract a "Artifact Guardian" */
2723 d_ptr->final_guardian = monst;
2725 /* Start at next entry */
2732 /* XXX XXX XXX Hack -- Read Special Percentage */
2733 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
2735 /* Extract a "Special %" */
2736 d_ptr->special_div = monst;
2738 /* Start at next entry */
2745 /* Parse this entry */
2746 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
2748 /* Start the next entry */
2753 /* Process 'M' for "Basic Flags" (multiple lines) */
2754 else if (buf[0] == 'M')
2756 byte r_char_number = 0, r_char;
2758 /* Parse every entry */
2759 for (s = buf + 2; *s; )
2761 /* Find the end of this entry */
2762 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2764 /* Nuke and skip any dividers */
2768 while (*t == ' ' || *t == '|') t++;
2771 /* XXX XXX XXX Hack -- Read monster symbols */
2772 if (1 == sscanf(s, "R_CHAR_%c", &r_char))
2774 /* Limited to 5 races */
2775 if(r_char_number >= 5) continue;
2777 /* Extract a "frequency" */
2778 d_ptr->r_char[r_char_number++] = r_char;
2780 /* Start at next entry */
2787 /* Parse this entry */
2788 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
2790 /* Start the next entry */
2795 /* Process 'S' for "Spell Flags" (multiple lines) */
2796 else if (buf[0] == 'S')
2798 /* Parse every entry */
2799 for (s = buf + 2; *s; )
2801 /* Find the end of this entry */
2802 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2804 /* Nuke and skip any dividers */
2808 while ((*t == ' ') || (*t == '|')) t++;
2811 /* XXX XXX XXX Hack -- Read spell frequency */
2812 if (1 == sscanf(s, "1_IN_%d", &i))
2814 /* Start at next entry */
2821 /* Parse this entry */
2822 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
2824 /* Start the next entry */
2837 #else /* ALLOW_TEMPLATES */
2843 #endif /* ALLOW_TEMPLATES */
2846 /* Random dungeon grid effects */
2847 #define RANDOM_NONE 0x00
2848 #define RANDOM_FEATURE 0x01
2849 #define RANDOM_MONSTER 0x02
2850 #define RANDOM_OBJECT 0x04
2851 #define RANDOM_EGO 0x08
2852 #define RANDOM_ARTIFACT 0x10
2853 #define RANDOM_TRAP 0x20
2856 typedef struct dungeon_grid dungeon_grid;
2860 int feature; /* Terrain feature */
2861 int monster; /* Monster */
2862 int object; /* Object */
2863 int ego; /* Ego-Item */
2864 int artifact; /* Artifact */
2865 int trap; /* Trap */
2866 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
2867 int special; /* Reserved for special terrain info */
2868 int random; /* Number of the random effect */
2872 static dungeon_grid letter[255];
2876 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
2878 static errr parse_line_feature(char *buf)
2884 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
2886 /* Tokenize the line */
2887 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
2889 /* Letter to assign */
2890 int index = zz[0][0];
2892 /* Reset the info for the letter */
2893 letter[index].feature = 0;
2894 letter[index].monster = 0;
2895 letter[index].object = 0;
2896 letter[index].ego = 0;
2897 letter[index].artifact = 0;
2898 letter[index].trap = 0;
2899 letter[index].cave_info = 0;
2900 letter[index].special = 0;
2901 letter[index].random = 0;
2907 letter[index].special = atoi(zz[8]);
2911 if (zz[7][0] == '*')
2913 letter[index].random |= RANDOM_TRAP;
2918 letter[index].trap = atoi(zz[7]);
2923 letter[index].trap = atoi(zz[7]);
2928 if (zz[6][0] == '*')
2930 letter[index].random |= RANDOM_ARTIFACT;
2935 letter[index].artifact = atoi(zz[6]);
2940 letter[index].artifact = atoi(zz[6]);
2945 if (zz[5][0] == '*')
2947 letter[index].random |= RANDOM_EGO;
2952 letter[index].ego = atoi(zz[5]);
2957 letter[index].ego = atoi(zz[5]);
2962 if (zz[4][0] == '*')
2964 letter[index].random |= RANDOM_OBJECT;
2969 letter[index].object = atoi(zz[4]);
2974 letter[index].object = atoi(zz[4]);
2979 if (zz[3][0] == '*')
2981 letter[index].random |= RANDOM_MONSTER;
2985 letter[index].monster = atoi(zz[3]);
2988 else if (zz[3][0] == 'c')
2990 letter[index].monster = - atoi(zz[3]+1);
2994 letter[index].monster = atoi(zz[3]);
2999 letter[index].cave_info = atoi(zz[2]);
3003 if (zz[1][0] == '*')
3005 letter[index].random |= RANDOM_FEATURE;
3009 letter[index].feature = atoi(zz[1]);
3014 letter[index].feature = atoi(zz[1]);
3027 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3029 static errr parse_line_building(char *buf)
3045 /* Get the building number */
3048 /* Find the colon after the building number */
3051 /* Verify that colon */
3054 /* Nuke the colon, advance to the sub-index */
3057 /* Paranoia -- require a sub-index */
3058 if (!*s) return (1);
3060 /* Building definition sub-index */
3063 /* Building name, owner, race */
3066 if (tokenize(s + 2, 3, zz, 0) == 3)
3068 /* Name of the building */
3069 strcpy(building[index].name, zz[0]);
3071 /* Name of the owner */
3072 strcpy(building[index].owner_name, zz[1]);
3074 /* Race of the owner */
3075 strcpy(building[index].owner_race, zz[2]);
3080 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3083 /* Building Action */
3086 if (tokenize(s + 2, 8, zz, 0) >= 7)
3088 /* Index of the action */
3089 int action_index = atoi(zz[0]);
3091 /* Name of the action */
3092 strcpy(building[index].act_names[action_index], zz[1]);
3094 /* Cost of the action for members */
3095 building[index].member_costs[action_index] = atoi(zz[2]);
3097 /* Cost of the action for non-members */
3098 building[index].other_costs[action_index] = atoi(zz[3]);
3100 /* Letter assigned to the action */
3101 building[index].letters[action_index] = zz[4][0];
3104 building[index].actions[action_index] = atoi(zz[5]);
3106 /* Action restriction */
3107 building[index].action_restr[action_index] = atoi(zz[6]);
3112 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3115 /* Building Classes */
3118 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3120 for (i = 0; i < MAX_CLASS; i++)
3122 building[index].member_class[i] = atoi(zz[i]);
3128 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3131 /* Building Races */
3134 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3136 for (i = 0; i < MAX_RACES; i++)
3138 building[index].member_race[i] = atoi(zz[i]);
3144 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3147 /* Building Realms */
3150 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3152 for (i = 0; i < MAX_MAGIC; i++)
3154 building[index].member_realm[i+1] = atoi(zz[i]);
3160 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3165 /* Ignore scripts */
3171 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3180 * Parse a sub-file of the "extra info"
3182 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3189 /* Skip "empty" lines */
3190 if (!buf[0]) return (0);
3192 /* Skip "blank" lines */
3193 if (isspace(buf[0])) return (0);
3196 if (buf[0] == '#') return (0);
3198 /* Require "?:*" format */
3199 if (buf[1] != ':') return (1);
3202 /* Process "%:<fname>" */
3205 /* Attempt to Process the given file */
3206 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3209 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3212 return parse_line_feature(buf);
3215 /* Process "D:<dungeon>" -- info for the cave grids */
3216 else if (buf[0] == 'D')
3218 object_type object_type_body;
3220 /* Acquire the text */
3223 /* Length of the text */
3224 int len = strlen(s);
3226 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3228 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3230 /* Access the grid */
3231 cave_type *c_ptr = &cave[*y][*x];
3235 int object_index = letter[idx].object;
3236 int monster_index = letter[idx].monster;
3237 int random = letter[idx].random;
3238 int artifact_index = letter[idx].artifact;
3240 /* Lay down a floor */
3241 c_ptr->feat = letter[idx].feature;
3243 /* Only the features */
3244 if (init_flags & INIT_ONLY_FEATURES) continue;
3247 c_ptr->info = letter[idx].cave_info;
3249 /* Create a monster */
3250 if (random & RANDOM_MONSTER)
3252 monster_level = base_level + monster_index;
3254 place_monster(*y, *x, TRUE, TRUE);
3256 monster_level = base_level;
3258 else if (monster_index)
3260 int old_cur_num, old_max_num;
3263 if (monster_index < 0)
3265 monster_index = -monster_index;
3268 old_cur_num = r_info[monster_index].cur_num;
3269 old_max_num = r_info[monster_index].max_num;
3271 /* Make alive again */
3272 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3274 r_info[monster_index].cur_num = 0;
3275 r_info[monster_index].max_num = 1;
3278 /* Make alive again */
3279 if (r_info[monster_index].flags7 & RF7_UNIQUE_7)
3281 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3283 r_info[monster_index].max_num++;
3288 place_monster_aux(*y, *x, monster_index, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);
3292 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3294 /* Make alive again for real unique monster */
3295 r_info[monster_index].cur_num = old_cur_num;
3296 r_info[monster_index].max_num = old_max_num;
3300 /* Object (and possible trap) */
3301 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3303 object_level = base_level + object_index;
3306 * Random trap and random treasure defined
3307 * 25% chance for trap and 75% chance for object
3309 if (randint0(100) < 75)
3311 place_object(*y, *x, FALSE, FALSE);
3318 object_level = base_level;
3320 else if (random & RANDOM_OBJECT)
3322 object_level = base_level + object_index;
3324 /* Create an out of deep object */
3325 if (randint0(100) < 75)
3326 place_object(*y, *x, FALSE, FALSE);
3327 else if (randint0(100) < 80)
3328 place_object(*y, *x, TRUE, FALSE);
3330 place_object(*y, *x, TRUE, TRUE);
3332 object_level = base_level;
3335 else if (random & RANDOM_TRAP)
3339 else if (object_index)
3341 /* Get local object */
3342 object_type *o_ptr = &object_type_body;
3344 /* Create the item */
3345 object_prep(o_ptr, object_index);
3347 if (o_ptr->tval == TV_GOLD)
3349 coin_type = object_index - OBJ_GOLD_LIST;
3354 /* Apply magic (no messages, no artifacts) */
3355 apply_magic(o_ptr, base_level, FALSE, TRUE, FALSE, FALSE);
3357 (void)drop_near(o_ptr, -1, *y, *x);
3363 if (a_info[artifact_index].cur_num)
3367 object_type *q_ptr = &forge;
3369 object_prep(q_ptr, k_idx);
3371 /* Drop it in the dungeon */
3372 (void)drop_near(q_ptr, -1, *y, *x);
3376 /* Create the artifact */
3377 create_named_art(artifact_index, *y, *x);
3379 a_info[artifact_index].cur_num = 1;
3383 /* Terrain special */
3384 c_ptr->special = letter[idx].special;
3392 /* Process "Q:<number>:<command>:... -- quest info */
3393 else if (buf[0] == 'Q')
3400 num = tokenize(buf + 2, 33, zz, 0);
3404 num = tokenize(buf + 3, 33, zz, 0);
3407 /* Have we enough parameters? */
3408 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3411 q_ptr = &(quest[atoi(zz[0])]);
3413 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3414 if (zz[1][0] == 'Q')
3416 if (init_flags & INIT_ASSIGN)
3418 monster_race *r_ptr;
3419 artifact_type *a_ptr;
3421 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3423 q_ptr->type = atoi(zz[2]);
3424 q_ptr->num_mon = atoi(zz[3]);
3425 q_ptr->cur_num = atoi(zz[4]);
3426 q_ptr->max_num = atoi(zz[5]);
3427 q_ptr->level = atoi(zz[6]);
3428 q_ptr->r_idx = atoi(zz[7]);
3429 q_ptr->k_idx = atoi(zz[8]);
3430 q_ptr->dungeon = atoi(zz[9]);
3433 q_ptr->flags = atoi(zz[10]);
3435 r_ptr = &r_info[q_ptr->r_idx];
3436 if (r_ptr->flags1 & RF1_UNIQUE)
3437 r_ptr->flags1 |= RF1_QUESTOR;
3439 a_ptr = &a_info[q_ptr->k_idx];
3440 a_ptr->flags3 |= TR3_QUESTITEM;
3445 /* Process "Q:<q_index>:N:<name>" -- quest name */
3446 else if (zz[1][0] == 'N')
3448 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3450 strcpy(q_ptr->name, zz[2]);
3456 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3457 else if (zz[1][0] == 'T')
3459 if (init_flags & INIT_SHOW_TEXT)
3461 strcpy(quest_text[quest_text_line], zz[2]);
3469 /* Process "W:<command>: ..." -- info for the wilderness */
3470 else if (buf[0] == 'W')
3472 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3475 /* Process "P:<y>:<x>" -- player position */
3476 else if (buf[0] == 'P')
3478 if (init_flags & INIT_CREATE_DUNGEON)
3480 if (tokenize(buf + 2, 2, zz, 0) == 2)
3482 int panels_x, panels_y;
3484 /* Hack - Set the dungeon size */
3485 panels_y = (*y / SCREEN_HGT);
3486 if (*y % SCREEN_HGT) panels_y++;
3487 cur_hgt = panels_y * SCREEN_HGT;
3489 panels_x = (*x / SCREEN_WID);
3490 if (*x % SCREEN_WID) panels_x++;
3491 cur_wid = panels_x * SCREEN_WID;
3493 /* Choose a panel row */
3494 max_panel_rows = (cur_hgt / SCREEN_HGT) * 2 - 2;
3495 if (max_panel_rows < 0) max_panel_rows = 0;
3497 /* Choose a panel col */
3498 max_panel_cols = (cur_wid / SCREEN_WID) * 2 - 2;
3499 if (max_panel_cols < 0) max_panel_cols = 0;
3501 /* Assume illegal panel */
3502 panel_row = max_panel_rows;
3503 panel_col = max_panel_cols;
3505 /* Place player in a quest level */
3506 if (p_ptr->inside_quest)
3510 /* Delete the monster (if any) */
3511 delete_monster(py, px);
3519 /* Place player in the town */
3520 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3522 p_ptr->oldpy = atoi(zz[0]);
3523 p_ptr->oldpx = atoi(zz[1]);
3531 /* Process "B:<Index>:<Command>:..." -- Building definition */
3532 else if (buf[0] == 'B')
3534 return parse_line_building(buf);
3537 /* Process "M:<type>:<maximum>" -- set maximum values */
3538 else if (buf[0] == 'M')
3540 if (tokenize(buf+2, 2, zz, 0) == 2)
3543 if (zz[0][0] == 'T')
3545 max_towns = atoi(zz[1]);
3548 /* Maximum quests */
3549 else if (zz[0][0] == 'Q')
3551 max_quests = atoi(zz[1]);
3555 else if (zz[0][0] == 'R')
3557 max_r_idx = atoi(zz[1]);
3561 else if (zz[0][0] == 'K')
3563 max_k_idx = atoi(zz[1]);
3567 else if (zz[0][0] == 'V')
3569 max_v_idx = atoi(zz[1]);
3573 else if (zz[0][0] == 'F')
3575 max_f_idx = atoi(zz[1]);
3579 else if (zz[0][0] == 'A')
3581 max_a_idx = atoi(zz[1]);
3585 else if (zz[0][0] == 'E')
3587 max_e_idx = atoi(zz[1]);
3591 else if (zz[0][0] == 'D')
3593 max_d_idx = atoi(zz[1]);
3597 else if (zz[0][0] == 'O')
3599 max_o_idx = atoi(zz[1]);
3603 else if (zz[0][0] == 'M')
3605 max_m_idx = atoi(zz[1]);
3608 /* Wilderness size */
3609 else if (zz[0][0] == 'W')
3611 /* Maximum wild_x_size */
3612 if (zz[0][1] == 'X')
3613 max_wild_x = atoi(zz[1]);
3614 /* Maximum wild_y_size */
3615 if (zz[0][1] == 'Y')
3616 max_wild_y = atoi(zz[1]);
3630 static cptr variant = "ZANGBAND";
3634 * Helper function for "process_dungeon_file()"
3636 static cptr process_dungeon_file_expr(char **sp, char *fp)
3652 while (isspace(*s)) s++;
3670 t = process_dungeon_file_expr(&s, &f);
3679 else if (streq(t, "IOR"))
3682 while (*s && (f != b2))
3684 t = process_dungeon_file_expr(&s, &f);
3685 if (*t && !streq(t, "0")) v = "1";
3690 else if (streq(t, "AND"))
3693 while (*s && (f != b2))
3695 t = process_dungeon_file_expr(&s, &f);
3696 if (*t && streq(t, "0")) v = "0";
3701 else if (streq(t, "NOT"))
3704 while (*s && (f != b2))
3706 t = process_dungeon_file_expr(&s, &f);
3707 if (*t && streq(t, "1")) v = "0";
3712 else if (streq(t, "EQU"))
3715 if (*s && (f != b2))
3717 t = process_dungeon_file_expr(&s, &f);
3719 while (*s && (f != b2))
3722 t = process_dungeon_file_expr(&s, &f);
3723 if (*t && !streq(p, t)) v = "0";
3728 else if (streq(t, "LEQ"))
3731 if (*s && (f != b2))
3733 t = process_dungeon_file_expr(&s, &f);
3735 while (*s && (f != b2))
3738 t = process_dungeon_file_expr(&s, &f);
3739 if (*t && (strcmp(p, t) > 0)) v = "0";
3744 else if (streq(t, "GEQ"))
3747 if (*s && (f != b2))
3749 t = process_dungeon_file_expr(&s, &f);
3751 while (*s && (f != b2))
3754 t = process_dungeon_file_expr(&s, &f);
3755 if (*t && (strcmp(p, t) < 0)) v = "0";
3762 while (*s && (f != b2))
3764 t = process_dungeon_file_expr(&s, &f);
3769 if (f != b2) v = "?x?x?";
3771 /* Extract final and Terminate */
3772 if ((f = *s) != '\0') *s++ = '\0';
3778 /* Accept all printables except spaces and brackets */
3779 while (isprint(*s) && !strchr(" []", *s)) ++s;
3781 /* Extract final and Terminate */
3782 if ((f = *s) != '\0') *s++ = '\0';
3788 if (streq(b+1, "SYS"))
3794 else if (streq(b+1, "GRAF"))
3799 else if (streq(b+1, "MONOCHROME"))
3808 else if (streq(b+1, "RACE"))
3811 v = rp_ptr->E_title;
3818 else if (streq(b+1, "CLASS"))
3821 v = cp_ptr->E_title;
3828 else if (streq(b+1, "REALM1"))
3831 v = E_realm_names[p_ptr->realm1];
3833 v = realm_names[p_ptr->realm1];
3838 else if (streq(b+1, "REALM2"))
3841 v = E_realm_names[p_ptr->realm2];
3843 v = realm_names[p_ptr->realm2];
3848 else if (streq(b+1, "PLAYER"))
3854 else if (streq(b+1, "TOWN"))
3856 sprintf(tmp, "%d", p_ptr->town_num);
3861 else if (streq(b+1, "LEVEL"))
3863 sprintf(tmp, "%d", p_ptr->lev);
3867 /* Current quest number */
3868 else if (streq(b+1, "QUEST_NUMBER"))
3870 sprintf(tmp, "%d", p_ptr->inside_quest);
3874 /* Number of last quest */
3875 else if (streq(b+1, "LEAVING_QUEST"))
3877 sprintf(tmp, "%d", leaving_quest);
3882 else if (prefix(b+1, "QUEST"))
3884 /* "QUEST" uses a special parameter to determine the number of the quest */
3885 sprintf(tmp, "%d", quest[atoi(b+6)].status);
3890 else if (prefix(b+1, "RANDOM"))
3892 /* "RANDOM" uses a special parameter to determine the number of the quest */
3893 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
3898 else if (streq(b+1, "VARIANT"))
3904 else if (streq(b+1, "WILDERNESS"))
3907 sprintf(tmp, "NONE");
3909 sprintf(tmp, "LITE");
3911 sprintf(tmp, "NORMAL");
3934 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
3944 bool bypass = FALSE;
3946 int x = xmin, y = ymin;
3949 /* Build the filename */
3950 path_build(buf, 1024, ANGBAND_DIR_EDIT, name);
3953 fp = my_fopen(buf, "r");
3956 if (!fp) return (-1);
3959 /* Process the file */
3960 while (0 == my_fgets(fp, buf, 1024))
3966 /* Skip "empty" lines */
3967 if (!buf[0]) continue;
3969 /* Skip "blank" lines */
3970 if (isspace(buf[0])) continue;
3973 if (buf[0] == '#') continue;
3976 /* Process "?:<expr>" */
3977 if ((buf[0] == '?') && (buf[1] == ':'))
3986 /* Parse the expr */
3987 v = process_dungeon_file_expr(&s, &f);
3990 bypass = (streq(v, "0") ? TRUE : FALSE);
3996 /* Apply conditionals */
3997 if (bypass) continue;
4000 /* Process "%:<file>" */
4003 /* Process that file if allowed */
4004 (void)process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax);
4011 /* Process the line */
4012 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4024 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4027 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4029 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4031 msg_format("Parsing '%s'.", buf);
4038 /* Close the file */
4048 void write_r_info_txt(void)
4050 int i, j, z, fc, bc;
4058 monster_race *r_ptr;
4060 monster_blow *b_ptr;
4062 FILE *fff = fopen("output.txt", "wt");
4070 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4072 fprintf(fff, "# Version stamp (required)\n\n");
4075 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4078 fprintf(fff, "##### The Player #####\n\n");
4080 for (z = -1; z < alloc_race_size; z++)
4082 /* Output the monsters in order */
4083 i = (z >= 0) ? alloc_race_table[z].index : 0;
4085 /* Acquire the monster */
4088 /* Ignore empty monsters */
4089 if (!strlen(r_name + r_ptr->name)) continue;
4091 /* Ignore useless monsters */
4092 if (i && !r_ptr->speed) continue;
4094 /* Write a note if necessary */
4095 if (i && (!r_ptr->level != !mode))
4100 fprintf(fff, "\n##### Town monsters #####\n\n");
4102 /* Note the dungeon */
4105 fprintf(fff, "\n##### Normal monsters #####\n\n");
4108 /* Record the change */
4109 mode = r_ptr->level;
4112 /* Acquire the flags */
4113 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4114 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4115 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4116 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4117 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4118 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4119 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4120 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4121 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4123 /* Write New/Number/Name */
4124 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4127 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4129 /* Write Information */
4130 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4131 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4133 /* Write more information */
4134 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4137 for(j = 0; j < 4; j++)
4139 b_ptr = &(r_ptr->blow[j]);
4141 /* Stop when done */
4142 if (!b_ptr->method) break;
4144 /* Write the blows */
4145 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4146 r_info_blow_effect[b_ptr->effect],
4147 b_ptr->d_dice, b_ptr->d_side);
4150 /* Extract the flags */
4151 for (fc = 0, j = 0; j < 96; j++)
4153 /* Check this flag */
4154 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4157 /* Extract the extra flags */
4158 for (j = 192; j < 288; j++)
4160 /* Check this flag */
4161 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4164 /* Write the flags */
4165 for (j = 0; j < fc;)
4169 /* Start the line */
4172 for (bc = 0; (bc < 60) && (j < fc); j++)
4176 /* Format the flag */
4177 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4179 /* Add it to the buffer */
4182 /* Note the length */
4186 /* Done with this line; write it */
4187 fprintf(fff, "%s\n", buf);
4190 /* Write Spells if applicable */
4191 if (r_ptr->freq_spell)
4193 /* Write the frequency */
4194 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4196 /* Extract the spell flags */
4197 for (fc = 0, j = 96; j < 192; j++)
4199 /* Check this flag */
4200 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4203 /* Write the flags */
4204 for (j = 0; j < fc;)
4208 /* Start the line */
4211 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4215 /* Format the flag */
4216 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4220 /* Note the length */
4227 /* Done with this line; write it */
4228 fprintf(fff, "%s\n", buf);
4232 /* Acquire the description */
4233 desc = r_text + r_ptr->text;
4234 dlen = strlen(desc);
4236 /* Write Description */
4237 for (j = 0; j < dlen;)
4241 /* Start the line */
4244 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4252 /* Done with this line; write it */
4253 fprintf(fff, "%s\n", buf);
4256 /* Space between entries */