Przeglądaj źródła

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

kdmcser 1 rok temu
rodzic
commit
1c6dfb5cc5
1 zmienionych plików z 12 dodań i 0 usunięć
  1. 12 0
      lib/battle/DamageCalculator.cpp

+ 12 - 0
lib/battle/DamageCalculator.cpp

@@ -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();