mirror of
https://github.com/ENSL/NS.git
synced 2024-11-10 07:11:38 +00:00
Fixed potential hang in path finding
* Fixed potential infinite loop in path finding * Fixed bots sometimes getting stuck on doors permanently
This commit is contained in:
parent
4efd22b709
commit
936ef5d609
2 changed files with 17 additions and 12 deletions
|
@ -1278,11 +1278,18 @@ dtStatus dtNavMeshQuery::getPathToNode(dtNode* endNode, dtPolyRef* path, int* pa
|
|||
// Find the length of the entire path.
|
||||
dtNode* curNode = endNode;
|
||||
int length = 0;
|
||||
int maxLength = maxPath * 2;
|
||||
|
||||
do
|
||||
{
|
||||
length++;
|
||||
curNode = m_nodePool->getNodeAtIdx(curNode->pidx);
|
||||
} while (curNode);
|
||||
|
||||
// Check to prevent infinite recursion
|
||||
dtNode* NewNode = m_nodePool->getNodeAtIdx(curNode->pidx);
|
||||
if (NewNode == curNode) { return DT_FAILURE; }
|
||||
|
||||
curNode = NewNode;
|
||||
} while (curNode && length < maxLength);
|
||||
|
||||
// If the path cannot be fully stored then advance to the last node we will be able to store.
|
||||
curNode = endNode;
|
||||
|
|
|
@ -1863,7 +1863,6 @@ dtStatus FindPathClosestToPoint(const nav_profile& NavProfile, const Vector From
|
|||
status = m_navQuery->findNearestPoly(pStartPos, pExtents, m_navFilter, &StartPoly, StartNearest);
|
||||
if ((status & DT_FAILURE) || (status & DT_STATUS_DETAIL_MASK))
|
||||
{
|
||||
//BotSay(pBot, "findNearestPoly start failed!");
|
||||
return (status & DT_STATUS_DETAIL_MASK); // couldn't find a polygon
|
||||
}
|
||||
|
||||
|
@ -1871,7 +1870,6 @@ dtStatus FindPathClosestToPoint(const nav_profile& NavProfile, const Vector From
|
|||
status = m_navQuery->findNearestPoly(pEndPos, pExtents, m_navFilter, &EndPoly, EndNearest);
|
||||
if ((status & DT_FAILURE) || (status & DT_STATUS_DETAIL_MASK))
|
||||
{
|
||||
//BotSay(pBot, "findNearestPoly end failed!");
|
||||
return (status & DT_STATUS_DETAIL_MASK); // couldn't find a polygon
|
||||
}
|
||||
|
||||
|
@ -2481,17 +2479,17 @@ void CheckAndHandleDoorObstruction(AvHAIPlayer* pBot)
|
|||
|
||||
Vector NearestPoint = UTIL_GetClosestPointOnEntityToLocation(pBot->Edict->v.origin, BlockingDoorEdict);
|
||||
|
||||
// If the door is in the process of opening or closing, let it finish before doing anything else
|
||||
if (BlockingDoor->m_toggle_state == TS_GOING_UP || BlockingDoor->m_toggle_state == TS_GOING_DOWN)
|
||||
{
|
||||
if (IsPlayerTouchingEntity(pBot->Edict, BlockingDoorEdict))
|
||||
{
|
||||
Vector MoveDir = UTIL_GetVectorNormal2D(pBot->Edict->v.origin - NearestPoint);
|
||||
Vector MoveDir = UTIL_GetVectorNormal2D(CurrentPathNode.Location - CurrentPathNode.FromLocation);
|
||||
|
||||
pBot->desiredMovementDir = MoveDir;
|
||||
return;
|
||||
}
|
||||
|
||||
// If the door is in the process of opening or closing, let it finish before doing anything else
|
||||
if (BlockingDoor->m_toggle_state == TS_GOING_UP || BlockingDoor->m_toggle_state == TS_GOING_DOWN)
|
||||
{
|
||||
if (vDist2DSq(pBot->Edict->v.origin, NearestPoint) < sqrf(UTIL_MetresToGoldSrcUnits(1.5f)))
|
||||
{
|
||||
// Wait for the door to finish opening
|
||||
|
|
Loading…
Reference in a new issue