|
|
@ -1,5 +1,7 @@
|
|
|
|
#include "aiwander.hpp"
|
|
|
|
#include "aiwander.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <cfloat>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/misc/rng.hpp>
|
|
|
|
#include <components/misc/rng.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/esm/aisequence.hpp>
|
|
|
|
#include <components/esm/aisequence.hpp>
|
|
|
@ -700,23 +702,30 @@ namespace MWMechanics
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!mAllowedNodes.empty())
|
|
|
|
if(!mAllowedNodes.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osg::Vec3f firstNodePos(PathFinder::MakeOsgVec3(mAllowedNodes[0]));
|
|
|
|
SetCurrentNodeToClosestAllowedNode(npcPos);
|
|
|
|
float closestNode = (npcPos - firstNodePos).length2();
|
|
|
|
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
for(unsigned int counterThree = 1; counterThree < mAllowedNodes.size(); counterThree++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::Vec3f nodePos(PathFinder::MakeOsgVec3(mAllowedNodes[counterThree]));
|
|
|
|
|
|
|
|
float tempDist = (npcPos - nodePos).length2();
|
|
|
|
|
|
|
|
if(tempDist < closestNode)
|
|
|
|
|
|
|
|
index = counterThree;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentNode = mAllowedNodes[index];
|
|
|
|
|
|
|
|
mAllowedNodes.erase(mAllowedNodes.begin() + index);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
|
|
|
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AiWander::SetCurrentNodeToClosestAllowedNode(osg::Vec3f npcPos)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
float distanceToClosestNode = FLT_MAX;
|
|
|
|
|
|
|
|
unsigned int index = 0;
|
|
|
|
|
|
|
|
for (unsigned int counterThree = 0; counterThree < mAllowedNodes.size(); counterThree++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::Vec3f nodePos(PathFinder::MakeOsgVec3(mAllowedNodes[counterThree]));
|
|
|
|
|
|
|
|
float tempDist = (npcPos - nodePos).length2();
|
|
|
|
|
|
|
|
if (tempDist < distanceToClosestNode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
index = counterThree;
|
|
|
|
|
|
|
|
distanceToClosestNode = tempDist;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentNode = mAllowedNodes[index];
|
|
|
|
|
|
|
|
mAllowedNodes.erase(mAllowedNodes.begin() + index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AiWander::writeState(ESM::AiSequence::AiSequence &sequence) const
|
|
|
|
void AiWander::writeState(ESM::AiSequence::AiSequence &sequence) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::auto_ptr<ESM::AiSequence::AiWander> wander(new ESM::AiSequence::AiWander());
|
|
|
|
std::auto_ptr<ESM::AiSequence::AiWander> wander(new ESM::AiSequence::AiWander());
|
|
|
|