OSDN Git Service

c_ptr->mimicを活用する一連の改造:
[hengband/hengband.git] / src / cmd2.c
index 334bf90..d67a4f2 100644 (file)
@@ -44,25 +44,9 @@ void do_cmd_go_up(void)
 #endif
 
 
-               leaving_quest = p_ptr->inside_quest;
-               p_ptr->inside_quest = c_ptr->special;
+               leave_quest_check();
 
-               /* Leaving an 'only once' quest marks it as failed */
-               if (leaving_quest &&
-                       ((quest[leaving_quest].flags & QUEST_FLAG_ONCE) || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
-                       (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
-               {
-                       quest[leaving_quest].status = QUEST_STATUS_FAILED;
-                       quest[leaving_quest].complev = (byte)p_ptr->lev;
-                       if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
-                       {
-                               r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
-                               if (record_rand_quest)
-                                       do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
-                       }
-                       else if (record_fix_quest)
-                               do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
-               }
+               p_ptr->inside_quest = c_ptr->special;
 
                /* Activate the quest */
                if (!quest[p_ptr->inside_quest].status)
@@ -118,25 +102,9 @@ if (get_check("
 
                        if (p_ptr->inside_quest)
                        {
-                               leaving_quest = p_ptr->inside_quest;
-                               if (quest[leaving_quest].type != QUEST_TYPE_RANDOM) dun_level = 1;
+                               if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM) dun_level = 1;
 
-                               /* Leaving an 'only once' quest marks it as failed */
-                               if (leaving_quest &&
-                                       ((quest[leaving_quest].flags & QUEST_FLAG_ONCE) || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
-                                       (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
-                               {
-                                       quest[leaving_quest].status = QUEST_STATUS_FAILED;
-                                       quest[leaving_quest].complev = (byte)p_ptr->lev;
-                                       if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
-                                       {
-                                               r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
-                                               if (record_rand_quest)
-                                                       do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
-                                       }
-                                       else if (record_fix_quest)
-                                               do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
-                               }
+                               leave_quest_check();
 
                                p_ptr->inside_quest = c_ptr->special;
                        }
@@ -179,10 +147,15 @@ if (get_check("
 #ifdef JP
                        if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
                                msg_print("¤Ê¤ó¤À¤³¤Î³¬Ãʤϡª");
-                       else
+                       else if (0 == dun_level)
+                               msg_print("ÃϾå¤ËÌá¤Ã¤¿¡£");
+                        else
                                msg_print("³¬Ãʤò¾å¤Ã¤Æ¿·¤¿¤Ê¤ë̵ܤؤÈ­¤òƧ¤ßÆþ¤ì¤¿¡£");
 #else
-                       msg_print("You enter a maze of up staircases.");
+                        if (0 == dun_level)
+                               msg_print("You go back to the surface.");
+                        else
+                                msg_print("You enter a maze of up staircases.");
 #endif
 
 
@@ -250,24 +223,7 @@ void do_cmd_go_down(void)
 #endif
 
 
-               leaving_quest = p_ptr->inside_quest;
-
-               /* Leaving an 'only once' quest marks it as failed */
-               if (leaving_quest &&
-                       ((quest[leaving_quest].flags & QUEST_FLAG_ONCE) || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
-                       (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
-               {
-                       quest[leaving_quest].status = QUEST_STATUS_FAILED;
-                       quest[leaving_quest].complev = (byte)p_ptr->lev;
-                       if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
-                       {
-                               r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
-                               if (record_rand_quest)
-                                       do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
-                       }
-                       else if (record_fix_quest)
-                               do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
-               }
+               leave_quest_check();
 
                p_ptr->inside_quest = c_ptr->special;
 
@@ -360,7 +316,7 @@ if (get_check("
                        /* Go down */
                        if (c_ptr->feat == FEAT_MORE_MORE) down_num += 2;
                        else down_num += 1;
-                       if (!quest_number(dun_level+down_num) && (dun_level < d_info[dungeon_type].maxdepth - 1 - down_num) && one_in_(13) && !fall_trap && dun_level)
+                       if (!quest_number(dun_level+down_num) && (dun_level < d_info[dungeon_type].maxdepth - 1 - down_num) && one_in_(13) && !fall_trap && dun_level && !ironman_downward)
                        {
                                down_num++;
 #ifdef JP
@@ -559,7 +515,7 @@ static void chest_death(bool scatter, int y, int x, s16b o_idx)
                object_wipe(q_ptr);
 
                /* Small chests often drop gold */
-               if (small && (rand_int(100) < 25))
+               if (small && (randint0(100) < 25))
                {
                        /* Make some gold */
                        if (!make_gold(q_ptr)) continue;
@@ -579,8 +535,8 @@ static void chest_death(bool scatter, int y, int x, s16b o_idx)
                        for (i = 0; i < 200; i++)
                        {
                                /* Pick a totally random spot. */
-                               y = rand_int(MAX_HGT);
-                               x = rand_int(MAX_WID);
+                               y = randint0(MAX_HGT);
+                               x = randint0(MAX_WID);
 
                                /* Must be an empty floor. */
                                if (!cave_empty_bold(y, x)) continue;
@@ -669,7 +625,7 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                if (!(p_ptr->resist_pois || p_ptr->oppose_pois))
                {
-                       (void)set_poisoned(p_ptr->poisoned + 10 + randint(20));
+                       (void)set_poisoned(p_ptr->poisoned + 10 + randint1(20));
                }
        }
 
@@ -685,14 +641,14 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                if (!p_ptr->free_act)
                {
-                       (void)set_paralyzed(p_ptr->paralyzed + 10 + randint(20));
+                       (void)set_paralyzed(p_ptr->paralyzed + 10 + randint1(20));
                }
        }
 
        /* Summon monsters */
        if (trap & (CHEST_SUMMON))
        {
-               int num = 2 + randint(3);
+               int num = 2 + randint1(3);
 #ifdef JP
                msg_print("ÆÍÇ¡¿á¤­½Ð¤·¤¿±ì¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡ª");
 #else
@@ -702,10 +658,10 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                for (i = 0; i < num; i++)
                {
-                       if (randint(100)<dun_level)
+                       if (randint1(100)<dun_level)
                                activate_hi_summon(py, px, FALSE);
                        else
-                               (void)summon_specific(0, y, x, mon_level, 0, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -717,9 +673,9 @@ static void chest_trap(int y, int x, s16b o_idx)
 #else
                msg_print("Elemental beings appear to protect their treasures!");
 #endif
-               for (i = 0; i < randint(3) + 5; i++)
+               for (i = 0; i < randint1(3) + 5; i++)
                {
-                       (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, TRUE, FALSE, FALSE, TRUE, TRUE);
+                       (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -732,12 +688,12 @@ static void chest_trap(int y, int x, s16b o_idx)
                msg_print("A storm of birds swirls around you!");
 #endif
 
-               for (i = 0; i < randint(3) + 3; i++)
+               for (i = 0; i < randint1(3) + 3; i++)
                        (void)fire_meteor(-1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
 
-               for (i = 0; i < randint(5) + o_ptr->pval / 5; i++)
+               for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
                {
-                       (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, TRUE, FALSE, FALSE, TRUE, TRUE);
+                       (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -745,7 +701,7 @@ static void chest_trap(int y, int x, s16b o_idx)
        if (trap & (CHEST_H_SUMMON))
        {
                /* Summon demons. */
-               if (rand_int(4) == 0)
+               if (one_in_(4))
                {
 #ifdef JP
                        msg_print("±ê¤Èⲫ¤Î±À¤ÎÃæ¤Ë°­Ë⤬»Ñ¤ò¸½¤·¤¿¡ª");
@@ -753,15 +709,15 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Demons materialize in clouds of fire and brimstone!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
                                (void)fire_meteor(-1, GF_FIRE, y, x, 10, 5);
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
                /* Summon dragons. */
-               else if (rand_int(3) == 0)
+               else if (one_in_(3))
                {
 #ifdef JP
                        msg_print("°Å°Ç¤Ë¥É¥é¥´¥ó¤Î±Æ¤¬¤Ü¤ó¤ä¤ê¤È¸½¤ì¤¿¡ª");
@@ -769,14 +725,14 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Draconic forms loom out of the darkness!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
                /* Summon hybrids. */
-               else if (rand_int(2) == 0)
+               else if (one_in_(2))
                {
 #ifdef JP
                        msg_print("´ñ̯¤Ê»Ñ¤Î²øʪ¤¬½±¤Ã¤ÆÍ褿¡ª");
@@ -784,9 +740,9 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Creatures strange and twisted assault you!");
 #endif
 
-                       for (i = 0; i < randint(5) + 3; i++)
+                       for (i = 0; i < randint1(5) + 3; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
@@ -799,9 +755,9 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Vortices coalesce and wreak destruction!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
        }
@@ -810,7 +766,7 @@ static void chest_trap(int y, int x, s16b o_idx)
        if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
        {
                /* Determine how many nasty tricks can be played. */
-               int nasty_tricks_count = 4 + rand_int(3);
+               int nasty_tricks_count = 4 + randint0(3);
 
                /* Message. */
 #ifdef JP
@@ -823,25 +779,25 @@ static void chest_trap(int y, int x, s16b o_idx)
                for (; nasty_tricks_count > 0; nasty_tricks_count--)
                {
                        /* ...but a high saving throw does help a little. */
-                       if (randint(100+o_ptr->pval*2) > p_ptr->skill_sav)
+                       if (randint1(100+o_ptr->pval*2) > p_ptr->skill_sav)
                        {
 #ifdef JP
-                               if (rand_int(6) == 0) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "ÇËÌǤΥȥé¥Ã¥×¤ÎÊõÈ¢", -1);
+                               if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "ÇËÌǤΥȥé¥Ã¥×¤ÎÊõÈ¢", -1);
 #else
-                               if (rand_int(6) == 0) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "a chest dispel-player trap", -1);
+                               if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "a chest dispel-player trap", -1);
 #endif
-                               else if (rand_int(5) == 0) (void)set_cut(p_ptr->cut + 200);
-                               else if (rand_int(4) == 0)
+                               else if (one_in_(5)) (void)set_cut(p_ptr->cut + 200);
+                               else if (one_in_(4))
                                {
                                        if (!p_ptr->free_act) 
                                                (void)set_paralyzed(p_ptr->paralyzed + 2 + 
-                                               rand_int(6));
+                                               randint0(6));
                                        else 
                                                (void)set_stun(p_ptr->stun + 10 + 
-                                               rand_int(100));
+                                               randint0(100));
                                }
-                               else if (rand_int(3) == 0) apply_disenchant(0);
-                               else if (rand_int(2) == 0)
+                               else if (one_in_(3)) apply_disenchant(0);
+                               else if (one_in_(2))
                                {
                                        (void)do_dec_stat(A_STR);
                                        (void)do_dec_stat(A_DEX);
@@ -855,6 +811,17 @@ static void chest_trap(int y, int x, s16b o_idx)
                }
        }
 
+       /* Aggravate monsters. */
+       if (trap & (CHEST_ALARM))
+       {
+#ifdef JP
+               msg_print("¤±¤¿¤¿¤Þ¤·¤¤²»¤¬ÌĤê¶Á¤¤¤¿¡ª");
+#else
+               msg_print("An alarm sounds!");
+#endif
+               aggravate_monsters(0);
+       }
+
        /* Explode */
        if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
        {
@@ -930,7 +897,7 @@ static bool do_cmd_open_chest(int y, int x, s16b o_idx)
                if (j < 2) j = 2;
 
                /* Success -- May still have traps */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
 #ifdef JP
                        msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
@@ -982,10 +949,6 @@ static bool is_open(int feat)
        return (feat == FEAT_OPEN);
 }
 
-static bool is_closed(int feat)
-{
-        return ((feat >= FEAT_DOOR_HEAD) && (feat <= FEAT_DOOR_TAIL));
-}
 
 /*
  * Return the number of features around (or under) the character.
@@ -1001,6 +964,9 @@ static int count_dt(int *y, int *x, bool (*test)(int feat), bool under)
        /* Check around (and under) the character */
        for (d = 0; d < 9; d++)
        {
+                cave_type *c_ptr;
+                byte feat;
+
                 /* if not searching under player continue */
                 if ((d == 8) && !under) continue;
 
@@ -1008,11 +974,17 @@ static int count_dt(int *y, int *x, bool (*test)(int feat), bool under)
                yy = py + ddy_ddd[d];
                xx = px + ddx_ddd[d];
 
+                /* Get the cave */
+                c_ptr = &cave[yy][xx];
+
                /* Must have knowledge */
-               if (!(cave[yy][xx].info & (CAVE_MARK))) continue;
+               if (!(c_ptr->info & (CAVE_MARK))) continue;
 
+                /* Feature code (applying "mimic" field) */
+                feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
+                
                /* Not looking for this feature */
-               if (!((*test)(cave[yy][xx].feat))) continue;
+               if (!((*test)(feat))) continue;
 
                /* OK */
                ++count;
@@ -1149,7 +1121,7 @@ static bool do_cmd_open_aux(int y, int x, int dir)
                if (j < 2) j = 2;
 
                /* Success */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
                        /* Message */
 #ifdef JP
@@ -1238,7 +1210,7 @@ void do_cmd_open(void)
                int num_doors, num_chests;
 
                /* Count closed doors (locked or jammed) */
-               num_doors = count_dt(&y, &x, is_closed, FALSE);
+               num_doors = count_dt(&y, &x, is_closed_door, FALSE);
 
                /* Count chests (locked) */
                num_chests = count_chests(&y, &x, FALSE);
@@ -1281,9 +1253,8 @@ void do_cmd_open(void)
                o_idx = chest_check(y, x);
 
                /* Nothing useful */
-               if (!((c_ptr->feat >= FEAT_DOOR_HEAD) &&
-                     (c_ptr->feat <= FEAT_DOOR_TAIL)) &&
-                   !o_idx)
+               if (!(is_closed_door(c_ptr->feat) && !c_ptr->mimic) &&
+                    !o_idx)
                {
                        /* Message */
 #ifdef JP
@@ -1540,8 +1511,6 @@ static bool twall(int y, int x, byte feat)
 
        /* Forget the wall */
        c_ptr->info &= ~(CAVE_MARK);
-       c_ptr->info &= ~(CAVE_MASK);
-       c_ptr->info |= (CAVE_FLOOR);
 
        /* Remove the feature */
        cave_set_feat(y, x, feat);
@@ -1568,6 +1537,7 @@ static bool twall(int y, int x, byte feat)
 static bool do_cmd_tunnel_aux(int y, int x, int dir)
 {
        cave_type *c_ptr;
+       byte feat;
 
        bool more = FALSE;
 
@@ -1580,12 +1550,15 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        /* Get grid */
        c_ptr = &cave[y][x];
 
+        /* Feature code (applying "mimic" field) */
+        feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
+
        /* Sound */
        sound(SOUND_DIG);
 
        /* Titanium */
-       if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
-           (c_ptr->feat <= FEAT_PERM_SOLID))
+       if ((feat >= FEAT_PERM_EXTRA) &&
+           (feat <= FEAT_PERM_SOLID))
        {
 #ifdef JP
                msg_print("¤³¤Î´ä¤Ï¹Å¤¹¤®¤Æ·¡¤ì¤Ê¤¤¤è¤¦¤À¡£");
@@ -1596,7 +1569,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        }
 
        /* No tunnelling through mountains */
-       else if (c_ptr->feat == FEAT_MOUNTAIN)
+       else if (feat == FEAT_MOUNTAIN)
        {
 #ifdef JP
                msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤!");
@@ -1606,10 +1579,10 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
 
        }
 
-       else if (c_ptr->feat == FEAT_TREES) /* -KMW- */
+       else if (feat == FEAT_TREES) /* -KMW- */
        {
                /* Chop Down */
-               if ((p_ptr->skill_dig > 10 + rand_int(400)) && twall(y, x, FEAT_GRASS))
+               if ((p_ptr->skill_dig > 10 + randint0(400)) && twall(y, x, FEAT_GRASS))
                {
 #ifdef JP
                        msg_print("ÌÚ¤òÀÚ¤êʧ¤Ã¤¿¡£");
@@ -1633,17 +1606,17 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                        more = TRUE;
 
                        /* Occasional Search XXX XXX */
-                       if (rand_int(100) < 25) search();
+                       if (randint0(100) < 25) search();
                }
        }
 
 
        /* Granite */
-       else if ((c_ptr->feat >= FEAT_WALL_EXTRA) &&
-                (c_ptr->feat <= FEAT_WALL_SOLID))
+       else if ((feat >= FEAT_WALL_EXTRA) &&
+                (feat <= FEAT_WALL_SOLID))
        {
                /* Tunnel */
-               if ((p_ptr->skill_dig > 40 + rand_int(1600)) && twall(y, x, floor_type[rand_int(100)]))
+               if ((p_ptr->skill_dig > 40 + randint0(1600)) && twall(y, x, floor_type[randint0(100)]))
                {
 #ifdef JP
                        msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
@@ -1670,33 +1643,33 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
 
 
        /* Quartz / Magma */
-       else if ((c_ptr->feat >= FEAT_MAGMA) &&
-           (c_ptr->feat <= FEAT_QUARTZ_K))
+       else if ((feat >= FEAT_MAGMA) &&
+           (feat <= FEAT_QUARTZ_K))
        {
                bool okay = FALSE;
                bool gold = FALSE;
                bool hard = FALSE;
 
                /* Found gold */
-               if (c_ptr->feat >= FEAT_MAGMA_H) gold = TRUE;
+               if (feat >= FEAT_MAGMA_H) gold = TRUE;
 
                /* Extract "quartz" flag XXX XXX XXX */
-               if ((c_ptr->feat - FEAT_MAGMA) & 0x01) hard = TRUE;
+               if ((feat - FEAT_MAGMA) & 0x01) hard = TRUE;
 
                /* Quartz */
                if (hard)
                {
-                       okay = (p_ptr->skill_dig > 20 + rand_int(800));
+                       okay = (p_ptr->skill_dig > 20 + randint0(800));
                }
 
                /* Magma */
                else
                {
-                       okay = (p_ptr->skill_dig > 10 + rand_int(400));
+                       okay = (p_ptr->skill_dig > 10 + randint0(400));
                }
 
                /* Success */
-               if (okay && twall(y, x, floor_type[rand_int(100)]))
+               if (okay && twall(y, x, floor_type[randint0(100)]))
                {
                        /* Found treasure */
                        if (gold)
@@ -1755,10 +1728,10 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        }
 
        /* Rubble */
-       else if (c_ptr->feat == FEAT_RUBBLE)
+       else if (feat == FEAT_RUBBLE)
        {
                /* Remove the rubble */
-               if ((p_ptr->skill_dig > rand_int(200)) && twall(y, x, floor_type[rand_int(100)]))
+               if ((p_ptr->skill_dig > randint0(200)) && twall(y, x, floor_type[randint0(100)]))
                {
                        /* Message */
 #ifdef JP
@@ -1768,7 +1741,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
 #endif
 
                        /* Hack -- place an object */
-                       if (rand_int(100) < (15 - dun_level/2))
+                       if (randint0(100) < (15 - dun_level/2))
                        {
                                /* Create a simple object */
                                place_object(y, x, FALSE, FALSE);
@@ -1799,42 +1772,11 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                }
        }
 
-       /* Secret doors */
-       else if (c_ptr->feat >= FEAT_SECRET)
-       {
-               /* Tunnel */
-               if ((p_ptr->skill_dig > 30 + rand_int(1200)) && twall(y, x, floor_type[rand_int(100)]))
-               {
-#ifdef JP
-                       msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
-#else
-                       msg_print("You have finished the tunnel.");
-#endif
-
-               }
-
-               /* Keep trying */
-               else
-               {
-                       /* We may continue tunelling */
-#ifdef JP
-                       msg_print("²ÖÖ¾´ä¤ÎÊɤ˷ê¤ò·¡¤Ã¤Æ¤¤¤ë¡£");
-#else
-                       msg_print("You tunnel into the granite wall.");
-#endif
-
-                       more = TRUE;
-
-                       /* Occasional Search XXX XXX */
-                       if (rand_int(100) < 25) search();
-               }
-       }
-
        /* Doors */
        else
        {
                /* Tunnel */
-               if ((p_ptr->skill_dig > 30 + rand_int(1200)) && twall(y, x, floor_type[randint(100)]))
+               if ((p_ptr->skill_dig > 30 + randint0(1200)) && twall(y, x, floor_type[randint1(100)]))
                {
 #ifdef JP
                        msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
@@ -1858,6 +1800,12 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                }
        }
 
+        if (is_hidden_door(c_ptr))
+        {
+                /* Occasional Search XXX XXX */
+                if (randint0(100) < 25) search();
+        }
+
        /* Notice new floor grids */
        if (!cave_floor_bold(y, x))
        {
@@ -1884,6 +1832,7 @@ void do_cmd_tunnel(void)
        int                     y, x, dir;
 
        cave_type       *c_ptr;
+       byte feat;
 
        bool            more = FALSE;
 
@@ -1916,11 +1865,14 @@ void do_cmd_tunnel(void)
                /* Get grid */
                c_ptr = &cave[y][x];
 
+                /* Feature code (applying "mimic" field) */
+                feat = c_ptr->mimic ? c_ptr->mimic : f_info[c_ptr->feat].mimic;
+
                /* No tunnelling through doors */
-               if (((c_ptr->feat >= FEAT_DOOR_HEAD) && (c_ptr->feat <= FEAT_DOOR_TAIL)) ||
-                   ((c_ptr->feat >= FEAT_BLDG_HEAD) && (c_ptr->feat <= FEAT_BLDG_TAIL)) ||
-                   ((c_ptr->feat >= FEAT_SHOP_HEAD) && (c_ptr->feat <= FEAT_SHOP_TAIL)) ||
-                   (c_ptr->feat == FEAT_MUSEUM))
+               if (((feat >= FEAT_DOOR_HEAD) && (feat <= FEAT_DOOR_TAIL)) ||
+                   ((feat >= FEAT_BLDG_HEAD) && (feat <= FEAT_BLDG_TAIL)) ||
+                   ((feat >= FEAT_SHOP_HEAD) && (feat <= FEAT_SHOP_TAIL)) ||
+                   (feat == FEAT_MUSEUM))
                {
                        /* Message */
 #ifdef JP
@@ -1932,8 +1884,8 @@ void do_cmd_tunnel(void)
                }
 
                /* No tunnelling through air */
-               else if (cave_floor_grid(c_ptr) || ((c_ptr->feat >= FEAT_MINOR_GLYPH) &&
-                   (c_ptr->feat <= FEAT_PATTERN_XTRA2)))
+               else if (cave_floor_grid(c_ptr) || ((feat >= FEAT_MINOR_GLYPH) &&
+                   (feat <= FEAT_PATTERN_XTRA2)))
                {
                        /* Message */
 #ifdef JP
@@ -1945,7 +1897,7 @@ void do_cmd_tunnel(void)
                }
 
                /* No tunnelling through mountains */
-               else if (c_ptr->feat == FEAT_MOUNTAIN)
+               else if (feat == FEAT_MOUNTAIN)
                {
 #ifdef JP
                        msg_print("¤½¤³¤Ï·¡¤ì¤Ê¤¤¡£");
@@ -2044,7 +1996,7 @@ bool easy_open_door(int y, int x)
                if (j < 2) j = 2;
 
                /* Success */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
                        /* Message */
 #ifdef JP
@@ -2171,7 +2123,7 @@ static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
        }
 
        /* Success (get a lot of experience) */
-       else if (rand_int(100) < j)
+       else if (randint0(100) < j)
        {
 #ifdef JP
                msg_print("È¢¤Ë»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¥È¥é¥Ã¥×¤ò²ò½ü¤·¤¿¡£");
@@ -2184,7 +2136,7 @@ static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
        }
 
        /* Failure -- Keep trying */
-       else if ((i > 5) && (randint(i) > 5))
+       else if ((i > 5) && (randint1(i) > 5))
        {
                /* We may keep trying */
                more = TRUE;
@@ -2271,7 +2223,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
        if (j < 2) j = 2;
 
        /* Success */
-       if (rand_int(100) < j)
+       if (randint0(100) < j)
        {
                /* Message */
 #ifdef JP
@@ -2288,9 +2240,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
                c_ptr->info &= ~(CAVE_MARK);
 
                /* Remove the trap */
-               c_ptr->feat = floor_type[rand_int(100)];
-               c_ptr->info &= ~(CAVE_MASK);
-               c_ptr->info |= CAVE_FLOOR;
+               c_ptr->feat = floor_type[randint0(100)];
                note_spot(y, x);
                lite_spot(y, x);
 
@@ -2308,7 +2258,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
        }
 
        /* Failure -- Keep trying */
-       else if ((i > 5) && (randint(i) > 5))
+       else if ((i > 5) && (randint1(i) > 5))
        {
                /* Failure */
                if (flush_failure) flush();
@@ -2517,7 +2467,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
        if (temp < 1) temp = 1;
 
        /* Hack -- attempt to bash down the door */
-       if (rand_int(100) < temp)
+       if (randint0(100) < temp)
        {
                /* Message */
 #ifdef JP
@@ -2528,7 +2478,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
 
 
                /* Break down the door */
-               if (rand_int(100) < 50)
+               if (randint0(100) < 50)
                {
                        cave_set_feat(y, x, FEAT_BROKEN);
                }
@@ -2551,7 +2501,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
        }
 
        /* Saving throw against stun */
-       else if (rand_int(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
+       else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
                 p_ptr->lev)
        {
                /* Message */
@@ -2578,7 +2528,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
 
 
                /* Hack -- Lose balance ala paralysis */
-               (void)set_paralyzed(p_ptr->paralyzed + 2 + rand_int(2));
+               (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
        }
 
        /* Result */
@@ -2739,43 +2689,45 @@ void do_cmd_alter(void)
                }
 
                /* Tunnel through walls */
-               else if (((c_ptr->feat >= FEAT_SECRET) &&
+               else if (((c_ptr->feat >= FEAT_RUBBLE) &&
                          (c_ptr->feat < FEAT_MINOR_GLYPH)) ||
                         ((c_ptr->feat == FEAT_TREES) ||
                          (c_ptr->feat == FEAT_MOUNTAIN)))
                {
-                       /* Tunnel */
                        more = do_cmd_tunnel_aux(y, x, dir);
                }
 
-               /* Bash jammed doors */
-               else if ((c_ptr->feat >= FEAT_DOOR_HEAD + 0x08) &&
-                        (c_ptr->feat < FEAT_MINOR_GLYPH))
-               {
-                       /* Tunnel */
-                       more = do_cmd_bash_aux(y, x, dir);
-               }
-
-               /* Open closed doors */
-               else if ((c_ptr->feat >= FEAT_DOOR_HEAD) &&
-                        (c_ptr->feat < FEAT_MINOR_GLYPH))
-               {
-                       /* Tunnel */
-                       more = do_cmd_open_aux(y, x, dir);
-               }
+                else if (is_closed_door(c_ptr->feat))
+                {
+                        /* Tunnel hidden door */
+                        if (c_ptr->mimic)
+                        {
+                                more = do_cmd_tunnel_aux(y, x, dir);
+                        }
+
+                        /* Bash jammed doors */
+                        else if (c_ptr->feat >= FEAT_DOOR_HEAD + 0x08)
+                        {
+                                more = do_cmd_bash_aux(y, x, dir);
+                        }
+
+                        /* Locked doors */
+                        else
+                        {
+                                more = do_cmd_open_aux(y, x, dir);
+                        }
+                }
 
                /* Close open doors */
                else if ((c_ptr->feat == FEAT_OPEN) ||
                         (c_ptr->feat == FEAT_BROKEN))
                {
-                       /* Tunnel */
                        more = do_cmd_close_aux(y, x, dir);
                }
 
                /* Disarm traps */
                else if (is_trap(c_ptr->feat))
                {
-                       /* Tunnel */
                        more = do_cmd_disarm_aux(y, x, dir);
                }
 
@@ -2981,7 +2933,7 @@ void do_cmd_walk(int pickup)
                int tmp = 120 + p_ptr->lev*10 - wilderness[py][px].level + 5;
                if (tmp < 1) 
                        tmp = 1;
-               if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && rand_int(tmp) < (21-p_ptr->skill_stl))
+               if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
                {
                        /* Inform the player of his horrible fate :=) */
 #ifdef JP
@@ -2993,8 +2945,8 @@ void do_cmd_walk(int pickup)
                        /* Go into large wilderness view */
                        p_ptr->wilderness_x = px;
                        p_ptr->wilderness_y = py;
-                       p_ptr->oldpy = randint(MAX_HGT-2);
-                       p_ptr->oldpx = randint(MAX_WID-2);
+                       p_ptr->oldpy = randint1(MAX_HGT-2);
+                       p_ptr->oldpx = randint1(MAX_WID-2);
                        energy_use = 100;
                        change_wild_mode();
 
@@ -3074,7 +3026,7 @@ void do_cmd_stay(int pickup)
 
 
        /* Spontaneous Searching */
-       if ((p_ptr->skill_fos >= 50) || (0 == rand_int(50 - p_ptr->skill_fos)))
+       if ((p_ptr->skill_fos >= 50) || (0 == randint0(50 - p_ptr->skill_fos)))
        {
                search();
        }
@@ -3100,7 +3052,7 @@ void do_cmd_stay(int pickup)
 
                energy_use = 0;
                /* Hack -- enter store */
-               command_new = 253;
+               command_new = SPECIAL_KEY_STORE;
        }
 
        /* Hack -- enter a building if we are on one -KMW- */
@@ -3112,7 +3064,7 @@ void do_cmd_stay(int pickup)
 
                energy_use = 0;
                /* Hack -- enter building */
-               command_new = 254;
+               command_new = SPECIAL_KEY_BUILDING;
        }
 
        /* Exit a quest if reach the quest exit */
@@ -3134,24 +3086,7 @@ void do_cmd_stay(int pickup)
                        msg_print(NULL);
                }
 
-               leaving_quest = p_ptr->inside_quest;
-
-               /* Leaving an 'only once' quest marks it as failed */
-               if (leaving_quest &&
-                       ((quest[leaving_quest].flags & QUEST_FLAG_ONCE) || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
-                       (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
-               {
-                       quest[leaving_quest].status = QUEST_STATUS_FAILED;
-                       quest[leaving_quest].complev = (byte)p_ptr->lev;
-                       if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
-                       {
-                               r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
-                               if (record_rand_quest)
-                                       do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
-                       }
-                       else if (record_fix_quest)
-                               do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
-               }
+               leave_quest_check();
 
                p_ptr->inside_quest = cave[py][px].special;
                dun_level = 0;
@@ -3298,16 +3233,16 @@ static int breakage_chance(object_type *o_ptr)
 }
 
 
-s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
+static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
 {
        int mult = 10;
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
-       u32b f1, f2, f3;
+       u32b flgs[TR_FLAG_SIZE];
 
        /* Extract the flags */
-       object_flags(o_ptr, &f1, &f2, &f3);
+       object_flags(o_ptr, flgs);
 
        /* Some "weapons" and "ammo" do extra damage */
        switch (o_ptr->tval)
@@ -3317,7 +3252,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                case TV_BOLT:
                {
                        /* Slay Animal */
-                       if ((f1 & TR1_SLAY_ANIMAL) &&
+                       if ((have_flag(flgs, TR_SLAY_ANIMAL)) &&
                            (r_ptr->flags3 & RF3_ANIMAL))
                        {
                                if (m_ptr->ml)
@@ -3328,8 +3263,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 17) mult = 17;
                        }
 
+                       /* Kill Animal */
+                       if ((have_flag(flgs, TR_KILL_ANIMAL)) &&
+                           (r_ptr->flags3 & RF3_ANIMAL))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_ANIMAL;
+                               }
+
+                               if (mult < 27) mult = 27;
+                       }
+
                        /* Slay Evil */
-                       if ((f1 & TR1_SLAY_EVIL) &&
+                       if ((have_flag(flgs, TR_SLAY_EVIL)) &&
                            (r_ptr->flags3 & RF3_EVIL))
                        {
                                if (m_ptr->ml)
@@ -3340,8 +3287,44 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 15) mult = 15;
                        }
 
+                       /* Kill Evil */
+                       if ((have_flag(flgs, TR_KILL_EVIL)) &&
+                           (r_ptr->flags3 & RF3_EVIL))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_EVIL;
+                               }
+
+                               if (mult < 25) mult = 25;
+                       }
+
+                       /* Slay Human */
+                       if ((have_flag(flgs, TR_SLAY_HUMAN)) &&
+                           (r_ptr->flags2 & RF2_HUMAN))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags2 |= RF2_HUMAN;
+                               }
+
+                               if (mult < 17) mult = 17;
+                       }
+
+                       /* Kill Human */
+                       if ((have_flag(flgs, TR_KILL_HUMAN)) &&
+                           (r_ptr->flags2 & RF2_HUMAN))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags2 |= RF2_HUMAN;
+                               }
+
+                               if (mult < 27) mult = 27;
+                       }
+
                        /* Slay Undead */
-                       if ((f1 & TR1_SLAY_UNDEAD) &&
+                       if ((have_flag(flgs, TR_SLAY_UNDEAD)) &&
                            (r_ptr->flags3 & RF3_UNDEAD))
                        {
                                if (m_ptr->ml)
@@ -3352,8 +3335,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 20) mult = 20;
                        }
 
+                       /* Kill Undead */
+                       if ((have_flag(flgs, TR_KILL_UNDEAD)) &&
+                           (r_ptr->flags3 & RF3_UNDEAD))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_UNDEAD;
+                               }
+
+                               if (mult < 30) mult = 30;
+                       }
+
                        /* Slay Demon */
-                       if ((f1 & TR1_SLAY_DEMON) &&
+                       if ((have_flag(flgs, TR_SLAY_DEMON)) &&
                            (r_ptr->flags3 & RF3_DEMON))
                        {
                                if (m_ptr->ml)
@@ -3364,8 +3359,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 20) mult = 20;
                        }
 
+                       /* Kill Demon */
+                       if ((have_flag(flgs, TR_KILL_DEMON)) &&
+                           (r_ptr->flags3 & RF3_DEMON))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_DEMON;
+                               }
+
+                               if (mult < 30) mult = 30;
+                       }
+
                        /* Slay Orc */
-                       if ((f1 & TR1_SLAY_ORC) &&
+                       if ((have_flag(flgs, TR_SLAY_ORC)) &&
                            (r_ptr->flags3 & RF3_ORC))
                        {
                                if (m_ptr->ml)
@@ -3376,8 +3383,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 20) mult = 20;
                        }
 
+                       /* Kill Orc */
+                       if ((have_flag(flgs, TR_KILL_ORC)) &&
+                           (r_ptr->flags3 & RF3_ORC))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_ORC;
+                               }
+
+                               if (mult < 30) mult = 30;
+                       }
+
                        /* Slay Troll */
-                       if ((f1 & TR1_SLAY_TROLL) &&
+                       if ((have_flag(flgs, TR_SLAY_TROLL)) &&
                            (r_ptr->flags3 & RF3_TROLL))
                        {
                                if (m_ptr->ml)
@@ -3388,8 +3407,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 20) mult = 20;
                        }
 
+                       /* Kill Troll */
+                       if ((have_flag(flgs, TR_KILL_TROLL)) &&
+                           (r_ptr->flags3 & RF3_TROLL))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_TROLL;
+                               }
+
+                               if (mult < 30) mult = 30;
+                       }
+
                        /* Slay Giant */
-                       if ((f1 & TR1_SLAY_GIANT) &&
+                       if ((have_flag(flgs, TR_SLAY_GIANT)) &&
                            (r_ptr->flags3 & RF3_GIANT))
                        {
                                if (m_ptr->ml)
@@ -3400,8 +3431,20 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 20) mult = 20;
                        }
 
+                       /* Kill Giant */
+                       if ((have_flag(flgs, TR_KILL_GIANT)) &&
+                           (r_ptr->flags3 & RF3_GIANT))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags3 |= RF3_GIANT;
+                               }
+
+                               if (mult < 30) mult = 30;
+                       }
+
                        /* Slay Dragon  */
-                       if ((f1 & TR1_SLAY_DRAGON) &&
+                       if ((have_flag(flgs, TR_SLAY_DRAGON)) &&
                            (r_ptr->flags3 & RF3_DRAGON))
                        {
                                if (m_ptr->ml)
@@ -3413,7 +3456,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Execute Dragon */
-                       if ((f1 & TR1_KILL_DRAGON) &&
+                       if ((have_flag(flgs, TR_KILL_DRAGON)) &&
                            (r_ptr->flags3 & RF3_DRAGON))
                        {
                                if (m_ptr->ml)
@@ -3430,7 +3473,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Brand (Acid) */
-                       if ((f1 & TR1_BRAND_ACID) || (p_ptr->special_attack & (ATTACK_ACID)))
+                       if ((have_flag(flgs, TR_BRAND_ACID)) || (p_ptr->special_attack & (ATTACK_ACID)))
                        {
                                /* Notice immunity */
                                if (r_ptr->flags3 & RF3_IM_ACID)
@@ -3449,7 +3492,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Brand (Elec) */
-                       if ((f1 & TR1_BRAND_ELEC) || (p_ptr->special_attack & (ATTACK_ELEC)))
+                       if ((have_flag(flgs, TR_BRAND_ELEC)) || (p_ptr->special_attack & (ATTACK_ELEC)))
                        {
                                /* Notice immunity */
                                if (r_ptr->flags3 & RF3_IM_ELEC)
@@ -3468,7 +3511,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Brand (Fire) */
-                       if ((f1 & TR1_BRAND_FIRE) || (p_ptr->special_attack & (ATTACK_FIRE)))
+                       if ((have_flag(flgs, TR_BRAND_FIRE)) || (p_ptr->special_attack & (ATTACK_FIRE)))
                        {
                                /* Notice immunity */
                                if (r_ptr->flags3 & RF3_IM_FIRE)
@@ -3487,7 +3530,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Brand (Cold) */
-                       if ((f1 & TR1_BRAND_COLD) || (p_ptr->special_attack & (ATTACK_COLD)))
+                       if ((have_flag(flgs, TR_BRAND_COLD)) || (p_ptr->special_attack & (ATTACK_COLD)))
                        {
                                /* Notice immunity */
                                if (r_ptr->flags3 & RF3_IM_COLD)
@@ -3505,7 +3548,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                        }
 
                        /* Brand (Poison) */
-                       if ((f1 & TR1_BRAND_POIS) || (p_ptr->special_attack & (ATTACK_POIS)))
+                       if ((have_flag(flgs, TR_BRAND_POIS)) || (p_ptr->special_attack & (ATTACK_POIS)))
                        {
                                /* Notice immunity */
                                if (r_ptr->flags3 & RF3_IM_POIS)
@@ -3523,7 +3566,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                }
                        }
 
-                       if ((f1 & TR1_FORCE_WEPON) && (p_ptr->csp > (p_ptr->msp / 30)))
+                       if ((have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (p_ptr->msp / 30)))
                        {
                                p_ptr->csp -= (1+(p_ptr->msp / 30));
                                p_ptr->redraw |= (PR_MANA);
@@ -3614,9 +3657,9 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
        /* Actually "fire" the object */
        bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
        if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
-               chance = (p_ptr->skill_thb + ((weapon_exp[0][j_ptr->sval])/400 + bonus) * BTH_PLUS_ADJ);
+               chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval])/400 + bonus) * BTH_PLUS_ADJ);
        else
-               chance = (p_ptr->skill_thb + ((weapon_exp[0][j_ptr->sval]-4000)/200 + bonus) * BTH_PLUS_ADJ);
+               chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval]-4000)/200 + bonus) * BTH_PLUS_ADJ);
 
        energy_use = bow_energy(j_ptr->sval);
        tmul = bow_tmul(j_ptr->sval);
@@ -3768,7 +3811,7 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
 
                        if ((r_ptr->level + 10) > p_ptr->lev)
                        {
-                               int now_exp = weapon_exp[0][j_ptr->sval];
+                               int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
                                if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
                                {
                                        int amount = 0;
@@ -3776,16 +3819,16 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
                                        else if (now_exp <  6000) amount = 25;
                                        else if ((now_exp < 7000) && (p_ptr->lev > 19)) amount = 10;
                                        else if (p_ptr->lev > 34) amount = 2;
-                                       weapon_exp[0][j_ptr->sval] += amount;
+                                       p_ptr->weapon_exp[0][j_ptr->sval] += amount;
                                        p_ptr->update |= (PU_BONUS);
                                }
                        }
 
                        if (p_ptr->riding)
                        {
-                               if (skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING] && ((skill_exp[GINOU_RIDING] - 1000) / 200 < r_info[m_list[p_ptr->riding].r_idx].level) && one_in_(2))
+                               if (p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING] && ((p_ptr->skill_exp[GINOU_RIDING] - 1000) / 200 < r_info[m_list[p_ptr->riding].r_idx].level) && one_in_(2))
                                {
-                                       skill_exp[GINOU_RIDING]+=1;
+                                       p_ptr->skill_exp[GINOU_RIDING]+=1;
                                        p_ptr->update |= (PU_BONUS);
                                }
                        }
@@ -3858,7 +3901,7 @@ note_dies = "
 
 
                                        /* Hack -- Track this monster race */
-                                       if (m_ptr->ml) monster_race_track((bool)(m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
+                                       if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
 
                                        /* Hack -- Track this monster */
                                        if (m_ptr->ml) health_track(c_ptr->m_idx);
@@ -3875,7 +3918,7 @@ note_dies = "
                                tdam = mon_damage_mod(m_ptr, tdam, FALSE);
 
                                /* Complex message */
-                               if (wizard || cheat_xtra)
+                               if (p_ptr->wizard || cheat_xtra)
                                {
 #ifdef JP
                                        msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
@@ -3938,8 +3981,7 @@ note_dies = "
                                        }
                                        if (!projectable(m_ptr->fy, m_ptr->fx, py, px))
                                        {
-                                               m_ptr->target_y = py;
-                                               m_ptr->target_x = px;
+                                               set_target(m_ptr, py, px);
                                        }
                                }
                        }
@@ -3976,7 +4018,7 @@ note_dies = "
                object_copy(o_ptr, q_ptr);
 
                /* Forget mark */
-               o_ptr->marked = FALSE;
+               o_ptr->marked = 0;
 
                /* Forget location */
                o_ptr->iy = o_ptr->ix = 0;
@@ -4099,7 +4141,7 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
 
        int msec = delay_factor * delay_factor * delay_factor;
 
-       u32b f1, f2, f3;
+       u32b flgs[TR_FLAG_SIZE];
        cptr q, s;
        bool come_back = FALSE;
        bool do_drop = TRUE;
@@ -4177,11 +4219,25 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
                msg_print("Hmmm, it seems to be cursed.");
 #endif
 
-
                /* Nope */
                return FALSE;
        }
 
+       if (p_ptr->inside_arena)
+       {
+               if (o_ptr->tval != 5)
+               {
+#ifdef JP
+                       msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
+#else
+                       msg_print("You're in the arena now. This is hand-to-hand!");
+#endif
+                       msg_print(NULL);
+
+                       /* Nope */
+                       return FALSE;
+               }
+       }
 
        /* Get local object */
        q_ptr = &forge;
@@ -4190,7 +4246,7 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
        object_copy(q_ptr, o_ptr);
 
        /* Extract the thrown object's flags. */
-       object_flags(q_ptr, &f1, &f2, &f3);
+       object_flags(q_ptr, flgs);
 
        /* Distribute the charges of rods/wands between the stacks */
        distribute_charges(o_ptr, q_ptr, 1);
@@ -4209,7 +4265,7 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
 
        /* Enforce a minimum "weight" of one pound */
        div = ((q_ptr->weight > 10) ? q_ptr->weight : 10);
-       if ((f2 & (TR2_THROW)) || boomerang) div /= 2;
+       if ((have_flag(flgs, TR_THROW)) || boomerang) div /= 2;
 
        /* Hack -- Distance -- Reward strength, penalize weight */
        tdis = (adj_str_blow[p_ptr->stat_ind[A_STR]] + 20) * mul / div;
@@ -4219,8 +4275,8 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
 
        if (shuriken)
        {
-               ty = rand_int(101)-50+py;
-               tx = rand_int(101)-50+px;
+               ty = randint0(101)-50+py;
+               tx = randint0(101)-50+px;
        }
        else
        {
@@ -4283,11 +4339,11 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
        /* Hack -- Handle stuff */
        handle_stuff();
 
-       if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((f2 & TR2_THROW) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
+       if ((p_ptr->pclass == CLASS_NINJA) && ((q_ptr->tval == TV_SPIKE) || ((have_flag(flgs, TR_THROW)) && (q_ptr->tval == TV_SWORD)))) shuriken = TRUE;
        else shuriken = FALSE;
 
        /* Chance of hitting */
-       if (f2 & (TR2_THROW)) chance = ((p_ptr->skill_tht) +
+       if (have_flag(flgs, TR_THROW)) chance = ((p_ptr->skill_tht) +
                ((p_ptr->to_h_b + q_ptr->to_h) * BTH_PLUS_ADJ));
        else chance = (p_ptr->skill_tht + (p_ptr->to_h_b * BTH_PLUS_ADJ));
 
@@ -4425,7 +4481,7 @@ note_dies = "
 
 
                                        /* Hack -- Track this monster race */
-                                       if (m_ptr->ml) monster_race_track((bool)(m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
+                                       if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
 
                                        /* Hack -- Track this monster */
                                        if (m_ptr->ml) health_track(c_ptr->m_idx);
@@ -4436,14 +4492,17 @@ note_dies = "
                                /* Apply special damage XXX XXX XXX */
                                tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0);
                                tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
-                               tdam += q_ptr->to_d;
+                               if (q_ptr->to_d > 0)
+                                       tdam += q_ptr->to_d;
+                               else
+                                       tdam += -q_ptr->to_d;
 
                                if (boomerang)
                                {
                                        tdam *= (mult+p_ptr->num_blow[item - INVEN_RARM]);
                                        tdam += p_ptr->to_d_m;
                                }
-                               else if (f2 & (TR2_THROW))
+                               else if (have_flag(flgs, TR_THROW))
                                {
                                        tdam *= (3+mult);
                                        tdam += p_ptr->to_d_m;
@@ -4464,7 +4523,7 @@ note_dies = "
                                tdam = mon_damage_mod(m_ptr, tdam, FALSE);
 
                                /* Complex message */
-                               if (wizard)
+                               if (p_ptr->wizard)
                                {
 #ifdef JP
                                        msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
@@ -4527,15 +4586,15 @@ note_dies = "
        {
                j = 100;
 
-               if (!(summon_named_creature(y, x, q_ptr->pval, FALSE, FALSE, FALSE,
-                     (bool)!(q_ptr->ident & IDENT_CURSED))))
+               if (!(summon_named_creature(0, y, x, q_ptr->pval,
+                                           !(cursed_p(q_ptr)) ? PM_FORCE_PET : 0L)))
 #ifdef JP
 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
 #else
                        msg_print("The Figurine writhes and then shatters.");
 #endif
 
-               else if (q_ptr->ident & IDENT_CURSED)
+               else if (cursed_p(q_ptr))
 #ifdef JP
 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
 #else
@@ -4548,7 +4607,7 @@ msg_print("
        /* Potions smash open */
        if (object_is_potion(q_ptr))
        {
-               if (hit_body || hit_wall || (randint(100) < j))
+               if (hit_body || hit_wall || (randint1(100) < j))
                {
                        /* Message */
 #ifdef JP
@@ -4588,16 +4647,16 @@ msg_print("
 
        if (return_when_thrown)
        {
-               int back_chance = randint(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
+               int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
                char o2_name[MAX_NLEN];
                bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
 
                j = -1;
-               if (boomerang) back_chance += 4+randint(5);
+               if (boomerang) back_chance += 4+randint1(5);
                if (super_boomerang) back_chance += 100;
                object_desc(o2_name, q_ptr, FALSE, 0);
 
-               if((back_chance > 30) && ((randint(100) != 1) || super_boomerang))
+               if((back_chance > 30) && (!one_in_(100) || super_boomerang))
                {
                        for (i = cur_dis-1;i>0;i--)
                        {