From f6829e0cf640248ec0de8c47f5224d7580da9bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 29 Oct 2015 17:40:30 +0100 Subject: SearchBoard: fix possibleTargetsFrom() --- .../ch/asynk/rustanddust/engine/SearchBoard.java | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index 6a1e6bb..9d251ac 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -286,40 +286,34 @@ public class SearchBoard queue.add(from); - boolean first = true; while (queue.size() != 0) { Node src = queue.remove(); if (src.remaining <= 0) continue; - if (!first && (((range - src.remaining) % 2) == 0)) + if (((range - src.remaining) % 2) == 1) adjacentTargets(src, extendedAngle, adjacents); else adjacentTargets(src, angle, adjacents); - first = false; int rangeLeft = src.remaining - 1; for(int i = 0; i < 6; i++) { Node dst = adjacents[i]; - if (dst != null) { - if (dst.search == searchCount) { - if ((rangeLeft > dst.remaining)) - dst.remaining = rangeLeft; - } else { - dst.search = searchCount; - dst.remaining = rangeLeft; - queue.add(dst); - Tile t = getTile(dst); - if (hasClearLineOfSight(from, dst, angle)) { - Iterator it = t.iterator(); - while (it.hasNext()) { - Pawn target = it.next(); - if (shooter.canEngage(target)) - targets.add(target); - } - } + if ((dst == null) || (dst.search == searchCount)) + continue; + + dst.search = searchCount; + dst.remaining = rangeLeft; + queue.add(dst); + Tile t = getTile(dst); + if (!t.isEmpty() && hasClearLineOfSight(from, dst, angle)) { + Iterator it = t.iterator(); + while (it.hasNext()) { + Pawn target = it.next(); + if (shooter.canEngage(target)) + targets.add(target); } } } -- cgit v1.1-2-g2b99