From d122699b2f5311dd699577c5f29327a00301b537 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 15 Aug 2013 18:29:09 +0200 Subject: [PATCH] and another fix for the same issue :( --- apps/openmw/mwworld/containerstore.cpp | 96 +++++++++++++++++++++++--- apps/openmw/mwworld/worldimp.cpp | 6 ++ 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index e7a4f0ea1..abc300d44 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -41,6 +41,26 @@ namespace return sum; } + + template + MWWorld::Ptr searchId (MWWorld::CellRefList& list, const std::string& id, + MWWorld::ContainerStore *store) + { + std::string id2 = Misc::StringUtils::lowerCase (id); + + for (typename MWWorld::CellRefList::List::iterator iter (list.mList.begin()); + iter!=list.mList.end(); ++iter) + { + if (Misc::StringUtils::lowerCase (iter->mBase->mId)==id2) + { + MWWorld::Ptr ptr (&*iter, 0); + ptr.setContainerStore (store); + return ptr; + } + } + + return MWWorld::Ptr(); + } } MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {} @@ -350,17 +370,75 @@ int MWWorld::ContainerStore::getType (const Ptr& ptr) MWWorld::Ptr MWWorld::ContainerStore::search (const std::string& id) { - /// \todo Since we have direct access to the CellRefList here, the performance of this function - /// could be improved notably by iterating directly over the CellRefLists instead of using - /// a ContainerStoreIterator. - - std::string id2 = Misc::StringUtils::lowerCase (id); - - for (ContainerStoreIterator iter (this); iter!=end(); ++iter) { - Ptr ptr = *iter; + Ptr ptr = searchId (potions, id, this); + if (!ptr.isEmpty()) + return ptr; + } - if (Misc::StringUtils::lowerCase (Class::get (ptr).getId (ptr))==id2) + { + Ptr ptr = searchId (appas, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (armors, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (books, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (clothes, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (ingreds, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (lights, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (lockpicks, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (miscItems, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (probes, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (repairs, id, this); + if (!ptr.isEmpty()) + return ptr; + } + + { + Ptr ptr = searchId (weapons, id, this); + if (!ptr.isEmpty()) return ptr; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index d47157366..5a3583f47 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -460,6 +460,12 @@ namespace MWWorld return mPlayer->getPlayer(); } + Ptr ptr = Class::get (mPlayer->getPlayer()). + getContainerStore (mPlayer->getPlayer()).search (name); + + if (!ptr.isEmpty()) + return ptr; + // active cells for (Scene::CellStoreCollection::const_iterator iter (mWorldScene->getActiveCells().begin()); iter!=mWorldScene->getActiveCells().end(); ++iter)