From 7686b1ee4a101e5a6daee4f6e937dec818416f18 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 6 May 2021 12:35:28 +0300 Subject: [PATCH] Simplified rough terrain check --- core/src/com/unciv/logic/map/TileInfo.kt | 7 +++---- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index d550ecaa20..26a2b11861 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -74,7 +74,7 @@ open class TileInfo { var roadStatus = RoadStatus.None var turnsToImprovement: Int = 0 - fun isHill() = terrainFeatures.contains(Constants.hill) + fun isHill() = baseTerrain == Constants.hill || terrainFeatures.contains(Constants.hill) var hasBottomRightRiver = false var hasBottomRiver = false @@ -191,6 +191,8 @@ open class TileInfo { } fun getTerrainFeatures(): List = terrainFeatures.mapNotNull { ruleset.terrains[it] } + fun getAllTerrains(): Sequence = sequenceOf(baseTerrainObject) + + terrainFeatures.asSequence().mapNotNull { ruleset.terrains[it] } fun getWorkingCity(): CityInfo? { val civInfo = getOwner() @@ -437,9 +439,6 @@ open class TileInfo { return min(distance, wrappedDistance).toInt() } - fun isRoughTerrain() = getBaseTerrain().rough || getTerrainFeatures().any { it.rough } - || getBaseTerrain().uniques.contains("Rough") || getTerrainFeatures().any { it.uniques.contains("Rough") } - override fun toString(): String { // for debugging, it helps to see what you're doing return toString(null) } diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 939e71d2e9..43ac0740da 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -43,7 +43,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (civInfo.nation.ignoreHillMovementCost && to.isHill()) return 1f + extraCost // usually hills take 2 movements, so here it is 1 - if (unit.roughTerrainPenalty && to.isRoughTerrain()) + if (unit.roughTerrainPenalty && to.getAllTerrains().any { it.rough || it.uniques.contains("Rough terrain") }) return 4f + extraCost if (unit.doubleMovementInCoast && to.baseTerrain == Constants.coast)