forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'dteviot/Bug2726'
This commit is contained in:
commit
88f1220a77
3 changed files with 5 additions and 45 deletions
|
@ -267,6 +267,7 @@ namespace MWMechanics
|
||||||
moveNow = false;
|
moveNow = false;
|
||||||
walking = false;
|
walking = false;
|
||||||
chooseAction = true;
|
chooseAction = true;
|
||||||
|
mStuckCount = 0;
|
||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
@ -410,7 +411,7 @@ namespace MWMechanics
|
||||||
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
||||||
|
|
||||||
// don't take shortcuts for wandering
|
// don't take shortcuts for wandering
|
||||||
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
|
storage.mPathFinder.buildSyncedPath(start, dest, actor.getCell(), false);
|
||||||
|
|
||||||
if(storage.mPathFinder.isPathConstructed())
|
if(storage.mPathFinder.isPathConstructed())
|
||||||
{
|
{
|
||||||
|
@ -510,17 +511,10 @@ namespace MWMechanics
|
||||||
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
ESM::Pathgrid::Point start(PathFinder::MakePathgridPoint(pos));
|
||||||
|
|
||||||
// don't take shortcuts for wandering
|
// don't take shortcuts for wandering
|
||||||
storage.mPathFinder.buildPath(start, dest, actor.getCell(), false);
|
storage.mPathFinder.buildSyncedPath(start, dest, actor.getCell(), false);
|
||||||
|
|
||||||
if(storage.mPathFinder.isPathConstructed())
|
if(storage.mPathFinder.isPathConstructed())
|
||||||
{
|
{
|
||||||
// buildPath inserts dest in case it is not a pathgraph point
|
|
||||||
// index which is a duplicate for AiWander. However below code
|
|
||||||
// does not work since getPath() returns a copy of path not a
|
|
||||||
// reference
|
|
||||||
//if(storage.mPathFinder.getPathSize() > 1)
|
|
||||||
//storage.mPathFinder.getPath().pop_back();
|
|
||||||
|
|
||||||
// Remove this node as an option and add back the previously used node (stops NPC from picking the same node):
|
// Remove this node as an option and add back the previously used node (stops NPC from picking the same node):
|
||||||
ESM::Pathgrid::Point temp = mAllowedNodes[randNode];
|
ESM::Pathgrid::Point temp = mAllowedNodes[randNode];
|
||||||
mAllowedNodes.erase(mAllowedNodes.begin() + randNode);
|
mAllowedNodes.erase(mAllowedNodes.begin() + randNode);
|
||||||
|
@ -726,36 +720,10 @@ namespace MWMechanics
|
||||||
mCurrentNode = mAllowedNodes[index];
|
mCurrentNode = mAllowedNodes[index];
|
||||||
mAllowedNodes.erase(mAllowedNodes.begin() + index);
|
mAllowedNodes.erase(mAllowedNodes.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In vanilla Morrowind, sometimes distance is too small to include at least two points,
|
|
||||||
// in which case, we will take the two closest points regardless of the wander distance
|
|
||||||
// This is a backup option, as std::sort is potentially O(n^2) in time.
|
|
||||||
if (mAllowedNodes.empty())
|
|
||||||
{
|
|
||||||
// Start with list of PathGrid nodes, sorted by distance from actor
|
|
||||||
std::vector<PathDistance> nodeDistances;
|
|
||||||
for (unsigned int counter = 0; counter < pathgrid->mPoints.size(); counter++)
|
|
||||||
{
|
|
||||||
float distance = (npcPos - PathFinder::MakeOsgVec3(pathgrid->mPoints[counter])).length2();
|
|
||||||
nodeDistances.push_back(std::make_pair(distance, &pathgrid->mPoints.at(counter)));
|
|
||||||
}
|
|
||||||
std::sort(nodeDistances.begin(), nodeDistances.end(), sortByDistance);
|
|
||||||
|
|
||||||
// make closest node the current node
|
|
||||||
mCurrentNode = *nodeDistances[0].second;
|
|
||||||
|
|
||||||
// give Actor a 2nd node to walk to
|
|
||||||
mAllowedNodes.push_back(*nodeDistances[1].second);
|
|
||||||
}
|
|
||||||
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
mStoredAvailableNodes = true; // set only if successful in finding allowed nodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AiWander::sortByDistance(const PathDistance& left, const PathDistance& right)
|
|
||||||
{
|
|
||||||
return left.first < right.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
@ -120,13 +120,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
/// 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];
|
||||||
|
|
||||||
/// record distances of pathgrid point nodes to actor
|
|
||||||
/// first value is distance between actor and node, second value is PathGrid node
|
|
||||||
typedef std::pair<float, const ESM::Pathgrid::Point*> PathDistance;
|
|
||||||
|
|
||||||
/// used to sort array of PathDistance objects into ascending order
|
|
||||||
static bool sortByDistance(const PathDistance& left, const PathDistance& right);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
void clearPath();
|
void clearPath();
|
||||||
|
|
||||||
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
|
|
||||||
const MWWorld::CellStore* cell, bool allowShortcuts = true);
|
|
||||||
|
|
||||||
bool checkPathCompleted(float x, float y, float tolerance=32.f);
|
bool checkPathCompleted(float x, float y, float tolerance=32.f);
|
||||||
///< \Returns true if we are within \a tolerance units of the last path point.
|
///< \Returns true if we are within \a tolerance units of the last path point.
|
||||||
|
|
||||||
|
@ -92,6 +89,8 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
|
||||||
|
const MWWorld::CellStore* cell, bool allowShortcuts = true);
|
||||||
|
|
||||||
std::list<ESM::Pathgrid::Point> mPath;
|
std::list<ESM::Pathgrid::Point> mPath;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue