OSDN Git Service

[Implement] #37285 量子生物が確率的に消滅する処理を変更し、ユニークならばショートテレポートまたはテレポートアウェイ (距離10)が発動するようにした...
[hengband/hengband.git] / src / monster-process.c
index ca95757..1a38a1e 100644 (file)
 #include "view-mainwindow.h"
 
 
-/*!
- * @brief モンスターが敵に接近するための方向を決める /
- * Calculate the direction to the next enemy
- * @param target_ptr プレーヤーへの参照ポインタ
- * @param m_idx モンスターの参照ID
- * @param mm 移動するべき方角IDを返す参照ポインタ
- * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
- */
+ /*!
 * @brief モンスターが敵に接近するための方向を決める /
 * Calculate the direction to the next enemy
 * @param target_ptr プレーヤーへの参照ポインタ
 * @param m_idx モンスターの参照ID
 * @param mm 移動するべき方角IDを返す参照ポインタ
 * @return 方向が確定した場合TRUE、接近する敵がそもそもいない場合FALSEを返す
 */
 static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
 {
-       int i;
-       POSITION x = 0, y = 0;
-       MONSTER_IDX t_idx;
-       int start;
-       int plus = 1;
-
        floor_type *floor_ptr = target_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        monster_type *t_ptr;
 
+       POSITION x = 0, y = 0;
        if (target_ptr->riding_t_m_idx && player_bold(target_ptr, m_ptr->fy, m_ptr->fx))
        {
                y = floor_ptr->m_list[target_ptr->riding_t_m_idx].fy;
@@ -74,21 +69,23 @@ static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
        }
        else
        {
+               int start;
+               int plus = 1;
                if (target_ptr->phase_out)
                {
-                       start = randint1(floor_ptr->m_max-1)+floor_ptr->m_max;
-                       if(randint0(2)) plus = -1;
+                       start = randint1(floor_ptr->m_max - 1) + floor_ptr->m_max;
+                       if (randint0(2)) plus = -1;
                }
                else start = floor_ptr->m_max + 1;
 
                /* Scan thru all monsters */
-               for (i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i+=plus)
+               for (int i = start; ((i < start + floor_ptr->m_max) && (i > start - floor_ptr->m_max)); i += plus)
                {
                        MONSTER_IDX dummy = (i % floor_ptr->m_max);
 
                        if (!dummy) continue;
 
-                       t_idx = dummy;
+                       MONSTER_IDX t_idx = dummy;
                        t_ptr = &floor_ptr->m_list[t_idx];
 
                        /* The monster itself isn't a target */
@@ -117,11 +114,11 @@ static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
                        }
 
                        /* Monster must be 'an enemy' */
-                       if (!are_enemies(m_ptr, t_ptr)) continue;
+                       if (!are_enemies(target_ptr, m_ptr, t_ptr)) continue;
 
                        /* Monster must be projectable if we can't pass through walls */
                        if (((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) ||
-                           ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
+                               ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))
                        {
                                if (!in_disintegration_range(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
                        }
@@ -136,6 +133,7 @@ static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
 
                        break;
                }
+
                if (!x && !y) return FALSE;
        }
 
@@ -200,7 +198,6 @@ static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
                mm[2] = 2;
        }
 
-       /* Found a monster */
        return TRUE;
 }
 
@@ -220,12 +217,9 @@ static bool get_enemy_dir(player_type *target_ptr, MONSTER_IDX m_idx, int *mm)
  * Note that this function is responsible for about one to five percent\n
  * of the processor use in normal conditions...\n
  */
-static bool mon_will_run(MONSTER_IDX m_idx)
+static bool mon_will_run(player_type *target_ptr, MONSTER_IDX m_idx)
 {
-       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
-
-#ifdef ALLOW_TERROR
-
+       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        PLAYER_LEVEL p_lev;
@@ -234,14 +228,12 @@ static bool mon_will_run(MONSTER_IDX m_idx)
        HIT_POINT m_chp, m_mhp;
        u32b p_val, m_val;
 
-#endif
-
        /* Friends can be commanded to avoid the player */
        if (is_pet(m_ptr))
        {
                /* Are we trying to avoid the player? */
-               return ((p_ptr->pet_follow_distance < 0) &&
-                                 (m_ptr->cdis <= (0 - p_ptr->pet_follow_distance)));
+               return ((target_ptr->pet_follow_distance < 0) &&
+                       (m_ptr->cdis <= (0 - target_ptr->pet_follow_distance)));
        }
 
        /* Keep monsters from running too far away */
@@ -250,13 +242,11 @@ static bool mon_will_run(MONSTER_IDX m_idx)
        /* All "afraid" monsters will run away */
        if (MON_MONFEAR(m_ptr)) return TRUE;
 
-#ifdef ALLOW_TERROR
-
        /* Nearby monsters will not become terrified */
        if (m_ptr->cdis <= 5) return FALSE;
 
        /* Examine player power (level) */
-       p_lev = p_ptr->lev;
+       p_lev = target_ptr->lev;
 
        /* Examine monster power (level plus morale) */
        m_lev = r_ptr->level + (m_idx & 0x08) + 25;
@@ -266,8 +256,8 @@ static bool mon_will_run(MONSTER_IDX m_idx)
        if (m_lev + 4 <= p_lev) return TRUE;
 
        /* Examine player health */
-       p_chp = p_ptr->chp;
-       p_mhp = p_ptr->mhp;
+       p_chp = target_ptr->chp;
+       p_mhp = target_ptr->mhp;
 
        /* Examine monster health */
        m_chp = m_ptr->hp;
@@ -280,9 +270,6 @@ static bool mon_will_run(MONSTER_IDX m_idx)
        /* Strong players scare strong monsters */
        if (p_val * m_mhp > m_val * p_mhp) return TRUE;
 
-#endif
-
-       /* Assume no terror */
        return FALSE;
 }
 
@@ -298,41 +285,36 @@ static bool mon_will_run(MONSTER_IDX m_idx)
  */
 static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
 {
-       int i, best = 999;
-       POSITION y, x, y1, x1;
-
-       grid_type *g_ptr;
-       bool can_open_door = FALSE;
-       int now_cost;
-
        floor_type *floor_ptr = target_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        /* Monster location */
-       y1 = m_ptr->fy;
-       x1 = m_ptr->fx;
+       POSITION y1 = m_ptr->fy;
+       POSITION x1 = m_ptr->fx;
 
        /* Monster can already cast spell to player */
        if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x)) return FALSE;
 
        /* Set current grid cost */
-       now_cost = floor_ptr->grid_array[y1][x1].cost;
+       int now_cost = floor_ptr->grid_array[y1][x1].cost;
        if (now_cost == 0) now_cost = 999;
 
        /* Can monster bash or open doors? */
+       bool can_open_door = FALSE;
        if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
        {
                can_open_door = TRUE;
        }
 
        /* Check nearby grids, diagonals first */
-       for (i = 7; i >= 0; i--)
+       int best = 999;
+       for (int i = 7; i >= 0; i--)
        {
                int cost;
 
-               y = y1 + ddy_ddd[i];
-               x = x1 + ddx_ddd[i];
+               POSITION y = y1 + ddy_ddd[i];
+               POSITION x = x1 + ddx_ddd[i];
 
                /* Ignore locations off of edge */
                if (!in_bounds2(floor_ptr, y, x)) continue;
@@ -340,6 +322,7 @@ static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION
                /* Simply move to player */
                if (player_bold(target_ptr, y, x)) return FALSE;
 
+               grid_type *g_ptr;
                g_ptr = &floor_ptr->grid_array[y][x];
 
                cost = g_ptr->cost;
@@ -348,7 +331,7 @@ static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION
                if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall)) || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding))))
                {
                        if (cost == 0) continue;
-                       if (!can_open_door && is_closed_door(g_ptr->feat)) continue;
+                       if (!can_open_door && is_closed_door(target_ptr, g_ptr->feat)) continue;
                }
 
                /* Hack -- for kill or pass wall monster.. */
@@ -366,10 +349,8 @@ static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION
                (*xp) = x1 + ddx_ddd[i];
        }
 
