1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 04:20:29 +00:00

Fix stats not working right for saves started before version 17

This commit is contained in:
Evil Eye 2022-02-14 18:38:37 +01:00
parent 72e76ad820
commit 649c2f8286
6 changed files with 23 additions and 5 deletions

View File

@ -21,13 +21,13 @@ namespace MWMechanics
void Stat<T>::writeState (ESM::StatState<T>& state) const void Stat<T>::writeState (ESM::StatState<T>& state) const
{ {
state.mBase = mBase; state.mBase = mBase;
state.mMod = mModifier + mBase; state.mMod = mModifier;
} }
template<typename T> template<typename T>
void Stat<T>::readState (const ESM::StatState<T>& state) void Stat<T>::readState (const ESM::StatState<T>& state)
{ {
mBase = state.mBase; mBase = state.mBase;
mModifier = state.mMod - mBase; mModifier = state.mMod;
} }

View File

@ -185,6 +185,11 @@ namespace
else if constexpr (std::is_same_v<T, ESM::NPC>) else if constexpr (std::is_same_v<T, ESM::NPC>)
MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory, &state.mNpcStats); 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()) if (state.mRef.mRefNum.hasContentFile())
{ {

View File

@ -201,14 +201,23 @@ namespace MWWorld
{ {
auto& dynamic = creatureStats.mDynamic[i]; auto& dynamic = creatureStats.mDynamic[i];
dynamic.mCurrent -= dynamic.mMod - dynamic.mBase; dynamic.mCurrent -= dynamic.mMod - dynamic.mBase;
dynamic.mMod = dynamic.mBase; dynamic.mMod = 0.f;
} }
for(std::size_t i = 0; i < 4; ++i) 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) if(npcStats)
{ {
for(std::size_t i = 0; i < ESM::Skill::Length; ++i) for(std::size_t i = 0; i < ESM::Skill::Length; ++i)
npcStats->mSkills[i].mMod = 0.f; 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;
}
} }

View File

@ -12,6 +12,8 @@ namespace MWWorld
{ {
void convertMagicEffects(ESM::CreatureStats& creatureStats, ESM::InventoryState& inventory, void convertMagicEffects(ESM::CreatureStats& creatureStats, ESM::InventoryState& inventory,
ESM::NpcStats* npcStats = nullptr); ESM::NpcStats* npcStats = nullptr);
void convertStats(ESM::CreatureStats& creatureStats);
} }
#endif #endif

View File

@ -383,6 +383,8 @@ namespace MWWorld
} }
if (reader.getFormat() < 17) if (reader.getFormat() < 17)
convertMagicEffects(player.mObject.mCreatureStats, player.mObject.mInventory, &player.mObject.mNpcStats); convertMagicEffects(player.mObject.mCreatureStats, player.mObject.mInventory, &player.mObject.mNpcStats);
else if(reader.getFormat() < 20)
convertStats(player.mObject.mCreatureStats);
if (!player.mObject.mEnabled) if (!player.mObject.mEnabled)
{ {

View File

@ -4,7 +4,7 @@
#include "esmwriter.hpp" #include "esmwriter.hpp"
unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE; unsigned int ESM::SavedGame::sRecordId = ESM::REC_SAVE;
int ESM::SavedGame::sCurrentFormat = 19; int ESM::SavedGame::sCurrentFormat = 20;
void ESM::SavedGame::load (ESMReader &esm) void ESM::SavedGame::load (ESMReader &esm)
{ {