OSDN Git Service

[Refactor] #38997 monspell_to_player() に player_type * 引数を追加. / Add player_type ...
[hengband/hengband.git] / src / mspells1.c
index 6f8511a..6a9145f 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+
+#include "floor.h"
+#include "dungeon.h"
+#include "grid.h"
+#include "object-curse.h"
+#include "quest.h"
+#include "realm-hex.h"
+#include "player-move.h"
+#include "player-status.h"
+#include "monster.h"
+#include "monster-spell.h"
+#include "spells.h"
+#include "world.h"
+#include "realm-song.h"
+#include "view-mainwindow.h"
+#include "player-race.h"
+#include "player-class.h"
 
 
 /*!
@@ -48,7 +66,7 @@
  * @param prob 基本確率(%)
  * @return 適した選択を取るならばTRUEを返す。
  */
-static bool int_outof(monster_race *r_ptr, int prob)
+static bool int_outof(monster_race *r_ptr, PERCENTAGE prob)
 {
        /* Non-Smart monsters are half as "smart" */
        if (!(r_ptr->flags2 & RF2_SMART)) prob = prob / 2;
@@ -67,9 +85,9 @@ static bool int_outof(monster_race *r_ptr, int prob)
  * @param f6p モンスター魔法のフラグリスト3
  * @return なし
  */
-static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
+static void remove_bad_spells(MONSTER_IDX m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 {
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        u32b f4 = (*f4p);
@@ -243,7 +261,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_RES_NETH))
        {
-               if (prace_is_(RACE_SPECTRE))
+               if (PRACE_IS_(p_ptr, RACE_SPECTRE))
                {
                        f4 &= ~(RF4_BR_NETH);
                        f5 &= ~(RF5_BA_NETH);
@@ -265,7 +283,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
 
        if (smart & (SM_RES_DARK))
        {
-               if (prace_is_(RACE_VAMPIRE))
+               if (PRACE_IS_(p_ptr, RACE_VAMPIRE))
                {
                        f4 &= ~(RF4_BR_DARK);
                        f5 &= ~(RF5_BA_DARK);
@@ -345,7 +363,7 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
                f5 &= ~(RF5_DRAIN_MANA);
        }
 
-       /* XXX XXX XXX No spells left? */
+       /* No spells left? */
        /* if (!f4 && !f5 && !f6) ... */
 
        (*f4p) = f4;
@@ -361,9 +379,9 @@ static void remove_bad_spells(int m_idx, u32b *f4p, u32b *f5p, u32b *f6p)
  * @param x1 判定を行いたいマスのX座標
  * @return 召還に相応しいならばTRUEを返す
  */
-bool summon_possible(int y1, int x1)
+bool summon_possible(POSITION y1, POSITION x1)
 {
-       int y, x;
+       POSITION y, x;
 
        /* Start at the player's location, and check 2 grids in each dir */
        for (y = y1 - 2; y <= y1 + 2; y++)
@@ -371,7 +389,7 @@ bool summon_possible(int y1, int x1)
                for (x = x1 - 2; x <= x1 + 2; x++)
                {
                        /* Ignore illegal locations */
-                       if (!in_bounds(y, x)) continue;
+                       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
 
                        /* Only check a circular area */
                        if (distance(y1, x1, y, x)>2) continue;
@@ -380,7 +398,7 @@ bool summon_possible(int y1, int x1)
                        if (pattern_tile(y, x)) continue;
 
                        /* Require empty floor grid in line of projection */
-                       if (cave_empty_bold(y, x) && projectable(y1, x1, y, x) && projectable(y, x, y1, x1)) return (TRUE);
+                       if (cave_empty_bold(p_ptr->current_floor_ptr, y, x) && projectable(p_ptr->current_floor_ptr, y1, x1, y, x) && projectable(p_ptr->current_floor_ptr, y, x, y1, x1)) return (TRUE);
                }
        }
 
@@ -396,28 +414,25 @@ bool summon_possible(int y1, int x1)
  */
 bool raise_possible(monster_type *m_ptr)
 {
-       int xx, yy;
-       int y = m_ptr->fy;
-       int x = m_ptr->fx;
-       s16b this_o_idx, next_o_idx = 0;
-       cave_type *c_ptr;
+       POSITION xx, yy;
+       POSITION y = m_ptr->fy;
+       POSITION x = m_ptr->fx;
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
+       grid_type *g_ptr;
 
        for (xx = x - 5; xx <= x + 5; xx++)
        {
                for (yy = y - 5; yy <= y + 5; yy++)
                {
                        if (distance(y, x, yy, xx) > 5) continue;
-                       if (!los(y, x, yy, xx)) continue;
-                       if (!projectable(y, x, yy, xx)) continue;
+                       if (!los(p_ptr->current_floor_ptr, y, x, yy, xx)) continue;
+                       if (!projectable(p_ptr->current_floor_ptr, y, x, yy, xx)) continue;
 
-                       c_ptr = &cave[yy][xx];
+                       g_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
                        /* Scan the pile of objects */
-                       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                        {
-                               /* Acquire object */
-                               object_type *o_ptr = &o_list[this_o_idx];
-
-                               /* Acquire next object */
+                               object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                                next_o_idx = o_ptr->next_o_idx;
 
                                /* Known to be worthless? */
@@ -452,11 +467,12 @@ bool raise_possible(monster_type *m_ptr)
  * no equally friendly monster is\n
  * between the attacker and target.\n
  */
-bool clean_shot(int y1, int x1, int y2, int x2, bool is_friend)
+bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
 {
        /* Must be the same as projectable() */
 
-       int i, y, x;
+       int i;
+       POSITION y, x;
 
        int grid_n = 0;
        u16b grid_g[512];
@@ -479,16 +495,16 @@ bool clean_shot(int y1, int x1, int y2, int x2, bool is_friend)
                y = GRID_Y(grid_g[i]);
                x = GRID_X(grid_g[i]);
 
-               if ((cave[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
+               if ((p_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
                {
-                       monster_type *m_ptr = &m_list[cave[y][x].m_idx];
+                       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[p_ptr->current_floor_ptr->grid_array[y][x].m_idx];
                        if (is_friend == is_pet(m_ptr))
                        {
                                return (FALSE);
                        }
                }
                /* Pets may not shoot through the character - TNB */
-               if (player_bold(y, x))
+               if (player_bold(p_ptr, y, x))
                {
                        if (is_friend) return (FALSE);
                }
@@ -509,9 +525,9 @@ bool clean_shot(int y1, int x1, int y2, int x2, bool is_friend)
  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
  * @return なし
  */
-void bolt(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target_type)
+void bolt(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp, int monspell, int target_type)
   {
-    int flg;
+    BIT_FLAGS flg = 0;
     bool learnable = spell_learnable(m_idx);
 
     switch (target_type)
@@ -526,7 +542,7 @@ void bolt(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target
        if (typ != GF_ARROW) flg  |= PROJECT_REFLECTABLE;
 
        /* Target the player with a bolt attack */
-       (void)project(m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
+       (void)project(p_ptr, m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
 }
 
 /*!
@@ -540,9 +556,9 @@ void bolt(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target
  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
  * @return なし
  */
-void beam(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target_type)
+void beam(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp, int monspell, int target_type)
 {
-    int flg;
+    BIT_FLAGS flg = 0;
     bool learnable = spell_learnable(m_idx);
 
     switch (target_type)
@@ -556,7 +572,7 @@ void beam(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target
     }
 
        /* Target the player with a bolt attack */
-       (void)project(m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
+       (void)project(p_ptr, m_idx, 0, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
 }
 
 
@@ -569,17 +585,17 @@ void beam(int m_idx, int y, int x, int typ, int dam_hp, int monspell, int target
  * @param typ 効果属性ID
  * @param dam_hp 威力
  * @param rad 半径
- * @param breath TRUEならばブ・E構萢・.ALSEならばボー・E萢
+ * @param breath 
  * @param monspell モンスター魔法のID
  * @param target_type モンスターからモンスターへ撃つならMONSTER_TO_MONSTER、モンスターからプレイヤーならMONSTER_TO_PLAYER
  * @return なし
  */
-void breath(int y, int x, int m_idx, int typ, int dam_hp, int rad, bool breath, int monspell, int target_type)
+void breath(POSITION y, POSITION x, MONSTER_IDX m_idx, EFFECT_ID typ, int dam_hp, POSITION rad, bool breath, int monspell, int target_type)
 {
-    monster_type *m_ptr = &m_list[m_idx];
+    monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
     monster_race *r_ptr = &r_info[m_ptr->r_idx];
     bool learnable = spell_learnable(m_idx);
-       int flg = 0x00;
+       BIT_FLAGS flg = 0x00;
 
     switch (target_type)
     {
@@ -615,114 +631,10 @@ void breath(int y, int x, int m_idx, int typ, int dam_hp, int rad, bool breath,
        }
 
        /* Target the player with a ball attack */
-       (void)project(m_idx, rad, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
+       (void)project(p_ptr, m_idx, rad, y, x, dam_hp, typ, flg, (learnable ? monspell : -1));
 }
 
-/*!
- * @brief モンスターのボール型&ブレス型魔法処理 /
- * @param power 呪いの段階
- * @param o_ptr 呪いをかけられる装備オブジェクトの構造体参照ポインタ
- * @return 与える呪いのID
- */
-u32b get_curse(int power, object_type *o_ptr)
-{
-       u32b new_curse;
-
-       while(1)
-       {
-               new_curse = (1 << (randint0(MAX_CURSE)+4));
-               if (power == 2)
-               {
-                       if (!(new_curse & TRC_HEAVY_MASK)) continue;
-               }
-               else if (power == 1)
-               {
-                       if (new_curse & TRC_SPECIAL_MASK) continue;
-               }
-               else if (power == 0)
-               {
-                       if (new_curse & TRC_HEAVY_MASK) continue;
-               }
-               if (new_curse == TRC_LOW_MELEE && !object_is_weapon(o_ptr)) continue;
-               if (new_curse == TRC_LOW_AC && !object_is_armour(o_ptr)) continue;
-               break;
-       }
-       return new_curse;
-}
-
-/*!
- * @brief 装備への呪い付加判定と付加処理 /
- * @param chance 呪いの基本確率
- * @param heavy_chance 重い呪いを選択肢に入れるか否か。
- * @return なし
- */
-void curse_equipment(int chance, int heavy_chance)
-{
-       bool        changed = FALSE;
-       int         curse_power = 0;
-       u32b        new_curse;
-       u32b oflgs[TR_FLAG_SIZE];
-       object_type *o_ptr = &inventory[INVEN_RARM + randint0(12)];
-       char o_name[MAX_NLEN];
-
-       if (randint1(100) > chance) return;
 
-       if (!o_ptr->k_idx) return;
-
-       object_flags(o_ptr, oflgs);
-
-       object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
-
-       /* Extra, biased saving throw for blessed items */
-       if (have_flag(oflgs, TR_BLESSED) && (randint1(888) > chance))
-       {
-#ifdef JP
-msg_format("%sは呪いを跳ね返した!", o_name,
-#else
-               msg_format("Your %s resist%s cursing!", o_name,
-#endif
-
-                       ((o_ptr->number > 1) ? "" : "s"));
-               /* Hmmm -- can we wear multiple items? If not, this is unnecessary */
-               return;
-       }
-
-       if ((randint1(100) <= heavy_chance) &&
-           (object_is_artifact(o_ptr) || object_is_ego(o_ptr)))
-       {
-               if (!(o_ptr->curse_flags & TRC_HEAVY_CURSE))
-                       changed = TRUE;
-               o_ptr->curse_flags |= TRC_HEAVY_CURSE;
-               o_ptr->curse_flags |= TRC_CURSED;
-               curse_power++;
-       }
-       else
-       {
-               if (!object_is_cursed(o_ptr))
-                       changed = TRUE;
-               o_ptr->curse_flags |= TRC_CURSED;
-       }
-       if (heavy_chance >= 50) curse_power++;
-
-       new_curse = get_curse(curse_power, o_ptr);
-       if (!(o_ptr->curse_flags & new_curse))
-       {
-               changed = TRUE;
-               o_ptr->curse_flags |= new_curse;
-       }
-
-       if (changed)
-       {
-#ifdef JP
-msg_format("悪意に満ちた黒いオーラが%sをとりまいた...", o_name);
-#else
-               msg_format("There is a malignant black aura surrounding %s...", o_name);
-#endif
-
-               o_ptr->feeling = FEEL_NONE;
-       }
-       p_ptr->update |= (PU_BONUS);
-}
 
 
 /*!
@@ -899,7 +811,7 @@ static bool spell_world(byte spell)
  */
 static bool spell_special(byte spell)
 {
-       if (p_ptr->inside_battle) return FALSE;
+       if (p_ptr->phase_out) return FALSE;
        if (spell == 160 + 7) return (TRUE);
        return (FALSE);
 }
@@ -959,9 +871,9 @@ static bool spell_dispel(byte spell)
  * @param m_idx モンスターの構造体配列ID
  * @return 魔力消去をかけるべきならTRUEを返す。
  */
-bool dispel_check(int m_idx)
+bool dispel_check(MONSTER_IDX m_idx)
 {
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        /* Invulnabilty (including the song) */
@@ -991,7 +903,7 @@ bool dispel_check(int m_idx)
        /* Elemental resistances */
        if (r_ptr->flags4 & RF4_BR_ACID)
        {
-               if (!p_ptr->immune_acid && (p_ptr->oppose_acid || music_singing(MUSIC_RESIST))) return (TRUE);
+               if (!p_ptr->immune_acid && (p_ptr->oppose_acid || music_singing(p_ptr, MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_ACID) return (TRUE);
        }
 
@@ -999,20 +911,20 @@ bool dispel_check(int m_idx)
        {
                if (!((p_ptr->prace == RACE_DEMON) && p_ptr->lev > 44))
                {
-                       if (!p_ptr->immune_fire && (p_ptr->oppose_fire || music_singing(MUSIC_RESIST))) return (TRUE);
+                       if (!p_ptr->immune_fire && (p_ptr->oppose_fire || music_singing(p_ptr, MUSIC_RESIST))) return (TRUE);
                        if (p_ptr->special_defense & DEFENSE_FIRE) return (TRUE);
                }
        }
 
        if (r_ptr->flags4 & RF4_BR_ELEC)
        {
-               if (!p_ptr->immune_elec && (p_ptr->oppose_elec || music_singing(MUSIC_RESIST))) return (TRUE);
+               if (!p_ptr->immune_elec && (p_ptr->oppose_elec || music_singing(p_ptr, MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_ELEC) return (TRUE);
        }
 
        if (r_ptr->flags4 & RF4_BR_COLD)
        {
-               if (!p_ptr->immune_cold && (p_ptr->oppose_cold || music_singing(MUSIC_RESIST))) return (TRUE);
+               if (!p_ptr->immune_cold && (p_ptr->oppose_cold || music_singing(p_ptr, MUSIC_RESIST))) return (TRUE);
                if (p_ptr->special_defense & DEFENSE_COLD) return (TRUE);
        }
 
@@ -1020,7 +932,7 @@ bool dispel_check(int m_idx)
        {
                if (!((p_ptr->pclass == CLASS_NINJA) && p_ptr->lev > 44))
                {
-                       if (p_ptr->oppose_pois || music_singing(MUSIC_RESIST)) return (TRUE);
+                       if (p_ptr->oppose_pois || music_singing(p_ptr, MUSIC_RESIST)) return (TRUE);
                        if (p_ptr->special_defense & DEFENSE_POIS) return (TRUE);
                }
        }
@@ -1038,7 +950,6 @@ bool dispel_check(int m_idx)
        if ((p_ptr->special_attack & ATTACK_COLD) && !(r_ptr->flagsr & RFR_EFF_IM_COLD_MASK)) return (TRUE);
        if ((p_ptr->special_attack & ATTACK_POIS) && !(r_ptr->flagsr & RFR_EFF_IM_POIS_MASK)) return (TRUE);
 
-       /* Speed */
        if (p_ptr->pspeed < 145)
        {
                if (IS_FAST()) return (TRUE);
@@ -1047,9 +958,9 @@ bool dispel_check(int m_idx)
        /* Light speed */
        if (p_ptr->lightspeed && (m_ptr->mspeed < 136)) return (TRUE);
 
-       if (p_ptr->riding && (m_list[p_ptr->riding].mspeed < 135))
+       if (p_ptr->riding && (p_ptr->current_floor_ptr->m_list[p_ptr->riding].mspeed < 135))
        {
-               if (MON_FAST(&m_list[p_ptr->riding])) return (TRUE);
+               if (MON_FAST(&p_ptr->current_floor_ptr->m_list[p_ptr->riding])) return (TRUE);
        }
 
        /* No need to cast dispel spell */
@@ -1076,9 +987,9 @@ bool dispel_check(int m_idx)
  *\n
  * This function may well be an efficiency bottleneck.\n
  */
-static int choose_attack_spell(int m_idx, byte spells[], byte num)
+static int choose_attack_spell(MONSTER_IDX m_idx, byte spells[], byte num)
 {
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        byte escape[96], escape_num = 0;
@@ -1150,7 +1061,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        /*** Try to pick an appropriate spell type ***/
 
        /* world */
-       if (world_num && (randint0(100) < 15) && !world_monster)
+       if (world_num && (randint0(100) < 15) && !current_world_ptr->timewalk_m_idx)
        {
                /* Choose haste spell */
                return (world[randint0(world_num)]);
@@ -1209,7 +1120,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        }
 
        /* Player is close and we have attack spells, blink away */
-       if ((distance(py, px, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->flags6 & RF6_TRAPS)) && (randint0(100) < 75) && !world_monster)
+       if ((distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx) < 4) && (attack_num || (r_ptr->a_ability_flags2 & RF6_TRAPS)) && (randint0(100) < 75) && !current_world_ptr->timewalk_m_idx)
        {
                /* Choose tactical spell */
                if (tactic_num) return (tactic[randint0(tactic_num)]);
@@ -1260,7 +1171,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
        }
 
        /* Try another tactical spell (sometimes) */
-       if (tactic_num && (randint0(100) < 50) && !world_monster)
+       if (tactic_num && (randint0(100) < 50) && !current_world_ptr->timewalk_m_idx)
        {
                /* Choose tactic spell */
                return (tactic[randint0(tactic_num)]);
@@ -1305,7 +1216,7 @@ static int choose_attack_spell(int m_idx, byte spells[], byte num)
  * @param spell 判定対象のID
  * @return 非魔術的な特殊技能ならばTRUEを返す。
  */
-bool spell_is_inate(u16b spell)
+bool spell_is_inate(SPELL_IDX spell)
 {
        if (spell < 32 * 4) /* Set RF4 */
        {
@@ -1334,8 +1245,8 @@ bool spell_is_inate(u16b spell)
  * @param path_check 射線を判定するための関数ポインタ
  * @return 有効な座標があった場合TRUEを返す
  */
-static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
-       int f_flag, bool (*path_check)(int, int, int, int))
+static bool adjacent_grid_check(monster_type *m_ptr, POSITION *yp, POSITION *xp,
+       int f_flag, bool (*path_check)(floor_type *, POSITION, POSITION, POSITION, POSITION))
 {
        int i;
        int tonari;
@@ -1348,24 +1259,24 @@ static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
                                             {-1,  0,  1, -1,  1, -1,  0,  1},
                                             { 1,  0, -1,  1, -1,  1,  0, -1}};
 
-       if (m_ptr->fy < py && m_ptr->fx < px) tonari = 0;
-       else if (m_ptr->fy < py) tonari = 1;
-       else if (m_ptr->fx < px) tonari = 2;
+       if (m_ptr->fy < p_ptr->y && m_ptr->fx < p_ptr->x) tonari = 0;
+       else if (m_ptr->fy < p_ptr->y) tonari = 1;
+       else if (m_ptr->fx < p_ptr->x) tonari = 2;
        else tonari = 3;
 
        for (i = 0; i < 8; i++)
        {
                int next_x = *xp + tonari_x[tonari][i];
                int next_y = *yp + tonari_y[tonari][i];
-               cave_type *c_ptr;
+               grid_type *g_ptr;
 
                /* Access the next grid */
-               c_ptr = &cave[next_y][next_x];
+               g_ptr = &p_ptr->current_floor_ptr->grid_array[next_y][next_x];
 
                /* Skip this feature */
-               if (!cave_have_flag_grid(c_ptr, f_flag)) continue;
+               if (!cave_have_flag_grid(g_ptr, f_flag)) continue;
 
-               if (path_check(m_ptr->fy, m_ptr->fx, next_y, next_x))
+               if (path_check(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, next_y, next_x))
                {
                        *yp = next_y;
                        *xp = next_x;
@@ -1389,12 +1300,12 @@ static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
  * @details
  * Returns "TRUE" if a spell (or whatever) was (successfully) cast.\n
  *\n
- * XXX XXX XXX This function could use some work, but remember to\n
+ * This function could use some work, but remember to\n
  * keep it as optimized as possible, while retaining generic code.\n
  *\n
  * Verify the various "blind-ness" checks in the code.\n
  *\n
- * XXX XXX XXX Note that several effects should really not be "seen"\n
+ * Note that several effects should really not be "seen"\n
  * if the player is blind.  See also "effects.c" for other "mistakes".\n
  *\n
  * Perhaps monsters should breathe at locations *near* the player,\n
@@ -1439,38 +1350,40 @@ static bool adjacent_grid_check(monster_type *m_ptr, int *yp, int *xp,
  * Note the special "MFLAG_NICE" flag, which prevents a monster from using\n
  * any spell attacks until the player has had a single chance to move.\n
  */
-bool make_attack_spell(int m_idx)
+bool make_attack_spell(MONSTER_IDX m_idx, player_type *target_ptr)
 {
-       int             k, thrown_spell = 0, rlev, failrate;
-       byte            spell[96], num = 0;
-       u32b            f4, f5, f6;
-       monster_type    *m_ptr = &m_list[m_idx];
-       monster_race    *r_ptr = &r_info[m_ptr->r_idx];
-       char            m_name[80];
+       int k;
+       SPELL_IDX thrown_spell = 0;
+       DEPTH rlev;
+       PERCENTAGE failrate;
+       byte spell[96], num = 0;
+       BIT_FLAGS f4, f5, f6;
+       monster_type *m_ptr = &target_ptr->current_floor_ptr->m_list[m_idx];
+       monster_race *r_ptr = &r_info[m_ptr->r_idx];
+       GAME_TEXT m_name[MAX_NLEN];
 #ifndef JP
-       char            m_poss[80];
+       char m_poss[80];
 #endif
        bool            no_inate = FALSE;
        bool            do_spell = DO_SPELL_NONE;
        int             dam = 0;
 
-       /* Target location */
-       int x = px;
-       int y = py;
+       POSITION x = target_ptr->x;
+       POSITION y = target_ptr->y;
 
        /* Target location for lite breath */
-       int x_br_lite = 0;
-       int y_br_lite = 0;
+       POSITION x_br_lite = 0;
+       POSITION y_br_lite = 0;
 
        /* Extract the "see-able-ness" */
-    bool seen = (!p_ptr->blind && m_ptr->ml);
-       bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
+    bool seen = (!target_ptr->blind && m_ptr->ml);
+       bool maneable = player_has_los_bold(target_ptr, m_ptr->fy, m_ptr->fx);
 
        /* Check "projectable" */
        bool direct;
 
-       bool in_no_magic_dungeon = (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && dun_level
-               && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
+       bool in_no_magic_dungeon = (d_info[target_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && target_ptr->current_floor_ptr->dun_level
+               && (!target_ptr->current_floor_ptr->inside_quest || is_fixed_quest_idx(target_ptr->current_floor_ptr->inside_quest));
 
        bool can_use_lite_area = FALSE;
 
@@ -1491,13 +1404,13 @@ bool make_attack_spell(int m_idx)
        /* Sometimes forbid inate attacks (breaths) */
        if (randint0(100) >= (r_ptr->freq_spell * 2)) no_inate = TRUE;
 
-       /* XXX XXX XXX Handle "track_target" option (?) */
+       /* Handle "track_target" option (?) */
 
 
        /* Extract the racial spell flags */
        f4 = r_ptr->flags4;
-       f5 = r_ptr->flags5;
-       f6 = r_ptr->flags6;
+       f5 = r_ptr->a_ability_flags1;
+       f6 = r_ptr->a_ability_flags2;
 
        /*** require projectable player ***/
 
@@ -1510,9 +1423,9 @@ bool make_attack_spell(int m_idx)
                y_br_lite = y;
                x_br_lite = x;
 
-               if (los(m_ptr->fy, m_ptr->fx, y_br_lite, x_br_lite))
+               if (los(target_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, y_br_lite, x_br_lite))
                {
-                       feature_type *f_ptr = &f_info[cave[y_br_lite][x_br_lite].feat];
+                       feature_type *f_ptr = &f_info[target_ptr->current_floor_ptr->grid_array[y_br_lite][x_br_lite].feat];
 
                        if (!have_flag(f_ptr->flags, FF_LOS))
                        {
@@ -1532,9 +1445,9 @@ bool make_attack_spell(int m_idx)
        }
 
        /* Check path */
-       if (projectable(m_ptr->fy, m_ptr->fx, y, x))
+       if (projectable(target_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, y, x))
        {
-               feature_type *f_ptr = &f_info[cave[y][x].feat];
+               feature_type *f_ptr = &f_info[target_ptr->current_floor_ptr->grid_array[y][x].feat];
 
                if (!have_flag(f_ptr->flags, FF_PROJECT))
                {
@@ -1553,22 +1466,22 @@ bool make_attack_spell(int m_idx)
 
                if ((f4 & RF4_BR_DISI) && (m_ptr->cdis < MAX_RANGE/2) &&
                    in_disintegration_range(m_ptr->fy, m_ptr->fx, y, x) &&
-                   (one_in_(10) || (projectable(y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
+                   (one_in_(10) || (projectable(target_ptr->current_floor_ptr, y, x, m_ptr->fy, m_ptr->fx) && one_in_(2))))
                {
                        do_spell = DO_SPELL_BR_DISI;
                        success = TRUE;
                }
                else if ((f4 & RF4_BR_LITE) && (m_ptr->cdis < MAX_RANGE/2) &&
-                   los(m_ptr->fy, m_ptr->fx, y, x) && one_in_(5))
+                   los(target_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, y, x) && one_in_(5))
                {
                        do_spell = DO_SPELL_BR_LITE;
                        success = TRUE;
                }
                else if ((f5 & RF5_BA_LITE) && (m_ptr->cdis <= MAX_RANGE))
                {
-                       int by = y, bx = x;
+                       POSITION by = y, bx = x;
                        get_project_point(m_ptr->fy, m_ptr->fx, &by, &bx, 0L);
-                       if ((distance(by, bx, y, x) <= 3) && los(by, bx, y, x) && one_in_(5))
+                       if ((distance(by, bx, y, x) <= 3) && los(target_ptr->current_floor_ptr, by, bx, y, x) && one_in_(5))
                        {
                                do_spell = DO_SPELL_BA_LITE;
                                success = TRUE;
@@ -1608,7 +1521,6 @@ bool make_attack_spell(int m_idx)
 
        reset_target(m_ptr);
 
-       /* Extract the monster level */
        rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
 
        /* Forbid inate attacks sometimes */
@@ -1621,15 +1533,15 @@ bool make_attack_spell(int m_idx)
 
        if (f6 & RF6_DARKNESS)
        {
-               if ((p_ptr->pclass == CLASS_NINJA) &&
+               if ((target_ptr->pclass == CLASS_NINJA) &&
                    !(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))
                {
-                       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
-                       else if ((p_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
+                       if (d_info[target_ptr->dungeon_idx].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
+                       else if ((target_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
                }
        }
 
@@ -1665,7 +1577,7 @@ bool make_attack_spell(int m_idx)
        /* Remove the "ineffective" spells */
        remove_bad_spells(m_idx, &f4, &f5, &f6);
 
-       if (p_ptr->inside_arena || p_ptr->inside_battle)
+       if (target_ptr->current_floor_ptr->inside_arena || target_ptr->phase_out)
        {
                f4 &= ~(RF4_SUMMON_MASK);
                f5 &= ~(RF5_SUMMON_MASK);
@@ -1679,13 +1591,13 @@ bool make_attack_spell(int m_idx)
 
        if (!(r_ptr->flags2 & RF2_STUPID))
        {
-               if (!p_ptr->csp) f5 &= ~(RF5_DRAIN_MANA);
+               if (!target_ptr->csp) f5 &= ~(RF5_DRAIN_MANA);
 
                /* Check for a clean bolt shot */
                if (((f4 & RF4_BOLT_MASK) ||
                     (f5 & RF5_BOLT_MASK) ||
                     (f6 & RF6_BOLT_MASK)) &&
-                   !clean_shot(m_ptr->fy, m_ptr->fx, py, px, FALSE))
+                   !clean_shot(m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x, FALSE))
                {
                        /* Remove spells that will only hurt friends */
                        f4 &= ~(RF4_BOLT_MASK);
@@ -1747,10 +1659,10 @@ bool make_attack_spell(int m_idx)
        if (!num) return (FALSE);
 
        /* Stop if player is dead or gone */
-       if (!p_ptr->playing || p_ptr->is_dead) return (FALSE);
+       if (!target_ptr->playing || target_ptr->is_dead) return (FALSE);
 
        /* Stop if player is leaving */
-       if (p_ptr->leaving) return (FALSE);
+       if (target_ptr->leaving) return (FALSE);
 
        /* Get the monster name (or "it") */
        monster_desc(m_name, m_ptr, 0x00);
@@ -1786,7 +1698,7 @@ bool make_attack_spell(int m_idx)
                break;
 
        default:
-               return FALSE; /* Paranoia */
+               return FALSE;
        }
 
        /* Abort if no spell was chosen */
@@ -1802,8 +1714,7 @@ bool make_attack_spell(int m_idx)
        if (!spell_is_inate(thrown_spell)
            && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2)) || (randint0(100) < failrate)))
        {
-               disturb(1, 1);
-               /* Message */
+               disturb(target_ptr, TRUE, TRUE);
                msg_format(_("%^sは呪文を唱えようとしたが失敗した。", "%^s tries to cast a spell, but fails."), m_name);
 
                return (TRUE);
@@ -1817,7 +1728,7 @@ bool make_attack_spell(int m_idx)
        }
 
        /* Projectable? */
-       direct = player_bold(y, x);
+       direct = player_bold(target_ptr, y, x);
 
        can_remember = is_original_ap_and_seen(m_ptr);
 
@@ -1861,34 +1772,34 @@ bool make_attack_spell(int m_idx)
     }
 
     /* Cast the spell. */
-    dam = monspell_to_player(thrown_spell, y, x, m_idx);
+    dam = monspell_to_player(thrown_spell, target_ptr, y, x, m_idx);
     if (dam < 0) return FALSE;
 
-       if ((p_ptr->action == ACTION_LEARN) && thrown_spell > 175)
+       if ((target_ptr->action == ACTION_LEARN) && thrown_spell > 175)
        {
                learn_spell(thrown_spell - 96);
        }
 
-       if (seen && maneable && !world_monster && (p_ptr->pclass == CLASS_IMITATOR))
+       if (seen && maneable && !current_world_ptr->timewalk_m_idx && (target_ptr->pclass == CLASS_IMITATOR))
        {
                if (thrown_spell != 167) /* Not RF6_SPECIAL */
                {
-                       if (p_ptr->mane_num == MAX_MANE)
+                       if (target_ptr->mane_num == MAX_MANE)
                        {
                                int i;
-                               p_ptr->mane_num--;
-                               for (i = 0;i < p_ptr->mane_num;i++)
+                               target_ptr->mane_num--;
+                               for (i = 0;i < target_ptr->mane_num;i++)
                                {
-                                       p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
-                                       p_ptr->mane_dam[i] = p_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];
                                }
                        }
-                       p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - 96;
-                       p_ptr->mane_dam[p_ptr->mane_num] = dam;
-                       p_ptr->mane_num++;
-                       new_mane = TRUE;
+                       target_ptr->mane_spell[target_ptr->mane_num] = thrown_spell - 96;
+                       target_ptr->mane_dam[target_ptr->mane_num] = dam;
+                       target_ptr->mane_num++;
+                       target_ptr->new_mane = TRUE;
 
-                       p_ptr->redraw |= (PR_IMITATION);
+                       target_ptr->redraw |= (PR_IMITATION);
                }
        }
 
@@ -1919,7 +1830,7 @@ bool make_attack_spell(int m_idx)
 
 
        /* Always take note of monsters that kill you */
-       if (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->inside_arena)
+       if (target_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !target_ptr->current_floor_ptr->inside_arena)
        {
                r_ptr->r_deaths++; /* Ignore appearance difference */
        }