River adjacency and 'is land unit' saved in lazies for another pathfinding performance boost

This commit is contained in:
Yair Morgenstern 2022-02-10 14:57:34 +02:00
parent 8ee2a34a4d
commit 505a78182c
3 changed files with 5 additions and 3 deletions

View File

@ -663,7 +663,8 @@ open class TileInfo {
}
}
fun isAdjacentToRiver() = neighbors.any { isConnectedByRiver(it) }
private val isAdjacentToRiverLazy by lazy { neighbors.any { isConnectedByRiver(it) } }
fun isAdjacentToRiver() = isAdjacentToRiverLazy
/**
* @returns whether units of [civInfo] can pass through this tile, considering only civ-wide filters.

View File

@ -40,7 +40,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
return RoadStatus.Railroad.movement + extraCost
val areConnectedByRoad = from.hasConnection(civInfo) && to.hasConnection(civInfo)
val areConnectedByRiver = from.isConnectedByRiver(to)
val areConnectedByRiver = from.isAdjacentToRiver() && to.isAdjacentToRiver() && from.isConnectedByRiver(to)
if (areConnectedByRoad && (!areConnectedByRiver || civInfo.tech.roadsConnectAcrossRivers))
return unit.civInfo.tech.movementSpeedOnRoads + extraCost

View File

@ -577,7 +577,8 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
fun isMilitary() = isRanged() || isMelee()
fun isCivilian() = !isMilitary()
fun isLandUnit() = getType().isLandUnit()
val isLandUnitInternal by lazy { getType().isLandUnit() }
fun isLandUnit() = isLandUnitInternal
fun isWaterUnit() = getType().isWaterUnit()
fun isAirUnit() = getType().isAirUnit()