OSDN Git Service

通常のセーブ/ロード時以外でc_ptr->mimicに0以外の値を代入する際に, 最
[hengband/hengband.git] / src / init1.c
index 71c9b10..7c00a26 100644 (file)
@@ -1,5 +1,13 @@
 /* File: init1.c */
 
+/*
+ * Copyright (c) 1997 Ben Harrison
+ *
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
+ */
+
 /* Purpose: Initialization (part 1) -BEN- */
 
 #include "angband.h"
 
 #ifdef JP
 #undef strchr
-char* _strchr(char* ptr, char ch)
+static char *_strchr(const char *ptr, char ch)
 {
        for ( ; *ptr != '\0'; ++ptr)
        {
-               if (*ptr == ch) return ptr;
+               if (*ptr == ch) return (char *)ptr;
                if (iskanji(*ptr)) ++ptr;
        }
 
@@ -143,14 +151,14 @@ static cptr r_info_flags1[] =
        "MALE",
        "FEMALE",
        "CHAR_CLEAR",
-       "CHAR_MULTI",
+       "SHAPECHANGER",
        "ATTR_CLEAR",
        "ATTR_MULTI",
        "FORCE_DEPTH",
        "FORCE_MAXHP",
        "FORCE_SLEEP",
        "FORCE_EXTRA",
-       "XXX1",
+       "ATTR_SEMIRAND",
        "FRIENDS",
        "ESCORT",
        "ESCORTS",
@@ -187,7 +195,7 @@ static cptr r_info_flags2[] =
        "WEIRD_MIND",
        "MULTIPLY",
        "REGENERATE",
-       "SHAPECHANGER",
+       "CHAR_MULTI",
        "ATTR_ANY",
        "POWERFUL",
        "ELDRITCH_HORROR",
@@ -201,12 +209,12 @@ static cptr r_info_flags2[] =
        "KILL_BODY",
        "TAKE_ITEM",
        "KILL_ITEM",
-       "BRAIN_1",
-       "BRAIN_2",
-       "BRAIN_3",
-       "BRAIN_4",
-       "BRAIN_5",
-       "BRAIN_6",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
        "HUMAN",
        "QUANTUM"
 };
@@ -232,18 +240,18 @@ static cptr r_info_flags3[] =
        "HURT_ROCK",
        "HURT_FIRE",
        "HURT_COLD",
-       "IM_ACID",
-       "IM_ELEC",
-       "IM_FIRE",
-       "IM_COLD",
-       "IM_POIS",
-       "RES_TELE",
-       "RES_NETH",
-       "RES_WATE",
-       "RES_PLAS",
-       "RES_NEXU",
-       "RES_DISE",
-       "RES_ALL",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
        "NO_FEAR",
        "NO_STUN",
        "NO_CONF",
@@ -388,11 +396,11 @@ static cptr r_info_flags7[] =
        "GUARDIAN",
        "CHAMELEON",
        "KILL_EXP",
-       "XXX7X15",
-       "XXX7X16",
-       "XXX7X17",
-       "XXX7X18",
-       "XXX7X19",
+       "TANUKI",
+       "HAS_DARK_1",
+       "SELF_DARK_1",
+       "HAS_DARK_2",
+       "SELF_DARK_2",
        "XXX7X20",
        "XXX7X21",
        "XXX7X22",
@@ -489,9 +497,49 @@ static cptr r_info_flags9[] =
 
 
 /*
+ * Monster race flags - Resistances
+ */
+static cptr r_info_flagsr[] =
+{
+       "IM_ACID",
+       "IM_ELEC",
+       "IM_FIRE",
+       "IM_COLD",
+       "IM_POIS",
+       "RES_LITE",
+       "RES_DARK",
+       "RES_NETH",
+       "RES_WATE",
+       "RES_PLAS",
+       "RES_SHAR",
+       "RES_SOUN",
+       "RES_CHAO",
+       "RES_NEXU",
+       "RES_DISE",
+       "RES_WALL",
+       "RES_INER",
+       "RES_TIME",
+       "RES_GRAV",
+       "RES_ALL",
+       "RES_TELE",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+};
+
+
+/*
  * Object flags
  */
