1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-26 08:41:13 +02:00

Fix creature min damage greater than max will cause game crash. #3780

This commit is contained in:
kdmcser 2024-04-17 23:24:13 +08:00
parent 9390825ee7
commit 1c6dfb5cc5

View File

@ -18,6 +18,8 @@
#include "../mapObjects/CGTownInstance.h"
#include "../spells/CSpellHandler.h"
#include "../GameSettings.h"
#include "../VCMI_Lib.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -29,6 +31,16 @@ DamageRange DamageCalculator::getBaseDamageSingle() const
minDmg = info.attacker->getMinDamage(info.shooting);
maxDmg = info.attacker->getMaxDamage(info.shooting);
if(minDmg > maxDmg)
{
auto creature = VLC->creatures()->getById(info.attacker->creatureId());
const auto & creatureName = creature->getNamePluralTranslated();
logGlobal->error("Creature %s min damage %lld exceed max damage %lld.", creatureName.c_str(), minDmg, maxDmg);
logGlobal->error("This problem may lead to unexpected result, please report it to modder.");
// to avoid RNG crash. and make bless and curse spell correct
std::swap(minDmg, maxDmg);
}
if(info.attacker->creatureIndex() == CreatureID::ARROW_TOWERS)
{
const auto * town = callback.battleGetDefendedTown();