-       /* No legal move (?) */
        if (best == 999) return FALSE;
 
-       /* Success */
        return TRUE;
 }
 
@@ -404,20 +385,15 @@ static bool get_moves_aux2(player_type *target_ptr, MONSTER_IDX m_idx, POSITION
  */
 static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no_flow)
 {
-       int i, best;
-       POSITION y, x, y1, x1;
-
        grid_type *g_ptr;
-       bool use_scent = FALSE;
-
        floor_type *floor_ptr = target_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        /* Can monster cast attack spell? */
        if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
-           r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
-           r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
+               r_ptr->a_ability_flags1 & (RF5_ATTACK_MASK) ||
+               r_ptr->a_ability_flags2 & (RF6_ATTACK_MASK))
        {
                /* Can move spell castable grid? */
                if (get_moves_aux2(target_ptr, m_idx, yp, xp)) return TRUE;
@@ -431,8 +407,8 @@ static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *
        if ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)) return FALSE;
 
        /* Monster location */
-       y1 = m_ptr->fy;
-       x1 = m_ptr->fx;
+       POSITION y1 = m_ptr->fy;
+       POSITION x1 = m_ptr->fx;
 
        /* Hack -- Player can see us, run towards him */
        if (player_has_los_bold(target_ptr, y1, x1) && projectable(target_ptr, target_ptr->y, target_ptr->x, y1, x1)) return FALSE;
@@ -441,6 +417,8 @@ static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *
        g_ptr = &floor_ptr->grid_array[y1][x1];
 
        /* If we can hear noises, advance towards them */
+       int best;
+       bool use_scent = FALSE;
        if (g_ptr->cost)
        {
                best = 999;
@@ -463,10 +441,10 @@ static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *
        }
 
        /* Check nearby grids, diagonals first */
-       for (i = 7; i >= 0; i--)
+       for (int i = 7; i >= 0; i--)
        {
-               y = y1 + ddy_ddd[i];
-               x = x1 + ddx_ddd[i];
+               POSITION y = y1 + ddy_ddd[i];
+               POSITION x = x1 + ddx_ddd[i];
 
                /* Ignore locations off of edge */
                if (!in_bounds2(floor_ptr, y, x)) continue;
@@ -502,10 +480,8 @@ static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *
                (*xp) = target_ptr->x + 16 * ddx_ddd[i];
        }
 
-       /* No legal move (?) */
        if (best == 999 || best == 0) return FALSE;
 
-       /* Success */
        return TRUE;
 }
 
@@ -522,38 +498,35 @@ static bool get_moves_aux(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *
  * but instead of heading directly for it, the monster should "swerve"\n
  * around the player so that he has a smaller chance of getting hit.\n
  */
-static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
+static bool get_fear_moves_aux(floor_type *floor_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
 {
-       POSITION y, x, y1, x1, fy, fx, gy = 0, gx = 0;
-       int score = -1;
-       int i;
-
-       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
+       POSITION gy = 0, gx = 0;
 
        /* Monster location */
-       fy = m_ptr->fy;
-       fx = m_ptr->fx;
+       monster_type *m_ptr = &floor_ptr->m_list[m_idx];
+       POSITION fy = m_ptr->fy;
+       POSITION fx = m_ptr->fx;
 
        /* Desired destination */
-       y1 = fy - (*yp);
-       x1 = fx - (*xp);
+       POSITION y1 = fy - (*yp);
+       POSITION x1 = fx - (*xp);
 
        /* Check nearby grids, diagonals first */
-       for (i = 7; i >= 0; i--)
+       int score = -1;
+       for (int i = 7; i >= 0; i--)
        {
                POSITION dis, s;
-
-               y = fy + ddy_ddd[i];
-               x = fx + ddx_ddd[i];
+               POSITION y = fy + ddy_ddd[i];
+               POSITION x = fx + ddx_ddd[i];
 
                /* Ignore locations off of edge */
-               if (!in_bounds2(p_ptr->current_floor_ptr, y, x)) continue;
+               if (!in_bounds2(floor_ptr, y, x)) continue;
 
                /* Calculate distance of this grid from our destination */
                dis = distance(y, x, y1, x1);
 
                /* Score this grid */
-               s = 5000 / (dis + 3) - 500 / (p_ptr->current_floor_ptr->grid_array[y][x].dist + 1);
+               s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].dist + 1);
 
                /* No negative scores */
                if (s < 0) s = 0;
@@ -594,13 +567,13 @@ static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
  * It is probably better to replace these arrays with code to compute
  * the relevant arrays, even if the storage is pre-allocated in hard
  * coded sizes.  At the very least, code should be included which is
- * able to generate and dump these arrays (ala "los()").  
+ * able to generate and dump these arrays (ala "los()").
  *
- * Also, the storage needs could be halved by using bytes.  
+ * Also, the storage needs could be halved by using bytes.
  *
  * These arrays could be combined into two big arrays, using sub-arrays
  * to hold the offsets and lengths of each portion of the sub-arrays, and
- * this could perhaps also be used somehow in the "look" code.  
+ * this could perhaps also be used somehow in the "look" code.
  */
 
 
@@ -719,36 +692,34 @@ static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp
        POSITION fy = m_ptr->fy;
        POSITION fx = m_ptr->fx;
 
-       POSITION y, x, dy, dx, d, dis, i;
        POSITION gy = 0, gx = 0, gdis = 0;
 
-       POSITION *y_offsets;
-       POSITION *x_offsets;
-
-       grid_type *g_ptr;
-
        /* Start with adjacent locations, spread further */
-       for (d = 1; d < 10; d++)
+       for (POSITION d = 1; d < 10; d++)
        {
                /* Get the lists of points with a distance d from (fx, fy) */
+               POSITION *y_offsets;
                y_offsets = dist_offsets_y[d];
+
+               POSITION *x_offsets;
                x_offsets = dist_offsets_x[d];
 
                /* Check the locations */
-               for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
-                    dx != 0 || dy != 0;
-                    i++, dx = x_offsets[i], dy = y_offsets[i])
+               for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
+                       dx != 0 || dy != 0;
+                       i++, dx = x_offsets[i], dy = y_offsets[i])
                {
-                       y = fy + dy;
-                       x = fx + dx;
+                       POSITION y = fy + dy;
+                       POSITION x = fx + dx;
 
                        /* Skip illegal locations */
                        if (!in_bounds(floor_ptr, y, x)) continue;
 
+                       grid_type *g_ptr;
                        g_ptr = &floor_ptr->grid_array[y][x];
 
                        /* Skip locations in a wall */
-                       if (!monster_can_cross_terrain(g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == target_ptr->riding) ? CEM_RIDING : 0)) continue;
+                       if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, &r_info[m_ptr->r_idx], (m_idx == target_ptr->riding) ? CEM_RIDING : 0)) continue;
 
                        /* Check for "availability" (if monsters can flow) */
                        if (!(m_ptr->mflag2 & MFLAG2_NOFLOW))
@@ -761,34 +732,29 @@ static bool find_safety(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp
                        }
 
                        /* Check for absence of shot (more or less) */
-                       if (!projectable(target_ptr, target_ptr->y, target_ptr->x, y, x))
-                       {
-                               /* Calculate distance from player */
-                               dis = distance(y, x, target_ptr->y, target_ptr->x);
+                       if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x)) continue;
 
-                               /* Remember if further than previous */
-                               if (dis > gdis)
-                               {
-                                       gy = y;
-                                       gx = x;
-                                       gdis = dis;
-                               }
-                       }
+                       /* Calculate distance from player */
+                       POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
+
+                       /* Remember if further than previous */
+                       if (dis <= gdis) continue;
+
+                       gy = y;
+                       gx = x;
+                       gdis = dis;
                }
 
                /* Check for success */
-               if (gdis > 0)
-               {
-                       /* Good location */
-                       (*yp) = fy - gy;
-                       (*xp) = fx - gx;
+               if (gdis <= 0) continue;
 
-                       /* Found safe place */
-                       return TRUE;
-               }
+               /* Good location */
+               (*yp) = fy - gy;
+               (*xp) = fx - gx;
+
+               return TRUE;
        }
 
