OSDN Git Service

[Refactor] #37353 projection.c/h を geometry.c/h に統合。
[hengband/hengband.git] / src / mspells1.c
index 70d5ef1..b716b85 100644 (file)
 
 #include "angband.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"
 
 
 /*!
@@ -70,7 +76,7 @@ static bool int_outof(monster_race *r_ptr, PERCENTAGE prob)
  */
 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 = &current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        u32b f4 = (*f4p);
@@ -401,7 +407,7 @@ bool raise_possible(monster_type *m_ptr)
        POSITION y = m_ptr->fy;
        POSITION x = m_ptr->fx;
        OBJECT_IDX this_o_idx, next_o_idx = 0;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        for (xx = x - 5; xx <= x + 5; xx++)
        {
@@ -411,13 +417,11 @@ bool raise_possible(monster_type *m_ptr)
                        if (!los(y, x, yy, xx)) continue;
                        if (!projectable(y, x, yy, xx)) continue;
 
-                       c_ptr = &cave[yy][xx];
+                       g_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)
                        {
-                               object_type *o_ptr = &o_list[this_o_idx];
-
-                               /* Acquire next object */
+                               object_type *o_ptr = &current_floor_ptr->o_list[this_o_idx];
                                next_o_idx = o_ptr->next_o_idx;
 
                                /* Known to be worthless? */
@@ -480,9 +484,9 @@ bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_frie
                y = GRID_Y(grid_g[i]);
                x = GRID_X(grid_g[i]);
 
-               if ((cave[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
+               if ((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 = &current_floor_ptr->m_list[current_floor_ptr->grid_array[y][x].m_idx];
                        if (is_friend == is_pet(m_ptr))
                        {
                                return (FALSE);
@@ -577,7 +581,7 @@ void beam(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp,
  */
 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 = &current_floor_ptr->m_list[m_idx];
     monster_race *r_ptr = &r_info[m_ptr->r_idx];
     bool learnable = spell_learnable(m_idx);
        BIT_FLAGS flg = 0x00;
@@ -858,7 +862,7 @@ static bool spell_dispel(byte spell)
  */
 bool dispel_check(MONSTER_IDX m_idx)
 {
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        /* Invulnabilty (including the song) */
@@ -935,7 +939,6 @@ bool dispel_check(MONSTER_IDX 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);
@@ -944,9 +947,9 @@ bool dispel_check(MONSTER_IDX 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 && (current_floor_ptr->m_list[p_ptr->riding].mspeed < 135))
        {
-               if (MON_FAST(&m_list[p_ptr->riding])) return (TRUE);
+               if (MON_FAST(&current_floor_ptr->m_list[p_ptr->riding])) return (TRUE);
        }
 
        /* No need to cast dispel spell */
@@ -975,7 +978,7 @@ bool dispel_check(MONSTER_IDX m_idx)
  */
 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 = &current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        byte escape[96], escape_num = 0;
@@ -1047,7 +1050,7 @@ static int choose_attack_spell(MONSTER_IDX 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)]);
@@ -1106,7 +1109,7 @@ static int choose_attack_spell(MONSTER_IDX m_idx, byte spells[], byte num)
        }
 
        /* Player is close and we have attack spells, blink away */
-       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) && !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)]);
@@ -1157,7 +1160,7 @@ static int choose_attack_spell(MONSTER_IDX 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)]);
@@ -1254,13 +1257,13 @@ static bool adjacent_grid_check(monster_type *m_ptr, POSITION *yp, POSITION *xp,
        {
                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 = &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))
                {
@@ -1342,11 +1345,11 @@ bool make_attack_spell(MONSTER_IDX m_idx)
        SPELL_IDX thrown_spell = 0;
        DEPTH rlev;
        PERCENTAGE failrate;
-       byte            spell[96], num = 0;
+       byte spell[96], num = 0;
        BIT_FLAGS f4, f5, f6;
-       monster_type *m_ptr = &m_list[m_idx];
+       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
-       char m_name[80];
+       GAME_TEXT m_name[MAX_NLEN];
 #ifndef JP
        char m_poss[80];
 #endif
@@ -1354,7 +1357,6 @@ bool make_attack_spell(MONSTER_IDX m_idx)
        bool            do_spell = DO_SPELL_NONE;
        int             dam = 0;
 
-       /* Target location */
        POSITION x = p_ptr->x;
        POSITION y = p_ptr->y;
 
@@ -1369,7 +1371,7 @@ bool make_attack_spell(MONSTER_IDX m_idx)
        /* Check "projectable" */
        bool direct;
 
-       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;
@@ -1412,7 +1414,7 @@ bool make_attack_spell(MONSTER_IDX m_idx)
 
                if (los(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[current_floor_ptr->grid_array[y_br_lite][x_br_lite].feat];
 
                        if (!have_flag(f_ptr->flags, FF_LOS))
                        {
@@ -1434,7 +1436,7 @@ bool make_attack_spell(MONSTER_IDX m_idx)
        /* Check path */
        if (projectable(m_ptr->fy, m_ptr->fx, y, x))
        {
-               feature_type *f_ptr = &f_info[cave[y][x].feat];
+               feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
 
                if (!have_flag(f_ptr->flags, FF_PROJECT))
                {
@@ -1508,7 +1510,6 @@ bool make_attack_spell(MONSTER_IDX m_idx)
 
        reset_target(m_ptr);
 
-       /* Extract the monster level */
        rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
 
        /* Forbid inate attacks sometimes */
@@ -1528,7 +1529,7 @@ bool make_attack_spell(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 ((p_ptr->pclass == CLASS_NINJA) && !can_use_lite_area) f6 &= ~(RF6_DARKNESS);
                }
        }
@@ -1686,7 +1687,7 @@ bool make_attack_spell(MONSTER_IDX m_idx)
                break;
 
        default:
-               return FALSE; /* Paranoia */
+               return FALSE;
        }
 
        /* Abort if no spell was chosen */
@@ -1768,7 +1769,7 @@ bool make_attack_spell(MONSTER_IDX m_idx)
                learn_spell(thrown_spell - 96);
        }
 
-       if (seen && maneable && !world_monster && (p_ptr->pclass == CLASS_IMITATOR))
+       if (seen && maneable && !current_world_ptr->timewalk_m_idx && (p_ptr->pclass == CLASS_IMITATOR))
        {
                if (thrown_spell != 167) /* Not RF6_SPECIAL */
                {