Savegame: Store AiSequence
parent
be6f1fe4fe
commit
a54ac579a5
@ -0,0 +1,211 @@
|
||||
#include "aisequence.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
#include "defs.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
namespace AiSequence
|
||||
{
|
||||
|
||||
void AiWander::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mData, "DATA");
|
||||
esm.getHNT(mStartTime, "STAR");
|
||||
}
|
||||
|
||||
void AiWander::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("DATA", mData);
|
||||
esm.writeHNT ("STAR", mStartTime);
|
||||
}
|
||||
|
||||
void AiTravel::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mData, "DATA");
|
||||
}
|
||||
|
||||
void AiTravel::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("DATA", mData);
|
||||
}
|
||||
|
||||
void AiEscort::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mData, "DATA");
|
||||
mTargetId = esm.getHNString("TARG");
|
||||
esm.getHNT (mRemainingDuration, "DURA");
|
||||
mCellId = esm.getHNOString ("CELL");
|
||||
}
|
||||
|
||||
void AiEscort::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("DATA", mData);
|
||||
esm.writeHNString ("TARG", mTargetId);
|
||||
esm.writeHNT ("DURA", mRemainingDuration);
|
||||
if (!mCellId.empty())
|
||||
esm.writeHNString ("CELL", mCellId);
|
||||
}
|
||||
|
||||
void AiFollow::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mData, "DATA");
|
||||
mTargetId = esm.getHNString("TARG");
|
||||
esm.getHNT (mRemainingDuration, "DURA");
|
||||
mCellId = esm.getHNOString ("CELL");
|
||||
esm.getHNT (mAlwaysFollow, "ALWY");
|
||||
}
|
||||
|
||||
void AiFollow::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("DATA", mData);
|
||||
esm.writeHNString("TARG", mTargetId);
|
||||
esm.writeHNT ("DURA", mRemainingDuration);
|
||||
if (!mCellId.empty())
|
||||
esm.writeHNString ("CELL", mCellId);
|
||||
esm.writeHNT ("ALWY", mAlwaysFollow);
|
||||
}
|
||||
|
||||
void AiActivate::load(ESMReader &esm)
|
||||
{
|
||||
mTargetId = esm.getHNString("TARG");
|
||||
}
|
||||
|
||||
void AiActivate::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNString("TARG", mTargetId);
|
||||
}
|
||||
|
||||
void AiCombat::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mTargetActorId, "TARG");
|
||||
}
|
||||
|
||||
void AiCombat::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("TARG", mTargetActorId);
|
||||
}
|
||||
|
||||
void AiPursue::load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT (mTargetActorId, "TARG");
|
||||
}
|
||||
|
||||
void AiPursue::save(ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNT ("TARG", mTargetActorId);
|
||||
}
|
||||
|
||||
AiSequence::~AiSequence()
|
||||
{
|
||||
for (std::vector<AiPackageContainer>::iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||
delete it->mPackage;
|
||||
}
|
||||
|
||||
void AiSequence::save(ESMWriter &esm) const
|
||||
{
|
||||
for (std::vector<AiPackageContainer>::const_iterator it = mPackages.begin(); it != mPackages.end(); ++it)
|
||||
{
|
||||
esm.writeHNT ("AIPK", it->mType);
|
||||
switch (it->mType)
|
||||
{
|
||||
case Ai_Wander:
|
||||
static_cast<const AiWander*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Travel:
|
||||
static_cast<const AiTravel*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Escort:
|
||||
static_cast<const AiEscort*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Follow:
|
||||
static_cast<const AiFollow*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Activate:
|
||||
static_cast<const AiActivate*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Combat:
|
||||
static_cast<const AiCombat*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
case Ai_Pursue:
|
||||
static_cast<const AiPursue*>(it->mPackage)->save(esm);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AiSequence::load(ESMReader &esm)
|
||||
{
|
||||
while (esm.isNextSub("AIPK"))
|
||||
{
|
||||
int type;
|
||||
esm.getHT(type);
|
||||
|
||||
mPackages.push_back(AiPackageContainer());
|
||||
mPackages.back().mType = type;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Ai_Wander:
|
||||
{
|
||||
std::auto_ptr<AiWander> ptr (new AiWander());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Travel:
|
||||
{
|
||||
std::auto_ptr<AiTravel> ptr (new AiTravel());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Escort:
|
||||
{
|
||||
std::auto_ptr<AiEscort> ptr (new AiEscort());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Follow:
|
||||
{
|
||||
std::auto_ptr<AiFollow> ptr (new AiFollow());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Activate:
|
||||
{
|
||||
std::auto_ptr<AiActivate> ptr (new AiActivate());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Combat:
|
||||
{
|
||||
std::auto_ptr<AiCombat> ptr (new AiCombat());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
case Ai_Pursue:
|
||||
{
|
||||
std::auto_ptr<AiPursue> ptr (new AiPursue());
|
||||
ptr->load(esm);
|
||||
mPackages.back().mPackage = ptr.release();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
#ifndef OPENMW_COMPONENTS_ESM_AISEQUENCE_H
|
||||
#define OPENMW_COMPONENTS_ESM_AISEQUENCE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "defs.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
namespace AiSequence
|
||||
{
|
||||
|
||||
// format 0, saved games only
|
||||
// As opposed to AiPackageList, this stores the "live" version of AI packages.
|
||||
|
||||
enum AiPackages
|
||||
{
|
||||
Ai_Wander = ESM::FourCC<'W','A','N','D'>::value,
|
||||
Ai_Travel = ESM::FourCC<'T','R','A','V'>::value,
|
||||
Ai_Escort = ESM::FourCC<'E','S','C','O'>::value,
|
||||
Ai_Follow = ESM::FourCC<'F','O','L','L'>::value,
|
||||
Ai_Activate = ESM::FourCC<'A','C','T','I'>::value,
|
||||
Ai_Combat = ESM::FourCC<'C','O','M','B'>::value,
|
||||
Ai_Pursue = ESM::FourCC<'P','U','R','S'>::value
|
||||
};
|
||||
|
||||
|
||||
struct AiPackage
|
||||
{
|
||||
virtual ~AiPackage() {}
|
||||
};
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct AiWanderData
|
||||
{
|
||||
short mDistance;
|
||||
short mDuration;
|
||||
unsigned char mTimeOfDay;
|
||||
unsigned char mIdle[8];
|
||||
unsigned char mShouldRepeat;
|
||||
};
|
||||
struct AiTravelData
|
||||
{
|
||||
float mX, mY, mZ;
|
||||
};
|
||||
struct AiEscortData
|
||||
{
|
||||
float mX, mY, mZ;
|
||||
short mDuration;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
struct AiWander : AiPackage
|
||||
{
|
||||
AiWanderData mData;
|
||||
ESM::TimeStamp mStartTime;
|
||||
|
||||
/// \todo add more AiWander state
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiTravel : AiPackage
|
||||
{
|
||||
AiTravelData mData;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiEscort : AiPackage
|
||||
{
|
||||
AiEscortData mData;
|
||||
|
||||
std::string mTargetId;
|
||||
std::string mCellId;
|
||||
float mRemainingDuration;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiFollow : AiPackage
|
||||
{
|
||||
AiEscortData mData;
|
||||
|
||||
std::string mTargetId;
|
||||
std::string mCellId;
|
||||
float mRemainingDuration;
|
||||
|
||||
bool mAlwaysFollow;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiActivate : AiPackage
|
||||
{
|
||||
std::string mTargetId;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiCombat : AiPackage
|
||||
{
|
||||
int mTargetActorId;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiPursue : AiPackage
|
||||
{
|
||||
int mTargetActorId;
|
||||
|
||||
void load(ESMReader &esm);
|
||||
void save(ESMWriter &esm) const;
|
||||
};
|
||||
|
||||
struct AiPackageContainer
|
||||
{
|
||||
int mType;
|
||||
|
||||
AiPackage* mPackage;
|
||||
};
|
||||
|
||||
struct AiSequence
|
||||
{
|
||||
AiSequence() {}
|
||||
~AiSequence();
|
||||
|
||||
std::vector<AiPackageContainer> mPackages;
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
|
||||
private:
|
||||
AiSequence(const AiSequence&);
|
||||
AiSequence& operator=(const AiSequence&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue