mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 22:45:33 +00:00
Attempt to fix restocking items in old saves
This commit is contained in:
parent
d990c425b8
commit
8ae4ee291f
1 changed files with 42 additions and 0 deletions
|
@ -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>
|
template<typename RecordType, typename T>
|
||||||
void readReferenceCollection (ESM::ESMReader& reader,
|
void readReferenceCollection (ESM::ESMReader& reader,
|
||||||
MWWorld::CellRefList<T>& collection, const ESM::CellRef& cref, const std::map<int, int>& contentFileMap, MWWorld::CellStore* cellstore)
|
MWWorld::CellRefList<T>& collection, const ESM::CellRef& cref, const std::map<int, int>& contentFileMap, MWWorld::CellStore* cellstore)
|
||||||
|
@ -134,6 +173,9 @@ namespace
|
||||||
if (!record)
|
if (!record)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (state.mVersion < 15)
|
||||||
|
fixRestocking(record, state);
|
||||||
|
|
||||||
if (state.mRef.mRefNum.hasContentFile())
|
if (state.mRef.mRefNum.hasContentFile())
|
||||||
{
|
{
|
||||||
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
|
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
|
||||||
|
|
Loading…
Reference in a new issue