From e60457b93f04a68d041898676966612861ac41a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 18 Feb 2015 11:17:01 +0100 Subject: SearchBoard: canAttack(...) set Pawn.attack --- core/src/ch/asynk/tankontank/engine/Pawn.java | 7 +++++++ core/src/ch/asynk/tankontank/engine/SearchBoard.java | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 716b66b..2986002 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -143,6 +143,13 @@ public abstract class Pawn implements Moveable, Disposable move(); } + public void setAttack(Pawn target, int distance) + { + attack.reset(); + attack.target = target; + attack.distance = distance; + } + public boolean justEntered() { return ((move != null) && move.isEntry()); diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 41516ae..199a7a7 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -326,9 +326,9 @@ public class SearchBoard Node from = getNode(pawn.getTile()); Node to = getNode(target.getTile()); - int distance = distance(from, to); + pawn.setAttack(target, distance(from, to)); - if (distance > pawn.getEngagementRangeFrom(pawn.getTile())) + if (pawn.attack.distance > pawn.getEngagementRangeFrom(pawn.getTile())) return false; List los = lineOfSight(from.col, from.row, to.col, to.row, clearVisibility); @@ -339,6 +339,9 @@ public class SearchBoard if (!validatePathAngle(pawn.getAngleOfAttack(), los)) return false; + pawn.attack.isClear = isClearAttack(getTile(from), los); + pawn.attack.isFlank = isFlankAttack(target.getFlankSides(), los); + return true; } -- cgit v1.1-2-g2b99