diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2017-05-18 13:23:45 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2017-05-18 13:23:45 +0200 |
commit | 65084e59bae1afe8fdb03b92d4312d8fee2d67aa (patch) | |
tree | 5c88e06fa8fea25c7506444e1ac11af418e64fa6 /core/src/ch | |
parent | d312cc529f90d025d0a199de7195196424641bed (diff) | |
download | RustAndDust-65084e59bae1afe8fdb03b92d4312d8fee2d67aa.zip RustAndDust-65084e59bae1afe8fdb03b92d4312d8fee2d67aa.tar.gz |
StateCommon : select(Unit) activate(Unit) -> u.select(boolean)
Diffstat (limited to 'core/src/ch')
8 files changed, 118 insertions, 96 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java index 1614465..446f79a 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java @@ -18,8 +18,30 @@ public abstract class StateCommon implements State protected static Hex selectedHex = null; protected static Hex to = null; - protected static Unit activeUnit; - protected static Unit selectedUnit; + private static Unit activeUnit; + private static Unit selectedUnit; + + private void select(Unit u, boolean s) + { + if (u != null) + u.select(s); + } + + public void select(Unit unit) + { + select(selectedUnit, false); + selectedUnit = unit; + select(selectedUnit, true); + } + public Unit selectedUnit() { return selectedUnit; } + + public void activate(Unit unit) + { + select(activeUnit, false); + activeUnit = unit; + select(activeUnit, true); + } + public Unit activeUnit() { return activeUnit; } public static void set(RustAndDust game) { diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java index 27ed7b8..bac0083 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java @@ -29,7 +29,7 @@ public class StateDeployment extends StateCommon showEntryZone((Unit) data); return true; case CANCEL: - if (activeUnit != null) + if (activeUnit() != null) undeployUnit(); return true; case OK: @@ -50,11 +50,11 @@ public class StateDeployment extends StateCommon @Override public void touch(Hex hex) { - if (activeUnit != null) { + if (activeUnit() != null) { deployUnit(Orientation.fromAdj(selectedHex, hex)); - } else if ((selectedUnit != null) && (entryZone != null)) { + } else if ((selectedUnit() != null) && (entryZone != null)) { if (hex.isEmpty() && entryZone.contains(hex)) { - showUnit(selectedUnit, hex); + showUnit(selectedUnit(), hex); } } else { Unit unit = hex.getUnit(); @@ -65,7 +65,7 @@ public class StateDeployment extends StateCommon private void showEntryZone(Unit unit) { - selectedUnit = unit; + select(unit); if (entryZone != null) entryZone.enable(Hex.AREA, false); entryZone = unit.entryZone; @@ -74,7 +74,7 @@ public class StateDeployment extends StateCommon private void showUnit(Unit unit, Hex hex) { - activeUnit = unit; + activate(unit); selectedHex = hex; ctrl.battle.getPlayer().reinforcement.remove(unit); map.setOnBoard(unit, hex, entryZone.orientation); @@ -86,7 +86,7 @@ public class StateDeployment extends StateCommon private void showRotation(Unit unit, Hex hex) { - activeUnit = unit; + activate(unit); selectedHex = hex; map.hexSelect(selectedHex); map.hexDirectionsShow(selectedHex); @@ -97,14 +97,14 @@ public class StateDeployment extends StateCommon private void deployUnit(Orientation o) { if (o == Orientation.KEEP) - o = activeUnit.getOrientation(); - ctrl.postOrder(map.getSetOrder(activeUnit, selectedHex, o), StateType.DEPLOYMENT); + o = activeUnit().getOrientation(); + ctrl.postOrder(map.getSetOrder(activeUnit(), selectedHex, o), StateType.DEPLOYMENT); clear(); } private void undeployUnit() { - ctrl.postOrder(map.getRevertSetOrder(activeUnit), StateType.DEPLOYMENT); + ctrl.postOrder(map.getRevertSetOrder(activeUnit()), StateType.DEPLOYMENT); ctrl.hud.update(); clear(); ctrl.hud.playerInfo.unitDock.show(); @@ -116,10 +116,10 @@ public class StateDeployment extends StateCommon map.hexUnselect(selectedHex); map.hexDirectionsHide(selectedHex); } - activeUnit = null; + activate(null); entryZone = null; selectedHex = null; - selectedUnit = null; + select(null); ctrl.hud.actionButtons.hide(); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java index 5d59d3c..32c4c42 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java @@ -20,15 +20,15 @@ public class StateEngage extends StateCommon { if (prevState == StateType.SELECT) { breakMove = false; - if ((to != null) && (activeUnit != null)) { + if ((to != null) && (activeUnit() != null)) { // quick fire - selectTarget(activeUnit, to); + selectTarget(activeUnit(), to); } - selectedUnit.showAttack(); + selectedUnit().showAttack(); map.hexSelect(selectedHex); } else { breakMove = true; - activeUnit = null; + activate(null); ctrl.hud.actionButtons.show(Buttons.DONE.b); ctrl.hud.notify("Break Through possible", Position.MIDDLE_CENTER); map.unitsActivableShow(); @@ -56,16 +56,16 @@ public class StateEngage extends StateCommon Unit unit = hex.getUnit(); if (!breakMove) { - if (unit == selectedUnit) + if (unit == selectedUnit()) abort(); - else if ((activeUnit == null) && map.unitsTargetContains(unit)) + else if ((activeUnit() == null) && map.unitsTargetContains(unit)) selectTarget(unit, hex); - else if (unit == activeUnit) + else if (unit == activeUnit()) engage(); - else if ((activeUnit != null) && map.unitsActivableContains(unit)) + else if ((activeUnit() != null) && map.unitsActivableContains(unit)) map.toggleAssist(unit); } else { - if (activeUnit == null) { + if (activeUnit() == null) { if (map.unitsActivableContains(unit)) selectBreakUnit(unit); } else { @@ -82,20 +82,20 @@ public class StateEngage extends StateCommon private void selectTarget(Unit unit, Hex hex) { to = hex; - activeUnit = unit; + activate(unit); map.unitsTargetHide(); - activeUnit.showTarget(); - map.collectAssists(selectedUnit, activeUnit, ctrl.battle.getPlayer().units); + activeUnit().showTarget(); + map.collectAssists(selectedUnit(), activeUnit(), ctrl.battle.getPlayer().units); map.unitsAssistShow(); } private void engage() { - activeUnit.hideTarget(); - selectedUnit.hideAttack(); + activeUnit().hideTarget(); + selectedUnit().hideAttack(); map.unitsAssistHide(); map.hexUnselect(selectedHex); - Order order = map.getEngageOrder(selectedUnit, activeUnit); + Order order = map.getEngageOrder(selectedUnit(), activeUnit()); if (order.cost == 0) ctrl.postOrder(order, StateType.ENGAGE); @@ -109,8 +109,8 @@ public class StateEngage extends StateCommon { map.unitsAssistHide(); map.unitsTargetHide(); - activeUnit.hideTarget(); - selectedUnit.hideAttack(); + activeUnit().hideTarget(); + selectedUnit().hideAttack(); map.hexUnselect(selectedHex); map.unitsActivatedClear(); ctrl.postActionAborted(); @@ -118,7 +118,7 @@ public class StateEngage extends StateCommon private void selectBreakUnit(Unit unit) { - activeUnit = unit; + activate(unit); map.hexMoveShow(to); map.hexMoveShow(unit.getHex()); map.hexDirectionsShow(to); @@ -128,27 +128,27 @@ public class StateEngage extends StateCommon private void unselectBreakUnit() { map.hexMoveHide(to); - map.hexMoveHide(activeUnit.getHex()); + map.hexMoveHide(activeUnit().getHex()); map.hexDirectionsHide(to); map.unitsActivableShow(); - activeUnit = null; + activate(null); } private void doBreakMove(Orientation o) { map.hexMoveHide(to); - map.hexMoveHide(activeUnit.getHex()); + map.hexMoveHide(activeUnit().getHex()); map.hexDirectionsHide(to); - map.pathsInit(activeUnit); + map.pathsInit(activeUnit()); map.pathsBuildShortest(to); map.pathsSetOrientation(o); - ctrl.postOrder(map.getMoveOrder(activeUnit, false)); + ctrl.postOrder(map.getMoveOrder(activeUnit(), false)); } private void abortBreakMove() { - if (activeUnit != null) - map.hexMoveHide(activeUnit.getHex()); + if (activeUnit() != null) + map.hexMoveHide(activeUnit().getHex()); map.hexMoveHide(to); map.hexDirectionsHide(to); map.unitsActivableHide(); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index ae0c751..b8fc638 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -34,8 +34,8 @@ public class StateMove extends StateCommon map.pathsClear(); if (prevState == StateType.SELECT) { map.hexSelect(selectedHex); - map.pathsInit(selectedUnit); - activeUnit = selectedUnit; + map.pathsInit(selectedUnit()); + activate(selectedUnit()); if (to == null) { hqMode = true; map.movesShow(); @@ -45,9 +45,9 @@ public class StateMove extends StateCommon } else if (prevState == StateType.REINFORCEMENT) { enter = true; map.hexSelect(selectedHex); - map.pathsInit(selectedUnit); - if (selectedUnit.getMovementPoints() > 0) { - map.movesCollect(selectedUnit); + map.pathsInit(selectedUnit()); + if (selectedUnit().getMovementPoints() > 0) { + map.movesCollect(selectedUnit()); map.movesShow(); } else { to = selectedHex; @@ -61,7 +61,7 @@ public class StateMove extends StateCommon if (hqMode) map.unitsActivableShow(); - activeUnit.hideActiveable(); + activeUnit().hideActiveable(); int n = (notFirst ? Buttons.DONE.b : 0); n |= (enter ? Buttons.ABORT.b : 0); ctrl.hud.actionButtons.show(n); @@ -107,18 +107,18 @@ public class StateMove extends StateCommon Orientation o = Orientation.fromAdj(to, hex); if (o != Orientation.KEEP) move(o); - else if (hex == activeUnit.getHex()) + else if (hex == activeUnit().getHex()) abortMove(); } return; } - if (hex == activeUnit.getHex()) { + if (hex == activeUnit().getHex()) { if (to != null) map.pathHide(to); map.pathsHide(); map.pathsClear(); - map.pathsInit(activeUnit); + map.pathsInit(activeUnit()); collectPaths(hex); return; } @@ -128,7 +128,7 @@ public class StateMove extends StateCommon Unit unit = hex.getUnit(); if (map.unitsActivableContains(unit)) { - if (unit != activeUnit) + if (unit != activeUnit()) selectUnit(unit); } else if ((s == 0) && map.movesContains(hex)) { collectPaths(hex); @@ -143,8 +143,8 @@ public class StateMove extends StateCommon private void selectNextUnit() { - if (selectedUnit.canMove()) - selectUnit(selectedUnit); + if (selectedUnit().canMove()) + selectUnit(selectedUnit()); else selectUnit(map.getFirstActivable()); } @@ -152,21 +152,21 @@ public class StateMove extends StateCommon private void selectUnit(Unit unit) { state = State.SHOW; - if (activeUnit != null ) { - map.hexUnselect(activeUnit.getHex()); - if (activeUnit.canMove()) - activeUnit.showActiveable(); + if (activeUnit() != null ) { + map.hexUnselect(activeUnit().getHex()); + if (activeUnit().canMove()) + activeUnit().showActiveable(); } to = null; - activeUnit = unit; - activeUnit.hideActiveable(); - map.hexSelect(activeUnit.getHex()); + activate(unit); + activeUnit().hideActiveable(); + map.hexSelect(activeUnit().getHex()); map.pathsClear(); - map.pathsInit(activeUnit); + map.pathsInit(activeUnit()); map.movesHide(); - map.movesCollect(activeUnit); + map.movesCollect(activeUnit()); map.movesShow(); - ctrl.hud.notify(activeUnit.toString()); + ctrl.hud.notify(activeUnit().toString()); } private void collectPaths(Hex hex) @@ -203,15 +203,15 @@ public class StateMove extends StateCommon { if (enter) return false; - if ((activeUnit.exitZone == null) || !activeUnit.exitZone.contains(hex)) + if ((activeUnit().exitZone == null) || !activeUnit().exitZone.contains(hex)) return false; int s = map.pathsBuild(to); - if (!map.pathsCanExit(activeUnit.exitZone.orientation)) + if (!map.pathsCanExit(activeUnit().exitZone.orientation)) return false; - if (map.pathsChooseExit(activeUnit.exitZone.orientation) > 1) + if (map.pathsChooseExit(activeUnit().exitZone.orientation) > 1) throw new RuntimeException(String.format("pathsChooseExit() -> %d", map.pathsSize())); map.pathShow(hex); @@ -234,20 +234,20 @@ public class StateMove extends StateCommon { map.pathsSetOrientation(o); if (enter) - completeMove(map.getEnterOrder(selectedUnit, hqMode)); + completeMove(map.getEnterOrder(selectedUnit(), hqMode)); else - completeMove(map.getMoveOrder(selectedUnit, hqMode)); + completeMove(map.getMoveOrder(selectedUnit(), hqMode)); } private void exit() { if (map.pathsTo() == null) { map.pathsBuild(to); - if (map.pathsChooseExit(activeUnit.exitZone.orientation) > 1) + if (map.pathsChooseExit(activeUnit().exitZone.orientation) > 1) throw new RuntimeException(String.format("pathsChooseExit() -> %d", map.pathsSize())); } - completeMove(map.getExitOrder(selectedUnit, hqMode)); + completeMove(map.getExitOrder(selectedUnit(), hqMode)); } private void completeMove(Order order) @@ -263,8 +263,8 @@ public class StateMove extends StateCommon private void endHqMode() { - if (selectedUnit.canMove()) - selectedUnit.setMoved(); + if (selectedUnit().canMove()) + selectedUnit().setMoved(); clear(); ctrl.postOrder(Order.END); } @@ -272,8 +272,8 @@ public class StateMove extends StateCommon private void abortMove() { if (enter) { - map.revertEnter(activeUnit); - ctrl.battle.getPlayer().revertUnitEntry(activeUnit); + map.revertEnter(activeUnit()); + ctrl.battle.getPlayer().revertUnitEntry(activeUnit()); ctrl.hud.update(); } clear(); @@ -283,7 +283,7 @@ public class StateMove extends StateCommon // map.revertMoves(); // ctrl.postTransitionToAborted(); // } else { - selectUnit(activeUnit); + selectUnit(activeUnit()); abortCompleted(); // } } @@ -308,7 +308,7 @@ public class StateMove extends StateCommon { if (hqMode) map.unitsActivableShow(); - activeUnit.hideActiveable(); + activeUnit().hideActiveable(); ctrl.hud.actionButtons.show((notFirst ? Buttons.DONE.b : 0)); } @@ -317,8 +317,8 @@ public class StateMove extends StateCommon state = State.SHOW; map.movesHide(); map.pathsHide(); - activeUnit.hideActiveable(); - map.hexUnselect(activeUnit.getHex()); + activeUnit().hideActiveable(); + map.hexUnselect(activeUnit().getHex()); map.unitsActivableHide(); if (to != null) { map.pathHide(to); diff --git a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java index 774b1a9..8dcf5f4 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java +++ b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java @@ -5,6 +5,6 @@ public class StatePromote extends StateCommon @Override public void enterFrom(StateType prevState) { - ctrl.postOrder(map.getPromoteOrder(selectedUnit)); + 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 847b622..7feee88 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java @@ -15,9 +15,9 @@ public class StateReinforcement extends StateCommon map.clearMoves(); map.clearUnits(); entryZone = null; - activeUnit = null; + activate(null); selectedHex = null; - selectedUnit = null; + select(null); ctrl.hud.playerInfo.unitDock.show(); } @@ -38,12 +38,12 @@ public class StateReinforcement extends StateCommon public void touch(Hex hex) { if ((entryZone != null) && hex.isEmpty() && entryZone.contains(hex)) - unitEnter(selectedUnit, hex); + unitEnter(selectedUnit(), hex); } private void showEntryZone(Unit unit) { - selectedUnit = unit; + select(unit); if (entryZone != null) entryZone.enable(Hex.AREA, false); entryZone = unit.entryZone; @@ -52,7 +52,7 @@ public class StateReinforcement extends StateCommon private void unitEnter(Unit unit, Hex hex) { - activeUnit = unit; + activate(unit); selectedHex = hex; map.enterBoard(unit, hex, entryZone); entryZone.enable(Hex.AREA, false); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReplay.java b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java index 22105fb..969262e 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateReplay.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateReplay.java @@ -31,7 +31,7 @@ public class StateReplay extends StateCommon switch (order.type) { case MOVE: - selectedUnit = order.leader; + select(order.leader); break; case ENGAGE: to = order.engagement.defender.getHex(); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java index 2460727..2a4f537 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java @@ -42,7 +42,7 @@ public class StateSelect extends StateCommon { Unit unit = hex.getUnit(); - if (!isEnemy && (selectedUnit != null)) { + if (!isEnemy && (selectedUnit() != null)) { if (map.movesContains(hex)) { // quick move to = hex; @@ -52,7 +52,7 @@ public class StateSelect extends StateCommon if (map.unitsTargetContains(unit)) { // quick fire to = hex; - activeUnit = unit; + activate(unit); changeTo(StateType.ENGAGE); return; } @@ -61,13 +61,13 @@ public class StateSelect extends StateCommon hide(); if ((unit == null) || hex.isOffMap()) { - selectedUnit = null; + select(null); return; } isEnemy = ctrl.battle.getPlayer().isEnemy(unit); - if (!isEnemy && (selectedUnit == unit) && unit.canMove()) { + if (!isEnemy && (selectedUnit() == unit) && unit.canMove()) { if (unit.isHq() && (map.unitsActivableSize() > 1)) { ctrl.hud.notify("HQ activation", Position.MIDDLE_CENTER); to = null; @@ -76,34 +76,34 @@ public class StateSelect extends StateCommon changeTo(StateType.MOVE); } else { select(hex, unit); - ctrl.hud.notify(selectedUnit.toString()); + ctrl.hud.notify(selectedUnit().toString()); } } private void select(Hex hex, Unit unit) { selectedHex = hex; - selectedUnit = unit; - RustAndDust.debug(String.format(" %s - %s", selectedUnit, selectedHex)); + select(unit); + RustAndDust.debug(String.format(" %s - %s", selectedUnit(), selectedHex)); map.hexSelect(selectedHex); if (isEnemy && !cfg.showEnemyPossibilities) return; - if(map.movesCollect(selectedUnit) > 0) { - map.collectMoveable(selectedUnit); + if(map.movesCollect(selectedUnit()) > 0) { + map.collectMoveable(selectedUnit()); if (cfg.showMoves) map.movesShow(); if (cfg.showMoveAssists) map.unitsActivableShow(); unit.hideActiveable(); } - if (map.collectTargets(selectedUnit, (isEnemy ? ctrl.battle.getPlayer() : ctrl.battle.getOpponent()).units) > 0) { + 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 ); + ctrl.hud.actionButtons.show((ctrl.battle.getPlayer().canPromote(selectedUnit())) ? Buttons.PROMOTE.b : 0 ); } private void changeTo(StateType nextState) @@ -130,7 +130,7 @@ public class StateSelect extends StateCommon to = null; isEnemy = false; selectedHex = null; - selectedUnit = null; - activeUnit = null; + select(null); + activate(null); } } |