From e81e0481698ba6a1a3e1ae413405b25dc337b8cf Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 31 May 2020 16:47:52 +0300 Subject: [PATCH] Added combat penalty when attacking across a river --- core/src/com/unciv/logic/battle/BattleDamage.kt | 13 ++++++++++--- core/src/com/unciv/logic/map/TileInfo.kt | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index a468657b50..02a80b20c0 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -137,6 +137,14 @@ object BattleDamage { } if (numberOfAttackersSurroundingDefender > 1) modifiers["Flanking"] = 0.1f * (numberOfAttackersSurroundingDefender-1) //https://www.carlsguides.com/strategy/civilization5/war/combatbonuses.php + + if (attacker.getTile().isConnectedByRiver(defender.getTile())){ + if (!attacker.getTile().hasConnection(attacker.getCivInfo()) // meaning, the tiles are not road-connected for this civ + || !defender.getTile().hasConnection(attacker.getCivInfo()) + || !attacker.getCivInfo().tech.roadsConnectAcrossRivers){ + modifiers["Across river"] = -0.2f + } + } } if (policies.autocracyCompletedTurns > 0 && policies.hasEffect("+20% attack bonus to all Military Units for 30 turns")) @@ -153,8 +161,6 @@ object BattleDamage { modifiers["Oligarchy"] = 0.5f } - - return modifiers } @@ -217,7 +223,8 @@ object BattleDamage { || tile.terrainFeature != Constants.jungle)) modifiers[tile.baseTerrain] = 0.25f - if(unit.getCivInfo().nation.unique == UniqueAbility.WAYFINDING && tile.getTilesInDistance(2).any { it.improvement=="Moai" }) + if(unit.getCivInfo().nation.unique == UniqueAbility.WAYFINDING + && tile.getTilesInDistance(2).any { it.improvement=="Moai" }) modifiers["Moai"] = 0.1f if(tile.neighbors.flatMap { it.getUnits() } diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 2fd503fd59..bf9e3dc1f6 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -341,12 +341,14 @@ open class TileInfo { return toString(null) } + /** The two tiles have a river between them */ fun isConnectedByRiver(otherTile:TileInfo): Boolean { - if(otherTile !in neighbors) throw Exception("Should never call this function on a non-neighbor!") val xDifference = this.position.x - otherTile.position.x val yDifference = this.position.y - otherTile.position.y return when { + yDifference < -1f || xDifference < -1f || yDifference > 1f || xDifference > 1f -> + throw Exception("Should never call this function on a non-neighbor!") xDifference == 1f && yDifference == 1f -> hasBottomRiver // we're directly above it xDifference == 1f -> hasBottomRightRiver // we're to the top-left of it yDifference == 1f -> hasBottomLeftRiver // we're to the top-right of it