mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-30 16:20:21 +00:00
more inventory sanity checks
This commit is contained in:
parent
4b73116b9d
commit
ea336214de
@ -371,6 +371,11 @@ int MWWorld::ContainerStoreIterator::getType() const
|
|||||||
return mType;
|
return mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MWWorld::ContainerStore *MWWorld::ContainerStoreIterator::getContainerStore() const
|
||||||
|
{
|
||||||
|
return mContainer;
|
||||||
|
}
|
||||||
|
|
||||||
bool MWWorld::operator== (const ContainerStoreIterator& left, const ContainerStoreIterator& right)
|
bool MWWorld::operator== (const ContainerStoreIterator& left, const ContainerStoreIterator& right)
|
||||||
{
|
{
|
||||||
return left.isEqual (right);
|
return left.isEqual (right);
|
||||||
|
@ -142,6 +142,8 @@ namespace MWWorld
|
|||||||
|
|
||||||
int getType() const;
|
int getType() const;
|
||||||
|
|
||||||
|
const ContainerStore *getContainerStore() const;
|
||||||
|
|
||||||
friend class ContainerStore;
|
friend class ContainerStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#include "inventorystore.hpp"
|
#include "inventorystore.hpp"
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "class.hpp"
|
||||||
|
|
||||||
void MWWorld::InventoryStore::copySlots (const InventoryStore& store)
|
void MWWorld::InventoryStore::copySlots (const InventoryStore& store)
|
||||||
{
|
{
|
||||||
@ -46,7 +49,20 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
|
|||||||
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
|
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
|
||||||
throw std::runtime_error ("slot number out of range");
|
throw std::runtime_error ("slot number out of range");
|
||||||
|
|
||||||
/// \todo verify slot
|
if (iterator.getContainerStore()!=this)
|
||||||
|
throw std::runtime_error ("attempt to equip an item that is not in the inventory");
|
||||||
|
|
||||||
|
if (iterator!=end())
|
||||||
|
{
|
||||||
|
std::pair<std::vector<int>, bool> 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)
|
||||||
|
|
||||||
|
/// \todo unstack item pointed to by iterator if required)
|
||||||
|
|
||||||
mSlots[slot] = iterator;
|
mSlots[slot] = iterator;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ namespace MWWorld
|
|||||||
InventoryStore& operator= (const InventoryStore& store);
|
InventoryStore& operator= (const InventoryStore& store);
|
||||||
|
|
||||||
void equip (int slot, const ContainerStoreIterator& iterator);
|
void equip (int slot, const ContainerStoreIterator& iterator);
|
||||||
|
///< \note \a iteartor can be an end-iterator
|
||||||
|
|
||||||
ContainerStoreIterator getSlot (int slot);
|
ContainerStoreIterator getSlot (int slot);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user