Add InventoryStore::unequipItem()

This commit is contained in:
Emanuel Guevel 2013-11-01 00:21:15 +01:00
parent 12dbbde1e3
commit 37e91a278e
2 changed files with 20 additions and 0 deletions

View file

@ -386,3 +386,15 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipSlot(int slot, c
return it;
}
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::unequipItem(const MWWorld::Ptr& item, const MWWorld::Ptr& actor)
{
for (int slot=0; slot<MWWorld::InventoryStore::Slots; ++slot)
{
MWWorld::ContainerStoreIterator equipped = getSlot(slot);
if (equipped != end() && *equipped == item)
return unequipSlot(slot, actor);
}
throw std::runtime_error ("attempt to unequip an item that is not currently equipped");
}

View file

@ -119,6 +119,14 @@ namespace MWWorld
/// @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).
ContainerStoreIterator unequipItem(const Ptr& item, const Ptr& actor);
///< Unequip an item identified by its Ptr. An exception is thrown
/// if the item is not currently equipped.
///
/// @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).
};
}