diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 09:45:24 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-13 09:45:24 +0200 |
commit | a3a8863729297d23d2f5b3d9dbc652f314205b32 (patch) | |
tree | 9bf39ce2fced9edbeb745ce3a73be973c48694f2 | |
parent | 2070da5b0cef71095a997107b79e2920dff16bd7 (diff) | |
download | RustAndDust-a3a8863729297d23d2f5b3d9dbc652f314205b32.zip RustAndDust-a3a8863729297d23d2f5b3d9dbc652f314205b32.tar.gz |
SearchBoard: add validatePathAngle(...) check angle of attack of successful LOS
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index df3c68b..c628363 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -336,7 +336,7 @@ public class SearchBoard dst.remaining = rangeLeft; queue.add(dst); Tile t = board.getTile(dst.col, dst.row); - if (t.hasTargetsFor(pawn) && hasClearLineOfSight(from, dst)) targets.add(dst); + if (t.hasTargetsFor(pawn) && hasClearLineOfSight(from, dst, angle)) targets.add(dst); } } } @@ -351,15 +351,33 @@ public class SearchBoard Node to = getNode(col1, row1); Tile tile = board.getTile(col0, row0); - if (distance(from, to) > pawn.getAttackRangeFrom(tile)) return false; - return hasClearLineOfSight(from, to); + if (distance(from, to) > pawn.getAttackRangeFrom(tile)) + return false; + return hasClearLineOfSight(from, to, pawn.getAngleOfAttack()); } - private boolean hasClearLineOfSight(Node from, Node to) + private boolean hasClearLineOfSight(Node from, Node to, int angleOfAttack) { List<Node> nodes = lineOfSight(from.col, from.row, to.col, to.row); Node last = nodes.get(nodes.size() -1); - return ((last.col == to.col) && (last.row == to.row)); + if ((last.col != to.col) || (last.row != to.row)) + return false; + return validatePathAngle(angleOfAttack, nodes); + } + + public boolean validatePathAngle(int angle, List<Node> nodes) + { + Node prev = null; + for (Node next : nodes) { + if (prev != null) { + Orientation o = Orientation.fromMove(prev.col, prev.row, next.col, next.row); + if (!o.isInSides(angle)) + return false; + } + prev = next; + } + + return true; } public List<Node> lineOfSight(int x0, int y0, int x1, int y1) |