New line-of-sight rules, with new "Blocks line-of-sight from tiles at same elevation" unique!

This commit is contained in:
Yair Morgenstern 2021-05-11 00:29:37 +03:00
parent 1f50f3e97e
commit 61c8ab3a8f
2 changed files with 21 additions and 15 deletions

View File

@ -100,7 +100,7 @@
"defenceBonus": 0.25, "defenceBonus": 0.25,
"occursOn": ["Tundra","Plains","Grassland","Hill"], "occursOn": ["Tundra","Plains","Grassland","Hill"],
"uniques": ["Provides a one-time Production bonus to the closest city when cut down", "Rough terrain", "uniques": ["Provides a one-time Production bonus to the closest city when cut down", "Rough terrain",
"Has an elevation of [1] for visibility calculations"] "Blocks line-of-sight from tiles at same elevation"]
}, },
{ {
"name": "Jungle", "name": "Jungle",
@ -111,7 +111,7 @@
"unbuildable": true, "unbuildable": true,
"defenceBonus": 0.25, "defenceBonus": 0.25,
"occursOn": ["Plains","Grassland"], "occursOn": ["Plains","Grassland"],
"uniques": ["Rough terrain", "Has an elevation of [1] for visibility calculations"] "uniques": ["Rough terrain", "Blocks line-of-sight from tiles at same elevation"]
}, },
{ {
"name": "Marsh", "name": "Marsh",

View File

@ -226,32 +226,38 @@ class TileMap {
// that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance // that is to say, the "viewableTiles.contains(it) check will return false for neighbors from the same distance
val tilesToAddInDistanceI = ArrayList<TileInfo>() val tilesToAddInDistanceI = ArrayList<TileInfo>()
for (tile in getTilesAtDistance(position, i)) { // for each tile in that layer, for (cTile in getTilesAtDistance(position, i)) { // for each tile in that layer,
val targetTileHeight = tile.getHeight() val cTileHeight = cTile.getHeight()
/* /*
Okay so, if we're looking at a tile from a to c with b in the middle, Okay so, if we're looking at a tile from a to c with b in the middle,
we have several scenarios: we have several scenarios:
1. a>b - - I can see everything, b does not hide c 1. a>b - - I can see everything, b does not hide c
2. a==b 2. a==b
2.1 a==b==0, all flat ground, no hiding 2.1 c>b - c is tall enough I can see it over b!
2.2 a>0, b>=c - b hides c from view (say I am in a forest/jungle and b is a forest/jungle, or hill) 2.2 b blocks view from same-elevation tiles - hides c
2.3 a>0, c>b - c is tall enough I can see it over b! 2.3 none of the above - I can see c
3. a<b 3. a<b
3.1 b>=c - b hides c 3.1 b>=c - b hides c
3.2 b<c - c is tall enough I can see it over b! 3.2 b<c - c is tall enough I can see it over b!
This can all be summed up as "I can see c if a>b || c>b || b==0 " This can all be summed up as "I can see c if a>b || c>b || (a==b && b !blocks same-elevation view)"
*/ */
val containsViewableNeighborThatCanSeeOver = tile.neighbors.any { val containsViewableNeighborThatCanSeeOver = cTile.neighbors.any {
val neighborHeight = it.getHeight() bNeighbor: TileInfo ->
viewableTiles.contains(it) && ( val bNeighborHeight = bNeighbor.getHeight()
currentTileHeight > neighborHeight // a>b if(cTile.resource=="Marble"
|| targetTileHeight > neighborHeight // c>b && bNeighbor.terrainFeatures.contains("Forest")
|| neighborHeight == 0) // b==0 )
println()
viewableTiles.contains(bNeighbor) && (
currentTileHeight > bNeighborHeight // a>b
|| cTileHeight > bNeighborHeight // c>b
|| currentTileHeight == bNeighborHeight // a==b
&& !bNeighbor.hasUnique("Blocks line-of-sight from tiles at same elevation"))
} }
if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(tile) if (containsViewableNeighborThatCanSeeOver) tilesToAddInDistanceI.add(cTile)
} }
viewableTiles.addAll(tilesToAddInDistanceI) viewableTiles.addAll(tilesToAddInDistanceI)
} }