diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 15:49:09 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-12-07 15:49:09 +0100 |
commit | 3ef72fb9f15c0954ac2464bd724a8b2595cce618 (patch) | |
tree | e09a8a5727bb834976d57006e82a398ad4ad5e16 | |
parent | 406635ee3709e511867e01a05ce24a79ffbe53f7 (diff) | |
download | RustAndDust-3ef72fb9f15c0954ac2464bd724a8b2595cce618.zip RustAndDust-3ef72fb9f15c0954ac2464bd724a8b2595cce618.tar.gz |
Map,States: possbleMoves->protected moves, pathBuilder->paths
7 files changed, 74 insertions, 69 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Map.java b/core/src/ch/asynk/rustanddust/game/Map.java index c5e1153..2a50512 100644 --- a/core/src/ch/asynk/rustanddust/game/Map.java +++ b/core/src/ch/asynk/rustanddust/game/Map.java @@ -37,8 +37,8 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS { private final Ctrl ctrl; - public final HexSet possibleMoves; - public final PathBuilder pathBuilder; + protected final HexSet moves; + public final PathBuilder paths; protected final UnitList moveableUnits; protected final UnitList targetUnits; @@ -84,8 +84,8 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS setup(); - possibleMoves = new HexSet(this, 40); - pathBuilder = new PathBuilder(this, 10, 20, 5, 10); + moves = new HexSet(this, 40); + paths = new PathBuilder(this, 10, 20, 5, 10); moveableUnits = new UnitList(6); targetUnits = new UnitList(10); @@ -105,7 +105,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS super.dispose(); clearAll(); destroy.dispose(); - pathBuilder.dispose(); + paths.dispose(); DiceAnimation.free(); PromoteAnimation.free(); FireAnimation.free(); @@ -116,8 +116,8 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS public void clearAll() { - possibleMoves.clear(); - pathBuilder.clear(); + moves.clear(); + paths.clear(); moveableUnits.clear(); targetUnits.clear(); assistUnits.clear(); @@ -162,18 +162,23 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS showObjective(hex, objectives.unclaim(hex)); } - public int collectPossibleMoves(Unit unit) + public boolean movesContains(Hex hex) + { + return moves.contains(hex); + } + + public int movesCollect(Unit unit) { if (unit.canMove()) - return collectPossibleMoves(unit, possibleMoves.asTiles()); + return collectPossibleMoves(unit, moves.asTiles()); - possibleMoves.clear(); + moves.clear(); return 0; } - public int togglePathBuilderHex(Hex hex) + public int pathsToggleHex(Hex hex) { - return pathBuilder.toggleCtrlTile(hex); + return paths.toggleCtrlTile(hex); } public int collectPossibleTargets(Unit unit, UnitList foes) @@ -221,11 +226,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS public void collectAndShowMovesAndAssits(Unit unit) { - hidePossibleMoves(); + movesHide(); unitsHide(UnitType.MOVEABLE); - collectPossibleMoves(unit); + movesCollect(unit); collectMoveableUnits(unit); - showPossibleMoves(); + movesShow(); unitsShow(UnitType.MOVEABLE); activatedUnits.clear(); } @@ -381,12 +386,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS public int exitBoard(final Unit unit) { - return process(getMoveCommand(unit, pathBuilder.getExitMove())); + return process(getMoveCommand(unit, paths.getExitMove())); } public int moveUnit(final Unit unit) { - return process(getMoveCommand(unit, pathBuilder.getMove())); + return process(getMoveCommand(unit, paths.getMove())); } public void revertMoves() @@ -663,12 +668,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS unit.enableOverlay(overlay, on); } - public void showPossibleMoves() { possibleMoves.enable(Hex.AREA, true); } - public void hidePossibleMoves() { possibleMoves.enable(Hex.AREA, false); } - public void showPathBuilder() { pathBuilder.enable(Hex.AREA, true); } - public void hidePathBuilder() { pathBuilder.enable(Hex.AREA, false); } - public void showPath(Hex dst) { pathBuilder.enable(Hex.MOVE, true); hexMoveShow(dst); } - public void hidePath(Hex dst) { pathBuilder.enable(Hex.MOVE, false); hexMoveHide(dst); } + public void movesShow() { moves.enable(Hex.AREA, true); } + public void movesHide() { moves.enable(Hex.AREA, false); } + public void pathsShow() { paths.enable(Hex.AREA, true); } + public void pathsHide() { paths.enable(Hex.AREA, false); } + public void pathShow(Hex dst) { paths.enable(Hex.MOVE, true); hexMoveShow(dst); } + public void pathHide(Hex dst) { paths.enable(Hex.MOVE, false); hexMoveHide(dst); } public void hexSelect(Hex hex) { selectedTile.set(hex); } public void hexUnselect(Hex hex) { selectedTile.hide(); } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java index 99dfb63..3768e6f 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java @@ -78,9 +78,9 @@ public class StateBreak extends StateCommon { if (activeUnit == null) return; - map.pathBuilder.init(activeUnit); - if (map.pathBuilder.build(to) == 1) { - map.pathBuilder.orientation = o; + map.paths.init(activeUnit); + if (map.paths.build(to) == 1) { + map.paths.orientation = o; map.moveUnit(activeUnit); ctrl.setAfterAnimationState(StateType.DONE); } else diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java index feda4ed..a2aa490 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java @@ -54,7 +54,7 @@ public abstract class StateCommon implements State protected void showPossibilities(Unit unit) { - if (ctrl.cfg.showMoves && unit.canMove()) map.showPossibleMoves(); + if (ctrl.cfg.showMoves && unit.canMove()) map.movesShow(); 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); @@ -62,8 +62,8 @@ public abstract class StateCommon implements State protected void hidePossibilities() { - map.hidePossibleMoves(); - map.unitsShow(UnitType.TARGETS); - map.unitsShow(UnitType.MOVEABLE); + map.movesHide(); + map.unitsHide(UnitType.TARGETS); + map.unitsHide(UnitType.MOVEABLE); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index 69f14c4..762c476 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -16,18 +16,18 @@ public class StateMove extends StateCommon | (ctrl.cfg.canCancel ? Buttons.ABORT.b : 0)); if (prevState == StateType.WITHDRAW) { - if (map.pathBuilder.size() == 1) + if (map.paths.size() == 1) ctrl.setState(StateType.ROTATE); return; } - map.pathBuilder.clear(); + map.paths.clear(); if (prevState == StateType.SELECT) { // use selectedHex and selectedUnit activeUnit = selectedUnit; activeUnit.showMoveable(); - map.pathBuilder.init(activeUnit); + map.paths.init(activeUnit); map.collectAndShowMovesAndAssits(activeUnit); if (to != null) { // quick move -> replay touchUp @@ -55,10 +55,10 @@ public class StateMove extends StateCommon // hide all but assists : want them when in rotation activeUnit.hideMoveable(); - map.hidePossibleMoves(); + map.movesHide(); map.hexUnselect(activeUnit.getHex()); if (to != null) - map.hidePath(to); + map.pathHide(to); if (nextState != StateType.SELECT) { if (to == null) @@ -102,23 +102,23 @@ public class StateMove extends StateCommon { if (upHex == activeUnit.getHex()) { if (to != null) - map.hidePath(to); + map.pathHide(to); to = null; - map.pathBuilder.clear(); + map.paths.clear(); ctrl.setState(StateType.ROTATE); return; } - int s = map.pathBuilder.size(); + int s = map.paths.size(); Unit unit = upHex.getUnit(); if (map.unitsContains(UnitType.MOVEABLE, unit)) { if(unit != activeUnit) changeUnit(unit); - } else if ((s == 0) && map.possibleMoves.contains(upHex)) { + } else if ((s == 0) && map.movesContains(upHex)) { s = collectPaths(upHex); - } else if (map.pathBuilder.contains(upHex)) { + } else if (map.paths.contains(upHex)) { s = togglePoint(downHex, s); } @@ -142,11 +142,11 @@ public class StateMove extends StateCommon } activeUnit = unit; Hex hex = activeUnit.getHex(); - map.pathBuilder.init(activeUnit, hex); + map.paths.init(activeUnit, hex); activeUnit.showMoveable(); - map.hidePossibleMoves(); - map.collectPossibleMoves(activeUnit); - map.showPossibleMoves(); + map.movesHide(); + map.movesCollect(activeUnit); + map.movesShow(); map.hexSelect(hex); activeUnit.enableOverlay(Unit.MOVE, false); ctrl.hud.notify(activeUnit.toString()); @@ -156,12 +156,12 @@ public class StateMove extends StateCommon private int collectPaths(Hex hex) { to = hex; - int s = map.pathBuilder.build(to); + int s = map.paths.build(to); if (s > 1) - s = map.pathBuilder.choosePath(); + s = map.paths.choosePath(); map.hexMoveShow(to); - map.hidePossibleMoves(); - map.showPathBuilder(); + map.movesHide(); + map.pathsShow(); return s; } @@ -172,10 +172,10 @@ public class StateMove extends StateCommon } else if (hex == to) { // } else { - map.hidePathBuilder(); + map.pathsHide(); map.togglePathOverlay(hex); - s = map.togglePathBuilderHex(hex); - map.showPathBuilder(); + s = map.pathsToggleHex(hex); + map.pathsShow(); } return s; @@ -188,7 +188,7 @@ public class StateMove extends StateCommon Zone exitZone = ctrl.battle.getExitZone(unit); if ((exitZone == null) || !exitZone.contains(hex)) return false; - if ((unit.getHex() != hex) && !map.pathBuilder.canExit(exitZone.orientation)) + if ((unit.getHex() != hex) && !map.paths.canExit(exitZone.orientation)) return false; ctrl.setState(StateType.WITHDRAW); return true; diff --git a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java index b92323b..a7dffa0 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java @@ -21,18 +21,18 @@ public class StateRotate extends StateCommon if (to == null) to = activeUnit.getHex(); - if (!map.pathBuilder.isSet()) { - map.pathBuilder.init(activeUnit); - map.pathBuilder.build(to); + if (!map.paths.isSet()) { + map.paths.init(activeUnit); + map.paths.build(to); } - if (map.pathBuilder.size() != 1) - RustAndDust.debug("ERROR: pathBuilder.size() == " + map.pathBuilder.size()); + if (map.paths.size() != 1) + RustAndDust.debug("ERROR: paths.size() == " + map.paths.size()); rotateOnly = (to == activeUnit.getHex()); if (!rotateOnly) - map.showPath(to); + map.pathShow(to); map.hexSelect(activeUnit.getHex()); map.hexDirectionsShow(to); @@ -43,9 +43,9 @@ public class StateRotate extends StateCommon public void leave(StateType nextState) { map.hexUnselect(activeUnit.getHex()); - map.hidePath(to); + map.pathHide(to); map.hexDirectionsHide(to); - map.pathBuilder.clear(); + map.paths.clear(); to = null; } @@ -96,7 +96,7 @@ public class StateRotate extends StateCommon if (!activeUnit.justEntered() && rotateOnly && (o == activeUnit.getOrientation())) return; - map.pathBuilder.orientation = o; + map.paths.orientation = o; rotationSet = true; if (ctrl.cfg.mustValidate) { diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java index 21fe844..def2224 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java @@ -58,7 +58,7 @@ public class StateSelect extends StateCommon public void touchUp() { if (!isEnemy) { - if (map.possibleMoves.contains(upHex)) { + if (map.movesContains(upHex)) { // quick move to = upHex; ctrl.setState(StateType.MOVE); @@ -116,7 +116,7 @@ public class StateSelect extends StateCommon if (isEnemy && !ctrl.cfg.showEnemyPossibilities) return; - int moves = map.collectPossibleMoves(selectedUnit); + int moves = map.movesCollect(selectedUnit); int targets = map.collectPossibleTargets(selectedUnit, (isEnemy ? ctrl.player.units : ctrl.opponent.units)); if (moves > 0) diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java index e1cfd0e..4e48d77 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java @@ -49,19 +49,19 @@ public class StateWithdraw extends StateCommon Hex hex = unit.getHex(); // rotation - if (map.pathBuilder.to == null) - map.pathBuilder.build(hex); + if (map.paths.to == null) + map.paths.build(hex); - Hex exitHex = (Hex) map.pathBuilder.to; + Hex exitHex = (Hex) map.paths.to; if (!exitZone.contains(exitHex)) throw new RuntimeException(String.format("%s not in exitZone", exitHex)); - map.pathBuilder.setExit(exitZone.orientation); + map.paths.setExit(exitZone.orientation); unit.hideMoveable(); if (to != null) - map.hidePath(to); - map.hidePossibleMoves(); + map.pathHide(to); + map.movesHide(); map.hexUnselect(hex); if (map.exitBoard(unit) > 0) |