OSDN Git Service

[Refactor] #919 Moved grid_cost() and grid_dist() from grid.cpp/h to grid-type-defini...
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Sat, 7 Aug 2021 04:24:21 +0000 (13:24 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Sun, 8 Aug 2021 05:59:42 +0000 (14:59 +0900)
src/grid/grid.cpp
src/grid/grid.h
src/monster-floor/monster-safety-hiding.cpp
src/monster-floor/monster-sweep-grid.cpp
src/system/grid-type-definition.cpp
src/system/grid-type-definition.h

index 1e57927..c75960f 100644 (file)
@@ -858,23 +858,6 @@ void update_flow(player_type *subject_ptr)
     }
 }
 
-static flow_type get_grid_flow_type(monster_race *r_ptr)
-{
-    if (any_bits(r_ptr->flags7, RF7_CAN_FLY))
-        return FLOW_CAN_FLY;
-    return FLOW_NORMAL;
-}
-
-byte grid_cost(grid_type *g_ptr, monster_race *r_ptr)
-{
-    return g_ptr->costs[get_grid_flow_type(r_ptr)];
-}
-
-byte grid_dist(grid_type *g_ptr, monster_race *r_ptr)
-{
-    return g_ptr->dists[get_grid_flow_type(r_ptr)];
-}
-
 /*
  * Take a feature, determine what that feature becomes
  * through applying the given action.
index b14353c..c36d20e 100644 (file)
@@ -54,8 +54,6 @@ void print_rel(player_type *subject_ptr, SYMBOL_CODE c, TERM_COLOR a, POSITION y
 void note_spot(player_type *player_ptr, POSITION y, POSITION x);
 void lite_spot(player_type *player_ptr, POSITION y, POSITION x);
 void update_flow(player_type *subject_ptr);
-byte grid_cost(grid_type *g_ptr, monster_race *r_ptr);
-byte grid_dist(grid_type *g_ptr, monster_race *r_ptr);
 FEAT_IDX feat_state(floor_type *floor_ptr, FEAT_IDX feat, int action);
 void cave_alter_feat(player_type *player_ptr, POSITION y, POSITION x, int action);
 void remove_mirror(player_type *caster_ptr, POSITION y, POSITION x);
index 8ceb2e7..dea947f 100644 (file)
@@ -50,10 +50,10 @@ static coordinate_candidate sweep_safe_coordinate(player_type *target_ptr, MONST
             continue;
 
         if (m_ptr->mflag2.has_not(MFLAG2::NOFLOW)) {
-            byte dist = grid_dist(g_ptr, r_ptr);
+            byte dist = g_ptr->get_distance(r_ptr);
             if (dist == 0)
                 continue;
-            if (dist > grid_dist(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) + 2 * d)
+            if (dist > floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].get_distance(r_ptr) + 2 * d)
                 continue;
         }
 
index 5cadb90..f975e8a 100644 (file)
@@ -100,7 +100,7 @@ static bool sweep_ranged_attack_grid(player_type *target_ptr, MONSTER_IDX m_idx,
     if (projectable(target_ptr, y1, x1, target_ptr->y, target_ptr->x))
         return false;
 
-    int now_cost = grid_cost(&floor_ptr->grid_array[y1][x1], r_ptr);
+    int now_cost = floor_ptr->grid_array[y1][x1].get_cost(r_ptr);
     if (now_cost == 0)
         now_cost = 999;
 
@@ -120,7 +120,7 @@ static bool sweep_ranged_attack_grid(player_type *target_ptr, MONSTER_IDX m_idx,
 
         grid_type *g_ptr;
         g_ptr = &floor_ptr->grid_array[y][x];
-        int cost = grid_cost(g_ptr, r_ptr);
+        int cost = g_ptr->get_cost(r_ptr);
         if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || has_pass_wall(target_ptr)))
                 || ((r_ptr->flags2 & RF2_KILL_WALL) && (m_idx != target_ptr->riding)))) {
             if (cost == 0)
@@ -204,13 +204,13 @@ static void sweep_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, POSIT
             return;
         if (r_ptr->freq_spell > 0)
             return;
-        if (grid_cost(g_ptr, r_ptr) > 5)
+        if (g_ptr->get_cost(r_ptr) > 5)
             return;
     }
 
     int best;
     bool use_scent = false;
-    if (grid_cost(g_ptr, r_ptr)) {
+    if (g_ptr->get_cost(r_ptr)) {
         best = 999;
     } else if (g_ptr->when) {
         if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].when - g_ptr->when > 127)
@@ -239,9 +239,9 @@ static void sweep_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, POSIT
         } else {
             int cost;
             if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR)) {
-                cost = grid_dist(g_ptr, r_ptr);
+                cost = g_ptr->get_distance(r_ptr);
             } else {
-                cost = grid_cost(g_ptr, r_ptr);
+                cost = g_ptr->get_cost(r_ptr);
             }
 
             if ((cost == 0) || (best < cost))
@@ -287,7 +287,7 @@ static bool sweep_runnable_away_grid(floor_type *floor_ptr, MONSTER_IDX m_idx, P
             continue;
 
         POSITION dis = distance(y, x, y1, x1);
-        POSITION s = 5000 / (dis + 3) - 500 / (grid_dist(&floor_ptr->grid_array[y][x], r_ptr) + 1);
+        POSITION s = 5000 / (dis + 3) - 500 / (floor_ptr->grid_array[y][x].get_distance(r_ptr) + 1);
         if (s < 0)
             s = 0;
 
@@ -327,8 +327,8 @@ bool get_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
     POSITION x2 = target_ptr->x;
     bool done = false;
     bool will_run = mon_will_run(target_ptr, m_idx);
-    grid_type *g_ptr;
-    bool no_flow = m_ptr->mflag2.has(MFLAG2::NOFLOW) && grid_cost(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) > 2;
+    grid_type *g_ptr = &floor_ptr->grid_array[m_ptr->fy][m_ptr->fx];
+    bool no_flow = m_ptr->mflag2.has(MFLAG2::NOFLOW) && g_ptr->get_cost(r_ptr) > 2;
     bool can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) != 0) && ((m_idx != target_ptr->riding) || has_pass_wall(target_ptr));
 
     if (!will_run && m_ptr->target_y) {
@@ -344,7 +344,7 @@ bool get_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
 
     if (!done && !will_run && is_hostile(m_ptr) && (r_ptr->flags1 & RF1_FRIENDS)
         && ((los(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x))
-            || (grid_dist(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) < MAX_SIGHT / 2))) {
+            || (g_ptr->get_distance(r_ptr) < MAX_SIGHT / 2))) {
         if ((r_ptr->flags3 & RF3_ANIMAL) && !can_pass_wall && !(r_ptr->flags2 & RF2_KILL_WALL)) {
             int room = 0;
             for (int i = 0; i < 8; i++) {
@@ -354,8 +354,8 @@ bool get_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
                 if (!in_bounds2(floor_ptr, yy, xx))
                     continue;
 
-                g_ptr = &floor_ptr->grid_array[yy][xx];
-                if (monster_can_cross_terrain(target_ptr, g_ptr->feat, r_ptr, 0)) {
+                auto *gg_ptr = &floor_ptr->grid_array[yy][xx];
+                if (monster_can_cross_terrain(target_ptr, gg_ptr->feat, r_ptr, 0)) {
                     room++;
                 }
             }
@@ -371,7 +371,7 @@ bool get_movable_grid(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
             }
         }
 
-        if (!done && grid_dist(&floor_ptr->grid_array[m_ptr->fy][m_ptr->fx], r_ptr) < 3) {
+        if (!done && g_ptr->get_distance(r_ptr) < 3) {
             for (int i = 0; i < 8; i++) {
                 y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
                 x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
index ab2efb7..abd5fd5 100644 (file)
@@ -1,5 +1,7 @@
 #include "system/grid-type-definition.h"
 #include "grid/feature.h" // @todo 相互依存している. 後で何とかする.
+#include "monster-race/race-flags7.h"
+#include "system/monster-race-definition.h"
 #include "util/bit-flags-calculator.h"
 
 /*!
@@ -88,3 +90,18 @@ bool grid_type::is_rune_explosion()
 {
     return this->is_object() && has_flag(f_info[this->mimic].flags, FF_RUNE_EXPLOSION);
 }
+
+byte grid_type::get_cost(monster_race *r_ptr)
+{
+    return this->costs[get_grid_flow_type(r_ptr)];
+}
+
+byte grid_type::get_distance(monster_race *r_ptr)
+{
+    return this->dists[get_grid_flow_type(r_ptr)];
+}
+
+flow_type grid_type::get_grid_flow_type(monster_race *r_ptr)
+{
+    return any_bits(r_ptr->flags7, RF7_CAN_FLY) ? FLOW_CAN_FLY : FLOW_NORMAL;
+}
index 7af63ce..402dec7 100644 (file)
@@ -44,7 +44,9 @@ enum flow_type {
     FLOW_MAX = 2,
 };
 
+struct monster_race;
 struct grid_type {
+public:
     BIT_FLAGS info{}; /* Hack -- grid flags */
 
     FEAT_IDX feat{}; /* Hack -- feature type */
@@ -79,4 +81,9 @@ struct grid_type {
     bool is_mirror();
     bool is_rune_protection();
     bool is_rune_explosion();
+    byte get_cost(monster_race *r_ptr);
+    byte get_distance(monster_race *r_ptr);
+
+private:
+    flow_type get_grid_flow_type(monster_race *r_ptr);
 };