diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 857fd59397..36c2d5b78a 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -2,6 +2,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/store.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" @@ -19,7 +21,37 @@ namespace MWGui if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; - if (MWBase::Environment::get().getWorld()->isBoundItemID(base.getCellRef().getRefId())) + static std::map boundItemIDCache; + + // If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason + if (boundItemIDCache.empty()) + { + // Build a list of known bound item ID's + const MWWorld::Store &gameSettings = MWBase::Environment::get().getWorld()->getStore().get(); + + for (MWWorld::Store::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration) + { + const ESM::GameSetting ¤tSetting = *currentIteration; + std::string currentGMSTID = currentSetting.mId; + Misc::StringUtils::toLower(currentGMSTID); + + // Don't bother checking this GMST if it's not a sMagicBound* one. + if (currentGMSTID.find("smagicbound") != 0) + continue; + + // All sMagicBound* GMST's should be of type string + std::string currentGMSTValue = currentSetting.getString(); + Misc::StringUtils::toLower(currentGMSTValue); + + boundItemIDCache[currentGMSTValue] = true; + } + } + + // Perform bound item check and assign the Flag_Bound bit if it passes + std::string tempItemID = base.getCellRef().getRefId(); + Misc::StringUtils::toLower(tempItemID); + + if (boundItemIDCache.count(tempItemID) != 0) mFlags |= Flag_Bound; }