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

@ -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

View File

@ -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)

View File

@ -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()
}
}