1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

implemented un-stacking

This commit is contained in:
scrawl 2012-05-13 11:52:17 +02:00
parent 16522ddc59
commit ee7e482cba
3 changed files with 31 additions and 4 deletions

View File

@ -75,7 +75,13 @@ void MWWorld::ContainerStore::add (const Ptr& ptr)
}
}
switch (type)
// if we got here, this means no stacking
addImpl(ptr);
}
void MWWorld::ContainerStore::addImpl (const Ptr& ptr)
{
switch (getType(ptr))
{
case Type_Potion: potions.list.push_back (*ptr.get<ESM::Potion>()); break;
case Type_Apparatus: appas.list.push_back (*ptr.get<ESM::Apparatus>()); break;

View File

@ -70,13 +70,19 @@ namespace MWWorld
///< @return true if the two specified objects can stack with each other
void add (const Ptr& ptr);
///< Add the item pointed to by \a ptr to this container.
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
///
/// \note The item pointed to is not required to exist beyond this function call.
///
/// \attention Do not add items to an existing stack by increasing the count instead of
/// calling this function!
protected:
void addImpl (const Ptr& ptr);
///< Add the item to this container (no stacking)
public:
void fill (const ESM::InventoryList& items, const ESMS::ESMStore& store);
///< Insert items into *this.

View File

@ -84,7 +84,11 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
// unstack item pointed to by iterator if required
if (iterator->getRefData().getCount() > 1)
{
/// \ŧodo ???
// add the item again with a count of count-1, then set the count of the original (that will be equipped) to 1
int count = iterator->getRefData().getCount();
iterator->getRefData().setCount(count-1);
addImpl(*iterator);
iterator->getRefData().setCount(1);
}
mSlots[slot] = iterator;
@ -163,7 +167,18 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
}
}
/// \todo unstack, if reqquired (itemsSlots.second)
if (!itemsSlots.second) // if itemsSlots.second is true, item can stay stacked when equipped
{
// unstack item pointed to by iterator if required
if (iter->getRefData().getCount() > 1)
{
// add the item again with a count of count-1, then set the count of the original (that will be equipped) to 1
int count = iter->getRefData().getCount();
iter->getRefData().setCount(count-1);
addImpl(*iter);
iter->getRefData().setCount(1);
}
}
slots[*iter2] = iter;
break;