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
This commit is contained in:
Arthur van der Staaij
2021-06-23 08:41:55 +02:00
committed by GitHub
parent 300eb6f726
commit e10c52efc1
4 changed files with 25 additions and 17 deletions

View File

@ -21,7 +21,7 @@
"food": 2, "food": 2,
"movementCost": 1, "movementCost": 1,
"RGB": [97,171,58], "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", "name": "Plains",
@ -31,7 +31,7 @@
"movementCost": 1, "movementCost": 1,
"RGB": [168,185,102], "RGB": [168,185,102],
"uniques": ["Occurs at temperature between [-0.4] and [0.8] and humidity between [0] and [0.5]", "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", "name": "Tundra",
@ -39,14 +39,14 @@
"food": 1, "food": 1,
"movementCost": 1, "movementCost": 1,
"RGB": [189,204,191], "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", "name": "Desert",
"type": "Land", "type": "Land",
"movementCost": 1, "movementCost": 1,
"RGB": [ 230, 230, 113], "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", "name": "Lakes",
@ -62,14 +62,14 @@
"impassable": true, "impassable": true,
"defenceBonus": 0.25, "defenceBonus": 0.25,
"RGB": [120, 120, 120], "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", "name": "Snow",
"type": "Land", "type": "Land",
"movementCost": 1, "movementCost": 1,
"RGB": [231, 242, 249], "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 // Terrain features
@ -95,7 +95,7 @@
"unbuildable": true, "unbuildable": true,
"defenceBonus": 0.25, "defenceBonus": 0.25,
"occursOn": ["Tundra","Plains","Grassland","Hill"], "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"] "Blocks line-of-sight from tiles at same elevation"]
}, },
{ {
@ -147,7 +147,6 @@
"movementCost": 1, "movementCost": 1,
"defenceBonus": -0.1, "defenceBonus": -0.1,
"occursOn": ["Desert"] "occursOn": ["Desert"]
"uniques":["Open terrain"]
}, },
{ {
"name": "Ice", "name": "Ice",

View File

@ -201,6 +201,8 @@ open class TileInfo {
yieldAll(terrainFeatures.asSequence().mapNotNull { ruleset.terrains[it] }) yieldAll(terrainFeatures.asSequence().mapNotNull { ruleset.terrains[it] })
} }
fun isRoughTerrain() = getAllTerrains().any{ it.isRough() }
fun hasUnique(unique: String) = getAllTerrains().any { it.uniques.contains(unique) } fun hasUnique(unique: String) = getAllTerrains().any { it.uniques.contains(unique) }
fun getWorkingCity(): CityInfo? { fun getWorkingCity(): CityInfo? {
@ -406,12 +408,13 @@ open class TileInfo {
"River" -> isAdjacentToRiver() "River" -> isAdjacentToRiver()
improvement -> true improvement -> true
naturalWonder -> true naturalWonder -> true
"Open terrain" -> !isRoughTerrain()
"Rough terrain" -> isRoughTerrain()
"Foreign Land" -> civInfo != null && !isFriendlyTerritory(civInfo) "Foreign Land" -> civInfo != null && !isFriendlyTerritory(civInfo)
"Friendly Land" -> civInfo != null && isFriendlyTerritory(civInfo) "Friendly Land" -> civInfo != null && isFriendlyTerritory(civInfo)
else -> { else -> {
if (terrainFeatures.contains(filter)) return true if (terrainFeatures.contains(filter)) return true
if (baseTerrainObject.uniques.contains(filter)) return true if (hasUnique(filter)) return true
if (terrainFeatures.isNotEmpty() && getTerrainFeatures().last().uniques.contains(filter)) return true
if (resource != null && getTileResource().resourceType.name + " resource" == filter) return true if (resource != null && getTileResource().resourceType.name + " resource" == filter) return true
if (civInfo != null && hasViewableResource(civInfo) && resource == filter) return true if (civInfo != null && hasViewableResource(civInfo) && resource == filter) return true
return false return false

View File

@ -43,7 +43,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
if (civInfo.nation.ignoreHillMovementCost && to.isHill()) if (civInfo.nation.ignoreHillMovementCost && to.isHill())
return 1f + extraCost // usually hills take 2 movements, so here it is 1 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 return 4f + extraCost
if (unit.doubleMovementInCoast && to.baseTerrain == Constants.coast) if (unit.doubleMovementInCoast && to.baseTerrain == Constants.coast)

View File

@ -36,16 +36,20 @@ class Terrain : NamedStats() {
var defenceBonus:Float = 0f var defenceBonus:Float = 0f
var impassable = false var impassable = false
/** Use isRough() instead */
@Deprecated("As of 3.14.1") @Deprecated("As of 3.14.1")
var rough = false 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 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 if (RGB == null) return Color.GOLD
return colorFromRGB(RGB!!) return colorFromRGB(RGB!!)
} }
fun getDescription(ruleset: Ruleset): String { fun getDescription(ruleset: Ruleset): String {
val sb = StringBuilder() val sb = StringBuilder()
sb.appendLine(this.clone().toString()) sb.appendLine(this.clone().toString())
@ -59,8 +63,13 @@ class Terrain : NamedStats() {
if (resourcesFound.isNotEmpty()) if (resourcesFound.isNotEmpty())
sb.appendLine("May contain [${resourcesFound.joinToString(", ") { it.name.tr() }}]".tr()) 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()) if(uniques.isNotEmpty())
sb.appendLine(uniques.joinToString { it.tr() }) sb.appendLine(uniques.filter{ it != "Rough terrain" }.joinToString{ it.tr() })
if (impassable) if (impassable)
sb.appendLine(Constants.impassable.tr()) sb.appendLine(Constants.impassable.tr())
@ -70,9 +79,6 @@ class Terrain : NamedStats() {
if (defenceBonus != 0f) if (defenceBonus != 0f)
sb.appendLine("{Defence bonus}: ".tr() + (defenceBonus * 100).toInt() + "%") sb.appendLine("{Defence bonus}: ".tr() + (defenceBonus * 100).toInt() + "%")
if (rough)
sb.appendLine("Rough Terrain".tr())
return sb.toString() return sb.toString()
} }
} }