diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 13:12:56 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 13:12:56 +0100 |
commit | ff3a287ed7663e1e672cb679374b035e9e82e60a (patch) | |
tree | c9d538513410eb2461de615ce256c69a47a81661 /core/src/ch/asynk/rustanddust/game/states | |
parent | 6ab504ae254d1ed4346ecab8ff7e0503224f6881 (diff) | |
download | RustAndDust-ff3a287ed7663e1e672cb679374b035e9e82e60a.zip RustAndDust-ff3a287ed7663e1e672cb679374b035e9e82e60a.tar.gz |
Map,States: UnitList are protected, set a common API
Diffstat (limited to 'core/src/ch/asynk/rustanddust/game/states')
6 files changed, 35 insertions, 29 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java index 89a9224..459f640 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java @@ -2,6 +2,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.engine.Orientation; import ch.asynk.rustanddust.game.Unit; +import ch.asynk.rustanddust.game.Map.UnitType; import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons; import ch.asynk.rustanddust.RustAndDust; @@ -16,13 +17,13 @@ public class StateBreak extends StateCommon activeUnit = null; ctrl.hud.actionButtons.show(Buttons.DONE.b); ctrl.hud.pushNotify("Break move possible"); - map.showBreakUnits(); + map.unitsShow(UnitType.BREAK_THROUGH); } @Override public void leave(StateType nextState) { - map.hideBreakUnits(); + map.unitsHide(UnitType.BREAK_THROUGH); map.hideMove(to); map.hideDirections(to); if (activeUnit != null) map.hideMove(activeUnit.getHex()); @@ -51,12 +52,12 @@ public class StateBreak extends StateCommon // TODO : cancel preview move before showing rotation if (activeUnit == null) { Unit unit = upHex.getUnit(); - if (map.breakUnits.contains(unit)) { + if (map.unitsContains(UnitType.BREAK_THROUGH, unit)) { activeUnit = unit; map.showMove(upHex); map.showMove(to); map.showDirections(to); - map.hideBreakUnits(); + map.unitsHide(UnitType.BREAK_THROUGH); } } else { o = Orientation.fromAdj(to, upHex); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java index 443182d..feda4ed 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.game.Map; +import ch.asynk.rustanddust.game.Map.UnitType; import ch.asynk.rustanddust.game.Hex; import ch.asynk.rustanddust.game.Unit; import ch.asynk.rustanddust.game.Ctrl; @@ -54,15 +55,15 @@ public abstract class StateCommon implements State 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(); + if (ctrl.cfg.showTargets && unit.canEngage()) map.unitsShow(UnitType.TARGETS); + if (ctrl.cfg.showMoveAssists && unit.canMove()) map.unitsShow(UnitType.MOVEABLE); unit.enableOverlay(Unit.MOVE, false); } protected void hidePossibilities() { map.hidePossibleMoves(); - map.hidePossibleTargets(); - map.hideMoveableUnits(); + map.unitsShow(UnitType.TARGETS); + map.unitsShow(UnitType.MOVEABLE); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java index 4588cb2..a4be2da 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.game.Unit; +import ch.asynk.rustanddust.game.Map.UnitType; import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons; import ch.asynk.rustanddust.RustAndDust; @@ -10,16 +11,16 @@ public class StateEngage extends StateCommon @Override public void enter(StateType prevState) { - map.possibleTargets.clear(); + map.unitsClear(UnitType.TARGETS); 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.unitsHide(UnitType.TARGETS); map.collectPossibleTargets(selectedUnit, ctrl.opponent.units); - map.showPossibleTargets(); + map.unitsShow(UnitType.TARGETS); if (to != null) { // quick fire -> replay touchUp upHex = to; @@ -35,8 +36,8 @@ public class StateEngage extends StateCommon public void leave(StateType nextState) { selectedUnit.hideAttack(); - map.hideAttackAssists(); - map.hidePossibleTargets(); + map.unitsHide(UnitType.ASSISTS); + map.unitsHide(UnitType.TARGETS); map.unselectHex(selectedHex); if (to != null) map.unselectHex(to); @@ -45,7 +46,7 @@ public class StateEngage extends StateCommon @Override public StateType abort() { - map.activatedUnits.clear(); + map.unitsClear(UnitType.ACTIVATED); return StateType.ABORT; } @@ -56,7 +57,7 @@ public class StateEngage extends StateCommon if (map.engageUnit(selectedUnit, activeUnit)) { ctrl.player.wonEngagementCount += 1; ctrl.opponent.casualty(activeUnit); - if (map.breakUnits.size() > 0) { + if (map.unitsSize(UnitType.BREAK_THROUGH) > 0) { nextState = StateType.BREAK; } } else { @@ -81,20 +82,20 @@ public class StateEngage extends StateCommon // activeUnit is the target, selectedTarget is the engagement leader if (unit == selectedUnit) { ctrl.setState(StateType.ABORT); - } else if ((activeUnit == null) && map.possibleTargets.contains(unit)) { + } else if ((activeUnit == null) && map.unitsContains(UnitType.TARGETS, unit)) { // ctrl.hud.notify("Engage " + unit); - map.hidePossibleTargets(); + map.unitsHide(UnitType.TARGETS); to = upHex; activeUnit = unit; activeUnit.showTarget(); map.collectAttackAssists(selectedUnit, activeUnit, ctrl.player.units); - map.showAttackAssists(); + map.unitsShow(UnitType.ASSISTS); 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)) { + else if ((activeUnit != null) && map.unitsContains(UnitType.ASSISTS, unit)) { map.toggleAttackAssist(unit); // if(map.toggleAttackAssist(unit)) // ctrl.hud.notify(unit + " will fire"); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index 798e127..78dfb40 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -3,6 +3,7 @@ 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.Map.UnitType; import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons; public class StateMove extends StateCommon @@ -11,7 +12,7 @@ public class StateMove extends StateCommon public void enter(StateType prevState) { ctrl.hud.actionButtons.show( - ((map.activatedUnits.size() > 0) ? Buttons.DONE.b : 0) + ((map.unitsSize(UnitType.ACTIVATED) > 0) ? Buttons.DONE.b : 0) | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0)); if (prevState == StateType.WITHDRAW) { @@ -39,7 +40,7 @@ public class StateMove extends StateCommon if (selectedUnit.canMove()) { changeUnit(selectedUnit); } else { - changeUnit(map.moveableUnits.get(0)); + changeUnit(map.unitsGet(UnitType.MOVEABLE, 0)); } } @@ -73,7 +74,7 @@ public class StateMove extends StateCommon map.revertEnter(activeUnit); return StateType.ABORT; } - int n = map.activatedUnits.size(); + int n = map.unitsSize(UnitType.ACTIVATED); if (n == 0) return StateType.ABORT; map.revertMoves(); @@ -85,7 +86,7 @@ public class StateMove extends StateCommon { hideAssists(); // be sure that the hq is activated - if (selectedUnit.canMove() && (map.activatedUnits.size() > 0)) + if (selectedUnit.canMove() && (map.unitsSize(UnitType.ACTIVATED) > 0)) selectedUnit.setMoved(); return StateType.DONE; @@ -112,7 +113,7 @@ public class StateMove extends StateCommon Unit unit = upHex.getUnit(); - if (map.moveableUnits.contains(unit)) { + if (map.unitsContains(UnitType.MOVEABLE, unit)) { if(unit != activeUnit) changeUnit(unit); } else if ((s == 0) && map.possibleMoves.contains(upHex)) { @@ -129,7 +130,7 @@ public class StateMove extends StateCommon private void hideAssists() { - map.hideMoveableUnits(); + map.unitsHide(UnitType.MOVEABLE); } private void changeUnit(Unit unit) diff --git a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java index 5a10471..4ec9829 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.engine.Orientation; +import ch.asynk.rustanddust.game.Map.UnitType; import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons; import ch.asynk.rustanddust.RustAndDust; @@ -13,7 +14,7 @@ public class StateRotate extends StateCommon @Override public void enter(StateType prevState) { - ctrl.hud.actionButtons.show((ctrl.cfg.canCancel && (map.moveableUnits.size() > 1))? Buttons.ABORT.b : 0); + ctrl.hud.actionButtons.show((ctrl.cfg.canCancel && (map.unitsSize(UnitType.MOVEABLE) > 1))? Buttons.ABORT.b : 0); if (activeUnit == null) activeUnit = selectedUnit; @@ -56,8 +57,8 @@ public class StateRotate extends StateCommon if (activeUnit.justEntered()) { map.revertEnter(activeUnit); nextState = StateType.ABORT; - } else if (map.activatedUnits.size() == 0) { - map.hideMoveableUnits(); + } else if (map.unitsSize(UnitType.ACTIVATED) == 0) { + map.unitsHide(UnitType.MOVEABLE); } else { nextState = StateType.MOVE; } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java index 9161a6b..5844453 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.game.Map; +import ch.asynk.rustanddust.game.Map.UnitType; import ch.asynk.rustanddust.game.Hex; import ch.asynk.rustanddust.game.Unit; import ch.asynk.rustanddust.game.Ctrl; @@ -63,7 +64,7 @@ public class StateSelect extends StateCommon ctrl.setState(StateType.MOVE); return; } - if (map.possibleTargets.contains(upHex.getUnit())) { + if (map.unitsContains(UnitType.TARGETS, upHex.getUnit())) { // quick fire to = upHex; ctrl.setState(StateType.ENGAGE); |