-static cptr k_info_flags1[] =
+static cptr k_info_flags[] =
 {
        "STR",
        "INT",
@@ -524,14 +572,8 @@ static cptr k_info_flags1[] =
        "BRAND_ACID",
        "BRAND_ELEC",
        "BRAND_FIRE",
-       "BRAND_COLD"
-};
+       "BRAND_COLD",
 
-/*
- * Object flags
- */
-static cptr k_info_flags2[] =
-{
        "SUST_STR",
        "SUST_INT",
        "SUST_WIS",
@@ -539,7 +581,7 @@ static cptr k_info_flags2[] =
        "SUST_CON",
        "SUST_CHR",
        "RIDING",
-       "XXX2",
+       "EASY_SPELL",
        "IM_ACID",
        "IM_ELEC",
        "IM_FIRE",
@@ -563,14 +605,8 @@ static cptr k_info_flags2[] =
        "RES_NETHER",
        "RES_NEXUS",
        "RES_CHAOS",
-       "RES_DISEN"
-};
+       "RES_DISEN",
 
-/*
- * Object flags
- */
-static cptr k_info_flags3[] =
-{
        "SH_FIRE",
        "SH_ELEC",
        "SLAY_HUMAN",
@@ -600,9 +636,31 @@ static cptr k_info_flags3[] =
        "TELEPORT",
        "AGGRAVATE",
        "BLESSED",
-       "XXX1",
-       "XXX2",
        "XXX3",
+       "XXX4",
+       "XXX5",
+
+       "KILL_ANIMAL",
+       "KILL_EVIL",
+       "KILL_UNDEAD",
+       "KILL_DEMON",
+       "KILL_ORC",
+       "KILL_TROLL",
+       "KILL_GIANT",
+       "KILL_HUMAN",
+       "ESP_ANIMAL",
+       "ESP_UNDEAD",
+       "ESP_DEMON",
+       "ESP_ORC",
+       "ESP_TROLL",
+       "ESP_GIANT",
+       "ESP_DRAGON",
+       "ESP_HUMAN",
+       "ESP_EVIL",
+       "ESP_GOOD",
+       "ESP_NONLIVING",
+       "ESP_UNIQUE",
+       "FULL_NAME",
 };
 
 
@@ -648,38 +706,38 @@ static cptr k_info_gen_flags[] =
  */
 static cptr d_info_flags1[] =
 {
-        "WINNER",
-        "MAZE",
-        "SMALLEST",
-        "BEGINNER",
-        "BIG",
-        "NO_DOORS",
-        "WATER_RIVER",
-        "LAVA_RIVER",
-        "WATER_RIVERS",
-        "LAVA_RIVERS",
-        "CAVE",
-        "CAVERN",
-        "NO_UP",
-        "HOT",
-        "COLD",
-        "NO_DOWN",
-        "FORGET",
-        "LAKE_WATER",
-        "LAKE_LAVA",
-        "LAKE_RUBBLE",
-        "LAKE_TREE",
-        "NO_VAULT",
-        "ARENA",
-        "DESTROY",
-        "XXX1",
-        "NO_CAVE",
-        "NO_MAGIC",
-        "NO_MELEE",
-        "CHAMELEON",
-        "DARKNESS",
-        "XXX1",
-        "XXX1"
+       "WINNER",
+       "MAZE",
+       "SMALLEST",
+       "BEGINNER",
+       "BIG",
+       "NO_DOORS",
+       "WATER_RIVER",
+       "LAVA_RIVER",
+       "XXX",
+       "XXX",
+       "CAVE",
+       "CAVERN",
+       "XXX",
+       "XXX",
+       "XXX",
+       "XXX",
+       "FORGET",
+       "LAKE_WATER",
+       "LAKE_LAVA",
+       "LAKE_RUBBLE",
+       "LAKE_TREE",
+       "NO_VAULT",
+       "ARENA",
+       "DESTROY",
+       "XXX",
+       "NO_CAVE",
+       "NO_MAGIC",
+       "NO_MELEE",
+       "CHAMELEON",
+       "DARKNESS",
+       "XXX",
+       "XXX"
 };
 
 
@@ -747,7 +805,7 @@ static bool add_name(u32b *offset, header *head, cptr buf)
  * Convert a "color letter" into an "actual" color
  * The colors are: dwsorgbuDWvyRGBU, as shown below
  */
