mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 18:59:57 +00:00
Fix stats not working right for saves started before version 17
This commit is contained in:
parent
72e76ad820
commit
649c2f8286
6 changed files with 23 additions and 5 deletions
|
@ -21,13 +21,13 @@ namespace MWMechanics
|
|||
void Stat<T>::writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier + mBase;
|
||||
state.mMod = mModifier;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModifier = state.mMod - mBase;
|
||||
mModifier = state.mMod;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -185,6 +185,11 @@ namespace
|
|||
else if constexpr (std::is_same_v<T, ESM::NPC>)
|
||||
MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory, &state.mNpcStats);
|
||||
}
|
||||
else if(state.mVersion < 20)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, ESM::Creature> || std::is_same_v<T, ESM::NPC>)
|
||||
MWWorld::convertStats(state.mCreatureStats);
|
||||
}
|
||||
|
||||
if (state.mRef.mRefNum.hasContentFile())
|
||||
{
|
||||
|
|
|
@ -201,14 +201,23 @@ namespace MWWorld
|
|||
{
|
||||
auto& dynamic = creatureStats.mDynamic[i];
|
||||
dynamic.mCurrent -= dynamic.mMod - dynamic.mBase;
|
||||
dynamic.mMod = dynamic.mBase;
|
||||
dynamic.mMod = 0.f;
|
||||
}
|
||||
for(std::size_t i = 0; i < 4; ++i)
|
||||
creatureStats.mAiSettings[i].mMod = creatureStats.mAiSettings[i].mBase;
|
||||
creatureStats.mAiSettings[i].mMod = 0.f;
|
||||
if(npcStats)
|
||||
{
|
||||
for(std::size_t i = 0; i < ESM::Skill::Length; ++i)
|
||||
npcStats->mSkills[i].mMod = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
// Versions 17-19 wrote different modifiers to the savegame depending on whether the save had upgraded from a pre-17 version or not
|
||||
void convertStats(ESM::CreatureStats& creatureStats)
|
||||
{
|
||||
for(std::size_t i = 0; i < 3; ++i)
|
||||
creatureStats.mDynamic[i].mMod = 0.f;
|
||||
for(std::size_t i = 0; i < 4; ++i)
|
||||
creatureStats.mAiSettings[i].mMod = 0.f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace MWWorld
|
|||
{
|
||||
void convertMagicEffects(ESM::CreatureStats& creatureStats, ESM::InventoryState& inventory,
|
||||
ESM::NpcStats* npcStats = nullptr);
|
||||
|
||||
void convertStats(ESM::CreatureStats& creatureStats);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -383,6 +383,8 @@ namespace MWWorld
|
|||
}
|
||||
if (reader.getFormat() < 17)
|
||||
convertMagicEffects(player.mObject.mCreatureStats, player.mObject.mInventory, &player.mObject.mNpcStats);
|
||||
else if(reader.getFormat() < 20)
|
||||
convertStats(player.mObject.mCreatureStats);
|
||||
|
||||
if (!player.mObject.mEnabled)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "esmwriter.hpp"
|
||||
|
||||
unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE;
|
||||
int ESM::SavedGame::sCurrentFormat = 19;
|
||||
int ESM::SavedGame::sCurrentFormat = 20;
|
||||
|
||||
void ESM::SavedGame::load (ESMReader &esm)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue