forked from mirror/openmw-tes3mp
Ensure the item can be equipped in the given slot when loading inventory
This commit is contained in:
parent
c65f9cb3c0
commit
d13335ba40
7 changed files with 29 additions and 14 deletions
|
@ -466,7 +466,7 @@ namespace MWWorld
|
|||
// List moved references, from separately tracked list.
|
||||
for (ESM::CellRefTracker::const_iterator it = mCell->mLeasedRefs.begin(); it != mCell->mLeasedRefs.end(); ++it)
|
||||
{
|
||||
ESM::CellRef &ref = const_cast<ESM::CellRef&>(*it);
|
||||
const ESM::CellRef &ref = *it;
|
||||
|
||||
mIds.push_back(Misc::StringUtils::lowerCase(ref.mRefID));
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ void MWWorld::ContainerStore::storeState (const LiveCellRef<T>& ref, ESM::Object
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
|
||||
void MWWorld::ContainerStore::storeStates (CellRefList<T>& collection,
|
||||
std::vector<std::pair<ESM::ObjectState, int> >& states, bool equipable) const
|
||||
{
|
||||
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
|
||||
|
@ -641,7 +641,7 @@ MWWorld::Ptr MWWorld::ContainerStore::search (const std::string& id)
|
|||
return Ptr();
|
||||
}
|
||||
|
||||
void MWWorld::ContainerStore::writeState (ESM::InventoryState& state) const
|
||||
void MWWorld::ContainerStore::writeState (ESM::InventoryState& state)
|
||||
{
|
||||
state.mItems.clear();
|
||||
|
||||
|
@ -688,7 +688,6 @@ void MWWorld::ContainerStore::readState (const ESM::InventoryState& state)
|
|||
case ESM::REC_REPA: getState (repairs, iter->first); break;
|
||||
case ESM::REC_WEAP: setSlot (getState (weapons, iter->first), slot); break;
|
||||
case ESM::REC_LIGH: setSlot (getState (lights, iter->first), slot); break;
|
||||
|
||||
default:
|
||||
std::cerr << "invalid item type in inventory state, refid " << state.mRef.mRefID << std::endl;
|
||||
break;
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace MWWorld
|
|||
void storeState (const LiveCellRef<T>& ref, ESM::ObjectState& state) const;
|
||||
|
||||
template<typename T>
|
||||
void storeStates (const CellRefList<T>& collection,
|
||||
void storeStates (CellRefList<T>& collection,
|
||||
std::vector<std::pair<ESM::ObjectState, int> >& states,
|
||||
bool equipable = false) const;
|
||||
|
||||
|
@ -171,7 +171,8 @@ namespace MWWorld
|
|||
|
||||
Ptr search (const std::string& id);
|
||||
|
||||
virtual void writeState (ESM::InventoryState& state) const;
|
||||
/// \todo make this method const once const-correct ContainerStoreIterators are available
|
||||
virtual void writeState (ESM::InventoryState& state);
|
||||
|
||||
virtual void readState (const ESM::InventoryState& state);
|
||||
|
||||
|
|
|
@ -58,10 +58,24 @@ int MWWorld::InventoryStore::getSlot (const MWWorld::LiveCellRefBase& ref) const
|
|||
return -1;
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::setSlot (const MWWorld::ContainerStoreIterator& iter, int slot)
|
||||
void MWWorld::InventoryStore::setSlot (const MWWorld::ContainerStoreIterator& iter, int relativeSlot)
|
||||
{
|
||||
if (iter!=end() && slot>=0 && slot<Slots)
|
||||
mSlots[slot] = iter;
|
||||
if (relativeSlot < 0 || iter == end())
|
||||
return;
|
||||
|
||||
// make sure the item can actually be equipped in this slot
|
||||
std::pair<std::vector<int>, bool> allowedSlots = iter->getClass().getEquipmentSlots(*iter);
|
||||
relativeSlot = std::min(int(allowedSlots.first.size()-1), relativeSlot);
|
||||
|
||||
// unstack if required
|
||||
if (!allowedSlots.second && iter->getRefData().getCount() > 1)
|
||||
{
|
||||
MWWorld::ContainerStoreIterator newIter = addNewStack(*iter, 1);
|
||||
iter->getRefData().setCount(iter->getRefData().getCount()-1);
|
||||
mSlots[allowedSlots.first[relativeSlot]] = newIter;
|
||||
}
|
||||
else
|
||||
mSlots[allowedSlots.first[relativeSlot]] = iter;
|
||||
}
|
||||
|
||||
MWWorld::InventoryStore::InventoryStore()
|
||||
|
@ -703,7 +717,7 @@ bool MWWorld::InventoryStore::isEquipped(const MWWorld::Ptr &item)
|
|||
return false;
|
||||
}
|
||||
|
||||
void MWWorld::InventoryStore::writeState(ESM::InventoryState &state) const
|
||||
void MWWorld::InventoryStore::writeState(ESM::InventoryState &state)
|
||||
{
|
||||
MWWorld::ContainerStore::writeState(state);
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace MWWorld
|
|||
virtual int getSlot (const MWWorld::LiveCellRefBase& ref) const;
|
||||
///< Return inventory slot that \a ref is in or -1 (if \a ref is not in a slot).
|
||||
|
||||
virtual void setSlot (const MWWorld::ContainerStoreIterator& iter, int slot);
|
||||
virtual void setSlot (const MWWorld::ContainerStoreIterator& iter, int relativeSlot);
|
||||
///< Set slot for \a iter. Ignored if \a iter is an end iterator or if slot==-1.
|
||||
|
||||
public:
|
||||
|
@ -209,7 +209,7 @@ namespace MWWorld
|
|||
virtual void clear();
|
||||
///< Empty container.
|
||||
|
||||
virtual void writeState (ESM::InventoryState& state) const;
|
||||
virtual void writeState (ESM::InventoryState& state);
|
||||
|
||||
virtual void readState (const ESM::InventoryState& state);
|
||||
};
|
||||
|
|
|
@ -2031,7 +2031,7 @@ namespace MWWorld
|
|||
bool World::isOnGround(const MWWorld::Ptr &ptr) const
|
||||
{
|
||||
RefData &refdata = ptr.getRefData();
|
||||
const OEngine::Physic::PhysicActor *physactor = mPhysEngine->getCharacter(refdata.getHandle());
|
||||
OEngine::Physic::PhysicActor *physactor = mPhysEngine->getCharacter(refdata.getHandle());
|
||||
|
||||
if(!physactor)
|
||||
return false;
|
||||
|
@ -2049,7 +2049,7 @@ namespace MWWorld
|
|||
mPhysEngine);
|
||||
if(tracer.mFraction < 1.0f) // collision, must be close to something below
|
||||
{
|
||||
const_cast<OEngine::Physic::PhysicActor *> (physactor)->setOnGround(true);
|
||||
physactor->setOnGround(true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace ESM
|
|||
/// \brief State for inventories and containers
|
||||
struct InventoryState
|
||||
{
|
||||
/// <ObjectState, relative equipment slot>
|
||||
std::vector<std::pair<ObjectState, int> > mItems;
|
||||
|
||||
std::map<std::string, int> mLevelledItemMap;
|
||||
|
|
Loading…
Reference in a new issue