-static int color_char_to_attr(char c)
+byte color_char_to_attr(char c)
 {
        switch (c)
        {
@@ -770,7 +828,7 @@ static int color_char_to_attr(char c)
                case 'U': return (TERM_L_UMBER);
        }
 
-       return (-1);
+       return (255);
 }
 
 
@@ -782,7 +840,7 @@ static int color_char_to_attr(char c)
  * Initialize an "*_info" array, by parsing an ascii "template" file
  */
 errr init_info_txt(FILE *fp, char *buf, header *head,
-                   parse_info_txt_func parse_info_txt_line)
+                  parse_info_txt_func parse_info_txt_line)
 {
        errr err;
 
@@ -817,6 +875,17 @@ errr init_info_txt(FILE *fp, char *buf, header *head,
                        continue;
                }
 
+               /* Mega Hack -- Calculate Check Sum */
+               if (buf[0] != 'N' && buf[0] != 'D')
+               {
+                       int i;
+                       for (i = 0; buf[i]; i++)
+                       {
+                               head->v_extra += (byte)buf[i];
+                               head->v_extra ^= (1 << (i % 8));
+                       }
+               }
+
                /* Parse the line */
                if ((err = (*parse_info_txt_line)(buf, head)) != 0)
                        return (err);
@@ -952,13 +1021,18 @@ errr parse_s_info(char *buf, header *head)
        else if (buf[0] == 'W')
        {
                int tval, sval, start, max;
-               const s16b exp_conv_table[] = { 0, 4000, 6000, 7000, 8000 };
+               const s16b exp_conv_table[] =
+               {
+                       WEAPON_EXP_UNSKILLED, WEAPON_EXP_BEGINNER, WEAPON_EXP_SKILLED,
+                       WEAPON_EXP_EXPERT, WEAPON_EXP_MASTER
+               };
 
                /* Scan for the values */
                if (4 != sscanf(buf+2, "%d:%d:%d:%d",
                                &tval, &sval, &start, &max)) return (1);
 
-               if (start < 0 || start > 4 || max < 0 || max > 4) return (8);
+               if (start < EXP_LEVEL_UNSKILLED || start > EXP_LEVEL_MASTER
+                       || max < EXP_LEVEL_UNSKILLED || max > EXP_LEVEL_MASTER) return (8);
 
                /* Save the values */
                s_ptr->w_start[tval][sval] = exp_conv_table[start];
@@ -974,7 +1048,8 @@ errr parse_s_info(char *buf, header *head)
                if (3 != sscanf(buf+2, "%d:%d:%d",
                                &num, &start, &max)) return (1);
 
-               if (start < 0 || start > 8000 || max < 0 || max > 8000) return (8);
+               if (start < WEAPON_EXP_UNSKILLED || start > WEAPON_EXP_MASTER
+                       || max < WEAPON_EXP_UNSKILLED || max > WEAPON_EXP_MASTER) return (8);
 
                /* Save the values */
                s_ptr->s_start[num] = start;
@@ -1074,7 +1149,7 @@ errr parse_m_info(char *buf, header *head)
 
                /* Scan for the values */
                if (4 != sscanf(s, "%x:%d:%d:%d",
-                               &xtra, &type, &first, &weight)) return (1);
+                               (uint *)&xtra, &type, &first, &weight)) return (1);
 
                m_ptr->spell_xtra = xtra;
                m_ptr->spell_type = type;
@@ -1192,20 +1267,6 @@ errr parse_f_info(char *buf, header *head)
        }
 #endif
 
-#if 0
-
-       /* Process 'D' for "Description" */
-       else if (buf[0] == 'D')
-       {
-               /* Acquire the text */
-               s = buf+2;
-
-               /* Store the text */
-               if (!add_text(&f_ptr->text, head, s)) return (7);
-       }
-
-#endif
-
 
        /* Process 'M' for "Mimic" (one line only) */
        else if (buf[0] == 'M')
