1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 20:53:52 +00:00
openmw/components/esm3/aipackage.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.1 KiB
C++
Raw Normal View History

2012-08-29 17:35:06 +00:00
#include "aipackage.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
2012-09-17 07:37:50 +00:00
2012-08-29 17:35:06 +00:00
namespace ESM
{
template <Misc::SameAsWithoutCvref<AIWander> T>
void decompose(T&& v, const auto& f)
{
f(v.mDistance, v.mDuration, v.mTimeOfDay, v.mIdle, v.mShouldRepeat);
}
template <Misc::SameAsWithoutCvref<AITravel> T>
void decompose(T&& v, const auto& f)
{
char padding[3] = { 0, 0, 0 };
f(v.mX, v.mY, v.mZ, v.mShouldRepeat, padding);
}
template <Misc::SameAsWithoutCvref<AITarget> T>
void decompose(T&& v, const auto& f)
{
char padding = 0;
f(v.mX, v.mY, v.mZ, v.mDuration, v.mId.mData, v.mShouldRepeat, padding);
}
template <Misc::SameAsWithoutCvref<AIActivate> T>
void decompose(T&& v, const auto& f)
{
f(v.mName.mData, v.mShouldRepeat);
}
void AIData::blank()
{
mHello = mFight = mFlee = mAlarm = 0;
mServices = 0;
}
void AIPackageList::add(ESMReader& esm)
{
AIPackage pack;
if (esm.retSubName() == AI_CNDT)
{
2021-05-13 11:58:56 +00:00
if (mList.empty())
{
esm.fail("AIPackge with an AI_CNDT applying to no cell.");
}
else
{
mList.back().mCellName = esm.getHString();
}
}
else if (esm.retSubName() == AI_Wander)
{
pack.mType = AI_Wander;
esm.getSubComposite(pack.mWander);
mList.push_back(pack);
}
else if (esm.retSubName() == AI_Travel)
{
pack.mType = AI_Travel;
esm.getSubComposite(pack.mTravel);
mList.push_back(pack);
}
else if (esm.retSubName() == AI_Escort || esm.retSubName() == AI_Follow)
{
pack.mType = (esm.retSubName() == AI_Escort) ? AI_Escort : AI_Follow;
esm.getSubComposite(pack.mTarget);
mList.push_back(pack);
}
else if (esm.retSubName() == AI_Activate)
{
pack.mType = AI_Activate;
esm.getSubComposite(pack.mActivate);
mList.push_back(pack);
}
}
void AIPackageList::save(ESMWriter& esm) const
2012-09-17 07:37:50 +00:00
{
for (const AIPackage& package : mList)
2012-09-18 15:30:19 +00:00
{
switch (package.mType)
2022-09-22 18:26:05 +00:00
{
2012-09-18 15:30:19 +00:00
case AI_Wander:
esm.writeNamedComposite("AI_W", package.mWander);
2012-09-18 15:30:19 +00:00
break;
case AI_Travel:
esm.writeNamedComposite("AI_T", package.mTravel);
2012-09-18 15:30:19 +00:00
break;
case AI_Activate:
esm.writeNamedComposite("AI_A", package.mActivate);
2012-09-18 15:30:19 +00:00
break;
case AI_Escort:
case AI_Follow:
{
const NAME name = (package.mType == AI_Escort) ? NAME("AI_E") : NAME("AI_F");
esm.writeNamedComposite(name, package.mTarget);
esm.writeHNOCString("CNDT", package.mCellName);
2012-09-18 15:30:19 +00:00
break;
}
default:
break;
}
}
2012-09-17 07:37:50 +00:00
}
2012-08-29 17:35:06 +00:00
}