forked from teamnwah/openmw-tes3coop
Bound items: store item ID instead of pointer
This commit is contained in:
parent
4de9d9fa77
commit
f977c6876f
2 changed files with 19 additions and 11 deletions
|
@ -262,7 +262,7 @@ namespace MWMechanics
|
||||||
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
|
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
|
||||||
|
|
||||||
if (prevItem != store.end())
|
if (prevItem != store.end())
|
||||||
mPreviousItems[itemId] = *prevItem;
|
mPreviousItems[itemId] = (*prevItem).getCellRef().getRefId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Actors::removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor)
|
void Actors::removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor)
|
||||||
|
@ -279,26 +279,34 @@ namespace MWMechanics
|
||||||
if (actor != MWMechanics::getPlayer())
|
if (actor != MWMechanics::getPlayer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MWWorld::Ptr prevItem = mPreviousItems[itemId];
|
std::string prevItemId = mPreviousItems[itemId];
|
||||||
|
|
||||||
mPreviousItems.erase(itemId);
|
mPreviousItems.erase(itemId);
|
||||||
|
|
||||||
if (prevItem.isEmpty())
|
if (prevItemId.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check if the item is still in the player's inventory
|
// Find the item by id
|
||||||
MWWorld::ContainerStoreIterator it = store.begin();
|
MWWorld::Ptr item;
|
||||||
for (; it != store.end(); ++it)
|
for (MWWorld::ContainerStoreIterator iter = store.begin(); iter != store.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (*it == prevItem)
|
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), prevItemId))
|
||||||
break;
|
{
|
||||||
|
if (item.isEmpty() ||
|
||||||
|
// Prefer the stack with the lowest remaining uses
|
||||||
|
!item.getClass().hasItemHealth(*iter) ||
|
||||||
|
iter->getClass().getItemHealth(*iter) < item.getClass().getItemHealth(item))
|
||||||
|
{
|
||||||
|
item = *iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we should equip previous item only if expired bound item was equipped.
|
// we should equip previous item only if expired bound item was equipped.
|
||||||
if (it == store.end() || !wasEquipped)
|
if (item.isEmpty() || !wasEquipped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MWWorld::ActionEquip action(prevItem);
|
MWWorld::ActionEquip action(item);
|
||||||
action.execute(actor);
|
action.execute(actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace MWMechanics
|
||||||
class Actors
|
class Actors
|
||||||
{
|
{
|
||||||
std::map<std::string, int> mDeathCount;
|
std::map<std::string, int> mDeathCount;
|
||||||
typedef std::map<std::string, MWWorld::Ptr> PreviousItems;
|
typedef std::map<std::string, std::string> PreviousItems;
|
||||||
PreviousItems mPreviousItems;
|
PreviousItems mPreviousItems;
|
||||||
|
|
||||||
void addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
void addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor);
|
||||||
|
|
Loading…
Reference in a new issue