1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

Merge pull request #4241 from vcmi/fix_damage_estimation

Limit predicted damage / loses to actual stack health
This commit is contained in:
Ivan Savenko 2024-07-09 14:28:28 +03:00 committed by GitHub
commit 7ec702bac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -77,6 +77,15 @@ public:
// FIXME: provide distance info for Jousting bonus
DamageEstimation retal;
DamageEstimation dmg = cb->getBattle(battleID)->battleEstimateDamage(ourStack, s, 0, &retal);
// Clip damage dealt to total stack health
auto totalHealth = s->getTotalHealth();
vstd::amin(dmg.damage.min, totalHealth);
vstd::amin(dmg.damage.max, totalHealth);
auto ourHealth = s->getTotalHealth();
vstd::amin(retal.damage.min, ourHealth);
vstd::amin(retal.damage.max, ourHealth);
adi = static_cast<int>((dmg.damage.min + dmg.damage.max) / 2);
adr = static_cast<int>((retal.damage.min + retal.damage.max) / 2);
}

View File

@ -509,7 +509,7 @@ int64_t DamageCalculator::getCasualties(int64_t damageDealt) const
int64_t damageLeft = damageDealt - info.defender->getFirstHPleft();
int64_t killsLeft = damageLeft / info.defender->getMaxHealth();
return 1 + killsLeft;
return std::min<int32_t>(1 + killsLeft, info.defender->getCount());
}
int DamageCalculator::battleBonusValue(const IBonusBearer * bearer, const CSelector & selector) const