MCPcopy Create free account
hub / github.com/assaultcube/AC / AStar

Method AStar

source/src/bot/bot_waypoint.cpp:2322–2595  ·  view source on GitHub ↗

return true when done calculating

Source from the content-addressed store, hash-verified

2320
2321// return true when done calculating
2322bool CBot::AStar()
2323{
2324 if (!m_pCurrentGoalWaypoint || !m_pCurrentWaypoint)
2325 {
2326 if (m_bCalculatingAStarPath)
2327 {
2328 m_bCalculatingAStarPath = false;
2329 BotManager.m_sUsingAStarBotsCount--;
2330 }
2331 return true;
2332 }
2333
2334 // Ideas by PMB :
2335 // * Make locals static to speed up a bit
2336 // * MaxCycles per frame and make it fps dependent
2337
2338 static int iMaxCycles;
2339 static int iCurrentCycles;
2340 static short newg;
2341 static waypoint_s *n, *n2;
2342 static TLinkedList<node_s *>::node_s *pPath = NULL;
2343 static bool bPathFailed;
2344
2345 iMaxCycles = BotManager.m_iFrameTime / 10;
2346 if (iMaxCycles < 10) iMaxCycles = 10;
2347 //condebug("MaxCycles: %d", iMaxCycles);
2348 iCurrentCycles = 0;
2349 bPathFailed = false;
2350
2351 if (!m_bCalculatingAStarPath)
2352 {
2353 if ((BotManager.m_sUsingAStarBotsCount+1) > BotManager.m_sMaxAStarBots)
2354 {
2355 return true;
2356 }
2357
2358 BotManager.m_sUsingAStarBotsCount++;
2359
2360 CleanAStarLists(false);
2361
2362 m_pCurrentWaypoint->g[0] = m_pCurrentWaypoint->g[1] = 0;
2363 m_pCurrentWaypoint->pParent[0] = m_pCurrentWaypoint->pParent[1] = NULL;
2364 m_pCurrentGoalWaypoint->g[0] = m_pCurrentGoalWaypoint->g[1] = 0;
2365 m_pCurrentGoalWaypoint->pParent[0] = m_pCurrentGoalWaypoint->pParent[1] = NULL;
2366
2367 m_AStarNodeList.DeleteAllNodes();
2368
2369 m_AStarOpenList[0].Clear();
2370 m_AStarOpenList[1].Clear();
2371 m_AStarClosedList[0].DeleteAllNodes();
2372 m_AStarClosedList[1].DeleteAllNodes();
2373
2374 m_AStarOpenList[0].AddEntry(m_pCurrentWaypoint,
2375 GetDistance(m_pCurrentGoalWaypoint->pNode->v_origin));
2376 m_AStarOpenList[1].AddEntry(m_pCurrentGoalWaypoint,
2377 GetDistance(m_pCurrentGoalWaypoint->pNode->v_origin));
2378
2379 m_pCurrentWaypoint->bIsOpen[0] = m_pCurrentGoalWaypoint->bIsOpen[1] = true;

Callers

nothing calls this directly

Calls 11

GetDistanceFunction · 0.85
condebugFunction · 0.85
DeleteAllNodesMethod · 0.80
AddEntryMethod · 0.80
PushNodeMethod · 0.80
AddNodeMethod · 0.80
ClearMethod · 0.45
EmptyMethod · 0.45
PopMethod · 0.45
IsInListMethod · 0.45
GetFirstMethod · 0.45

Tested by

no test coverage detected