1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 19:15:41 +00:00
openmw/components/esm3/activespells.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
4.3 KiB
C++
Raw Normal View History

2014-05-14 20:16:39 +00:00
#include "activespells.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
namespace
2014-05-14 20:16:39 +00:00
{
void saveImpl(ESMWriter& esm, const std::vector<ActiveSpells::ActiveSpellParams>& spells, NAME tag)
2014-05-14 20:16:39 +00:00
{
for (const auto& params : spells)
{
esm.writeHNString(tag, params.mId);
2014-05-14 20:16:39 +00:00
esm.writeHNT("CAST", params.mCasterActorId);
esm.writeHNString("DISP", params.mDisplayName);
esm.writeHNT("TYPE", params.mType);
if (params.mItem.isSet())
params.mItem.save(esm, true, "ITEM");
if (params.mWorsenings >= 0)
2022-09-22 18:26:05 +00:00
{
esm.writeHNT("WORS", params.mWorsenings);
esm.writeHNT("TIME", params.mNextWorsening);
2022-09-22 18:26:05 +00:00
}
2022-08-15 07:52:09 +00:00
for (auto& effect : params.mEffects)
2014-05-14 20:16:39 +00:00
{
esm.writeHNT("MGEF", effect.mEffectId);
if (effect.mArg != -1)
esm.writeHNT("ARG_", effect.mArg);
esm.writeHNT("MAGN", effect.mMagnitude);
esm.writeHNT("MAGN", effect.mMinMagnitude);
esm.writeHNT("MAGN", effect.mMaxMagnitude);
esm.writeHNT("DURA", effect.mDuration);
esm.writeHNT("EIND", effect.mEffectIndex);
esm.writeHNT("LEFT", effect.mTimeLeft);
esm.writeHNT("FLAG", effect.mFlags);
2022-09-22 18:26:05 +00:00
}
2014-05-14 20:16:39 +00:00
}
}
void loadImpl(ESMReader& esm, std::vector<ActiveSpells::ActiveSpellParams>& spells, NAME tag)
2014-05-14 20:16:39 +00:00
{
int format = esm.getFormat();
2014-05-14 20:16:39 +00:00
while (esm.isNextSub(tag))
{
ActiveSpells::ActiveSpellParams params;
2014-05-14 20:16:39 +00:00
params.mId = esm.getHString();
esm.getHNT(params.mCasterActorId, "CAST");
params.mDisplayName = esm.getHNString("DISP");
params.mItem.unset();
if (format < 17)
params.mType = ActiveSpells::Type_Temporary;
2022-09-22 18:26:05 +00:00
else
{
esm.getHNT(params.mType, "TYPE");
if (esm.peekNextSub("ITEM"))
params.mItem.load(esm, true, "ITEM");
}
if (esm.isNextSub("WORS"))
{
esm.getHT(params.mWorsenings);
esm.getHNT(params.mNextWorsening, "TIME");
}
else
params.mWorsenings = -1;
2022-09-22 18:26:05 +00:00
// spell casting timestamp, no longer used
if (esm.isNextSub("TIME"))
esm.skipHSub();
2022-09-22 18:26:05 +00:00
while (esm.isNextSub("MGEF"))
2022-09-22 18:26:05 +00:00
{
ActiveEffect effect;
esm.getHT(effect.mEffectId);
2014-05-14 20:16:39 +00:00
effect.mArg = -1;
esm.getHNOT(effect.mArg, "ARG_");
esm.getHNT(effect.mMagnitude, "MAGN");
if (format < 17)
2022-09-22 18:26:05 +00:00
{
effect.mMinMagnitude = effect.mMagnitude;
effect.mMaxMagnitude = effect.mMagnitude;
2022-09-22 18:26:05 +00:00
}
else
{
esm.getHNT(effect.mMinMagnitude, "MAGN");
esm.getHNT(effect.mMaxMagnitude, "MAGN");
2022-09-22 18:26:05 +00:00
}
2014-05-14 20:16:39 +00:00
esm.getHNT(effect.mDuration, "DURA");
effect.mEffectIndex = -1;
esm.getHNOT(effect.mEffectIndex, "EIND");
if (format < 9)
effect.mTimeLeft = effect.mDuration;
2022-09-22 18:26:05 +00:00
else
esm.getHNT(effect.mTimeLeft, "LEFT");
if (format < 17)
effect.mFlags = ActiveEffect::Flag_None;
else
esm.getHNT(effect.mFlags, "FLAG");
2014-05-14 20:16:39 +00:00
params.mEffects.push_back(effect);
2022-09-22 18:26:05 +00:00
}
spells.emplace_back(params);
2014-05-14 20:16:39 +00:00
}
}
}
}
namespace ESM
{
void ActiveSpells::save(ESMWriter& esm) const
{
saveImpl(esm, mSpells, "ID__");
saveImpl(esm, mQueue, "QID_");
}
void ActiveSpells::load(ESMReader& esm)
{
loadImpl(esm, mSpells, "ID__");
loadImpl(esm, mQueue, "QID_");
}
}