summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/game/states
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
commitde0463bcf0f76ef8b07f2719679c9e0d72745c5d (patch)
tree9a33df947ceeea16a3e20b400585b1d3c304e77e /core/src/ch/asynk/rustanddust/game/states
parente66f9f2a61d3dab4545e996046486de0d44e2901 (diff)
downloadRustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip
RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/states')
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateAnimation.java37
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateBreak.java90
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateCommon.java68
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateDeployment.java138
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateEngage.java105
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateMove.java193
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StatePromote.java42
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java87
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateRotate.java111
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateSelect.java132
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java71
11 files changed, 1074 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java
new file mode 100644
index 0000000..41831e0
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java
@@ -0,0 +1,37 @@
+package ch.asynk.rustanddust.game.states;
+
+public class StateAnimation extends StateCommon
+{
+ @Override
+ public void enter(StateType prevState)
+ {
+ ctrl.hud.actionButtons.hide();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ }
+
+ @Override
+ public StateType abort()
+ {
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java
new file mode 100644
index 0000000..f1e40f6
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java
@@ -0,0 +1,90 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.engine.Orientation;
+import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class StateBreak extends StateCommon
+{
+ private Orientation o = Orientation.KEEP;
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ activeUnit = null;
+ ctrl.hud.actionButtons.show(Buttons.DONE.b);
+ ctrl.hud.pushNotify("Break move possible");
+ map.showBreakUnits();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ map.hideBreakUnits();
+ map.hideMove(to);
+ map.hideDirections(to);
+ map.hideOrientation(to);
+ if (activeUnit != null) map.hideMove(activeUnit.getHex());
+ }
+
+ @Override
+ public StateType abort()
+ {
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ // TODO : cancel preview move before showing rotation
+ if (activeUnit == null) {
+ Unit unit = upHex.getUnit();
+ if (map.breakUnits.contains(unit)) {
+ activeUnit = unit;
+ map.showMove(upHex);
+ map.showMove(to);
+ map.showDirections(to);
+ map.hideBreakUnits();
+ }
+ } else {
+ o = Orientation.fromAdj(to, upHex);
+
+ if (o == Orientation.KEEP) return;
+
+ if (ctrl.cfg.mustValidate) {
+ map.hideDirections(to);
+ map.showOrientation(to, o);
+ ctrl.hud.actionButtons.show(Buttons.DONE.b);
+ } else {
+ doRotation(o);
+ ctrl.setState(StateType.ANIMATION);
+ }
+ }
+ }
+
+ private void doRotation(Orientation o)
+ {
+ if (activeUnit == null) return;
+
+ map.pathBuilder.init(activeUnit);
+ if (map.pathBuilder.build(to) == 1) {
+ map.pathBuilder.orientation = o;
+ map.moveUnit(activeUnit);
+ ctrl.setAfterAnimationState(StateType.DONE);
+ } else
+ RustAndDust.debug("That's very wrong there should be only one path");
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java
new file mode 100644
index 0000000..443182d
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java
@@ -0,0 +1,68 @@
+package ch.asynk.rustanddust.game.states;
+
+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.State;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public abstract class StateCommon implements State
+{
+ protected static Ctrl ctrl;
+ protected static Map map;
+
+ protected static Hex selectedHex = null;
+ protected static Hex downHex = null;
+ protected static Hex upHex = null;
+ protected static Hex to = null;
+
+ protected boolean isEnemy;
+ protected static Unit activeUnit;
+ protected static Unit selectedUnit;
+
+ protected StateCommon()
+ {
+ }
+
+ public StateCommon(Ctrl ctrl, Map map)
+ {
+ this.ctrl = ctrl;
+ this.map = map;
+ }
+
+ @Override
+ public boolean downInMap(float x, float y)
+ {
+ downHex = map.getHexAt(x, y);
+ return (downHex != null);
+ }
+
+ @Override
+ public boolean upInMap(float x, float y)
+ {
+ upHex = map.getHexAt(x, y);
+ return (upHex != null);
+ }
+
+ protected boolean hasUnit()
+ {
+ return (selectedUnit != null);
+ }
+
+ protected void showPossibilities(Unit unit)
+ {
+ if (ctrl.cfg.showMoves && unit.canMove()) map.showPossibleMoves();
+ if (ctrl.cfg.showTargets && unit.canEngage()) map.showPossibleTargets();
+ if (ctrl.cfg.showMoveAssists && unit.canMove()) map.showMoveableUnits();
+ unit.enableOverlay(Unit.MOVE, false);
+ }
+
+ protected void hidePossibilities()
+ {
+ map.hidePossibleMoves();
+ map.hidePossibleTargets();
+ map.hideMoveableUnits();
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
new file mode 100644
index 0000000..9528d2a
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java
@@ -0,0 +1,138 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.engine.Orientation;
+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.hud.ActionButtons.Buttons;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class StateDeployment extends StateCommon
+{
+ private boolean completed;
+ private Zone entryZone;
+ private UnitList deployedUnits = new UnitList(10);
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ completed = false;
+ entryZone = null;
+ selectedHex = null;
+ selectedUnit = null;
+ ctrl.hud.actionButtons.hide();
+ ctrl.hud.playerInfo.unitDock.show();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ selectedUnit = null;
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ if (entryZone != null)
+ entryZone.enable(Hex.AREA, false);
+ ctrl.hud.playerInfo.unitDock.hide();
+ }
+
+ @Override
+ public StateType abort()
+ {
+ if (activeUnit != null)
+ undo();
+ return StateType.DEPLOYMENT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ deployedUnits.clear();
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit;
+ if (!completed && (unit != null) && (unit != activeUnit)) {
+ showEntryZone(unit);
+ } else if (selectedUnit != null) {
+ doRotation(Orientation.fromAdj(selectedHex, upHex));
+ } else if (!completed && (entryZone != null) && (upHex != null)) {
+ if (upHex.isEmpty() && entryZone.contains(upHex))
+ unitEnter(activeUnit);
+ } else {
+ unit = downHex.getUnit();
+ if (deployedUnits.contains(unit)) {
+ showRotation(unit, downHex);
+ activeUnit = unit;
+ }
+ }
+ }
+
+ private void showEntryZone(Unit unit)
+ {
+ activeUnit = unit;
+ if (entryZone != null) entryZone.enable(Hex.AREA, false);
+ entryZone = ctrl.battle.getEntryZone(activeUnit);
+ entryZone.enable(Hex.AREA, true);
+ }
+
+ private void undo()
+ {
+ map.unselectHex(selectedHex);
+ map.hideDirections(selectedHex);
+ map.revertEnter(activeUnit);
+ activeUnit = null;
+ selectedUnit = null;
+ ctrl.hud.update();
+ }
+
+ private void unitEnter(Unit unit)
+ {
+ selectedUnit = unit;
+ selectedHex = upHex;
+ ctrl.player.reinforcement.remove(unit);
+ map.showOnBoard(unit, upHex, entryZone.orientation);
+ deployedUnits.add(unit);
+ entryZone.enable(Hex.AREA, false);
+ showRotation(unit, upHex);
+ ctrl.hud.update();
+ }
+
+ private void showRotation(Unit unit, Hex hex)
+ {
+ selectedUnit = unit;
+ selectedHex = hex;
+ map.selectHex(selectedHex);
+ map.showDirections(selectedHex);
+ ctrl.hud.playerInfo.unitDock.hide();
+ ctrl.hud.actionButtons.show(Buttons.ABORT.b);
+ }
+
+ private void doRotation(Orientation o)
+ {
+ map.unselectHex(selectedHex);
+ map.hideDirections(selectedHex);
+
+ if (o != Orientation.KEEP)
+ map.setOnBoard(selectedUnit, selectedHex, o);
+
+ ctrl.hud.actionButtons.hide();
+ ctrl.hud.playerInfo.unitDock.show();
+ entryZone = null;
+ activeUnit = null;
+ selectedUnit = null;
+ if (ctrl.checkDeploymentDone())
+ completed = true;
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
new file mode 100644
index 0000000..4588cb2
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java
@@ -0,0 +1,105 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class StateEngage extends StateCommon
+{
+ @Override
+ public void enter(StateType prevState)
+ {
+ map.possibleTargets.clear();
+ ctrl.hud.actionButtons.show(ctrl.cfg.canCancel ? Buttons.ABORT.b : 0);
+
+ // activeUnit is the target
+ if (prevState == StateType.SELECT) {
+ activeUnit = null;
+ // use selectedHex and selectedUnit
+ map.hidePossibleTargets();
+ map.collectPossibleTargets(selectedUnit, ctrl.opponent.units);
+ map.showPossibleTargets();
+ if (to != null) {
+ // quick fire -> replay touchUp
+ upHex = to;
+ touchUp();
+ }
+ selectedUnit.showAttack();
+ map.selectHex(selectedHex);
+ } else
+ RustAndDust.debug("should not happen");
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ selectedUnit.hideAttack();
+ map.hideAttackAssists();
+ map.hidePossibleTargets();
+ map.unselectHex(selectedHex);
+ if (to != null)
+ map.unselectHex(to);
+ }
+
+ @Override
+ public StateType abort()
+ {
+ map.activatedUnits.clear();
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ StateType nextState = StateType.DONE;
+ if (map.engageUnit(selectedUnit, activeUnit)) {
+ ctrl.player.wonEngagementCount += 1;
+ ctrl.opponent.casualty(activeUnit);
+ if (map.breakUnits.size() > 0) {
+ nextState = StateType.BREAK;
+ }
+ } else {
+ ctrl.player.lostEngagementCount += 1;
+ }
+
+ activeUnit.showTarget();
+ ctrl.setAfterAnimationState(nextState);
+ return StateType.ANIMATION;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ Unit unit = upHex.getUnit();
+
+ // activeUnit is the target, selectedTarget is the engagement leader
+ if (unit == selectedUnit) {
+ ctrl.setState(StateType.ABORT);
+ } else if ((activeUnit == null) && map.possibleTargets.contains(unit)) {
+ // ctrl.hud.notify("Engage " + unit);
+ map.hidePossibleTargets();
+ to = upHex;
+ activeUnit = unit;
+ activeUnit.showTarget();
+ map.collectAttackAssists(selectedUnit, activeUnit, ctrl.player.units);
+ map.showAttackAssists();
+ ctrl.hud.actionButtons.show((ctrl.cfg.mustValidate ? Buttons.DONE.b : 0) | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0));
+ }
+ else if (unit == activeUnit) {
+ ctrl.setState(StateType.DONE);
+ }
+ else if ((activeUnit != null) && map.engagementAssists.contains(unit)) {
+ map.toggleAttackAssist(unit);
+ // if(map.toggleAttackAssist(unit))
+ // ctrl.hud.notify(unit + " will fire");
+ // else
+ // ctrl.hud.notify(unit + " wont fire");
+ }
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java
new file mode 100644
index 0000000..b59b133
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java
@@ -0,0 +1,193 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.game.Hex;
+import ch.asynk.rustanddust.game.Unit;
+import ch.asynk.rustanddust.game.Zone;
+import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
+
+public class StateMove extends StateCommon
+{
+ @Override
+ public void enter(StateType prevState)
+ {
+ ctrl.hud.actionButtons.show(
+ ((map.activatedUnits.size() > 0) ? Buttons.DONE.b : 0)
+ | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0));
+
+ if (prevState == StateType.WITHDRAW) {
+ if (map.pathBuilder.size() == 1)
+ ctrl.setState(StateType.ROTATE);
+ return;
+ }
+
+ map.pathBuilder.clear();
+
+ if (prevState == StateType.SELECT) {
+ // use selectedHex and selectedUnit
+ activeUnit = selectedUnit;
+ activeUnit.showMoveable();
+ map.pathBuilder.init(activeUnit);
+ map.collectAndShowMovesAndAssits(activeUnit);
+ if (to != null) {
+ // quick move -> replay touchUp
+ upHex = to;
+ touchUp();
+ } else
+ checkExit(activeUnit, activeUnit.getHex());
+ } else {
+ // back from rotation -> chose next Pawn
+ if (selectedUnit.canMove()) {
+ changeUnit(selectedUnit);
+ } else {
+ changeUnit(map.moveableUnits.get(0));
+ }
+ }
+
+ activeUnit.enableOverlay(Unit.MOVE, false);
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ if (nextState == StateType.WITHDRAW)
+ return;
+
+ // hide all but assists : want them when in rotation
+ activeUnit.hideMoveable();
+ map.hidePossibleMoves();
+ map.unselectHex(activeUnit.getHex());
+ if (to != null)
+ map.hidePath(to);
+
+ if (nextState != StateType.SELECT) {
+ if (to == null)
+ to = activeUnit.getHex();
+ }
+ }
+
+ @Override
+ public StateType abort()
+ {
+ hideAssists();
+ if (activeUnit.justEntered()) {
+ map.revertEnter(activeUnit);
+ return StateType.ABORT;
+ }
+ int n = map.activatedUnits.size();
+ if (n == 0)
+ return StateType.ABORT;
+ map.revertMoves();
+ return StateType.ANIMATION;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ hideAssists();
+ // be sure that the hq is activated
+ if (selectedUnit.canMove() && (map.activatedUnits.size() > 0))
+ selectedUnit.setMoved();
+
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ if (upHex == activeUnit.getHex()) {
+ if (to != null)
+ map.hidePath(to);
+ to = null;
+ map.pathBuilder.clear();
+ ctrl.setState(StateType.ROTATE);
+ return;
+ }
+
+ int s = map.pathBuilder.size();
+
+ Unit unit = upHex.getUnit();
+
+ if (map.moveableUnits.contains(unit)) {
+ if(unit != activeUnit)
+ changeUnit(unit);
+ } else if ((s == 0) && map.possibleMoves.contains(upHex)) {
+ s = collectPaths(upHex);
+ } else if (map.pathBuilder.contains(upHex)) {
+ s = togglePoint(downHex, s);
+ }
+
+ if (s == 1) {
+ if (!checkExit(activeUnit, upHex))
+ ctrl.setState(StateType.ROTATE);
+ }
+ }
+
+ private void hideAssists()
+ {
+ map.hideMoveableUnits();
+ }
+
+ private void changeUnit(Unit unit)
+ {
+ if (activeUnit != null ) {
+ map.unselectHex(activeUnit.getHex());
+ if (activeUnit.canMove())
+ activeUnit.enableOverlay(Unit.MOVE, true);
+ }
+ activeUnit = unit;
+ Hex hex = activeUnit.getHex();
+ map.pathBuilder.init(activeUnit, hex);
+ activeUnit.showMoveable();
+ map.hidePossibleMoves();
+ map.collectPossibleMoves(activeUnit);
+ map.showPossibleMoves();
+ map.selectHex(hex);
+ activeUnit.enableOverlay(Unit.MOVE, false);
+ ctrl.hud.notify(activeUnit.toString());
+ checkExit(activeUnit, hex);
+ }
+
+ private int collectPaths(Hex hex)
+ {
+ to = hex;
+ int s = map.pathBuilder.build(to);
+ map.showMove(to);
+ map.hidePossibleMoves();
+ map.showPathBuilder();
+ return s;
+ }
+
+ private int togglePoint(Hex hex, int s)
+ {
+ if (hex == activeUnit.getHex()) {
+ //
+ } else if (hex == to) {
+ //
+ } else {
+ map.hidePathBuilder();
+ map.togglePathOverlay(hex);
+ s = map.togglePathBuilderHex(hex);
+ map.showPathBuilder();
+ }
+
+ return s;
+ }
+
+ private boolean checkExit(Unit unit, Hex hex)
+ {
+ if ((hex == unit.getHex()) && (unit.justEntered()))
+ return false;
+ Zone exitZone = ctrl.battle.getExitZone(unit);
+ if ((exitZone == null) || !exitZone.contains(hex))
+ return false;
+ if ((unit.getHex() != hex) && !map.pathBuilder.canExit(exitZone.orientation))
+ return false;
+ ctrl.setState(StateType.WITHDRAW);
+ return true;
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java
new file mode 100644
index 0000000..8543c89
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java
@@ -0,0 +1,42 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.game.Unit;
+
+public class StatePromote extends StateCommon
+{
+ @Override
+ public void enter(StateType prevState)
+ {
+ ctrl.setAfterAnimationState(StateType.DONE);
+ ctrl.setState(StateType.ANIMATION);
+ map.promoteUnit(selectedUnit);
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ map.unselectHex(selectedHex);
+ }
+
+ @Override
+ public StateType abort()
+ {
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java
new file mode 100644
index 0000000..77ff826
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java
@@ -0,0 +1,87 @@
+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.hud.ActionButtons.Buttons;
+
+public class StateReinforcement extends StateCommon
+{
+ private Zone entryZone;
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ map.clearAll();
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ entryZone = null;
+ selectedHex = null;
+ ctrl.hud.playerInfo.unitDock.show();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ if (entryZone != null)
+ entryZone.enable(Hex.AREA, false);
+ ctrl.hud.playerInfo.unitDock.hide();
+ }
+
+ @Override
+ public StateType abort()
+ {
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit;
+ if ((unit != null) && (unit != activeUnit))
+ changeUnit(unit);
+ else if ((entryZone != null) && upHex.isEmpty() && entryZone.contains(upHex))
+ unitEnter(activeUnit);
+ else
+ ctrl.setState(StateType.SELECT);
+ }
+
+ private void changeUnit(Unit unit)
+ {
+ activeUnit = unit;
+ if (entryZone != null)
+ entryZone.enable(Hex.AREA, false);
+ entryZone = ctrl.battle.getEntryZone(activeUnit);
+ entryZone.enable(Hex.AREA, true);
+ ctrl.hud.actionButtons.show(((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
+ }
+
+ private void unitEnter(Unit unit)
+ {
+ selectedUnit = unit;
+ selectedHex = upHex;
+ map.selectHex(selectedHex);
+ entryZone.enable(Hex.AREA, false);
+ if (map.enterBoard(unit, upHex, entryZone.allowedMoves)) {
+ if (unit.getMovementPoints() > 0)
+ ctrl.setState(StateType.MOVE);
+ else
+ ctrl.setState(StateType.ROTATE);
+ } else {
+ ctrl.hud.notify("Can not enter the map at that position");
+ }
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java
new file mode 100644
index 0000000..4d91740
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java
@@ -0,0 +1,111 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.engine.Orientation;
+import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class StateRotate extends StateCommon
+{
+ private boolean rotateOnly;
+ private boolean rotationSet;
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ ctrl.hud.actionButtons.show((ctrl.cfg.canCancel && (map.moveableUnits.size() > 1))? Buttons.ABORT.b : 0);
+
+ if (activeUnit == null)
+ activeUnit = selectedUnit;
+ if (to == null)
+ to = activeUnit.getHex();
+
+ if (!map.pathBuilder.isSet()) {
+ map.pathBuilder.init(activeUnit);
+ map.pathBuilder.build(to);
+ }
+
+ if (map.pathBuilder.size() != 1)
+ RustAndDust.debug("ERROR: pathBuilder.size() == " + map.pathBuilder.size());
+
+ rotateOnly = (to == activeUnit.getHex());
+
+ if (!rotateOnly)
+ map.showPath(to);
+ map.selectHex(activeUnit.getHex());
+ map.showDirections(to);
+
+ rotationSet = false;
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ map.unselectHex(activeUnit.getHex());
+ map.hidePath(to);
+ map.hideDirections(to);
+ map.hideOrientation(to);
+ map.pathBuilder.clear();
+ 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.activatedUnits.size() == 0) {
+ map.hideMoveableUnits();
+ } else {
+ nextState = StateType.MOVE;
+ }
+ return nextState;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ StateType whenDone = StateType.DONE;
+
+ if (map.moveUnit(activeUnit) > 0)
+ whenDone = StateType.MOVE;
+
+ ctrl.setAfterAnimationState(whenDone);
+ return StateType.ANIMATION;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ if (rotationSet) return;
+
+ Orientation o = Orientation.fromAdj(to, upHex);
+ if (o == Orientation.KEEP) {
+ ctrl.setState(StateType.ABORT);
+ return;
+ }
+
+ if (!activeUnit.justEntered() && rotateOnly && (o == activeUnit.getOrientation()))
+ return;
+
+ map.pathBuilder.orientation = o;
+ rotationSet = true;
+
+ if (ctrl.cfg.mustValidate) {
+ map.hideDirections(to);
+ map.showOrientation(to, o);
+ ctrl.hud.actionButtons.show(Buttons.DONE.b | ((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
+ } else {
+ execute();
+ ctrl.setState(StateType.ANIMATION);
+ }
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
new file mode 100644
index 0000000..9161a6b
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java
@@ -0,0 +1,132 @@
+package ch.asynk.rustanddust.game.states;
+
+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.hud.ActionButtons.Buttons;
+
+import ch.asynk.rustanddust.RustAndDust;
+
+public class StateSelect extends StateCommon
+{
+ public StateSelect(Ctrl ctrl, Map map)
+ {
+ super(ctrl, map);
+ }
+
+ @Override
+ public void enter(StateType prevState)
+ {
+ to = null;
+ selectedHex = null;
+ selectedUnit = null;
+ activeUnit = null;
+ map.clearAll();
+ ctrl.hud.actionButtons.hide();
+ }
+
+ @Override
+ public void leave(StateType nextState)
+ {
+ hidePossibilities();
+ }
+
+ @Override
+ public StateType abort()
+ {
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+ hidePossibilities();
+ map.clearAll();
+ return StateType.ABORT;
+ }
+
+ @Override
+ public StateType execute()
+ {
+ return StateType.DONE;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ if (!isEnemy) {
+ if (map.possibleMoves.contains(upHex)) {
+ // quick move
+ to = upHex;
+ ctrl.setState(StateType.MOVE);
+ return;
+ }
+ if (map.possibleTargets.contains(upHex.getUnit())) {
+ // quick fire
+ to = upHex;
+ ctrl.setState(StateType.ENGAGE);
+ return;
+ }
+ }
+
+ if (selectedHex != null)
+ map.unselectHex(selectedHex);
+
+ hidePossibilities();
+ if (upHex.isOffMap()) {
+ selectedUnit = null;
+ return;
+ }
+
+ Unit unit = upHex.getUnit();
+
+ if (unit == null) {
+ isEnemy = false;
+ ctrl.hud.actionButtons.hide();
+ map.clearAll();
+ selectedUnit = null;
+ return;
+ }
+
+ isEnemy = ctrl.player.isEnemy(unit);
+ if (!isEnemy && (unit == selectedUnit) && unit.canMove()) {
+ if (unit.isHq()) {
+ ctrl.hud.notify("HQ activation");
+ select(upHex, unit, isEnemy);
+ ctrl.setState(StateType.MOVE);
+ } else {
+ // quick rotate
+ to = upHex;
+ ctrl.setState(StateType.ROTATE);
+ }
+ } else {
+ select(upHex, unit, isEnemy);
+ ctrl.hud.notify(selectedUnit.toString());
+ }
+ }
+
+ private void select(Hex hex, Unit unit, boolean isEnemy)
+ {
+ selectedHex = hex;
+ selectedUnit = unit;
+
+ if (isEnemy && !ctrl.cfg.showEnemyPossibilities)
+ return;
+
+ int moves = map.collectPossibleMoves(selectedUnit);
+ int targets = map.collectPossibleTargets(selectedUnit, (isEnemy ? ctrl.player.units : ctrl.opponent.units));
+
+ if (moves > 0)
+ map.collectMoveableUnits(selectedUnit);
+
+ if ((moves > 0) || (targets > 0)) {
+ map.selectHex(selectedHex);
+ showPossibilities(selectedUnit);
+ }
+
+ ctrl.hud.actionButtons.show((ctrl.player.canPromote(selectedUnit)) ? Buttons.PROMOTE.b : 0 );
+ RustAndDust.debug("Select", selectedHex.toString() + " " + selectedUnit + (isEnemy ? " enemy " : " friend "));
+ }
+}
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java
new file mode 100644
index 0000000..f4f11a6
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java
@@ -0,0 +1,71 @@
+package ch.asynk.rustanddust.game.states;
+
+import ch.asynk.rustanddust.game.Zone;
+import ch.asynk.rustanddust.game.Hex;
+import ch.asynk.rustanddust.game.Unit;
+
+public class StateWithdraw extends StateCommon
+{
+ @Override
+ public void enter(StateType prevState)
+ {
+ ctrl.hud.askExitBoard();
+ }
+
+ @Override
+ public void leave(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;
+ }
+
+ @Override
+ public void touchDown()
+ {
+ }
+
+ @Override
+ public void touchUp()
+ {
+ }
+
+ private StateType withdraw(Unit unit)
+ {
+ Zone exitZone = ctrl.battle.getExitZone(unit);
+ Hex hex = unit.getHex();
+
+ // rotation
+ if (map.pathBuilder.to == null)
+ map.pathBuilder.build(hex);
+
+ Hex exitHex = (Hex) map.pathBuilder.to;
+ if (!exitZone.contains(exitHex))
+ throw new RuntimeException(String.format("%s not in exitZone", exitHex));
+
+ map.pathBuilder.setExit(exitZone.orientation);
+
+ unit.hideMoveable();
+ if (to != null)
+ map.hidePath(to);
+ map.hidePossibleMoves();
+ map.unselectHex(hex);
+
+ if (map.exitBoard(unit) > 0)
+ return StateType.MOVE;
+ return StateType.DONE;
+ }
+}