@@ -1225,7 +1286,7 @@ errr parse_f_info(char *buf, header *head)
        /* Process 'G' for "Graphics" (one line only) */
        else if (buf[0] == 'G')
        {
-               int tmp;
+               byte tmp;
 
                /* Paranoia */
                if (!buf[2]) return (1);
@@ -1236,7 +1297,7 @@ errr parse_f_info(char *buf, header *head)
                tmp = color_char_to_attr(buf[4]);
 
                /* Paranoia */
-               if (tmp < 0) return (1);
+               if (tmp > 127) return (1);
 
                /* Save the values */
                f_ptr->d_attr = tmp;
@@ -1259,32 +1320,12 @@ static errr grab_one_kind_flag(object_kind *k_ptr, cptr what)
 {
        int i;
 
-       /* Check flags1 */
-       for (i = 0; i < 32; i++)
+       /* Check flags */
+       for (i = 0; i < TR_FLAG_MAX; i++)
        {
-               if (streq(what, k_info_flags1[i]))
+               if (streq(what, k_info_flags[i]))
                {
-                       k_ptr->flags1 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags2 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags2[i]))
-               {
-                       k_ptr->flags2 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags3 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags3[i]))
-               {
-                       k_ptr->flags3 |= (1L << i);
+                       add_flag(k_ptr->flags, i);
                        return (0);
                }
        }
@@ -1383,26 +1424,31 @@ errr parse_k_info(char *buf, header *head)
                if (!add_name(&k_ptr->name, head, s)) return (7);
        }
 #endif
-#if 0
 
        /* Process 'D' for "Description" */
        else if (buf[0] == 'D')
        {
+#ifdef JP
+               if (buf[2] == '$')
+                       return (0);
                /* Acquire the text */
                s = buf+2;
+#else
+               if (buf[2] != '$')
+                       return (0);
+               /* Acquire the text */
+               s = buf+3;
+#endif
 
                /* Store the text */
                if (!add_text(&k_ptr->text, head, s)) return (7);
        }
 
-#endif
-
-
        /* Process 'G' for "Graphics" (one line only) */
        else if (buf[0] == 'G')
        {
                char sym;
-               int tmp;
+               byte tmp;
 
                /* Paranoia */
                if (!buf[2]) return (1);
@@ -1416,7 +1462,7 @@ errr parse_k_info(char *buf, header *head)
                tmp = color_char_to_attr(buf[4]);
 
                /* Paranoia */
-               if (tmp < 0) return (1);
+               if (tmp > 127) return (1);
 
                /* Save the values */
                k_ptr->d_attr = tmp;
@@ -1542,32 +1588,12 @@ static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what)
 {
        int i;
 
-       /* Check flags1 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags1[i]))
-               {
-                       a_ptr->flags1 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags2 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags2[i]))
-               {
-                       a_ptr->flags2 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags3 */
-       for (i = 0; i < 32; i++)
+       /* Check flags */
+       for (i = 0; i < TR_FLAG_MAX; i++)
        {
-               if (streq(what, k_info_flags3[i]))
+               if (streq(what, k_info_flags[i]))
                {
-                       a_ptr->flags3 |= (1L << i);
+                       add_flag(a_ptr->flags, i);
                        return (0);
                }
        }
@@ -1641,10 +1667,10 @@ errr parse_a_info(char *buf, header *head)
                a_ptr = &a_info[i];
 
                /* Ignore everything */
-               a_ptr->flags3 |= (TR3_IGNORE_ACID);
-               a_ptr->flags3 |= (TR3_IGNORE_ELEC);
-               a_ptr->flags3 |= (TR3_IGNORE_FIRE);
-               a_ptr->flags3 |= (TR3_IGNORE_COLD);
+               add_flag(a_ptr->flags, TR_IGNORE_ACID);
+               add_flag(a_ptr->flags, TR_IGNORE_ELEC);
+               add_flag(a_ptr->flags, TR_IGNORE_FIRE);
+               add_flag(a_ptr->flags, TR_IGNORE_COLD);
 #ifdef JP
                /* Store the name */
                if (!add_name(&a_ptr->name, head, s)) return (7);
@@ -1783,32 +1809,12 @@ static bool grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what)
 {
        int i;
 
-       /* Check flags1 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags1[i]))
-               {
-                       e_ptr->flags1 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags2 */
-       for (i = 0; i < 32; i++)
-       {
-               if (streq(what, k_info_flags2[i]))
-               {
-                       e_ptr->flags2 |= (1L << i);
-                       return (0);
-               }
-       }
-
-       /* Check flags3 */
-       for (i = 0; i < 32; i++)
+       /* Check flags */
+       for (i = 0; i < TR_FLAG_MAX; i++)
        {
-               if (streq(what, k_info_flags3[i]))
+               if (streq(what, k_info_flags[i]))
                {
-                       e_ptr->flags3 |= (1L << i);
+                       add_flag(e_ptr->flags, i);
                        return (0);
                }
        }
@@ -2073,6 +2079,16 @@ static errr grab_one_basic_flag(monster_race *r_ptr, cptr what)
                }
        }
 
