OSDN Git Service

[Refactor] #921 Separated search_room_to_run() from check_hiding_grid()
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 2 Aug 2021 13:30:09 +0000 (22:30 +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 f32012c..7b28bc1 100644 (file)
@@ -165,36 +165,7 @@ void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2,
         }
     }
 
-    if (any_bits(r_ptr->flags3, RF3_ANIMAL) && !this->can_pass_wall && !any_bits(r_ptr->flags2, RF2_KILL_WALL)) {
-        auto room = 0;
-        for (auto i = 0; i < 8; i++) {
-            auto xx = this->target_ptr->x + ddx_ddd[i];
-            auto yy = this->target_ptr->y + ddy_ddd[i];
-            if (!in_bounds2(floor_ptr, yy, xx)) {
-                continue;
-            }
-
-            auto *g_ptr = &floor_ptr->grid_array[yy][xx];
-            if (monster_can_cross_terrain(this->target_ptr, g_ptr->feat, r_ptr, 0)) {
-                room++;
-            }
-        }
-
-        if (any_bits(floor_ptr->grid_array[this->target_ptr->y][this->target_ptr->x].info, CAVE_ROOM)) {
-            room -= 2;
-        }
-
-        if (r_ptr->ability_flags.none()) {
-            room -= 2;
-        }
-
-        if (room < (8 * (this->target_ptr->chp + this->target_ptr->csp)) / (this->target_ptr->mhp + this->target_ptr->msp)) {
-            if (find_hiding(this->target_ptr, this->m_idx, y, x)) {
-                this->done = true;
-            }
-        }
-    }
-
+    this->search_room_to_run(y, x);
     if (this->done || (grid_dist(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) >= 3)) {
         return;
     }
@@ -220,6 +191,45 @@ void MonsterSweepGrid::check_hiding_grid(POSITION *y, POSITION *x, POSITION *y2,
     this->done = true;
 }
 
+void MonsterSweepGrid::search_room_to_run(POSITION *y, POSITION *x)
+{
+    auto *floor_ptr = this->target_ptr->current_floor_ptr;
+    auto *r_ptr = &r_info[floor_ptr->m_list[this->m_idx].r_idx];
+    if (none_bits(r_ptr->flags3, RF3_ANIMAL) || this->can_pass_wall || any_bits(r_ptr->flags2, RF2_KILL_WALL)) {
+        return;
+    }
+
+    auto room = 0;
+    for (auto i = 0; i < 8; i++) {
+        auto xx = this->target_ptr->x + ddx_ddd[i];
+        auto yy = this->target_ptr->y + ddy_ddd[i];
+        if (!in_bounds2(floor_ptr, yy, xx)) {
+            continue;
+        }
+
+        auto *g_ptr = &floor_ptr->grid_array[yy][xx];
+        if (monster_can_cross_terrain(this->target_ptr, g_ptr->feat, r_ptr, 0)) {
+            room++;
+        }
+    }
+
+    if (any_bits(floor_ptr->grid_array[this->target_ptr->y][this->target_ptr->x].info, CAVE_ROOM)) {
+        room -= 2;
+    }
+
+    if (r_ptr->ability_flags.none()) {
+        room -= 2;
+    }
+
+    if (room >= (8 * (this->target_ptr->chp + this->target_ptr->csp)) / (this->target_ptr->mhp + this->target_ptr->msp)) {
+        return;
+    }
+
+    if (find_hiding(this->target_ptr, this->m_idx, y, x)) {
+        this->done = true;
+    }
+}
+
 /*!
  * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
  * Choose the "best" direction for "flowing"
index f4e8ae0..ac47937 100644 (file)
@@ -23,4 +23,5 @@ private:
     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);
+    void search_room_to_run(POSITION *y, POSITION *x);
 };