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

deque
scrawl 11 years ago
parent 2db50da8dd
commit 360c7f863c

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

@ -6,6 +6,7 @@
#include <stdexcept> #include <stdexcept>
#include <components/esm/effectlist.hpp> #include <components/esm/effectlist.hpp>
#include <components/esm/magiceffects.hpp>
namespace MWMechanics namespace MWMechanics
{ {
@ -50,6 +51,16 @@ namespace MWMechanics
mBase += diff; mBase += diff;
} }
int EffectParam::getBase() const
{
return mBase;
}
void EffectParam::setBase(int base)
{
mBase = base;
}
void EffectParam::setModifier(float mod) void EffectParam::setModifier(float mod)
{ {
mModifier = mod; mModifier = mod;
@ -182,4 +193,25 @@ namespace MWMechanics
return result; 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);
}
}
} }

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

@ -42,7 +42,7 @@ add_component_dir (esm
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter 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 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 npcstats creaturestats weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate
aisequence aisequence magiceffects
) )
add_component_dir (esmterrain add_component_dir (esmterrain

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

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

@ -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));
}
}
}

@ -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
Loading…
Cancel
Save