diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index 5dba7d3c26..0ec624e207 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -286,7 +286,8 @@ object BattleDamage { fun calculateDamageToAttacker( attacker: ICombatant, tileToAttackFrom: TileInfo?, - defender: ICombatant + defender: ICombatant, + ignoreRandomness: Boolean = false, ): Int { if (attacker.isRanged()) return 0 if (defender.isCivilian()) return 0 @@ -295,13 +296,14 @@ object BattleDamage { attacker, defender ) - return (damageModifier(ratio, true, attacker) * getHealthDependantDamageRatio(defender)).roundToInt() + return (damageModifier(ratio, true, attacker, ignoreRandomness) * getHealthDependantDamageRatio(defender)).roundToInt() } fun calculateDamageToDefender( attacker: ICombatant, tileToAttackFrom: TileInfo?, - defender: ICombatant + defender: ICombatant, + ignoreRandomness: Boolean = false, ): Int { val ratio = getAttackingStrength(attacker, defender) / getDefendingStrength( @@ -309,13 +311,14 @@ object BattleDamage { defender ) if (defender.isCivilian()) return 40 - return (damageModifier(ratio, false, attacker) * getHealthDependantDamageRatio(attacker)).roundToInt() + return (damageModifier(ratio, false, attacker, ignoreRandomness) * getHealthDependantDamageRatio(attacker)).roundToInt() } private fun damageModifier( attackerToDefenderRatio: Float, damageToAttacker: Boolean, - attacker: ICombatant // for the randomness + attacker: ICombatant, // for the randomness + ignoreRandomness: Boolean = false, ): Float { // https://forums.civfanatics.com/threads/getting-the-combat-damage-math.646582/#post-15468029 val strongerToWeakerRatio = @@ -324,7 +327,9 @@ object BattleDamage { if (damageToAttacker && attackerToDefenderRatio > 1 || !damageToAttacker && attackerToDefenderRatio < 1) // damage ratio from the weaker party is inverted ratioModifier = ratioModifier.pow(-1) val randomSeed = attacker.getCivInfo().gameInfo.turns * attacker.getTile().position.hashCode() // so people don't save-scum to get optimal results - val randomCenteredAround30 = 24 + 12 * Random(randomSeed.toLong()).nextFloat() + val randomCenteredAround30 = 24 + + if (ignoreRandomness) 6f + else 12 * Random(randomSeed.toLong()).nextFloat() return randomCenteredAround30 * ratioModifier } } diff --git a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt index 8184af5606..f3fb07e210 100644 --- a/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/worldscreen/bottombar/BattleTable.kt @@ -171,8 +171,8 @@ class BattleTable(val worldScreen: WorldScreen): Table() { row() } - var damageToDefender = BattleDamage.calculateDamageToDefender(attacker,null,defender) - var damageToAttacker = BattleDamage.calculateDamageToAttacker(attacker,null,defender) + var damageToDefender = BattleDamage.calculateDamageToDefender(attacker, null, defender, true) + var damageToAttacker = BattleDamage.calculateDamageToAttacker(attacker, null, defender, true) if (damageToAttacker>attacker.getHealth() && damageToDefender>defender.getHealth()) // when damage exceeds health, we don't want to show negative health numbers