mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +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>
|
||||
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());
|
||||
|
|
Loading…
Reference in a new issue