1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'threesacharm' into 'master'

Attempt to fix restocking items in old saves

Closes #5823

See merge request OpenMW/openmw!580
This commit is contained in:
psi29a 2021-03-08 10:45:13 +00:00
commit 611a63acc6

View File

@ -104,6 +104,45 @@ namespace
}
}
template<class RecordType, class T>
void fixRestockingImpl(const T* base, RecordType& state)
{
// Workaround for old saves not containing negative quantities
for(const auto& baseItem : base->mInventory.mList)
{
if(baseItem.mCount < 0)
{
for(auto& item : state.mInventory.mItems)
{
if(item.mCount > 0 && Misc::StringUtils::ciEqual(baseItem.mItem, item.mRef.mRefID))
item.mCount = -item.mCount;
}
}
}
}
template<class RecordType, class T>
void fixRestocking(const T* base, RecordType& state)
{}
template<>
void fixRestocking<>(const ESM::Creature* base, ESM::CreatureState& state)
{
fixRestockingImpl(base, state);
}
template<>
void fixRestocking<>(const ESM::NPC* base, ESM::NpcState& state)
{
fixRestockingImpl(base, state);
}
template<>
void fixRestocking<>(const ESM::Container* base, ESM::ContainerState& state)
{
fixRestockingImpl(base, state);
}
template<typename RecordType, typename T>
void readReferenceCollection (ESM::ESMReader& reader,
MWWorld::CellRefList<T>& collection, const ESM::CellRef& cref, const std::map<int, int>& contentFileMap, MWWorld::CellStore* cellstore)
@ -134,6 +173,9 @@ namespace
if (!record)
return;
if (state.mVersion < 15)
fixRestocking(record, state);
if (state.mRef.mRefNum.hasContentFile())
{
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());