OSDN Git Service

[Refactor] #37353 mmove2() を geometry.c/h に移動。
authordeskull <deskull@users.sourceforge.jp>
Wed, 17 Apr 2019 14:15:51 +0000 (23:15 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Wed, 17 Apr 2019 14:15:51 +0000 (23:15 +0900)
src/externs.h
src/geometry.c
src/geometry.h
src/grid.c

index 1f506a3..498d8e8 100644 (file)
@@ -449,7 +449,6 @@ extern FEAT_IDX feat_state(FEAT_IDX feat, int action);
 extern void cave_alter_feat(POSITION y, POSITION x, int action);
 extern void remove_mirror(POSITION y, POSITION x);
 
-extern void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern void health_track(MONSTER_IDX m_idx);
 extern void monster_race_track(MONRACE_IDX r_idx);
 extern void object_kind_track(KIND_OBJECT_IDX k_idx);
index ec73947..8307ba5 100644 (file)
@@ -439,3 +439,57 @@ void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT
        (*xp) = nx;
 }
 
+/*
+ * Calculate "incremental motion". Used by project() and shoot().
+ * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
+ */
+void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
+{
+       POSITION dy, dx, dist, shift;
+
+       /* Extract the distance travelled */
+       dy = (*y < y1) ? y1 - *y : *y - y1;
+       dx = (*x < x1) ? x1 - *x : *x - x1;
+
+       /* Number of steps */
+       dist = (dy > dx) ? dy : dx;
+
+       /* We are calculating the next location */
+       dist++;
+
+
+       /* Calculate the total distance along each axis */
+       dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
+       dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
+
+       /* Paranoia -- Hack -- no motion */
+       if (!dy && !dx) return;
+
+
+       /* Move mostly vertically */
+       if (dy > dx)
+       {
+               /* Extract a shift factor */
+               shift = (dist * dx + (dy - 1) / 2) / dy;
+
+               /* Sometimes move along the minor axis */
+               (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
+
+               /* Always move along major axis */
+               (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
+       }
+
+       /* Move mostly horizontally */
+       else
+       {
+               /* Extract a shift factor */
+               shift = (dist * dy + (dx - 1) / 2) / dx;
+
+               /* Sometimes move along the minor axis */
+               (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
+
+               /* Always move along major axis */
+               (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
+       }
+}
+
index 1b0da5c..742a84a 100644 (file)
@@ -25,6 +25,7 @@ extern sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POS
 
 extern bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 extern void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode);
+extern void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
 
 //!< 対象グリッドの一覧をまとめる構造体
 typedef struct
index 80cdcd4..854bcdd 100644 (file)
@@ -5325,63 +5325,6 @@ bool is_explosive_rune_grid(grid_type *g_ptr)
 
 
 /*
- * Calculate "incremental motion". Used by project() and shoot().
- * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
- */
-void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
-{
-       POSITION dy, dx, dist, shift;
-
-       /* Extract the distance travelled */
-       dy = (*y < y1) ? y1 - *y : *y - y1;
-       dx = (*x < x1) ? x1 - *x : *x - x1;
-
-       /* Number of steps */
-       dist = (dy > dx) ? dy : dx;
-
-       /* We are calculating the next location */
-       dist++;
-
-
-       /* Calculate the total distance along each axis */
-       dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
-       dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
-
-       /* Paranoia -- Hack -- no motion */
-       if (!dy && !dx) return;
-
-
-       /* Move mostly vertically */
-       if (dy > dx)
-       {
-               /* Extract a shift factor */
-               shift = (dist * dx + (dy - 1) / 2) / dy;
-
-               /* Sometimes move along the minor axis */
-               (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
-
-               /* Always move along major axis */
-               (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
-       }
-
-       /* Move mostly horizontally */
-       else
-       {
-               /* Extract a shift factor */
-               shift = (dist * dy + (dx - 1) / 2) / dx;
-
-               /* Sometimes move along the minor axis */
-               (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
-
-               /* Always move along major axis */
-               (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
-       }
-}
-
-
-
-
-/*
  * Track a new monster
  */
 void health_track(MONSTER_IDX m_idx)