mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 16:19:56 +00:00
70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
|
|
#include "inventorystore.hpp"
|
|
|
|
#include <iterator>
|
|
|
|
void MWWorld::InventoryStore::copySlots (const InventoryStore& store)
|
|
{
|
|
// some const-trickery, required because of a flaw in the handling of MW-references and the
|
|
// resulting workarounds
|
|
for (std::vector<ContainerStoreIterator>::const_iterator iter (
|
|
const_cast<InventoryStore&> (store).mSlots.begin());
|
|
iter!=const_cast<InventoryStore&> (store).mSlots.end(); ++iter)
|
|
{
|
|
std::size_t distance = std::distance (const_cast<InventoryStore&> (store).begin(), *iter);
|
|
|
|
ContainerStoreIterator slot = begin();
|
|
|
|
std::advance (slot, distance);
|
|
|
|
mSlots.push_back (slot);
|
|
}
|
|
}
|
|
|
|
MWWorld::InventoryStore::InventoryStore()
|
|
{
|
|
for (int i=0; i<Slots; ++i)
|
|
mSlots.push_back (end());
|
|
}
|
|
|
|
MWWorld::InventoryStore::InventoryStore (const InventoryStore& store)
|
|
: ContainerStore (store)
|
|
{
|
|
copySlots (store);
|
|
}
|
|
|
|
MWWorld::InventoryStore& MWWorld::InventoryStore::operator= (const InventoryStore& store)
|
|
{
|
|
ContainerStore::operator= (store);
|
|
mSlots.clear();
|
|
copySlots (store);
|
|
return *this;
|
|
}
|
|
|
|
void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator)
|
|
{
|
|
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
|
|
throw std::runtime_error ("slot number out of range");
|
|
|
|
/// \todo verify slot
|
|
|
|
mSlots[slot] = iterator;
|
|
}
|
|
|
|
MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot)
|
|
{
|
|
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
|
|
throw std::runtime_error ("slot number out of range");
|
|
|
|
if (mSlots[slot]==end())
|
|
return end();
|
|
|
|
if (mSlots[slot]->getRefData().getCount()<1)
|
|
{
|
|
// object has been deleted
|
|
mSlots[slot] = end();
|
|
return end();
|
|
}
|
|
|
|
return mSlots[slot];
|
|
}
|