From a5cef081cee24e162d18d48ff798612f4dafbbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 11 May 2016 14:46:11 +0200 Subject: Unit: add IterableSet that keeps ref to the instances --- core/src/ch/asynk/rustanddust/game/Unit.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/ch/asynk/rustanddust/game/Unit.java b/core/src/ch/asynk/rustanddust/game/Unit.java index 38b1d7e..43125a2 100644 --- a/core/src/ch/asynk/rustanddust/game/Unit.java +++ b/core/src/ch/asynk/rustanddust/game/Unit.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import ch.asynk.rustanddust.engine.Pawn; import ch.asynk.rustanddust.engine.Tile; import ch.asynk.rustanddust.engine.HeadedPawn; +import ch.asynk.rustanddust.engine.util.Collection; +import ch.asynk.rustanddust.engine.util.IterableSet; import ch.asynk.rustanddust.game.Hex.Terrain; import ch.asynk.rustanddust.RustAndDust; @@ -25,6 +27,17 @@ public class Unit extends HeadedPawn public static boolean blockId = false; public static int unitId = 1; + private static Collection units = new IterableSet(20); + + public static void clear() { units.clear(); } + public static Unit findById(int id) + { + for (Unit u : units) { + if (u.id() == id) + return u; + } + return null; + } public enum UnitType implements Pawn.PawnType { @@ -81,6 +94,7 @@ public class Unit extends HeadedPawn } this.entryZone = null; this.exitZone = null; + units.add(this); } private void commonSetup() -- cgit v1.1-2-g2b99