Edit InventoryStore::equip() to call the new unequipSlot function…

…to unequip previously equipped item.
actorid
Emanuel Guevel 12 years ago
parent 52cef19982
commit 2786530430

@ -384,7 +384,7 @@ namespace MWGui
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
if (it != invStore.end() && *it == item)
{
invStore.equip(slot, invStore.end());
invStore.equip(slot, invStore.end(), mPtr);
std::string script = MWWorld::Class::get(*it).getScript(*it);
// Unset OnPCEquip Variable on item's script, if it has a script with that variable declared

@ -159,7 +159,7 @@ namespace MWMechanics
// auto-equip again. we need this for when the race is changed to a beast race
MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
for (int i=0; i<MWWorld::InventoryStore::Slots; ++i)
invStore.equip(i, invStore.end());
invStore.equip(i, invStore.end(), ptr);
invStore.autoEquip(ptr);
}

@ -32,10 +32,10 @@ namespace MWWorld
case 0:
return;
case 2:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedLeft, actor);
break;
case 3:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, actor);
break;
}
@ -64,7 +64,7 @@ namespace MWWorld
// if all slots are occupied, replace the last slot
if (slot == --slots.first.end())
{
invStore.equip(*slot, it);
invStore.equip(*slot, it, actor);
equipped = true;
break;
}
@ -72,7 +72,7 @@ namespace MWWorld
if (invStore.getSlot(*slot) == invStore.end())
{
// slot is not occupied
invStore.equip(*slot, it);
invStore.equip(*slot, it, actor);
equipped = true;
break;
}

@ -81,7 +81,7 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
return retVal;
}
void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator)
void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor)
{
if (slot<0 || slot>=static_cast<int> (mSlots.size()))
throw std::runtime_error ("slot number out of range");
@ -98,19 +98,8 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite
throw std::runtime_error ("invalid slot");
}
// 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;
}
}
}
unequipSlot(slot, actor);
// 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
@ -214,10 +203,10 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& npc)
case 0:
continue;
case 2:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, invStore.end());
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedLeft, npc);
break;
case 3:
invStore.equip(MWWorld::InventoryStore::Slot_CarriedRight, invStore.end());
invStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, npc);
break;
}
@ -325,7 +314,7 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
if (*mSlots[slot] == item)
{
unequipSlot(slot, actorPtr);
unequipSlot(slot, actor);
break;
}
}
@ -338,7 +327,19 @@ void MWWorld::InventoryStore::unequipSlot(int slot, const MWWorld::Ptr& actor)
ContainerStoreIterator it = getSlot(slot);
if (it != end())
{
equip(slot, end());
// restack item previously in this slot
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;
}
}
// empty this slot
mSlots[slot] = end();
if (actor.getRefData().getHandle() == "player")
{

@ -76,7 +76,7 @@ namespace MWWorld
///
/// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item.
void equip (int slot, const ContainerStoreIterator& iterator);
void equip (int slot, const ContainerStoreIterator& iterator, const Ptr& actor);
///< \note \a iterator can be an end-iterator
void setSelectedEnchantItem(const ContainerStoreIterator& iterator);

@ -1960,7 +1960,7 @@ namespace MWWorld
// Not sure this is right
InventoryStore &inv = Class::get(actor).getInventoryStore(actor);
inv.equip(InventoryStore::Slot_Robe, inv.add(ref.getPtr(), actor));
inv.equip(InventoryStore::Slot_Robe, inv.add(ref.getPtr(), actor), actor);
}
else
{

Loading…
Cancel
Save