From 0b083495c6ace256c01bc1ac57099fe511b1c334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 29 Oct 2015 14:48:58 +0100 Subject: SearchBoard: validatePathAngle -> validateFireAngle + fix, works like isFlankAttack --- .../ch/asynk/rustanddust/engine/SearchBoard.java | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index eda9055..7393352 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -335,7 +335,7 @@ public class SearchBoard if (los.get(los.size() -1) != to) return false; - if (!validatePathAngle(shooter.getAngleOfAttack(), los)) + if (!validateFireAngle(shooter.getAngleOfAttack(), los)) return false; shooter.attack.isClear = isClearAttack(getTile(from), los); @@ -350,7 +350,7 @@ public class SearchBoard Node last = los.get(los.size() -1); if ((last.col != to.col) || (last.row != to.row)) return false; - return validatePathAngle(angleOfAttack, los); + return validateFireAngle(angleOfAttack, los); } private boolean isFlankAttack(int angle, List los) @@ -380,24 +380,21 @@ public class SearchBoard return true; } - private boolean validatePathAngle(int angle, List los) + private boolean validateFireAngle(int angle, List los) { - int forth = 0; - Node prev = null; - for (Node next : los) { - if (prev != null) { - Orientation o = Orientation.fromMove(prev.col, prev.row, next.col, next.row); - if (!o.isInSides(angle)) { - forth -= 1; - if (forth < 0) - return false; - } - forth += 1; - } - prev = next; - } + Node from = los.get(0); + Node p0 = los.get(1); + Orientation o = Orientation.fromMove(from.col, from.row, p0.col, p0.row); - return true; + if (los.size() < 3) + return o.isInSides(angle); + + Node p1 = los.get(2); + if (distance(from, p1) > 1) + return o.isInSides(angle); + + Orientation o2 = Orientation.fromMove(from.col, from.row, p1.col, p1.row); + return (o.isInSides(angle) || o2.isInSides(angle)); } public List lineOfSight(int x0, int y0, int x1, int y1, boolean clearVisibility) -- cgit v1.1-2-g2b99