summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-10-29 14:48:58 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-10-29 14:48:58 +0100
commit0b083495c6ace256c01bc1ac57099fe511b1c334 (patch)
treeb2584e7e5bac8d4e426840f4dcf7f2f4c033eceb /core/src/ch/asynk/rustanddust/engine
parent7461e96feeac507345ec454fe0b3b097162c6ccb (diff)
downloadRustAndDust-0b083495c6ace256c01bc1ac57099fe511b1c334.zip
RustAndDust-0b083495c6ace256c01bc1ac57099fe511b1c334.tar.gz
SearchBoard: validatePathAngle -> validateFireAngle + fix, works like isFlankAttack
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/SearchBoard.java33
1 files 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<Node> los)
@@ -380,24 +380,21 @@ public class SearchBoard
return true;
}
- private boolean validatePathAngle(int angle, List<Node> los)
+ private boolean validateFireAngle(int angle, List<Node> 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<Node> lineOfSight(int x0, int y0, int x1, int y1, boolean clearVisibility)