Store magic effect Base values in savegame (Fixes #1489)

This commit is contained in:
scrawl 2014-08-17 04:58:58 +02:00
parent 2db50da8dd
commit 360c7f863c
8 changed files with 99 additions and 1 deletions

View file

@ -516,6 +516,7 @@ namespace MWMechanics
mSpells.writeState(state.mSpells);
mActiveSpells.writeState(state.mActiveSpells);
mAiSequence.writeState(state.mAiSequence);
mMagicEffects.writeState(state.mMagicEffects);
state.mSummonedCreatureMap = mSummonedCreatures;
state.mSummonGraveyard = mSummonGraveyard;
@ -564,6 +565,7 @@ namespace MWMechanics
mSpells.readState(state.mSpells);
mActiveSpells.readState(state.mActiveSpells);
mAiSequence.readState(state.mAiSequence);
mMagicEffects.readState(state.mMagicEffects);
mSummonedCreatures = state.mSummonedCreatureMap;
mSummonGraveyard = state.mSummonGraveyard;

View file

@ -6,6 +6,7 @@
#include <stdexcept>
#include <components/esm/effectlist.hpp>
#include <components/esm/magiceffects.hpp>
namespace MWMechanics
{
@ -50,6 +51,16 @@ namespace MWMechanics
mBase += diff;
}
int EffectParam::getBase() const
{
return mBase;
}
void EffectParam::setBase(int base)
{
mBase = base;
}
void EffectParam::setModifier(float mod)
{
mModifier = mod;
@ -182,4 +193,25 @@ namespace MWMechanics
return result;
}
void MagicEffects::writeState(ESM::MagicEffects &state) const
{
// Don't need to save Modifiers, they are recalculated every frame anyway.
for (Collection::const_iterator iter (begin()); iter!=end(); ++iter)
{
if (iter->second.getBase() != 0)
{
// Don't worry about mArg, never used by magic effect script instructions
state.mEffects.insert(std::make_pair(iter->first.mId, iter->second.getBase()));
}
}
}
void MagicEffects::readState(const ESM::MagicEffects &state)
{
for (std::map<int, int>::const_iterator it = state.mEffects.begin(); it != state.mEffects.end(); ++it)
{
mCollection[EffectKey(it->first)].setBase(it->second);
}
}
}

View file

@ -8,6 +8,8 @@ namespace ESM
{
struct ENAMstruct;
struct EffectList;
struct MagicEffects;
}
namespace MWMechanics
@ -43,6 +45,8 @@ namespace MWMechanics
/// Change mBase by \a diff
void modifyBase(int diff);
void setBase(int base);
int getBase() const;
EffectParam();
@ -90,6 +94,9 @@ namespace MWMechanics
Collection::const_iterator end() const { return mCollection.end(); }
void readState (const ESM::MagicEffects& state);
void writeState (ESM::MagicEffects& state) const;
void add (const EffectKey& key, const EffectParam& param);
void remove (const EffectKey& key);

View file

@ -42,7 +42,7 @@ add_component_dir (esm
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
savedgame journalentry queststate locals globalscript player objectstate cellid cellstate globalmap lightstate inventorystate containerstate npcstate creaturestate dialoguestate statstate
npcstats creaturestats weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate
aisequence
aisequence magiceffects
)
add_component_dir (esmterrain

View file

@ -86,6 +86,7 @@ void ESM::CreatureStats::load (ESMReader &esm)
mSpells.load(esm);
mActiveSpells.load(esm);
mAiSequence.load(esm);
mMagicEffects.load(esm);
while (esm.isNextSub("SUMM"))
{
@ -196,6 +197,7 @@ void ESM::CreatureStats::save (ESMWriter &esm) const
mSpells.save(esm);
mActiveSpells.save(esm);
mAiSequence.save(esm);
mMagicEffects.save(esm);
for (std::map<int, int>::const_iterator it = mSummonedCreatureMap.begin(); it != mSummonedCreatureMap.end(); ++it)
{

View file

@ -11,6 +11,7 @@
#include "spellstate.hpp"
#include "activespells.hpp"
#include "magiceffects.hpp"
#include "aisequence.hpp"
namespace ESM
@ -24,6 +25,8 @@ namespace ESM
StatState<int> mAttributes[8];
StatState<float> mDynamic[3];
MagicEffects mMagicEffects;
AiSequence::AiSequence mAiSequence;
bool mHasAiSettings;

View file

@ -0,0 +1,29 @@
#include "magiceffects.hpp"
#include "esmwriter.hpp"
#include "esmreader.hpp"
namespace ESM
{
void MagicEffects::save(ESMWriter &esm) const
{
for (std::map<int, int>::const_iterator it = mEffects.begin(); it != mEffects.end(); ++it)
{
esm.writeHNT("EFID", it->first);
esm.writeHNT("BASE", it->second);
}
}
void MagicEffects::load(ESMReader &esm)
{
while (esm.isNextSub("EFID"))
{
int id, base;
esm.getHT(id);
esm.getHNT(base, "BASE");
mEffects.insert(std::make_pair(id, base));
}
}
}

View file

@ -0,0 +1,23 @@
#ifndef COMPONENTS_ESM_MAGICEFFECTS_H
#define COMPONENTS_ESM_MAGICEFFECTS_H
#include <map>
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
struct MagicEffects
{
// <Effect Id, Base value>
std::map<int, int> mEffects;
void load (ESMReader &esm);
void save (ESMWriter &esm) const;
};
}
#endif