2015-07-07 17:16:32 +00:00
|
|
|
#include "statstate.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
StatState<T>::StatState()
|
|
|
|
: mBase(0)
|
|
|
|
, mMod(0)
|
|
|
|
, mCurrent(0)
|
|
|
|
, mDamage(0)
|
|
|
|
, mProgress(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-12-23 11:18:33 +00:00
|
|
|
void StatState<T>::load(ESMReader& esm, bool intFallback)
|
2015-07-07 17:16:32 +00:00
|
|
|
{
|
2018-12-23 11:18:33 +00:00
|
|
|
// We changed stats values from integers to floats; ensure backwards compatibility
|
|
|
|
if (intFallback)
|
|
|
|
{
|
2023-10-24 17:25:52 +00:00
|
|
|
int32_t base = 0;
|
2018-12-23 11:18:33 +00:00
|
|
|
esm.getHNT(base, "STBA");
|
2021-05-02 08:59:22 +00:00
|
|
|
mBase = static_cast<T>(base);
|
2015-07-07 17:16:32 +00:00
|
|
|
|
2023-10-24 17:25:52 +00:00
|
|
|
int32_t mod = 0;
|
2018-12-23 11:18:33 +00:00
|
|
|
esm.getHNOT(mod, "STMO");
|
2021-05-02 08:59:22 +00:00
|
|
|
mMod = static_cast<T>(mod);
|
2015-07-07 17:16:32 +00:00
|
|
|
|
2023-10-24 17:25:52 +00:00
|
|
|
int32_t current = 0;
|
2018-12-23 11:18:33 +00:00
|
|
|
esm.getHNOT(current, "STCU");
|
2021-05-02 08:59:22 +00:00
|
|
|
mCurrent = static_cast<T>(current);
|
2018-12-23 11:18:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mBase = 0;
|
|
|
|
esm.getHNT(mBase, "STBA");
|
|
|
|
|
|
|
|
mMod = 0;
|
|
|
|
esm.getHNOT(mMod, "STMO");
|
|
|
|
|
|
|
|
mCurrent = 0;
|
|
|
|
esm.getHNOT(mCurrent, "STCU");
|
|
|
|
|
|
|
|
mDamage = 0;
|
|
|
|
esm.getHNOT(mDamage, "STDF");
|
|
|
|
|
|
|
|
mProgress = 0;
|
|
|
|
}
|
2015-07-07 17:16:32 +00:00
|
|
|
|
|
|
|
esm.getHNOT(mDamage, "STDF");
|
|
|
|
|
|
|
|
mProgress = 0;
|
|
|
|
esm.getHNOT(mProgress, "STPR");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void StatState<T>::save(ESMWriter& esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNT("STBA", mBase);
|
|
|
|
|
|
|
|
if (mMod != 0)
|
|
|
|
esm.writeHNT("STMO", mMod);
|
|
|
|
|
|
|
|
if (mCurrent)
|
|
|
|
esm.writeHNT("STCU", mCurrent);
|
|
|
|
|
|
|
|
if (mDamage)
|
|
|
|
esm.writeHNT("STDF", mDamage);
|
|
|
|
|
|
|
|
if (mProgress)
|
|
|
|
esm.writeHNT("STPR", mProgress);
|
|
|
|
}
|
2015-07-09 20:45:25 +00:00
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
template struct StatState<int>;
|
|
|
|
template struct StatState<float>;
|
|
|
|
}
|