+       /* Scan flagsr (resistance) */
+       for (i = 0; i < 32; i++)
+       {
+               if (streq(what, r_info_flagsr[i]))
+               {
+                       r_ptr->flagsr |= (1L << i);
+                       return (0);
+               }
+       }
+
        /* Oops */
 #ifdef JP
        msg_format("̤ÃΤΥâ¥ó¥¹¥¿¡¼¡¦¥Õ¥é¥° '%s'¡£", what);
@@ -2234,7 +2250,7 @@ errr parse_r_info(char *buf, header *head)
        else if (buf[0] == 'G')
        {
                char sym;
-               int tmp;
+               byte tmp;
 
                /* Paranoia */
                if (!buf[2]) return (1);
@@ -2248,7 +2264,7 @@ errr parse_r_info(char *buf, header *head)
                tmp = color_char_to_attr(buf[4]);
 
                /* Paranoia */
-               if (tmp < 0) return (1);
+               if (tmp > 127) return (1);
 
                /* Save the values */
                r_ptr->d_char = sym;
@@ -2396,7 +2412,7 @@ errr parse_r_info(char *buf, header *head)
                        if (1 == sscanf(s, "1_IN_%d", &i))
                        {
                                /* Extract a "frequency" */
-                               r_ptr->freq_spell = r_ptr->freq_inate = 100 / i;
+                               r_ptr->freq_spell = 100 / i;
 
                                        /* Start at next entry */
                                s = t;
@@ -2432,18 +2448,18 @@ static errr grab_one_dungeon_flag(dungeon_info_type *d_ptr, cptr what)
        /* Scan flags1 */
        for (i = 0; i < 32; i++)
        {
-                if (streq(what, d_info_flags1[i]))
+               if (streq(what, d_info_flags1[i]))
                {
-                        d_ptr->flags1 |= (1L << i);
+                       d_ptr->flags1 |= (1L << i);
                        return (0);
                }
        }
 
        /* Oops */
 #ifdef JP
-        msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
+       msg_format("̤ÃΤΥÀ¥ó¥¸¥ç¥ó¡¦¥Õ¥é¥° '%s'¡£", what);
 #else
-        msg_format("Unknown dungeon type flag '%s'.", what);
+       msg_format("Unknown dungeon type flag '%s'.", what);
 #endif
 
        /* Failure */
@@ -2460,9 +2476,9 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        /* Scan flags1 */
        for (i = 0; i < 32; i++)
        {
-                if (streq(what, r_info_flags1[i]))
+               if (streq(what, r_info_flags1[i]))
                {
-                        d_ptr->mflags1 |= (1L << i);
+                       d_ptr->mflags1 |= (1L << i);
                        return (0);
                }
        }
@@ -2472,7 +2488,7 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags2[i]))
                {
-                        d_ptr->mflags2 |= (1L << i);
+                       d_ptr->mflags2 |= (1L << i);
                        return (0);
                }
        }
@@ -2482,7 +2498,7 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags3[i]))
                {
-                        d_ptr->mflags3 |= (1L << i);
+                       d_ptr->mflags3 |= (1L << i);
                        return (0);
                }
        }
@@ -2490,9 +2506,9 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        /* Scan flags7 */
        for (i = 0; i < 32; i++)
        {
-                if (streq(what, r_info_flags7[i]))
+               if (streq(what, r_info_flags7[i]))
                {
-                        d_ptr->mflags7 |= (1L << i);
+                       d_ptr->mflags7 |= (1L << i);
                        return (0);
                }
        }
