forked from mirror/openmw-tes3mp
Extracted function SetCurrentNodeToClosestAllowedNode()
This commit is contained in:
parent
76f20b8b20
commit
eb2aa965b9
2 changed files with 23 additions and 12 deletions
|
@ -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());
|
||||||
|
|
|
@ -121,6 +121,8 @@ namespace MWMechanics
|
||||||
/// convert point from local (i.e. cell) to world co-ordinates
|
/// convert point from local (i.e. cell) to world co-ordinates
|
||||||
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
|
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
|
||||||
|
|
||||||
|
void SetCurrentNodeToClosestAllowedNode(osg::Vec3f npcPos);
|
||||||
|
|
||||||
/// lookup table for converting idleSelect value to groupName
|
/// lookup table for converting idleSelect value to groupName
|
||||||
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
|
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue