OSDN Git Service

[Refactor] #38844 pet_t_m_idx, riding_t_m_idx を player_type 構造体に移動.
[hengband/hengband.git] / src / mspells2.c
index 9a27208..e71647b 100644 (file)
  */
 
 #include "angband.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];
@@ -46,8 +63,8 @@ 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 && current_floor_ptr->grid_array[y][x].m_idx > 0 &&
+                        !are_enemies(m_ptr, &current_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx]))
                {
                        /* Friends don't shoot friends */
                        return FALSE;
@@ -191,7 +208,7 @@ static bool breath_direct(POSITION y1, POSITION x1, POSITION y2, POSITION x2, PO
  * @param flg 判定のフラグ配列
  * @return なし
  */
-void get_project_point(int sy, int sx, int *ty, int *tx, BIT_FLAGS flg)
+void get_project_point(POSITION sy, POSITION sx, POSITION *ty, POSITION *tx, BIT_FLAGS flg)
 {
        u16b path_g[128];
        int  path_n, i;
@@ -224,12 +241,10 @@ void get_project_point(int sy, int sx, int *ty, int *tx, BIT_FLAGS flg)
  */
 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 = &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;
@@ -265,14 +280,14 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
 
        byte spell[96], num = 0;
 
-       char m_name[160];
-       char t_name[160];
+       GAME_TEXT m_name[160];
+       GAME_TEXT t_name[160];
 
 #ifndef JP
        char m_poss[160];
 #endif
 
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
        monster_type *t_ptr = NULL;
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
@@ -283,7 +298,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
        bool maneable = player_has_los_bold(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
+       bool in_no_magic_dungeon = (d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC) && current_floor_ptr->dun_level
                && (!p_ptr->inside_quest || is_fixed_quest_idx(p_ptr->inside_quest));
 
        bool can_use_lite_area = FALSE;
@@ -298,10 +313,10 @@ 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 = &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))
@@ -313,15 +328,15 @@ 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 = 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 = &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;
                        }
@@ -343,22 +358,21 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
 
                if (p_ptr->inside_battle)
                {
-                       start = randint1(m_max-1) + m_max;
+                       start = randint1(current_floor_ptr->m_max-1) + current_floor_ptr->m_max;
                        if (randint0(2)) plus = -1;
                }
-               else start = m_max + 1;
+               else start = 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 + current_floor_ptr->m_max) && (i > start - current_floor_ptr->m_max)); i += plus)
                {
-                       MONSTER_IDX dummy = (i % m_max);
+                       MONSTER_IDX dummy = (i % current_floor_ptr->m_max);
                        if (!dummy) continue;
 
                        target_idx = dummy;
-                       t_ptr = &m_list[target_idx];
+                       t_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;
@@ -410,7 +424,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);
                }
        }
@@ -474,8 +488,8 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                            (f5 & RF5_BALL_MASK) ||
                            (f6 & RF6_BALL_MASK))
                        {
-                               int real_y = y;
-                               int real_x = x;
+                               POSITION real_y = y;
+                               POSITION real_x = x;
 
                                get_project_point(m_ptr->fy, m_ptr->fx, &real_y, &real_x, 0L);
 
@@ -505,17 +519,15 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
 
                        if (f4 & RF4_ROCKET)
                        {
-                               int real_y = y;
-                               int real_x = x;
+                               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))
                                        f4 &= ~(RF4_ROCKET);
                        }
 
-                       if (((f4 & RF4_BEAM_MASK) ||
-                            (f5 & RF5_BEAM_MASK) ||
-                            (f6 & RF6_BEAM_MASK)) &&
+                       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))
                        {
                                f4 &= ~(RF4_BEAM_MASK);
@@ -523,9 +535,7 @@ bool monst_spell_monst(MONSTER_IDX m_idx)
                                f6 &= ~(RF6_BEAM_MASK);
                        }
 
-                       if ((f4 & RF4_BREATH_MASK) ||
-                           (f5 & RF5_BREATH_MASK) ||
-                           (f6 & RF6_BREATH_MASK))
+                       if ((f4 & RF4_BREATH_MASK) || (f5 & RF5_BREATH_MASK) || (f6 & RF6_BREATH_MASK))
                        {
                                /* Expected breath radius */
                                POSITION rad = (r_ptr->flags2 & RF2_POWERFUL) ? 3 : 2;
@@ -705,7 +715,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 */
                {
@@ -721,7 +731,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);
                }