Rivers at the bottom edge of maps are considered by tiles for river-adjacency

This commit is contained in:
Yair Morgenstern 2023-08-10 10:45:41 +03:00
parent 0fbe5a18b8
commit 95b8fab950
2 changed files with 7 additions and 1 deletions

View File

@ -63,6 +63,8 @@ class UnitMovement(val unit: MapUnit) {
// when entering territory of a city state
val areConnectedByRoad = from.hasConnection(civInfo) && to.hasConnection(civInfo)
// You might think "wait doesn't isAdjacentToRiver() call isConnectedByRiver() anyway, why have those checks?"
// The answer is that the isAdjacentToRiver values are CACHED per tile, but the isConnectedByRiver are not - this is an efficiency optimization
val areConnectedByRiver =
from.isAdjacentToRiver() && to.isAdjacentToRiver() && from.isConnectedByRiver(to)

View File

@ -673,7 +673,11 @@ open class Tile : IsPartOfGameInfoSerialization {
}
@delegate:Transient
private val isAdjacentToRiverLazy by lazy { neighbors.any { isConnectedByRiver(it) } }
private val isAdjacentToRiverLazy by lazy {
// These are so if you add a river at the bottom of the map (no neighboring tile to be connected to)
// that tile is still considered adjacent to river
hasBottomLeftRiver || hasBottomRiver || hasBottomRightRiver
|| neighbors.any { isConnectedByRiver(it) } }
fun isAdjacentToRiver() = isAdjacentToRiverLazy
/**