2014-06-12 23:27:04 +02:00
|
|
|
#include "aisequence.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2021-11-17 20:44:55 +01:00
|
|
|
#include <algorithm>
|
2014-06-12 23:27:04 +02:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
namespace AiSequence
|
|
|
|
{
|
|
|
|
|
|
|
|
void AiWander::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getHNT (mData, "DATA");
|
2016-06-11 22:34:49 +09:00
|
|
|
esm.getHNT(mDurationData, "STAR"); // was mStartTime
|
2014-12-31 21:27:19 +01:00
|
|
|
mStoredInitialActorPosition = false;
|
|
|
|
if (esm.isNextSub("POS_"))
|
|
|
|
{
|
|
|
|
mStoredInitialActorPosition = true;
|
|
|
|
esm.getHT(mInitialActorPosition);
|
|
|
|
}
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiWander::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNT ("DATA", mData);
|
2016-06-10 00:56:01 +09:00
|
|
|
esm.writeHNT ("STAR", mDurationData);
|
2014-12-31 21:27:19 +01:00
|
|
|
if (mStoredInitialActorPosition)
|
|
|
|
esm.writeHNT ("POS_", mInitialActorPosition);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiTravel::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getHNT (mData, "DATA");
|
2018-05-25 19:31:31 +04:00
|
|
|
esm.getHNOT (mHidden, "HIDD");
|
2021-11-17 20:44:55 +01:00
|
|
|
mRepeat = false;
|
|
|
|
esm.getHNOT(mRepeat, "REPT");
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiTravel::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNT ("DATA", mData);
|
2018-05-25 19:31:31 +04:00
|
|
|
esm.writeHNT ("HIDD", mHidden);
|
2021-11-17 20:44:55 +01:00
|
|
|
if(mRepeat)
|
|
|
|
esm.writeHNT("REPT", mRepeat);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiEscort::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getHNT (mData, "DATA");
|
|
|
|
mTargetId = esm.getHNString("TARG");
|
2019-02-05 08:03:31 +04:00
|
|
|
mTargetActorId = -1;
|
2017-11-21 20:00:51 +04:00
|
|
|
esm.getHNOT (mTargetActorId, "TAID");
|
2014-06-12 23:27:04 +02:00
|
|
|
esm.getHNT (mRemainingDuration, "DURA");
|
|
|
|
mCellId = esm.getHNOString ("CELL");
|
2021-11-17 20:44:55 +01:00
|
|
|
mRepeat = false;
|
|
|
|
esm.getHNOT(mRepeat, "REPT");
|
|
|
|
if(esm.getFormat() < 18)
|
|
|
|
{
|
|
|
|
// mDuration isn't saved in the save file, so just giving it "1" for now if the package has a duration.
|
|
|
|
// The exact value of mDuration only matters for repeating packages.
|
|
|
|
// Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should fix old saves.
|
|
|
|
mData.mDuration = std::max<float>(mRemainingDuration > 0, mRemainingDuration);
|
|
|
|
}
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiEscort::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNT ("DATA", mData);
|
|
|
|
esm.writeHNString ("TARG", mTargetId);
|
2017-11-21 20:00:51 +04:00
|
|
|
esm.writeHNT ("TAID", mTargetActorId);
|
2014-06-12 23:27:04 +02:00
|
|
|
esm.writeHNT ("DURA", mRemainingDuration);
|
|
|
|
if (!mCellId.empty())
|
|
|
|
esm.writeHNString ("CELL", mCellId);
|
2021-11-17 20:44:55 +01:00
|
|
|
if(mRepeat)
|
|
|
|
esm.writeHNT("REPT", mRepeat);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiFollow::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
esm.getHNT (mData, "DATA");
|
|
|
|
mTargetId = esm.getHNString("TARG");
|
2019-02-05 08:03:31 +04:00
|
|
|
mTargetActorId = -1;
|
2017-11-21 20:00:51 +04:00
|
|
|
esm.getHNOT (mTargetActorId, "TAID");
|
2014-06-12 23:27:04 +02:00
|
|
|
esm.getHNT (mRemainingDuration, "DURA");
|
|
|
|
mCellId = esm.getHNOString ("CELL");
|
|
|
|
esm.getHNT (mAlwaysFollow, "ALWY");
|
2014-08-06 21:16:14 +02:00
|
|
|
mCommanded = false;
|
|
|
|
esm.getHNOT (mCommanded, "CMND");
|
2014-12-09 22:25:28 +01:00
|
|
|
mActive = false;
|
|
|
|
esm.getHNOT (mActive, "ACTV");
|
2021-11-17 20:44:55 +01:00
|
|
|
mRepeat = false;
|
|
|
|
esm.getHNOT(mRepeat, "REPT");
|
|
|
|
if(esm.getFormat() < 18)
|
|
|
|
{
|
|
|
|
// mDuration isn't saved in the save file, so just giving it "1" for now if the package has a duration.
|
|
|
|
// The exact value of mDuration only matters for repeating packages.
|
|
|
|
// Previously mRemainingDuration could be negative even when mDuration was 0. Checking for > 0 should fix old saves.
|
|
|
|
mData.mDuration = std::max<float>(mRemainingDuration > 0, mRemainingDuration);
|
|
|
|
}
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiFollow::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNT ("DATA", mData);
|
|
|
|
esm.writeHNString("TARG", mTargetId);
|
2017-11-21 20:00:51 +04:00
|
|
|
esm.writeHNT ("TAID", mTargetActorId);
|
2014-06-12 23:27:04 +02:00
|
|
|
esm.writeHNT ("DURA", mRemainingDuration);
|
|
|
|
if (!mCellId.empty())
|
|
|
|
esm.writeHNString ("CELL", mCellId);
|
|
|
|
esm.writeHNT ("ALWY", mAlwaysFollow);
|
2014-08-06 21:16:14 +02:00
|
|
|
esm.writeHNT ("CMND", mCommanded);
|
2014-12-09 22:25:28 +01:00
|
|
|
if (mActive)
|
|
|
|
esm.writeHNT("ACTV", mActive);
|
2021-11-17 20:44:55 +01:00
|
|
|
if(mRepeat)
|
|
|
|
esm.writeHNT("REPT", mRepeat);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiActivate::load(ESMReader &esm)
|
|
|
|
{
|
|
|
|
mTargetId = esm.getHNString("TARG");
|
2021-11-17 20:44:55 +01:00
|
|
|
mRepeat = false;
|
|
|
|
esm.getHNOT(mRepeat, "REPT");
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiActivate::save(ESMWriter &esm) const
|
|
|
|
{
|
|
|
|
esm.writeHNString("TARG", mTargetId);
|
2021-11-17 20:44:55 +01:00
|
|
|
if(mRepeat)
|
|
|
|
esm.writeHNT("REPT", mRepeat);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiWander&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Travel:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiTravel&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Escort:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiEscort&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Follow:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiFollow&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Activate:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiActivate&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Combat:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiCombat&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
case Ai_Pursue:
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<const AiPursue&>(*it->mPackage).save(esm);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-25 20:07:08 +04:00
|
|
|
|
|
|
|
esm.writeHNT ("LAST", mLastAiPackage);
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AiSequence::load(ESMReader &esm)
|
|
|
|
{
|
2021-11-17 20:44:55 +01:00
|
|
|
int count = 0;
|
2014-06-12 23:27:04 +02:00
|
|
|
while (esm.isNextSub("AIPK"))
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
esm.getHT(type);
|
|
|
|
|
2020-10-17 12:26:35 +04:00
|
|
|
mPackages.emplace_back();
|
2014-06-12 23:27:04 +02:00
|
|
|
mPackages.back().mType = type;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Ai_Wander:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiWander> ptr = std::make_unique<AiWander>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2021-11-17 20:44:55 +01:00
|
|
|
++count;
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Travel:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiTravel> ptr = std::make_unique<AiTravel>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2021-11-17 20:44:55 +01:00
|
|
|
++count;
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Escort:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiEscort> ptr = std::make_unique<AiEscort>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2021-11-17 20:44:55 +01:00
|
|
|
++count;
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Follow:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiFollow> ptr = std::make_unique<AiFollow>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2021-11-17 20:44:55 +01:00
|
|
|
++count;
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Activate:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiActivate> ptr = std::make_unique<AiActivate>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2021-11-17 20:44:55 +01:00
|
|
|
++count;
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Combat:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiCombat> ptr = std::make_unique<AiCombat>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Ai_Pursue:
|
|
|
|
{
|
2021-06-25 20:55:38 +02:00
|
|
|
std::unique_ptr<AiPursue> ptr = std::make_unique<AiPursue>();
|
2014-06-12 23:27:04 +02:00
|
|
|
ptr->load(esm);
|
2022-02-23 00:39:30 +01:00
|
|
|
mPackages.back().mPackage = std::move(ptr);
|
2014-06-12 23:27:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-05-25 20:07:08 +04:00
|
|
|
|
|
|
|
esm.getHNOT (mLastAiPackage, "LAST");
|
2021-11-17 20:44:55 +01:00
|
|
|
|
|
|
|
if(count > 1 && esm.getFormat() < 18)
|
|
|
|
{
|
|
|
|
for(auto& pkg : mPackages)
|
|
|
|
{
|
|
|
|
if(pkg.mType == Ai_Wander)
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<AiWander&>(*pkg.mPackage).mData.mShouldRepeat = true;
|
2021-11-17 20:44:55 +01:00
|
|
|
else if(pkg.mType == Ai_Travel)
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<AiTravel&>(*pkg.mPackage).mRepeat = true;
|
2021-11-17 20:44:55 +01:00
|
|
|
else if(pkg.mType == Ai_Escort)
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<AiEscort&>(*pkg.mPackage).mRepeat = true;
|
2021-11-17 20:44:55 +01:00
|
|
|
else if(pkg.mType == Ai_Follow)
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<AiFollow&>(*pkg.mPackage).mRepeat = true;
|
2021-11-17 20:44:55 +01:00
|
|
|
else if(pkg.mType == Ai_Activate)
|
2022-02-23 00:39:30 +01:00
|
|
|
static_cast<AiActivate&>(*pkg.mPackage).mRepeat = true;
|
2021-11-17 20:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 23:27:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|