From bfa93be7654153fc733ec22d1c478c12440b8f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Tue, 9 Jul 2024 06:39:41 +0200 Subject: [PATCH 1/2] Limit predicted damage / loses to actual stack health --- AI/StupidAI/StupidAI.cpp | 9 +++++++++ lib/battle/DamageCalculator.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index d2486507c..f29d6ce49 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -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(totalHealth, dmg.damage.min); + dmg.damage.max = std::min(totalHealth, dmg.damage.max); + + auto ourHealth = s->getTotalHealth(); + retal.damage.min = std::min(ourHealth, retal.damage.min); + retal.damage.max = std::min(ourHealth, retal.damage.max); + adi = static_cast((dmg.damage.min + dmg.damage.max) / 2); adr = static_cast((retal.damage.min + retal.damage.max) / 2); } diff --git a/lib/battle/DamageCalculator.cpp b/lib/battle/DamageCalculator.cpp index 12ee5cff5..99bce45e6 100644 --- a/lib/battle/DamageCalculator.cpp +++ b/lib/battle/DamageCalculator.cpp @@ -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(1 + killsLeft, info.defender->getCount()); } int DamageCalculator::battleBonusValue(const IBonusBearer * bearer, const CSelector & selector) const From 5eabadd7db614f1ada8a2e71bfd22cfc37aa4e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Tue, 9 Jul 2024 06:50:00 +0200 Subject: [PATCH 2/2] Use vstd --- AI/StupidAI/StupidAI.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AI/StupidAI/StupidAI.cpp b/AI/StupidAI/StupidAI.cpp index f29d6ce49..3c152de13 100644 --- a/AI/StupidAI/StupidAI.cpp +++ b/AI/StupidAI/StupidAI.cpp @@ -79,13 +79,13 @@ public: 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(totalHealth, dmg.damage.min); - dmg.damage.max = std::min(totalHealth, dmg.damage.max); + vstd::amin(dmg.damage.min, totalHealth); + vstd::amin(dmg.damage.max, totalHealth); auto ourHealth = s->getTotalHealth(); - retal.damage.min = std::min(ourHealth, retal.damage.min); - retal.damage.max = std::min(ourHealth, retal.damage.max); - + vstd::amin(retal.damage.min, ourHealth); + vstd::amin(retal.damage.max, ourHealth); + adi = static_cast((dmg.damage.min + dmg.damage.max) / 2); adr = static_cast((retal.damage.min + retal.damage.max) / 2); }