From 08e78adfb9f93e8833d46cf037da2e9d7723d288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 14 Oct 2014 11:20:25 +0200 Subject: Board: buildAttack(...) -> buildAttackAssists(...), clean up code --- core/src/ch/asynk/tankontank/engine/Board.java | 16 ++++++++-------- core/src/ch/asynk/tankontank/game/Map.java | 4 ++-- 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 units, ArrayList assists) + protected int buildAttackAssists(Pawn pawn, Pawn target, GridPoint2 coords, Iterator units, ArrayList 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 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 units) + public int buildAttackAssists(Pawn pawn, Pawn target, GridPoint2 hex, Iterator 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)); -- cgit v1.1-2-g2b99