1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-15 11:46:56 +02:00

Avoid crash in case if Witch Hut or Shrine is not a rewardable object

This commit is contained in:
Ivan Savenko 2023-12-13 16:52:44 +02:00
parent 76cb5387c5
commit 337e090ee9

View File

@ -1145,14 +1145,14 @@ CGObjectInstance * CMapLoaderH3M::readWitchHut(const int3 & position, std::share
auto * object = readGeneric(position, objectTemplate);
auto * rewardable = dynamic_cast<CRewardableObject*>(object);
assert(rewardable);
// AB and later maps have allowed abilities defined in H3M
if(features.levelAB)
{
std::set<SecondarySkill> allowedAbilities;
reader->readBitmaskSkills(allowedAbilities, false);
if (rewardable)
{
if(allowedAbilities.size() != 1)
{
auto defaultAllowed = VLC->skillh->getDefaultAllowed();
@ -1182,6 +1182,11 @@ CGObjectInstance * CMapLoaderH3M::readWitchHut(const int3 & position, std::share
variable.setMeta(ModScope::scopeGame()); // list may include skills from all mods
rewardable->configuration.presetVariable("secondarySkill", "gainedSkill", variable);
}
else
{
logGlobal->warn("Failed to set allowed secondary skills to a Witch Hut! Object is not rewardable!");
}
}
return object;
}
@ -1362,10 +1367,10 @@ CGObjectInstance * CMapLoaderH3M::readShrine(const int3 & position, std::shared_
auto * object = readGeneric(position, objectTemplate);
auto * rewardable = dynamic_cast<CRewardableObject*>(object);
assert(rewardable);
SpellID spell = reader->readSpell32();
if (rewardable)
{
if(spell != SpellID::NONE)
{
JsonNode variable;
@ -1373,6 +1378,11 @@ CGObjectInstance * CMapLoaderH3M::readShrine(const int3 & position, std::shared_
variable.setMeta(ModScope::scopeGame()); // list may include spells from all mods
rewardable->configuration.presetVariable("spell", "gainedSpell", variable);
}
}
else
{
logGlobal->warn("Failed to set selected spell to a Shrine!. Object is not rewardable!");
}
return object;
}