OSDN Git Service

[Refactor] #921 Separated search_pet_runnable_grid() from get_movable_grid()
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 2 Aug 2021 13:38:19 +0000 (22:38 +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 7b28bc1..293097e 100644 (file)
@@ -77,25 +77,7 @@ bool MonsterSweepGrid::get_movable_grid()
         x = m_ptr->fx - x2;
     }
 
-    if (is_pet(m_ptr) && this->will_run) {
-        y = (-y), x = (-x);
-    } else {
-        if (!this->done && this->will_run) {
-            int tmp_x = (-x);
-            int tmp_y = (-y);
-            if (find_safety(this->target_ptr, this->m_idx, &y, &x) && !no_flow) {
-                if (this->sweep_runnable_away_grid(&y, &x)) {
-                    this->done = true;
-                }
-            }
-
-            if (!this->done) {
-                y = tmp_y;
-                x = tmp_x;
-            }
-        }
-    }
-
+    this->search_pet_runnable_grid(&y, &x, no_flow);
     if (!x && !y) {
         return false;
     }
@@ -230,6 +212,34 @@ void MonsterSweepGrid::search_room_to_run(POSITION *y, POSITION *x)
     }
 }
 
+void MonsterSweepGrid::search_pet_runnable_grid(POSITION *y, POSITION *x, bool no_flow)
+{
+    auto *floor_ptr = this->target_ptr->current_floor_ptr;
+    auto *m_ptr = &floor_ptr->m_list[this->m_idx];
+    if (is_pet(m_ptr) && this->will_run) {
+        *y = -(*y);
+        *x = -(*x);
+        return;
+    }
+
+    if (this->done || !this->will_run) {
+        return;
+    }
+
+    auto tmp_x = -(*x);
+    auto tmp_y = -(*y);
+    if (find_safety(this->target_ptr, this->m_idx, y, x) && !no_flow && this->sweep_runnable_away_grid(y, x)) {
+        this->done = true;
+    }
+
+    if (this->done) {
+        return;
+    }
+
+    *y = tmp_y;
+    *x = tmp_x;
+}
+
 /*!
  * @brief モンスターがプレイヤーに向けて接近することが可能なマスを走査する /
  * Choose the "best" direction for "flowing"
index ac47937..c211dc9 100644 (file)
@@ -24,4 +24,5 @@ private:
     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);
+    void search_pet_runnable_grid(POSITION *y, POSITION *x, bool no_flow);
 };