OSDN Git Service

[Refactor] #38997 are_enemies()にplayer_type * 引数を追加 / Added player_type * argument...
[hengband/hengband.git] / src / mspells2.c
index bd3460c..3f02451 100644 (file)
 #include "world.h"
 #include "view-mainwindow.h"
 
-/*!
- * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
- * Determine if a beam spell will hit the target.
- * @param y1 始点のY座標
- * @param x1 始点のX座標
- * @param y2 目標のY座標
- * @param x2 目標のX座標
- * @param m_ptr 使用するモンスターの構造体参照ポインタ
- * @return ビームが到達可能ならばTRUEを返す
- */
-static bool direct_beam(POSITION y1, POSITION x1, POSITION y2, POSITION x2, monster_type *m_ptr)
+ /*!
+  * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
+  * Determine if a beam spell will hit the target.
+  * @param target_ptr プレーヤーへの参照ポインタ
+  * @param y1 始点のY座標
+  * @param x1 始点のX座標
+  * @param y2 目標のY座標
+  * @param x2 目標のX座標
+  * @param m_ptr 使用するモンスターの構造体参照ポインタ
+  * @return ビームが到達可能ならばTRUEを返す
+  */
+static bool direct_beam(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, monster_type *m_ptr)
 {
-       bool hit2 = FALSE;
-       int i;
-       POSITION y, x;
-
-       int grid_n = 0;
-       u16b grid_g[512];
-
-       bool is_friend = is_pet(m_ptr);
-
        /* Check the projection path */
-       grid_n = project_path(p_ptr->current_floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, PROJECT_THRU);
+       floor_type *floor_ptr = target_ptr->current_floor_ptr;
+       u16b grid_g[512];
+       int grid_n = project_path(target_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, PROJECT_THRU);
 
        /* No grid is ever projectable from itself */
        if (!grid_n) return FALSE;
 
-       for (i = 0; i < grid_n; i++)
+       bool hit2 = FALSE;
+       POSITION y, x;
+       bool is_friend = is_pet(m_ptr);
+       for (int i = 0; i < grid_n; i++)
        {
                y = GRID_Y(grid_g[i]);
                x = GRID_X(grid_g[i]);
 
                if (y == y2 && x == x2)
                        hit2 = TRUE;
-               else if (is_friend && p_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0 &&
-                        !are_enemies(m_ptr, &p_ptr->current_floor_ptr->m_list[p_ptr->current_floor_ptr->grid_array[y][x].m_idx]))
+               else if (is_friend && floor_ptr->grid_array[y][x].m_idx > 0 &&
+                       !are_enemies(target_ptr, m_ptr, &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx]))
                {
                        /* Friends don't shoot friends */
                        return FALSE;
                }
 
-               if (is_friend && player_bold(p_ptr, y, x))
+               if (is_friend && player_bold(target_ptr, y, x))
                        return FALSE;
        }
-       if (!hit2)
-               return FALSE;
+
+       if (!hit2) return FALSE;
        return TRUE;
 }
 
