summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-30 01:02:06 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-30 01:02:06 +0200
commitd1d29ff0fea471168a23eefeaf8608c69556ac51 (patch)
tree8510cb4c65d34252f23f78f81c5e25b1a43df3fa
parent26010226c374741a0edf8bdba5e94de2d0d9815c (diff)
downloadRustAndDust-d1d29ff0fea471168a23eefeaf8608c69556ac51.zip
RustAndDust-d1d29ff0fea471168a23eefeaf8608c69556ac51.tar.gz
SearchBoard: add diagonalLineOfSight(...)
-rw-r--r--core/src/ch/asynk/tankontank/engine/SearchBoard.java34
1 files changed, 33 insertions, 1 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
index 583c2c8..57e75cf 100644
--- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java
+++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java
@@ -317,8 +317,11 @@ public class SearchBoard
Math.abs(dx);
}
}
+
if (dx == 0)
return verticalLineOfSight(x0, y0, x1, y1, check);
+ if (dx == (3 * dy))
+ return diagonalLineOfSight(x0, y0, x1, y1, check);
int dx3 = 3 * dx;
int dy3 = 3 * dy;
@@ -327,7 +330,6 @@ public class SearchBoard
int y = y0;
int e = -2 * dx;
- boolean vert = (dx == 0);
boolean flat = (dx > (3 * dy));
boolean diag = (dx == (3 * dy));
@@ -385,4 +387,34 @@ public class SearchBoard
return los;
}
+
+ private List<Node> diagonalLineOfSight(int x0, int y0, int x1, int y1, boolean check)
+ {
+ int dy = ( (y1 > y0) ? 1 : -1);
+ int dx = ( (x1 > x0) ? 1 : -1);
+ boolean sig = !(((dx < 0) && (dy >= 0)) || ((dx >= 0) && (dy < 0)));
+
+ int x = x0;
+ int y = y0;
+
+ Tile t = null;
+ los.add(getNode(x, y));
+ while((x != x1) || (y != y1)) {
+ x += dx;
+ t = board.getTile(x, y);
+ if (!t.isOffMap()) los.add(getNode(x, y));
+
+ y += dy;
+ if (!sig)
+ x -= dx;
+ t = board.getTile(x, y);
+ if (!t.isOffMap()) los.add(getNode(x, y));
+
+ x += dx;
+ t = board.getTile(x, y);
+ if (!t.isOffMap()) los.add(getNode(x, y));
+ }
+
+ return los;
+ }
}