|
|
|
@ -59,17 +59,38 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
|
|
|
|
|
if (iterator.getContainerStore()!=this)
|
|
|
|
|
throw std::runtime_error ("attempt to equip an item that is not in the inventory");
|
|
|
|
|
|
|
|
|
|
std::pair<std::vector<int>, bool> slots;
|
|
|
|
|
if (iterator!=end())
|
|
|
|
|
{
|
|
|
|
|
std::pair<std::vector<int>, bool> slots = Class::get (*iterator).getEquipmentSlots (*iterator);
|
|
|
|
|
slots = Class::get (*iterator).getEquipmentSlots (*iterator);
|
|
|
|
|
|
|
|
|
|
if (std::find (slots.first.begin(), slots.first.end(), slot)==slots.first.end())
|
|
|
|
|
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!=end() && !slots.second && iterator->getRefData().getCount() > 1) // if slots.second is true, item can stay stacked when equipped
|
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
@ -147,7 +168,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;
|
|
|
|
@ -168,3 +200,20 @@ void MWWorld::InventoryStore::autoEquip (const MWMechanics::NpcStats& stats)
|
|
|
|
|
flagAsModified();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MWWorld::InventoryStore::stacks(const Ptr& ptr1, const Ptr& ptr2) const
|
|
|
|
|
{
|
|
|
|
|
bool canStack = MWWorld::ContainerStore::stacks(ptr1, ptr2);
|
|
|
|
|
if (!canStack)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// don't stack if the item being checked against is currently equipped.
|
|
|
|
|
for (TSlots::const_iterator iter (mSlots.begin());
|
|
|
|
|
iter!=mSlots.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
if (ptr1 == **iter)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|