summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/states
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-05-03 15:31:32 +0200
commit79793cf2dd5cad2af5fa513a7213292d2ee53f86 (patch)
tree306e849be86d992a543e42c8e8ddec80d24795a6 /core/src/ch/asynk/rustanddust/game/states
parentcff800a98e8aec4e454c5dc84fd4249b7127a1fd (diff)
downloadRustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.zip
RustAndDust-79793cf2dd5cad2af5fa513a7213292d2ee53f86.tar.gz
OMG: add event queue, messages, replay, bounce animation, complete states rewrite ...
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/states')
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateAnimation.java18
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateBreak.java76
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateCommon.java28
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateDeployment.java111
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateEngage.java175
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateMove.java336
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StatePromote.java22
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java64
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateReplay.java98
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateRotate.java103
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateSelect.java133
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java64
12 files changed, 575 insertions, 653 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java
index c19f16b..4c6a965 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java
@@ -5,23 +5,7 @@ public class StateAnimation extends StateCommon
@Override
public void enterFrom(StateType prevState)
{
+ ctrl.blockMap = true;
ctrl.hud.actionButtons.hide();
}
-
- @Override
- public void leaveFor(StateType nextState)
- {
- }
-
- @Override
- public StateType abort()
- {
- return StateType.ABORT;
- }
-
- @Override
- public StateType execute()
- {
- return StateType.DONE;
- }
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java
deleted file mode 100644
index 1dab40b..0000000
--- a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package ch.asynk.rustanddust.game.states;
-
-import ch.asynk.rustanddust.engine.Orientation;
-import ch.asynk.rustanddust.game.Hex;
-import ch.asynk.rustanddust.game.Unit;
-import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
-
-public class StateBreak extends StateCommon
-{
- private Orientation o = Orientation.KEEP;
-
- @Override
- public void enterFrom(StateType prevState)
- {
- activeUnit = null;
- ctrl.hud.actionButtons.show(Buttons.DONE.b);
- ctrl.hud.notify("Break Through possible");
- map.unitsActivableShow();
- }
-
- @Override
- public void leaveFor(StateType nextState)
- {
- map.unitsActivableHide();
- map.hexMoveHide(to);
- map.hexDirectionsHide(to);
- if (activeUnit != null) map.hexMoveHide(activeUnit.getHex());
- }
-
- @Override
- public StateType abort()
- {
- return StateType.ABORT;
- }
-
- @Override
- public StateType execute()
- {
- return StateType.DONE;
- }
-
- @Override
- public void touch(Hex hex)
- {
- // TODO : cancel preview move before showing rotation
- if (activeUnit == null) {
- Unit unit = hex.getUnit();
- if (map.unitsActivableContains(unit)) {
- activeUnit = unit;
- map.hexMoveShow(hex);
- map.hexMoveShow(to);
- map.hexDirectionsShow(to);
- map.unitsActivableHide();
- }
- } else {
- o = Orientation.fromAdj(to, hex);
-
- if (o == Orientation.KEEP) return;
-
- doRotation(o);
- ctrl.post(StateType.ANIMATION);
- }
- }
-
- private void doRotation(Orientation o)
- {
- if (activeUnit == null) return;
-
- map.pathsInit(activeUnit);
- map.pathsBuild(to);
- map.pathsChooseShortest();
- map.pathsSetOrientation(o);
- map.moveUnit(activeUnit);
- ctrl.setAfterAnimationState(StateType.DONE);
- }
-}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java
index b894c0f..1614465 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java
@@ -1,12 +1,13 @@
package ch.asynk.rustanddust.game.states;
+import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.game.Map;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.Ctrl;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.State;
import ch.asynk.rustanddust.game.Config;
-import ch.asynk.rustanddust.RustAndDust;
public abstract class StateCommon implements State
{
@@ -17,7 +18,6 @@ public abstract class StateCommon implements State
protected static Hex selectedHex = null;
protected static Hex to = null;
- protected boolean isEnemy;
protected static Unit activeUnit;
protected static Unit selectedUnit;
@@ -28,26 +28,12 @@ public abstract class StateCommon implements State
map = game.ctrl.map;
}
- protected boolean hasUnit()
- {
- return (selectedUnit != null);
- }
-
- protected void showPossibilities(Unit unit)
- {
- if (cfg.showMoves && unit.canMove()) map.movesShow();
- if (cfg.showTargets && unit.canEngage()) map.unitsTargetShow();
- if (cfg.showMoveAssists && unit.canMove()) map.unitsActivableShow();
- unit.hideActiveable();
- }
+ @Override
+ public void touch(Hex hex) { }
- protected void hidePossibilities()
+ @Override
+ public boolean processMsg(MsgType state, Object data)
{
- map.movesHide();
- map.unitsTargetHide();
- map.unitsActivableHide();
+ return false;
}
-
- @Override
- public void touch(Hex hex) { }
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
index f967917..27ed7b8 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
@@ -5,6 +5,7 @@ import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Zone;
import ch.asynk.rustanddust.game.Unit;
import ch.asynk.rustanddust.game.UnitList;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
public class StateDeployment extends StateCommon
@@ -15,55 +16,48 @@ public class StateDeployment extends StateCommon
@Override
public void enterFrom(StateType prevState)
{
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
- entryZone = null;
- selectedHex = null;
- selectedUnit = null;
- ctrl.hud.actionButtons.hide();
+ clear();
ctrl.hud.playerInfo.unitDock.show();
}
@Override
- public void leaveFor(StateType nextState)
- {
- selectedUnit = null;
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
- if (entryZone != null)
- entryZone.enable(Hex.AREA, false);
- ctrl.hud.playerInfo.unitDock.hide();
- }
-
- @Override
- public StateType abort()
+ public boolean processMsg(MsgType msg, Object data)
{
- if (activeUnit != null)
- undo();
- return StateType.DEPLOYMENT;
- }
+ switch(msg)
+ {
+ case UNIT_DOCK_SELECT:
+ showEntryZone((Unit) data);
+ return true;
+ case CANCEL:
+ if (activeUnit != null)
+ undeployUnit();
+ return true;
+ case OK:
+ deployedUnits.clear();
+ ctrl.postTurnDone();
+ return true;
+ case UNIT_DEPLOYED:
+ deployedUnits.add((Unit) data);
+ return true;
+ case UNIT_UNDEPLOYED:
+ ctrl.battle.getPlayer().revertUnitEntry((Unit) data);
+ return true;
+ }
- @Override
- public StateType execute()
- {
- deployedUnits.clear();
- return StateType.DONE;
+ return false;
}
@Override
public void touch(Hex hex)
{
- Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit;
- if (hex == null) {
- showEntryZone(unit);
- } else if (selectedUnit != null) {
+ if (activeUnit != null) {
deployUnit(Orientation.fromAdj(selectedHex, hex));
- } else if (!ctrl.battle.isDeploymentDone() && (entryZone != null) && (hex != null)) {
+ } else if ((selectedUnit != null) && (entryZone != null)) {
if (hex.isEmpty() && entryZone.contains(hex)) {
- showUnit(activeUnit, hex);
+ showUnit(selectedUnit, hex);
}
} else {
- unit = hex.getUnit();
+ Unit unit = hex.getUnit();
if (deployedUnits.contains(unit))
showRotation(unit, hex);
}
@@ -71,28 +65,19 @@ public class StateDeployment extends StateCommon
private void showEntryZone(Unit unit)
{
- activeUnit = unit;
- if (entryZone != null) entryZone.enable(Hex.AREA, false);
- entryZone = activeUnit.entryZone;
+ selectedUnit = unit;
+ if (entryZone != null)
+ entryZone.enable(Hex.AREA, false);
+ entryZone = unit.entryZone;
entryZone.enable(Hex.AREA, true);
}
- private void undo()
- {
- map.hexUnselect(selectedHex);
- map.hexDirectionsHide(selectedHex);
- map.revertEnter(activeUnit);
- activeUnit = null;
- selectedUnit = null;
- ctrl.hud.update();
- }
-
private void showUnit(Unit unit, Hex hex)
{
- selectedUnit = unit;
+ activeUnit = unit;
selectedHex = hex;
ctrl.battle.getPlayer().reinforcement.remove(unit);
- map.showOnBoard(unit, hex, entryZone.orientation);
+ map.setOnBoard(unit, hex, entryZone.orientation);
deployedUnits.add(unit);
entryZone.enable(Hex.AREA, false);
showRotation(unit, hex);
@@ -102,7 +87,6 @@ public class StateDeployment extends StateCommon
private void showRotation(Unit unit, Hex hex)
{
activeUnit = unit;
- selectedUnit = unit;
selectedHex = hex;
map.hexSelect(selectedHex);
map.hexDirectionsShow(selectedHex);
@@ -113,16 +97,29 @@ public class StateDeployment extends StateCommon
private void deployUnit(Orientation o)
{
if (o == Orientation.KEEP)
- o = selectedUnit.getOrientation();
- map.setOnBoard(selectedUnit, selectedHex, o);
+ o = activeUnit.getOrientation();
+ ctrl.postOrder(map.getSetOrder(activeUnit, selectedHex, o), StateType.DEPLOYMENT);
+ clear();
+ }
- entryZone = null;
+ private void undeployUnit()
+ {
+ ctrl.postOrder(map.getRevertSetOrder(activeUnit), StateType.DEPLOYMENT);
+ ctrl.hud.update();
+ clear();
+ ctrl.hud.playerInfo.unitDock.show();
+ }
+
+ private void clear()
+ {
+ if (selectedHex != null) {
+ map.hexUnselect(selectedHex);
+ map.hexDirectionsHide(selectedHex);
+ }
activeUnit = null;
+ entryZone = null;
+ selectedHex = null;
selectedUnit = null;
- map.hexUnselect(selectedHex);
- map.hexDirectionsHide(selectedHex);
ctrl.hud.actionButtons.hide();
- ctrl.hud.playerInfo.unitDock.show();
- ctrl.post(StateType.DONE);
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
index bfeced8..ccd79c7 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
@@ -1,89 +1,158 @@
package ch.asynk.rustanddust.game.states;
+import ch.asynk.rustanddust.engine.Orientation;
+import ch.asynk.rustanddust.ui.Position;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Order;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
+import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
public class StateEngage extends StateCommon
{
+ // selectedUnit -> fire leader
+ // activeUnit -> target / break
+
+ private boolean breakMove = false;
+
@Override
public void enterFrom(StateType prevState)
{
if (prevState == StateType.SELECT) {
- // activeUnit will be target
- activeUnit = null;
- if (to != null) {
- // quick fire -> replay touchUp
- touch(to);
+ breakMove = false;
+ if ((to != null) && (activeUnit != null)) {
+ // quick fire
+ selectTarget(activeUnit, to);
}
selectedUnit.showAttack();
map.hexSelect(selectedHex);
+ } else {
+ breakMove = true;
+ activeUnit = null;
+ ctrl.hud.actionButtons.show(Buttons.DONE.b);
+ ctrl.hud.notify("Break Through possible", Position.MIDDLE_CENTER);
+ map.unitsActivableShow();
+ map.hexUnselect(selectedHex);
}
}
@Override
- public void leaveFor(StateType nextState)
+ public boolean processMsg(MsgType msg, Object data)
+ {
+ switch(msg)
+ {
+ case OK:
+ if (breakMove)
+ abortBreakMove();
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public void touch(Hex hex)
+ {
+ Unit unit = hex.getUnit();
+
+ if (!breakMove) {
+ if (unit == selectedUnit)
+ abort();
+ else if ((activeUnit == null) && map.unitsTargetContains(unit))
+ selectTarget(unit, hex);
+ else if (unit == activeUnit)
+ engage();
+ else if ((activeUnit != null) && map.unitsActivableContains(unit))
+ map.toggleAssist(unit);
+ } else {
+ if (activeUnit == null) {
+ if (map.unitsActivableContains(unit))
+ selectBreakUnit(unit);
+ } else {
+ Orientation o = Orientation.fromAdj(to, hex);
+ if (o == Orientation.KEEP)
+ unselectBreakUnit();
+ else
+ doRotation(o);
+ }
+
+ }
+ }
+
+ private void selectTarget(Unit unit, Hex hex)
+ {
+ to = hex;
+ activeUnit = unit;
+ map.unitsTargetHide();
+ activeUnit.showTarget();
+ map.collectAssists(selectedUnit, activeUnit, ctrl.battle.getPlayer().units);
+ map.unitsAssistShow();
+ }
+
+ private void engage()
{
+ activeUnit.hideTarget();
selectedUnit.hideAttack();
map.unitsAssistHide();
- map.unitsTargetHide();
map.hexUnselect(selectedHex);
- if (to != null)
- map.hexUnselect(to);
+ Order order = map.getEngageOrder(selectedUnit, activeUnit);
+
+ if (order.cost == 0)
+ ctrl.postOrder(order, StateType.ENGAGE);
+ else {
+ order.cost = order.engagement.cost;
+ ctrl.postOrder(order);
+ }
}
- @Override
- public StateType abort()
+ private void abort()
{
+ map.unitsAssistHide();
+ map.unitsTargetHide();
+ activeUnit.hideTarget();
+ selectedUnit.hideAttack();
+ map.hexUnselect(selectedHex);
map.unitsActivatedClear();
- return StateType.ABORT;
+ ctrl.postActionAborted();
}
- @Override
- public StateType execute()
+ private void selectBreakUnit(Unit unit)
{
- map.unitsAssistHide();
- StateType nextState = StateType.DONE;
- if (map.engageUnit(selectedUnit, activeUnit)) {
- ctrl.battle.getPlayer().engagementWon += 1;
- ctrl.battle.getOpponent().casualty(activeUnit);
- if (map.unitsActivableSize() > 0) {
- nextState = StateType.BREAK;
- }
- } else {
- ctrl.battle.getPlayer().engagementLost += 1;
- }
+ activeUnit = unit;
+ map.hexMoveShow(to);
+ map.hexMoveShow(unit.getHex());
+ map.hexDirectionsShow(to);
+ map.unitsActivableHide();
+ }
- activeUnit.showTarget();
- ctrl.setAfterAnimationState(nextState);
- return StateType.ANIMATION;
+ private void unselectBreakUnit()
+ {
+ map.hexMoveHide(to);
+ map.hexMoveHide(activeUnit.getHex());
+ map.hexDirectionsHide(to);
+ map.unitsActivableShow();
+ activeUnit = null;
}
- @Override
- public void touch(Hex hex)
+ private void doRotation(Orientation o)
{
- Unit unit = hex.getUnit();
+ map.hexMoveHide(to);
+ map.hexMoveHide(activeUnit.getHex());
+ map.hexDirectionsHide(to);
+ map.pathsInit(activeUnit);
+ map.pathsBuild(to);
+ map.pathsChooseShortest();
+ map.pathsSetOrientation(o);
+ ctrl.postOrder(map.getMoveOrder(activeUnit, false));
+ }
- // activeUnit is the target, selectedTarget is the engagement leader
- if (unit == selectedUnit) {
- ctrl.post(StateType.ABORT);
- } else if ((activeUnit == null) && map.unitsTargetContains(unit)) {
- // ctrl.hud.notify("Engage " + unit);
- map.unitsTargetHide();
- to = hex;
- activeUnit = unit;
- activeUnit.showTarget();
- map.collectAssists(selectedUnit, activeUnit, ctrl.battle.getPlayer().units);
- map.unitsAssistShow();
- }
- else if (unit == activeUnit) {
- ctrl.post(StateType.DONE);
- }
- else if ((activeUnit != null) && map.unitsActivableContains(unit)) {
- map.toggleAssist(unit);
- // if (map.toggleAssist(unit))
- // ctrl.hud.notify(unit + " will fire");
- // else
- // ctrl.hud.notify(unit + " wont fire");
- }
+ private void abortBreakMove()
+ {
+ if (activeUnit != null)
+ map.hexMoveHide(activeUnit.getHex());
+ map.hexMoveHide(to);
+ map.hexDirectionsHide(to);
+ map.unitsActivableHide();
+ ctrl.postOrder(Order.END);
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java
index 3aa684d..ae0c751 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java
@@ -1,103 +1,125 @@
package ch.asynk.rustanddust.game.states;
-import ch.asynk.rustanddust.ui.Position;
+import ch.asynk.rustanddust.engine.Orientation;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Order;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
public class StateMove extends StateCommon
{
+ enum State
+ {
+ SHOW,
+ PATH,
+ ROTATE,
+ EXIT
+ }
+
+ private State state;
+ private boolean enter;
+ private boolean hqMode;
+ private boolean notFirst;
+
@Override
public void enterFrom(StateType prevState)
{
- ctrl.hud.actionButtons.show(
- ((map.unitsActivatedSize() > 0) ? Buttons.DONE.b : 0)
- );
+ state = State.SHOW;
- if (prevState == StateType.WITHDRAW) {
- completePath(map.pathsSize());
- return;
- }
+ enter = false;
+ hqMode = false;
+ notFirst = false;
map.pathsClear();
-
if (prevState == StateType.SELECT) {
- // use selectedHex and selectedUnit
+ map.hexSelect(selectedHex);
+ map.pathsInit(selectedUnit);
activeUnit = selectedUnit;
- map.pathsInit(activeUnit);
- map.collectUpdate(activeUnit);
- if (to != null) {
- // quick move -> replay touchUp
- touch(to);
- } else
- checkExit(activeUnit);
- } else {
- // back from rotation -> chose next Pawn
- if (selectedUnit.canMove()) {
- changeUnit(selectedUnit);
+ if (to == null) {
+ hqMode = true;
+ map.movesShow();
+ } else {
+ collectPaths(to);
+ }
+ } else if (prevState == StateType.REINFORCEMENT) {
+ enter = true;
+ map.hexSelect(selectedHex);
+ map.pathsInit(selectedUnit);
+ if (selectedUnit.getMovementPoints() > 0) {
+ map.movesCollect(selectedUnit);
+ map.movesShow();
} else {
- changeUnit(map.unitsMoveableGet(0));
+ to = selectedHex;
+ showRotation(to);
+ collectPaths(to);
}
+ } else {
+ notFirst = hqMode = true;
+ selectNextUnit();
}
- map.unitsActivableShow();
+ if (hqMode)
+ map.unitsActivableShow();
activeUnit.hideActiveable();
+ int n = (notFirst ? Buttons.DONE.b : 0);
+ n |= (enter ? Buttons.ABORT.b : 0);
+ ctrl.hud.actionButtons.show(n);
}
@Override
- public void leaveFor(StateType nextState)
+ public boolean processMsg(MsgType msg, Object data)
{
- if (nextState == StateType.WITHDRAW)
- return;
-
- // hide all but assists : want them when in rotation
- activeUnit.hideActiveable();
- map.movesHide();
- map.hexUnselect(activeUnit.getHex());
- if (to != null)
- map.pathHide(to);
-
- if (nextState != StateType.SELECT) {
- if (to == null)
- to = activeUnit.getHex();
- }
- }
-
- @Override
- public StateType abort()
- {
- hideActivable();
- if (activeUnit.justEntered()) {
- map.revertEnter(activeUnit);
- return StateType.ABORT;
+ switch(msg)
+ {
+ case OK:
+ if (state == State.EXIT) {
+ exit();
+ return true;
+ }
+ if (hqMode) {
+ endHqMode();
+ return true;
+ }
+ break;
+ case CANCEL:
+ if (enter || (state == State.PATH) || (state == State.ROTATE)) {
+ abortMove();
+ return true;
+ }
+ if (state == State.EXIT) {
+ abortExit();
+ return true;
+ }
+ break;
}
- int n = map.unitsActivatedSize();
- if (n == 0)
- return StateType.ABORT;
- map.revertMoves();
- return StateType.ANIMATION;
- }
- @Override
- public StateType execute()
- {
- hideActivable();
- // be sure that the hq is activated
- if (selectedUnit.canMove() && (map.unitsActivatedSize() > 0))
- selectedUnit.setMoved();
-
- return StateType.DONE;
+ return false;
}
@Override
public void touch(Hex hex)
{
+ if (state == State.ROTATE) {
+ if (hex == to)
+ abortMove();
+ else {
+ Orientation o = Orientation.fromAdj(to, hex);
+ if (o != Orientation.KEEP)
+ move(o);
+ else if (hex == activeUnit.getHex())
+ abortMove();
+ }
+ return;
+ }
+
if (hex == activeUnit.getHex()) {
if (to != null)
map.pathHide(to);
- to = null;
+ map.pathsHide();
map.pathsClear();
- ctrl.post(StateType.ROTATE);
+ map.pathsInit(activeUnit);
+ collectPaths(hex);
return;
}
@@ -107,21 +129,29 @@ public class StateMove extends StateCommon
if (map.unitsActivableContains(unit)) {
if (unit != activeUnit)
- changeUnit(unit);
+ selectUnit(unit);
} else if ((s == 0) && map.movesContains(hex)) {
collectPaths(hex);
+ } else if ((s > 1) && hex == to) {
+ s = map.pathsChooseBest();
+ if (s == 1)
+ showRotation(to);
} else if (map.pathsContains(hex)) {
togglePoint(hex, s);
}
}
- private void hideActivable()
+ private void selectNextUnit()
{
- map.unitsActivableHide();
+ if (selectedUnit.canMove())
+ selectUnit(selectedUnit);
+ else
+ selectUnit(map.getFirstActivable());
}
- private void changeUnit(Unit unit)
+ private void selectUnit(Unit unit)
{
+ state = State.SHOW;
if (activeUnit != null ) {
map.hexUnselect(activeUnit.getHex());
if (activeUnit.canMove())
@@ -130,70 +160,170 @@ public class StateMove extends StateCommon
to = null;
activeUnit = unit;
activeUnit.hideActiveable();
- Hex hex = activeUnit.getHex();
- map.pathsInit(activeUnit, hex);
+ map.hexSelect(activeUnit.getHex());
+ map.pathsClear();
+ map.pathsInit(activeUnit);
map.movesHide();
map.movesCollect(activeUnit);
map.movesShow();
- map.hexSelect(hex);
- ctrl.hud.notify(activeUnit.toString(), Position.TOP_CENTER);
- checkExit(activeUnit);
+ ctrl.hud.notify(activeUnit.toString());
}
private void collectPaths(Hex hex)
{
+ state = State.PATH;
to = hex;
map.movesHide();
map.hexMoveShow(to);
- int s = map.pathsBuild(to);
- if (!checkExit(activeUnit, hex))
- completePath(s);
+ if (!checkExit(to))
+ completePath();
+ ctrl.hud.actionButtons.show(Buttons.ABORT.b);
}
- private void completePath(int s)
+ private void completePath()
{
+ int s = map.pathsBuild(to);
if (cfg.autoPath && (s > 1))
s = map.pathsChooseBest();
map.pathsShow();
if (s == 1)
- ctrl.post(StateType.ROTATE);
+ showRotation(to);
}
private void togglePoint(Hex hex, int s)
{
- if (hex == activeUnit.getHex()) {
- //
- } else if (hex == to) {
- //
- } else {
- map.pathsHide();
- s = map.pathsToggleHex(hex);
- map.pathsShow();
- }
-
- if (s == 1) {
- if (!checkExit(activeUnit, hex))
- ctrl.post(StateType.ROTATE);
- }
+ map.pathsHide();
+ s = map.pathsToggleHex(hex);
+ map.pathsShow();
+ if (s == 1)
+ showRotation(to);
}
- private boolean checkExit(Unit unit)
+ private boolean checkExit(Hex hex)
{
- if (unit.justEntered())
+ if (enter)
return false;
- if ((unit.exitZone == null) || !unit.exitZone.contains(unit.getHex()))
+ if ((activeUnit.exitZone == null) || !activeUnit.exitZone.contains(hex))
return false;
- ctrl.post(StateType.WITHDRAW);
+
+ int s = map.pathsBuild(to);
+
+ if (!map.pathsCanExit(activeUnit.exitZone.orientation))
+ return false;
+
+ if (map.pathsChooseExit(activeUnit.exitZone.orientation) > 1)
+ throw new RuntimeException(String.format("pathsChooseExit() -> %d", map.pathsSize()));
+ map.pathShow(hex);
+
+ state = State.EXIT;
+ ctrl.hud.askExitBoard();
return true;
}
- private boolean checkExit(Unit unit, Hex hex)
+ private void showRotation(Hex hex)
{
- if ((unit.exitZone == null) || !unit.exitZone.contains(hex))
- return false;
- if (!map.pathsCanExit(unit.exitZone.orientation))
- return false;
- ctrl.post(StateType.WITHDRAW);
- return true;
+ state = State.ROTATE;
+ map.movesHide();
+ map.pathsHide();
+ map.pathShow(hex);
+ map.hexDirectionsShow(hex);
+ ctrl.hud.actionButtons.show(Buttons.ABORT.b);
+ }
+
+ private void move(Orientation o)
+ {
+ map.pathsSetOrientation(o);
+ if (enter)
+ completeMove(map.getEnterOrder(selectedUnit, hqMode));
+ else
+ completeMove(map.getMoveOrder(selectedUnit, hqMode));
+ }
+
+ private void exit()
+ {
+ if (map.pathsTo() == null) {
+ map.pathsBuild(to);
+ if (map.pathsChooseExit(activeUnit.exitZone.orientation) > 1)
+ throw new RuntimeException(String.format("pathsChooseExit() -> %d", map.pathsSize()));
+ }
+
+ completeMove(map.getExitOrder(selectedUnit, hqMode));
+ }
+
+ private void completeMove(Order order)
+ {
+ map.pathHide(to);
+ map.hexDirectionsHide(to);
+ map.hexUnselect(selectedHex);
+ if (order.cost == 0)
+ ctrl.postOrder(order, StateType.MOVE);
+ else
+ ctrl.postOrder(order);
+ }
+
+ private void endHqMode()
+ {
+ if (selectedUnit.canMove())
+ selectedUnit.setMoved();
+ clear();
+ ctrl.postOrder(Order.END);
+ }
+
+ private void abortMove()
+ {
+ if (enter) {
+ map.revertEnter(activeUnit);
+ ctrl.battle.getPlayer().revertUnitEntry(activeUnit);
+ ctrl.hud.update();
+ }
+ clear();
+ if (notFirst) {
+ // FIXME abortMove : cfg.revertAllMoves
+ // if (cfg.revertAllMoves) {
+ // map.revertMoves();
+ // ctrl.postTransitionToAborted();
+ // } else {
+ selectUnit(activeUnit);
+ abortCompleted();
+ // }
+ }
+ else
+ ctrl.postActionAborted();
+ }
+
+ private void abortExit()
+ {
+ map.pathHide(to);
+ if (to == null) {
+ state = State.SHOW;
+ } else {
+ state = State.PATH;
+ map.hexMoveShow(to);
+ completePath();
+ }
+ abortCompleted();
+ }
+
+ private void abortCompleted()
+ {
+ if (hqMode)
+ map.unitsActivableShow();
+ activeUnit.hideActiveable();
+ ctrl.hud.actionButtons.show((notFirst ? Buttons.DONE.b : 0));
+ }
+
+ private void clear()
+ {
+ state = State.SHOW;
+ map.movesHide();
+ map.pathsHide();
+ activeUnit.hideActiveable();
+ map.hexUnselect(activeUnit.getHex());
+ map.unitsActivableHide();
+ if (to != null) {
+ map.pathHide(to);
+ map.hexDirectionsHide(to);
+ }
+ map.pathsClear();
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java
index bfec208..774b1a9 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java
@@ -5,26 +5,6 @@ public class StatePromote extends StateCommon
@Override
public void enterFrom(StateType prevState)
{
- ctrl.setAfterAnimationState(StateType.DONE);
- ctrl.post(StateType.ANIMATION);
- map.promoteUnit(selectedUnit);
- }
-
- @Override
- public void leaveFor(StateType nextState)
- {
- map.hexUnselect(selectedHex);
- }
-
- @Override
- public StateType abort()
- {
- return StateType.ABORT;
- }
-
- @Override
- public StateType execute()
- {
- return StateType.DONE;
+ ctrl.postOrder(map.getPromoteOrder(selectedUnit));
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java
index e118924..ffb1f24 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java
@@ -3,6 +3,7 @@ package ch.asynk.rustanddust.game.states;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Zone;
import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
public class StateReinforcement extends StateCommon
{
@@ -11,70 +12,53 @@ public class StateReinforcement extends StateCommon
@Override
public void enterFrom(StateType prevState)
{
- map.clearAll();
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
+ map.clear();
entryZone = null;
+ activeUnit = null;
selectedHex = null;
+ selectedUnit = null;
ctrl.hud.playerInfo.unitDock.show();
}
@Override
- public void leaveFor(StateType nextState)
+ public boolean processMsg(MsgType msg, Object data)
{
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
- if (entryZone != null)
- entryZone.enable(Hex.AREA, false);
- ctrl.hud.playerInfo.unitDock.hide();
- }
-
- @Override
- public StateType abort()
- {
- return StateType.ABORT;
- }
+ switch(msg)
+ {
+ case UNIT_DOCK_SELECT:
+ showEntryZone((Unit) data);
+ return true;
+ }
- @Override
- public StateType execute()
- {
- return StateType.DONE;
+ return false;
}
@Override
public void touch(Hex hex)
{
- Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit;
- if (hex == null)
- changeUnit(unit);
- else if ((entryZone != null) && hex.isEmpty() && entryZone.contains(hex))
- unitEnter(activeUnit, hex);
- else
- ctrl.post(StateType.SELECT);
+ if ((entryZone != null) && hex.isEmpty() && entryZone.contains(hex))
+ unitEnter(selectedUnit, hex);
}
- private void changeUnit(Unit unit)
+ private void showEntryZone(Unit unit)
{
- activeUnit = unit;
+ selectedUnit = unit;
if (entryZone != null)
entryZone.enable(Hex.AREA, false);
- entryZone = activeUnit.entryZone;
+ entryZone = unit.entryZone;
entryZone.enable(Hex.AREA, true);
}
private void unitEnter(Unit unit, Hex hex)
{
- selectedUnit = unit;
+ activeUnit = unit;
selectedHex = hex;
- map.hexSelect(selectedHex);
+ map.enterBoard(unit, hex, entryZone);
entryZone.enable(Hex.AREA, false);
- if (map.enterBoard(unit, hex, entryZone.allowedMoves)) {
- if (unit.getMovementPoints() > 0)
- ctrl.post(StateType.MOVE);
- else
- ctrl.post(StateType.ROTATE);
- } else {
- ctrl.hud.notify("Can not enter the map at that position");
- }
+ ctrl.battle.getPlayer().reinforcement.remove(unit);
+ ctrl.hud.playerInfo.unitDock.hide();
+ ctrl.hud.update();
+ ctrl.post(StateType.MOVE);
+ entryZone = null;
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReplay.java b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java
index ec8295d..22105fb 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateReplay.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java
@@ -1,87 +1,111 @@
package ch.asynk.rustanddust.game.states;
import ch.asynk.rustanddust.game.Order;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
public class StateReplay extends StateCommon
{
- private Order order;
+ private Order order = null;
@Override
public void enterFrom(StateType prevState)
{
+ if (this.order != null)
+ replayStep();
+
Order o = map.stepReplay();
if (o == null) {
- StateType nextState = nextState();
+ ctrl.postReplayDone(replayDone());
order = null;
- ctrl.post(nextState);
} else {
this.order = o;
setup();
- map.replay(order);
- ctrl.setAfterAnimationState(StateType.REPLAY);
- ctrl.post(StateType.ANIMATION);
+ ctrl.postOrder(o, StateType.REPLAY);
}
}
private void setup()
{
- int s = order.activable.size();
+ int s = order.activables.size();
- switch (order.type) {
+ switch (order.type)
+ {
case MOVE:
- selectedUnit = ((s > 0) ? order.activable.get(s - 1) : order.unit);
+ selectedUnit = order.leader;
break;
case ENGAGE:
to = order.engagement.defender.getHex();
- if (order.engagement.success) {
- ctrl.battle.getPlayer().engagementWon += 1;
- ctrl.battle.getOpponent().casualty(order.engagement.defender);
- } else {
- ctrl.battle.getPlayer().engagementLost += 1;
- }
break;
+ case PROMOTE:
default:
break;
}
}
- private StateType nextState()
+ private void replayStep()
{
- if (map.unitsActivableSize() <= 0)
- return StateType.DONE;
-
- StateType next = null;
-
- switch (order.type) {
+ switch (order.type)
+ {
case MOVE:
- next = StateType.MOVE;
+ moveReplayStep();
break;
case ENGAGE:
- next = StateType.BREAK;
- break;
+ case PROMOTE:
default:
- next = StateType.DONE;
break;
}
-
- return next;
}
- @Override
- public void leaveFor(StateType nextState)
+ private void moveReplayStep()
{
+ switch(order.move.type)
+ {
+ case SET:
+ ctrl.sendMsg(MsgType.UNIT_DEPLOYED, order.move.pawn);
+ break;
+ case REGULAR:
+ case EXIT:
+ case ENTER:
+ break;
+ }
}
- @Override
- public StateType abort()
+ private StateType replayDone()
{
- return StateType.ABORT;
+ if (order == null) return null;
+
+ boolean more = (order.activables.size() > 0);
+ StateType nextState = null;
+ switch (order.type)
+ {
+ case MOVE:
+ nextState = moveReplayDone(more);
+ break;
+ case ENGAGE:
+ if (more) nextState = StateType.ENGAGE;
+ break;
+ case PROMOTE:
+ default:
+ break;
+ }
+ return nextState;
}
- @Override
- public StateType execute()
+ private StateType moveReplayDone(boolean more)
{
- // called at the end of animation DONE -> burn 1 AP
- return ((order.cost == 0) ? StateType.REPLAY : StateType.DONE);
+ StateType nextState = null;
+ switch(order.move.type)
+ {
+ case REGULAR:
+ case EXIT:
+ if (more) nextState = StateType.MOVE;
+ break;
+ case SET:
+ nextState = StateType.DEPLOYMENT;
+ break;
+ case ENTER:
+ break;
+ }
+ return nextState;
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java
deleted file mode 100644
index 4aa9608..0000000
--- a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package ch.asynk.rustanddust.game.states;
-
-import ch.asynk.rustanddust.engine.Orientation;
-import ch.asynk.rustanddust.game.Hex;
-import ch.asynk.rustanddust.RustAndDust;
-
-public class StateRotate extends StateCommon
-{
- private boolean rotateOnly;
- private boolean rotationSet;
-
- @Override
- public void enterFrom(StateType prevState)
- {
- if (!cfg.showMoveAssists) map.unitsActivableHide();
-
- if (activeUnit == null)
- activeUnit = selectedUnit;
- if (to == null)
- to = activeUnit.getHex();
-
- if (!map.pathsIsSet()) {
- map.pathsInit(activeUnit);
- map.pathsBuild(to);
- }
-
- if (map.pathsSize() > 1)
- RustAndDust.debug("ERROR: Rotate pathsSize() == " + map.pathsSize());
-
- rotateOnly = (to == activeUnit.getHex());
-
- if (!rotateOnly)
- map.pathShow(to);
- map.hexSelect(activeUnit.getHex());
- map.hexDirectionsShow(to);
-
- rotationSet = false;
- }
-
- @Override
- public void leaveFor(StateType nextState)
- {
- map.hexUnselect(activeUnit.getHex());
- map.pathHide(to);
- map.hexDirectionsHide(to);
- map.pathsClear();
- to = null;
- }
-
- @Override
- public StateType abort()
- {
- StateType nextState = StateType.ABORT;
- ctrl.hud.actionButtons.hide();
- if (activeUnit.justEntered()) {
- map.revertEnter(activeUnit);
- nextState = StateType.ABORT;
- } else if (map.unitsActivatedSize() == 0) {
- map.unitsActivableHide();
- } else {
- nextState = StateType.MOVE;
- }
- return nextState;
- }
-
- @Override
- public StateType execute()
- {
- if (!rotationSet)
- return StateType.DONE;
-
- StateType whenDone = StateType.DONE;
-
- if (map.moveUnit(activeUnit)) {
- if (map.unitsActivableSize() > 0)
- whenDone = StateType.MOVE;
- } else
- RustAndDust.debug("rotate failed");
-
- ctrl.setAfterAnimationState(whenDone);
- return StateType.ANIMATION;
- }
-
- @Override
- public void touch(Hex hex)
- {
- if (rotationSet) return;
-
- Orientation o = Orientation.fromAdj(to, hex);
- if (o == Orientation.KEEP) {
- ctrl.post(StateType.ABORT);
- return;
- }
-
- if (!activeUnit.justEntered() && rotateOnly && (o == activeUnit.getOrientation()))
- return;
-
- map.pathsSetOrientation(o);
- rotationSet = true;
- execute();
- ctrl.post(StateType.ANIMATION);
- }
-}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
index 518258f..f6c42c3 100644
--- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
+++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
@@ -1,120 +1,131 @@
package ch.asynk.rustanddust.game.states;
+import ch.asynk.rustanddust.RustAndDust;
import ch.asynk.rustanddust.ui.Position;
import ch.asynk.rustanddust.game.Hex;
import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Ctrl.MsgType;
import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
-import ch.asynk.rustanddust.RustAndDust;
public class StateSelect extends StateCommon
{
- @Override
- public void enterFrom(StateType prevState)
- {
- to = null;
- selectedHex = null;
- selectedUnit = null;
- activeUnit = null;
- map.clearAll();
- ctrl.hud.actionButtons.hide();
- }
+ private boolean isEnemy;
@Override
- public void leaveFor(StateType nextState)
+ public void enterFrom(StateType prevState)
{
- hidePossibilities();
+ clear();
}
@Override
- public StateType abort()
+ public boolean processMsg(MsgType msg, Object data)
{
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
- hidePossibilities();
- map.clearAll();
- return StateType.ABORT;
- }
+ switch(msg)
+ {
+ case OK:
+ ctrl.postTurnDone();
+ return true;
+ case PROMOTE:
+ changeTo(StateType.PROMOTE);
+ return true;
+ }
- @Override
- public StateType execute()
- {
- return StateType.DONE;
+ return false;
}
@Override
public void touch(Hex hex)
{
- if (!isEnemy) {
+ Unit unit = hex.getUnit();
+
+ if (!isEnemy && (selectedUnit != null)) {
if (map.movesContains(hex)) {
// quick move
to = hex;
- ctrl.post(StateType.MOVE);
+ changeTo(StateType.MOVE);
return;
}
- if (map.unitsTargetContains(hex.getUnit())) {
+ if (map.unitsTargetContains(unit)) {
// quick fire
to = hex;
- ctrl.post(StateType.ENGAGE);
+ activeUnit = unit;
+ changeTo(StateType.ENGAGE);
return;
}
}
- if (selectedHex != null)
- map.hexUnselect(selectedHex);
+ hide();
- hidePossibilities();
- if (hex.isOffMap()) {
- selectedUnit = null;
- return;
- }
-
- Unit unit = hex.getUnit();
-
- if (unit == null) {
- isEnemy = false;
- ctrl.hud.actionButtons.hide();
- map.clearAll();
+ if ((unit == null) || hex.isOffMap()) {
selectedUnit = null;
return;
}
isEnemy = ctrl.battle.getPlayer().isEnemy(unit);
- if (!isEnemy && (unit == selectedUnit) && unit.canMove()) {
+
+ if (!isEnemy && (selectedUnit == unit) && unit.canMove()) {
if (unit.isHq() && (map.unitsActivableSize() > 1)) {
- ctrl.hud.notify("HQ activation");
- select(hex, unit, isEnemy);
- ctrl.post(StateType.MOVE);
- } else {
- // quick rotate
+ ctrl.hud.notify("HQ activation", Position.MIDDLE_CENTER);
+ to = null;
+ } else
to = hex;
- ctrl.post(StateType.ROTATE);
- }
+ changeTo(StateType.MOVE);
} else {
- select(hex, unit, isEnemy);
- ctrl.hud.notify(selectedUnit.toString(), Position.TOP_CENTER);
+ select(hex, unit);
+ ctrl.hud.notify(selectedUnit.toString());
}
}
- private void select(Hex hex, Unit unit, boolean isEnemy)
+ private void select(Hex hex, Unit unit)
{
selectedHex = hex;
selectedUnit = unit;
+ RustAndDust.debug(String.format(" %s - %s", selectedUnit, selectedHex));
+
+ map.hexSelect(selectedHex);
if (isEnemy && !cfg.showEnemyPossibilities)
return;
- int moves = map.movesCollect(selectedUnit);
- int targets = map.collectTargets(selectedUnit, (isEnemy ? ctrl.battle.getPlayer() : ctrl.battle.getOpponent()).units);
-
- if (moves > 0)
+ if(map.movesCollect(selectedUnit) > 0) {
map.collectMoveable(selectedUnit);
+ if (cfg.showMoves) map.movesShow();
+ if (cfg.showMoveAssists) map.unitsActivableShow();
+ unit.hideActiveable();
+ }
- if ((moves > 0) || (targets > 0)) {
- map.hexSelect(selectedHex);
- showPossibilities(selectedUnit);
+ if (map.collectTargets(selectedUnit, (isEnemy ? ctrl.battle.getPlayer() : ctrl.battle.getOpponent()).units) > 0) {
+ if (cfg.showTargets) map.unitsTargetShow();
+ unit.hideActiveable();
}
ctrl.hud.actionButtons.show((ctrl.battle.getPlayer().canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 );
- RustAndDust.debug("Select", selectedHex.toString() + " " + selectedUnit + (isEnemy ? " enemy " : " friend "));
+ }
+
+ private void changeTo(StateType nextState)
+ {
+ hide();
+ ctrl.post(nextState);
+ }
+
+ private void hide()
+ {
+ if (selectedHex != null)
+ map.hexUnselect(selectedHex);
+ map.movesHide();
+ map.unitsTargetHide();
+ map.unitsActivableHide();
+ ctrl.hud.actionButtons.hide();
+ }
+
+ private void clear()
+ {
+ hide();
+ map.clear();
+ to = null;
+ isEnemy = false;
+ selectedHex = null;
+ selectedUnit = null;
+ activeUnit = null;
}
}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java
deleted file mode 100644
index f21fbed..0000000
--- a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package ch.asynk.rustanddust.game.states;
-
-import ch.asynk.rustanddust.game.Hex;
-import ch.asynk.rustanddust.game.Unit;
-import ch.asynk.rustanddust.RustAndDust;
-
-public class StateWithdraw extends StateCommon
-{
- @Override
- public void enterFrom(StateType prevState)
- {
- ctrl.hud.askExitBoard();
- }
-
- @Override
- public void leaveFor(StateType nextState)
- {
- }
-
- @Override
- public StateType abort()
- {
- return StateType.MOVE;
- }
-
- @Override
- public StateType execute()
- {
- if (activeUnit == null)
- activeUnit = selectedUnit;
-
- ctrl.setAfterAnimationState(withdraw(activeUnit));
- return StateType.ANIMATION;
- }
-
- private StateType withdraw(Unit unit)
- {
- Hex hex = unit.getHex();
-
- // rotation
- if (map.pathsTo() == null)
- map.pathsBuild(hex);
-
- Hex exitHex = (Hex) map.pathsTo();
- if (!unit.exitZone.contains(exitHex))
- throw new RuntimeException(String.format("%s not in exitZone", exitHex));
-
- if (map.pathsChooseExit(unit.exitZone.orientation) > 1)
- RustAndDust.debug("ERROR: Withdraw pathsSize() == " + map.pathsSize());
-
- unit.hideActiveable();
- if (to != null)
- map.pathHide(to);
- map.movesHide();
- map.hexUnselect(hex);
-
- if (map.exitBoard(unit)) {
- if (map.unitsActivableSize() > 0)
- return StateType.MOVE;
- } else
- RustAndDust.debug("exit failed");
- return StateType.DONE;
- }
-}