2014-01-14 11:25:35 +00:00
|
|
|
#include "objectstate.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
|
|
|
void ESM::ObjectState::load (ESMReader &esm)
|
|
|
|
{
|
2015-06-30 15:26:33 +00:00
|
|
|
mVersion = esm.getFormat();
|
2015-06-30 01:58:23 +00:00
|
|
|
|
2015-07-20 14:23:14 +00:00
|
|
|
bool isDeleted;
|
|
|
|
mRef.loadData(esm, isDeleted);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
|
|
|
mHasLocals = 0;
|
|
|
|
esm.getHNOT (mHasLocals, "HLOC");
|
|
|
|
|
|
|
|
if (mHasLocals)
|
|
|
|
mLocals.load (esm);
|
|
|
|
|
|
|
|
mEnabled = 1;
|
|
|
|
esm.getHNOT (mEnabled, "ENAB");
|
|
|
|
|
|
|
|
mCount = 1;
|
|
|
|
esm.getHNOT (mCount, "COUN");
|
|
|
|
|
2014-01-31 12:25:32 +00:00
|
|
|
esm.getHNOT (mPosition, "POS_", 24);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2015-11-12 00:16:37 +00:00
|
|
|
if (esm.isNextSub("LROT"))
|
|
|
|
esm.skipHSub(); // local rotation, no longer used
|
2015-01-19 09:34:49 +00:00
|
|
|
|
2016-02-26 11:59:35 +00:00
|
|
|
mFlags = 0;
|
|
|
|
esm.getHNOT (mFlags, "FLAG");
|
|
|
|
|
2015-01-23 14:33:39 +00:00
|
|
|
// obsolete
|
|
|
|
int unused;
|
|
|
|
esm.getHNOT(unused, "LTIM");
|
2015-01-19 22:29:06 +00:00
|
|
|
|
2016-07-30 17:24:03 +00:00
|
|
|
mAnimationState.load(esm);
|
|
|
|
|
2015-01-19 22:29:06 +00:00
|
|
|
// FIXME: assuming "false" as default would make more sense, but also break compatibility with older save files
|
|
|
|
mHasCustomState = true;
|
|
|
|
esm.getHNOT (mHasCustomState, "HCUS");
|
2014-01-14 11:25:35 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 12:49:59 +00:00
|
|
|
void ESM::ObjectState::save (ESMWriter &esm, bool inInventory) const
|
2014-01-14 11:25:35 +00:00
|
|
|
{
|
2014-01-28 12:49:59 +00:00
|
|
|
mRef.save (esm, true, inInventory);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
|
|
|
if (mHasLocals)
|
|
|
|
{
|
|
|
|
esm.writeHNT ("HLOC", mHasLocals);
|
|
|
|
mLocals.save (esm);
|
|
|
|
}
|
|
|
|
|
2014-01-28 12:49:59 +00:00
|
|
|
if (!mEnabled && !inInventory)
|
2014-01-14 11:25:35 +00:00
|
|
|
esm.writeHNT ("ENAB", mEnabled);
|
|
|
|
|
|
|
|
if (mCount!=1)
|
|
|
|
esm.writeHNT ("COUN", mCount);
|
|
|
|
|
2014-01-28 12:49:59 +00:00
|
|
|
if (!inInventory)
|
|
|
|
esm.writeHNT ("POS_", mPosition, 24);
|
2015-01-19 09:34:49 +00:00
|
|
|
|
2016-02-26 11:59:35 +00:00
|
|
|
if (mFlags != 0)
|
|
|
|
esm.writeHNT ("FLAG", mFlags);
|
|
|
|
|
2016-07-30 17:24:03 +00:00
|
|
|
mAnimationState.save(esm);
|
|
|
|
|
2015-01-19 22:29:06 +00:00
|
|
|
if (!mHasCustomState)
|
|
|
|
esm.writeHNT ("HCUS", false);
|
2014-01-28 12:53:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-18 18:59:29 +00:00
|
|
|
void ESM::ObjectState::blank()
|
|
|
|
{
|
|
|
|
mRef.blank();
|
|
|
|
mHasLocals = 0;
|
|
|
|
mEnabled = false;
|
|
|
|
mCount = 1;
|
|
|
|
for (int i=0;i<3;++i)
|
|
|
|
{
|
|
|
|
mPosition.pos[i] = 0;
|
|
|
|
mPosition.rot[i] = 0;
|
|
|
|
}
|
2016-02-26 11:59:35 +00:00
|
|
|
mFlags = 0;
|
2015-01-19 22:29:06 +00:00
|
|
|
mHasCustomState = true;
|
2015-01-18 18:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ESM::ObjectState::~ObjectState() {}
|