summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch')
-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;
}