@@ -2502,7 +2518,7 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags8[i]))
                {
-                        d_ptr->mflags8 |= (1L << i);
+                       d_ptr->mflags8 |= (1L << i);
                        return (0);
                }
        }
@@ -2512,7 +2528,17 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags9[i]))
                {
-                        d_ptr->mflags9 |= (1L << i);
+                       d_ptr->mflags9 |= (1L << i);
+                       return (0);
+               }
+       }
+
+       /* Scan flagsr (resistance) */
+       for (i = 0; i < 32; i++)
+       {
+               if (streq(what, r_info_flagsr[i]))
+               {
+                       d_ptr->mflagsr |= (1L << i);
                        return (0);
                }
        }
@@ -2540,7 +2566,7 @@ static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags4[i]))
                {
-                        d_ptr->mflags4 |= (1L << i);
+                       d_ptr->mflags4 |= (1L << i);
                        return (0);
                }
        }
@@ -2550,7 +2576,7 @@ static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags5[i]))
                {
-                        d_ptr->mflags5 |= (1L << i);
+                       d_ptr->mflags5 |= (1L << i);
                        return (0);
                }
        }
@@ -2560,7 +2586,7 @@ static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what)
        {
                if (streq(what, r_info_flags6[i]))
                {
-                        d_ptr->mflags6 |= (1L << i);
+                       d_ptr->mflags6 |= (1L << i);
                        return (0);
                }
        }
@@ -2704,7 +2730,7 @@ errr parse_d_info(char *buf, header *head)
 
                /* Scan for the values */
                if (7 != sscanf(buf+2, "%d:%d:%d:%d:%d:%d:%d",
-                                &f1, &p1, &f2, &p2, &f3, &p3, &tunnel)) return (1);
+                               &f1, &p1, &f2, &p2, &f3, &p3, &tunnel)) return (1);
 
                /* Save the values */
                d_ptr->floor1 = f1;
@@ -2747,17 +2773,17 @@ errr parse_d_info(char *buf, header *head)
                /* Parse every entry */
                for (s = buf + 2; *s; )
                {
-                               /* Find the end of this entry */
+                       /* Find the end of this entry */
                        for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
 
-                               /* Nuke and skip any dividers */
+                       /* Nuke and skip any dividers */
                        if (*t)
                        {
                                *t++ = '\0';
                                while (*t == ' ' || *t == '|') t++;
                        }
 
-                                /* XXX XXX XXX Hack -- Read Final Artifact */
+                       /* XXX XXX XXX Hack -- Read Final Artifact */
                        if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif))
                        {
                                /* Extract a "Final Artifact" */
@@ -2770,7 +2796,7 @@ errr parse_d_info(char *buf, header *head)
                                continue;
                        }
 
-                                /* XXX XXX XXX Hack -- Read Final Object */
+                       /* XXX XXX XXX Hack -- Read Final Object */
                        if (1 == sscanf(s, "FINAL_OBJECT_%d", &artif))
                        {
                                /* Extract a "Final Artifact" */
@@ -2783,7 +2809,7 @@ errr parse_d_info(char *buf, header *head)
                                continue;
                        }
 
-                                /* XXX XXX XXX Hack -- Read Artifact Guardian */
+                       /* XXX XXX XXX Hack -- Read Artifact Guardian */
                        if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst))
                        {
                                /* Extract a "Artifact Guardian" */
@@ -2796,7 +2822,7 @@ errr parse_d_info(char *buf, header *head)
                                continue;
                        }
 
-                                /* XXX XXX XXX Hack -- Read Special Percentage */
+                       /* XXX XXX XXX Hack -- Read Special Percentage */
                        if (1 == sscanf(s, "MONSTER_DIV_%d", &monst))
                        {
                                /* Extract a "Special %" */
@@ -2809,10 +2835,10 @@ errr parse_d_info(char *buf, header *head)
                                continue;
                        }
 
-                               /* Parse this entry */
+                       /* Parse this entry */
                        if (0 != grab_one_dungeon_flag(d_ptr, s)) return (5);
 
-                               /* Start the next entry */
+                       /* Start the next entry */
                        s = t;
                }
        }