-       /* No safe place */
        return FALSE;
 }
 
@@ -816,61 +782,56 @@ static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp
        POSITION fy = m_ptr->fy;
        POSITION fx = m_ptr->fx;
 
-       POSITION y, x, dy, dx, d, dis, i;
        POSITION gy = 0, gx = 0, gdis = 999;
 
-       POSITION *y_offsets, *x_offsets;
-
        /* Start with adjacent locations, spread further */
-       for (d = 1; d < 10; d++)
+       for (POSITION d = 1; d < 10; d++)
        {
                /* Get the lists of points with a distance d from (fx, fy) */
+               POSITION *y_offsets;
                y_offsets = dist_offsets_y[d];
+
+               POSITION *x_offsets;
                x_offsets = dist_offsets_x[d];
 
                /* Check the locations */
-               for (i = 0, dx = x_offsets[0], dy = y_offsets[0];
-                    dx != 0 || dy != 0;
-                    i++, dx = x_offsets[i], dy = y_offsets[i])
+               for (POSITION i = 0, dx = x_offsets[0], dy = y_offsets[0];
+                       dx != 0 || dy != 0;
+                       i++, dx = x_offsets[i], dy = y_offsets[i])
                {
-                       y = fy + dy;
-                       x = fx + dx;
+                       POSITION y = fy + dy;
+                       POSITION x = fx + dx;
 
                        /* Skip illegal locations */
                        if (!in_bounds(floor_ptr, y, x)) continue;
 
                        /* Skip occupied locations */
-                       if (!monster_can_enter(y, x, r_ptr, 0)) continue;
+                       if (!monster_can_enter(target_ptr, y, x, r_ptr, 0)) continue;
 
                        /* Check for hidden, available grid */
-                       if (!projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
-                       {
-                               /* Calculate distance from player */
-                               dis = distance(y, x, target_ptr->y, target_ptr->x);
+                       if (projectable(target_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
+                               continue;
 
-                               /* Remember if closer than previous */
-                               if (dis < gdis && dis >= 2)
-                               {
-                                       gy = y;
-                                       gx = x;
-                                       gdis = dis;
-                               }
+                       /* Calculate distance from player */
+                       POSITION dis = distance(y, x, target_ptr->y, target_ptr->x);
+
+                       /* Remember if closer than previous */
+                       if (dis < gdis && dis >= 2)
+                       {
+                               gy = y;
+                               gx = x;
+                               gdis = dis;
                        }
                }
 
-               /* Check for success */
-               if (gdis < 999)
-               {
-                       /* Good location */
-                       (*yp) = fy - gy;
-                       (*xp) = fx - gx;
+               if (gdis >= 999) continue;
 
-                       /* Found good place */
-                       return TRUE;
-               }
+               *yp = fy - gy;
+               *xp = fx - gx;
+
+               return TRUE;
        }
 
-       /* No good place */
        return FALSE;
 }
 
@@ -888,15 +849,15 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
        floor_type *floor_ptr = target_ptr->current_floor_ptr;
        monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       POSITION     y = 0, ay, x = 0, ax;
-       int          move_val = 0;
-       POSITION     y2 = target_ptr->y;
-       POSITION     x2 = target_ptr->x;
-       bool         done = FALSE;
-       bool         will_run = mon_will_run(m_idx);
-       grid_type    *g_ptr;
-       bool         no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
-       bool         can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall));
+       POSITION y = 0, ay, x = 0, ax;
+       int move_val = 0;
+       POSITION y2 = target_ptr->y;
+       POSITION x2 = target_ptr->x;
+       bool done = FALSE;
+       bool will_run = mon_will_run(target_ptr, m_idx);
+       grid_type *g_ptr;
+       bool no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
+       bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall));
 
        /* Counter attack to an enemy monster */
        if (!will_run && m_ptr->target_y)
