diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index e1dadab938..d610e83eaf 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -31,7 +31,7 @@ object UnitAutomation { unit.movement.getDistanceToTiles().keys.filter { isGoodTileToExplore(unit, it) } if (explorableTilesThisTurn.any()) { val bestTile = explorableTilesThisTurn - .sortedByDescending { it.getHeight() } // secondary sort is by 'how far can you see' + .sortedByDescending { it.height } // secondary sort is by 'how far can you see' .maxByOrNull { it.aerialDistanceTo(unit.currentTile) }!! // primary sort is by 'how far can you go' unit.movement.headTowards(bestTile) return true diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 5b56801827..c86e7d90f3 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -157,12 +157,14 @@ open class TileInfo { // We have to .toList() so that the values are stored together once for caching, // and the toSequence so that aggregations (like neighbors.flatMap{it.units} don't take up their own space - fun getHeight(): Int { - return getAllTerrains().flatMap { it.uniqueObjects } - .filter { it.placeholderText == "Has an elevation of [] for visibility calculations" } + @delegate:Transient + val height : Int by lazy { + getAllTerrains().flatMap { it.uniqueObjects } + .filter { it.isOfType(UniqueType.VisibilityElevation) } .map { it.params[0].toInt() }.sum() } + fun getBaseTerrain(): Terrain = baseTerrainObject fun getOwner(): CivilizationInfo? { diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 0abe4b19d2..5d9b5456e6 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -280,7 +280,7 @@ class TileMap { /** @return List of tiles visible from location [position] for a unit with sight range [sightDistance] */ fun getViewableTiles(position: Vector2, sightDistance: Int): List { val viewableTiles = getTilesInDistance(position, 1).toMutableList() - val currentTileHeight = get(position).getHeight() + val currentTileHeight = get(position).height for (i in 1..sightDistance) { // in each layer, // This is so we don't use tiles in the same distance to "see over", @@ -288,7 +288,7 @@ class TileMap { val tilesToAddInDistanceI = ArrayList() for (cTile in getTilesAtDistance(position, i)) { // for each tile in that layer, - val cTileHeight = cTile.getHeight() + val cTileHeight = cTile.height /* Okay so, if we're looking at a tile from a to c with b in the middle, @@ -307,7 +307,7 @@ class TileMap { val containsViewableNeighborThatCanSeeOver = cTile.neighbors.any { bNeighbor: TileInfo -> - val bNeighborHeight = bNeighbor.getHeight() + val bNeighborHeight = bNeighbor.height viewableTiles.contains(bNeighbor) && ( currentTileHeight > bNeighborHeight // a>b || cTileHeight > bNeighborHeight // c>b diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index b5b81520d3..d132cc115e 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -223,6 +223,7 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) { TileProvidesYieldWithoutPopulation("Tile provides yield without assigned population", UniqueTarget.Terrain, UniqueTarget.Improvement), NullifyYields("Nullifies all other stats this tile provides", UniqueTarget.Terrain), + VisibilityElevation("Has an elevation of [amount] for visibility calculations", UniqueTarget.Terrain), NoNaturalGeneration("Doesn't generate naturally", UniqueTarget.Terrain),