From 0512a574e810de21c49668b5f8958c2718af9736 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 26 Oct 2020 20:13:24 +0100 Subject: [PATCH] Fix remove item regression --- apps/openmw/mwscript/containerextensions.cpp | 2 +- apps/openmw/mwworld/containerstore.cpp | 14 ++++------ apps/openmw/mwworld/containerstore.hpp | 6 ++--- apps/openmw/mwworld/inventorystore.cpp | 28 ++------------------ apps/openmw/mwworld/inventorystore.hpp | 7 ++--- 5 files changed, 12 insertions(+), 45 deletions(-) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 2e78fe374..186940dd9 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -246,7 +246,7 @@ namespace MWScript auto& store = container.getClass().getContainerStore(container); // Note that unlike AddItem, RemoveItem only removes from unresolved containers if(!store.isResolved()) - store.remove(item, count, ptr, false); + store.remove(item, count, ptr, false, false); } } return; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 3852b1abe..6fad42926 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -463,7 +463,7 @@ void MWWorld::ContainerStore::updateRechargingItems() } } -int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool resolveFirst) +int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) { if(resolveFirst) resolve(); @@ -471,7 +471,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter) if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId)) - toRemove -= removeImp(*iter, toRemove, actor); + toRemove -= remove(*iter, toRemove, actor, equipReplacement, resolveFirst); flagAsModified(); @@ -490,16 +490,12 @@ bool MWWorld::ContainerStore::hasVisibleItems() const return false; } -int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor) +int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) { assert(this == item.getContainerStore()); - resolve(); - - return removeImp(item, count, actor); -} + if(resolveFirst) + resolve(); -int MWWorld::ContainerStore::removeImp(const Ptr& item, int count, const Ptr& actor) -{ int toRemove = count; RefData& itemRef = item.getRefData(); diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 9092d41fc..e0843efba 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -129,8 +129,6 @@ namespace MWWorld void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true); void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true); - int removeImp(const Ptr& item, int count, const Ptr& actor); - template ContainerStoreIterator getState (CellRefList& collection, const ESM::ObjectState& state); @@ -180,12 +178,12 @@ namespace MWWorld ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr); ///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) - int remove(const std::string& itemId, int count, const Ptr& actor, bool resolve = true); + int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); ///< Remove \a count item(s) designated by \a itemId from this container. /// /// @return the number of items actually removed - virtual int remove(const Ptr& item, int count, const Ptr& actor); + virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); ///< Remove \a count item(s) designated by \a item from this inventory. /// /// @return the number of items actually removed diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index c2785579b..9dcddb921 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -710,33 +710,9 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSelectedEnchantItem( return mSelectedEnchantItem; } -int MWWorld::InventoryStore::remove(const std::string& itemId, int count, const Ptr& actor) +int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement, bool resolve) { - return remove(itemId, count, actor, false); -} - -int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor) -{ - return remove(item, count, actor, false); -} - -int MWWorld::InventoryStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement) -{ - int toRemove = count; - - for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter) - if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId)) - toRemove -= remove(*iter, toRemove, actor, equipReplacement); - - flagAsModified(); - - // number of removed items - return count - toRemove; -} - -int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement) -{ - int retCount = ContainerStore::remove(item, count, actor); + int retCount = ContainerStore::remove(item, count, actor, equipReplacement, resolve); bool wasEquipped = false; if (!item.getRefData().getCount()) diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 12306f809..e70c21480 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -165,11 +165,8 @@ namespace MWWorld bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2) const override; ///< @return true if the two specified objects can stack with each other - virtual int remove(const std::string& itemId, int count, const Ptr& actor); - virtual int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement); - - int remove(const Ptr& item, int count, const Ptr& actor) override; - virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement); + using ContainerStore::remove; + int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true) override; ///< Remove \a count item(s) designated by \a item from this inventory. /// /// @return the number of items actually removed