diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Move.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Path.java | 33 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Engagement.java | 99 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hud.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 45 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/EngagementPanel.java | 10 |
7 files changed, 137 insertions, 62 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index a097454..764fccd 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -131,6 +131,8 @@ public abstract class Board implements Disposable, Animation animations.clear(); if (selectedTile != null) selectedTile.dispose(); + Move.clearPool(); + Path.clearPool(); } public float getWidth() diff --git a/core/src/ch/asynk/tankontank/engine/Move.java b/core/src/ch/asynk/tankontank/engine/Move.java index 16a0860..2f0c138 100644 --- a/core/src/ch/asynk/tankontank/engine/Move.java +++ b/core/src/ch/asynk/tankontank/engine/Move.java @@ -15,7 +15,8 @@ public class Move extends Path implements Iterable<Vector3> EXIT; } - private static final Pool<Move> movePool = new Pool<Move>() { + private static final Pool<Move> movePool = new Pool<Move>() + { @Override protected Move newObject() { return new Move(); @@ -42,6 +43,11 @@ public class Move extends Path implements Iterable<Vector3> return m; } + public static void clearPool() + { + movePool.clear(); + } + public static Move getEnter(Pawn pawn, Tile to, Orientation orientation) { Move m = get(pawn, null, to, orientation, null); diff --git a/core/src/ch/asynk/tankontank/engine/Path.java b/core/src/ch/asynk/tankontank/engine/Path.java index 393a0a5..8ed7f8d 100644 --- a/core/src/ch/asynk/tankontank/engine/Path.java +++ b/core/src/ch/asynk/tankontank/engine/Path.java @@ -7,6 +7,25 @@ import com.badlogic.gdx.utils.Disposable; public class Path implements Disposable, Pool.Poolable { + private static final Pool<Path> pathPool = new Pool<Path>() { + @Override + protected Path newObject() { + return new Path(); + } + }; + + public static Path get(int size) + { + Path p = pathPool.obtain(); + p.init(size); + return p; + } + + public static void clearPool() + { + pathPool.clear(); + } + public int cost; public boolean roadMarch; public ArrayList<Tile> tiles; @@ -40,18 +59,4 @@ public class Path implements Disposable, Pool.Poolable tiles.clear(); pathPool.free(this); } - - private static final Pool<Path> pathPool = new Pool<Path>() { - @Override - protected Path newObject() { - return new Path(); - } - }; - - public static Path get(int size) - { - Path p = pathPool.obtain(); - p.init(size); - return p; - } } diff --git a/core/src/ch/asynk/tankontank/game/Engagement.java b/core/src/ch/asynk/tankontank/game/Engagement.java new file mode 100644 index 0000000..4b2edcd --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/Engagement.java @@ -0,0 +1,99 @@ +package ch.asynk.tankontank.game; + +import java.util.List; +import java.util.LinkedList; + +import com.badlogic.gdx.utils.Pool; +import com.badlogic.gdx.utils.Disposable; + +public class Engagement implements Disposable, Pool.Poolable +{ + private static final Pool<Engagement> engagementPool = new Pool<Engagement>() { + @Override + protected Engagement newObject() { + return new Engagement(); + } + }; + + public static Engagement get(Unit attacker, Unit defender) + { + Engagement e = engagementPool.obtain(); + e.attacker = attacker; + e.defender = defender; + + return e; + } + + + public Unit attacker; + public Unit defender; + public List<Unit> assists; + public Army attackerArmy; + public Army defenderArmy; + public boolean success; + public int d1; + public int d2; + public int d3; + public int d4; + public int unitCount; + public int flankBonus; + public int unitDefense; + public int terrainDefense; + public int weatherDefense; + public int attackSum; + public int defenseSum; + + public Engagement() + { + assists = new LinkedList<Unit>(); + reset(); + } + + @Override + public void reset() + { + attacker = null; + defender = null; + assists.clear(); + } + + @Override + public void dispose() + { + assists.clear(); + engagementPool.free(this); + } + + public void set(int d1, int d2, int d3, int d4, int cnt, int flk, int def, int tdf, int wdf) + { + this.d1 = d1; + this.d2 = d2; + this.d3 = d3; + this.d4 = d4; + this.unitCount = cnt; + this.flankBonus = flk; + this.unitDefense = def; + this.terrainDefense = tdf; + this.weatherDefense = wdf; + if (d3 == 0) + this.attackSum = (d1 + d2 + unitCount + flankBonus); + else + this.attackSum = (d3 + d4 + unitCount + flankBonus); + this.defenseSum = (unitDefense + terrainDefense + weatherDefense); + } + + + @Override + public String toString() + { + int a, b; + if (d3 == 0) { + a = d1; + b = d2; + } else { + a = d3; + b = d4; + } + return String.format("Engagement : (%d + %d + %d + %d) vs (%d + %d + %d) -> %b", a, b, unitCount, flankBonus, unitDefense, terrainDefense, weatherDefense, success); + } +} diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 02472df..63996fe 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -280,7 +280,7 @@ public class Hud implements Disposable, Animation pushDialog(okCancel); } - public void engagementSummary(Map.Engagement e, float volume) + public void engagementSummary(Engagement e, float volume) { engagement.show(e, Position.BOTTOM_CENTER, volume); pushDialog(engagement); diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index b3b1ed3..a78a4cf 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -61,43 +61,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS protected abstract void setup(); - public class Engagement - { - public Army attacker; - public Army defender; - public boolean success; - public int d1; - public int d2; - public int d3; - public int d4; - public int unitCount; - public int flankBonus; - public int unitDefense; - public int terrainDefense; - public int weatherDefense; - public int attack; - public int defense; - - public void set(int d1, int d2, int d3, int d4, int cnt, int flk, int def, int tdf, int wdf) - { - this.d1 = d1; - this.d2 = d2; - this.d3 = d3; - this.d4 = d4; - this.unitCount = cnt; - this.flankBonus = flk; - this.unitDefense = def; - this.terrainDefense = tdf; - this.weatherDefense = wdf; - if (d3 == 0) - this.attack = (d1 + d2 + unitCount + flankBonus); - else - this.attack = (d3 + d4 + unitCount + flankBonus); - this.defense = (unitDefense + terrainDefense + weatherDefense); - } - } - private Engagement engagement; - public int d6() { return rand.nextInt(6) + 1; @@ -140,7 +103,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS objectives = new ObjectiveSet(this, 4); meteorology = new Meteorology(); - engagement = new Engagement(); } @Override @@ -535,8 +497,8 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS e.set(d1, d2, d3, d4, cnt, flk, def, tdf, wdf); e.success = success; - e.attacker = ctrl.player.army; - e.defender = ctrl.opponent.army; + e.attackerArmy = ctrl.player.army; + e.defenderArmy = ctrl.opponent.army; ctrl.hud.engagementSummary(e, ctrl.cfg.fxVolume); return success; @@ -545,8 +507,9 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS public boolean engageUnit(Unit unit, final Unit target) { attack(unit, target, true); + Engagement e = Engagement.get(unit, target); - boolean success = resolveFight(unit, target, engagement); + boolean success = resolveFight(unit, target, e); breakUnits.clear(); for (Unit u : activatedUnits) { diff --git a/core/src/ch/asynk/tankontank/game/hud/EngagementPanel.java b/core/src/ch/asynk/tankontank/game/hud/EngagementPanel.java index 6da7406..e524bf7 100644 --- a/core/src/ch/asynk/tankontank/game/hud/EngagementPanel.java +++ b/core/src/ch/asynk/tankontank/game/hud/EngagementPanel.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.tankontank.game.Map.Engagement; +import ch.asynk.tankontank.game.Engagement; import ch.asynk.tankontank.game.Army; import ch.asynk.tankontank.engine.gfx.Animation; import ch.asynk.tankontank.engine.gfx.animations.DiceAnimation; @@ -91,12 +91,12 @@ public class EngagementPanel extends Patch implements Animation defense.write(String.format("%d + %d =", e.unitDefense, e.terrainDefense)); else defense.write(String.format("%d + %d + %d =", e.unitDefense, e.terrainDefense, e.weatherDefense)); - attackR.write(String.format(" %2d", e.attack)); - defenseR.write(String.format(" %2d", e.defense)); + attackR.write(String.format(" %2d", e.attackSum)); + defenseR.write(String.format(" %2d", e.defenseSum)); if (e.success) - winner = ((e.attacker == Army.US) ? usFlag : geFlag); + winner = ((e.attackerArmy == Army.US) ? usFlag : geFlag); else - winner = ((e.attacker == Army.US) ? geFlag : usFlag); + winner = ((e.attackerArmy == Army.US) ? geFlag : usFlag); this.position = position; placeElements(); |