summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-01-19 12:24:25 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-01-19 12:24:25 +0100
commit0b57bfb1840d0020634c413ef6d4a0f2d88ced99 (patch)
tree24d29191dbe5c6b3521e5db481e87e3826a0dc4c /core
parent51f534e24dc3406851693990ad2dc748ae642816 (diff)
downloadRustAndDust-0b57bfb1840d0020634c413ef6d4a0f2d88ced99.zip
RustAndDust-0b57bfb1840d0020634c413ef6d4a0f2d88ced99.tar.gz
PossiblePaths: add boolean canExit(Orientation o)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/PossiblePaths.java21
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateMove.java6
2 files changed, 22 insertions, 5 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
index f45b3ac..49a317f 100644
--- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
+++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java
@@ -207,6 +207,27 @@ public class PossiblePaths implements Disposable
return move;
}
+ public boolean canExit(Orientation o)
+ {
+ List<Path> ps;
+ if (ctrlTiles.size() == 0)
+ ps = paths;
+ else
+ ps = filteredPaths;
+
+ int mvt = pawn.getMovementPoints();
+ int rBonus = pawn.getRoadMarchBonus();
+ boolean road = to.road(o);
+ int cost = to.exitCost();
+
+ for (Path p : ps) {
+ int c = (p.cost + cost);
+ if ((c <= mvt) || (p.roadMarch && road && (c <= (mvt + rBonus))))
+ return true;
+ }
+ return false;
+ }
+
public Path getPath(int i)
{
if (ctrlTiles.size() == 0)
diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java
index 7f2767b..b388862 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java
@@ -184,12 +184,8 @@ public class StateMove extends StateCommon
Zone exitZone = ctrl.battle.getExitZone(unit);
if ((exitZone == null) || !exitZone.contains(hex))
return false;
- if (map.possiblePaths.size() == 1) {
- // TODO pathCost called with applayToPawn from Board it updates Pawn.move
- int left = (unit.getMovementPoints() - map.possiblePaths.pathCost(0));
- if (left < 1)
+ if (!map.possiblePaths.canExit(exitZone.orientation))
return false;
- }
ctrl.setState(StateType.ESCAPE);
return true;
}