OSDN Git Service

[Refactor] #921 Separated check_movable_grid() from sweep_movable_grid()
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 2 Aug 2021 13:45:29 +0000 (22:45 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Sun, 8 Aug 2021 06:00:09 +0000 (15:00 +0900)
src/monster-floor/monster-sweep-grid.cpp
src/monster-floor/monster-sweep-grid.h

index 293097e..07338c4 100644 (file)
@@ -252,19 +252,7 @@ void MonsterSweepGrid::sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_fl
     auto *floor_ptr = this->target_ptr->current_floor_ptr;
     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
     auto *r_ptr = &r_info[m_ptr->r_idx];
-    if ((r_ptr->ability_flags.has_any_of(RF_ABILITY_ATTACK_MASK)) && (sweep_ranged_attack_grid(yp, xp))) {
-        return;
-    }
-
-    if (no_flow) {
-        return;
-    }
-
-    if (any_bits(r_ptr->flags2, RF2_PASS_WALL) && ((this->m_idx != this->target_ptr->riding) || has_pass_wall(this->target_ptr))) {
-        return;
-    }
-
-    if (any_bits(r_ptr->flags2, RF2_KILL_WALL) && (this->m_idx != this->target_ptr->riding)) {
+    if (!this->check_movable_grid(yp, xp, no_flow)) {
         return;
     }
 
@@ -321,6 +309,28 @@ void MonsterSweepGrid::sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_fl
     }
 }
 
+bool MonsterSweepGrid::check_movable_grid(POSITION *yp, POSITION *xp, const bool no_flow)
+{
+    auto *r_ptr = &r_info[this->target_ptr->current_floor_ptr->m_list[this->m_idx].r_idx];
+    if ((r_ptr->ability_flags.has_any_of(RF_ABILITY_ATTACK_MASK)) && (sweep_ranged_attack_grid(yp, xp))) {
+        return false;
+    }
+
+    if (no_flow) {
+        return false;
+    }
+
+    if (any_bits(r_ptr->flags2, RF2_PASS_WALL) && ((this->m_idx != this->target_ptr->riding) || has_pass_wall(this->target_ptr))) {
+        return false;
+    }
+
+    if (any_bits(r_ptr->flags2, RF2_KILL_WALL) && (this->m_idx != this->target_ptr->riding)) {
+        return false;
+    }
+
+    return true;
+}
+
 /*!
  * @brief モンスターがプレイヤーに向けて遠距離攻撃を行うことが可能なマスを走査する /
  * Search spell castable grid
index c211dc9..506cee4 100644 (file)
@@ -20,6 +20,7 @@ private:
     bool can_pass_wall = false;
     bool mon_will_run();
     void sweep_movable_grid(POSITION *yp, POSITION *xp, bool no_flow);
+    bool check_movable_grid(POSITION *yp, POSITION *xp, const bool no_flow);
     bool sweep_ranged_attack_grid(POSITION *yp, POSITION *xp);
     bool sweep_runnable_away_grid(POSITION *yp, POSITION *xp);
     void check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2, POSITION *x2);