diff options
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 18 |
2 files changed, 14 insertions, 8 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 42fae2e..7083f4a 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -262,9 +262,7 @@ public abstract class Board implements Disposable protected int collectPossibleTargets(Pawn pawn, PawnCollection targets) { - Tile from = pawn.getTile(); - List<SearchBoard.Node> nodes = searchBoard.possibleTargetsFrom(pawn, from.getCol(), from.getRow()); - return targets.fromNodes(nodes); + return searchBoard.possibleTargetsFrom(pawn, targets); } protected int collectPossibleTargets(Pawn pawn, Iterator<Pawn> units, PawnCollection targets) diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index e32f586..44769df 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.ArrayDeque; +import java.util.Iterator; public class SearchBoard { @@ -299,10 +300,10 @@ public class SearchBoard a[5] = null; } - public List<Node> possibleTargetsFrom(Pawn pawn, int col, int row) + public int possibleTargetsFrom(Pawn pawn, Board.PawnCollection targets) { - searchCount += 1; targets.clear(); + searchCount += 1; Node adjacents[] = new Node[6]; @@ -315,7 +316,7 @@ public class SearchBoard from.remaining = range; if (range <= 0) - return targets; + return targets.size(); queue.add(from); @@ -345,13 +346,20 @@ public class SearchBoard dst.remaining = rangeLeft; queue.add(dst); Tile t = getTile(dst); - if (t.hasTargetsFor(pawn) && hasClearLineOfSight(from, dst, angle)) targets.add(dst); + if (hasClearLineOfSight(from, dst, angle)) { + Iterator<Pawn> it = t.iterator(); + while (it.hasNext()) { + Pawn target = it.next(); + if (pawn.canAttack(target)) + targets.add(target); + } + } } } } } - return targets; + return targets.size(); } public boolean collectAttack(Pawn pawn, boolean clearVisibility, Pawn target, int col0, int row0, int col1, int row1) |