mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Fix creature min damage greater than max will cause game crash. #3780
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
#include "../mapObjects/CGTownInstance.h"
|
#include "../mapObjects/CGTownInstance.h"
|
||||||
#include "../spells/CSpellHandler.h"
|
#include "../spells/CSpellHandler.h"
|
||||||
#include "../GameSettings.h"
|
#include "../GameSettings.h"
|
||||||
|
#include "../VCMI_Lib.h"
|
||||||
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -29,6 +31,16 @@ DamageRange DamageCalculator::getBaseDamageSingle() const
|
|||||||
minDmg = info.attacker->getMinDamage(info.shooting);
|
minDmg = info.attacker->getMinDamage(info.shooting);
|
||||||
maxDmg = info.attacker->getMaxDamage(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)
|
if(info.attacker->creatureIndex() == CreatureID::ARROW_TOWERS)
|
||||||
{
|
{
|
||||||
const auto * town = callback.battleGetDefendedTown();
|
const auto * town = callback.battleGetDefendedTown();
|
||||||
|
|||||||
Reference in New Issue
Block a user