diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-10-30 14:02:44 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-10-30 14:02:44 +0100 |
commit | df7569c614fcea80e6a25dd0749a75d5ba00a68e (patch) | |
tree | c0b006f24ad13545f4b31560b9b8c669ab2b6547 /core | |
parent | 127d30bb790271c6bccd26f82dc91793891fa750 (diff) | |
download | RustAndDust-df7569c614fcea80e6a25dd0749a75d5ba00a68e.zip RustAndDust-df7569c614fcea80e6a25dd0749a75d5ba00a68e.tar.gz |
SearchBoard: add fixLineOfSight, unset losBlocked and return true if dst reached
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/rustanddust/engine/SearchBoard.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java index 9d251ac..59e3b2e 100644 --- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java +++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java @@ -388,6 +388,19 @@ public class SearchBoard return (o.isInSides(angle) || o2.isInSides(angle)); } + private boolean fixLineOfSight(boolean ret, int x1, int y1) + { + if (ret) return true; + if (!losBlocked) return false; + + Node last = los.get(los.size() - 1); + if ((last.col == x1) && (last.row == y1)) { + losBlocked = false; + return true; + } + return false; + } + private boolean lineOfSight(int x0, int y0, int x1, int y1, boolean clearVisibility) { los.clear(); @@ -418,9 +431,9 @@ public class SearchBoard } if (dx == 0) - return verticalLineOfSight(x0, y0, x1, y1, clearVisibility); + return fixLineOfSight(verticalLineOfSight(x0, y0, x1, y1, clearVisibility), x1, y1); if (dx == (3 * dy)) - return diagonalLineOfSight(x0, y0, x1, y1, clearVisibility); + return fixLineOfSight(diagonalLineOfSight(x0, y0, x1, y1, clearVisibility), x1, y1); int dx3 = 3 * dx; int dy3 = 3 * dy; @@ -458,7 +471,7 @@ public class SearchBoard } los.add(getNode(x, y)); if (!losBlocked) losBlocked = board.getTile(x, y).blockLineOfSightFrom(from); - if(losBlocked && clearVisibility) return false; + if(losBlocked && clearVisibility) return fixLineOfSight(false, x1, y1); } return true; |