forked from mirror/openmw-tes3mp
fixed some issues
This commit is contained in:
parent
ee7e482cba
commit
d341d2113c
4 changed files with 32 additions and 6 deletions
|
@ -49,7 +49,7 @@ 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
|
||||
&& MWWorld::Class::get(ptr1).getScript(ptr1) == "" // item with a script never stacks
|
||||
&& ptr1.mCellRef->owner == ptr2.mCellRef->owner
|
||||
&& ptr1.mCellRef->soul == ptr2.mCellRef->soul
|
||||
&& ptr1.mCellRef->charge == ptr2.mCellRef->charge)
|
||||
|
|
|
@ -66,9 +66,6 @@ namespace MWWorld
|
|||
|
||||
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);
|
||||
///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed)
|
||||
///
|
||||
|
@ -81,6 +78,10 @@ namespace MWWorld
|
|||
void addImpl (const Ptr& ptr);
|
||||
///< Add the item to this container (no stacking)
|
||||
|
||||
virtual bool stacks (const Ptr& ptr1, const Ptr& ptr2) const;
|
||||
///< @return true if the two specified objects can stack with each other
|
||||
/// @note ptr1 is the item that is already in this container
|
||||
|
||||
public:
|
||||
|
||||
void fill (const ESM::InventoryList& items, const ESMS::ESMStore& store);
|
||||
|
|
|
@ -59,9 +59,10 @@ 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");
|
||||
|
@ -82,7 +83,7 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
|
|||
}
|
||||
|
||||
// unstack item pointed to by iterator if required
|
||||
if (iterator->getRefData().getCount() > 1)
|
||||
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();
|
||||
|
@ -199,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;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,13 @@ namespace MWWorld
|
|||
|
||||
void autoEquip (const MWMechanics::NpcStats& stats);
|
||||
///< Auto equip items according to stats and item value.
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool stacks (const Ptr& ptr1, const Ptr& ptr2) const;
|
||||
///< @return true if the two specified objects can stack with each other
|
||||
/// @note ptr1 is the item that is already in this container
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue