Skip to content

Commit

Permalink
Disable equipped item re-stacking when the item is removed from inven…
Browse files Browse the repository at this point in the history
…tory

The item was not removed if it was re-stacked.
  • Loading branch information
PotatoesMaster committed Nov 10, 2013
1 parent d2dcf0b commit bbfd7f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions apps/openmw/mwworld/inventorystore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwworld/inventorystore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bbfd7f4

Please sign in to comment.