Disable equipped item re-stacking when the item is removed from inventory

The item was not removed if it was re-stacked.
This commit is contained in:
Emanuel Guevel 2013-11-09 02:47:11 +01:00
parent d2dcf0b203
commit bbfd7f4c9d
2 changed files with 17 additions and 13 deletions

View file

@ -325,7 +325,8 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
if (*mSlots[slot] == item) if (*mSlots[slot] == item)
{ {
unequipSlot(slot, actor); // restacking is disabled cause it may break removal
unequipSlot(slot, actor, false);
break; break;
} }
} }
@ -345,22 +346,25 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
return retCount; 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); ContainerStoreIterator it = getSlot(slot);
if (it != end()) if (it != end())
{ {
// restack item previously in this slot
ContainerStoreIterator retval = it; ContainerStoreIterator retval = it;
for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter)
{ if (restack) {
if (stacks(*iter, *it)) // restack item previously in this slot
for (MWWorld::ContainerStoreIterator iter (begin()); iter != end(); ++iter)
{ {
iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount()); if (stacks(*iter, *it))
it->getRefData().setCount(0); {
retval = iter; iter->getRefData().setCount(iter->getRefData().getCount() + it->getRefData().getCount());
break; it->getRefData().setCount(0);
retval = iter;
break;
}
} }
} }

View file

@ -116,12 +116,12 @@ namespace MWWorld
/// ///
/// @return the number of items actually removed /// @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. ///< Unequip \a slot.
/// ///
/// @return an iterator to the item that was previously in the 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 /// (if \a restack is true, the item can be re-stacked so its count
/// was equipped). /// may differ from when it was equipped).
ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor); ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor);
///< Unequip an item identified by its Ptr. An exception is thrown ///< Unequip an item identified by its Ptr. An exception is thrown