summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java50
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java17
-rw-r--r--core/src/ch/asynk/tankontank/game/UnitList.java20
-rw-r--r--core/src/ch/asynk/tankontank/game/UnitSet.java35
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/UnitDock.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateDeployment.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateMove.java2
7 files changed, 61 insertions, 72 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 09aa4fe..9cebed5 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -29,11 +29,11 @@ public abstract class Map extends Board
public final HexSet possibleMoves;
public final PossiblePaths possiblePaths;
- public final UnitSet moveableUnits;
- public final UnitSet possibleTargets;
- public final UnitSet engagementAssists;
- public final UnitSet activatedUnits;
- public final UnitSet breakUnits;
+ public final UnitList moveableUnits;
+ public final UnitList possibleTargets;
+ public final UnitList engagementAssists;
+ public final UnitList activatedUnits;
+ public final UnitList breakUnits;
public final Meteorology meteorology;
@@ -64,12 +64,12 @@ public abstract class Map extends Board
possibleMoves = new HexSet(this, 40);
possiblePaths = new PossiblePaths(this, 10, 20, 5, 10);
- moveableUnits = new UnitSet(this, 6);
+ moveableUnits = new UnitList(6);
- possibleTargets = new UnitSet(this, 10);
- engagementAssists = new UnitSet(this, 6);
- activatedUnits = new UnitSet(this, 7);
- breakUnits = new UnitSet(this, 4);
+ possibleTargets = new UnitList(10);
+ engagementAssists = new UnitList(6);
+ activatedUnits = new UnitList(7);
+ breakUnits = new UnitList(4);
meteorology = new Meteorology();
}
@@ -120,7 +120,7 @@ public abstract class Map extends Board
return possiblePaths.toggleCtrlTile(hex);
}
- public int collectPossibleTargets(Unit unit, UnitSet foes)
+ public int collectPossibleTargets(Unit unit, UnitList foes)
{
if (!unit.canEngage()) {
possibleTargets.clear();
@@ -142,7 +142,7 @@ public abstract class Map extends Board
return moveableUnits.size();
}
- public int collectAttackAssists(Unit unit, Unit target, UnitSet units)
+ public int collectAttackAssists(Unit unit, Unit target, UnitList units)
{
int s = collectAttackAssists(unit, target, units.asPawns(), engagementAssists.asPawns());
activatedUnits.add(unit);
@@ -353,6 +353,22 @@ public abstract class Map extends Board
enableOverlayOn(hex, Hex.MOVE, enable);
}
+ private void showUnitsOverlay(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 showPossiblePaths() { possiblePaths.enable(Hex.AREA, true); }
@@ -360,16 +376,6 @@ public abstract class Map extends Board
public void showPath(Hex dst) { possiblePaths.enable(Hex.MOVE, true); showMove(dst); }
public void hidePath(Hex dst) { possiblePaths.enable(Hex.MOVE, false); hideMove(dst); }
- public void showMoveableUnits() { moveableUnits.enable(Unit.MOVE, true); }
- public void hideMoveableUnits() { moveableUnits.enable(Unit.MOVE, false); }
- public void showPossibleTargets() { possibleTargets.enable(Unit.TARGET, true); }
- public void hidePossibleTargets() { possibleTargets.enable(Unit.TARGET, false); }
- public void showAttackAssists() { engagementAssists.enable(Unit.MAY_FIRE, true); }
- public void hideAttackAssists() { engagementAssists.enable(Unit.FIRE, false);
- engagementAssists.enable(Unit.MAY_FIRE, false); }
- public void showBreakUnits() { breakUnits.enable(Unit.MOVE, true); }
- public void hideBreakUnits() { breakUnits.enable(Unit.MOVE, false); }
-
public void showObjective(Hex hex) { enableOverlayOn(hex, Hex.OBJECTIVE, true); }
public void hideObjective(Hex hex) { enableOverlayOn(hex, Hex.OBJECTIVE, true); }
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
index f92e74c..e84761d 100644
--- a/core/src/ch/asynk/tankontank/game/Player.java
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -2,7 +2,6 @@ package ch.asynk.tankontank.game;
import java.util.Random;
import java.util.List;
-import java.util.ArrayList;
import ch.asynk.tankontank.TankOnTank;
@@ -18,10 +17,10 @@ public class Player
private boolean deploymentDone;
public Army army;
- public UnitSet units;
- public ArrayList<Unit> casualties;
- public ArrayList<Unit> reinforcement;
- public ArrayList<Unit> escaped;
+ public UnitList units;
+ public UnitList casualties;
+ public UnitList reinforcement;
+ public UnitList escaped;
public int actionCount;
public int lostEngagementCount;
@@ -30,10 +29,10 @@ public class Player
public Player(final TankOnTank game, Army army, int n)
{
this.army = army;
- this.units = new UnitSet(null, n); // FIXME ugly
- this.casualties = new ArrayList<Unit>(n);
- this.reinforcement = new ArrayList<Unit>(n);
- this.escaped = new ArrayList<Unit>(n);
+ this.units = new UnitList(n);
+ this.casualties = new UnitList(n);
+ this.reinforcement = new UnitList(n);
+ this.escaped = new UnitList(n);
this.turn = 0;
this.apSpent = 0;
this.actionPoints = 0;
diff --git a/core/src/ch/asynk/tankontank/game/UnitList.java b/core/src/ch/asynk/tankontank/game/UnitList.java
new file mode 100644
index 0000000..4019add
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/UnitList.java
@@ -0,0 +1,20 @@
+package ch.asynk.tankontank.game;
+
+import java.util.Collection;
+import java.util.ArrayList;
+
+import ch.asynk.tankontank.engine.Pawn;
+
+public class UnitList extends ArrayList<Unit>
+{
+ public UnitList(int n)
+ {
+ super(n);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<Pawn> asPawns()
+ {
+ return (Collection) this;
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/game/UnitSet.java b/core/src/ch/asynk/tankontank/game/UnitSet.java
deleted file mode 100644
index e4e63c0..0000000
--- a/core/src/ch/asynk/tankontank/game/UnitSet.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package ch.asynk.tankontank.game;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-
-import ch.asynk.tankontank.engine.Pawn;
-
-public class UnitSet extends LinkedHashSet<Unit>
-{
- private final Map map;
-
- public UnitSet(Map map, int n)
- {
- super(n);
- this.map = map;
- }
-
- @SuppressWarnings("unchecked")
- public Collection<Pawn> asPawns()
- {
- return (Collection) this;
- }
-
- public Unit first()
- {
- if (isEmpty()) return null;
- return iterator().next();
- }
-
- public void enable(int i, boolean enable)
- {
- for (Unit unit : this)
- unit.enableOverlay(i, enable);
- }
-}
diff --git a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
index 108b776..cd433e8 100644
--- a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
+++ b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
@@ -1,7 +1,5 @@
package ch.asynk.tankontank.game.hud;
-import java.util.List;
-
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.Sprite;
@@ -13,6 +11,7 @@ import com.badlogic.gdx.math.Rectangle;
import ch.asynk.tankontank.engine.Orientation;
import ch.asynk.tankontank.game.Ctrl;
import ch.asynk.tankontank.game.Unit;
+import ch.asynk.tankontank.game.UnitList;
public class UnitDock extends Bg
{
@@ -30,7 +29,7 @@ public class UnitDock extends Bg
private boolean done;
public Unit selectedUnit;
private Sprite selected;
- private List<Unit> units;
+ private UnitList units;
private Vector3 point;
private Matrix4 saved;
private Matrix4 transform;
diff --git a/core/src/ch/asynk/tankontank/game/states/StateDeployment.java b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java
index ace1265..3a6f2a5 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateDeployment.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java
@@ -4,7 +4,7 @@ import ch.asynk.tankontank.engine.Orientation;
import ch.asynk.tankontank.game.Hex;
import ch.asynk.tankontank.game.Zone;
import ch.asynk.tankontank.game.Unit;
-import ch.asynk.tankontank.game.UnitSet;
+import ch.asynk.tankontank.game.UnitList;
import ch.asynk.tankontank.game.hud.ActionButtons.Buttons;
import ch.asynk.tankontank.TankOnTank;
@@ -13,7 +13,7 @@ public class StateDeployment extends StateCommon
{
private boolean done;
private Zone entryZone;
- private UnitSet deployedUnits = new UnitSet(map, 10);
+ private UnitList deployedUnits = new UnitList(10);
@Override
public void enter(StateType prevState)
diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java
index 13280ce..caeebb2 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateMove.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java
@@ -38,7 +38,7 @@ public class StateMove extends StateCommon
if (selectedUnit.canMove()) {
changeUnit(selectedUnit);
} else {
- changeUnit((Unit) map.moveableUnits.first());
+ changeUnit((Unit) map.moveableUnits.get(0));
}
}
}