1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-07 03:40:15 +00:00

Unset RefNums after copying containers (otherwise copies will have the same RefNums, but they should be unique)

This commit is contained in:
Petr Mikheev 2023-01-17 03:04:34 +01:00
parent 5983f22290
commit e7120f189b
3 changed files with 22 additions and 2 deletions

View File

@ -192,6 +192,12 @@ int MWWorld::ContainerStore::count(const ESM::RefId& id) const
return total;
}
void MWWorld::ContainerStore::clearRefNums()
{
for (const auto& iter : *this)
iter.getCellRef().unsetRefNum();
}
MWWorld::ContainerStoreListener* MWWorld::ContainerStore::getContListener() const
{
return mListener;

View File

@ -102,6 +102,10 @@ namespace MWWorld
protected:
ContainerStoreListener* mListener;
// Used in clone() to unset refnums of copies.
// (RefNum should be unique, copy can not have the same RefNum).
void clearRefNums();
// (item, max charge)
typedef std::vector<std::pair<ContainerStoreIterator, float>> TRechargingItems;
TRechargingItems mRechargingItems;
@ -165,7 +169,12 @@ namespace MWWorld
virtual ~ContainerStore();
virtual std::unique_ptr<ContainerStore> clone() { return std::make_unique<ContainerStore>(*this); }
virtual std::unique_ptr<ContainerStore> clone()
{
auto res = std::make_unique<ContainerStore>(*this);
res->clearRefNums();
return res;
}
ConstContainerStoreIterator cbegin(int mask = Type_All) const;
ConstContainerStoreIterator cend() const;

View File

@ -97,7 +97,12 @@ namespace MWWorld
const MWWorld::Ptr& getActor() const { return mActor; }
void setActor(const MWWorld::Ptr& actor) { mActor = actor; }
std::unique_ptr<ContainerStore> clone() override { return std::make_unique<InventoryStore>(*this); }
std::unique_ptr<ContainerStore> clone() override
{
auto res = std::make_unique<InventoryStore>(*this);
res->clearRefNums();
return res;
}
ContainerStoreIterator add(
const Ptr& itemPtr, int count, bool allowAutoEquip = true, bool resolve = true) override;