@@ -905,9 +866,9 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
 
                /* The monster must be an enemy, and in LOS */
                if (t_m_idx &&
-                   are_enemies(m_ptr, &floor_ptr->m_list[t_m_idx]) &&
-                   los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
-                   projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
+                       are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[t_m_idx]) &&
+                       los(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
+                       projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
                {
                        /* Extract the "pseudo-direction" */
                        y = m_ptr->fy - m_ptr->target_y;
@@ -917,16 +878,16 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
        }
 
        if (!done && !will_run && is_hostile(m_ptr) &&
-           (r_ptr->flags1 & RF1_FRIENDS) &&
-           ((los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) ||
-           (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
+               (r_ptr->flags1 & RF1_FRIENDS) &&
+               ((los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) ||
+               (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
        {
-       /*
-        * Animal packs try to get the player out of corridors
-        * (...unless they can move through walls -- TY)
-        */
+               /*
+                * Animal packs try to get the player out of corridors
+                * (...unless they can move through walls -- TY)
+                */
                if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall &&
-                        !(r_ptr->flags2 & RF2_KILL_WALL))
+                       !(r_ptr->flags2 & RF2_KILL_WALL))
                {
                        int i, room = 0;
 
@@ -941,7 +902,7 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
                                g_ptr = &floor_ptr->grid_array[yy][xx];
 
                                /* Check grid */
-                               if (monster_can_cross_terrain(g_ptr->feat, r_ptr, 0))
+                               if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0))
                                {
                                        /* One more room grid */
                                        room++;
@@ -952,7 +913,7 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
 
                        /* Not in a room and strong player */
                        if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
-                           (target_ptr->mhp + target_ptr->msp))
+                               (target_ptr->mhp + target_ptr->msp))
                        {
                                /* Find hiding place */
                                if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
@@ -984,7 +945,7 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
                                if (!in_bounds2(floor_ptr, y2, x2)) continue;
 
                                /* Ignore filled grids */
-                               if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
+                               if (!monster_can_enter(target_ptr, y2, x2, r_ptr, 0)) continue;
 
                                /* Try to fill this hole */
                                break;
@@ -1030,7 +991,7 @@ static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
                                if (!no_flow)
                                {
                                        /* Adjust movement */
-                                       if (get_fear_moves_aux(m_idx, &y, &x)) done = TRUE;
+                                       if (get_fear_moves_aux(target_ptr->current_floor_ptr, m_idx, &y, &x)) done = TRUE;
                                }
                        }
 
@@ -1264,21 +1225,21 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        monster_type    *y_ptr;
 
-       bool            do_turn;
-       bool            do_move;
-       bool            do_view;
-       bool            must_alter_to_move;
-
-       bool            did_open_door;
-       bool            did_bash_door;
-       bool            did_take_item;
-       bool            did_kill_item;
-       bool            did_move_body;
-       bool            did_pass_wall;
-       bool            did_kill_wall;
-       bool            gets_angry = FALSE;
-       bool            can_cross;
-       bool            aware = TRUE;
+       bool do_turn;
+       bool do_move;
+       bool do_view;
+       bool must_alter_to_move;
+
+       bool did_open_door;
+       bool did_bash_door;
+       bool did_take_item;
+       bool did_kill_item;
+       bool did_move_body;
+       bool did_pass_wall;
+       bool did_kill_wall;
+       bool gets_angry = FALSE;
+       bool can_cross;
+       bool aware = TRUE;
 
        bool fear, dead;
        bool is_riding_mon = (m_idx == target_ptr->riding);
@@ -1292,7 +1253,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        msg_print("地面に落とされた。");
 #else
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
+                       monster_desc(target_ptr, m_name, &target_ptr->current_floor_ptr->m_list[target_ptr->riding], 0);
                        msg_format("You have fallen from %s.", m_name);
 #endif
                }
@@ -1300,19 +1261,19 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        if ((m_ptr->mflag2 & MFLAG2_CHAMELEON) && one_in_(13) && !MON_CSLEEP(m_ptr))
        {
-               choose_new_monster(m_idx, FALSE, 0);
+               choose_new_monster(target_ptr, m_idx, FALSE, 0);
                r_ptr = &r_info[m_ptr->r_idx];
        }
 
        /* Players hidden in shadow are almost imperceptable. -LM- */
        if (target_ptr->special_defense & NINJA_S_STEALTH)
        {
-               int tmp = target_ptr->lev*6+(target_ptr->skill_stl+10)*4;
+               int tmp = target_ptr->lev * 6 + (target_ptr->skill_stl + 10) * 4;
                if (target_ptr->monlite) tmp /= 3;
                if (target_ptr->cursed & TRC_AGGRAVATE) tmp /= 2;
                if (r_ptr->level > (target_ptr->lev * target_ptr->lev / 20 + 10)) tmp /= 3;
                /* Low-level monsters will find it difficult to locate the player. */
-               if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
+               if (randint0(tmp) > (r_ptr->level + 20)) aware = FALSE;
        }
 
        /* Are there its parent? */
@@ -1323,18 +1284,18 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if (see_m)
                {
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, 0);
+                       monster_desc(target_ptr, m_name, m_ptr, 0);
                        msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
                }
 
                if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
                {
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
-                       exe_write_diary(target_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
+                       monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
+                       exe_write_diary(target_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
                }
 
-               delete_monster_idx(m_idx);
+               delete_monster_idx(target_ptr, m_idx);
 
                return;
        }
@@ -1346,52 +1307,76 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if (!randint0(2)) return;
 
                /* Sometimes die */
-               if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
+               if (!randint0((m_idx % 100) + 10))
                {
-                       bool sad = FALSE;
-
-                       if (is_pet(m_ptr) && !(m_ptr->ml)) sad = TRUE;
-
-                       if (see_m)
+                       if ((r_ptr->flags1 & RF1_UNIQUE) == 0)
                        {
-                               GAME_TEXT m_name[MAX_NLEN];
-                               monster_desc(m_name, m_ptr, 0);
+                               if (!(r_ptr->flags1 & RF1_QUESTOR))
+                               {
+                                       if (see_m)
+                                       {
+                                               GAME_TEXT m_name[MAX_NLEN];
+                                               monster_desc(target_ptr, m_name, m_ptr, 0);
+                                               msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
+                                       }
 
-                               msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
+                                       monster_death(target_ptr, m_idx, FALSE);
+                                       delete_monster_idx(target_ptr, m_idx);
+                                       if (is_pet(m_ptr) && !(m_ptr->ml))
+                                       {
+                                               msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
+                                       }
+
+                                       return;
+                               }
                        }
+                       else
+                       {
+                               if (see_m)
+                               {
+                                       GAME_TEXT m_name[MAX_NLEN];
+                                       monster_desc(target_ptr, m_name, m_ptr, 0);
+                                       msg_format(_("%sは量子的効果を起こした!", "%^s produced a quantum effect!"), m_name);
+                               }
+                               else
+                               {
+                                       msg_print(_("量子的効果が起こった!", "A quantum effect was produced!"));
+                               }
 
-                       /* Generate treasure, etc */
-                       monster_death(m_idx, FALSE);
+                               bool target = one_in_(2);
+                               const int blink = 32 * 5 + 4;
+                               if (target)
+                               {
+                                       (void)monspell_to_monster(target_ptr, blink, m_ptr->fy, m_ptr->fx, m_idx, m_idx);
 
-                       delete_monster_idx(m_idx);
-                       if (sad)
-                       {
-                               msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
+                               }
+                               else
+                               {
+                                       teleport_player_away(m_idx, target_ptr, 10, TRUE);
+                               }
                        }
-
-                       return;
                }
        }
 
        if (m_ptr->r_idx == MON_SHURYUUDAN)
        {
-               mon_take_hit_mon(m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
-               if(dead) return;
+               mon_take_hit_mon(target_ptr, m_idx, 1, &dead, &fear, _("は爆発して粉々になった。", " explodes into tiny shreds."), m_idx);
+               if (dead) return;
        }
 
        if ((is_pet(m_ptr) || is_friendly(m_ptr)) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && !target_ptr->phase_out)
        {
                static int riding_pinch = 0;
 
-               if (m_ptr->hp < m_ptr->maxhp/3)
+               if (m_ptr->hp < m_ptr->maxhp / 3)
                {
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, 0);
+                       monster_desc(target_ptr, m_name, m_ptr, 0);
 
                        if (is_riding_mon && riding_pinch < 2)
                        {
                                msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
-                                                        "%^s seems to be in so much pain and trying to escape from your restriction."), m_name);
+                                       "%^s seems to be in so much pain and tries to escape from your restriction."), m_name);
                                riding_pinch++;
                                disturb(target_ptr, TRUE, TRUE);
                        }
@@ -1402,14 +1387,14 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                        msg_format(_("%sはあなたの束縛から脱出した。", "%^s succeeded to escape from your restriction!"), m_name);
                                        if (rakuba(target_ptr, -1, FALSE))
                                        {
-                                               msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
+                                               msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
                                        }
                                }
 
                                if (see_m)
                                {
                                        if ((r_ptr->flags2 & RF2_CAN_SPEAK) && (m_ptr->r_idx != MON_GRIP) && (m_ptr->r_idx != MON_WOLF) && (m_ptr->r_idx != MON_FANG) &&
-                                           player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x))
+                                               player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x))
                                        {
                                                msg_format(_("%^s「ピンチだ!退却させてもらう!」", "%^s says 'It is the pinch! I will retreat'."), m_name);
                                        }
@@ -1419,11 +1404,11 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                                if (is_riding_mon && rakuba(target_ptr, -1, FALSE))
                                {
-                                       msg_print(_("地面に落とされた。", "You have fallen from riding pet."));
+                                       msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
                                }
 
                                check_quest_completion(target_ptr, m_ptr);
-                               delete_monster_idx(m_idx);
+                               delete_monster_idx(target_ptr, m_idx);
                                return;
                        }
                }
@@ -1440,18 +1425,18 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                /* Handle non-aggravation - Still sleeping */
                if (!(target_ptr->cursed & TRC_AGGRAVATE)) return;
 
-               (void)set_monster_csleep(m_idx, 0);
+               (void)set_monster_csleep(target_ptr, m_idx, 0);
 
                /* Notice the "waking up" */
                if (m_ptr->ml)
                {
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, 0);
+                       monster_desc(target_ptr, m_name, m_ptr, 0);
                        msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
                }
 
                /* Hack -- Count the wakings */