@@ -2820,29 +2846,27 @@ errr parse_d_info(char *buf, header *head)
        /* Process 'M' for "Basic Flags" (multiple lines) */
        else if (buf[0] == 'M')
        {
-               byte r_char_number = 0, r_char;
-
                /* Parse every entry */
                for (s = buf + 2; *s; )
                {
-                               /* Find the end of this entry */
+                       /* Find the end of this entry */
                        for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */;
 
-                               /* Nuke and skip any dividers */
+                       /* Nuke and skip any dividers */
                        if (*t)
                        {
                                *t++ = '\0';
                                while (*t == ' ' || *t == '|') t++;
                        }
 
-                                /* XXX XXX XXX Hack -- Read monster symbols */
-                       if (1 == sscanf(s, "R_CHAR_%c", &r_char))
+                       /* Hack -- Read monster symbols */
+                       if (!strncmp(s, "R_CHAR_", 7))
                        {
-                               /* Limited to 5 races */
-                               if(r_char_number >= 5) continue;
+                               /* Skip "R_CHAR_" */
+                               s += 7;
 
-                               /* Extract a "frequency" */
-                               d_ptr->r_char[r_char_number++] = r_char;
+                               /* Read a string */
+                               strncpy(d_ptr->r_char, s, sizeof(d_ptr->r_char));
 
                                /* Start at next entry */
                                s = t;
@@ -2851,10 +2875,10 @@ errr parse_d_info(char *buf, header *head)
                                continue;
                        }
 
-                               /* Parse this entry */
+                       /* Parse this entry */
                        if (0 != grab_one_basic_monster_flag(d_ptr, s)) return (5);
 
-                               /* Start the next entry */
+                       /* Start the next entry */
                        s = t;
                }
        }
@@ -3318,7 +3342,7 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                        {
                                monster_level = base_level + monster_index;
 
-                               place_monster(*y, *x, TRUE, TRUE);
+                               place_monster(*y, *x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
 
                                monster_level = base_level;
                        }
@@ -3352,7 +3376,7 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                                }
 
                                /* Place it */
-                               place_monster_aux(*y, *x, monster_index, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE);
+                               place_monster_aux(0, *y, *x, monster_index, (PM_ALLOW_SLEEP | PM_NO_KAGE));
                                if (clone)
                                {
                                        /* clone */
@@ -3375,7 +3399,7 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                                 */
                                if (randint0(100) < 75)
                                {
-                                       place_object(*y, *x, FALSE, FALSE);
+                                       place_object(*y, *x, 0L);
                                }
                                else
                                {
@@ -3390,11 +3414,11 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
 
                                /* Create an out of deep object */
                                if (randint0(100) < 75)
-                                       place_object(*y, *x, FALSE, FALSE);
+                                       place_object(*y, *x, 0L);
                                else if (randint0(100) < 80)
-                                       place_object(*y, *x, TRUE, FALSE);
+                                       place_object(*y, *x, AM_GOOD);
                                else
-                                       place_object(*y, *x, TRUE, TRUE);
+                                       place_object(*y, *x, AM_GOOD | AM_GREAT);
 
                                object_level = base_level;
                        }
@@ -3403,6 +3427,12 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                        {
                                place_trap(*y, *x);
                        }
+                       /* Hidden trap (or door) */
+                       else if (letter[idx].trap)
+                       {
+                               c_ptr->mimic = f_info[c_ptr->feat].mimic;
+                               c_ptr->feat = letter[idx].trap;
+                       }
                        else if (object_index)
                        {
                                /* Get local object */
@@ -3419,7 +3449,7 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                                }
 
                                /* Apply magic (no messages, no artifacts) */
-                               apply_magic(o_ptr, base_level, FALSE, TRUE, FALSE, FALSE);
+                               apply_magic(o_ptr, base_level, AM_NO_FIXED_ART | AM_GOOD);
 
                                (void)drop_near(o_ptr, -1, *y, *x);
                        }
