return true when done calculating
| 2320 | |
| 2321 | // return true when done calculating |
| 2322 | bool 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; |
nothing calls this directly
no test coverage detected