forked from teamnwah/openmw-tes3coop
Savegame: store ActiveSpells
parent
1141c1f3f2
commit
9052cc4a57
@ -0,0 +1,56 @@
|
|||||||
|
#include "activespells.hpp"
|
||||||
|
|
||||||
|
#include "esmreader.hpp"
|
||||||
|
#include "esmwriter.hpp"
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
|
||||||
|
void ActiveSpells::save(ESMWriter &esm) const
|
||||||
|
{
|
||||||
|
for (TContainer::const_iterator it = mSpells.begin(); it != mSpells.end(); ++it)
|
||||||
|
{
|
||||||
|
esm.writeHNString ("ID__", it->first);
|
||||||
|
|
||||||
|
const ActiveSpellParams& params = it->second;
|
||||||
|
|
||||||
|
esm.writeHNT ("CAST", params.mCasterActorId);
|
||||||
|
esm.writeHNString ("DISP", params.mDisplayName);
|
||||||
|
esm.writeHNT ("TIME", params.mTimeStamp);
|
||||||
|
|
||||||
|
for (std::vector<ActiveEffect>::const_iterator effectIt = params.mEffects.begin(); effectIt != params.mEffects.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
esm.writeHNT ("MGEF", effectIt->mEffectId);
|
||||||
|
if (effectIt->mArg != -1)
|
||||||
|
esm.writeHNT ("ARG_", effectIt->mArg);
|
||||||
|
esm.writeHNT ("MAGN", effectIt->mMagnitude);
|
||||||
|
esm.writeHNT ("DURA", effectIt->mDuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActiveSpells::load(ESMReader &esm)
|
||||||
|
{
|
||||||
|
while (esm.isNextSub("ID__"))
|
||||||
|
{
|
||||||
|
std::string spellId = esm.getHString();
|
||||||
|
|
||||||
|
ActiveSpellParams params;
|
||||||
|
esm.getHNT (params.mCasterActorId, "CAST");
|
||||||
|
params.mDisplayName = esm.getHNString ("DISP");
|
||||||
|
esm.getHNT (params.mTimeStamp, "TIME");
|
||||||
|
|
||||||
|
while (esm.isNextSub("MGEF"))
|
||||||
|
{
|
||||||
|
ActiveEffect effect;
|
||||||
|
esm.getHT(effect.mEffectId);
|
||||||
|
effect.mArg = -1;
|
||||||
|
esm.getHNOT(effect.mArg, "ARG_");
|
||||||
|
esm.getHNT (effect.mMagnitude, "MAGN");
|
||||||
|
esm.getHNT (effect.mDuration, "DURA");
|
||||||
|
params.mEffects.push_back(effect);
|
||||||
|
}
|
||||||
|
mSpells.insert(std::make_pair(spellId, params));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef OPENMW_ESM_ACTIVESPELLS_H
|
||||||
|
#define OPENMW_ESM_ACTIVESPELLS_H
|
||||||
|
|
||||||
|
#include "effectlist.hpp"
|
||||||
|
#include "defs.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class ESMReader;
|
||||||
|
class ESMWriter;
|
||||||
|
|
||||||
|
// Parameters of an effect concerning lasting effects.
|
||||||
|
// Note we are not using ENAMstruct since the magnitude may be modified by magic resistance, etc.
|
||||||
|
// It could also be a negative magnitude, in case of inversing an effect, e.g. Absorb spell causes damage on target, but heals the caster.
|
||||||
|
struct ActiveEffect
|
||||||
|
{
|
||||||
|
int mEffectId;
|
||||||
|
float mMagnitude;
|
||||||
|
int mArg; // skill or attribute
|
||||||
|
float mDuration;
|
||||||
|
};
|
||||||
|
|
||||||
|
// format 0, saved games only
|
||||||
|
struct ActiveSpells
|
||||||
|
{
|
||||||
|
struct ActiveSpellParams
|
||||||
|
{
|
||||||
|
std::vector<ActiveEffect> mEffects;
|
||||||
|
ESM::TimeStamp mTimeStamp;
|
||||||
|
std::string mDisplayName;
|
||||||
|
int mCasterActorId;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::multimap<std::string, ActiveSpellParams > TContainer;
|
||||||
|
TContainer mSpells;
|
||||||
|
|
||||||
|
void load (ESMReader &esm);
|
||||||
|
void save (ESMWriter &esm) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue