OSDN Git Service

[Refactor] #40577 Separated projection-path-calculator.c/h from floor.c/h
authorHourier <hourier@users.sourceforge.jp>
Thu, 20 Aug 2020 08:01:43 +0000 (17:01 +0900)
committerHourier <hourier@users.sourceforge.jp>
Thu, 20 Aug 2020 08:01:43 +0000 (17:01 +0900)
14 files changed:
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/combat/shoot.c
src/effect/effect-processor.c
src/floor/floor.c
src/floor/floor.h
src/io/cursor.c
src/mind/mind-ninja.c
src/mspell/mspell-checker.c
src/mspell/mspell-judgement.c
src/spell-kind/spells-fetcher.c
src/target/projection-path-calculator.c [new file with mode: 0644]
src/target/projection-path-calculator.h [new file with mode: 0644]

index c614f51..a192531 100644 (file)
     <ClCompile Include="..\..\src\store\sell-order.c" />\r
     <ClCompile Include="..\..\src\store\service-checker.c" />\r
     <ClCompile Include="..\..\src\target\grid-selector.c" />\r
+    <ClCompile Include="..\..\src\target\projection-path-calculator.c" />\r
     <ClCompile Include="..\..\src\target\target-describer.c" />\r
     <ClCompile Include="..\..\src\target\target-getter.c" />\r
     <ClCompile Include="..\..\src\target\target-preparation.c" />\r
     <ClInclude Include="..\..\src\system\dungeon-data-definition.h" />\r
     <ClInclude Include="..\..\src\system\floor-type-definition.h" />\r
     <ClInclude Include="..\..\src\target\grid-selector.h" />\r
+    <ClInclude Include="..\..\src\target\projection-path-calculator.h" />\r
     <ClInclude Include="..\..\src\target\target-describer.h" />\r
     <ClInclude Include="..\..\src\target\target-getter.h" />\r
     <ClInclude Include="..\..\src\target\target-preparation.h" />\r
index 1f1b7ca..7f5e6d7 100644 (file)
     <ClCompile Include="..\..\src\cmd-item\cmd-destroy.c">
       <Filter>cmd-item</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\target\projection-path-calculator.c">
+      <Filter>target</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\combat\shoot.h">
     <ClInclude Include="..\..\src\cmd-item\cmd-destroy.h">
       <Filter>cmd-item</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\target\projection-path-calculator.h">
+      <Filter>target</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 3c97234..508b4df 100644 (file)
@@ -788,6 +788,7 @@ hengband_SOURCES = \
        system/gamevalue.h \
        \
        target/grid-selector.c target/grid-selector.h \
+       target/projection-path-calculator.c target/projection-path-calculator.h
        target/target-checker.c target/target-checker.h \
        target/target-describer.c target/target-describer.h \
        target/target-getter.c target/target-getter.h \
index b1eaf12..4d2234b 100644 (file)
@@ -10,7 +10,6 @@
 #include "flavor/object-flavor-types.h"
 #include "floor/cave.h"
 #include "floor/floor-object.h"
-#include "floor/floor.h"
 #include "game-option/cheat-types.h"
 #include "game-option/special-options.h"
 #include "grid/feature-flag-types.h"
@@ -55,6 +54,7 @@
 #include "sv-definition/sv-bow-types.h"
 #include "system/artifact-type-definition.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "target/target-checker.h"
 #include "target/target-getter.h"
 #include "util/bit-flags-calculator.h"
@@ -452,7 +452,7 @@ void exe_fire(player_type *shooter_ptr, INVENTORY_IDX item, object_type *j_ptr,
     }
 
     /* Get projection path length */
-    tdis = project_path(shooter_ptr, path_g, project_length, shooter_ptr->y, shooter_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU) - 1;
+    tdis = projection_path(shooter_ptr, path_g, project_length, shooter_ptr->y, shooter_ptr->x, ty, tx, PROJECT_PATH | PROJECT_THRU) - 1;
 
     project_length = 0; /* reset to default */
 
index 82e3f16..7cae456 100644 (file)
@@ -24,6 +24,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "term/gameterm.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
index dddace3..bac1ef4 100644 (file)
@@ -30,6 +30,7 @@
 #include "room/door-definition.h"
 #include "system/artifact-type-definition.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world-object.h"
@@ -880,203 +881,6 @@ void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
 }
 
 /*!
- * @brief 始点から終点への直線経路を返す /
- * Determine the path taken by a projection.
- * @param player_ptr プレーヤーへの参照ポインタ
- * @param gp 経路座標リストを返す参照ポインタ
- * @param range 距離
- * @param y1 始点Y座標
- * @param x1 始点X座標
- * @param y2 終点Y座標
- * @param x2 終点X座標
- * @param flg フラグID
- * @return リストの長さ
- */
-int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
-{
-    if ((x1 == x2) && (y1 == y2))
-        return 0;
-
-    POSITION y, x;
-    POSITION ay, ax;
-    POSITION sy, sx;
-    int frac;
-    int m;
-
-    if (y2 < y1) {
-        ay = (y1 - y2);
-        sy = -1;
-    } else {
-        ay = (y2 - y1);
-        sy = 1;
-    }
-
-    if (x2 < x1) {
-        ax = (x1 - x2);
-        sx = -1;
-    } else {
-        ax = (x2 - x1);
-        sx = 1;
-    }
-
-    int half = (ay * ax);
-    int full = half << 1;
-    floor_type *floor_ptr = player_ptr->current_floor_ptr;
-    int n = 0;
-    int k = 0;
-   
-    /* Vertical */
-    if (ay > ax) {
-        m = ax * ax * 2;
-        y = y1 + sy;
-        x = x1;
-        frac = m;
-        if (frac > half) {
-            x += sx;
-            frac -= full;
-            k++;
-        }
-
-        while (TRUE) {
-            gp[n++] = GRID(y, x);
-            if ((n + (k >> 1)) >= range)
-                break;
-
-            if (!(flg & PROJECT_THRU)) {
-                if ((x == x2) && (y == y2))
-                    break;
-            }
-
-            if (flg & PROJECT_DISI) {
-                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
-                    break;
-            } else if (flg & PROJECT_LOS) {
-                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
-                    break;
-            } else if (!(flg & PROJECT_PATH)) {
-                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
-                    break;
-            }
-
-            if (flg & PROJECT_STOP) {
-                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                    break;
-            }
-
-            if (!in_bounds(floor_ptr, y, x))
-                break;
-
-            if (m) {
-                frac += m;
-                if (frac > half) {
-                    x += sx;
-                    frac -= full;
-                    k++;
-                }
-            }
-
-            y += sy;
-        }
-
-        return n;
-    }
-
-    /* Horizontal */
-    if (ax > ay) {
-        m = ay * ay * 2;
-        y = y1;
-        x = x1 + sx;
-        frac = m;
-        if (frac > half) {
-            y += sy;
-            frac -= full;
-            k++;
-        }
-
-        while (TRUE) {
-            gp[n++] = GRID(y, x);
-            if ((n + (k >> 1)) >= range)
-                break;
-
-            if (!(flg & (PROJECT_THRU))) {
-                if ((x == x2) && (y == y2))
-                    break;
-            }
-
-            if (flg & (PROJECT_DISI)) {
-                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
-                    break;
-            } else if (flg & (PROJECT_LOS)) {
-                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
-                    break;
-            } else if (!(flg & (PROJECT_PATH))) {
-                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
-                    break;
-            }
-
-            if (flg & (PROJECT_STOP)) {
-                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                    break;
-            }
-
-            if (!in_bounds(floor_ptr, y, x))
-                break;
-
-            if (m) {
-                frac += m;
-                if (frac > half) {
-                    y += sy;
-                    frac -= full;
-                    k++;
-                }
-            }
-
-            x += sx;
-        }
-
-        return n;
-    }
-
-    y = y1 + sy;
-    x = x1 + sx;
-
-    while (TRUE) {
-        gp[n++] = GRID(y, x);
-        if ((n + (n >> 1)) >= range)
-            break;
-
-        if (!(flg & (PROJECT_THRU))) {
-            if ((x == x2) && (y == y2))
-                break;
-        }
-
-        if (flg & (PROJECT_DISI)) {
-            if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
-                break;
-        } else if (flg & (PROJECT_LOS)) {
-            if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
-                break;
-        } else if (!(flg & (PROJECT_PATH))) {
-            if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
-                break;
-        }
-
-        if (flg & (PROJECT_STOP)) {
-            if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
-                break;
-        }
-
-        if (!in_bounds(floor_ptr, y, x))
-            break;
-
-        y += sy;
-        x += sx;
-    }
-
-    return n;
-}
-
-/*!
  * @brief 指定のマスを床地形に変える / Set a square to be floor.  (Includes range checking.)
  * @param player_ptr プレーヤーへの参照ポインタ
  * @param x 地形を変えたいマスのX座標
index 5075383..144ecab 100644 (file)
@@ -5,12 +5,6 @@
 extern floor_type floor_info;
 
 /*
- * Convert a "location" (Y,X) into a "grid" (G)
- */
-#define GRID(Y,X) \
-       (256 * (Y) + (X))
-
-/*
  * Convert a "grid" (G) into a "location" (Y)
  */
 #define GRID_Y(G) \
@@ -40,7 +34,6 @@ void wipe_o_list(floor_type *floor_ptr);
 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y);
 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat);
 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num);
-int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);
 void set_floor(player_type *player_ptr, POSITION x, POSITION y);
 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode);
 void place_gold(player_type *player_ptr, POSITION y, POSITION x);
index 7e3bbe6..a57ae2f 100644 (file)
@@ -12,6 +12,7 @@
 #include "grid/grid.h"
 #include "io/screen-util.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "term/term-color-types.h"
 #include "view/display-map.h"
 #include "window/main-window-util.h"
index d9d9b47..e95dc2e 100644 (file)
@@ -42,6 +42,7 @@
 #include "status/element-resistance.h"
 #include "status/temporary-resistance.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "target/target-checker.h"
 #include "target/target-getter.h"
 #include "util/bit-flags-calculator.h"
index 045e5cb..39cea85 100644 (file)
@@ -51,6 +51,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "util/bit-flags-calculator.h"
 #include "view/display-messages.h"
 #include "world/world.h"
index 419bf26..8695197 100644 (file)
@@ -28,6 +28,7 @@
 #include "spell/range-calc.h"
 #include "spell/spell-types.h"
 #include "system/floor-type-definition.h"
+#include "target/projection-path-calculator.h"
 
 /*!
  * @brief モンスターが敵対モンスターにビームを当てること可能かを判定する /
index faef529..b17a844 100644 (file)
@@ -15,6 +15,7 @@
 #include "monster/monster-update.h"
 #include "system/floor-type-definition.h"
 #include "system/object-type-definition.h"
+#include "target/projection-path-calculator.h"
 #include "target/target-checker.h"
 #include "target/target-setter.h"
 #include "target/target-types.h"
@@ -135,7 +136,7 @@ bool fetch_monster(player_type *caster_ptr)
     m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
     monster_desc(caster_ptr, m_name, m_ptr, 0);
     msg_format(_("%sを引き戻した。", "You pull back %s."), m_name);
-    path_n = project_path(caster_ptr, path_g, get_max_range(caster_ptr), target_row, target_col, caster_ptr->y, caster_ptr->x, 0);
+    path_n = projection_path(caster_ptr, path_g, get_max_range(caster_ptr), target_row, target_col, caster_ptr->y, caster_ptr->x, 0);
     ty = target_row, tx = target_col;
     for (i = 1; i < path_n; i++) {
         POSITION ny = GRID_Y(path_g[i]);
diff --git a/src/target/projection-path-calculator.c b/src/target/projection-path-calculator.c
new file mode 100644 (file)
index 0000000..21bb41b
--- /dev/null
@@ -0,0 +1,211 @@
+#include "target/projection-path-calculator.h"
+#include "effect/effect-characteristics.h"
+#include "floor/cave.h"
+#include "grid/feature-flag-types.h"
+#include "grid/grid.h"
+#include "system/floor-type-definition.h"
+
+/*
+ * @brief Convert a "location" (Y, X) into a "grid" (G)
+ * @param y Y\8dÀ\95W
+ * @param x X\8dÀ\95W
+ * return \8co\98H\8dÀ\95W
+ */
+static u16b location_to_grid(POSITION y, POSITION x) { return 256 * y + x; }
+
+/*!
+ * @brief \8en\93_\82©\82ç\8fI\93_\82Ö\82Ì\92¼\90ü\8co\98H\82ð\95Ô\82· /
+ * Determine the path taken by a projection.
+ * @param player_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
+ * @param gp \8co\98H\8dÀ\95W\83\8a\83X\83g\82ð\95Ô\82·\8eQ\8fÆ\83|\83C\83\93\83^
+ * @param range \8b\97\97£
+ * @param y1 \8en\93_Y\8dÀ\95W
+ * @param x1 \8en\93_X\8dÀ\95W
+ * @param y2 \8fI\93_Y\8dÀ\95W
+ * @param x2 \8fI\93_X\8dÀ\95W
+ * @param flg \83t\83\89\83OID
+ * @return \83\8a\83X\83g\82Ì\92·\82³
+ */
+int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
+{
+    if ((x1 == x2) && (y1 == y2))
+        return 0;
+
+    POSITION y, x;
+    POSITION ay, ax;
+    POSITION sy, sx;
+    int frac;
+    int m;
+
+    if (y2 < y1) {
+        ay = (y1 - y2);
+        sy = -1;
+    } else {
+        ay = (y2 - y1);
+        sy = 1;
+    }
+
+    if (x2 < x1) {
+        ax = (x1 - x2);
+        sx = -1;
+    } else {
+        ax = (x2 - x1);
+        sx = 1;
+    }
+
+    int half = (ay * ax);
+    int full = half << 1;
+    floor_type *floor_ptr = player_ptr->current_floor_ptr;
+    int n = 0;
+    int k = 0;
+
+    /* Vertical */
+    if (ay > ax) {
+        m = ax * ax * 2;
+        y = y1 + sy;
+        x = x1;
+        frac = m;
+        if (frac > half) {
+            x += sx;
+            frac -= full;
+            k++;
+        }
+
+        while (TRUE) {
+            gp[n++] = location_to_grid(y, x);
+            if ((n + (k >> 1)) >= range)
+                break;
+
+            if (!(flg & PROJECT_THRU)) {
+                if ((x == x2) && (y == y2))
+                    break;
+            }
+
+            if (flg & PROJECT_DISI) {
+                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                    break;
+            } else if (flg & PROJECT_LOS) {
+                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                    break;
+            } else if (!(flg & PROJECT_PATH)) {
+                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                    break;
+            }
+
+            if (flg & PROJECT_STOP) {
+                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                    break;
+            }
+
+            if (!in_bounds(floor_ptr, y, x))
+                break;
+
+            if (m) {
+                frac += m;
+                if (frac > half) {
+                    x += sx;
+                    frac -= full;
+                    k++;
+                }
+            }
+
+            y += sy;
+        }
+
+        return n;
+    }
+
+    /* Horizontal */
+    if (ax > ay) {
+        m = ay * ay * 2;
+        y = y1;
+        x = x1 + sx;
+        frac = m;
+        if (frac > half) {
+            y += sy;
+            frac -= full;
+            k++;
+        }
+
+        while (TRUE) {
+            gp[n++] = location_to_grid(y, x);
+            if ((n + (k >> 1)) >= range)
+                break;
+
+            if (!(flg & (PROJECT_THRU))) {
+                if ((x == x2) && (y == y2))
+                    break;
+            }
+
+            if (flg & (PROJECT_DISI)) {
+                if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                    break;
+            } else if (flg & (PROJECT_LOS)) {
+                if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                    break;
+            } else if (!(flg & (PROJECT_PATH))) {
+                if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                    break;
+            }
+
+            if (flg & (PROJECT_STOP)) {
+                if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                    break;
+            }
+
+            if (!in_bounds(floor_ptr, y, x))
+                break;
+
+            if (m) {
+                frac += m;
+                if (frac > half) {
+                    y += sy;
+                    frac -= full;
+                    k++;
+                }
+            }
+
+            x += sx;
+        }
+
+        return n;
+    }
+
+    y = y1 + sy;
+    x = x1 + sx;
+
+    while (TRUE) {
+        gp[n++] = location_to_grid(y, x);
+        if ((n + (n >> 1)) >= range)
+            break;
+
+        if (!(flg & PROJECT_THRU)) {
+            if ((x == x2) && (y == y2))
+                break;
+        }
+
+        if (flg & PROJECT_DISI) {
+            if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x))
+                break;
+        } else if (flg & PROJECT_LOS) {
+            if ((n > 0) && !cave_los_bold(floor_ptr, y, x))
+                break;
+        } else if (!(flg & PROJECT_PATH)) {
+            if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT))
+                break;
+        }
+
+        if (flg & PROJECT_STOP) {
+            if ((n > 0) && (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
+                break;
+        }
+
+        if (!in_bounds(floor_ptr, y, x))
+            break;
+
+        y += sy;
+        x += sx;
+    }
+
+    return n;
+}
diff --git a/src/target/projection-path-calculator.h b/src/target/projection-path-calculator.h
new file mode 100644 (file)
index 0000000..97709d3
--- /dev/null
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "system/angband.h"
+
+int projection_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);