From 16cacb338a43fb13f3942097c838fa1dcd29d100 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 31 Jul 2013 00:55:08 +0200 Subject: [PATCH] Initialize MWMechanics::AiSequence from ESM::AiPackageList --- apps/openmw/mwclass/creature.cpp | 2 ++ apps/openmw/mwclass/npc.cpp | 2 ++ apps/openmw/mwmechanics/aisequence.cpp | 43 ++++++++++++++++++++++++++ apps/openmw/mwmechanics/aisequence.hpp | 4 +++ 4 files changed, 51 insertions(+) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 960f57430..99da3b215 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -79,6 +79,8 @@ namespace MWClass data->mCreatureStats.setLevel(ref->mBase->mData.mLevel); + data->mCreatureStats.getAiSequence().fill(ref->mBase->mAiPackage); + data->mCreatureStats.setAiSetting (0, ref->mBase->mAiData.mHello); data->mCreatureStats.setAiSetting (1, ref->mBase->mAiData.mFight); data->mCreatureStats.setAiSetting (2, ref->mBase->mAiData.mFlee); diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index f1d66a2e1..a468148b4 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -215,6 +215,8 @@ namespace MWClass autoCalculateAttributes(ref->mBase, data->mCreatureStats); } + data->mCreatureStats.getAiSequence().fill(ref->mBase->mAiPackage); + data->mCreatureStats.setAiSetting (0, ref->mBase->mAiData.mHello); data->mCreatureStats.setAiSetting (1, ref->mBase->mAiData.mFight); data->mCreatureStats.setAiSetting (2, ref->mBase->mAiData.mFlee); diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index c4dcf89af..2f06b849a 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -3,6 +3,12 @@ #include "aipackage.hpp" +#include "aiwander.hpp" +#include "aiescort.hpp" +#include "aitravel.hpp" +#include "aifollow.hpp" +#include "aiactivate.hpp" + void MWMechanics::AiSequence::copy (const AiSequence& sequence) { for (std::list::const_iterator iter (sequence.mPackages.begin()); @@ -77,3 +83,40 @@ void MWMechanics::AiSequence::queue (const AiPackage& package) { mPackages.push_back (package.clone()); } + +void MWMechanics::AiSequence::fill(const ESM::AIPackageList &list) +{ + for (std::vector::const_iterator it = list.mList.begin(); it != list.mList.end(); ++it) + { + MWMechanics::AiPackage* package; + if (it->mType == ESM::AI_Wander) + { + ESM::AIWander data = it->mWander; + std::vector idles; + for (int i=0; i<8; ++i) + idles.push_back(data.mIdle[i]); + package = new MWMechanics::AiWander(data.mDistance, data.mDuration, data.mTimeOfDay, idles, data.mUnk); + } + else if (it->mType == ESM::AI_Escort) + { + ESM::AITarget data = it->mTarget; + package = new MWMechanics::AiEscort(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ); + } + else if (it->mType == ESM::AI_Travel) + { + ESM::AITravel data = it->mTravel; + package = new MWMechanics::AiTravel(data.mX, data.mY, data.mZ); + } + else if (it->mType == ESM::AI_Activate) + { + ESM::AIActivate data = it->mActivate; + package = new MWMechanics::AiActivate(data.mName.toString()); + } + else //if (it->mType == ESM::AI_Follow) + { + ESM::AITarget data = it->mTarget; + package = new MWMechanics::AiFollow(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ); + } + mPackages.push_back(package); + } +} diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index b9ec9d615..9f70daeb8 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -3,6 +3,8 @@ #include +#include + namespace MWWorld { class Ptr; @@ -48,6 +50,8 @@ namespace MWMechanics void queue (const AiPackage& package); ///< Add \a package to the end of the sequence (executed after all other packages have been /// completed) + + void fill (const ESM::AIPackageList& list); }; }