From bbfd7f4c9d0d53c2be676a1591e81e626e974180 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Sat, 9 Nov 2013 02:47:11 +0100 Subject: [PATCH] Disable equipped item re-stacking when the item is removed from inventory The item was not removed if it was re-stacked. --- apps/openmw/mwworld/inventorystore.cpp | 24 ++++++++++++++---------- apps/openmw/mwworld/inventorystore.hpp | 6 +++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index dbb5a80b5..dc2d0cab1 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -325,7 +325,8 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor if (*mSlots[slot] == item) { - unequipSlot(slot, actor); + // restacking is disabled cause it may break removal + unequipSlot(slot, actor, false); break; } } @@ -345,22 +346,25 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor return retCount; } -MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) +MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor, bool restack) { ContainerStoreIterator it = getSlot(slot); if (it != end()) { - // restack item previously in this slot ContainerStoreIterator retval = it; - for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) - { - if (stacks(*iter, *it)) + + if (restack) { + // restack item previously in this slot + for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter) { - iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount()); - it->getRefData().setCount(0); - retval = iter; - break; + if (stacks(*iter, *it)) + { + iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount()); + it->getRefData().setCount(0); + retval = iter; + break; + } } } diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 02d65d54a..c4ad51777 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -116,12 +116,12 @@ namespace MWWorld /// /// @return the number of items actually removed - ContainerStoreIterator unequipSlot(int slot, const Ptr& actor); + ContainerStoreIterator unequipSlot(int slot, const Ptr& actor, bool restack = true); ///< Unequip \a slot. /// /// @return an iterator to the item that was previously in the slot - /// (it can be re-stacked so its count may be different than when it - /// was equipped). + /// (if \a restack is true, the item can be re-stacked so its count + /// may differ from when it was equipped). ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor); ///< Unequip an item identified by its Ptr. An exception is thrown