forked from mirror/openmw-tes3mp
InventoryStore re-stacking unequipped items
This commit is contained in:
parent
9f2595183b
commit
16522ddc59
3 changed files with 35 additions and 7 deletions
|
@ -45,18 +45,27 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end()
|
||||||
return ContainerStoreIterator (this);
|
return ContainerStoreIterator (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) const
|
||||||
|
{
|
||||||
|
/// \todo add current weapon/armor health, remaining lockpick/repair uses, current enchantment charge here as soon as they are implemented
|
||||||
|
if ( ptr1.mCellRef->refID == ptr2.mCellRef->refID
|
||||||
|
&& (MWWorld::Class::get(ptr1).getScript(ptr1) == "" && MWWorld::Class::get(ptr2).getScript(ptr2) == "") // item with a script never stacks
|
||||||
|
&& ptr1.mCellRef->owner == ptr2.mCellRef->owner
|
||||||
|
&& ptr1.mCellRef->soul == ptr2.mCellRef->soul
|
||||||
|
&& ptr1.mCellRef->charge == ptr2.mCellRef->charge)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MWWorld::ContainerStore::add (const Ptr& ptr)
|
void MWWorld::ContainerStore::add (const Ptr& ptr)
|
||||||
{
|
{
|
||||||
int type = getType(ptr);
|
int type = getType(ptr);
|
||||||
|
|
||||||
// determine whether to stack or not
|
// determine whether to stack or not
|
||||||
// item stacking depends on owner, script, enchantment and name
|
|
||||||
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
|
for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter)
|
||||||
{
|
{
|
||||||
if ( iter->mCellRef->refID == ptr.mCellRef->refID
|
if (stacks(*iter, ptr))
|
||||||
&& MWWorld::Class::get(*iter).getScript(*iter) == MWWorld::Class::get(ptr).getScript(ptr)
|
|
||||||
&& MWWorld::Class::get(*iter).getEnchantment(*iter) == MWWorld::Class::get(ptr).getEnchantment(ptr)
|
|
||||||
&& iter->mCellRef->owner == ptr.mCellRef->owner)
|
|
||||||
{
|
{
|
||||||
// stack
|
// stack
|
||||||
iter->getRefData().setCount( iter->getRefData().getCount() + ptr.getRefData().getCount() );
|
iter->getRefData().setCount( iter->getRefData().getCount() + ptr.getRefData().getCount() );
|
||||||
|
|
|
@ -66,6 +66,9 @@ namespace MWWorld
|
||||||
|
|
||||||
ContainerStoreIterator end();
|
ContainerStoreIterator end();
|
||||||
|
|
||||||
|
bool stacks (const Ptr& ptr1, const Ptr& ptr2) const;
|
||||||
|
///< @return true if the two specified objects can stack with each other
|
||||||
|
|
||||||
void add (const Ptr& ptr);
|
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.
|
||||||
///
|
///
|
||||||
|
|
|
@ -67,9 +67,25 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
|
||||||
throw std::runtime_error ("invalid slot");
|
throw std::runtime_error ("invalid slot");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \todo restack item previously in this slot (if required)
|
// restack item previously in this slot (if required)
|
||||||
|
if (mSlots[slot] != end())
|
||||||
|
{
|
||||||
|
for (MWWorld::ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
|
||||||
|
{
|
||||||
|
if (stacks(*iter, *mSlots[slot]))
|
||||||
|
{
|
||||||
|
iter->getRefData().setCount( iter->getRefData().getCount() + mSlots[slot]->getRefData().getCount() );
|
||||||
|
mSlots[slot]->getRefData().setCount(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// \todo unstack item pointed to by iterator if required)
|
// unstack item pointed to by iterator if required
|
||||||
|
if (iterator->getRefData().getCount() > 1)
|
||||||
|
{
|
||||||
|
/// \ŧodo ???
|
||||||
|
}
|
||||||
|
|
||||||
mSlots[slot] = iterator;
|
mSlots[slot] = iterator;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue