From c60700193fede5bca47b79a8d0aea4bce0bebf4d Mon Sep 17 00:00:00 2001 From: soggerr <64605293+soggerr@users.noreply.github.com> Date: Fri, 15 Dec 2023 02:13:12 -0700 Subject: [PATCH] Show average damage in battle calculations (#10738) Change BattleTable to calulate average damage and show alongside the min and max for easier calculations when planning to attack with multiple units such as when sieging a city Unfortunately for min-maxers the randomness is still turn dependent for a given defending unit, so the damage randomness will not average out across multiple attacks on a given turn but they will all be more or all be less depending on the luck that turn. --- .../ui/screens/worldscreen/bottombar/BattleTable.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt index eb3ab43de8..18f2b6fe48 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/bottombar/BattleTable.kt @@ -202,9 +202,11 @@ class BattleTable(val worldScreen: WorldScreen) : Table() { val maxDamageToDefender = BattleDamage.calculateDamageToDefender(attacker, defender, tileToAttackFrom, 1f) val minDamageToDefender = BattleDamage.calculateDamageToDefender(attacker, defender, tileToAttackFrom, 0f) + val avgDamageToDefender = arrayOf(maxDamageToDefender, minDamageToDefender).average().roundToInt() val maxDamageToAttacker = BattleDamage.calculateDamageToAttacker(attacker, defender, tileToAttackFrom, 1f) val minDamageToAttacker = BattleDamage.calculateDamageToAttacker(attacker, defender, tileToAttackFrom, 0f) + val avgDamageToAttacker = arrayOf(maxDamageToAttacker, minDamageToAttacker).average().roundToInt() if (attacker.isMelee() && (defender.isCivilian() || defender is CityCombatant && defender.isDefeated())) { @@ -228,12 +230,12 @@ class BattleTable(val worldScreen: WorldScreen) : Table() { add(getHealthBar(defender.getMaxHealth(), defender.getHealth(), maxRemainingLifeDefender, minRemainingLifeDefender)).row() if (minRemainingLifeAttacker == attackerHealth) add(attackerHealth.toLabel()) - else if (maxRemainingLifeAttacker == minRemainingLifeAttacker) add("$attackerHealth → $maxRemainingLifeAttacker".toLabel()) - else add("$attackerHealth → $minRemainingLifeAttacker-$maxRemainingLifeAttacker".toLabel()) + else if (maxRemainingLifeAttacker == minRemainingLifeAttacker) add("$attackerHealth → $maxRemainingLifeAttacker ($avgDamageToAttacker)".toLabel()) + else add("$attackerHealth → $minRemainingLifeAttacker-$maxRemainingLifeAttacker (~$avgDamageToAttacker)".toLabel()) - if (minRemainingLifeDefender == maxRemainingLifeDefender) add("$defenderHealth → $maxRemainingLifeDefender".toLabel()) - else add("$defenderHealth → $minRemainingLifeDefender-$maxRemainingLifeDefender".toLabel()) + if (minRemainingLifeDefender == maxRemainingLifeDefender) add("$defenderHealth → $maxRemainingLifeDefender ($avgDamageToDefender)".toLabel()) + else add("$defenderHealth → $minRemainingLifeDefender-$maxRemainingLifeDefender (~$avgDamageToDefender)".toLabel()) } row().pad(5f)