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[] =
93 * Monster Blow Effects
95 static cptr r_info_blow_effect[] =
138 static cptr r_info_flags1[] =
177 static cptr r_info_flags2[] =
216 static cptr r_info_flags3[] =
255 static cptr r_info_flags4[] =
294 static cptr r_info_flags5[] =
333 static cptr r_info_flags6[] =
350 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
373 static cptr r_info_flags7[] =
412 static cptr r_info_flags8[] =
444 "WILD_SWAMP", /* ToDo: Implement Swamp */
450 * Monster race flags - Drops
452 static cptr r_info_flags9[] =
493 static cptr k_info_flags1[] =
532 static cptr k_info_flags2[] =
571 static cptr k_info_flags3[] =
611 static cptr d_info_flags1[] =
649 * Add a text to the text-storage and store offset to it.
651 * Returns FALSE when there isn't enough space available to store
654 static bool add_text(u32b *offset, header *head, cptr buf)
656 /* Hack -- Verify space */
657 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
663 /* Advance and save the text index */
664 *offset = ++head->text_size;
667 /* Append chars to the text */
668 strcpy(head->text_ptr + head->text_size, buf);
670 /* Advance the index */
671 head->text_size += strlen(buf);
679 * Add a name to the name-storage and return an offset to it.
681 * Returns FALSE when there isn't enough space available to store
684 static bool add_name(u32b *offset, header *head, cptr buf)
686 /* Hack -- Verify space */
687 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
693 /* Advance and save the name index */
694 *offset = ++head->name_size;
697 /* Append chars to the names */
698 strcpy(head->name_ptr + head->name_size, buf);
700 /* Advance the index */
701 head->name_size += strlen(buf);
709 * Convert a "color letter" into an "actual" color
710 * The colors are: dwsorgbuDWvyRGBU, as shown below
712 static int color_char_to_attr(char c)
716 case 'd': return (TERM_DARK);
717 case 'w': return (TERM_WHITE);
718 case 's': return (TERM_SLATE);
719 case 'o': return (TERM_ORANGE);
720 case 'r': return (TERM_RED);
721 case 'g': return (TERM_GREEN);
722 case 'b': return (TERM_BLUE);
723 case 'u': return (TERM_UMBER);
725 case 'D': return (TERM_L_DARK);
726 case 'W': return (TERM_L_WHITE);
727 case 'v': return (TERM_VIOLET);
728 case 'y': return (TERM_YELLOW);
729 case 'R': return (TERM_L_RED);
730 case 'G': return (TERM_L_GREEN);
731 case 'B': return (TERM_L_BLUE);
732 case 'U': return (TERM_L_UMBER);
740 /*** Initialize from ascii template files ***/
744 * Initialize an "*_info" array, by parsing an ascii "template" file
746 errr init_info_txt(FILE *fp, char *buf, header *head,
747 parse_info_txt_func parse_info_txt_line)
751 /* Just before the first record */
754 /* Just before the first line */
758 /* Prepare the "fake" stuff */
763 while (0 == my_fgets(fp, buf, 1024))
765 /* Advance the line number */
768 /* Skip comments and blank lines */
769 if (!buf[0] || (buf[0] == '#')) continue;
771 /* Verify correct "colon" format */
772 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
775 /* Hack -- Process 'V' for "Version" */
783 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
788 /* Complete the "name" and "text" sizes */
789 if (head->name_size) head->name_size++;
790 if (head->text_size) head->text_size++;
798 * Initialize the "v_info" array, by parsing an ascii "template" file
800 errr parse_v_info(char *buf, header *head)
806 static vault_type *v_ptr = NULL;
808 /* Process 'N' for "New/Number/Name" */
811 /* Find the colon before the name */
812 s = strchr(buf+2, ':');
814 /* Verify that colon */
817 /* Nuke the colon, advance to the name */
820 /* Paranoia -- require a name */
826 /* Verify information */
827 if (i <= error_idx) return (4);
829 /* Verify information */
830 if (i >= head->info_num) return (2);
835 /* Point at the "info" */
839 if (!add_name(&v_ptr->name, head, s)) return (7);
842 /* There better be a current v_ptr */
843 else if (!v_ptr) return (3);
845 /* Process 'D' for "Description" */
846 else if (buf[0] == 'D')
848 /* Acquire the text */
852 if (!add_text(&v_ptr->text, head, s)) return (7);
855 /* Process 'X' for "Extra info" (one line only) */
856 else if (buf[0] == 'X')
858 int typ, rat, hgt, wid;
860 /* Scan for the values */
861 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
862 &typ, &rat, &hgt, &wid)) return (1);
864 /* Save the values */
881 * Initialize the "s_info" array, by parsing an ascii "template" file
883 errr parse_s_info(char *buf, header *head)
888 static skill_table *s_ptr = NULL;
891 /* Process 'N' for "New/Number/Name" */
897 /* Verify information */
898 if (i <= error_idx) return (4);
900 /* Verify information */
901 if (i >= head->info_num) return (2);
906 /* Point at the "info" */
910 /* There better be a current s_ptr */
911 else if (!s_ptr) return (3);
913 /* Process 'W' for "Weapon exp" */
914 else if (buf[0] == 'W')
916 int tval, sval, start, max;
917 const s16b exp_conv_table[] = { 0, 4000, 6000, 7000, 8000 };
919 /* Scan for the values */
920 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
921 &tval, &sval, &start, &max)) return (1);
923 if (start < 0 || start > 4 || max < 0 || max > 4) return (8);
925 /* Save the values */
926 s_ptr->w_start[tval][sval] = exp_conv_table[start];
927 s_ptr->w_max[tval][sval] = exp_conv_table[max];
930 /* Process 'S' for "Skill exp" */
931 else if (buf[0] == 'S')
935 /* Scan for the values */
936 if (3 != sscanf(buf+2, "%d:%d:%d",
937 &num, &start, &max)) return (1);
939 if (start < 0 || start > 8000 || max < 0 || max > 8000) return (8);
941 /* Save the values */
942 s_ptr->s_start[num] = start;
943 s_ptr->s_max[num] = max;
956 * Initialize the "m_info" array, by parsing an ascii "template" file
958 errr parse_m_info(char *buf, header *head)
965 static player_magic *m_ptr = NULL;
968 static int realm, magic_idx = 0, readable = 0;
971 /* Process 'N' for "New/Number/Name" */
977 /* Verify information */
978 if (i <= error_idx) return (4);
980 /* Verify information */
981 if (i >= head->info_num) return (2);
986 /* Point at the "info" */
990 /* There better be a current m_ptr */
991 else if (!m_ptr) return (3);
993 /* Process 'I' for "Info" (one line only) */
994 else if (buf[0] == 'I')
997 int xtra, type, first, weight;
999 /* Find the colon before the name */
1000 s = strchr(buf+2, ':');
1002 /* Verify that colon */
1005 /* Nuke the colon, advance to the name */
1010 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1011 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1012 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1013 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1014 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1019 /* Find the colon before the name */
1022 /* Verify that colon */
1025 /* Nuke the colon, advance to the name */
1028 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1029 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1030 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1031 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1032 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1033 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1037 /* Scan for the values */
1038 if (4 != sscanf(s, "%x:%d:%d:%d",
1039 &xtra, &type, &first, &weight)) return (1);
1041 m_ptr->spell_xtra = xtra;
1042 m_ptr->spell_type = type;
1043 m_ptr->spell_first = first;
1044 m_ptr->spell_weight = weight;
1048 /* Process 'R' for "Realm" (one line only) */
1049 else if (buf[0] == 'R')
1051 /* Scan for the values */
1052 if (2 != sscanf(buf+2, "%d:%d",
1053 &realm, &readable)) return (1);
1058 else if (buf[0] == 'T')
1060 int level, mana, fail, exp;
1062 if (!readable) return (1);
1063 /* Scan for the values */
1064 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1065 &level, &mana, &fail, &exp)) return (1);
1067 m_ptr->info[realm][magic_idx].slevel = level;
1068 m_ptr->info[realm][magic_idx].smana = mana;
1069 m_ptr->info[realm][magic_idx].sfail = fail;
1070 m_ptr->info[realm][magic_idx].sexp = exp;
1084 * Initialize the "f_info" array, by parsing an ascii "template" file
1086 errr parse_f_info(char *buf, header *head)
1093 static feature_type *f_ptr = NULL;
1096 /* Process 'N' for "New/Number/Name" */
1099 /* Find the colon before the name */
1100 s = strchr(buf+2, ':');
1102 /* Verify that colon */
1105 /* Nuke the colon, advance to the name */
1109 /* Paranoia -- require a name */
1110 if (!*s) return (1);
1116 /* Verify information */
1117 if (i <= error_idx) return (4);
1119 /* Verify information */
1120 if (i >= head->info_num) return (2);
1122 /* Save the index */
1125 /* Point at the "info" */
1129 /* Store the name */
1130 if (!add_name(&f_ptr->name, head, s)) return (7);
1132 /* Default "mimic" */
1136 /* There better be a current f_ptr */
1137 else if (!f_ptr) return (3);
1140 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1141 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1142 else if (buf[0] == 'E')
1147 else if (buf[0] == 'E')
1149 /* Acquire the Text */
1152 /* Store the name */
1153 if (!add_name(&f_ptr->name, head, s)) return (7);
1159 /* Process 'D' for "Description" */
1160 else if (buf[0] == 'D')
1162 /* Acquire the text */
1165 /* Store the text */
1166 if (!add_text(&f_ptr->text, head, s)) return (7);
1172 /* Process 'M' for "Mimic" (one line only) */
1173 else if (buf[0] == 'M')
1177 /* Scan for the values */
1178 if (1 != sscanf(buf+2, "%d",
1179 &mimic)) return (1);
1181 /* Save the values */
1182 f_ptr->mimic = mimic;
1187 /* Process 'G' for "Graphics" (one line only) */
1188 else if (buf[0] == 'G')
1193 if (!buf[2]) return (1);
1194 if (!buf[3]) return (1);
1195 if (!buf[4]) return (1);
1197 /* Extract the color */
1198 tmp = color_char_to_attr(buf[4]);
1201 if (tmp < 0) return (1);
1203 /* Save the values */
1204 f_ptr->d_attr = tmp;
1205 f_ptr->d_char = buf[2];
1218 * Grab one flag in an object_kind from a textual string
1220 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1225 for (i = 0; i < 32; i++)
1227 if (streq(what, k_info_flags1[i]))
1229 k_ptr->flags1 |= (1L << i);
1235 for (i = 0; i < 32; i++)
1237 if (streq(what, k_info_flags2[i]))
1239 k_ptr->flags2 |= (1L << i);
1245 for (i = 0; i < 32; i++)
1247 if (streq(what, k_info_flags3[i]))
1249 k_ptr->flags3 |= (1L << i);
1256 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1258 msg_format("Unknown object flag '%s'.", what);
1268 * Initialize the "k_info" array, by parsing an ascii "template" file
1270 errr parse_k_info(char *buf, header *head)
1277 static object_kind *k_ptr = NULL;
1280 /* Process 'N' for "New/Number/Name" */
1283 /* Find the colon before the name */
1284 s = strchr(buf+2, ':');
1286 /* Verify that colon */
1289 /* Nuke the colon, advance to the name */
1293 /* Paranoia -- require a name */
1294 if (!*s) return (1);
1299 /* Verify information */
1300 if (i <= error_idx) return (4);
1302 /* Verify information */
1303 if (i >= head->info_num) return (2);
1305 /* Save the index */
1308 /* Point at the "info" */
1312 /* Store the name */
1313 if (!add_name(&k_ptr->name, head, s)) return (7);
1317 /* There better be a current k_ptr */
1318 else if (!k_ptr) return (3);
1322 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1323 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1324 else if (buf[0] == 'E')
1329 else if (buf[0] == 'E')
1331 /* Acquire the Text */
1334 /* Store the name */
1335 if (!add_name(&k_ptr->name, head, s)) return (7);
1340 /* Process 'D' for "Description" */
1341 else if (buf[0] == 'D')
1343 /* Acquire the text */
1346 /* Store the text */
1347 if (!add_text(&k_ptr->text, head, s)) return (7);
1353 /* Process 'G' for "Graphics" (one line only) */
1354 else if (buf[0] == 'G')
1360 if (!buf[2]) return (1);
1361 if (!buf[3]) return (1);
1362 if (!buf[4]) return (1);
1364 /* Extract the char */
1367 /* Extract the attr */
1368 tmp = color_char_to_attr(buf[4]);
1371 if (tmp < 0) return (1);
1373 /* Save the values */
1374 k_ptr->d_attr = tmp;
1375 k_ptr->d_char = sym;
1378 /* Process 'I' for "Info" (one line only) */
1379 else if (buf[0] == 'I')
1381 int tval, sval, pval;
1383 /* Scan for the values */
1384 if (3 != sscanf(buf+2, "%d:%d:%d",
1385 &tval, &sval, &pval)) return (1);
1387 /* Save the values */
1393 /* Process 'W' for "More Info" (one line only) */
1394 else if (buf[0] == 'W')
1396 int level, extra, wgt;
1399 /* Scan for the values */
1400 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1401 &level, &extra, &wgt, &cost)) return (1);
1403 /* Save the values */
1404 k_ptr->level = level;
1405 k_ptr->extra = extra;
1406 k_ptr->weight = wgt;
1410 /* Process 'A' for "Allocation" (one line only) */
1411 else if (buf[0] == 'A')
1415 /* XXX XXX XXX Simply read each number following a colon */
1416 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1418 /* Default chance */
1419 k_ptr->chance[i] = 1;
1421 /* Store the attack damage index */
1422 k_ptr->locale[i] = atoi(s+1);
1424 /* Find the slash */
1425 t = strchr(s+1, '/');
1427 /* Find the next colon */
1428 s = strchr(s+1, ':');
1430 /* If the slash is "nearby", use it */
1431 if (t && (!s || t < s))
1433 int chance = atoi(t+1);
1434 if (chance > 0) k_ptr->chance[i] = chance;
1439 /* Hack -- Process 'P' for "power" and such */
1440 else if (buf[0] == 'P')
1442 int ac, hd1, hd2, th, td, ta;
1444 /* Scan for the values */
1445 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1446 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1456 /* Hack -- Process 'F' for flags */
1457 else if (buf[0] == 'F')
1459 /* Parse every entry textually */
1460 for (s = buf + 2; *s; )
1462 /* Find the end of this entry */
1463 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1465 /* Nuke and skip any dividers */
1469 while (*t == ' ' || *t == '|') t++;
1472 /* Parse this entry */
1473 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
1475 /* Start the next entry */
1491 * Grab one flag in an artifact_type from a textual string
1493 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
1498 for (i = 0; i < 32; i++)
1500 if (streq(what, k_info_flags1[i]))
1502 a_ptr->flags1 |= (1L << i);
1508 for (i = 0; i < 32; i++)
1510 if (streq(what, k_info_flags2[i]))
1512 a_ptr->flags2 |= (1L << i);
1518 for (i = 0; i < 32; i++)
1520 if (streq(what, k_info_flags3[i]))
1522 a_ptr->flags3 |= (1L << i);
1529 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1531 msg_format("Unknown artifact flag '%s'.", what);
1543 * Initialize the "a_info" array, by parsing an ascii "template" file
1545 errr parse_a_info(char *buf, header *head)
1552 static artifact_type *a_ptr = NULL;
1555 /* Process 'N' for "New/Number/Name" */
1558 /* Find the colon before the name */
1559 s = strchr(buf+2, ':');
1561 /* Verify that colon */
1564 /* Nuke the colon, advance to the name */
1567 /* Paranoia -- require a name */
1568 if (!*s) return (1);
1573 /* Verify information */
1574 if (i < error_idx) return (4);
1576 /* Verify information */
1577 if (i >= head->info_num) return (2);
1579 /* Save the index */
1582 /* Point at the "info" */
1585 /* Ignore everything */
1586 a_ptr->flags3 |= (TR3_IGNORE_ACID);
1587 a_ptr->flags3 |= (TR3_IGNORE_ELEC);
1588 a_ptr->flags3 |= (TR3_IGNORE_FIRE);
1589 a_ptr->flags3 |= (TR3_IGNORE_COLD);
1591 /* Store the name */
1592 if (!add_name(&a_ptr->name, head, s)) return (7);
1596 /* There better be a current a_ptr */
1597 else if (!a_ptr) return (3);
1601 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1602 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1603 else if (buf[0] == 'E')
1608 else if (buf[0] == 'E')
1610 /* Acquire the Text */
1613 /* Store the name */
1614 if (!add_name(&a_ptr->name, head, s)) return (7);
1618 /* Process 'D' for "Description" */
1619 else if (buf[0] == 'D')
1624 /* Acquire the text */
1629 /* Acquire the text */
1633 /* Store the text */
1634 if (!add_text(&a_ptr->text, head, s)) return (7);
1638 /* Process 'I' for "Info" (one line only) */
1639 else if (buf[0] == 'I')
1641 int tval, sval, pval;
1643 /* Scan for the values */
1644 if (3 != sscanf(buf+2, "%d:%d:%d",
1645 &tval, &sval, &pval)) return (1);
1647 /* Save the values */
1653 /* Process 'W' for "More Info" (one line only) */
1654 else if (buf[0] == 'W')
1656 int level, rarity, wgt;
1659 /* Scan for the values */
1660 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1661 &level, &rarity, &wgt, &cost)) return (1);
1663 /* Save the values */
1664 a_ptr->level = level;
1665 a_ptr->rarity = rarity;
1666 a_ptr->weight = wgt;
1670 /* Hack -- Process 'P' for "power" and such */
1671 else if (buf[0] == 'P')
1673 int ac, hd1, hd2, th, td, ta;
1675 /* Scan for the values */
1676 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1677 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1687 /* Hack -- Process 'F' for flags */
1688 else if (buf[0] == 'F')
1690 /* Parse every entry textually */
1691 for (s = buf + 2; *s; )
1693 /* Find the end of this entry */
1694 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1696 /* Nuke and skip any dividers */
1700 while ((*t == ' ') || (*t == '|')) t++;
1703 /* Parse this entry */
1704 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
1706 /* Start the next entry */
1722 * Grab one flag in a ego-item_type from a textual string
1724 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
1729 for (i = 0; i < 32; i++)
1731 if (streq(what, k_info_flags1[i]))
1733 e_ptr->flags1 |= (1L << i);
1739 for (i = 0; i < 32; i++)
1741 if (streq(what, k_info_flags2[i]))
1743 e_ptr->flags2 |= (1L << i);
1749 for (i = 0; i < 32; i++)
1751 if (streq(what, k_info_flags3[i]))
1753 e_ptr->flags3 |= (1L << i);
1760 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1762 msg_format("Unknown ego-item flag '%s'.", what);
1774 * Initialize the "e_info" array, by parsing an ascii "template" file
1776 errr parse_e_info(char *buf, header *head)
1783 static ego_item_type *e_ptr = NULL;
1786 /* Just before the first record */
1789 /* Just before the first line */
1793 /* Process 'N' for "New/Number/Name" */
1796 /* Find the colon before the name */
1797 s = strchr(buf+2, ':');
1799 /* Verify that colon */
1802 /* Nuke the colon, advance to the name */
1805 /* Paranoia -- require a name */
1806 if (!*s) return (1);
1811 /* Verify information */
1812 if (i < error_idx) return (4);
1814 /* Verify information */
1815 if (i >= head->info_num) return (2);
1817 /* Save the index */
1820 /* Point at the "info" */
1823 /* Store the name */
1824 if (!add_name(&e_ptr->name, head, s)) return (7);
1828 /* There better be a current e_ptr */
1829 else if (!e_ptr) return (3);
1833 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1834 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
1835 else if (buf[0] == 'E')
1840 else if (buf[0] == 'E')
1842 /* Acquire the Text */
1845 /* Store the name */
1846 if (!add_name(&e_ptr->name, head, s)) return (7);
1851 /* Process 'D' for "Description" */
1852 else if (buf[0] == 'D')
1854 /* Acquire the text */
1857 /* Store the text */
1858 if (!add_text(&e_ptr->text, head, s)) return (7);
1863 /* Process 'X' for "Xtra" (one line only) */
1864 else if (buf[0] == 'X')
1868 /* Scan for the values */
1869 if (2 != sscanf(buf+2, "%d:%d",
1870 &slot, &rating)) return (1);
1872 /* Save the values */
1874 e_ptr->rating = rating;
1877 /* Process 'W' for "More Info" (one line only) */
1878 else if (buf[0] == 'W')
1880 int level, rarity, pad2;
1883 /* Scan for the values */
1884 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1885 &level, &rarity, &pad2, &cost)) return (1);
1887 /* Save the values */
1888 e_ptr->level = level;
1889 e_ptr->rarity = rarity;
1890 /* e_ptr->weight = wgt; */
1894 /* Hack -- Process 'C' for "creation" */
1895 else if (buf[0] == 'C')
1899 /* Scan for the values */
1900 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1901 &th, &td, &ta, &pv)) return (1);
1903 e_ptr->max_to_h = th;
1904 e_ptr->max_to_d = td;
1905 e_ptr->max_to_a = ta;
1906 e_ptr->max_pval = pv;
1909 /* Hack -- Process 'F' for flags */
1910 else if (buf[0] == 'F')
1912 /* Parse every entry textually */
1913 for (s = buf + 2; *s; )
1915 /* Find the end of this entry */
1916 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1918 /* Nuke and skip any dividers */
1922 while ((*t == ' ') || (*t == '|')) t++;
1925 /* Parse this entry */
1926 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
1928 /* Start the next entry */
1942 * Grab one (basic) flag in a monster_race from a textual string
1944 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
1949 for (i = 0; i < 32; i++)
1951 if (streq(what, r_info_flags1[i]))
1953 r_ptr->flags1 |= (1L << i);
1959 for (i = 0; i < 32; i++)
1961 if (streq(what, r_info_flags2[i]))
1963 r_ptr->flags2 |= (1L << i);
1969 for (i = 0; i < 32; i++)
1971 if (streq(what, r_info_flags3[i]))
1973 r_ptr->flags3 |= (1L << i);
1979 for (i = 0; i < 32; i++)
1981 if (streq(what, r_info_flags7[i]))
1983 r_ptr->flags7 |= (1L << i);
1989 for (i = 0; i < 32; i++)
1991 if (streq(what, r_info_flags8[i]))
1993 r_ptr->flags8 |= (1L << i);
1999 for (i = 0; i < 32; i++)
2001 if (streq(what, r_info_flags9[i]))
2003 r_ptr->flags9 |= (1L << i);
2010 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2012 msg_format("Unknown monster flag '%s'.", what);
2022 * Grab one (spell) flag in a monster_race from a textual string
2024 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2029 for (i = 0; i < 32; i++)
2031 if (streq(what, r_info_flags4[i]))
2033 r_ptr->flags4 |= (1L << i);
2039 for (i = 0; i < 32; i++)
2041 if (streq(what, r_info_flags5[i]))
2043 r_ptr->flags5 |= (1L << i);
2049 for (i = 0; i < 32; i++)
2051 if (streq(what, r_info_flags6[i]))
2053 r_ptr->flags6 |= (1L << i);
2060 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2062 msg_format("Unknown monster flag '%s'.", what);
2074 * Initialize the "r_info" array, by parsing an ascii "template" file
2076 errr parse_r_info(char *buf, header *head)
2083 static monster_race *r_ptr = NULL;
2086 /* Process 'N' for "New/Number/Name" */
2089 /* Find the colon before the name */
2090 s = strchr(buf+2, ':');
2092 /* Verify that colon */
2095 /* Nuke the colon, advance to the name */
2098 /* Paranoia -- require a name */
2099 if (!*s) return (1);
2104 /* Verify information */
2105 if (i < error_idx) return (4);
2107 /* Verify information */
2108 if (i >= head->info_num) return (2);
2110 /* Save the index */
2113 /* Point at the "info" */
2116 /* Store the name */
2117 if (!add_name(&r_ptr->name, head, s)) return (7);
2121 /* There better be a current r_ptr */
2122 else if (!r_ptr) return (3);
2126 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2127 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2128 else if (buf[0] == 'E')
2130 /* Acquire the Text */
2133 /* Store the name */
2134 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2137 else if (buf[0] == 'E')
2139 /* Acquire the Text */
2142 /* Store the name */
2143 if (!add_name(&r_ptr->name, head, s)) return (7);
2146 /* Process 'D' for "Description" */
2147 else if (buf[0] == 'D')
2152 /* Acquire the text */
2157 /* Acquire the text */
2161 /* Store the text */
2162 if (!add_text(&r_ptr->text, head, s)) return (7);
2165 /* Process 'G' for "Graphics" (one line only) */
2166 else if (buf[0] == 'G')
2172 if (!buf[2]) return (1);
2173 if (!buf[3]) return (1);
2174 if (!buf[4]) return (1);
2176 /* Extract the char */
2179 /* Extract the attr */
2180 tmp = color_char_to_attr(buf[4]);
2183 if (tmp < 0) return (1);
2185 /* Save the values */
2186 r_ptr->d_char = sym;
2187 r_ptr->d_attr = tmp;
2190 /* Process 'I' for "Info" (one line only) */
2191 else if (buf[0] == 'I')
2193 int spd, hp1, hp2, aaf, ac, slp;
2195 /* Scan for the other values */
2196 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2197 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2199 /* Save the values */
2208 /* Process 'W' for "More Info" (one line only) */
2209 else if (buf[0] == 'W')
2216 /* Scan for the values */
2217 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2218 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2220 /* Save the values */
2222 r_ptr->rarity = rar;
2225 r_ptr->next_exp = nextexp;
2226 r_ptr->next_r_idx = nextmon;
2229 /* Process 'B' for "Blows" (up to four lines) */
2230 else if (buf[0] == 'B')
2234 /* Find the next empty blow slot (if any) */
2235 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2237 /* Oops, no more slots */
2238 if (i == 4) return (1);
2240 /* Analyze the first field */
2241 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2243 /* Terminate the field (if necessary) */
2244 if (*t == ':') *t++ = '\0';
2246 /* Analyze the method */
2247 for (n1 = 0; r_info_blow_method[n1]; n1++)
2249 if (streq(s, r_info_blow_method[n1])) break;
2252 /* Invalid method */
2253 if (!r_info_blow_method[n1]) return (1);
2255 /* Analyze the second field */
2256 for (s = t; *t && (*t != ':'); t++) /* loop */;
2258 /* Terminate the field (if necessary) */
2259 if (*t == ':') *t++ = '\0';
2261 /* Analyze effect */
2262 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2264 if (streq(s, r_info_blow_effect[n2])) break;
2267 /* Invalid effect */
2268 if (!r_info_blow_effect[n2]) return (1);
2270 /* Analyze the third field */
2271 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2273 /* Terminate the field (if necessary) */
2274 if (*t == 'd') *t++ = '\0';
2276 /* Save the method */
2277 r_ptr->blow[i].method = n1;
2279 /* Save the effect */
2280 r_ptr->blow[i].effect = n2;
2282 /* Extract the damage dice and sides */
2283 r_ptr->blow[i].d_dice = atoi(s);
2284 r_ptr->blow[i].d_side = atoi(t);
2287 /* Process 'F' for "Basic Flags" (multiple lines) */
2288 else if (buf[0] == 'F')
2290 /* Parse every entry */
2291 for (s = buf + 2; *s; )
2293 /* Find the end of this entry */
2294 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2296 /* Nuke and skip any dividers */
2300 while (*t == ' ' || *t == '|') t++;
2303 /* Parse this entry */
2304 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2306 /* Start the next entry */
2311 /* Process 'S' for "Spell Flags" (multiple lines) */
2312 else if (buf[0] == 'S')
2314 /* Parse every entry */
2315 for (s = buf + 2; *s; )
2317 /* Find the end of this entry */
2318 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2320 /* Nuke and skip any dividers */
2324 while ((*t == ' ') || (*t == '|')) t++;
2327 /* XXX XXX XXX Hack -- Read spell frequency */
2328 if (1 == sscanf(s, "1_IN_%d", &i))
2330 /* Extract a "frequency" */
2331 r_ptr->freq_spell = r_ptr->freq_inate = 100 / i;
2333 /* Start at next entry */
2340 /* Parse this entry */
2341 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2343 /* Start the next entry */
2358 * Grab one flag for a dungeon type from a textual string
2360 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2365 for (i = 0; i < 32; i++)
2367 if (streq(what, d_info_flags1[i]))
2369 d_ptr->flags1 |= (1L << i);
2376 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2378 msg_format("Unknown dungeon type flag '%s'.", what);
2386 * Grab one (basic) flag in a monster_race from a textual string
2388 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2393 for (i = 0; i < 32; i++)
2395 if (streq(what, r_info_flags1[i]))
2397 d_ptr->mflags1 |= (1L << i);
2403 for (i = 0; i < 32; i++)
2405 if (streq(what, r_info_flags2[i]))
2407 d_ptr->mflags2 |= (1L << i);
2413 for (i = 0; i < 32; i++)
2415 if (streq(what, r_info_flags3[i]))
2417 d_ptr->mflags3 |= (1L << i);
2423 for (i = 0; i < 32; i++)
2425 if (streq(what, r_info_flags7[i]))
2427 d_ptr->mflags7 |= (1L << i);
2433 for (i = 0; i < 32; i++)
2435 if (streq(what, r_info_flags8[i]))
2437 d_ptr->mflags8 |= (1L << i);
2443 for (i = 0; i < 32; i++)
2445 if (streq(what, r_info_flags9[i]))
2447 d_ptr->mflags9 |= (1L << i);
2454 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2456 msg_format("Unknown monster flag '%s'.", what);
2464 * Grab one (spell) flag in a monster_race from a textual string
2466 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2471 for (i = 0; i < 32; i++)
2473 if (streq(what, r_info_flags4[i]))
2475 d_ptr->mflags4 |= (1L << i);
2481 for (i = 0; i < 32; i++)
2483 if (streq(what, r_info_flags5[i]))
2485 d_ptr->mflags5 |= (1L << i);
2491 for (i = 0; i < 32; i++)
2493 if (streq(what, r_info_flags6[i]))
2495 d_ptr->mflags6 |= (1L << i);
2502 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2504 msg_format("Unknown monster flag '%s'.", what);
2512 * Initialize the "d_info" array, by parsing an ascii "template" file
2514 errr parse_d_info(char *buf, header *head)
2521 static dungeon_info_type *d_ptr = NULL;
2524 /* Process 'N' for "New/Number/Name" */
2527 /* Find the colon before the name */
2528 s = strchr(buf+2, ':');
2530 /* Verify that colon */
2533 /* Nuke the colon, advance to the name */
2536 /* Paranoia -- require a name */
2537 if (!*s) return (1);
2542 /* Verify information */
2543 if (i < error_idx) return (4);
2545 /* Verify information */
2546 if (i >= head->info_num) return (2);
2548 /* Save the index */
2551 /* Point at the "info" */
2554 /* Store the name */
2555 if (!add_name(&d_ptr->name, head, s)) return (7);
2560 else if (buf[0] == 'E') return (0);
2562 else if (buf[0] == 'E')
2564 /* Acquire the Text */
2567 /* Store the name */
2568 if (!add_name(&d_ptr->name, head, s)) return (7);
2572 /* Process 'D' for "Description */
2573 else if (buf[0] == 'D')
2578 /* Acquire the text */
2583 /* Acquire the text */
2587 /* Store the text */
2588 if (!add_text(&d_ptr->text, head, s)) return (7);
2591 /* Process 'W' for "More Info" (one line only) */
2592 else if (buf[0] == 'W')
2594 int min_lev, max_lev;
2596 int min_alloc, max_chance;
2597 int obj_good, obj_great;
2600 /* Scan for the values */
2601 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2602 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2604 /* Save the values */
2605 d_ptr->mindepth = min_lev;
2606 d_ptr->maxdepth = max_lev;
2607 d_ptr->min_plev = min_plev;
2609 d_ptr->min_m_alloc_level = min_alloc;
2610 d_ptr->max_m_alloc_chance = max_chance;
2611 d_ptr->obj_good = obj_good;
2612 d_ptr->obj_great = obj_great;
2617 /* Process 'P' for "Place Info" */
2618 else if (buf[0] == 'P')
2622 /* Scan for the values */
2623 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
2625 /* Save the values */
2630 /* Process 'L' for "fLoor type" (one line only) */
2631 else if (buf[0] == 'L')
2637 /* Scan for the values */
2638 if (7 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d",
2639 &f1, &p1, &f2, &p2, &f3, &p3, &tunnel)) return (1);
2641 /* Save the values */
2643 d_ptr->floor_percent1 = p1;
2645 d_ptr->floor_percent2 = p2;
2647 d_ptr->floor_percent3 = p3;
2648 d_ptr->tunnel_percent = tunnel;
2651 /* Process 'A' for "wAll type" (one line only) */
2652 else if (buf[0] == 'A')
2654 int w1, w2, w3, outer, inner, stream1, stream2;
2657 /* Scan for the values */
2658 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
2659 &w1, &p1, &w2, &p2, &w3, &p3, &outer, &inner, &stream1, &stream2)) return (1);
2661 /* Save the values */
2662 d_ptr->fill_type1 = w1;
2663 d_ptr->fill_percent1 = p1;
2664 d_ptr->fill_type2 = w2;
2665 d_ptr->fill_percent2 = p2;
2666 d_ptr->fill_type3 = w3;
2667 d_ptr->fill_percent3 = p3;
2668 d_ptr->outer_wall = outer;
2669 d_ptr->inner_wall = inner;
2670 d_ptr->stream1 = stream1;
2671 d_ptr->stream2 = stream2;
2674 /* Process 'F' for "Dungeon Flags" (multiple lines) */
2675 else if (buf[0] == 'F')
2677 int artif = 0, monst = 0;
2679 /* Parse every entry */
2680 for (s = buf + 2; *s; )
2682 /* Find the end of this entry */
2683 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2685 /* Nuke and skip any dividers */
2689 while (*t == ' ' || *t == '|') t++;
2692 /* XXX XXX XXX Hack -- Read Final Artifact */
2693 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
2695 /* Extract a "Final Artifact" */
2696 d_ptr->final_artifact = artif;
2698 /* Start at next entry */
2705 /* XXX XXX XXX Hack -- Read Final Object */
2706 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
2708 /* Extract a "Final Artifact" */
2709 d_ptr->final_object = artif;
2711 /* Start at next entry */
2718 /* XXX XXX XXX Hack -- Read Artifact Guardian */
2719 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
2721 /* Extract a "Artifact Guardian" */
2722 d_ptr->final_guardian = monst;
2724 /* Start at next entry */
2731 /* XXX XXX XXX Hack -- Read Special Percentage */
2732 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
2734 /* Extract a "Special %" */
2735 d_ptr->special_div = monst;
2737 /* Start at next entry */
2744 /* Parse this entry */
2745 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
2747 /* Start the next entry */
2752 /* Process 'M' for "Basic Flags" (multiple lines) */
2753 else if (buf[0] == 'M')
2755 byte r_char_number = 0, r_char;
2757 /* Parse every entry */
2758 for (s = buf + 2; *s; )
2760 /* Find the end of this entry */
2761 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2763 /* Nuke and skip any dividers */
2767 while (*t == ' ' || *t == '|') t++;
2770 /* XXX XXX XXX Hack -- Read monster symbols */
2771 if (1 == sscanf(s, "R_CHAR_%c", &r_char))
2773 /* Limited to 5 races */
2774 if(r_char_number >= 5) continue;
2776 /* Extract a "frequency" */
2777 d_ptr->r_char[r_char_number++] = r_char;
2779 /* Start at next entry */
2786 /* Parse this entry */
2787 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
2789 /* Start the next entry */
2794 /* Process 'S' for "Spell Flags" (multiple lines) */
2795 else if (buf[0] == 'S')
2797 /* Parse every entry */
2798 for (s = buf + 2; *s; )
2800 /* Find the end of this entry */
2801 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2803 /* Nuke and skip any dividers */
2807 while ((*t == ' ') || (*t == '|')) t++;
2810 /* XXX XXX XXX Hack -- Read spell frequency */
2811 if (1 == sscanf(s, "1_IN_%d", &i))
2813 /* Start at next entry */
2820 /* Parse this entry */
2821 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
2823 /* Start the next entry */
2836 #else /* ALLOW_TEMPLATES */
2842 #endif /* ALLOW_TEMPLATES */
2845 /* Random dungeon grid effects */
2846 #define RANDOM_NONE 0x00
2847 #define RANDOM_FEATURE 0x01
2848 #define RANDOM_MONSTER 0x02
2849 #define RANDOM_OBJECT 0x04
2850 #define RANDOM_EGO 0x08
2851 #define RANDOM_ARTIFACT 0x10
2852 #define RANDOM_TRAP 0x20
2855 typedef struct dungeon_grid dungeon_grid;
2859 int feature; /* Terrain feature */
2860 int monster; /* Monster */
2861 int object; /* Object */
2862 int ego; /* Ego-Item */
2863 int artifact; /* Artifact */
2864 int trap; /* Trap */
2865 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
2866 int special; /* Reserved for special terrain info */
2867 int random; /* Number of the random effect */
2871 static dungeon_grid letter[255];
2875 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
2877 static errr parse_line_feature(char *buf)
2883 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
2885 /* Tokenize the line */
2886 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
2888 /* Letter to assign */
2889 int index = zz[0][0];
2891 /* Reset the info for the letter */
2892 letter[index].feature = 0;
2893 letter[index].monster = 0;
2894 letter[index].object = 0;
2895 letter[index].ego = 0;
2896 letter[index].artifact = 0;
2897 letter[index].trap = 0;
2898 letter[index].cave_info = 0;
2899 letter[index].special = 0;
2900 letter[index].random = 0;
2906 letter[index].special = atoi(zz[8]);
2910 if (zz[7][0] == '*')
2912 letter[index].random |= RANDOM_TRAP;
2917 letter[index].trap = atoi(zz[7]);
2922 letter[index].trap = atoi(zz[7]);
2927 if (zz[6][0] == '*')
2929 letter[index].random |= RANDOM_ARTIFACT;
2934 letter[index].artifact = atoi(zz[6]);
2939 letter[index].artifact = atoi(zz[6]);
2944 if (zz[5][0] == '*')
2946 letter[index].random |= RANDOM_EGO;
2951 letter[index].ego = atoi(zz[5]);
2956 letter[index].ego = atoi(zz[5]);
2961 if (zz[4][0] == '*')
2963 letter[index].random |= RANDOM_OBJECT;
2968 letter[index].object = atoi(zz[4]);
2973 letter[index].object = atoi(zz[4]);
2978 if (zz[3][0] == '*')
2980 letter[index].random |= RANDOM_MONSTER;
2984 letter[index].monster = atoi(zz[3]);
2987 else if (zz[3][0] == 'c')
2989 letter[index].monster = - atoi(zz[3]+1);
2993 letter[index].monster = atoi(zz[3]);
2998 letter[index].cave_info = atoi(zz[2]);
3002 if (zz[1][0] == '*')
3004 letter[index].random |= RANDOM_FEATURE;
3008 letter[index].feature = atoi(zz[1]);
3013 letter[index].feature = atoi(zz[1]);
3026 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
3028 static errr parse_line_building(char *buf)
3044 /* Get the building number */
3047 /* Find the colon after the building number */
3050 /* Verify that colon */
3053 /* Nuke the colon, advance to the sub-index */
3056 /* Paranoia -- require a sub-index */
3057 if (!*s) return (1);
3059 /* Building definition sub-index */
3062 /* Building name, owner, race */
3065 if (tokenize(s + 2, 3, zz, 0) == 3)
3067 /* Name of the building */
3068 strcpy(building[index].name, zz[0]);
3070 /* Name of the owner */
3071 strcpy(building[index].owner_name, zz[1]);
3073 /* Race of the owner */
3074 strcpy(building[index].owner_race, zz[2]);
3079 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3082 /* Building Action */
3085 if (tokenize(s + 2, 8, zz, 0) >= 7)
3087 /* Index of the action */
3088 int action_index = atoi(zz[0]);
3090 /* Name of the action */
3091 strcpy(building[index].act_names[action_index], zz[1]);
3093 /* Cost of the action for members */
3094 building[index].member_costs[action_index] = atoi(zz[2]);
3096 /* Cost of the action for non-members */
3097 building[index].other_costs[action_index] = atoi(zz[3]);
3099 /* Letter assigned to the action */
3100 building[index].letters[action_index] = zz[4][0];
3103 building[index].actions[action_index] = atoi(zz[5]);
3105 /* Action restriction */
3106 building[index].action_restr[action_index] = atoi(zz[6]);
3111 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3114 /* Building Classes */
3117 if (tokenize(s + 2, MAX_CLASS, zz, 0) == MAX_CLASS)
3119 for (i = 0; i < MAX_CLASS; i++)
3121 building[index].member_class[i] = atoi(zz[i]);
3127 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3130 /* Building Races */
3133 if (tokenize(s+2, MAX_RACES, zz, 0) == MAX_RACES)
3135 for (i = 0; i < MAX_RACES; i++)
3137 building[index].member_race[i] = atoi(zz[i]);
3143 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3146 /* Building Realms */
3149 if (tokenize(s+2, MAX_MAGIC, zz, 0) == MAX_MAGIC)
3151 for (i = 0; i < MAX_MAGIC; i++)
3153 building[index].member_realm[i+1] = atoi(zz[i]);
3159 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3164 /* Ignore scripts */
3170 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3179 * Parse a sub-file of the "extra info"
3181 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3188 /* Skip "empty" lines */
3189 if (!buf[0]) return (0);
3191 /* Skip "blank" lines */
3192 if (isspace(buf[0])) return (0);
3195 if (buf[0] == '#') return (0);
3197 /* Require "?:*" format */
3198 if (buf[1] != ':') return (1);
3201 /* Process "%:<fname>" */
3204 /* Attempt to Process the given file */
3205 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3208 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3211 return parse_line_feature(buf);
3214 /* Process "D:<dungeon>" -- info for the cave grids */
3215 else if (buf[0] == 'D')
3217 object_type object_type_body;
3219 /* Acquire the text */
3222 /* Length of the text */
3223 int len = strlen(s);
3225 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3227 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3229 /* Access the grid */
3230 cave_type *c_ptr = &cave[*y][*x];
3234 int object_index = letter[idx].object;
3235 int monster_index = letter[idx].monster;
3236 int random = letter[idx].random;
3237 int artifact_index = letter[idx].artifact;
3239 /* Lay down a floor */
3240 c_ptr->feat = letter[idx].feature;
3242 /* Only the features */
3243 if (init_flags & INIT_ONLY_FEATURES) continue;
3246 c_ptr->info = letter[idx].cave_info;
3248 /* Create a monster */
3249 if (random & RANDOM_MONSTER)
3251 monster_level = base_level + monster_index;
3253 place_monster(*y, *x, TRUE, TRUE);
3255 monster_level = base_level;
3257 else if (monster_index)
3259 int old_cur_num, old_max_num;
3262 if (monster_index < 0)
3264 monster_index = -monster_index;
3267 old_cur_num = r_info[monster_index].cur_num;
3268 old_max_num = r_info[monster_index].max_num;
3270 /* Make alive again */
3271 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3273 r_info[monster_index].cur_num = 0;
3274 r_info[monster_index].max_num = 1;
3277 /* Make alive again */
3278 if (r_info[monster_index].flags7 & RF7_UNIQUE_7)
3280 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3282 r_info[monster_index].max_num++;
3287 place_monster_aux(*y, *x, monster_index, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);
3291 m_list[hack_m_idx_ii].smart |= SM_CLONED;
3293 /* Make alive again for real unique monster */
3294 r_info[monster_index].cur_num = old_cur_num;
3295 r_info[monster_index].max_num = old_max_num;
3299 /* Object (and possible trap) */
3300 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3302 object_level = base_level + object_index;
3305 * Random trap and random treasure defined
3306 * 25% chance for trap and 75% chance for object
3308 if (rand_int(100) < 75)
3310 place_object(*y, *x, FALSE, FALSE);
3317 object_level = base_level;
3319 else if (random & RANDOM_OBJECT)
3321 object_level = base_level + object_index;
3323 /* Create an out of deep object */
3324 if (rand_int(100) < 75)
3325 place_object(*y, *x, FALSE, FALSE);
3326 else if (rand_int(100) < 80)
3327 place_object(*y, *x, TRUE, FALSE);
3329 place_object(*y, *x, TRUE, TRUE);
3331 object_level = base_level;
3334 else if (random & RANDOM_TRAP)
3338 else if (object_index)
3340 /* Get local object */
3341 object_type *o_ptr = &object_type_body;
3343 /* Create the item */
3344 object_prep(o_ptr, object_index);
3346 if (o_ptr->tval == TV_GOLD)
3348 coin_type = object_index - OBJ_GOLD_LIST;
3353 /* Apply magic (no messages, no artifacts) */
3354 apply_magic(o_ptr, base_level, FALSE, TRUE, FALSE, FALSE);
3356 (void)drop_near(o_ptr, -1, *y, *x);
3362 if (a_info[artifact_index].cur_num)
3366 object_type *q_ptr = &forge;
3368 object_prep(q_ptr, k_idx);
3370 /* Drop it in the dungeon */
3371 (void)drop_near(q_ptr, -1, *y, *x);
3375 /* Create the artifact */
3376 create_named_art(artifact_index, *y, *x);
3378 a_info[artifact_index].cur_num = 1;
3382 /* Terrain special */
3383 c_ptr->special = letter[idx].special;
3391 /* Process "Q:<number>:<command>:... -- quest info */
3392 else if (buf[0] == 'Q')
3399 num = tokenize(buf + 2, 33, zz, 0);
3403 num = tokenize(buf + 3, 33, zz, 0);
3406 /* Have we enough parameters? */
3407 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3410 q_ptr = &(quest[atoi(zz[0])]);
3412 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3413 if (zz[1][0] == 'Q')
3415 if (init_flags & INIT_ASSIGN)
3417 monster_race *r_ptr;
3418 artifact_type *a_ptr;
3420 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3422 q_ptr->type = atoi(zz[2]);
3423 q_ptr->num_mon = atoi(zz[3]);
3424 q_ptr->cur_num = atoi(zz[4]);
3425 q_ptr->max_num = atoi(zz[5]);
3426 q_ptr->level = atoi(zz[6]);
3427 q_ptr->r_idx = atoi(zz[7]);
3428 q_ptr->k_idx = atoi(zz[8]);
3429 q_ptr->dungeon = atoi(zz[9]);
3432 q_ptr->flags = atoi(zz[10]);
3434 r_ptr = &r_info[q_ptr->r_idx];
3435 if (r_ptr->flags1 & RF1_UNIQUE)
3436 r_ptr->flags1 |= RF1_QUESTOR;
3438 a_ptr = &a_info[q_ptr->k_idx];
3439 a_ptr->flags3 |= TR3_QUESTITEM;
3444 /* Process "Q:<q_index>:N:<name>" -- quest name */
3445 else if (zz[1][0] == 'N')
3447 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3449 strcpy(q_ptr->name, zz[2]);
3455 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3456 else if (zz[1][0] == 'T')
3458 if (init_flags & INIT_SHOW_TEXT)
3460 strcpy(quest_text[quest_text_line], zz[2]);
3468 /* Process "W:<command>: ..." -- info for the wilderness */
3469 else if (buf[0] == 'W')
3471 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3474 /* Process "P:<y>:<x>" -- player position */
3475 else if (buf[0] == 'P')
3477 if (init_flags & INIT_CREATE_DUNGEON)
3479 if (tokenize(buf + 2, 2, zz, 0) == 2)
3481 int panels_x, panels_y;
3483 /* Hack - Set the dungeon size */
3484 panels_y = (*y / SCREEN_HGT);
3485 if (*y % SCREEN_HGT) panels_y++;
3486 cur_hgt = panels_y * SCREEN_HGT;
3488 panels_x = (*x / SCREEN_WID);
3489 if (*x % SCREEN_WID) panels_x++;
3490 cur_wid = panels_x * SCREEN_WID;
3492 /* Choose a panel row */
3493 max_panel_rows = (cur_hgt / SCREEN_HGT) * 2 - 2;
3494 if (max_panel_rows < 0) max_panel_rows = 0;
3496 /* Choose a panel col */
3497 max_panel_cols = (cur_wid / SCREEN_WID) * 2 - 2;
3498 if (max_panel_cols < 0) max_panel_cols = 0;
3500 /* Assume illegal panel */
3501 panel_row = max_panel_rows;
3502 panel_col = max_panel_cols;
3504 /* Place player in a quest level */
3505 if (p_ptr->inside_quest)
3509 /* Delete the monster (if any) */
3510 delete_monster(py, px);
3518 /* Place player in the town */
3519 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3521 p_ptr->oldpy = atoi(zz[0]);
3522 p_ptr->oldpx = atoi(zz[1]);
3530 /* Process "B:<Index>:<Command>:..." -- Building definition */
3531 else if (buf[0] == 'B')
3533 return parse_line_building(buf);
3536 /* Process "M:<type>:<maximum>" -- set maximum values */
3537 else if (buf[0] == 'M')
3539 if (tokenize(buf+2, 2, zz, 0) == 2)
3542 if (zz[0][0] == 'T')
3544 max_towns = atoi(zz[1]);
3547 /* Maximum quests */
3548 else if (zz[0][0] == 'Q')
3550 max_quests = atoi(zz[1]);
3554 else if (zz[0][0] == 'R')
3556 max_r_idx = atoi(zz[1]);
3560 else if (zz[0][0] == 'K')
3562 max_k_idx = atoi(zz[1]);
3566 else if (zz[0][0] == 'V')
3568 max_v_idx = atoi(zz[1]);
3572 else if (zz[0][0] == 'F')
3574 max_f_idx = atoi(zz[1]);
3578 else if (zz[0][0] == 'A')
3580 max_a_idx = atoi(zz[1]);
3584 else if (zz[0][0] == 'E')
3586 max_e_idx = atoi(zz[1]);
3590 else if (zz[0][0] == 'D')
3592 max_d_idx = atoi(zz[1]);
3596 else if (zz[0][0] == 'O')
3598 max_o_idx = atoi(zz[1]);
3602 else if (zz[0][0] == 'M')
3604 max_m_idx = atoi(zz[1]);
3607 /* Wilderness size */
3608 else if (zz[0][0] == 'W')
3610 /* Maximum wild_x_size */
3611 if (zz[0][1] == 'X')
3612 max_wild_x = atoi(zz[1]);
3613 /* Maximum wild_y_size */
3614 if (zz[0][1] == 'Y')
3615 max_wild_y = atoi(zz[1]);
3629 static cptr variant = "ZANGBAND";
3633 * Helper function for "process_dungeon_file()"
3635 static cptr process_dungeon_file_expr(char **sp, char *fp)
3651 while (isspace(*s)) s++;
3669 t = process_dungeon_file_expr(&s, &f);
3678 else if (streq(t, "IOR"))
3681 while (*s && (f != b2))
3683 t = process_dungeon_file_expr(&s, &f);
3684 if (*t && !streq(t, "0")) v = "1";
3689 else if (streq(t, "AND"))
3692 while (*s && (f != b2))
3694 t = process_dungeon_file_expr(&s, &f);
3695 if (*t && streq(t, "0")) v = "0";
3700 else if (streq(t, "NOT"))
3703 while (*s && (f != b2))
3705 t = process_dungeon_file_expr(&s, &f);
3706 if (*t && streq(t, "1")) v = "0";
3711 else if (streq(t, "EQU"))
3714 if (*s && (f != b2))
3716 t = process_dungeon_file_expr(&s, &f);
3718 while (*s && (f != b2))
3721 t = process_dungeon_file_expr(&s, &f);
3722 if (*t && !streq(p, t)) v = "0";
3727 else if (streq(t, "LEQ"))
3730 if (*s && (f != b2))
3732 t = process_dungeon_file_expr(&s, &f);
3734 while (*s && (f != b2))
3737 t = process_dungeon_file_expr(&s, &f);
3738 if (*t && (strcmp(p, t) > 0)) v = "0";
3743 else if (streq(t, "GEQ"))
3746 if (*s && (f != b2))
3748 t = process_dungeon_file_expr(&s, &f);
3750 while (*s && (f != b2))
3753 t = process_dungeon_file_expr(&s, &f);
3754 if (*t && (strcmp(p, t) < 0)) v = "0";
3761 while (*s && (f != b2))
3763 t = process_dungeon_file_expr(&s, &f);
3768 if (f != b2) v = "?x?x?";
3770 /* Extract final and Terminate */
3771 if ((f = *s) != '\0') *s++ = '\0';
3777 /* Accept all printables except spaces and brackets */
3778 while (isprint(*s) && !strchr(" []", *s)) ++s;
3780 /* Extract final and Terminate */
3781 if ((f = *s) != '\0') *s++ = '\0';
3787 if (streq(b+1, "SYS"))
3793 else if (streq(b+1, "GRAF"))
3798 else if (streq(b+1, "MONOCHROME"))
3807 else if (streq(b+1, "RACE"))
3810 v = rp_ptr->E_title;
3817 else if (streq(b+1, "CLASS"))
3820 v = cp_ptr->E_title;
3827 else if (streq(b+1, "REALM1"))
3830 v = E_realm_names[p_ptr->realm1];
3832 v = realm_names[p_ptr->realm1];
3837 else if (streq(b+1, "REALM2"))
3840 v = E_realm_names[p_ptr->realm2];
3842 v = realm_names[p_ptr->realm2];
3847 else if (streq(b+1, "PLAYER"))
3853 else if (streq(b+1, "TOWN"))
3855 sprintf(tmp, "%d", p_ptr->town_num);
3860 else if (streq(b+1, "LEVEL"))
3862 sprintf(tmp, "%d", p_ptr->lev);
3866 /* Current quest number */
3867 else if (streq(b+1, "QUEST_NUMBER"))
3869 sprintf(tmp, "%d", p_ptr->inside_quest);
3873 /* Number of last quest */
3874 else if (streq(b+1, "LEAVING_QUEST"))
3876 sprintf(tmp, "%d", leaving_quest);
3881 else if (prefix(b+1, "QUEST"))
3883 /* "QUEST" uses a special parameter to determine the number of the quest */
3884 sprintf(tmp, "%d", quest[atoi(b+6)].status);
3889 else if (prefix(b+1, "RANDOM"))
3891 /* "RANDOM" uses a special parameter to determine the number of the quest */
3892 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
3897 else if (streq(b+1, "VARIANT"))
3903 else if (streq(b+1, "WILDERNESS"))
3906 sprintf(tmp, "NONE");
3908 sprintf(tmp, "LITE");
3910 sprintf(tmp, "NORMAL");
3933 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
3943 bool bypass = FALSE;
3945 int x = xmin, y = ymin;
3948 /* Build the filename */
3949 path_build(buf, 1024, ANGBAND_DIR_EDIT, name);
3952 fp = my_fopen(buf, "r");
3955 if (!fp) return (-1);
3958 /* Process the file */
3959 while (0 == my_fgets(fp, buf, 1024))
3965 /* Skip "empty" lines */
3966 if (!buf[0]) continue;
3968 /* Skip "blank" lines */
3969 if (isspace(buf[0])) continue;
3972 if (buf[0] == '#') continue;
3975 /* Process "?:<expr>" */
3976 if ((buf[0] == '?') && (buf[1] == ':'))
3985 /* Parse the expr */
3986 v = process_dungeon_file_expr(&s, &f);
3989 bypass = (streq(v, "0") ? TRUE : FALSE);
3995 /* Apply conditionals */
3996 if (bypass) continue;
3999 /* Process "%:<file>" */
4002 /* Process that file if allowed */
4003 (void)process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax);
4010 /* Process the line */
4011 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4023 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4026 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4028 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4030 msg_format("Parsing '%s'.", buf);
4037 /* Close the file */
4047 void write_r_info_txt(void)
4049 int i, j, z, fc, bc;
4057 monster_race *r_ptr;
4059 monster_blow *b_ptr;
4061 FILE *fff = fopen("output.txt", "wt");
4069 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4071 fprintf(fff, "# Version stamp (required)\n\n");
4074 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4077 fprintf(fff, "##### The Player #####\n\n");
4079 for (z = -1; z < alloc_race_size; z++)
4081 /* Output the monsters in order */
4082 i = (z >= 0) ? alloc_race_table[z].index : 0;
4084 /* Acquire the monster */
4087 /* Ignore empty monsters */
4088 if (!strlen(r_name + r_ptr->name)) continue;
4090 /* Ignore useless monsters */
4091 if (i && !r_ptr->speed) continue;
4093 /* Write a note if necessary */
4094 if (i && (!r_ptr->level != !mode))
4099 fprintf(fff, "\n##### Town monsters #####\n\n");
4101 /* Note the dungeon */
4104 fprintf(fff, "\n##### Normal monsters #####\n\n");
4107 /* Record the change */
4108 mode = r_ptr->level;
4111 /* Acquire the flags */
4112 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4113 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4114 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4115 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4116 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4117 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4118 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4119 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4120 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4122 /* Write New/Number/Name */
4123 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4126 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4128 /* Write Information */
4129 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4130 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4132 /* Write more information */
4133 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4136 for(j = 0; j < 4; j++)
4138 b_ptr = &(r_ptr->blow[j]);
4140 /* Stop when done */
4141 if (!b_ptr->method) break;
4143 /* Write the blows */
4144 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4145 r_info_blow_effect[b_ptr->effect],
4146 b_ptr->d_dice, b_ptr->d_side);
4149 /* Extract the flags */
4150 for (fc = 0, j = 0; j < 96; j++)
4152 /* Check this flag */
4153 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4156 /* Extract the extra flags */
4157 for (j = 192; j < 288; j++)
4159 /* Check this flag */
4160 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4163 /* Write the flags */
4164 for (j = 0; j < fc;)
4168 /* Start the line */
4171 for (bc = 0; (bc < 60) && (j < fc); j++)
4175 /* Format the flag */
4176 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4178 /* Add it to the buffer */
4181 /* Note the length */
4185 /* Done with this line; write it */
4186 fprintf(fff, "%s\n", buf);
4189 /* Write Spells if applicable */
4190 if (r_ptr->freq_spell)
4192 /* Write the frequency */
4193 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4195 /* Extract the spell flags */
4196 for (fc = 0, j = 96; j < 192; j++)
4198 /* Check this flag */
4199 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4202 /* Write the flags */
4203 for (j = 0; j < fc;)
4207 /* Start the line */
4210 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4214 /* Format the flag */
4215 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4219 /* Note the length */
4226 /* Done with this line; write it */
4227 fprintf(fff, "%s\n", buf);
4231 /* Acquire the description */
4232 desc = r_text + r_ptr->text;
4233 dlen = strlen(desc);
4235 /* Write Description */
4236 for (j = 0; j < dlen;)
4240 /* Start the line */
4243 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4251 /* Done with this line; write it */
4252 fprintf(fff, "%s\n", buf);
4255 /* Space between entries */