-               if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
+               if (is_original_ap_and_seen(target_ptr, m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
                {
                        r_ptr->r_wake++;
                }
@@ -1475,7 +1460,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        /* Paranoia... no pet uniques outside wizard mode -- TY */
        if (is_pet(m_ptr) && ((((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) &&
-             monster_has_hostile_align(NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
+               monster_has_hostile_align(target_ptr, NULL, 10, -10, r_ptr)) || (r_ptr->flagsr & RFR_RES_ALL)))
        {
                gets_angry = TRUE;
        }
@@ -1487,11 +1472,11 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if (is_pet(m_ptr) || see_m)
                {
                        GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
+                       monster_desc(target_ptr, m_name, m_ptr, is_pet(m_ptr) ? MD_ASSUME_VISIBLE : 0);
                        msg_format(_("%^sは突然敵にまわった!", "%^s suddenly becomes hostile!"), m_name);
                }
 
-               set_hostile(m_ptr);
+               set_hostile(target_ptr, m_ptr);
        }
 
        /* Get the origin */
@@ -1521,10 +1506,10 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
                {
                        /* Try to multiply */
-                       if (multiply_monster(m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
+                       if (multiply_monster(target_ptr, m_idx, FALSE, (is_pet(m_ptr) ? PM_FORCE_PET : 0)))
                        {
                                /* Take note if visible */
-                               if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(m_ptr))
+                               if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml && is_original_ap_and_seen(target_ptr, m_ptr))
                                {
                                        r_ptr->r_flags2 |= (RF2_MULTIPLY);
                                }
@@ -1550,13 +1535,13 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                                        for (k = 0; k < A_MAX; k++)
                                        {
-                                               if (summon_specific(m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
+                                               if (summon_specific(target_ptr, m_idx, m_ptr->fy, m_ptr->fx, rlev, SUMMON_MOLD, (PM_ALLOW_GROUP | p_mode)))
                                                {
                                                        if (target_ptr->current_floor_ptr->m_list[hack_m_idx_ii].ml) count++;
                                                }
                                        }
 
-                                       if (count && is_original_ap_and_seen(m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
+                                       if (count && is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags6 |= (RF6_SPECIAL);
                                }
                        }
                }
@@ -1566,8 +1551,8 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
        {
                /* Hack! "Cyber" monster makes noise... */
                if (m_ptr->ap_r_idx == MON_CYBER &&
-                   one_in_(CYBERNOISE) &&
-                   !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
+                       one_in_(CYBERNOISE) &&
+                       !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
                {
                        if (disturb_minor) disturb(target_ptr, FALSE, FALSE);
                        msg_print(_("重厚な足音が聞こえた。", "You hear heavy steps."));
@@ -1575,9 +1560,9 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                /* Some monsters can speak */
                if ((ap_r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
-                   one_in_(SPEAK_CHANCE) &&
-                   player_has_los_bold(target_ptr, oy, ox) &&
-                   projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
+                       one_in_(SPEAK_CHANCE) &&
+                       player_has_los_bold(target_ptr, oy, ox) &&
+                       projectable(target_ptr, oy, ox, target_ptr->y, target_ptr->x))
                {
                        GAME_TEXT m_name[MAX_NLEN];
                        char monmessage[1024];
@@ -1585,7 +1570,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                        /* Acquire the monster name/poss */
                        if (m_ptr->ml)
-                               monster_desc(m_name, m_ptr, 0);
+                               monster_desc(target_ptr, m_name, m_ptr, 0);
                        else
                                strcpy(m_name, _("それ", "It"));
 
@@ -1618,8 +1603,8 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        MONSTER_IDX t_m_idx = target_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
 
                        /* The monster must be an enemy, and projectable */
-                       if (t_m_idx && are_enemies(m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
-                           projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
+                       if (t_m_idx && are_enemies(target_ptr, m_ptr, &target_ptr->current_floor_ptr->m_list[t_m_idx]) &&
+                               projectable(target_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
                        {
                                counterattack = TRUE;
                        }
@@ -1659,10 +1644,10 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        /* 75% random movement */
        else if (((r_ptr->flags1 & (RF1_RAND_50 | RF1_RAND_25)) == (RF1_RAND_50 | RF1_RAND_25)) &&
-                (randint0(100) < 75))
+               (randint0(100) < 75))
        {
                /* Memorize flags */
-               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
+               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50 | RF1_RAND_25);
 
                /* Try four "random" directions */
                mm[0] = mm[1] = mm[2] = mm[3] = 5;
@@ -1670,10 +1655,10 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        /* 50% random movement */
        else if ((r_ptr->flags1 & RF1_RAND_50) &&
-                               (randint0(100) < 50))
+               (randint0(100) < 50))
        {
                /* Memorize flags */
-               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
+               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_RAND_50);
 
                /* Try four "random" directions */
                mm[0] = mm[1] = mm[2] = mm[3] = 5;
@@ -1681,10 +1666,10 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
        /* 25% random movement */
        else if ((r_ptr->flags1 & RF1_RAND_25) &&
-                               (randint0(100) < 25))
+               (randint0(100) < 25))
        {
                /* Memorize flags */
-               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
+               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= RF1_RAND_25;
 
                /* Try four "random" directions */
                mm[0] = mm[1] = mm[2] = mm[3] = 5;
@@ -1695,11 +1680,6 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
        {
                /* Try four "random" directions */
                mm[0] = mm[1] = mm[2] = mm[3] = 5;
-
-               /* Look for an enemy */
-#if 0  /* Hack - Too slow.  Mimic pits are horrible with this on. */
-               get_enemy_dir(m_idx, mm);
-#endif /* 0 */
        }
 
        /* Pets will follow the player */
@@ -1791,7 +1771,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                /* Access that grid */
                g_ptr = &target_ptr->current_floor_ptr->grid_array[ny][nx];
                f_ptr = &f_info[g_ptr->feat];
-               can_cross = monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
+               can_cross = monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0);
 
                /* Access that grid's contents */
                y_ptr = &target_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
@@ -1810,9 +1790,9 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                /* Monster destroys walls (and doors) */
                else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
-                        (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
-                        have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
-                        check_hp_for_feat_destruction(f_ptr, m_ptr))
+                       (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
+                       have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
+                       check_hp_for_feat_destruction(f_ptr, m_ptr))
                {
                        /* Eat through walls/doors/rubble */
                        do_move = TRUE;
@@ -1830,7 +1810,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                        /* Monster moves through walls (and doors) */
                        if ((r_ptr->flags2 & RF2_PASS_WALL) && (!is_riding_mon || target_ptr->pass_wall) &&
-                           have_flag(f_ptr->flags, FF_CAN_PASS))
+                               have_flag(f_ptr->flags, FF_CAN_PASS))
                        {
                                /* Monster went through a wall */
                                did_pass_wall = TRUE;
@@ -1838,7 +1818,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                }
 
                /* Handle doors and secret doors */
-               else if (is_closed_door(g_ptr->feat))
+               else if (is_closed_door(target_ptr, g_ptr->feat))
                {
                        bool may_bash = TRUE;
 
@@ -1847,7 +1827,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                        /* Creature can open doors. */
                        if ((r_ptr->flags2 & RF2_OPEN_DOOR) && have_flag(f_ptr->flags, FF_OPEN) &&
-                                (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
+                               (!is_pet(m_ptr) || (target_ptr->pet_extra_flags & PF_OPEN_DOORS)))
                        {
                                /* Closed doors */
                                if (!f_ptr->power)
@@ -1886,7 +1866,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
                                {
                                        if (have_flag(f_ptr->flags, FF_GLASS))
-                                               msg_print(_("ガラスが砕ける音がした!", "You hear a glass was crashed!"));
+                                               msg_print(_("ガラスが砕ける音がした!", "You hear glass breaking!"));
                                        else
                                                msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
 
@@ -1907,7 +1887,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        if (did_open_door || did_bash_door)
                        {
                                /* Break down the door */
-                               if (did_bash_door && ((randint0(100) < 50) || (feat_state(g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
+                               if (did_bash_door && ((randint0(100) < 50) || (feat_state(target_ptr, g_ptr->feat, FF_OPEN) == g_ptr->feat) || have_flag(f_ptr->flags, FF_GLASS)))
                                {
                                        cave_alter_feat(target_ptr, ny, nx, FF_BASH);
 
@@ -1915,7 +1895,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                        {
                                                target_ptr->update |= (PU_FLOW);
                                                target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-                                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
+                                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_BASH_DOOR);
 
                                                return;
                                        }
@@ -1936,7 +1916,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                /* Hack -- check for Glyph of Warding */
                if (do_move && is_glyph_grid(g_ptr) &&
-                   !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
+                       !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
                {
                        /* Assume no move allowed */
                        do_move = FALSE;
@@ -1960,11 +1940,11 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                /* Allow movement */
                                do_move = TRUE;
 
-                               note_spot(ny, nx);
+                               note_spot(target_ptr, ny, nx);
                        }
                }
                else if (do_move && is_explosive_rune_grid(g_ptr) &&
-                        !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
+                       !((r_ptr->flags1 & RF1_NEVER_BLOW) && player_bold(target_ptr, ny, nx)))
                {
                        /* Assume no move allowed */
                        do_move = FALSE;
@@ -1994,8 +1974,8 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                g_ptr->info &= ~(CAVE_OBJECT);
                                g_ptr->mimic = 0;
 
-                               note_spot(ny, nx);
-                               lite_spot(ny, nx);
+                               note_spot(target_ptr, ny, nx);
+                               lite_spot(target_ptr, ny, nx);
 
                                if (!monster_is_valid(m_ptr)) return;
                                /* Allow movement */
@@ -2010,7 +1990,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        if (r_ptr->flags1 & RF1_NEVER_BLOW)
                        {
                                /* Hack -- memorize lack of attacks */
-                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
+                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_BLOW);
 
                                /* Do not move */
                                do_move = FALSE;
@@ -2024,7 +2004,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                        if (!(r_ptr->flags2 & RF2_STUPID)) do_move = FALSE;
                                        else
                                        {
-                                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
+                                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
                                        }
                                }
                        }
@@ -2056,15 +2036,15 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                        /* Attack 'enemies' */
                        if (((r_ptr->flags2 & RF2_KILL_BODY) && !(r_ptr->flags1 & RF1_NEVER_BLOW) &&
-                                (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
-                                can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
-                               are_enemies(m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
+                               (r_ptr->mexp * r_ptr->level > z_ptr->mexp * z_ptr->level) &&
+                               can_cross && (g_ptr->m_idx != target_ptr->riding)) ||
+                               are_enemies(target_ptr, m_ptr, y_ptr) || MON_CONFUSED(m_ptr))
                        {
                                if (!(r_ptr->flags1 & RF1_NEVER_BLOW))
                                {
                                        if (r_ptr->flags2 & RF2_KILL_BODY)
                                        {
-                                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
+                                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_BODY);
                                        }
 
                                        /* attack */
@@ -2078,7 +2058,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                                        if (MON_CONFUSED(m_ptr)) return;
                                                        else if (r_ptr->flags2 & RF2_STUPID)
                                                        {
-                                                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
+                                                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_STUPID);
                                                                return;
                                                        }
                                                }
@@ -2090,7 +2070,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        else if ((r_ptr->flags2 & RF2_MOVE_BODY) && !(r_ptr->flags1 & RF1_NEVER_MOVE) &&
                                (r_ptr->mexp > z_ptr->mexp) &&
                                can_cross && (g_ptr->m_idx != target_ptr->riding) &&
-                               monster_can_cross_terrain(target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
+                               monster_can_cross_terrain(target_ptr, target_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].feat, z_ptr, 0))
                        {
                                /* Allow movement */
                                do_move = TRUE;
@@ -2099,7 +2079,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                did_move_body = TRUE;
 
                                /* Wake up the moved monster */
-                               (void)set_monster_csleep(g_ptr->m_idx, 0);
+                               (void)set_monster_csleep(target_ptr, g_ptr->m_idx, 0);
 
                                /* Message */
                        }
@@ -2126,7 +2106,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                        {
                                target_ptr->update |= (PU_FLOW);
                                target_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-                               if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
+                               if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags2 |= (RF2_KILL_WALL);
 
                                return;
                        }
@@ -2140,7 +2120,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
 
                if (must_alter_to_move && (r_ptr->flags7 & RF7_AQUATIC))
                {
-                       if (!monster_can_cross_terrain(g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
+                       if (!monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, is_riding_mon ? CEM_RIDING : 0))
                        {
                                /* Assume no move allowed */
                                do_move = FALSE;
@@ -2163,194 +2143,203 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if (do_move && (r_ptr->flags1 & RF1_NEVER_MOVE))
                {
                        /* Hack -- memorize lack of moves */
-                       if (is_original_ap_and_seen(m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
+                       if (is_original_ap_and_seen(target_ptr, m_ptr)) r_ptr->r_flags1 |= (RF1_NEVER_MOVE);
 
                        /* Do not move */
                        do_move = FALSE;
                }
 
                /* Creature has been allowed move */
-               if (do_move)
+               if (!do_move)
                {
-                       do_turn = TRUE;
+                       if (do_turn) break;
+                       continue;
+               }
+
+               do_turn = TRUE;
 
-                       if (have_flag(f_ptr->flags, FF_TREE))
+               if (have_flag(f_ptr->flags, FF_TREE))
+               {
+                       if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
                        {
-                               if (!(r_ptr->flags7 & RF7_CAN_FLY) && !(r_ptr->flags8 & RF8_WILD_WOOD))
-                               {
-                                       m_ptr->energy_need += ENERGY_NEED();
-                               }
+                               m_ptr->energy_need += ENERGY_NEED();
                        }
+               }
+
+               if (!is_riding_mon)
+               {
+                       /* Hack -- Update the old location */
+                       target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
 
-                       if (!is_riding_mon)
+                       /* Mega-Hack -- move the old monster, if any */
+                       if (g_ptr->m_idx)
                        {
-                               /* Hack -- Update the old location */
-                               target_ptr->current_floor_ptr->grid_array[oy][ox].m_idx = g_ptr->m_idx;
+                               /* Move the old monster */
+                               y_ptr->fy = oy;
+                               y_ptr->fx = ox;
 
-                               /* Mega-Hack -- move the old monster, if any */
-                               if (g_ptr->m_idx)
-                               {
-                                       /* Move the old monster */
-                                       y_ptr->fy = oy;
-                                       y_ptr->fx = ox;
+                               /* Update the old monster */
+                               update_monster(target_ptr, g_ptr->m_idx, TRUE);
+                       }
 
-                                       /* Update the old monster */
-                                       update_monster(target_ptr, g_ptr->m_idx, TRUE);
-                               }
+                       /* Hack -- Update the new location */
+                       g_ptr->m_idx = m_idx;
+
+                       /* Move the monster */
+                       m_ptr->fy = ny;
+                       m_ptr->fx = nx;
+                       update_monster(target_ptr, m_idx, TRUE);
+
+                       lite_spot(target_ptr, oy, ox);
+                       lite_spot(target_ptr, ny, nx);
+               }
+               else
+               {
+                       /* sound(SOUND_WALK); */
+                       if (!move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP)) break;
+               }
 
-                               /* Hack -- Update the new location */
-                               g_ptr->m_idx = m_idx;
+               /* Possible disturb */
+               if (m_ptr->ml &&
+                       (disturb_move ||
+                       (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
+                               (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
+               {
+                       if (is_hostile(m_ptr))
+                               disturb(target_ptr, FALSE, TRUE);
+               }
 
-                               /* Move the monster */
-                               m_ptr->fy = ny;
-                               m_ptr->fx = nx;
-                               update_monster(target_ptr, m_idx, TRUE);
+               /* Take or Kill objects on the floor */
+               bool is_takable_or_killable = g_ptr->o_idx > 0;
+               is_takable_or_killable &= (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) != 0;
+               bool is_pickup_items = (target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) != 0;
+               is_pickup_items &= (r_ptr->flags2 & RF2_TAKE_ITEM) != 0;
+               is_takable_or_killable &= !is_pet(m_ptr) || is_pickup_items;
+               if (!is_takable_or_killable)
+               {
+                       if (do_turn) break;
+                       continue;
+               }
 
-                               lite_spot(oy, ox);
-                               lite_spot(ny, nx);
-                       }
-                       else
-                       {
-                               /* sound(SOUND_WALK); */
-                               if (!move_player_effect(target_ptr, ny, nx, MPE_DONT_PICKUP)) break;
-                       }
+               OBJECT_IDX this_o_idx, next_o_idx;
+               bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
 
-                       /* Possible disturb */
-                       if (m_ptr->ml &&
-                           (disturb_move ||
-                            (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(target_ptr, target_ptr->y, target_ptr->x, m_ptr->fy, m_ptr->fx)) ||
-                            (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= target_ptr->lev)))
+               /* Scan all objects in the grid */
+               for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+               {
+                       BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
+                       GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
+                       object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
+                       next_o_idx = o_ptr->next_o_idx;
+
+                       if (do_take)
                        {
-                               if (is_hostile(m_ptr))
-                                       disturb(target_ptr, FALSE, TRUE);
+                               /* Skip gold */
+                               if (o_ptr->tval == TV_GOLD) continue;
+
+                               /*
+                                * Skip "real" corpses and statues, to avoid extreme
+                                * silliness like a novice rogue pockets full of statues
+                                * and corpses.
+                                */
+                               if ((o_ptr->tval == TV_CORPSE) ||
+                                       (o_ptr->tval == TV_STATUE)) continue;
                        }
 
-                       /* Take or Kill objects on the floor */
-                       if (g_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
-                           (!is_pet(m_ptr) || ((target_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
+                       /* Extract some flags */
+                       object_flags(o_ptr, flgs);
+
+                       /* Acquire the object name */
+                       object_desc(target_ptr, o_name, o_ptr, 0);
+                       monster_desc(target_ptr, m_name, m_ptr, MD_INDEF_HIDDEN);
+
+                       /* React to objects that hurt the monster */
+                       if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
+                       if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
+                       if (have_flag(flgs, TR_SLAY_TROLL))  flg3 |= (RF3_TROLL);
+                       if (have_flag(flgs, TR_KILL_TROLL))  flg3 |= (RF3_TROLL);
+                       if (have_flag(flgs, TR_SLAY_GIANT))  flg3 |= (RF3_GIANT);
+                       if (have_flag(flgs, TR_KILL_GIANT))  flg3 |= (RF3_GIANT);
+                       if (have_flag(flgs, TR_SLAY_ORC))    flg3 |= (RF3_ORC);
+                       if (have_flag(flgs, TR_KILL_ORC))    flg3 |= (RF3_ORC);
+                       if (have_flag(flgs, TR_SLAY_DEMON))  flg3 |= (RF3_DEMON);
+                       if (have_flag(flgs, TR_KILL_DEMON))  flg3 |= (RF3_DEMON);
+                       if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
+                       if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
+                       if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
+                       if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
+                       if (have_flag(flgs, TR_SLAY_EVIL))   flg3 |= (RF3_EVIL);
+                       if (have_flag(flgs, TR_KILL_EVIL))   flg3 |= (RF3_EVIL);
+                       if (have_flag(flgs, TR_SLAY_HUMAN))  flg2 |= (RF2_HUMAN);
+                       if (have_flag(flgs, TR_KILL_HUMAN))  flg2 |= (RF2_HUMAN);
+                       if (have_flag(flgs, TR_BRAND_ACID))  flgr |= (RFR_IM_ACID);
+                       if (have_flag(flgs, TR_BRAND_ELEC))  flgr |= (RFR_IM_ELEC);
+                       if (have_flag(flgs, TR_BRAND_FIRE))  flgr |= (RFR_IM_FIRE);
+                       if (have_flag(flgs, TR_BRAND_COLD))  flgr |= (RFR_IM_COLD);
+                       if (have_flag(flgs, TR_BRAND_POIS))  flgr |= (RFR_IM_POIS);
+
+                       /* The object cannot be picked up by the monster */
+                       if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
+                               ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
                        {
-                               OBJECT_IDX this_o_idx, next_o_idx;
-                               bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
-
-                               /* Scan all objects in the grid */
-                               for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+                               /* Only give a message for "take_item" */
+                               if (do_take && (r_ptr->flags2 & RF2_STUPID))
                                {
-                                       BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
-                                       GAME_TEXT m_name[MAX_NLEN], o_name[MAX_NLEN];
-                                       object_type *o_ptr = &target_ptr->current_floor_ptr->o_list[this_o_idx];
-                                       next_o_idx = o_ptr->next_o_idx;
-
-                                       if (do_take)
-                                       {
-                                               /* Skip gold */
-                                               if (o_ptr->tval == TV_GOLD) continue;
-
-                                               /*
-                                                * Skip "real" corpses and statues, to avoid extreme
-                                                * silliness like a novice rogue pockets full of statues
-                                                * and corpses.
-                                                */
-                                               if ((o_ptr->tval == TV_CORPSE) ||
-                                                   (o_ptr->tval == TV_STATUE)) continue;
-                                       }
+                                       did_take_item = TRUE;
 
-                                       /* Extract some flags */
-                                       object_flags(o_ptr, flgs);
-
-                                       /* Acquire the object name */
-                                       object_desc(o_name, o_ptr, 0);
-                                       monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
-
-                                       /* React to objects that hurt the monster */
-                                       if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
-                                       if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
-                                       if (have_flag(flgs, TR_SLAY_TROLL))  flg3 |= (RF3_TROLL);
-                                       if (have_flag(flgs, TR_KILL_TROLL))  flg3 |= (RF3_TROLL);
-                                       if (have_flag(flgs, TR_SLAY_GIANT))  flg3 |= (RF3_GIANT);
-                                       if (have_flag(flgs, TR_KILL_GIANT))  flg3 |= (RF3_GIANT);
-                                       if (have_flag(flgs, TR_SLAY_ORC))    flg3 |= (RF3_ORC);
-                                       if (have_flag(flgs, TR_KILL_ORC))    flg3 |= (RF3_ORC);
-                                       if (have_flag(flgs, TR_SLAY_DEMON))  flg3 |= (RF3_DEMON);
-                                       if (have_flag(flgs, TR_KILL_DEMON))  flg3 |= (RF3_DEMON);
-                                       if (have_flag(flgs, TR_SLAY_UNDEAD)) flg3 |= (RF3_UNDEAD);
-                                       if (have_flag(flgs, TR_KILL_UNDEAD)) flg3 |= (RF3_UNDEAD);
-                                       if (have_flag(flgs, TR_SLAY_ANIMAL)) flg3 |= (RF3_ANIMAL);
-                                       if (have_flag(flgs, TR_KILL_ANIMAL)) flg3 |= (RF3_ANIMAL);
-                                       if (have_flag(flgs, TR_SLAY_EVIL))   flg3 |= (RF3_EVIL);
-                                       if (have_flag(flgs, TR_KILL_EVIL))   flg3 |= (RF3_EVIL);
-                                       if (have_flag(flgs, TR_SLAY_HUMAN))  flg2 |= (RF2_HUMAN);
-                                       if (have_flag(flgs, TR_KILL_HUMAN))  flg2 |= (RF2_HUMAN);
-                                       if (have_flag(flgs, TR_BRAND_ACID))  flgr |= (RFR_IM_ACID);
-                                       if (have_flag(flgs, TR_BRAND_ELEC))  flgr |= (RFR_IM_ELEC);
-                                       if (have_flag(flgs, TR_BRAND_FIRE))  flgr |= (RFR_IM_FIRE);
-                                       if (have_flag(flgs, TR_BRAND_COLD))  flgr |= (RFR_IM_COLD);
-                                       if (have_flag(flgs, TR_BRAND_POIS))  flgr |= (RFR_IM_POIS);
-
-                                       /* The object cannot be picked up by the monster */
-                                       if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
-                                           ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
+                                       /* Describe observable situations */
+                                       if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
                                        {
-                                               /* Only give a message for "take_item" */
-                                               if (do_take && (r_ptr->flags2 & RF2_STUPID))
-                                               {
-                                                       did_take_item = TRUE;
-
-                                                       /* Describe observable situations */
-                                                       if (m_ptr->ml && player_can_see_bold(target_ptr, ny, nx))
-                                                       {
-                                                               msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
-                                                       }
-                                               }
+                                               msg_format(_("%^sは%sを拾おうとしたが、だめだった。", "%^s tries to pick up %s, but fails."), m_name, o_name);
                                        }
+                               }
+                       }
 
-                                       /* Pick up the item */
-                                       else if (do_take)
-                                       {
-                                               did_take_item = TRUE;
-
-                                               /* Describe observable situations */
-                                               if (player_can_see_bold(target_ptr, ny, nx))
-                                               {
-                                                       msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
-                                               }
+                       /* Pick up the item */
+                       else if (do_take)
+                       {
+                               did_take_item = TRUE;
 
-                                               /* Excise the object */
-                                               excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
+                               /* Describe observable situations */
+                               if (player_can_see_bold(target_ptr, ny, nx))
+                               {
+                                       msg_format(_("%^sが%sを拾った。", "%^s picks up %s."), m_name, o_name);
+                               }
 
-                                               /* Forget mark */
-                                               o_ptr->marked &= OM_TOUCHED;
+                               /* Excise the object */
+                               excise_object_idx(target_ptr->current_floor_ptr, this_o_idx);
 
-                                               /* Forget location */
-                                               o_ptr->iy = o_ptr->ix = 0;
+                               /* Forget mark */
+                               o_ptr->marked &= OM_TOUCHED;
 
-                                               /* Memorize monster */
-                                               o_ptr->held_m_idx = m_idx;
+                               /* Forget location */
+                               o_ptr->iy = o_ptr->ix = 0;
 
-                                               /* Build a stack */
-                                               o_ptr->next_o_idx = m_ptr->hold_o_idx;
+                               /* Memorize monster */
+                               o_ptr->held_m_idx = m_idx;
 
-                                               /* Carry object */
-                                               m_ptr->hold_o_idx = this_o_idx;
-                                       }
+                               /* Build a stack */
+                               o_ptr->next_o_idx = m_ptr->hold_o_idx;
 
-                                       /* Destroy the item if not a pet */
-                                       else if (!is_pet(m_ptr))
-                                       {
-                                               did_kill_item = TRUE;
+                               /* Carry object */
+                               m_ptr->hold_o_idx = this_o_idx;
+                       }
 
-                                               /* Describe observable situations */
-                                               if (player_has_los_bold(target_ptr, ny, nx))
-                                               {
-                                                       msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
-                                               }
+                       /* Destroy the item if not a pet */
+                       else if (!is_pet(m_ptr))
+                       {
+                               did_kill_item = TRUE;
 
-                                               delete_object_idx(target_ptr->current_floor_ptr, this_o_idx);
-                                       }
+                               /* Describe observable situations */
+                               if (player_has_los_bold(target_ptr, ny, nx))
+                               {
+                                       msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
                                }
+
+                               delete_object_idx(target_ptr, this_o_idx);
                        }
                }
 
-               /* Stop when done */
                if (do_turn) break;
        }
 
@@ -2358,7 +2347,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
         *  Forward movements failed, but now received LOS attack!
         *  Try to flow by smell.
         */
-       if (target_ptr->no_flowed && i > 2 &&  m_ptr->target_y)
+       if (target_ptr->no_flowed && i > 2 && m_ptr->target_y)
                m_ptr->mflag2 &= ~MFLAG2_NOFLOW;
 
        /* If we haven't done anything, try casting a spell again */
@@ -2371,7 +2360,6 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                }
        }
 
-
        /* Notice changes in view */
        if (do_view)
        {
@@ -2387,7 +2375,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
        }
 
        /* Learn things from observable monster */
-       if (is_original_ap_and_seen(m_ptr))
+       if (is_original_ap_and_seen(target_ptr, m_ptr))
        {
                /* Monster opened a door */
                if (did_open_door) r_ptr->r_flags2 |= (RF2_OPEN_DOOR);
@@ -2411,25 +2399,21 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                if (did_kill_wall) r_ptr->r_flags2 |= (RF2_KILL_WALL);
        }
 
+       bool is_battle_determined = !do_turn && !do_move && MON_MONFEAR(m_ptr) && aware;
+       if (!is_battle_determined) return;
 
-       /* Hack -- get "bold" if out of options */
-       if (!do_turn && !do_move && MON_MONFEAR(m_ptr) && aware)
-       {
-               /* No longer afraid */
-               (void)set_monster_monfear(m_idx, 0);
+       /* No longer afraid */
+       (void)set_monster_monfear(target_ptr, m_idx, 0);
 
-               /* Message if seen */
-               if (see_m)
-               {
-                       GAME_TEXT m_name[MAX_NLEN];
-                       monster_desc(m_name, m_ptr, 0);
-                       msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
-               }
-
-               if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
-
-               /* Actually do something now (?) */
+       /* Message if seen */
+       if (see_m)
+       {
+               GAME_TEXT m_name[MAX_NLEN];
+               monster_desc(target_ptr, m_name, m_ptr, 0);
+               msg_format(_("%^sは戦いを決意した!", "%^s turns to fight!"), m_name);
        }
+
+       if (m_ptr->ml) chg_virtue(target_ptr, V_COMPASSION, -1);
 }
 
 /*!
@@ -2468,16 +2452,6 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
  */
 void process_monsters(player_type *target_ptr)
 {
-       MONSTER_IDX i;
-       POSITION fx, fy;
-
-       bool            test;
-
-       monster_type    *m_ptr;
-       monster_race    *r_ptr;
-
-       MONRACE_IDX old_monster_race_idx;
-
        BIT_FLAGS old_r_flags1 = 0L;
        BIT_FLAGS old_r_flags2 = 0L;
        BIT_FLAGS old_r_flags3 = 0L;
@@ -2491,21 +2465,19 @@ void process_monsters(player_type *target_ptr)
        byte old_r_blows2 = 0;
        byte old_r_blows3 = 0;
 
-       byte old_r_cast_spell = 0;
-
-       SPEED speed;
-
        /* Clear monster fighting indicator */
        floor_type *floor_ptr = target_ptr->current_floor_ptr;
        floor_ptr->monster_noise = FALSE;
 
        /* Memorize old race */
-       old_monster_race_idx = target_ptr->monster_race_idx;
+       MONRACE_IDX old_monster_race_idx = target_ptr->monster_race_idx;
 
        /* Acquire knowledge */
+       byte old_r_cast_spell = 0;
        if (target_ptr->monster_race_idx)
        {
                /* Acquire current monster */
+               monster_race *r_ptr;
                r_ptr = &r_info[target_ptr->monster_race_idx];
 
                /* Memorize flags */
@@ -2527,10 +2499,12 @@ void process_monsters(player_type *target_ptr)
                old_r_cast_spell = r_ptr->r_cast_spell;
        }
 
-
        /* Process the monsters (backwards) */
-       for (i = floor_ptr->m_max - 1; i >= 1; i--)
+       bool test;
+       for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--)
        {
+               monster_type *m_ptr;
+               monster_race *r_ptr;
                m_ptr = &floor_ptr->m_list[i];
                r_ptr = &r_info[m_ptr->r_idx];
 
@@ -2556,8 +2530,8 @@ void process_monsters(player_type *target_ptr)
                /* Hack -- Require proximity */
                if (m_ptr->cdis >= AAF_LIMIT) continue;
 
-               fx = m_ptr->fx;
-               fy = m_ptr->fy;
+               POSITION fx = m_ptr->fx;
+               POSITION fy = m_ptr->fy;
 
                /* Flow by smell is allowed */
                if (!target_ptr->no_flowed)
@@ -2576,32 +2550,19 @@ void process_monsters(player_type *target_ptr)
                }
 
                /* Handle "sight" and "aggravation" */
-        else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
+               else if ((m_ptr->cdis <= MAX_SIGHT || target_ptr->phase_out) &&
                        (player_has_los_bold(target_ptr, fy, fx) || (target_ptr->cursed & TRC_AGGRAVATE)))
                {
                        /* We can "see" or "feel" the player */
                        test = TRUE;
                }
 
-#if 0 /* (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when == floor_ptr->grid_array[fy][fx].when) is always FALSE... */
-               /* Hack -- Monsters can "smell" the player from far away */
-               /* Note that most monsters have "aaf" of "20" or so */
-               else if (!(m_ptr->mflag2 & MFLAG2_NOFLOW) &&
-                       cave_have_flag_bold(target_ptr->y, target_ptr->x, FF_MOVE) &&
-                       (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when == floor_ptr->grid_array[fy][fx].when) &&
-                       (floor_ptr->grid_array[fy][fx].dist < MONSTER_FLOW_DEPTH) &&
-                       (floor_ptr->grid_array[fy][fx].dist < r_ptr->aaf))
-               {
-                       /* We can "smell" the player */
-                       test = TRUE;
-               }
-#endif
                else if (m_ptr->target_y) test = TRUE;
 
                /* Do nothing */
                if (!test) continue;
 
-
+               SPEED speed;
                if (target_ptr->riding == i)
                        speed = target_ptr->pspeed;
                else
@@ -2652,6 +2613,7 @@ void process_monsters(player_type *target_ptr)
                return;
 
        /* Acquire monster race */
+       monster_race *r_ptr;
        r_ptr = &r_info[target_ptr->monster_race_idx];
 
        /* Check for knowledge change */
@@ -2671,4 +2633,3 @@ void process_monsters(player_type *target_ptr)
                target_ptr->window |= (PW_MONSTER);
        }
 }
-