@@ -3429,7 +3459,7 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                        {
                                if (a_info[artifact_index].cur_num)
                                {
-                                       int k_idx = 198;
+                                       int k_idx = lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
                                        object_type forge;
                                        object_type *q_ptr = &forge;
 
@@ -3646,10 +3676,10 @@ static errr process_dungeon_file_aux(char *buf, int ymin, int xmin, int ymax, in
                                max_e_idx = atoi(zz[1]);
                        }
 
-                        /* Maximum d_idx */
-                        else if (zz[0][0] == 'D')
+                       /* Maximum d_idx */
+                       else if (zz[0][0] == 'D')
                        {
-                                max_d_idx = atoi(zz[1]); 
+                               max_d_idx = atoi(zz[1]); 
                        }
 
                        /* Maximum o_idx */
@@ -3867,7 +3897,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "RACE"))
                        {
 #ifdef JP
-                                v = rp_ptr->E_title;
+                               v = rp_ptr->E_title;
 #else
                                v = rp_ptr->title;
 #endif
@@ -3877,7 +3907,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "CLASS"))
                        {
 #ifdef JP
-                                v = cp_ptr->E_title;
+                               v = cp_ptr->E_title;
 #else
                                v = cp_ptr->title;
 #endif
@@ -3889,7 +3919,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
 #ifdef JP
                                v = E_realm_names[p_ptr->realm1];
 #else
-                                v = realm_names[p_ptr->realm1];
+                               v = realm_names[p_ptr->realm1];
 #endif
                        }
 
@@ -3897,7 +3927,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp)
                        else if (streq(b+1, "REALM2"))
                        {
 #ifdef JP
-                                v = E_realm_names[p_ptr->realm2];
+                               v = E_realm_names[p_ptr->realm2];
 #else
                                v = realm_names[p_ptr->realm2];
 #endif
@@ -4006,7 +4036,7 @@ errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
 
 
        /* Build the filename */
-       path_build(buf, 1024, ANGBAND_DIR_EDIT, name);
+       path_build(buf, sizeof(buf), ANGBAND_DIR_EDIT, name);
 
        /* Open the file */
        fp = my_fopen(buf, "r");
@@ -4016,7 +4046,7 @@ errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
 
 
        /* Process the file */
-       while (0 == my_fgets(fp, buf, 1024))
+       while (0 == my_fgets(fp, buf, sizeof(buf)))
        {
                /* Count lines */
                num++;
@@ -4055,18 +4085,6 @@ errr process_dungeon_file(cptr name, int ymin, int xmin, int ymax, int xmax)
                /* Apply conditionals */
                if (bypass) continue;
 
-
-               /* Process "%:<file>" */
-               if (buf[0] == '%')
-               {
-                       /* Process that file if allowed */
-                       (void)process_dungeon_file(buf + 2, ymin, xmin, ymax, xmax);
-
-                       /* Continue */
-                       continue;
-               }
-
-
                /* Process the line */
                err = process_dungeon_file_aux(buf, ymin, xmin, ymax, xmax, &y, &x);
 
@@ -4109,10 +4127,10 @@ void write_r_info_txt(void)
        int i, j, z, fc, bc;
        int dlen;
 
-       cptr flags[288];
+       cptr flags[32 * 10];
 
-       u32b f_ptr[9];
-       cptr *n_ptr[9];
+       u32b f_ptr[10];
+       cptr *n_ptr[10];
 
        monster_race *r_ptr;
 
@@ -4178,6 +4196,7 @@ void write_r_info_txt(void)
                f_ptr[6] = r_ptr->flags7; n_ptr[6] = r_info_flags7;
                f_ptr[7] = r_ptr->flags8; n_ptr[7] = r_info_flags8;
                f_ptr[8] = r_ptr->flags9; n_ptr[8] = r_info_flags9;
+               f_ptr[9] = r_ptr->flagsr; n_ptr[9] = r_info_flagsr;
 
                /* Write New/Number/Name */
                fprintf(fff, "N:%d:%s\n", z + 1, r_name + r_ptr->name);
@@ -4207,14 +4226,14 @@ void write_r_info_txt(void)
                }
 
                /* Extract the flags */
-               for (fc = 0, j = 0; j < 96; j++)
+               for (fc = 0, j = 0; j < 32 * 3; j++)
                {
                        /* Check this flag */
                        if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];
                }
 
                /* Extract the extra flags */
-               for (j = 192; j < 288; j++)
+               for (j = 32 * 6; j < 32 * 10; j++)
                {
                        /* Check this flag */
                        if (f_ptr[j / 32] & (1L << (j % 32))) flags[fc++] = n_ptr[j / 32][j % 32];