mirror of https://github.com/OpenMW/openmw.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.9 KiB
C++
114 lines
2.9 KiB
C++
11 years ago
|
#include "spellstate.hpp"
|
||
|
|
||
|
#include "esmreader.hpp"
|
||
|
#include "esmwriter.hpp"
|
||
|
|
||
|
namespace ESM
|
||
|
{
|
||
|
|
||
|
void SpellState::load(ESMReader &esm)
|
||
|
{
|
||
3 years ago
|
if(esm.getFormat() < 17)
|
||
11 years ago
|
{
|
||
3 years ago
|
while (esm.isNextSub("SPEL"))
|
||
11 years ago
|
{
|
||
3 years ago
|
std::string id = esm.getHString();
|
||
11 years ago
|
|
||
3 years ago
|
SpellParams state;
|
||
|
while (esm.isNextSub("INDX"))
|
||
|
{
|
||
|
int index;
|
||
|
esm.getHT(index);
|
||
11 years ago
|
|
||
3 years ago
|
float magnitude;
|
||
|
esm.getHNT(magnitude, "RAND");
|
||
11 years ago
|
|
||
3 years ago
|
state.mEffectRands[index] = magnitude;
|
||
|
}
|
||
9 years ago
|
|
||
3 years ago
|
while (esm.isNextSub("PURG")) {
|
||
|
int index;
|
||
|
esm.getHT(index);
|
||
|
state.mPurgedEffects.insert(index);
|
||
|
}
|
||
|
|
||
|
mSpellParams[id] = state;
|
||
|
mSpells.emplace_back(id);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
while (esm.isNextSub("SPEL"))
|
||
|
mSpells.emplace_back(esm.getHString());
|
||
11 years ago
|
}
|
||
|
|
||
5 years ago
|
// Obsolete
|
||
11 years ago
|
while (esm.isNextSub("PERM"))
|
||
|
{
|
||
|
std::string spellId = esm.getHString();
|
||
|
std::vector<PermanentSpellEffectInfo> permEffectList;
|
||
5 years ago
|
|
||
|
while (true)
|
||
11 years ago
|
{
|
||
5 years ago
|
ESM_Context restorePoint = esm.getContext();
|
||
|
|
||
|
if (!esm.isNextSub("EFID"))
|
||
|
break;
|
||
|
|
||
11 years ago
|
PermanentSpellEffectInfo info;
|
||
|
esm.getHT(info.mId);
|
||
5 years ago
|
if (esm.isNextSub("BASE"))
|
||
|
{
|
||
|
esm.restoreContext(restorePoint);
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
esm.getHNT(info.mArg, "ARG_");
|
||
11 years ago
|
|
||
5 years ago
|
esm.getHNT(info.mMagnitude, "MAGN");
|
||
11 years ago
|
permEffectList.push_back(info);
|
||
|
}
|
||
|
mPermanentSpellEffects[spellId] = permEffectList;
|
||
|
}
|
||
|
|
||
5 years ago
|
// Obsolete
|
||
11 years ago
|
while (esm.isNextSub("CORP"))
|
||
|
{
|
||
|
std::string id = esm.getHString();
|
||
|
|
||
|
CorprusStats stats;
|
||
|
esm.getHNT(stats.mWorsenings, "WORS");
|
||
|
esm.getHNT(stats.mNextWorsening, "TIME");
|
||
|
|
||
|
mCorprusSpells[id] = stats;
|
||
|
}
|
||
|
|
||
11 years ago
|
while (esm.isNextSub("USED"))
|
||
|
{
|
||
|
std::string id = esm.getHString();
|
||
|
TimeStamp time;
|
||
|
esm.getHNT(time, "TIME");
|
||
|
|
||
|
mUsedPowers[id] = time;
|
||
|
}
|
||
|
|
||
|
mSelectedSpell = esm.getHNOString("SLCT");
|
||
|
}
|
||
|
|
||
|
void SpellState::save(ESMWriter &esm) const
|
||
|
{
|
||
3 years ago
|
for (const std::string& spell : mSpells)
|
||
|
esm.writeHNString("SPEL", spell);
|
||
11 years ago
|
|
||
11 years ago
|
for (std::map<std::string, TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
||
|
{
|
||
|
esm.writeHNString("USED", it->first);
|
||
|
esm.writeHNT("TIME", it->second);
|
||
|
}
|
||
|
|
||
|
if (!mSelectedSpell.empty())
|
||
|
esm.writeHNString("SLCT", mSelectedSpell);
|
||
|
}
|
||
|
|
||
|
}
|