From 12dbbde1e37898781bf94198b945eaf65e9c0cd9 Mon Sep 17 00:00:00 2001 From: Emanuel Guevel Date: Fri, 1 Nov 2013 01:01:55 +0100 Subject: [PATCH] InvStore::unequipSlot: return an iterator to the unequipped item --- apps/openmw/mwworld/inventorystore.cpp | 15 +++++++++++---- apps/openmw/mwworld/inventorystore.hpp | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 3571f64baa..4d7fa2d64d 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -336,18 +336,21 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor return retCount; } -void MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) +MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) { 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, *mSlots[slot])) + if (stacks(*iter, *it)) { - iter->getRefData().setCount(iter->getRefData().getCount() + mSlots[slot]->getRefData().getCount()); - mSlots[slot]->getRefData().setCount(0); + iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount()); + it->getRefData().setCount(0); + retval = iter; break; } } @@ -377,5 +380,9 @@ void MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor) } /// \todo update actor model + + return retval; } + + return it; } diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 26ea90c3d6..1b11d9dcea 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -113,7 +113,12 @@ namespace MWWorld /// /// @return the number of items actually removed - void unequipSlot(int slot, const Ptr& actor); + ContainerStoreIterator unequipSlot(int slot, const Ptr& actor); + ///< 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). }; }