summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-07 13:12:56 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-07 13:12:56 +0100
commitff3a287ed7663e1e672cb679374b035e9e82e60a (patch)
treec9d538513410eb2461de615ce256c69a47a81661 /core/src/ch/asynk
parent6ab504ae254d1ed4346ecab8ff7e0503224f6881 (diff)
downloadRustAndDust-ff3a287ed7663e1e672cb679374b035e9e82e60a.zip
RustAndDust-ff3a287ed7663e1e672cb679374b035e9e82e60a.tar.gz
Map,States: UnitList are protected, set a common API
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/rustanddust/game/Map.java142
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateBreak.java9
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateCommon.java9
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateEngage.java23
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateMove.java13
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateRotate.java7
-rw-r--r--core/src/ch/asynk/rustanddust/game/states/StateSelect.java3
7 files changed, 137 insertions, 69 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Map.java b/core/src/ch/asynk/rustanddust/game/Map.java
index def903f..7cf52e9 100644
--- a/core/src/ch/asynk/rustanddust/game/Map.java
+++ b/core/src/ch/asynk/rustanddust/game/Map.java
@@ -40,13 +40,13 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public final HexSet possibleMoves;
public final PathBuilder pathBuilder;
- public final UnitList moveableUnits;
- public final UnitList possibleTargets;
- public final UnitList engagementAssists;
- public final UnitList activatedUnits;
- public final UnitList breakUnits;
- public final ObjectiveSet objectives;
+ protected final UnitList moveableUnits;
+ protected final UnitList targetUnits;
+ protected final UnitList assistUnits;
+ protected final UnitList breakthroughUnits;
+ protected final UnitList activatedUnits;
+ public final ObjectiveSet objectives;
public final Meteorology meteorology;
private final DestroyAnimation destroy;
@@ -86,12 +86,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
possibleMoves = new HexSet(this, 40);
pathBuilder = new PathBuilder(this, 10, 20, 5, 10);
- moveableUnits = new UnitList(6);
- possibleTargets = new UnitList(10);
- engagementAssists = new UnitList(6);
+ moveableUnits = new UnitList(6);
+ targetUnits = new UnitList(10);
+ assistUnits = new UnitList(6);
+ breakthroughUnits = new UnitList(4);
activatedUnits = new UnitList(7);
- breakUnits = new UnitList(4);
objectives = new ObjectiveSet(this, 4);
@@ -117,12 +117,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public void clearAll()
{
possibleMoves.clear();
- possibleTargets.clear();
pathBuilder.clear();
moveableUnits.clear();
- engagementAssists.clear();
+ targetUnits.clear();
+ assistUnits.clear();
+ breakthroughUnits.clear();
activatedUnits.clear();
- breakUnits.clear();
}
public Hex getHexAt(float x, float y)
@@ -164,11 +164,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public int collectPossibleMoves(Unit unit)
{
- if (!unit.canMove()) {
- possibleMoves.clear();
- return 0;
- }
- return collectPossibleMoves(unit, possibleMoves.asTiles());
+ if (unit.canMove())
+ return collectPossibleMoves(unit, possibleMoves.asTiles());
+
+ possibleMoves.clear();
+ return 0;
}
public int togglePathBuilderHex(Hex hex)
@@ -178,12 +178,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public int collectPossibleTargets(Unit unit, UnitList foes)
{
- if (!unit.canEngage()) {
- possibleTargets.clear();
- return 0;
- }
- // return collectPossibleTargets(unit, possibleTargets);
- return collectPossibleTargets(unit, foes.asPawns(), possibleTargets.asPawns());
+ if (unit.canEngage())
+ return collectPossibleTargets(unit, foes.asPawns(), targetUnits.asPawns());
+
+ targetUnits.clear();
+ return 0;
}
public int collectMoveableUnits(Unit unit)
@@ -200,7 +199,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public int collectAttackAssists(Unit unit, Unit target, UnitList units)
{
- int s = collectAttackAssists(unit, target, units.asPawns(), engagementAssists.asPawns());
+ int s = collectAttackAssists(unit, target, units.asPawns(), assistUnits.asPawns());
activatedUnits.add(unit);
return s;
}
@@ -223,11 +222,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
public void collectAndShowMovesAndAssits(Unit unit)
{
hidePossibleMoves();
- hideMoveableUnits();
+ unitsHide(UnitType.MOVEABLE);
collectPossibleMoves(unit);
collectMoveableUnits(unit);
showPossibleMoves();
- showMoveableUnits();
+ unitsShow(UnitType.MOVEABLE);
activatedUnits.clear();
}
@@ -547,7 +546,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
private int doEngagement(Engagement e)
{
- breakUnits.clear();
+ breakthroughUnits.clear();
activatedUnits.clear();
activatedUnits.add(e.attacker);
@@ -557,7 +556,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
for (Unit u : activatedUnits) {
u.engage();
if (u.canBreak())
- breakUnits.add(u);
+ breakthroughUnits.add(u);
}
if (e.success) {
@@ -585,22 +584,85 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
enableOverlayOn(hex, Hex.MOVE, enable);
}
- private void showUnitsOverlay(UnitList units, int overlay, boolean on)
+ public enum UnitType
+ {
+ MOVEABLE,
+ TARGETS,
+ ASSISTS,
+ BREAK_THROUGH,
+ ACTIVATED
+ };
+
+ public void unitsClear(UnitType unitType)
+ {
+ getUnitList(unitType).clear();
+ }
+
+ public int unitsSize(UnitType unitType)
+ {
+ return getUnitList(unitType).size();
+ }
+
+ public Unit unitsGet(UnitType unitType, int i)
+ {
+ return getUnitList(unitType).get(i);
+ }
+
+ public boolean unitsContains(UnitType unitType, Unit unit)
+ {
+ return getUnitList(unitType).contains(unit);
+ }
+
+ private UnitList getUnitList(UnitType unitType)
+ {
+ UnitList ul = null;
+ switch(unitType) {
+ case MOVEABLE:
+ ul = moveableUnits;
+ break;
+ case TARGETS:
+ ul = targetUnits;
+ break;
+ case ASSISTS:
+ ul = assistUnits;
+ break;
+ case BREAK_THROUGH:
+ ul = breakthroughUnits;
+ break;
+ case ACTIVATED:
+ ul = activatedUnits;
+ break;
+ }
+ return ul;
+ }
+
+ public void unitsShow(UnitType unitType) { unitsShow(unitType, true); }
+ public void unitsHide(UnitType unitType) { unitsShow(unitType, false); }
+ private void unitsShow(UnitType unitType, boolean show)
+ {
+ switch(unitType) {
+ case MOVEABLE:
+ unitsShowOverlay(moveableUnits, Unit.MOVE, show);
+ break;
+ case TARGETS:
+ unitsShowOverlay(targetUnits, Unit.TARGET, show);
+ break;
+ case ASSISTS:
+ unitsShowOverlay(assistUnits, Unit.MAY_FIRE, show);
+ if (!show)
+ unitsShowOverlay(assistUnits, Unit.FIRE, show);
+ break;
+ case BREAK_THROUGH:
+ unitsShowOverlay(breakthroughUnits, Unit.MOVE, show);
+ break;
+ }
+ }
+ private void unitsShowOverlay(UnitList units, int overlay, boolean on)
{
for (Unit unit : units)
unit.enableOverlay(overlay, on);
}
- public void showMoveableUnits() { showUnitsOverlay(moveableUnits, Unit.MOVE, true); }
- public void hideMoveableUnits() { showUnitsOverlay(moveableUnits, Unit.MOVE, false); }
- public void showPossibleTargets() { showUnitsOverlay(possibleTargets, Unit.TARGET, true); }
- public void hidePossibleTargets() { showUnitsOverlay(possibleTargets, Unit.TARGET, false); }
- public void showAttackAssists() { showUnitsOverlay(engagementAssists, Unit.MAY_FIRE, true); }
- public void hideAttackAssists() { showUnitsOverlay(engagementAssists, Unit.FIRE, false);
- showUnitsOverlay(engagementAssists, Unit.MAY_FIRE, false); }
- public void showBreakUnits() { showUnitsOverlay(breakUnits, Unit.MOVE, true); }
- public void hideBreakUnits() { showUnitsOverlay(breakUnits, Unit.MOVE, false); }
-
public void showPossibleMoves() { possibleMoves.enable(Hex.AREA, true); }
public void hidePossibleMoves() { possibleMoves.enable(Hex.AREA, false); }
public void showPathBuilder() { pathBuilder.enable(Hex.AREA, true); }
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);