diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-30 14:18:54 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-30 14:18:54 +0100 |
commit | 26ef6e40f1121e3ecf1338a8d47c510048158c08 (patch) | |
tree | 4e54adbd332d8d03f63ad7dbdfc1e35e5eeefcc7 /core | |
parent | 94ddf0defaf09f89bcd2443b00683f2c9b0f7695 (diff) | |
download | RustAndDust-26ef6e40f1121e3ecf1338a8d47c510048158c08.zip RustAndDust-26ef6e40f1121e3ecf1338a8d47c510048158c08.tar.gz |
Board,SearchBoard: optimize collectPossibleTargets(Pawn, Iterator<Pawn>, PawnCollection)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 11 |
2 files changed, 8 insertions, 8 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 7083f4a..6d1a2ab 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -267,13 +267,10 @@ public abstract class Board implements Disposable protected int collectPossibleTargets(Pawn pawn, Iterator<Pawn> units, PawnCollection targets) { - Tile from = pawn.getTile(); targets.clear(); while (units.hasNext()) { Pawn target = units.next(); - if (!pawn.canAttack(target)) continue; - Tile to = target.getTile(); - if (searchBoard.collectAttack(pawn, true, target, from.getCol(), from.getRow(), to.getCol(), to.getRow())) + if (pawn.canAttack(target) && searchBoard.collectAttacks(pawn, target, true)) targets.add(target); } diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 44769df..5190829 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -362,18 +362,21 @@ public class SearchBoard return targets.size(); } - public boolean collectAttack(Pawn pawn, boolean clearVisibility, Pawn target, int col0, int row0, int col1, int row1) + public boolean collectAttacks(Pawn pawn, Pawn target, boolean clearVisibility) { + Node from = getNode(pawn.getTile()); + Node to = getNode(target.getTile()); + pawn.attack.isClear = false; pawn.attack.target = target; - pawn.attack.distance = distance(col0, row0, col1, row1); + pawn.attack.distance = distance(from.col, from.row, to.col, to.row); if (pawn.attack.distance > pawn.getAttackRangeFrom(pawn.getTile())) return false; - List<Node> los = lineOfSight(col0, row0, col1, row1, clearVisibility); + List<Node> los = lineOfSight(from.col, from.row, to.col, to.row, clearVisibility); Node last = los.get(los.size() -1); - if ((last.col != col1) || (last.row != row1)) + if (last != to) return false; if (!validatePathAngle(pawn.getAngleOfAttack(), los)) |