OSDN Git Service

[Refactor] #38997 get_project_point() に floor_type * 引数を追加. / Add floor_type * argume...
[hengband/hengband.git] / src / mspells2.c
index c7f4b85..77d085d 100644 (file)
  */
 
 #include "angband.h"
-#include "projection.h"
+#include "util.h"
+
+#include "cmd-pet.h"
+#include "floor.h"
+#include "grid.h"
+#include "quest.h"
+#include "realm-hex.h"
+#include "player-move.h"
+#include "player-class.h"
+#include "monster.h"
+#include "monster-status.h"
+#include "monster-spell.h"
+#include "spells.h"
+#include "dungeon.h"
+#include "world.h"
+#include "view-mainwindow.h"
 
 /*!
  * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
  * @param m_ptr 使用するモンスターの構造体参照ポインタ
  * @return ビームが到達可能ならばTRUEを返す
  */
-static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
+static bool direct_beam(POSITION y1, POSITION x1, POSITION y2, POSITION x2, monster_type *m_ptr)
 {
        bool hit2 = FALSE;
-       int i, y, x;
+       int i;
+       POSITION y, x;
 
        int grid_n = 0;
        u16b grid_g[512];
@@ -35,7 +51,7 @@ static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
        bool is_friend = is_pet(m_ptr);
 
        /* Check the projection path */
-       grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, PROJECT_THRU);
+       grid_n = project_path(p_ptr->current_floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, PROJECT_THRU);
 
        /* No grid is ever projectable from itself */
        if (!grid_n) return (FALSE);
@@ -47,14 +63,14 @@ static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
 
                if (y == y2 && x == x2)
                        hit2 = TRUE;
-               else if (is_friend && cave[y][x].m_idx > 0 &&
-                        !are_enemies(m_ptr, &m_list[cave[y][x].m_idx]))
+               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]))
                {
                        /* Friends don't shoot friends */
                        return FALSE;
                }
 
-               if (is_friend && player_bold(y, x))
+               if (is_friend && player_bold(p_ptr, y, x))
                        return FALSE;
        }
        if (!hit2)
@@ -74,7 +90,7 @@ static bool direct_beam(int y1, int x1, int y2, int x2, monster_type *m_ptr)
  * @param is_friend TRUEならば、プレイヤーを巻き込む時にブレスの判定をFALSEにする。
  * @return ブレスを直接当てられるならばTRUEを返す
  */
-static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, POSITION rad, EFFECT_ID typ, bool is_friend)
+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() */
 
@@ -112,7 +128,7 @@ static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, PO
        }
 
        /* Check the projection path */
-       grid_n = project_path(grid_g, MAX_RANGE, y1, x1, y2, x2, flg);
+       grid_n = project_path(p_ptr->current_floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, flg);
 
        /* Project along the path */
        for (i = 0; i < grid_n; ++i)
@@ -123,17 +139,17 @@ static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, PO
                if (flg & PROJECT_DISI)
                {
                        /* Hack -- Balls explode before reaching walls */
-                       if (cave_stop_disintegration(ny, nx)) break;
+                       if (cave_stop_disintegration(master_ptr->current_floor_ptr, ny, nx)) break;
                }
                else if (flg & PROJECT_LOS)
                {
                        /* Hack -- Balls explode before reaching walls */
-                       if (!cave_los_bold(ny, nx)) break;
+                       if (!cave_los_bold(master_ptr->current_floor_ptr, ny, nx)) break;
                }
                else
                {
                        /* Hack -- Balls explode before reaching walls */
-                       if (!cave_have_flag_bold(ny, nx, FF_PROJECT)) break;
+                       if (!cave_have_flag_bold(master_ptr->current_floor_ptr, ny, nx, FF_PROJECT)) break;
                }
 
                /* Save the "blast epicenter" */
