mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Damage in battle table is now the average damage done (#6176)
* Damage in battle table is now the average damage done * Trailing comma's * Fixed typo
This commit is contained in:
parent
402a9ba825
commit
a8be359ed2
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user