From 4f3e3b341317288bf2da57aca90d86a1e9c8f956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 10 Feb 2016 11:20:13 +0100 Subject: Battle,State: use entry and exit Zones from Unit and Map --- core/src/ch/asynk/rustanddust/game/Battle.java | 4 --- .../rustanddust/game/battles/BattleCommon.java | 36 +++++----------------- .../rustanddust/game/states/StateDeployment.java | 2 +- .../asynk/rustanddust/game/states/StateMove.java | 9 ++---- .../game/states/StateReinforcement.java | 2 +- .../rustanddust/game/states/StateWithdraw.java | 6 ++-- 6 files changed, 15 insertions(+), 44 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java index baa27bb..1f82bfb 100644 --- a/core/src/ch/asynk/rustanddust/game/Battle.java +++ b/core/src/ch/asynk/rustanddust/game/Battle.java @@ -35,9 +35,5 @@ public interface Battle public State.StateType getState(); - public Zone getEntryZone(Unit unit); - - public Zone getExitZone(Unit unit); - public String unload(); } diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index d744734..fbf088d 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -1,7 +1,6 @@ package ch.asynk.rustanddust.game.battles; import java.util.Random; -import java.util.HashMap; import ch.asynk.rustanddust.game.Ctrl; import ch.asynk.rustanddust.game.Battle; @@ -15,7 +14,6 @@ import ch.asynk.rustanddust.game.Unit.UnitCode; import ch.asynk.rustanddust.game.Factory; import ch.asynk.rustanddust.game.State.StateType; import ch.asynk.rustanddust.engine.Orientation; -import ch.asynk.rustanddust.engine.util.IterableArray; public abstract class BattleCommon implements Battle { @@ -30,10 +28,6 @@ public abstract class BattleCommon implements Battle protected Map map; protected Player currentPlayer; protected Player[] players; - protected IterableArray entryZones = new IterableArray(10); - protected IterableArray exitZones = new IterableArray(10); - protected HashMap unitEntry = new HashMap(); - protected HashMap unitExit = new HashMap(); protected abstract Player getWinner(); protected abstract void setupMap(); @@ -227,26 +221,14 @@ public abstract class BattleCommon implements Battle return StateType.SELECT; } - @Override - public Zone getEntryZone(Unit unit) - { - return unitEntry.get(unit); - } - - @Override - public Zone getExitZone(Unit unit) - { - return unitExit.get(unit); - } - protected void addEntryZone(Zone entry) { - entryZones.add(entry); + map.addEntryZone(entry); } protected void addExitZone(Zone exit) { - exitZones.add(exit); + map.addExitZone(exit); exit.enable(Hex.EXIT, true); } @@ -269,9 +251,8 @@ public abstract class BattleCommon implements Battle { Unit unit = factory.getUnit(unitCode, hq, ace); player.addReinforcement(unit); - unitEntry.put(unit, entryZone); - if (exitZone != null) - unitExit.put(unit, exitZone); + unit.entryZone = entryZone; + if (exitZone != null) unit.exitZone = exitZone; } protected Unit setUnit(Map map, Player player, UnitCode unitCode, int col, int row, Orientation orientation, Zone exitZone) @@ -281,10 +262,9 @@ public abstract class BattleCommon implements Battle protected Unit setUnit(Map map, Player player, UnitCode unitCode, int col, int row, Orientation orientation, boolean hq, boolean ace, Zone exitZone) { - Unit u = factory.getUnit(unitCode, hq, ace); - if (exitZone != null) - unitExit.put(u, exitZone); - map.setOnBoard(u, map.getHex(col, row), orientation); - return u; + Unit unit = factory.getUnit(unitCode, hq, ace); + if (exitZone != null) unit.exitZone = exitZone; + map.setOnBoard(unit, map.getHex(col, row), orientation); + return unit; } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java index 1abac5a..516c058 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java @@ -73,7 +73,7 @@ public class StateDeployment extends StateCommon { activeUnit = unit; if (entryZone != null) entryZone.enable(Hex.AREA, false); - entryZone = ctrl.battle.getEntryZone(activeUnit); + entryZone = activeUnit.entryZone; entryZone.enable(Hex.AREA, true); } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index 3072396..16d5dd3 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -3,7 +3,6 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.ui.Position; 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 @@ -181,8 +180,7 @@ public class StateMove extends StateCommon { if (unit.justEntered()) return false; - Zone exitZone = ctrl.battle.getExitZone(unit); - if ((exitZone == null) || !exitZone.contains(unit.getHex())) + if ((unit.exitZone == null) || !unit.exitZone.contains(unit.getHex())) return false; ctrl.setState(StateType.WITHDRAW); return true; @@ -190,10 +188,9 @@ public class StateMove extends StateCommon private boolean checkExit(Unit unit, Hex hex) { - Zone exitZone = ctrl.battle.getExitZone(unit); - if ((exitZone == null) || !exitZone.contains(hex)) + if ((unit.exitZone == null) || !unit.exitZone.contains(hex)) return false; - if (!map.pathsCanExit(exitZone.orientation)) + if (!map.pathsCanExit(unit.exitZone.orientation)) return false; ctrl.setState(StateType.WITHDRAW); return true; diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java index 8c89f3b..bb975df 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java @@ -58,7 +58,7 @@ public class StateReinforcement extends StateCommon activeUnit = unit; if (entryZone != null) entryZone.enable(Hex.AREA, false); - entryZone = ctrl.battle.getEntryZone(activeUnit); + entryZone = activeUnit.entryZone; entryZone.enable(Hex.AREA, true); } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java index 12bb3c4..921eecc 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java @@ -1,6 +1,5 @@ package ch.asynk.rustanddust.game.states; -import ch.asynk.rustanddust.game.Zone; import ch.asynk.rustanddust.game.Hex; import ch.asynk.rustanddust.game.Unit; import ch.asynk.rustanddust.RustAndDust; @@ -36,7 +35,6 @@ public class StateWithdraw extends StateCommon private StateType withdraw(Unit unit) { - Zone exitZone = ctrl.battle.getExitZone(unit); Hex hex = unit.getHex(); // rotation @@ -44,10 +42,10 @@ public class StateWithdraw extends StateCommon map.pathsBuild(hex); Hex exitHex = (Hex) map.pathsTo(); - if (!exitZone.contains(exitHex)) + if (!unit.exitZone.contains(exitHex)) throw new RuntimeException(String.format("%s not in exitZone", exitHex)); - if (map.pathsChooseExit(exitZone.orientation) > 1) + if (map.pathsChooseExit(unit.exitZone.orientation) > 1) RustAndDust.debug("ERROR: Withdraw pathsSize() == " + map.pathsSize()); unit.hideActiveable(); -- cgit v1.1-2-g2b99