@@ -147,32 +163,30 @@ static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, PO
        {
                if (flg & PROJECT_DISI)
                {
-                       if (in_disintegration_range(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (in_disintegration_range(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
+                       if (in_disintegration_range(master_ptr->current_floor_ptr, y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
+                       if (in_disintegration_range(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;
                }
                else if (flg & PROJECT_LOS)
                {
-                       if (los(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (los(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
+                       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;
                }
                else
                {
-                       if (projectable(y1, x1, y2, x2) && (distance(y1, x1, y2, x2) <= rad)) hit2 = TRUE;
-                       if (projectable(y1, x1, p_ptr->y, p_ptr->x) && (distance(y1, x1, p_ptr->y, p_ptr->x) <= rad)) hityou = TRUE;
+                       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;
                }
        }
        else
        {
-               breath_shape(grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
+               breath_shape(master_ptr->current_floor_ptr, grid_g, grid_n, &grids, gx, gy, gm, &gm_rad, rad, y1, x1, y, x, typ);
 
                for (i = 0; i < grids; i++)
                {
-                       /* Extract the location */
                        y = gy[i];
                        x = gx[i];
-
                        if ((y == y2) && (x == x2)) hit2 = TRUE;
-                       if (player_bold(y, x)) hityou = TRUE;
+                       if (player_bold(master_ptr, y, x)) hityou = TRUE;
                }
        }
 
@@ -192,12 +206,12 @@ static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, PO
  * @param flg 判定のフラグ配列
  * @return なし
  */
-void get_project_point(POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
+void get_project_point(floor_type *floor_ptr, POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
 {
        u16b path_g[128];
        int  path_n, i;
 
-       path_n = project_path(path_g, MAX_RANGE, sy, sx, *ty, *tx, flg);
+       path_n = project_path(floor_ptr, path_g, MAX_RANGE, sy, sx, *ty, *tx, flg);
 
        *ty = sy;
        *tx = sx;
@@ -209,7 +223,7 @@ void get_project_point(POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT
                sx = GRID_X(path_g[i]);
 
                /* Hack -- Balls explode before reaching walls */
-               if (!cave_have_flag_bold(sy, sx, FF_PROJECT)) break;
+               if (!cave_have_flag_bold(floor_ptr, sy, sx, FF_PROJECT)) break;
 
                *ty = sy;
                *tx = sx;
@@ -225,12 +239,10 @@ void get_project_point(POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT
  */
 static bool dispel_check_monster(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
 {
-       monster_type *t_ptr = &m_list[t_idx];
+       monster_type *t_ptr = &p_ptr->current_floor_ptr->m_list[t_idx];
 
-       /* Invulnabilty */
        if (MON_INVULNER(t_ptr)) return TRUE;
 
-       /* Speed */
        if (t_ptr->mspeed < 135)
        {
                if (MON_FAST(t_ptr)) return TRUE;
@@ -239,7 +251,7 @@ static bool dispel_check_monster(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
        /* Riding monster */
        if (t_idx == p_ptr->riding)
        {
-               if (dispel_check(m_idx)) return TRUE;
+               if (dispel_check(p_ptr, m_idx)) return TRUE;
        }
 
        /* No need to cast dispel spell */
@@ -273,7 +285,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        char m_poss[160];
 #endif
 
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
        monster_type *t_ptr = NULL;
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
@@ -281,11 +293,11 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        u32b f4, f5, f6;
 
        bool see_m = is_seen(m_ptr);
-       bool maneable = player_has_los_bold(m_ptr->fy, m_ptr->fx);
+       bool maneable = player_has_los_bold(p_ptr, m_ptr->fy, m_ptr->fx);
        bool pet = is_pet(m_ptr);
 
-       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[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && p_ptr->current_floor_ptr->dun_level
+               && (!p_ptr->current_floor_ptr->inside_quest || is_fixed_quest_idx(p_ptr->current_floor_ptr->inside_quest));
 
        bool can_use_lite_area = FALSE;
        bool can_remember;
@@ -299,13 +311,13 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        f6 = r_ptr->a_ability_flags2;
 
        /* Target is given for pet? */
-       if (pet_t_m_idx && pet)
+       if (p_ptr->pet_t_m_idx && pet)
        {
-               target_idx = pet_t_m_idx;
-               t_ptr = &m_list[target_idx];
+               target_idx = p_ptr->pet_t_m_idx;
+               t_ptr = &p_ptr->current_floor_ptr->m_list[target_idx];
 
                /* Cancel if not projectable (for now) */
-               if ((m_idx == target_idx) || !projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+               if ((m_idx == target_idx) || !projectable(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                {
                        target_idx = 0;
                }
@@ -314,21 +326,21 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        /* Is there counter attack target? */
        if (!target_idx && m_ptr->target_y)
        {
-               target_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
+               target_idx = p_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
 
                if (target_idx)
                {
-                       t_ptr = &m_list[target_idx];
+                       t_ptr = &p_ptr->current_floor_ptr->m_list[target_idx];
 
                        /* Cancel if neither enemy nor a given target */
                        if ((m_idx == target_idx) ||
-                           ((target_idx != pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
+                           ((target_idx != p_ptr->pet_t_m_idx) && !are_enemies(m_ptr, t_ptr)))
                        {
                                target_idx = 0;
                        }
 
                        /* Allow only summoning etc.. if not projectable */
-                       else if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+                       else if (!projectable(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                        {
                                f4 &= (RF4_INDIRECT_MASK);
                                f5 &= (RF5_INDIRECT_MASK);
@@ -342,30 +354,29 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        {
                bool success = FALSE;
 
-               if (p_ptr->inside_battle)
+               if (p_ptr->phase_out)
                {
-                       start = randint1(m_max-1) + m_max;
+                       start = randint1(p_ptr->current_floor_ptr->m_max-1) + p_ptr->current_floor_ptr->m_max;
                        if (randint0(2)) plus = -1;
                }
-               else start = m_max + 1;
+               else start = p_ptr->current_floor_ptr->m_max + 1;
 
                /* Scan thru all monsters */
-               for (i = start; ((i < start + m_max) && (i > start - m_max)); i += plus)
+               for (i = start; ((i < start + p_ptr->current_floor_ptr->m_max) && (i > start - p_ptr->current_floor_ptr->m_max)); i += plus)
                {
-                       MONSTER_IDX dummy = (i % m_max);
+                       MONSTER_IDX dummy = (i % p_ptr->current_floor_ptr->m_max);
                        if (!dummy) continue;
 
                        target_idx = dummy;
-                       t_ptr = &m_list[target_idx];
+                       t_ptr = &p_ptr->current_floor_ptr->m_list[target_idx];
 
-                       /* Skip dead monsters */
-                       if (!t_ptr->r_idx) continue;
+                       if (!monster_is_valid(t_ptr)) continue;
 
                        /* Monster must be 'an enemy' */
                        if ((m_idx == target_idx) || !are_enemies(m_ptr, t_ptr)) continue;
 
                        /* Monster must be projectable */
-                       if (!projectable(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
+                       if (!projectable(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx)) continue;
 
                        /* Get it */
                        success = TRUE;
@@ -389,7 +400,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
 
        if (f4 & RF4_BR_LITE)
        {
-               if (!los(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
+               if (!los(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx))
                        f4 &= ~(RF4_BR_LITE);
        }
 
@@ -411,7 +422,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
 
                if (!(r_ptr->flags2 & RF2_STUPID))
                {
-                       if (d_info[dungeon_type].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
+                       if (d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS) f6 &= ~(RF6_DARKNESS);
                        else if (vs_ninja && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
                }
        }
@@ -423,7 +434,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                f6 &= (RF6_NOMAGIC_MASK);
        }
 
-       if (p_ptr->inside_arena || p_ptr->inside_battle)
+       if (p_ptr->current_floor_ptr->inside_arena || p_ptr->phase_out)
        {
                f4 &= ~(RF4_SUMMON_MASK);
                f5 &= ~(RF5_SUMMON_MASK);
@@ -432,7 +443,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                if (m_ptr->r_idx == MON_ROLENTO) f6 &= ~(RF6_SPECIAL);
        }
 
-       if (p_ptr->inside_battle && !one_in_(3))
+       if (p_ptr->phase_out && !one_in_(3))
        {
                f6 &= ~(RF6_HEAL);
        }
@@ -478,9 +489,9 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                                POSITION real_y = y;
                                POSITION real_x = x;
 
-                               get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
+                               get_project_point(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
 
-                               if (projectable(real_y, real_x, p_ptr->y, p_ptr->x))
+                               if (projectable(p_ptr->current_floor_ptr, real_y, real_x, p_ptr->y, p_ptr->x))
                                {
                                        int dist = distance(real_y, real_x, p_ptr->y, p_ptr->x);
 
@@ -499,7 +510,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                                }
                                else if (f5 & RF5_BA_LITE)
                                {
-                                       if ((distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 4) && los(real_y, real_x, p_ptr->y, p_ptr->x))
+                                       if ((distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 4) && los(p_ptr->current_floor_ptr, real_y, real_x, p_ptr->y, p_ptr->x))
                                                f5 &= ~(RF5_BA_LITE);
                                }
                        }
@@ -509,8 +520,8 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                                POSITION real_y = y;
                                POSITION real_x = x;
 
-                               get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
-                               if (projectable(real_y, real_x, p_ptr->y, p_ptr->x) && (distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 2))
+                               get_project_point(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, &real_y, &real_x, PROJECT_STOP);
+                               if (projectable(p_ptr->current_floor_ptr, real_y, real_x, p_ptr->y, p_ptr->x) && (distance(real_y, real_x, p_ptr->y, p_ptr->x) <= 2))
                                        f4 &= ~(RF4_ROCKET);
                        }
 
@@ -527,19 +538,19 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                                /* Expected breath radius */
                                POSITION rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
 
-                               if (!breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, 0, TRUE))
+                               if (!breath_direct(p_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, 0, TRUE))
                                {
                                        f4 &= ~(RF4_BREATH_MASK);
                                        f5 &= ~(RF5_BREATH_MASK);
                                        f6 &= ~(RF6_BREATH_MASK);
                                }
                                else if ((f4 & RF4_BR_LITE) &&
-                                        !breath_direct(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_LITE, TRUE))
+                                        !breath_direct(p_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(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_DISINTEGRATE, TRUE))
+                                        !breath_direct(p_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, rad, GF_DISINTEGRATE, TRUE))
                                {
                                        f4 &= ~(RF4_BR_DISI);
                                }
@@ -677,12 +688,12 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        /* Choose a spell to cast */
        thrown_spell = spell[randint0(num)];
 
-       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
+       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(p_ptr, TRUE, TRUE);
 
        /* Check for spell failure (inate attacks never fail) */
        if (!spell_is_inate(thrown_spell) && (in_no_magic_dungeon || (MON_STUNNED(m_ptr) && one_in_(2))))
        {
-               disturb(TRUE, TRUE);
+               disturb(p_ptr, TRUE, TRUE);
                if (see_m) msg_format(_("%^sは呪文を唱えようとしたが失敗した。", 
                                            "%^s tries to cast a spell, but fails."), m_name);
 
@@ -690,7 +701,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        }
 
        /* Hex: Anti Magic Barrier */
-       if (!spell_is_inate(thrown_spell) && magic_barrier(m_idx))
+       if (!spell_is_inate(thrown_spell) && magic_barrier(p_ptr, m_idx))
        {
                if (see_m) msg_format(_("反魔法バリアが%^sの呪文をかき消した。", 
                                            "Anti magic barrier cancels the spell which %^s casts."), m_name);
@@ -702,7 +713,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        dam = monspell_to_monster(thrown_spell, y, x, m_idx, target_idx);
        if (dam < 0) return FALSE;
 
-       if (m_ptr->ml && maneable && !world_monster && !p_ptr->blind && (p_ptr->pclass == CLASS_IMITATOR))
+       if (m_ptr->ml && maneable && !current_world_ptr->timewalk_m_idx && !p_ptr->blind && (p_ptr->pclass == CLASS_IMITATOR))
        {
                if (thrown_spell != 167) /* Not RF6_SPECIAL */
                {
@@ -718,7 +729,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                        p_ptr->mane_spell[p_ptr->mane_num] = thrown_spell - RF4_SPELL_START;
                        p_ptr->mane_dam[p_ptr->mane_num] = dam;
                        p_ptr->mane_num++;
-                       new_mane = TRUE;
+                       p_ptr->new_mane = TRUE;
 
                        p_ptr->redraw |= (PR_IMITATION);
                }
@@ -750,7 +761,7 @@ bool monst_spell_monst(MONSTER_IDX 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 (p_ptr->is_dead && (r_ptr->r_deaths < MAX_SHORT) && !p_ptr->current_floor_ptr->inside_arena)
        {
                r_ptr->r_deaths++; /* Ignore appearance difference */
        }