Replace empty NPC class with fallback

fix/shrink_builds
Evil Eye 3 years ago
parent c7449dc272
commit f41e46db64

@ -120,6 +120,7 @@
Bug #6730: LoopGroup stalls animation after playing :Stop frame until another animation is played
Bug #6753: Info records without a DATA subrecords are loaded incorrectly
Bug #6794: Light sources are attached to mesh bounds centers instead of mesh origins when AttachLight NiNode is missing
Bug #6799: Game crashes if an NPC has no Class attached
Feature #890: OpenMW-CS: Column filtering
Feature #1465: "Reset" argument for AI functions
Feature #2491: Ability to make OpenMW "portable"

@ -59,15 +59,18 @@ namespace
}
}
std::vector<ESM::NPC> getNPCsToReplace(const MWWorld::Store<ESM::Faction>& factions, const MWWorld::Store<ESM::Class>& classes, const std::unordered_map<std::string, ESM::NPC, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>& npcs)
const std::string& getDefaultClass(const MWWorld::Store<ESM::Class>& classes)
{
// Cache first class from store - we will use it if current class is not found
std::string defaultCls;
auto it = classes.begin();
if (it != classes.end())
defaultCls = it->mId;
else
throw std::runtime_error("List of NPC classes is empty!");
return it->mId;
throw std::runtime_error("List of NPC classes is empty!");
}
std::vector<ESM::NPC> getNPCsToReplace(const MWWorld::Store<ESM::Faction>& factions, const MWWorld::Store<ESM::Class>& classes, const std::unordered_map<std::string, ESM::NPC, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>& npcs)
{
// Cache first class from store - we will use it if current class is not found
const std::string& defaultCls = getDefaultClass(classes);
// Validate NPCs for non-existing class and faction.
// We will replace invalid entries by fixed ones
@ -78,7 +81,7 @@ namespace
ESM::NPC npc = npcIter.second;
bool changed = false;
const std::string npcFaction = npc.mFaction;
const std::string& npcFaction = npc.mFaction;
if (!npcFaction.empty())
{
const ESM::Faction *fact = factions.search(npcFaction);
@ -91,16 +94,13 @@ namespace
}
}
std::string npcClass = npc.mClass;
if (!npcClass.empty())
const std::string& npcClass = npc.mClass;
const ESM::Class *cls = classes.search(npcClass);
if (!cls)
{
const ESM::Class *cls = classes.search(npcClass);
if (!cls)
{
Log(Debug::Verbose) << "NPC '" << npc.mId << "' (" << npc.mName << ") has nonexistent class '" << npc.mClass << "', using '" << defaultCls << "' class as replacement.";
npc.mClass = defaultCls;
changed = true;
}
Log(Debug::Verbose) << "NPC '" << npc.mId << "' (" << npc.mName << ") has nonexistent class '" << npc.mClass << "', using '" << defaultCls << "' class as replacement.";
npc.mClass = defaultCls;
changed = true;
}
if (changed)

Loading…
Cancel
Save