Cycle with equipped items if all slots are occupied (Fixes #1395)

deque
scrawl 11 years ago
parent 00775035af
commit c0f1449004

@ -41,6 +41,8 @@ namespace MWWorld
// slots that this item can be equipped in // slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots_ = getTarget().getClass().getEquipmentSlots(getTarget()); std::pair<std::vector<int>, bool> slots_ = getTarget().getClass().getEquipmentSlots(getTarget());
if (slots_.first.empty())
return;
// retrieve ContainerStoreIterator to the item // retrieve ContainerStoreIterator to the item
MWWorld::ContainerStoreIterator it = invStore.begin(); MWWorld::ContainerStoreIterator it = invStore.begin();
@ -55,25 +57,32 @@ namespace MWWorld
assert(it != invStore.end()); assert(it != invStore.end());
// equip the item in the first free slot // equip the item in the first free slot
for (std::vector<int>::const_iterator slot=slots_.first.begin(); std::vector<int>::const_iterator slot=slots_.first.begin();
slot!=slots_.first.end(); ++slot) for (;slot!=slots_.first.end(); ++slot)
{ {
// if the item is equipped already, nothing to do // if the item is equipped already, nothing to do
if (invStore.getSlot(*slot) == it) if (invStore.getSlot(*slot) == it)
return; return;
// if all slots are occupied, replace the last slot if (invStore.getSlot(*slot) == invStore.end())
if (slot == --slots_.first.end())
{ {
// slot is not occupied
invStore.equip(*slot, it, actor); invStore.equip(*slot, it, actor);
break; break;
} }
}
if (invStore.getSlot(*slot) == invStore.end()) // all slots are occupied -> cycle
// move all slots one towards begin(), then equip the item in the slot that is now free
if (slot == slots_.first.end())
{
for (slot=slots_.first.begin();slot!=slots_.first.end(); ++slot)
{ {
// slot is not occupied invStore.unequipSlot(*slot, actor);
invStore.equip(*slot, it, actor); if (slot+1 != slots_.first.end())
break; invStore.equip(*slot, invStore.getSlot(*(slot+1)), actor);
else
invStore.equip(*slot, it, actor);
} }
} }
} }

Loading…
Cancel
Save