From 621c62b44e8e999dc6594e940198f5275fbbf855 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sat, 31 Oct 2015 21:15:40 +0100 Subject: [PATCH] Don't crash when spell school level is higher than 3 (which is another bug) --- lib/mapObjects/CGHeroInstance.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 873534eb5..3042e35df 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -865,7 +865,7 @@ ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSc spell->forEachSchool([&, this](const SpellSchoolInfo & cnf, bool & stop) { - int thisSchool = std::max(getSecSkillLevel(cnf.skill), valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << ((ui8)cnf.id))); + int thisSchool = std::max(getSecSkillLevel(cnf.skill), valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << ((ui8)cnf.id))); //FIXME: Bonus shouldn't be additive (Witchking Artifacts : Crown of Skies) if(thisSchool > skill) { skill = thisSchool; @@ -877,7 +877,8 @@ ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSc vstd::amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus vstd::amax(skill, valOfBonuses(Bonus::SPELL, spell->id.toEnum())); //given by artifact or other effect - assert(skill >= 0 && skill <= 3); + vstd::amax(skill, 0); //in case we don't know any school + vstd::amin(skill, 3); return skill; }