summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-12-24 20:02:21 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-12-24 20:02:21 +0100
commit4fdf26458bc803ec6f818ee4e96356b565ff25b1 (patch)
tree530993a6581133bf299e27b4aaba6704b12d80d5
parentcf17d0465c15cf5770138f79176f3892df50104d (diff)
downloadRustAndDust-4fdf26458bc803ec6f818ee4e96356b565ff25b1.zip
RustAndDust-4fdf26458bc803ec6f818ee4e96356b565ff25b1.tar.gz
Hex: blockLineOfSightFrom(Tile) -> blockLineOfSight(Tile, Tile)
-rw-r--r--core/src/ch/asynk/rustanddust/engine/SearchBoard.java13
-rw-r--r--core/src/ch/asynk/rustanddust/engine/Tile.java2
-rw-r--r--core/src/ch/asynk/rustanddust/game/Hex.java4
-rw-r--r--core/test/ch/asynk/rustanddust/Helpers.java2
4 files changed, 12 insertions, 9 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java
index e8c07f9..f4bfd4c 100644
--- a/core/src/ch/asynk/rustanddust/engine/SearchBoard.java
+++ b/core/src/ch/asynk/rustanddust/engine/SearchBoard.java
@@ -401,6 +401,7 @@ public class SearchBoard
los.clear();
losBlocked = false;
Tile from = board.getTile(x0, y0);
+ Tile to = board.getTile(x1, y1);
// orthogonal axis
int ox0 = x0 - ((y0 +1) / 2);
@@ -465,7 +466,7 @@ public class SearchBoard
}
}
los.add(getNode(x, y));
- if (!losBlocked) losBlocked = board.getTile(x, y).blockLineOfSightFrom(from);
+ if (!losBlocked) losBlocked = board.getTile(x, y).blockLineOfSight(from, to);
if(losBlocked && clearVisibility) return fixLineOfSight(false, x1, y1);
}
@@ -475,6 +476,7 @@ public class SearchBoard
private boolean verticalLineOfSight(int x0, int y0, int x1, int y1, boolean clearVisibility)
{
Tile from = board.getTile(x0, y0);
+ Tile to = board.getTile(x1, y1);
int d = ( (y1 > y0) ? 1 : -1);
int x = x0;
@@ -488,12 +490,12 @@ public class SearchBoard
y += d;
t = board.getTile(x, y);
if (!t.isOffMap()) los.add(getNode(x, y));
- if (!losBlocked) blocked = t.blockLineOfSightFrom(from);
+ if (!losBlocked) blocked = t.blockLineOfSight(from, to);
x += d;
t = board.getTile(x, y);
if (!t.isOffMap()) los.add(getNode(x, y));
- if (blocked && !t.blockLineOfSightFrom(from))
+ if (blocked && !t.blockLineOfSight(from, to))
blocked = false;
if (blocked) losBlocked = true;
@@ -510,6 +512,7 @@ public class SearchBoard
private boolean diagonalLineOfSight(int x0, int y0, int x1, int y1, boolean clearVisibility)
{
Tile from = board.getTile(x0, y0);
+ Tile to = board.getTile(x1, y1);
int dy = ( (y1 > y0) ? 1 : -1);
int dx = ( (x1 > x0) ? 1 : -1);
@@ -526,14 +529,14 @@ public class SearchBoard
x += dx;
t = board.getTile(x, y);
if (!t.isOffMap()) los.add(getNode(x, y));
- if (!losBlocked) blocked = t.blockLineOfSightFrom(from);
+ if (!losBlocked) blocked = t.blockLineOfSight(from, to);
y += dy;
if (!sig)
x -= dx;
t = board.getTile(x, y);
if (!t.isOffMap()) los.add(getNode(x, y));
- if (blocked && !t.blockLineOfSightFrom(from))
+ if (blocked && !t.blockLineOfSight(from, to))
blocked = false;
if (blocked) losBlocked = true;
diff --git a/core/src/ch/asynk/rustanddust/engine/Tile.java b/core/src/ch/asynk/rustanddust/engine/Tile.java
index c3ccf37..63ff193 100644
--- a/core/src/ch/asynk/rustanddust/engine/Tile.java
+++ b/core/src/ch/asynk/rustanddust/engine/Tile.java
@@ -33,7 +33,7 @@ public abstract class Tile implements Drawable, Disposable, Iterable<Pawn>
public abstract boolean isA(TileTerrain terrain);
public abstract boolean road(Orientation side);
public abstract boolean atLeastOneMove(Pawn pawn);
- public abstract boolean blockLineOfSightFrom(Tile tile);
+ public abstract boolean blockLineOfSight(Tile from, Tile to);
protected Tile(int col, int row)
{
diff --git a/core/src/ch/asynk/rustanddust/game/Hex.java b/core/src/ch/asynk/rustanddust/game/Hex.java
index d8800ec..5f970ba 100644
--- a/core/src/ch/asynk/rustanddust/game/Hex.java
+++ b/core/src/ch/asynk/rustanddust/game/Hex.java
@@ -68,12 +68,12 @@ public class Hex extends Tile
}
@Override
- public boolean blockLineOfSightFrom(Tile tile)
+ public boolean blockLineOfSight(Tile from, Tile to)
{
if (isA(Terrain.DEPRESSION))
return false;
- if (isA(Terrain.CLEAR) && (!hasUnits() || tile.isA(Terrain.HILLS)))
+ if (isA(Terrain.CLEAR) && (!hasUnits() || from.isA(Terrain.HILLS) || to.isA(Terrain.HILLS)))
return false;
return true;
diff --git a/core/test/ch/asynk/rustanddust/Helpers.java b/core/test/ch/asynk/rustanddust/Helpers.java
index 8dd04ff..3d5a671 100644
--- a/core/test/ch/asynk/rustanddust/Helpers.java
+++ b/core/test/ch/asynk/rustanddust/Helpers.java
@@ -78,7 +78,7 @@ public class Helpers
@Override public boolean isA(TileTerrain terrain) { return true; }
@Override public boolean road(Orientation side) { return false; }
@Override public boolean atLeastOneMove(Pawn pawn) { return true; }
- @Override public boolean blockLineOfSightFrom(Tile from) { return blockLineOfSight; }
+ @Override public boolean blockLineOfSight(Tile from, Tile to) { return blockLineOfSight; }
public void setBlockLineOfSight(boolean block) { blockLineOfSight = block; }
}