diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-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)) |