@@ -93,27 +90,7 @@ static bool direct_beam(POSITION y1, POSITION x1, POSITION y2, POSITION x2, mons
  */
 static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, POSITION rad, EFFECT_ID typ, bool is_friend)
 {
-       /* Must be the same as projectable() */
-
-       int i;
-
-       /* Initial grid */
-       POSITION y = y1;
-       POSITION x = x1;
-
-       int grid_n = 0;
-       u16b grid_g[512];
-
-       int grids = 0;
-       POSITION gx[1024], gy[1024];
-       POSITION gm[32];
-       POSITION gm_rad = rad;
-
-       bool hit2 = FALSE;
-       bool hityou = FALSE;
-
        BIT_FLAGS flg;
-
        switch (typ)
        {
        case GF_LITE:
@@ -129,9 +106,13 @@ static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POS
        }
 
        /* Check the projection path */
-       grid_n = project_path(master_ptr->current_floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, flg);
+       u16b grid_g[512];
+       int grid_n = project_path(master_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, flg);
 
        /* Project along the path */
+       int i;
+       POSITION y = y1;
+       POSITION x = x1;
        for (i = 0; i < grid_n; ++i)
        {
                int ny = GRID_Y(grid_g[i]);
@@ -160,6 +141,8 @@ static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POS
 
        grid_n = i;
 
+       bool hit2 = FALSE;
+       bool hityou = FALSE;
        if (!grid_n)
        {
                if (flg & PROJECT_DISI)
@@ -169,18 +152,22 @@ static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POS
                }
                else if (flg & PROJECT_LOS)
                {
-                       if (los(master_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (los(master_ptr->current_floor_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad)) hityou = TRUE;
+                       if (los(master_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
+                       if (los(master_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad)) hityou = TRUE;
                }
                else
                {
-                       if (projectable(master_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (projectable(master_ptr->current_floor_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad)) hityou = TRUE;
+                       if (projectable(master_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
+                       if (projectable(master_ptr, y1, x1, master_ptr->y, master_ptr->x) && (distance(y1, x1, master_ptr->y, master_ptr->x) <= rad)) hityou = TRUE;
                }
        }
        else
        {
-               breath_shape(master_ptr->current_floor_ptr, grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
+               int grids = 0;
+               POSITION gx[1024], gy[1024];
+               POSITION gm[32];
+               POSITION gm_rad = rad;
+               breath_shape(master_ptr, grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
 
                for (i = 0; i < grids; i++)
                {
@@ -201,6 +188,7 @@ static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POS
 /*!
  * @brief モンスターが特殊能力の目標地点を決める処理 /
  * Get the actual center point of ball spells (rad > 1) (originally from TOband)
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param sy 始点のY座標
  * @param sx 始点のX座標
  * @param ty 目標Y座標を返す参照ポインタ
@@ -208,24 +196,22 @@ static bool breath_direct(player_type *master_ptr, POSITION y1, POSITION x1, POS
  * @param flg 判定のフラグ配列
  * @return なし
  */
-void get_project_point(floor_type *floor_ptr, POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
+void get_project_point(player_type *target_ptr, POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
 {
        u16b path_g[128];
-       int  path_n, i;
-
-       path_n = project_path(floor_ptr, path_g, MAX_RANGE, sy, sx, *ty, *tx, flg);
+       int path_n = project_path(target_ptr, path_g, MAX_RANGE, sy, sx, *ty, *tx, flg);
 
        *ty = sy;
        *tx = sx;
 
        /* Project along the path */
-       for (i = 0; i < path_n; i++)
+       for (int i = 0; i < path_n; i++)
        {
                sy = GRID_Y(path_g[i]);
                sx = GRID_X(path_g[i]);
 
                /* Hack -- Balls explode before reaching walls */
-               if (!cave_have_flag_bold(floor_ptr, sy, sx, FF_PROJECT)) break;
+               if (!cave_have_flag_bold(target_ptr->current_floor_ptr, sy, sx, FF_PROJECT)) break;
 
                *ty = sy;
                *tx = sx;
@@ -236,26 +222,20 @@ void get_project_point(floor_type *floor_ptr, POSITION sy, POSITION sx, POSITION
 /*!
  * @brief モンスターが敵モンスターに魔力消去を使うかどうかを返す /
  * Check should monster cast dispel spell at other monster.
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx 術者のモンスターID
  * @param t_idx 目標のモンスターID
  * @return 魔力消去を使うべきならばTRUEを変えす。
  */
-static bool dispel_check_monster(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
+static bool dispel_check_monster(player_type *target_ptr, MONSTER_IDX m_idx, MONSTER_IDX t_idx)
 {
-       monster_type *t_ptr = &p_ptr->current_floor_ptr->m_list[t_idx];
-
+       monster_type *t_ptr = &target_ptr->current_floor_ptr->m_list[t_idx];
        if (MON_INVULNER(t_ptr)) return TRUE;
 
-       if (t_ptr->mspeed < 135)
-       {
-               if (MON_FAST(t_ptr)) return TRUE;
-       }
+       if ((t_ptr->mspeed < 135) && MON_FAST(t_ptr)) return TRUE;
 
        /* Riding monster */
-       if (t_idx == p_ptr->riding)
-       {
-               if (dispel_check(p_ptr, m_idx)) return TRUE;
-       }
+       if ((t_idx == target_ptr->riding) && dispel_check(target_ptr, m_idx)) return TRUE;
 
        /* No need to cast dispel spell */
        return FALSE;
@@ -275,7 +255,7 @@ static bool dispel_check_monster(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
 bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 {
        POSITION y = 0, x = 0;
-       int i, k;
+       int k;
        MONSTER_IDX target_idx = 0;
        int thrown_spell;
        HIT_POINT dam = 0;
@@ -287,7 +267,9 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        GAME_TEXT m_name[160];
        GAME_TEXT t_name[160];
 
-#ifndef JP
+#ifdef JP
+#else
+
        char m_poss[160];
 #endif
 
@@ -297,8 +279,6 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
-       u32b f4, f5, f6;
-
        bool see_m = is_seen(m_ptr);
        bool maneable = player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx);
        bool pet = is_pet(m_ptr);
@@ -313,9 +293,9 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        if (MON_CONFUSED(m_ptr)) return FALSE;
 
        /* Extract the racial spell flags */
-       f4 = r_ptr->flags4;
-       f5 = r_ptr->a_ability_flags1;
-       f6 = r_ptr->a_ability_flags2;
+       BIT_FLAGS f4 = r_ptr->flags4;
+       BIT_FLAGS f5 = r_ptr->a_ability_flags1;
+       BIT_FLAGS f6 = r_ptr->a_ability_flags2;
 
        /* Target is given for pet? */
        if (target_ptr->pet_t_m_idx && pet)
@@ -324,7 +304,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                t_ptr = &floor_ptr->m_list[target_idx];
 
                /* Cancel if not projectable (for now) */
-               if ((m_idx == target_idx) || !projectable(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+               if ((m_idx == target_idx) || !projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                {
                        target_idx = 0;
                }
@@ -341,13 +321,13 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 
                        /* Cancel if neither enemy nor a given target */
                        if ((m_idx == target_idx) ||
-                           ((target_idx != target_ptr->pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
+                               ((target_idx != target_ptr->pet_t_m_idx) && !are_enemies(target_ptr, m_ptr, t_ptr)))
                        {
                                target_idx = 0;
                        }
 
                        /* Allow only summoning etc.. if not projectable */
-                       else if (!projectable(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+                       else if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                        {
                                f4 &= (RF4_INDIRECT_MASK);
                                f5 &= (RF5_INDIRECT_MASK);
@@ -363,13 +343,13 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 
                if (target_ptr->phase_out)
                {
-                       start = randint1(floor_ptr->m_max-1) + floor_ptr->m_max;
+                       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;
@@ -380,10 +360,10 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                        if (!monster_is_valid(t_ptr)) continue;
 
                        /* Monster must be 'an enemy' */
-                       if ((m_idx == target_idx) || !are_enemies(m_ptr, t_ptr)) continue;
+                       if ((m_idx == target_idx) || !are_enemies(target_ptr, m_ptr, t_ptr)) continue;
 
                        /* Monster must be projectable */
-                       if (!projectable(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
+                       if (!projectable(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
 
                        /* Get it */
                        success = TRUE;
@@ -393,7 +373,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                /* No enemy found */
                if (!success) return FALSE;
        }
-       
+
        /* OK -- we've got a target */
        y = t_ptr->fy;
        x = t_ptr->fx;
@@ -406,7 +386,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 
        if (f4 & RF4_BR_LITE)
        {
-               if (!los(floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+               if (!los(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                        f4 &= ~(RF4_BR_LITE);
        }
 
@@ -422,8 +402,8 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                bool vs_ninja = (target_ptr->pclass == CLASS_NINJA) && !is_hostile(t_ptr);
 
                if (vs_ninja &&
-                   !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
-                   !(r_ptr->flags7 & RF7_DARK_MASK))
+                       !(r_ptr->flags3 & (RF3_UNDEAD | RF3_HURT_LITE)) &&
+                       !(r_ptr->flags7 & RF7_DARK_MASK))
                        can_use_lite_area = TRUE;
 
                if (!(r_ptr->flags2 & RF2_STUPID))
@@ -489,15 +469,15 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                if (!(target_ptr->pet_extra_flags & PF_BALL_SPELL) && (m_idx != target_ptr->riding))
                {
                        if ((f4 & (RF4_BALL_MASK & ~(RF4_ROCKET))) ||
-                           (f5 & RF5_BALL_MASK) ||
-                           (f6 & RF6_BALL_MASK))
+                               (f5 & RF5_BALL_MASK) ||
+                               (f6 & RF6_BALL_MASK))
                        {
                                POSITION real_y = y;
                                POSITION real_x = x;
 
-                               get_project_point(floor_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
+                               get_project_point(target_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
 
-                               if (projectable(floor_ptr, real_y, real_x, target_ptr->y, target_ptr->x))
+                               if (projectable(target_ptr, real_y, real_x, target_ptr->y, target_ptr->x))
                                {
                                        int dist = distance(real_y, real_x, target_ptr->y, target_ptr->x);
 
@@ -516,7 +496,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                                }
                                else if (f5 & RF5_BA_LITE)
                                {
-                                       if ((distance(real_y, real_x, target_ptr->y, target_ptr->x) <= 4) && los(floor_ptr, real_y, real_x, target_ptr->y, target_ptr->x))
+                                       if ((distance(real_y, real_x, target_ptr->y, target_ptr->x) <= 4) && los(target_ptr, real_y, real_x, target_ptr->y, target_ptr->x))
                                                f5 &= ~(RF5_BA_LITE);
                                }
                        }
@@ -526,13 +506,13 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                                POSITION real_y = y;
                                POSITION real_x = x;
 
-                               get_project_point(floor_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
-                               if (projectable(floor_ptr, real_y, real_x, target_ptr->y, target_ptr->x) && (distance(real_y, real_x, target_ptr->y, target_ptr->x) <= 2))
+                               get_project_point(target_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
+                               if (projectable(target_ptr, real_y, real_x, target_ptr->y, target_ptr->x) && (distance(real_y, real_x, target_ptr->y, target_ptr->x) <= 2))
                                        f4 &= ~(RF4_ROCKET);
                        }
 
                        if (((f4 & RF4_BEAM_MASK) || (f5 & RF5_BEAM_MASK) || (f6 & RF6_BEAM_MASK)) &&
-                           !direct_beam(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, m_ptr))
+                               !direct_beam(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, m_ptr))
                        {
                                f4 &= ~(RF4_BEAM_MASK);
                                f5 &= ~(RF5_BEAM_MASK);
@@ -551,12 +531,12 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                                        f6 &= ~(RF6_BREATH_MASK);
                                }
                                else if ((f4 & RF4_BR_LITE) &&
-                                        !breath_direct(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_LITE, TRUE))
+                                       !breath_direct(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_LITE, TRUE))
                                {
                                        f4 &= ~(RF4_BR_LITE);
                                }
                                else if ((f4 & RF4_BR_DISI) &&
-                                        !breath_direct(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_DISINTEGRATE, TRUE))
+                                       !breath_direct(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_DISINTEGRATE, TRUE))
                                {
                                        f4 &= ~(RF4_BR_DISI);
                                }
@@ -586,9 +566,9 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        {
                /* Check for a clean bolt shot */
                if (((f4 & RF4_BOLT_MASK) ||
-                    (f5 & RF5_BOLT_MASK) ||
-                    (f6 & RF6_BOLT_MASK)) &&
-                   !clean_shot(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, pet))
+                       (f5 & RF5_BOLT_MASK) ||
+                       (f6 & RF6_BOLT_MASK)) &&
+                       !clean_shot(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, pet))
                {
                        f4 &= ~(RF4_BOLT_MASK);
                        f5 &= ~(RF5_BOLT_MASK);
@@ -597,9 +577,9 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
 
                /* Check for a possible summon */
                if (((f4 & RF4_SUMMON_MASK) ||
-                    (f5 & RF5_SUMMON_MASK) ||
-                    (f6 & RF6_SUMMON_MASK)) &&
-                   !(summon_possible(floor_ptr, t_ptr->fy, t_ptr->fx)))
+                       (f5 & RF5_SUMMON_MASK) ||
+                       (f6 & RF6_SUMMON_MASK)) &&
+                       !(summon_possible(target_ptr, t_ptr->fy, t_ptr->fx)))
                {
                        /* Remove summoning spells */
                        f4 &= ~(RF4_SUMMON_MASK);
@@ -608,14 +588,14 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                }
 
                /* Dispel magic */
-               if ((f4 & RF4_DISPEL) && !dispel_check_monster(m_idx, target_idx))
+               if ((f4 & RF4_DISPEL) && !dispel_check_monster(target_ptr, m_idx, target_idx))
                {
                        /* Remove dispel spell */
                        f4 &= ~(RF4_DISPEL);
                }
 
                /* Check for a possible raise dead */
-               if ((f6 & RF6_RAISE_DEAD) && !raise_possible(floor_ptr, m_ptr))
+               if ((f6 & RF6_RAISE_DEAD) && !raise_possible(target_ptr, m_ptr))
                {
                        /* Remove raise dead spell */
                        f6 &= ~(RF6_RAISE_DEAD);
@@ -624,7 +604,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                /* Special moves restriction */
                if (f6 & RF6_SPECIAL)
                {
-                       if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(floor_ptr, t_ptr->fy, t_ptr->fx))
+                       if ((m_ptr->r_idx == MON_ROLENTO) && !summon_possible(target_ptr, t_ptr->fy, t_ptr->fx))
                        {
                                f6 &= ~(RF6_SPECIAL);
                        }
@@ -635,7 +615,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        {
                /* Hack -- allow "desperate" spells */
                if ((m_ptr->hp < m_ptr->maxhp / 10) &&
-                   (randint0(100) < 50))
+                       (randint0(100) < 50))
                {
                        /* Require intelligent spells */
                        f4 &= (RF4_INT_MASK);
@@ -662,13 +642,13 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        /* Extract the "normal" spells */
        for (k = 0; k < 32; k++)
        {
-        if (f5 & (1L << k)) spell[num++] = k + RF5_SPELL_START;
+               if (f5 & (1L << k)) spell[num++] = k + RF5_SPELL_START;
        }
 
        /* Extract the "bizarre" spells */
        for (k = 0; k < 32; k++)
        {
-        if (f6 & (1L << k)) spell[num++] = k + RF6_SPELL_START;
+               if (f6 & (1L << k)) spell[num++] = k + RF6_SPELL_START;
        }
 
        /* No spells left */
@@ -681,15 +661,17 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        if (target_ptr->leaving) return FALSE;
 
        /* Get the monster name (or "it") */
-       monster_desc(m_name, m_ptr, 0x00);
+       monster_desc(target_ptr, m_name, m_ptr, 0x00);
+
+#ifdef JP
+#else
 
-#ifndef JP
        /* Get the monster possessive ("his"/"her"/"its") */
        monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
 #endif
 
        /* Get the target's name (or "it") */
-       monster_desc(t_name, t_ptr, 0x00);
+       monster_desc(target_ptr, t_name, t_ptr, 0x00);
 
        /* Choose a spell to cast */
        thrown_spell = spell[randint0(num)];
@@ -700,8 +682,8 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        if (!spell_is_inate(thrown_spell) && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2))))
        {
                disturb(target_ptr, TRUE, TRUE);
-               if (see_m) msg_format(_("%^sは呪文を唱えようとしたが失敗した。", 
-                                           "%^s tries to cast a spell, but fails."), m_name);
+               if (see_m) msg_format(_("%^sは呪文を唱えようとしたが失敗した。",
+                       "%^s tries to cast a spell, but fails."), m_name);
 
                return TRUE;
        }
@@ -709,60 +691,63 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
        /* Hex: Anti Magic Barrier */
        if (!spell_is_inate(thrown_spell) && magic_barrier(target_ptr, m_idx))
        {
-               if (see_m) msg_format(_("反魔法バリアが%^sの呪文をかき消した。", 
-                                           "Anti magic barrier cancels the spell which %^s casts."), m_name);
+               if (see_m) msg_format(_("反魔法バリアが%^sの呪文をかき消した。",
+                       "Anti magic barrier cancels the spell which %^s casts."), m_name);
                return TRUE;
        }
 
-       can_remember = is_original_ap_and_seen(m_ptr);
+       can_remember = is_original_ap_and_seen(target_ptr, m_ptr);
 
        dam = monspell_to_monster(target_ptr, thrown_spell, y, x, m_idx, target_idx);
        if (dam < 0) return FALSE;
 
-       if (m_ptr->ml && maneable && !current_world_ptr->timewalk_m_idx && !target_ptr->blind && (target_ptr->pclass == CLASS_IMITATOR))
+       bool is_special_magic = m_ptr->ml;
+       is_special_magic &= maneable;
+       is_special_magic &= current_world_ptr->timewalk_m_idx == 0;
+       is_special_magic &= !target_ptr->blind;
+       is_special_magic &= target_ptr->pclass == CLASS_IMITATOR;
+       is_special_magic &= thrown_spell != 167; /* Not RF6_SPECIAL */
+       if (is_special_magic)
        {
-               if (thrown_spell != 167) /* Not RF6_SPECIAL */
+               if (target_ptr->mane_num == MAX_MANE)
                {
-                       if (target_ptr->mane_num == MAX_MANE)
+                       target_ptr->mane_num--;
+                       for (int i = 0; i < target_ptr->mane_num - 1; i++)
                        {
-                               target_ptr->mane_num--;
-                               for (i = 0; i < target_ptr->mane_num - 1; i++)
-                               {
-                                       target_ptr->mane_spell[i] = target_ptr->mane_spell[i+1];
-                                       target_ptr->mane_dam[i] = target_ptr->mane_dam[i+1];
-                               }
+                               target_ptr->mane_spell[i] = target_ptr->mane_spell[i + 1];
+                               target_ptr->mane_dam[i] = target_ptr->mane_dam[i + 1];
                        }
+               }
 
-                       target_ptr->mane_spell[target_ptr->mane_num] = thrown_spell - RF4_SPELL_START;
-                       target_ptr->mane_dam[target_ptr->mane_num] = dam;
-                       target_ptr->mane_num++;
-                       target_ptr->new_mane = TRUE;
+               target_ptr->mane_spell[target_ptr->mane_num] = thrown_spell - RF4_SPELL_START;
+               target_ptr->mane_dam[target_ptr->mane_num] = dam;
+               target_ptr->mane_num++;
+               target_ptr->new_mane = TRUE;
 
-                       target_ptr->redraw |= (PR_IMITATION);
-               }
+               target_ptr->redraw |= PR_IMITATION;
        }
 
        /* Remember what the monster did, if we saw it */
        if (can_remember)
        {
                /* Inate spell */
-        if (thrown_spell < RF4_SPELL_START + RF4_SPELL_SIZE)
+               if (thrown_spell < RF4_SPELL_START + RF4_SPELL_SIZE)
                {
-            r_ptr->r_flags4 |= (1L << (thrown_spell - RF4_SPELL_START));
+                       r_ptr->r_flags4 |= (1L << (thrown_spell - RF4_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
 
                /* Bolt or Ball */
-        else if (thrown_spell < RF5_SPELL_START + RF5_SPELL_SIZE)
+               else if (thrown_spell < RF5_SPELL_START + RF5_SPELL_SIZE)
                {
-            r_ptr->r_flags5 |= (1L << (thrown_spell - RF5_SPELL_START));
+                       r_ptr->r_flags5 |= (1L << (thrown_spell - RF5_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
 
                /* Special spell */
-        else if (thrown_spell < RF6_SPELL_START + RF6_SPELL_SIZE)
+               else if (thrown_spell < RF6_SPELL_START + RF6_SPELL_SIZE)
                {
-            r_ptr->r_flags6 |= (1L << (thrown_spell - RF6_SPELL_START));
+                       r_ptr->r_flags6 |= (1L << (thrown_spell - RF6_SPELL_START));
                        if (r_ptr->r_cast_spell < MAX_UCHAR) r_ptr->r_cast_spell++;
                }
        }