Merge branch 'removeitem' into 'master'

Fix remove item regression

Closes #5663

See merge request OpenMW/openmw!380
pull/3024/head
psi29a 4 years ago
commit 74dfc09e2d

@ -246,7 +246,7 @@ namespace MWScript
auto& store = container.getClass().getContainerStore(container);
// Note that unlike AddItem, RemoveItem only removes from unresolved containers
if(!store.isResolved())
store.remove(item, count, ptr, false);
store.remove(item, count, ptr, false, false);
}
}
return;

@ -463,7 +463,7 @@ void MWWorld::ContainerStore::updateRechargingItems()
}
}
int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool resolveFirst)
int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst)
{
if(resolveFirst)
resolve();
@ -471,7 +471,7 @@ int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const
for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter)
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId))
toRemove -= removeImp(*iter, toRemove, actor);
toRemove -= remove(*iter, toRemove, actor, equipReplacement, resolveFirst);
flagAsModified();
@ -490,16 +490,12 @@ bool MWWorld::ContainerStore::hasVisibleItems() const
return false;
}
int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor)
int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst)
{
assert(this == item.getContainerStore());
resolve();
return removeImp(item, count, actor);
}
if(resolveFirst)
resolve();
int MWWorld::ContainerStore::removeImp(const Ptr& item, int count, const Ptr& actor)
{
int toRemove = count;
RefData& itemRef = item.getRefData();

@ -129,8 +129,6 @@ namespace MWWorld
void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true);
void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Seed* seed, bool topLevel=true);
int removeImp(const Ptr& item, int count, const Ptr& actor);
template<typename T>
ContainerStoreIterator getState (CellRefList<T>& collection,
const ESM::ObjectState& state);
@ -180,12 +178,12 @@ namespace MWWorld
ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr);
///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true)
int remove(const std::string& itemId, int count, const Ptr& actor, bool resolve = true);
int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true);
///< Remove \a count item(s) designated by \a itemId from this container.
///
/// @return the number of items actually removed
virtual int remove(const Ptr& item, int count, const Ptr& actor);
virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true);
///< Remove \a count item(s) designated by \a item from this inventory.
///
/// @return the number of items actually removed

@ -710,33 +710,9 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSelectedEnchantItem(
return mSelectedEnchantItem;
}
int MWWorld::InventoryStore::remove(const std::string& itemId, int count, const Ptr& actor)
int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement, bool resolve)
{
return remove(itemId, count, actor, false);
}
int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor)
{
return remove(item, count, actor, false);
}
int MWWorld::InventoryStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement)
{
int toRemove = count;
for (ContainerStoreIterator iter(begin()); iter != end() && toRemove > 0; ++iter)
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), itemId))
toRemove -= remove(*iter, toRemove, actor, equipReplacement);
flagAsModified();
// number of removed items
return count - toRemove;
}
int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement)
{
int retCount = ContainerStore::remove(item, count, actor);
int retCount = ContainerStore::remove(item, count, actor, equipReplacement, resolve);
bool wasEquipped = false;
if (!item.getRefData().getCount())

@ -165,11 +165,8 @@ namespace MWWorld
bool stacks (const ConstPtr& ptr1, const ConstPtr& ptr2) const override;
///< @return true if the two specified objects can stack with each other
virtual int remove(const std::string& itemId, int count, const Ptr& actor);
virtual int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement);
int remove(const Ptr& item, int count, const Ptr& actor) override;
virtual int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement);
using ContainerStore::remove;
int remove(const Ptr& item, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true) override;
///< Remove \a count item(s) designated by \a item from this inventory.
///
/// @return the number of items actually removed

Loading…
Cancel
Save