From e10c52efc147ecca026fe5c608b192d24ec2b3a0 Mon Sep 17 00:00:00 2001 From: Arthur van der Staaij <32672293+avdstaaij@users.noreply.github.com> Date: Wed, 23 Jun 2021 08:41:55 +0200 Subject: [PATCH] Fixed open terrain bonus working in rough terrain (#4219) * Fixed open terrain bonus working in rough terrain Fixed #4139 - The open terrain combat bonus no longer works in rough terrain. Deprecated "Open terrain" and "Rough terrain" uniques and undeprecated "rough" property of terrains. * Minor simplification * Replaced "rough" with "Rough terrain" unique * Empty commit to re-run the build checks --- .../assets/jsons/Civ V - Vanilla/Terrains.json | 15 +++++++-------- core/src/com/unciv/logic/map/TileInfo.kt | 7 +++++-- .../unciv/logic/map/UnitMovementAlgorithms.kt | 2 +- .../com/unciv/models/ruleset/tile/Terrain.kt | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Terrains.json b/android/assets/jsons/Civ V - Vanilla/Terrains.json index 03f2f57856..711c771ed3 100644 --- a/android/assets/jsons/Civ V - Vanilla/Terrains.json +++ b/android/assets/jsons/Civ V - Vanilla/Terrains.json @@ -21,7 +21,7 @@ "food": 2, "movementCost": 1, "RGB": [97,171,58], - "uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0.5] and [1]", "Open terrain"] + "uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0.5] and [1]"] }, { "name": "Plains", @@ -31,7 +31,7 @@ "movementCost": 1, "RGB": [168,185,102], "uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0] and [0.5]", - "Occurs at temperature between [0.8] and [1] and humidity between [0.7] and [1]", "Open terrain"] + "Occurs at temperature between [0.8] and [1] and humidity between [0.7] and [1]"] }, { "name": "Tundra", @@ -39,14 +39,14 @@ "food": 1, "movementCost": 1, "RGB": [189,204,191], - "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0.5] and [1]", "Open terrain"] + "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0.5] and [1]"] }, { "name": "Desert", "type": "Land", "movementCost": 1, "RGB": [ 230, 230, 113], - "uniques": ["Occurs at temperature between [0.8] and [1] and humidity between [0] and [0.7]", "Open terrain"] + "uniques": ["Occurs at temperature between [0.8] and [1] and humidity between [0] and [0.7]"] }, { "name": "Lakes", @@ -62,14 +62,14 @@ "impassable": true, "defenceBonus": 0.25, "RGB": [120, 120, 120], - "uniques":["Has an elevation of [4] for visibility calculations"] + "uniques":["Rough terrain", "Has an elevation of [4] for visibility calculations"] }, { "name": "Snow", "type": "Land", "movementCost": 1, "RGB": [231, 242, 249], - "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0] and [0.5]", "Open terrain"] + "uniques": ["Occurs at temperature between [-1] and [-0.4] and humidity between [0] and [0.5]"] }, // Terrain features @@ -95,7 +95,7 @@ "unbuildable": true, "defenceBonus": 0.25, "occursOn": ["Tundra","Plains","Grassland","Hill"], - "uniques": ["Provides a one-time Production bonus to the closest city when cut down", "Rough terrain", + "uniques": ["Rough terrain", "Provides a one-time Production bonus to the closest city when cut down", "Blocks line-of-sight from tiles at same elevation"] }, { @@ -147,7 +147,6 @@ "movementCost": 1, "defenceBonus": -0.1, "occursOn": ["Desert"] - "uniques":["Open terrain"] }, { "name": "Ice", diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index af22c99a06..1152bc8977 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -201,6 +201,8 @@ open class TileInfo { yieldAll(terrainFeatures.asSequence().mapNotNull { ruleset.terrains[it] }) } + fun isRoughTerrain() = getAllTerrains().any{ it.isRough() } + fun hasUnique(unique: String) = getAllTerrains().any { it.uniques.contains(unique) } fun getWorkingCity(): CityInfo? { @@ -406,12 +408,13 @@ open class TileInfo { "River" -> isAdjacentToRiver() improvement -> true naturalWonder -> true + "Open terrain" -> !isRoughTerrain() + "Rough terrain" -> isRoughTerrain() "Foreign Land" -> civInfo != null && !isFriendlyTerritory(civInfo) "Friendly Land" -> civInfo != null && isFriendlyTerritory(civInfo) else -> { if (terrainFeatures.contains(filter)) return true - if (baseTerrainObject.uniques.contains(filter)) return true - if (terrainFeatures.isNotEmpty() && getTerrainFeatures().last().uniques.contains(filter)) return true + if (hasUnique(filter)) return true if (resource != null && getTileResource().resourceType.name + " resource" == filter) return true if (civInfo != null && hasViewableResource(civInfo) && resource == filter) return true return false diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 10b8c5bf0a..c36d4a1bd0 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.getAllTerrains().any { it.rough || it.uniques.contains("Rough terrain") }) + if (unit.roughTerrainPenalty && to.isRoughTerrain()) return 4f + extraCost if (unit.doubleMovementInCoast && to.baseTerrain == Constants.coast) diff --git a/core/src/com/unciv/models/ruleset/tile/Terrain.kt b/core/src/com/unciv/models/ruleset/tile/Terrain.kt index 987f208c61..17a4cd8985 100644 --- a/core/src/com/unciv/models/ruleset/tile/Terrain.kt +++ b/core/src/com/unciv/models/ruleset/tile/Terrain.kt @@ -35,17 +35,21 @@ class Terrain : NamedStats() { var movementCost = 1 var defenceBonus:Float = 0f var impassable = false - + + /** Use isRough() instead */ @Deprecated("As of 3.14.1") var rough = false + fun isRough(): Boolean { + // "rough" property deprecated since 3.14.1 + return uniques.contains("Rough terrain") || rough + } fun getColor(): Color { // Can't be a lazy initialize, because we play around with the resulting color with lerp()s and the like if (RGB == null) return Color.GOLD return colorFromRGB(RGB!!) } - fun getDescription(ruleset: Ruleset): String { val sb = StringBuilder() sb.appendLine(this.clone().toString()) @@ -59,8 +63,13 @@ class Terrain : NamedStats() { if (resourcesFound.isNotEmpty()) sb.appendLine("May contain [${resourcesFound.joinToString(", ") { it.name.tr() }}]".tr()) + if (isRough()) + sb.appendLine("Rough terrain".tr()) + else + sb.appendLine("Open terrain".tr()) + if(uniques.isNotEmpty()) - sb.appendLine(uniques.joinToString { it.tr() }) + sb.appendLine(uniques.filter{ it != "Rough terrain" }.joinToString{ it.tr() }) if (impassable) sb.appendLine(Constants.impassable.tr()) @@ -70,9 +79,6 @@ class Terrain : NamedStats() { if (defenceBonus != 0f) sb.appendLine("{Defence bonus}: ".tr() + (defenceBonus * 100).toInt() + "%") - if (rough) - sb.appendLine("Rough Terrain".tr()) - return sb.toString() } } \ No newline at end of file