added savedgame-specifc record structs for objects state

pull/22/head
Marc Zinnschlag 11 years ago
parent e453468eff
commit 8c5f313546

@ -40,7 +40,7 @@ add_component_dir (esm
loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc
loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat
loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter
savedgame journalentry queststate locals globalscript
savedgame journalentry queststate locals globalscript player objectstate cellid
)
add_component_dir (misc

@ -0,0 +1,26 @@
#include "cellid.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
void ESM::CellId::load (ESMReader &esm)
{
mWorldspace = esm.getHNString ("SPAC");
if (esm.isNextSub ("CIDX"))
{
esm.getHT (mIndex, 8);
mPaged = true;
}
else
mPaged = false;
}
void ESM::CellId::save (ESMWriter &esm) const
{
esm.writeHNString ("SPAC", mWorldspace);
if (mPaged)
esm.writeHNT ("CIDX", mIndex, 8);
}

@ -0,0 +1,28 @@
#ifndef OPENMW_ESM_CELLID_H
#define OPENMW_ESM_CELLID_H
#include <string>
namespace ESM
{
class ESMReader;
class ESMWriter;
struct CellId
{
struct CellIndex
{
int mX;
int mY;
};
std::string mWorldspace;
CellIndex mIndex;
bool mPaged;
void load (ESMReader &esm);
void save (ESMWriter &esm) const;
};
}
#endif

@ -88,6 +88,7 @@ enum RecNameInts
REC_JOUR = 0x524f55a4,
REC_QUES = 0x53455551,
REC_GSCR = 0x52435347,
REC_PLAY = 0x504c4159,
// format 1
REC_FILT = 0x544C4946

@ -3,11 +3,15 @@
#include <string>
#include <sstream>
#include <list>
#include <boost/concept_check.hpp>
#include <components/misc/stringops.hpp>
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "defs.hpp"
#include "cellid.hpp"
namespace
{
@ -221,4 +225,24 @@ bool Cell::getNextMVRF(ESMReader &esm, MovedCellRef &mref)
mAmbi.mFog = 0;
mAmbi.mFogDensity = 0;
}
CellId Cell::getCellId() const
{
CellId id;
id.mPaged = (mData.mFlags & Interior);
if (id.mPaged)
{
id.mWorldspace = "default";
id.mIndex.mX = mData.mX;
id.mIndex.mY = mData.mY;
}
else
{
id.mWorldspace = Misc::StringUtils::lowerCase (mName);
}
return id;
}
}

@ -18,6 +18,7 @@ namespace ESM
{
class ESMReader;
class ESMWriter;
class CellId;
/* Moved cell reference tracking object. This mainly stores the target cell
of the reference, so we can easily know where it has been moved when another
@ -150,6 +151,8 @@ struct Cell
void blank();
///< Set record to default state (does not touch the ID/index).
CellId getCellId() const;
};
}
#endif

@ -0,0 +1,47 @@
#include "objectstate.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
void ESM::ObjectState::load (ESMReader &esm)
{
mRef.load (esm, true);
mHasLocals = 0;
esm.getHNOT (mHasLocals, "HLOC");
if (mHasLocals)
mLocals.load (esm);
mEnabled = 1;
esm.getHNOT (mEnabled, "ENAB");
mCount = 1;
esm.getHNOT (mCount, "COUN");
esm.getHNT (mPosition, "POS_", 24);
esm.getHNT (mLocalRotation, "LROT", 12);
}
void ESM::ObjectState::save (ESMWriter &esm) const
{
mRef.save (esm);
if (mHasLocals)
{
esm.writeHNT ("HLOC", mHasLocals);
mLocals.save (esm);
}
if (!mEnabled)
esm.writeHNT ("ENAB", mEnabled);
if (mCount!=1)
esm.writeHNT ("COUN", mCount);
esm.writeHNT ("POS_", mPosition, 24);
esm.writeHNT ("LROT", mLocalRotation, 12);
}

@ -0,0 +1,36 @@
#ifndef OPENMW_ESM_OBJECTSTATE_H
#define OPENMW_ESM_OBJECTSTATE_H
#include <string>
#include <vector>
#include "cellref.hpp"
#include "locals.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
///< \brief Save state for objects, that do not use custom data
struct ObjectState
{
std::string mId;
CellRef mRef;
unsigned char mHasLocals;
Locals mLocals;
unsigned char mEnabled;
int mCount;
ESM::Position mPosition;
float mLocalRotation[3];
void load (ESMReader &esm);
void save (ESMWriter &esm) const;
};
}
#endif

@ -0,0 +1,44 @@
#include "player.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
void ESM::Player::load (ESMReader &esm)
{
mObject.load (esm);
mCellId.load (esm);
esm.getHNT (mLastKnownExteriorPosition, "LKEP", 12);
if (esm.isNextSub ("MARK"))
{
mHasMark = true;
esm.getHT (mMarkedPosition, 24);
mMarkedCell.load (esm);
}
else
mHasMark = false;
mAutoMove = 0;
esm.getHNOT (mAutoMove, "AMOV");
}
void ESM::Player::save (ESMWriter &esm) const
{
mObject.save (esm);
mCellId.save (esm);
esm.writeHNT ("LKEP", mLastKnownExteriorPosition, 12);
if (mHasMark)
{
esm.writeHNT ("MARK", mMarkedPosition, 24);
mMarkedCell.save (esm);
}
if (mAutoMove)
esm.writeHNT ("AMOV", mAutoMove);
}

@ -0,0 +1,32 @@
#ifndef OPENMW_ESM_PLAYER_H
#define OPENMW_ESM_PLAYER_H
#include <string>
#include "objectstate.hpp"
#include "cellid.hpp"
#include "defs.hpp"
namespace ESM
{
class ESMReader;
class ESMWriter;
// format 0, saved games only
struct Player
{
ObjectState mObject;
CellId mCellId;
float mLastKnownExteriorPosition[3];
unsigned char mHasMark;
ESM::Position mMarkedPosition;
CellId mMarkedCell;
unsigned char mAutoMove;
void load (ESMReader &esm);
void save (ESMWriter &esm) const;
};
}
#endif
Loading…
Cancel
Save