summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java16
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java4
2 files changed, 10 insertions, 10 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 91a88f5..94e55ed 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -367,28 +367,28 @@ public abstract class Board implements Disposable
return assists.size();
}
- protected int buildAttack(Pawn pawn, Pawn target, GridPoint2 hex, Iterator<Pawn> units, ArrayList<GridPoint2> assists)
+ protected int buildAttackAssists(Pawn pawn, Pawn target, GridPoint2 coords, Iterator<Pawn> units, ArrayList<GridPoint2> assists)
{
clearPointVector(assists);
- GridPoint2 from = null;
+ GridPoint2 from = gridPoint2Pool.obtain();
while (units.hasNext()) {
Pawn p = units.next();
if (!p.canAttack()) continue;
- if (from == null)
- from = gridPoint2Pool.obtain();
getHexUnder(p, from);
- if (searchBoard.buildAttack(p, target, from.x, from.y, hex.x, hex.y)) {
+ if (searchBoard.buildAttack(p, target, from.x, from.y, coords.x, coords.y)) {
if (p != pawn) {
assists.add(from);
- from = null;
+ from = gridPoint2Pool.obtain();
}
}
}
- if (from != null) gridPoint2Pool.free(from);
+ int s = assists.size();
+ if ((s > 0) && (from != assists.get(s- 1)))
+ gridPoint2Pool.free(from);
- return assists.size();
+ return s;
}
protected void clearPointSet(Set<GridPoint2> points)
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index fdf7e8b..352d73d 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -223,9 +223,9 @@ public abstract class Map extends Board
return buildMoveAssists(pawn, hex, moveAssists);
}
- public int buildAttack(Pawn pawn, Pawn target, GridPoint2 hex, Iterator<Pawn> units)
+ public int buildAttackAssists(Pawn pawn, Pawn target, GridPoint2 hex, Iterator<Pawn> units)
{
- int s = buildAttack(pawn, target, hex, units, attackAssists);
+ int s = buildAttackAssists(pawn, target, hex, units, attackAssists);
activatedPawns.add(pawn);
for (GridPoint2 p : attackAssists)
activablePawns.add(getTopPawnAt(p));