3 /* Purpose: Initialization (part 1) -BEN- */
10 char* _strchr(char* ptr, char ch)
14 for ( ; *ptr != '\0'; ++ptr)
25 #define strchr _strchr
28 * This file is used to initialize various variables and arrays for the
29 * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass
30 * the common limitation of "read()" and "write()" to only 32767 bytes
33 * Several of the arrays for Angband are built from "template" files in
34 * the "lib/file" directory, from which quick-load binary "image" files
35 * are constructed whenever they are not present in the "lib/data"
36 * directory, or if those files become obsolete, if we are allowed.
38 * Warning -- the "ascii" file parsers use a minor hack to collect the
39 * name and text information in a single pass. Thus, the game will not
40 * be able to load any template file with more than 20K of names or 60K
41 * of text, even though technically, up to 64K should be legal.
43 * Note that if "ALLOW_TEMPLATES" is not defined, then a lot of the code
44 * in this file is compiled out, and the game will not run unless valid
45 * "binary template files" already exist in "lib/data". Thus, one can
46 * compile Angband with ALLOW_TEMPLATES defined, run once to create the
47 * "*.raw" files in "lib/data", and then quit, and recompile without
48 * defining ALLOW_TEMPLATES, which will both save 20K and prevent people
49 * from changing the ascii template files in potentially dangerous ways.
51 * The code could actually be removed and placed into a "stand-alone"
52 * program, but that feels a little silly, especially considering some
53 * of the platforms that we currently support.
56 #ifdef ALLOW_TEMPLATES
61 /*** Helper arrays for parsing ascii template files ***/
64 * Monster Blow Methods
66 static cptr r_info_blow_method[] =
98 * Monster Blow Effects
100 static cptr r_info_blow_effect[] =
143 static cptr r_info_flags1[] =
182 static cptr r_info_flags2[] =
221 static cptr r_info_flags3[] =
260 static cptr r_info_flags4[] =
299 static cptr r_info_flags5[] =
338 static cptr r_info_flags6[] =
355 "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */
378 static cptr r_info_flags7[] =
417 static cptr r_info_flags8[] =
449 "WILD_SWAMP", /* ToDo: Implement Swamp */
455 * Monster race flags - Drops
457 static cptr r_info_flags9[] =
498 static cptr k_info_flags1[] =
537 static cptr k_info_flags2[] =
576 static cptr k_info_flags3[] =
616 static cptr d_info_flags1[] =
654 * Add a text to the text-storage and store offset to it.
656 * Returns FALSE when there isn't enough space available to store
659 static bool add_text(u32b *offset, header *head, cptr buf)
661 /* Hack -- Verify space */
662 if (head->text_size + strlen(buf) + 8 > FAKE_TEXT_SIZE)
668 /* Advance and save the text index */
669 *offset = ++head->text_size;
672 /* Append chars to the text */
673 strcpy(head->text_ptr + head->text_size, buf);
675 /* Advance the index */
676 head->text_size += strlen(buf);
684 * Add a name to the name-storage and return an offset to it.
686 * Returns FALSE when there isn't enough space available to store
689 static bool add_name(u32b *offset, header *head, cptr buf)
691 /* Hack -- Verify space */
692 if (head->name_size + strlen(buf) + 8 > FAKE_NAME_SIZE)
698 /* Advance and save the name index */
699 *offset = ++head->name_size;
702 /* Append chars to the names */
703 strcpy(head->name_ptr + head->name_size, buf);
705 /* Advance the index */
706 head->name_size += strlen(buf);
714 * Convert a "color letter" into an "actual" color
715 * The colors are: dwsorgbuDWvyRGBU, as shown below
717 static int color_char_to_attr(char c)
721 case 'd': return (TERM_DARK);
722 case 'w': return (TERM_WHITE);
723 case 's': return (TERM_SLATE);
724 case 'o': return (TERM_ORANGE);
725 case 'r': return (TERM_RED);
726 case 'g': return (TERM_GREEN);
727 case 'b': return (TERM_BLUE);
728 case 'u': return (TERM_UMBER);
730 case 'D': return (TERM_L_DARK);
731 case 'W': return (TERM_L_WHITE);
732 case 'v': return (TERM_VIOLET);
733 case 'y': return (TERM_YELLOW);
734 case 'R': return (TERM_L_RED);
735 case 'G': return (TERM_L_GREEN);
736 case 'B': return (TERM_L_BLUE);
737 case 'U': return (TERM_L_UMBER);
745 /*** Initialize from ascii template files ***/
749 * Initialize an "*_info" array, by parsing an ascii "template" file
751 errr init_info_txt(FILE *fp, char *buf, header *head,
752 parse_info_txt_func parse_info_txt_line)
756 /* Just before the first record */
759 /* Just before the first line */
763 /* Prepare the "fake" stuff */
768 while (0 == my_fgets(fp, buf, 1024))
770 /* Advance the line number */
773 /* Skip comments and blank lines */
774 if (!buf[0] || (buf[0] == '#')) continue;
776 /* Verify correct "colon" format */
777 if (buf[1] != ':') return (PARSE_ERROR_GENERIC);
780 /* Hack -- Process 'V' for "Version" */
788 if ((err = (*parse_info_txt_line)(buf, head)) != 0)
793 /* Complete the "name" and "text" sizes */
794 if (head->name_size) head->name_size++;
795 if (head->text_size) head->text_size++;
803 * Initialize the "v_info" array, by parsing an ascii "template" file
805 errr parse_v_info(char *buf, header *head)
811 static vault_type *v_ptr = NULL;
813 /* Process 'N' for "New/Number/Name" */
816 /* Find the colon before the name */
817 s = strchr(buf+2, ':');
819 /* Verify that colon */
822 /* Nuke the colon, advance to the name */
825 /* Paranoia -- require a name */
831 /* Verify information */
832 if (i <= error_idx) return (4);
834 /* Verify information */
835 if (i >= head->info_num) return (2);
840 /* Point at the "info" */
844 if (!add_name(&v_ptr->name, head, s)) return (7);
847 /* There better be a current v_ptr */
848 else if (!v_ptr) return (3);
850 /* Process 'D' for "Description" */
851 else if (buf[0] == 'D')
853 /* Acquire the text */
857 if (!add_text(&v_ptr->text, head, s)) return (7);
860 /* Process 'X' for "Extra info" (one line only) */
861 else if (buf[0] == 'X')
863 int typ, rat, hgt, wid;
865 /* Scan for the values */
866 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
867 &typ, &rat, &hgt, &wid)) return (1);
869 /* Save the values */
886 * Initialize the "s_info" array, by parsing an ascii "template" file
888 errr parse_s_info(char *buf, header *head)
893 static skill_table *s_ptr = NULL;
896 /* Process 'N' for "New/Number/Name" */
902 /* Verify information */
903 if (i <= error_idx) return (4);
905 /* Verify information */
906 if (i >= head->info_num) return (2);
911 /* Point at the "info" */
915 /* There better be a current s_ptr */
916 else if (!s_ptr) return (3);
918 /* Process 'W' for "Weapon exp" */
919 else if (buf[0] == 'W')
921 int tval, sval, start, max;
922 const s16b exp_conv_table[] = { 0, 4000, 6000, 7000, 8000 };
924 /* Scan for the values */
925 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
926 &tval, &sval, &start, &max)) return (1);
928 if (start < 0 || start > 4 || max < 0 || max > 4) return (8);
930 /* Save the values */
931 s_ptr->w_start[tval][sval] = exp_conv_table[start];
932 s_ptr->w_max[tval][sval] = exp_conv_table[max];
935 /* Process 'S' for "Skill exp" */
936 else if (buf[0] == 'S')
940 /* Scan for the values */
941 if (3 != sscanf(buf+2, "%d:%d:%d",
942 &num, &start, &max)) return (1);
944 if (start < 0 || start > 8000 || max < 0 || max > 8000) return (8);
946 /* Save the values */
947 s_ptr->s_start[num] = start;
948 s_ptr->s_max[num] = max;
961 * Initialize the "m_info" array, by parsing an ascii "template" file
963 errr parse_m_info(char *buf, header *head)
970 static player_magic *m_ptr = NULL;
973 static int realm, magic_idx = 0, readable = 0;
976 /* Process 'N' for "New/Number/Name" */
982 /* Verify information */
983 if (i <= error_idx) return (4);
985 /* Verify information */
986 if (i >= head->info_num) return (2);
991 /* Point at the "info" */
995 /* There better be a current m_ptr */
996 else if (!m_ptr) return (3);
998 /* Process 'I' for "Info" (one line only) */
999 else if (buf[0] == 'I')
1002 int xtra, type, first, weight;
1004 /* Find the colon before the name */
1005 s = strchr(buf+2, ':');
1007 /* Verify that colon */
1010 /* Nuke the colon, advance to the name */
1015 if (streq(book, "SORCERY")) m_ptr->spell_book = TV_SORCERY_BOOK;
1016 else if (streq(book, "LIFE")) m_ptr->spell_book = TV_LIFE_BOOK;
1017 else if (streq(book, "MUSIC")) m_ptr->spell_book = TV_MUSIC_BOOK;
1018 else if (streq(book, "HISSATSU")) m_ptr->spell_book = TV_HISSATSU_BOOK;
1019 else if (streq(book, "NONE")) m_ptr->spell_book = 0;
1024 /* Find the colon before the name */
1027 /* Verify that colon */
1030 /* Nuke the colon, advance to the name */
1033 if (streq(stat, "STR")) m_ptr->spell_stat = A_STR;
1034 else if (streq(stat, "INT")) m_ptr->spell_stat = A_INT;
1035 else if (streq(stat, "WIS")) m_ptr->spell_stat = A_WIS;
1036 else if (streq(stat, "DEX")) m_ptr->spell_stat = A_DEX;
1037 else if (streq(stat, "CON")) m_ptr->spell_stat = A_CON;
1038 else if (streq(stat, "CHR")) m_ptr->spell_stat = A_CHR;
1042 /* Scan for the values */
1043 if (4 != sscanf(s, "%x:%d:%d:%d",
1044 &xtra, &type, &first, &weight)) return (1);
1046 m_ptr->spell_xtra = xtra;
1047 m_ptr->spell_type = type;
1048 m_ptr->spell_first = first;
1049 m_ptr->spell_weight = weight;
1053 /* Process 'R' for "Realm" (one line only) */
1054 else if (buf[0] == 'R')
1056 /* Scan for the values */
1057 if (2 != sscanf(buf+2, "%d:%d",
1058 &realm, &readable)) return (1);
1063 else if (buf[0] == 'T')
1065 int level, mana, fail, exp;
1067 if (!readable) return (1);
1068 /* Scan for the values */
1069 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1070 &level, &mana, &fail, &exp)) return (1);
1072 m_ptr->info[realm][magic_idx].slevel = level;
1073 m_ptr->info[realm][magic_idx].smana = mana;
1074 m_ptr->info[realm][magic_idx].sfail = fail;
1075 m_ptr->info[realm][magic_idx].sexp = exp;
1089 * Initialize the "f_info" array, by parsing an ascii "template" file
1091 errr parse_f_info(char *buf, header *head)
1098 static feature_type *f_ptr = NULL;
1101 /* Process 'N' for "New/Number/Name" */
1104 /* Find the colon before the name */
1105 s = strchr(buf+2, ':');
1107 /* Verify that colon */
1110 /* Nuke the colon, advance to the name */
1114 /* Paranoia -- require a name */
1115 if (!*s) return (1);
1121 /* Verify information */
1122 if (i <= error_idx) return (4);
1124 /* Verify information */
1125 if (i >= head->info_num) return (2);
1127 /* Save the index */
1130 /* Point at the "info" */
1134 /* Store the name */
1135 if (!add_name(&f_ptr->name, head, s)) return (7);
1137 /* Default "mimic" */
1141 /* There better be a current f_ptr */
1142 else if (!f_ptr) return (3);
1145 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1146 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1147 else if (buf[0] == 'E')
1152 else if (buf[0] == 'E')
1154 /* Acquire the Text */
1157 /* Store the name */
1158 if (!add_name(&f_ptr->name, head, s)) return (7);
1164 /* Process 'D' for "Description" */
1165 else if (buf[0] == 'D')
1167 /* Acquire the text */
1170 /* Store the text */
1171 if (!add_text(&f_ptr->text, head, s)) return (7);
1177 /* Process 'M' for "Mimic" (one line only) */
1178 else if (buf[0] == 'M')
1182 /* Scan for the values */
1183 if (1 != sscanf(buf+2, "%d",
1184 &mimic)) return (1);
1186 /* Save the values */
1187 f_ptr->mimic = mimic;
1192 /* Process 'G' for "Graphics" (one line only) */
1193 else if (buf[0] == 'G')
1198 if (!buf[2]) return (1);
1199 if (!buf[3]) return (1);
1200 if (!buf[4]) return (1);
1202 /* Extract the color */
1203 tmp = color_char_to_attr(buf[4]);
1206 if (tmp < 0) return (1);
1208 /* Save the values */
1209 f_ptr->d_attr = tmp;
1210 f_ptr->d_char = buf[2];
1223 * Grab one flag in an object_kind from a textual string
1225 static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
1230 for (i = 0; i < 32; i++)
1232 if (streq(what, k_info_flags1[i]))
1234 k_ptr->flags1 |= (1L << i);
1240 for (i = 0; i < 32; i++)
1242 if (streq(what, k_info_flags2[i]))
1244 k_ptr->flags2 |= (1L << i);
1250 for (i = 0; i < 32; i++)
1252 if (streq(what, k_info_flags3[i]))
1254 k_ptr->flags3 |= (1L << i);
1261 msg_format("̤ÃΤΥ¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1263 msg_format("Unknown object flag '%s'.", what);
1273 * Initialize the "k_info" array, by parsing an ascii "template" file
1275 errr parse_k_info(char *buf, header *head)
1282 static object_kind *k_ptr = NULL;
1285 /* Process 'N' for "New/Number/Name" */
1288 /* Find the colon before the name */
1289 s = strchr(buf+2, ':');
1291 /* Verify that colon */
1294 /* Nuke the colon, advance to the name */
1298 /* Paranoia -- require a name */
1299 if (!*s) return (1);
1304 /* Verify information */
1305 if (i <= error_idx) return (4);
1307 /* Verify information */
1308 if (i >= head->info_num) return (2);
1310 /* Save the index */
1313 /* Point at the "info" */
1317 /* Store the name */
1318 if (!add_name(&k_ptr->name, head, s)) return (7);
1322 /* There better be a current k_ptr */
1323 else if (!k_ptr) return (3);
1327 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1328 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1329 else if (buf[0] == 'E')
1334 else if (buf[0] == 'E')
1336 /* Acquire the Text */
1339 /* Store the name */
1340 if (!add_name(&k_ptr->name, head, s)) return (7);
1345 /* Process 'D' for "Description" */
1346 else if (buf[0] == 'D')
1348 /* Acquire the text */
1351 /* Store the text */
1352 if (!add_text(&k_ptr->text, head, s)) return (7);
1358 /* Process 'G' for "Graphics" (one line only) */
1359 else if (buf[0] == 'G')
1365 if (!buf[2]) return (1);
1366 if (!buf[3]) return (1);
1367 if (!buf[4]) return (1);
1369 /* Extract the char */
1372 /* Extract the attr */
1373 tmp = color_char_to_attr(buf[4]);
1376 if (tmp < 0) return (1);
1378 /* Save the values */
1379 k_ptr->d_attr = tmp;
1380 k_ptr->d_char = sym;
1383 /* Process 'I' for "Info" (one line only) */
1384 else if (buf[0] == 'I')
1386 int tval, sval, pval;
1388 /* Scan for the values */
1389 if (3 != sscanf(buf+2, "%d:%d:%d",
1390 &tval, &sval, &pval)) return (1);
1392 /* Save the values */
1398 /* Process 'W' for "More Info" (one line only) */
1399 else if (buf[0] == 'W')
1401 int level, extra, wgt;
1404 /* Scan for the values */
1405 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1406 &level, &extra, &wgt, &cost)) return (1);
1408 /* Save the values */
1409 k_ptr->level = level;
1410 k_ptr->extra = extra;
1411 k_ptr->weight = wgt;
1415 /* Process 'A' for "Allocation" (one line only) */
1416 else if (buf[0] == 'A')
1420 /* XXX XXX XXX Simply read each number following a colon */
1421 for (i = 0, s = buf+1; s && (s[0] == ':') && s[1]; ++i)
1423 /* Default chance */
1424 k_ptr->chance[i] = 1;
1426 /* Store the attack damage index */
1427 k_ptr->locale[i] = atoi(s+1);
1429 /* Find the slash */
1430 t = strchr(s+1, '/');
1432 /* Find the next colon */
1433 s = strchr(s+1, ':');
1435 /* If the slash is "nearby", use it */
1436 if (t && (!s || t < s))
1438 int chance = atoi(t+1);
1439 if (chance > 0) k_ptr->chance[i] = chance;
1444 /* Hack -- Process 'P' for "power" and such */
1445 else if (buf[0] == 'P')
1447 int ac, hd1, hd2, th, td, ta;
1449 /* Scan for the values */
1450 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1451 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1461 /* Hack -- Process 'F' for flags */
1462 else if (buf[0] == 'F')
1464 /* Parse every entry textually */
1465 for (s = buf + 2; *s; )
1467 /* Find the end of this entry */
1468 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1470 /* Nuke and skip any dividers */
1474 while (*t == ' ' || *t == '|') t++;
1477 /* Parse this entry */
1478 if (0 != grab_one_kind_flag(k_ptr, s)) return (5);
1480 /* Start the next entry */
1496 * Grab one flag in an artifact_type from a textual string
1498 static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
1503 for (i = 0; i < 32; i++)
1505 if (streq(what, k_info_flags1[i]))
1507 a_ptr->flags1 |= (1L << i);
1513 for (i = 0; i < 32; i++)
1515 if (streq(what, k_info_flags2[i]))
1517 a_ptr->flags2 |= (1L << i);
1523 for (i = 0; i < 32; i++)
1525 if (streq(what, k_info_flags3[i]))
1527 a_ptr->flags3 |= (1L << i);
1534 msg_format("̤ÃΤÎÅÁÀâ¤Î¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1536 msg_format("Unknown artifact flag '%s'.", what);
1548 * Initialize the "a_info" array, by parsing an ascii "template" file
1550 errr parse_a_info(char *buf, header *head)
1557 static artifact_type *a_ptr = NULL;
1560 /* Process 'N' for "New/Number/Name" */
1563 /* Find the colon before the name */
1564 s = strchr(buf+2, ':');
1566 /* Verify that colon */
1569 /* Nuke the colon, advance to the name */
1572 /* Paranoia -- require a name */
1573 if (!*s) return (1);
1578 /* Verify information */
1579 if (i < error_idx) return (4);
1581 /* Verify information */
1582 if (i >= head->info_num) return (2);
1584 /* Save the index */
1587 /* Point at the "info" */
1590 /* Ignore everything */
1591 a_ptr->flags3 |= (TR3_IGNORE_ACID);
1592 a_ptr->flags3 |= (TR3_IGNORE_ELEC);
1593 a_ptr->flags3 |= (TR3_IGNORE_FIRE);
1594 a_ptr->flags3 |= (TR3_IGNORE_COLD);
1596 /* Store the name */
1597 if (!add_name(&a_ptr->name, head, s)) return (7);
1601 /* There better be a current a_ptr */
1602 else if (!a_ptr) return (3);
1606 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1607 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾¤È¤·¤Æ¤¤¤ë */
1608 else if (buf[0] == 'E')
1613 else if (buf[0] == 'E')
1615 /* Acquire the Text */
1618 /* Store the name */
1619 if (!add_name(&a_ptr->name, head, s)) return (7);
1623 /* Process 'D' for "Description" */
1624 else if (buf[0] == 'D')
1629 /* Acquire the text */
1634 /* Acquire the text */
1638 /* Store the text */
1639 if (!add_text(&a_ptr->text, head, s)) return (7);
1643 /* Process 'I' for "Info" (one line only) */
1644 else if (buf[0] == 'I')
1646 int tval, sval, pval;
1648 /* Scan for the values */
1649 if (3 != sscanf(buf+2, "%d:%d:%d",
1650 &tval, &sval, &pval)) return (1);
1652 /* Save the values */
1658 /* Process 'W' for "More Info" (one line only) */
1659 else if (buf[0] == 'W')
1661 int level, rarity, wgt;
1664 /* Scan for the values */
1665 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1666 &level, &rarity, &wgt, &cost)) return (1);
1668 /* Save the values */
1669 a_ptr->level = level;
1670 a_ptr->rarity = rarity;
1671 a_ptr->weight = wgt;
1675 /* Hack -- Process 'P' for "power" and such */
1676 else if (buf[0] == 'P')
1678 int ac, hd1, hd2, th, td, ta;
1680 /* Scan for the values */
1681 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
1682 &ac, &hd1, &hd2, &th, &td, &ta)) return (1);
1692 /* Hack -- Process 'F' for flags */
1693 else if (buf[0] == 'F')
1695 /* Parse every entry textually */
1696 for (s = buf + 2; *s; )
1698 /* Find the end of this entry */
1699 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1701 /* Nuke and skip any dividers */
1705 while ((*t == ' ') || (*t == '|')) t++;
1708 /* Parse this entry */
1709 if (0 != grab_one_artifact_flag(a_ptr, s)) return (5);
1711 /* Start the next entry */
1727 * Grab one flag in a ego-item_type from a textual string
1729 static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
1734 for (i = 0; i < 32; i++)
1736 if (streq(what, k_info_flags1[i]))
1738 e_ptr->flags1 |= (1L << i);
1744 for (i = 0; i < 32; i++)
1746 if (streq(what, k_info_flags2[i]))
1748 e_ptr->flags2 |= (1L << i);
1754 for (i = 0; i < 32; i++)
1756 if (streq(what, k_info_flags3[i]))
1758 e_ptr->flags3 |= (1L << i);
1765 msg_format("̤ÃΤÎ̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¡¦¥Õ¥é¥° '%s'¡£", what);
1767 msg_format("Unknown ego-item flag '%s'.", what);
1779 * Initialize the "e_info" array, by parsing an ascii "template" file
1781 errr parse_e_info(char *buf, header *head)
1788 static ego_item_type *e_ptr = NULL;
1791 /* Just before the first record */
1794 /* Just before the first line */
1798 /* Process 'N' for "New/Number/Name" */
1801 /* Find the colon before the name */
1802 s = strchr(buf+2, ':');
1804 /* Verify that colon */
1807 /* Nuke the colon, advance to the name */
1810 /* Paranoia -- require a name */
1811 if (!*s) return (1);
1816 /* Verify information */
1817 if (i < error_idx) return (4);
1819 /* Verify information */
1820 if (i >= head->info_num) return (2);
1822 /* Save the index */
1825 /* Point at the "info" */
1828 /* Store the name */
1829 if (!add_name(&e_ptr->name, head, s)) return (7);
1833 /* There better be a current e_ptr */
1834 else if (!e_ptr) return (3);
1838 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
1839 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
1840 else if (buf[0] == 'E')
1845 else if (buf[0] == 'E')
1847 /* Acquire the Text */
1850 /* Store the name */
1851 if (!add_name(&e_ptr->name, head, s)) return (7);
1856 /* Process 'D' for "Description" */
1857 else if (buf[0] == 'D')
1859 /* Acquire the text */
1862 /* Store the text */
1863 if (!add_text(&e_ptr->text, head, s)) return (7);
1868 /* Process 'X' for "Xtra" (one line only) */
1869 else if (buf[0] == 'X')
1873 /* Scan for the values */
1874 if (2 != sscanf(buf+2, "%d:%d",
1875 &slot, &rating)) return (1);
1877 /* Save the values */
1879 e_ptr->rating = rating;
1882 /* Process 'W' for "More Info" (one line only) */
1883 else if (buf[0] == 'W')
1885 int level, rarity, pad2;
1888 /* Scan for the values */
1889 if (4 != sscanf(buf+2, "%d:%d:%d:%ld",
1890 &level, &rarity, &pad2, &cost)) return (1);
1892 /* Save the values */
1893 e_ptr->level = level;
1894 e_ptr->rarity = rarity;
1895 /* e_ptr->weight = wgt; */
1899 /* Hack -- Process 'C' for "creation" */
1900 else if (buf[0] == 'C')
1904 /* Scan for the values */
1905 if (4 != sscanf(buf+2, "%d:%d:%d:%d",
1906 &th, &td, &ta, &pv)) return (1);
1908 e_ptr->max_to_h = th;
1909 e_ptr->max_to_d = td;
1910 e_ptr->max_to_a = ta;
1911 e_ptr->max_pval = pv;
1914 /* Hack -- Process 'F' for flags */
1915 else if (buf[0] == 'F')
1917 /* Parse every entry textually */
1918 for (s = buf + 2; *s; )
1920 /* Find the end of this entry */
1921 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
1923 /* Nuke and skip any dividers */
1927 while ((*t == ' ') || (*t == '|')) t++;
1930 /* Parse this entry */
1931 if (0 != grab_one_ego_item_flag(e_ptr, s)) return (5);
1933 /* Start the next entry */
1947 * Grab one (basic) flag in a monster_race from a textual string
1949 static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
1954 for (i = 0; i < 32; i++)
1956 if (streq(what, r_info_flags1[i]))
1958 r_ptr->flags1 |= (1L << i);
1964 for (i = 0; i < 32; i++)
1966 if (streq(what, r_info_flags2[i]))
1968 r_ptr->flags2 |= (1L << i);
1974 for (i = 0; i < 32; i++)
1976 if (streq(what, r_info_flags3[i]))
1978 r_ptr->flags3 |= (1L << i);
1984 for (i = 0; i < 32; i++)
1986 if (streq(what, r_info_flags7[i]))
1988 r_ptr->flags7 |= (1L << i);
1994 for (i = 0; i < 32; i++)
1996 if (streq(what, r_info_flags8[i]))
1998 r_ptr->flags8 |= (1L << i);
2004 for (i = 0; i < 32; i++)
2006 if (streq(what, r_info_flags9[i]))
2008 r_ptr->flags9 |= (1L << i);
2015 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2017 msg_format("Unknown monster flag '%s'.", what);
2027 * Grab one (spell) flag in a monster_race from a textual string
2029 static errr grab_one_spell_flag(monster_race *r_ptr, cptr what)
2034 for (i = 0; i < 32; i++)
2036 if (streq(what, r_info_flags4[i]))
2038 r_ptr->flags4 |= (1L << i);
2044 for (i = 0; i < 32; i++)
2046 if (streq(what, r_info_flags5[i]))
2048 r_ptr->flags5 |= (1L << i);
2054 for (i = 0; i < 32; i++)
2056 if (streq(what, r_info_flags6[i]))
2058 r_ptr->flags6 |= (1L << i);
2065 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2067 msg_format("Unknown monster flag '%s'.", what);
2079 * Initialize the "r_info" array, by parsing an ascii "template" file
2081 errr parse_r_info(char *buf, header *head)
2088 static monster_race *r_ptr = NULL;
2091 /* Process 'N' for "New/Number/Name" */
2094 /* Find the colon before the name */
2095 s = strchr(buf+2, ':');
2097 /* Verify that colon */
2100 /* Nuke the colon, advance to the name */
2103 /* Paranoia -- require a name */
2104 if (!*s) return (1);
2109 /* Verify information */
2110 if (i < error_idx) return (4);
2112 /* Verify information */
2113 if (i >= head->info_num) return (2);
2115 /* Save the index */
2118 /* Point at the "info" */
2121 /* Store the name */
2122 if (!add_name(&r_ptr->name, head, s)) return (7);
2126 /* There better be a current r_ptr */
2127 else if (!r_ptr) return (3);
2131 /* ±Ñ¸ì̾¤òÆɤà¥ë¡¼¥Á¥ó¤òÄɲà */
2132 /* 'E' ¤«¤é»Ï¤Þ¤ë¹Ô¤Ï±Ñ¸ì̾ */
2133 else if (buf[0] == 'E')
2135 /* Acquire the Text */
2138 /* Store the name */
2139 if (!add_name(&r_ptr->E_name, head, s)) return (7);
2142 else if (buf[0] == 'E')
2144 /* Acquire the Text */
2147 /* Store the name */
2148 if (!add_name(&r_ptr->name, head, s)) return (7);
2151 /* Process 'D' for "Description" */
2152 else if (buf[0] == 'D')
2157 /* Acquire the text */
2162 /* Acquire the text */
2166 /* Store the text */
2167 if (!add_text(&r_ptr->text, head, s)) return (7);
2170 /* Process 'G' for "Graphics" (one line only) */
2171 else if (buf[0] == 'G')
2177 if (!buf[2]) return (1);
2178 if (!buf[3]) return (1);
2179 if (!buf[4]) return (1);
2181 /* Extract the char */
2184 /* Extract the attr */
2185 tmp = color_char_to_attr(buf[4]);
2188 if (tmp < 0) return (1);
2190 /* Save the values */
2191 r_ptr->d_char = sym;
2192 r_ptr->d_attr = tmp;
2195 /* Process 'I' for "Info" (one line only) */
2196 else if (buf[0] == 'I')
2198 int spd, hp1, hp2, aaf, ac, slp;
2200 /* Scan for the other values */
2201 if (6 != sscanf(buf+2, "%d:%dd%d:%d:%d:%d",
2202 &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1);
2204 /* Save the values */
2213 /* Process 'W' for "More Info" (one line only) */
2214 else if (buf[0] == 'W')
2221 /* Scan for the values */
2222 if (6 != sscanf(buf+2, "%d:%d:%d:%ld:%ld:%d",
2223 &lev, &rar, &pad, &exp, &nextexp, &nextmon)) return (1);
2225 /* Save the values */
2227 r_ptr->rarity = rar;
2230 r_ptr->next_exp = nextexp;
2231 r_ptr->next_r_idx = nextmon;
2234 /* Process 'B' for "Blows" (up to four lines) */
2235 else if (buf[0] == 'B')
2239 /* Find the next empty blow slot (if any) */
2240 for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break;
2242 /* Oops, no more slots */
2243 if (i == 4) return (1);
2245 /* Analyze the first field */
2246 for (s = t = buf+2; *t && (*t != ':'); t++) /* loop */;
2248 /* Terminate the field (if necessary) */
2249 if (*t == ':') *t++ = '\0';
2251 /* Analyze the method */
2252 for (n1 = 0; r_info_blow_method[n1]; n1++)
2254 if (streq(s, r_info_blow_method[n1])) break;
2257 /* Invalid method */
2258 if (!r_info_blow_method[n1]) return (1);
2260 /* Analyze the second field */
2261 for (s = t; *t && (*t != ':'); t++) /* loop */;
2263 /* Terminate the field (if necessary) */
2264 if (*t == ':') *t++ = '\0';
2266 /* Analyze effect */
2267 for (n2 = 0; r_info_blow_effect[n2]; n2++)
2269 if (streq(s, r_info_blow_effect[n2])) break;
2272 /* Invalid effect */
2273 if (!r_info_blow_effect[n2]) return (1);
2275 /* Analyze the third field */
2276 for (s = t; *t && (*t != 'd'); t++) /* loop */;
2278 /* Terminate the field (if necessary) */
2279 if (*t == 'd') *t++ = '\0';
2281 /* Save the method */
2282 r_ptr->blow[i].method = n1;
2284 /* Save the effect */
2285 r_ptr->blow[i].effect = n2;
2287 /* Extract the damage dice and sides */
2288 r_ptr->blow[i].d_dice = atoi(s);
2289 r_ptr->blow[i].d_side = atoi(t);
2292 /* Process 'F' for "Basic Flags" (multiple lines) */
2293 else if (buf[0] == 'F')
2295 /* Parse every entry */
2296 for (s = buf + 2; *s; )
2298 /* Find the end of this entry */
2299 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2301 /* Nuke and skip any dividers */
2305 while (*t == ' ' || *t == '|') t++;
2308 /* Parse this entry */
2309 if (0 != grab_one_basic_flag(r_ptr, s)) return (5);
2311 /* Start the next entry */
2316 /* Process 'S' for "Spell Flags" (multiple lines) */
2317 else if (buf[0] == 'S')
2319 /* Parse every entry */
2320 for (s = buf + 2; *s; )
2322 /* Find the end of this entry */
2323 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2325 /* Nuke and skip any dividers */
2329 while ((*t == ' ') || (*t == '|')) t++;
2332 /* XXX XXX XXX Hack -- Read spell frequency */
2333 if (1 == sscanf(s, "1_IN_%d", &i))
2335 /* Extract a "frequency" */
2336 r_ptr->freq_spell = r_ptr->freq_inate = 100 / i;
2338 /* Start at next entry */
2345 /* Parse this entry */
2346 if (0 != grab_one_spell_flag(r_ptr, s)) return (5);
2348 /* Start the next entry */
2363 * Grab one flag for a dungeon type from a textual string
2365 static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
2370 for (i = 0; i < 32; i++)
2372 if (streq(what, d_info_flags1[i]))
2374 d_ptr->flags1 |= (1L << i);
2381 msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
2383 msg_format("Unknown dungeon type flag '%s'.", what);
2391 * Grab one (basic) flag in a monster_race from a textual string
2393 static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
2398 for (i = 0; i < 32; i++)
2400 if (streq(what, r_info_flags1[i]))
2402 d_ptr->mflags1 |= (1L << i);
2408 for (i = 0; i < 32; i++)
2410 if (streq(what, r_info_flags2[i]))
2412 d_ptr->mflags2 |= (1L << i);
2418 for (i = 0; i < 32; i++)
2420 if (streq(what, r_info_flags3[i]))
2422 d_ptr->mflags3 |= (1L << i);
2428 for (i = 0; i < 32; i++)
2430 if (streq(what, r_info_flags7[i]))
2432 d_ptr->mflags7 |= (1L << i);
2438 for (i = 0; i < 32; i++)
2440 if (streq(what, r_info_flags8[i]))
2442 d_ptr->mflags8 |= (1L << i);
2448 for (i = 0; i < 32; i++)
2450 if (streq(what, r_info_flags9[i]))
2452 d_ptr->mflags9 |= (1L << i);
2459 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2461 msg_format("Unknown monster flag '%s'.", what);
2469 * Grab one (spell) flag in a monster_race from a textual string
2471 static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
2476 for (i = 0; i < 32; i++)
2478 if (streq(what, r_info_flags4[i]))
2480 d_ptr->mflags4 |= (1L << i);
2486 for (i = 0; i < 32; i++)
2488 if (streq(what, r_info_flags5[i]))
2490 d_ptr->mflags5 |= (1L << i);
2496 for (i = 0; i < 32; i++)
2498 if (streq(what, r_info_flags6[i]))
2500 d_ptr->mflags6 |= (1L << i);
2507 msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
2509 msg_format("Unknown monster flag '%s'.", what);
2517 * Initialize the "d_info" array, by parsing an ascii "template" file
2519 errr parse_d_info(char *buf, header *head)
2526 static dungeon_info_type *d_ptr = NULL;
2529 /* Process 'N' for "New/Number/Name" */
2532 /* Find the colon before the name */
2533 s = strchr(buf+2, ':');
2535 /* Verify that colon */
2538 /* Nuke the colon, advance to the name */
2541 /* Paranoia -- require a name */
2542 if (!*s) return (1);
2547 /* Verify information */
2548 if (i < error_idx) return (4);
2550 /* Verify information */
2551 if (i >= head->info_num) return (2);
2553 /* Save the index */
2556 /* Point at the "info" */
2559 /* Store the name */
2560 if (!add_name(&d_ptr->name, head, s)) return (7);
2565 else if (buf[0] == 'E') return (0);
2567 else if (buf[0] == 'E')
2569 /* Acquire the Text */
2572 /* Store the name */
2573 if (!add_name(&d_ptr->name, head, s)) return (7);
2577 /* Process 'D' for "Description */
2578 else if (buf[0] == 'D')
2583 /* Acquire the text */
2588 /* Acquire the text */
2592 /* Store the text */
2593 if (!add_text(&d_ptr->text, head, s)) return (7);
2596 /* Process 'W' for "More Info" (one line only) */
2597 else if (buf[0] == 'W')
2599 int min_lev, max_lev;
2601 int min_alloc, max_chance;
2602 int obj_good, obj_great;
2605 /* Scan for the values */
2606 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%x:%x",
2607 &min_lev, &max_lev, &min_plev, &mode, &min_alloc, &max_chance, &obj_good, &obj_great, (unsigned int *)&pit, (unsigned int *)&nest)) return (1);
2609 /* Save the values */
2610 d_ptr->mindepth = min_lev;
2611 d_ptr->maxdepth = max_lev;
2612 d_ptr->min_plev = min_plev;
2614 d_ptr->min_m_alloc_level = min_alloc;
2615 d_ptr->max_m_alloc_chance = max_chance;
2616 d_ptr->obj_good = obj_good;
2617 d_ptr->obj_great = obj_great;
2622 /* Process 'P' for "Place Info" */
2623 else if (buf[0] == 'P')
2627 /* Scan for the values */
2628 if (2 != sscanf(buf+2, "%d:%d", &dy, &dx)) return (1);
2630 /* Save the values */
2635 /* Process 'L' for "fLoor type" (one line only) */
2636 else if (buf[0] == 'L')
2642 /* Scan for the values */
2643 if (7 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d",
2644 &f1, &p1, &f2, &p2, &f3, &p3, &tunnel)) return (1);
2646 /* Save the values */
2648 d_ptr->floor_percent1 = p1;
2650 d_ptr->floor_percent2 = p2;
2652 d_ptr->floor_percent3 = p3;
2653 d_ptr->tunnel_percent = tunnel;
2656 /* Process 'A' for "wAll type" (one line only) */
2657 else if (buf[0] == 'A')
2659 int w1, w2, w3, outer, inner, stream1, stream2;
2662 /* Scan for the values */
2663 if (10 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
2664 &w1, &p1, &w2, &p2, &w3, &p3, &outer, &inner, &stream1, &stream2)) return (1);
2666 /* Save the values */
2667 d_ptr->fill_type1 = w1;
2668 d_ptr->fill_percent1 = p1;
2669 d_ptr->fill_type2 = w2;
2670 d_ptr->fill_percent2 = p2;
2671 d_ptr->fill_type3 = w3;
2672 d_ptr->fill_percent3 = p3;
2673 d_ptr->outer_wall = outer;
2674 d_ptr->inner_wall = inner;
2675 d_ptr->stream1 = stream1;
2676 d_ptr->stream2 = stream2;
2679 /* Process 'F' for "Dungeon Flags" (multiple lines) */
2680 else if (buf[0] == 'F')
2682 int artif = 0, monst = 0;
2684 /* Parse every entry */
2685 for (s = buf + 2; *s; )
2687 /* Find the end of this entry */
2688 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2690 /* Nuke and skip any dividers */
2694 while (*t == ' ' || *t == '|') t++;
2697 /* XXX XXX XXX Hack -- Read Final Artifact */
2698 if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
2700 /* Extract a "Final Artifact" */
2701 d_ptr->final_artifact = artif;
2703 /* Start at next entry */
2710 /* XXX XXX XXX Hack -- Read Final Object */
2711 if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
2713 /* Extract a "Final Artifact" */
2714 d_ptr->final_object = artif;
2716 /* Start at next entry */
2723 /* XXX XXX XXX Hack -- Read Artifact Guardian */
2724 if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
2726 /* Extract a "Artifact Guardian" */
2727 d_ptr->final_guardian = monst;
2729 /* Start at next entry */
2736 /* XXX XXX XXX Hack -- Read Special Percentage */
2737 if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
2739 /* Extract a "Special %" */
2740 d_ptr->special_div = monst;
2742 /* Start at next entry */
2749 /* Parse this entry */
2750 if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
2752 /* Start the next entry */
2757 /* Process 'M' for "Basic Flags" (multiple lines) */
2758 else if (buf[0] == 'M')
2760 byte r_char_number = 0, r_char;
2762 /* Parse every entry */
2763 for (s = buf + 2; *s; )
2765 /* Find the end of this entry */
2766 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2768 /* Nuke and skip any dividers */
2772 while (*t == ' ' || *t == '|') t++;
2775 /* XXX XXX XXX Hack -- Read monster symbols */
2776 if (1 == sscanf(s, "R_CHAR_%c", &r_char))
2778 /* Limited to 5 races */
2779 if(r_char_number >= 5) continue;
2781 /* Extract a "frequency" */
2782 d_ptr->r_char[r_char_number++] = r_char;
2784 /* Start at next entry */
2791 /* Parse this entry */
2792 if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
2794 /* Start the next entry */
2799 /* Process 'S' for "Spell Flags" (multiple lines) */
2800 else if (buf[0] == 'S')
2802 /* Parse every entry */
2803 for (s = buf + 2; *s; )
2805 /* Find the end of this entry */
2806 for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
2808 /* Nuke and skip any dividers */
2812 while ((*t == ' ') || (*t == '|')) t++;
2815 /* XXX XXX XXX Hack -- Read spell frequency */
2816 if (1 == sscanf(s, "1_IN_%d", &i))
2818 /* Start at next entry */
2825 /* Parse this entry */
2826 if (0 != grab_one_spell_monster_flag(d_ptr, s)) return (5);
2828 /* Start the next entry */
2841 #else /* ALLOW_TEMPLATES */
2847 #endif /* ALLOW_TEMPLATES */
2850 /* Random dungeon grid effects */
2851 #define RANDOM_NONE 0x00
2852 #define RANDOM_FEATURE 0x01
2853 #define RANDOM_MONSTER 0x02
2854 #define RANDOM_OBJECT 0x04
2855 #define RANDOM_EGO 0x08
2856 #define RANDOM_ARTIFACT 0x10
2857 #define RANDOM_TRAP 0x20
2860 typedef struct dungeon_grid dungeon_grid;
2864 int feature; /* Terrain feature */
2865 int monster; /* Monster */
2866 int object; /* Object */
2867 int ego; /* Ego-Item */
2868 int artifact; /* Artifact */
2869 int trap; /* Trap */
2870 int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */
2871 int special; /* Reserved for special terrain info */
2872 int random; /* Number of the random effect */
2876 static dungeon_grid letter[255];
2880 * Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid
2882 static errr parse_line_feature(char *buf)
2888 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
2890 /* Tokenize the line */
2891 if ((num = tokenize(buf+2, 9, zz, 0)) > 1)
2893 /* Letter to assign */
2894 int index = zz[0][0];
2896 /* Reset the info for the letter */
2897 letter[index].feature = 0;
2898 letter[index].monster = 0;
2899 letter[index].object = 0;
2900 letter[index].ego = 0;
2901 letter[index].artifact = 0;
2902 letter[index].trap = 0;
2903 letter[index].cave_info = 0;
2904 letter[index].special = 0;
2905 letter[index].random = 0;
2911 letter[index].special = atoi(zz[8]);
2915 if (zz[7][0] == '*')
2917 letter[index].random |= RANDOM_TRAP;
2922 letter[index].trap = atoi(zz[7]);
2927 letter[index].trap = atoi(zz[7]);
2932 if (zz[6][0] == '*')
2934 letter[index].random |= RANDOM_ARTIFACT;
2939 letter[index].artifact = atoi(zz[6]);
2944 letter[index].artifact = atoi(zz[6]);
2949 if (zz[5][0] == '*')
2951 letter[index].random |= RANDOM_EGO;
2956 letter[index].ego = atoi(zz[5]);
2961 letter[index].ego = atoi(zz[5]);
2966 if (zz[4][0] == '*')
2968 letter[index].random |= RANDOM_OBJECT;
2973 letter[index].object = atoi(zz[4]);
2978 letter[index].object = atoi(zz[4]);
2983 if (zz[3][0] == '*')
2985 letter[index].random |= RANDOM_MONSTER;
2989 letter[index].monster = atoi(zz[3]);
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);
3166 if (tokenize(s+2, 2, zz, 0) == 2)
3168 /* Index of the action */
3169 int action_index = atoi(zz[0]);
3171 /* Name of the action */
3172 strcpy(building[index].act_script[action_index], zz[1]);
3177 #else /* USE_SCRIPT */
3178 /* Ignore scripts */
3180 #endif /* USE_SCRIPT */
3185 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
3194 * Parse a sub-file of the "extra info"
3196 static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
3203 /* Skip "empty" lines */
3204 if (!buf[0]) return (0);
3206 /* Skip "blank" lines */
3207 if (isspace(buf[0])) return (0);
3210 if (buf[0] == '#') return (0);
3212 /* Require "?:*" format */
3213 if (buf[1] != ':') return (1);
3216 /* Process "%:<fname>" */
3219 /* Attempt to Process the given file */
3220 return (process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax));
3223 /* Process "F:<letter>:<terrain>:<cave_info>:<monster>:<object>:<ego>:<artifact>:<trap>:<special>" -- info for dungeon grid */
3226 return parse_line_feature(buf);
3229 /* Process "D:<dungeon>" -- info for the cave grids */
3230 else if (buf[0] == 'D')
3232 object_type object_type_body;
3234 /* Acquire the text */
3237 /* Length of the text */
3238 int len = strlen(s);
3240 if (init_flags & INIT_ONLY_BUILDINGS) return (0);
3242 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
3244 /* Access the grid */
3245 cave_type *c_ptr = &cave[*y][*x];
3249 int object_index = letter[idx].object;
3250 int monster_index = letter[idx].monster;
3251 int random = letter[idx].random;
3252 int artifact_index = letter[idx].artifact;
3254 /* Lay down a floor */
3255 c_ptr->feat = letter[idx].feature;
3257 /* Only the features */
3258 if (init_flags & INIT_ONLY_FEATURES) continue;
3261 c_ptr->info = letter[idx].cave_info;
3263 /* Create a monster */
3264 if (random & RANDOM_MONSTER)
3266 monster_level = base_level + monster_index;
3268 place_monster(*y, *x, TRUE, TRUE);
3270 monster_level = base_level;
3272 else if (monster_index)
3274 /* Make alive again */
3275 if (r_info[monster_index].flags1 & RF1_UNIQUE)
3277 r_info[monster_index].cur_num = 0;
3278 r_info[monster_index].max_num = 1;
3281 /* Make alive again */
3282 if (r_info[monster_index].flags7 & RF7_UNIQUE_7)
3284 if (r_info[monster_index].cur_num == r_info[monster_index].max_num)
3286 r_info[monster_index].max_num++;
3291 place_monster_aux(*y, *x, monster_index, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);
3294 /* Object (and possible trap) */
3295 if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP))
3297 object_level = base_level + object_index;
3300 * Random trap and random treasure defined
3301 * 25% chance for trap and 75% chance for object
3303 if (rand_int(100) < 75)
3305 place_object(*y, *x, FALSE, FALSE);
3312 object_level = base_level;
3314 else if (random & RANDOM_OBJECT)
3316 object_level = base_level + object_index;
3318 /* Create an out of deep object */
3319 if (rand_int(100) < 75)
3320 place_object(*y, *x, FALSE, FALSE);
3321 else if (rand_int(100) < 80)
3322 place_object(*y, *x, TRUE, FALSE);
3324 place_object(*y, *x, TRUE, TRUE);
3326 object_level = base_level;
3329 else if (random & RANDOM_TRAP)
3333 else if (object_index)
3335 /* Get local object */
3336 object_type *o_ptr = &object_type_body;
3338 /* Create the item */
3339 object_prep(o_ptr, object_index);
3341 if (o_ptr->tval == TV_GOLD)
3343 coin_type = object_index - OBJ_GOLD_LIST;
3348 /* Apply magic (no messages, no artifacts) */
3349 apply_magic(o_ptr, base_level, FALSE, TRUE, FALSE, FALSE);
3352 o_ptr->python = object_create_callback(o_ptr);
3353 #endif /* USE_SCRIPT */
3355 (void)drop_near(o_ptr, -1, *y, *x);
3361 if (a_info[artifact_index].cur_num)
3365 object_type *q_ptr = &forge;
3367 object_prep(q_ptr, k_idx);
3369 q_ptr->python = object_create_callback(q_ptr);
3370 #endif /* USE_SCRIPT */
3372 /* Drop it in the dungeon */
3373 (void)drop_near(q_ptr, -1, *y, *x);
3377 /* Create the artifact */
3378 create_named_art(artifact_index, *y, *x);
3380 a_info[artifact_index].cur_num = 1;
3384 /* Terrain special */
3385 c_ptr->special = letter[idx].special;
3393 /* Process "Q:<number>:<command>:... -- quest info */
3394 else if (buf[0] == 'Q')
3401 num = tokenize(buf + 2, 33, zz, 0);
3405 num = tokenize(buf + 3, 33, zz, 0);
3408 /* Have we enough parameters? */
3409 if (num < 3) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3412 q_ptr = &(quest[atoi(zz[0])]);
3414 /* Process "Q:<q_index>:Q:<type>:<num_mon>:<cur_num>:<max_num>:<level>:<r_idx>:<k_idx>:<flags>" -- quest info */
3415 if (zz[1][0] == 'Q')
3417 if (init_flags & INIT_ASSIGN)
3419 monster_race *r_ptr;
3420 artifact_type *a_ptr;
3422 if (num < 9) return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
3424 q_ptr->type = atoi(zz[2]);
3425 q_ptr->num_mon = atoi(zz[3]);
3426 q_ptr->cur_num = atoi(zz[4]);
3427 q_ptr->max_num = atoi(zz[5]);
3428 q_ptr->level = atoi(zz[6]);
3429 q_ptr->r_idx = atoi(zz[7]);
3430 q_ptr->k_idx = atoi(zz[8]);
3431 q_ptr->dungeon = atoi(zz[9]);
3434 q_ptr->flags = atoi(zz[10]);
3436 r_ptr = &r_info[q_ptr->r_idx];
3437 if (r_ptr->flags1 & RF1_UNIQUE)
3438 r_ptr->flags1 |= RF1_QUESTOR;
3440 a_ptr = &a_info[q_ptr->k_idx];
3441 a_ptr->flags3 |= TR3_QUESTITEM;
3446 /* Process "Q:<q_index>:N:<name>" -- quest name */
3447 else if (zz[1][0] == 'N')
3449 if (init_flags & (INIT_ASSIGN | INIT_SHOW_TEXT))
3451 strcpy(q_ptr->name, zz[2]);
3457 /* Process "Q:<q_index>:T:<text>" -- quest description line */
3458 else if (zz[1][0] == 'T')
3460 if (init_flags & INIT_SHOW_TEXT)
3462 strcpy(quest_text[quest_text_line], zz[2]);
3470 /* Process "W:<command>: ..." -- info for the wilderness */
3471 else if (buf[0] == 'W')
3473 return parse_line_wilderness(buf, ymin, xmin, ymax, xmax, y, x);
3476 /* Process "P:<y>:<x>" -- player position */
3477 else if (buf[0] == 'P')
3479 if (init_flags & INIT_CREATE_DUNGEON)
3481 if (tokenize(buf + 2, 2, zz, 0) == 2)
3483 int panels_x, panels_y;
3485 /* Hack - Set the dungeon size */
3486 panels_y = (*y / SCREEN_HGT);
3487 if (*y % SCREEN_HGT) panels_y++;
3488 cur_hgt = panels_y * SCREEN_HGT;
3490 panels_x = (*x / SCREEN_WID);
3491 if (*x % SCREEN_WID) panels_x++;
3492 cur_wid = panels_x * SCREEN_WID;
3494 /* Choose a panel row */
3495 max_panel_rows = (cur_hgt / SCREEN_HGT) * 2 - 2;
3496 if (max_panel_rows < 0) max_panel_rows = 0;
3498 /* Choose a panel col */
3499 max_panel_cols = (cur_wid / SCREEN_WID) * 2 - 2;
3500 if (max_panel_cols < 0) max_panel_cols = 0;
3502 /* Assume illegal panel */
3503 panel_row = max_panel_rows;
3504 panel_col = max_panel_cols;
3506 /* Place player in a quest level */
3507 if (p_ptr->inside_quest)
3511 /* Delete the monster (if any) */
3512 delete_monster(py, px);
3520 /* Place player in the town */
3521 else if (!p_ptr->oldpx && !p_ptr->oldpy)
3523 p_ptr->oldpy = atoi(zz[0]);
3524 p_ptr->oldpx = atoi(zz[1]);
3532 /* Process "B:<Index>:<Command>:..." -- Building definition */
3533 else if (buf[0] == 'B')
3535 return parse_line_building(buf);
3538 /* Process "M:<type>:<maximum>" -- set maximum values */
3539 else if (buf[0] == 'M')
3541 if (tokenize(buf+2, 2, zz, 0) == 2)
3544 if (zz[0][0] == 'T')
3546 max_towns = atoi(zz[1]);
3549 /* Maximum quests */
3550 else if (zz[0][0] == 'Q')
3552 max_quests = atoi(zz[1]);
3556 else if (zz[0][0] == 'R')
3558 max_r_idx = atoi(zz[1]);
3562 else if (zz[0][0] == 'K')
3564 max_k_idx = atoi(zz[1]);
3568 else if (zz[0][0] == 'V')
3570 max_v_idx = atoi(zz[1]);
3574 else if (zz[0][0] == 'F')
3576 max_f_idx = atoi(zz[1]);
3580 else if (zz[0][0] == 'A')
3582 max_a_idx = atoi(zz[1]);
3586 else if (zz[0][0] == 'E')
3588 max_e_idx = atoi(zz[1]);
3592 else if (zz[0][0] == 'D')
3594 max_d_idx = atoi(zz[1]);
3598 else if (zz[0][0] == 'O')
3600 max_o_idx = atoi(zz[1]);
3604 else if (zz[0][0] == 'M')
3606 max_m_idx = atoi(zz[1]);
3609 /* Wilderness size */
3610 else if (zz[0][0] == 'W')
3612 /* Maximum wild_x_size */
3613 if (zz[0][1] == 'X')
3614 max_wild_x = atoi(zz[1]);
3615 /* Maximum wild_y_size */
3616 if (zz[0][1] == 'Y')
3617 max_wild_y = atoi(zz[1]);
3631 static cptr variant = "ZANGBAND";
3635 * Helper function for "process_dungeon_file()"
3637 static cptr process_dungeon_file_expr(char **sp, char *fp)
3653 while (isspace(*s)) s++;
3671 t = process_dungeon_file_expr(&s, &f);
3680 else if (streq(t, "IOR"))
3683 while (*s && (f != b2))
3685 t = process_dungeon_file_expr(&s, &f);
3686 if (*t && !streq(t, "0")) v = "1";
3691 else if (streq(t, "AND"))
3694 while (*s && (f != b2))
3696 t = process_dungeon_file_expr(&s, &f);
3697 if (*t && streq(t, "0")) v = "0";
3702 else if (streq(t, "NOT"))
3705 while (*s && (f != b2))
3707 t = process_dungeon_file_expr(&s, &f);
3708 if (*t && streq(t, "1")) v = "0";
3713 else if (streq(t, "EQU"))
3716 if (*s && (f != b2))
3718 t = process_dungeon_file_expr(&s, &f);
3720 while (*s && (f != b2))
3723 t = process_dungeon_file_expr(&s, &f);
3724 if (*t && !streq(p, t)) v = "0";
3729 else if (streq(t, "LEQ"))
3732 if (*s && (f != b2))
3734 t = process_dungeon_file_expr(&s, &f);
3736 while (*s && (f != b2))
3739 t = process_dungeon_file_expr(&s, &f);
3740 if (*t && (strcmp(p, t) > 0)) v = "0";
3745 else if (streq(t, "GEQ"))
3748 if (*s && (f != b2))
3750 t = process_dungeon_file_expr(&s, &f);
3752 while (*s && (f != b2))
3755 t = process_dungeon_file_expr(&s, &f);
3756 if (*t && (strcmp(p, t) < 0)) v = "0";
3763 while (*s && (f != b2))
3765 t = process_dungeon_file_expr(&s, &f);
3770 if (f != b2) v = "?x?x?";
3772 /* Extract final and Terminate */
3773 if ((f = *s) != '\0') *s++ = '\0';
3779 /* Accept all printables except spaces and brackets */
3780 while (isprint(*s) && !strchr(" []", *s)) ++s;
3782 /* Extract final and Terminate */
3783 if ((f = *s) != '\0') *s++ = '\0';
3789 if (streq(b+1, "SYS"))
3795 else if (streq(b+1, "GRAF"))
3800 else if (streq(b+1, "MONOCHROME"))
3809 else if (streq(b+1, "RACE"))
3812 v = rp_ptr->E_title;
3819 else if (streq(b+1, "CLASS"))
3822 v = cp_ptr->E_title;
3829 else if (streq(b+1, "REALM1"))
3832 v = E_realm_names[p_ptr->realm1];
3834 v = realm_names[p_ptr->realm1];
3839 else if (streq(b+1, "REALM2"))
3842 v = E_realm_names[p_ptr->realm2];
3844 v = realm_names[p_ptr->realm2];
3849 else if (streq(b+1, "PLAYER"))
3855 else if (streq(b+1, "TOWN"))
3857 sprintf(tmp, "%d", p_ptr->town_num);
3862 else if (streq(b+1, "LEVEL"))
3864 sprintf(tmp, "%d", p_ptr->lev);
3868 /* Current quest number */
3869 else if (streq(b+1, "QUEST_NUMBER"))
3871 sprintf(tmp, "%d", p_ptr->inside_quest);
3875 /* Number of last quest */
3876 else if (streq(b+1, "LEAVING_QUEST"))
3878 sprintf(tmp, "%d", leaving_quest);
3883 else if (prefix(b+1, "QUEST"))
3885 /* "QUEST" uses a special parameter to determine the number of the quest */
3886 sprintf(tmp, "%d", quest[atoi(b+6)].status);
3891 else if (prefix(b+1, "RANDOM"))
3893 /* "RANDOM" uses a special parameter to determine the number of the quest */
3894 sprintf(tmp, "%d", (int)(seed_town%atoi(b+7)));
3899 else if (streq(b+1, "VARIANT"))
3905 else if (streq(b+1, "WILDERNESS"))
3908 sprintf(tmp, "NONE");
3910 sprintf(tmp, "LITE");
3912 sprintf(tmp, "NORMAL");
3935 errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
3945 bool bypass = FALSE;
3947 int x = xmin, y = ymin;
3950 /* Build the filename */
3951 path_build(buf, 1024, ANGBAND_DIR_EDIT, name);
3954 fp = my_fopen(buf, "r");
3957 if (!fp) return (-1);
3960 /* Process the file */
3961 while (0 == my_fgets(fp, buf, 1024))
3967 /* Skip "empty" lines */
3968 if (!buf[0]) continue;
3970 /* Skip "blank" lines */
3971 if (isspace(buf[0])) continue;
3974 if (buf[0] == '#') continue;
3977 /* Process "?:<expr>" */
3978 if ((buf[0] == '?') && (buf[1] == ':'))
3987 /* Parse the expr */
3988 v = process_dungeon_file_expr(&s, &f);
3991 bypass = (streq(v, "0") ? TRUE : FALSE);
3997 /* Apply conditionals */
3998 if (bypass) continue;
4001 /* Process "%:<file>" */
4004 /* Process that file if allowed */
4005 (void)process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax);
4012 /* Process the line */
4013 err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
4025 oops = (((err > 0) && (err < PARSE_ERROR_MAX)) ? err_str[err] : "unknown");
4028 msg_format("Error %d (%s) at line %d of '%s'.", err, oops, num, name);
4030 msg_format("'%s'¤ò²òÀÏÃæ¡£", buf);
4032 msg_format("Parsing '%s'.", buf);
4039 /* Close the file */
4049 void write_r_info_txt(void)
4051 int i, j, z, fc, bc;
4059 monster_race *r_ptr;
4061 monster_blow *b_ptr;
4063 FILE *fff = fopen("output.txt", "wt");
4071 fprintf(fff, "# File: r_info.txt (autogenerated)\n\n");
4073 fprintf(fff, "# Version stamp (required)\n\n");
4076 fprintf(fff, "V:%d.%d.%d\n\n\n", r_head->v_major, r_head->v_minor, r_head->v_patch);
4079 fprintf(fff, "##### The Player #####\n\n");
4081 for (z = -1; z < alloc_race_size; z++)
4083 /* Output the monsters in order */
4084 i = (z >= 0) ? alloc_race_table[z].index : 0;
4086 /* Acquire the monster */
4089 /* Ignore empty monsters */
4090 if (!strlen(r_name + r_ptr->name)) continue;
4092 /* Ignore useless monsters */
4093 if (i && !r_ptr->speed) continue;
4095 /* Write a note if necessary */
4096 if (i && (!r_ptr->level != !mode))
4101 fprintf(fff, "\n##### Town monsters #####\n\n");
4103 /* Note the dungeon */
4106 fprintf(fff, "\n##### Normal monsters #####\n\n");
4109 /* Record the change */
4110 mode = r_ptr->level;
4113 /* Acquire the flags */
4114 f_ptr[0] = r_ptr->flags1; n_ptr[0] = r_info_flags1;
4115 f_ptr[1] = r_ptr->flags2; n_ptr[1] = r_info_flags2;
4116 f_ptr[2] = r_ptr->flags3; n_ptr[2] = r_info_flags3;
4117 f_ptr[3] = r_ptr->flags4; n_ptr[3] = r_info_flags4;
4118 f_ptr[4] = r_ptr->flags5; n_ptr[4] = r_info_flags5;
4119 f_ptr[5] = r_ptr->flags6; n_ptr[5] = r_info_flags6;
4120 f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
4121 f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
4122 f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
4124 /* Write New/Number/Name */
4125 fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
4128 fprintf(fff, "G:%c:%c\n", r_ptr->d_char, color_char[r_ptr->d_attr]);
4130 /* Write Information */
4131 fprintf(fff, "I:%d:%dd%d:%d:%d:%d\n", r_ptr->speed, r_ptr->hdice, r_ptr->hside,
4132 r_ptr->aaf, r_ptr->ac, r_ptr->sleep);
4134 /* Write more information */
4135 fprintf(fff, "W:%d:%d:%d:%ld\n", r_ptr->level, r_ptr->rarity, r_ptr->extra, r_ptr->mexp);
4138 for(j = 0; j < 4; j++)
4140 b_ptr = &(r_ptr->blow[j]);
4142 /* Stop when done */
4143 if (!b_ptr->method) break;
4145 /* Write the blows */
4146 fprintf(fff, "B:%s:%s:%dd%d\n", r_info_blow_method[b_ptr->method],
4147 r_info_blow_effect[b_ptr->effect],
4148 b_ptr->d_dice, b_ptr->d_side);
4151 /* Extract the flags */
4152 for (fc = 0, j = 0; j < 96; j++)
4154 /* Check this flag */
4155 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4158 /* Extract the extra flags */
4159 for (j = 192; j < 288; j++)
4161 /* Check this flag */
4162 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4165 /* Write the flags */
4166 for (j = 0; j < fc;)
4170 /* Start the line */
4173 for (bc = 0; (bc < 60) && (j < fc); j++)
4177 /* Format the flag */
4178 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4180 /* Add it to the buffer */
4183 /* Note the length */
4187 /* Done with this line; write it */
4188 fprintf(fff, "%s\n", buf);
4191 /* Write Spells if applicable */
4192 if (r_ptr->freq_spell)
4194 /* Write the frequency */
4195 fprintf(fff, "S:1_IN_%d | \n", 100 / r_ptr->freq_spell);
4197 /* Extract the spell flags */
4198 for (fc = 0, j = 96; j < 192; j++)
4200 /* Check this flag */
4201 if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
4204 /* Write the flags */
4205 for (j = 0; j < fc;)
4209 /* Start the line */
4212 for (bc = 0, t = buf + 2; (bc < 60) && (j < fc); j++)
4216 /* Format the flag */
4217 sprintf(t, "%s%s", flags[j], (j < fc - 1) ? " | " : "");
4221 /* Note the length */
4228 /* Done with this line; write it */
4229 fprintf(fff, "%s\n", buf);
4233 /* Acquire the description */
4234 desc = r_text + r_ptr->text;
4235 dlen = strlen(desc);
4237 /* Write Description */
4238 for (j = 0; j < dlen;)
4242 /* Start the line */
4245 for (bc = 0, t = buf + 2; ((bc < 60) || !isspace(desc[j])) && (j < dlen); j++, bc++, t++)
4253 /* Done with this line; write it */
4254 fprintf(fff, "%s\n", buf);
4257 /* Space between entries */