1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Limit predicted damage / loses to actual stack health

This commit is contained in:
Tomasz Zieliński
2024-07-09 06:39:41 +02:00
parent ae689625e4
commit bfa93be765
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();
dmg.damage.min = std::min<int64_t>(totalHealth, dmg.damage.min);
dmg.damage.max = std::min<int64_t>(totalHealth, dmg.damage.max);
auto ourHealth = s->getTotalHealth();
retal.damage.min = std::min<int64_t>(ourHealth, retal.damage.min);
retal.damage.max = std::min<int64_t>(ourHealth, retal.damage.max);
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