summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-14 11:20:25 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-14 11:20:25 +0200
commit08e78adfb9f93e8833d46cf037da2e9d7723d288 (patch)
tree3987faa46695f3352a4850a26f36dce530f02673 /core/src/ch/asynk
parent03d764fc87370a7dc024b9065b019ed21107c95e (diff)
downloadRustAndDust-08e78adfb9f93e8833d46cf037da2e9d7723d288.zip
RustAndDust-08e78adfb9f93e8833d46cf037da2e9d7723d288.tar.gz
Board: buildAttack(...) -> buildAttackAssists(...), clean up code
Diffstat (limited to 'core/src/ch/asynk')
-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));