1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 10:23:52 +00:00

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

…to unequip previously equipped item.
This commit is contained in:
Emanuel Guevel 2013-08-13 02:06:46 +02:00
parent 52cef19982
commit 2786530430
6 changed files with 26 additions and 25 deletions

View file

@ -384,7 +384,7 @@ namespace MWGui
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
if (it != invStore.end() && *it == item) 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); 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 // Unset OnPCEquip Variable on item's script, if it has a script with that variable declared

View file

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

View file

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

View file

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

View file

@ -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. /// @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 ///< \note \a iterator can be an end-iterator
void setSelectedEnchantItem(const ContainerStoreIterator& iterator); void setSelectedEnchantItem(const ContainerStoreIterator& iterator);

View file

@ -1960,7 +1960,7 @@ namespace MWWorld
// Not sure this is right // Not sure this is right
InventoryStore &inv = Class::get(actor).getInventoryStore(actor); 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 else
{ {