| 1482 | */ |
| 1483 | |
| 1484 | int CNavigator::GetNearestNode( gentity_t *ent, int lastID, int flags, int targetID ) |
| 1485 | { |
| 1486 | int bestNode = NODE_NONE; |
| 1487 | //Must have nodes |
| 1488 | if ( m_nodes.size() == 0 ) |
| 1489 | return NODE_NONE; |
| 1490 | |
| 1491 | if ( targetID == NODE_NONE ) |
| 1492 | { |
| 1493 | //Try and find an early match using our last node |
| 1494 | bestNode = TestBestFirst( ent, lastID, flags ); |
| 1495 | |
| 1496 | if ( bestNode != NODE_NONE ) |
| 1497 | return bestNode; |
| 1498 | }//else can't rely on testing last, we want best to targetID |
| 1499 | |
| 1500 | ///////////////////////////////////////////////// |
| 1501 | |
| 1502 | #define MAX_Z_DELTA 18 |
| 1503 | |
| 1504 | ///////////////////////////////////////////////// |
| 1505 | |
| 1506 | nodeChain_l nodeChain; |
| 1507 | nodeChain_l::iterator nci; |
| 1508 | |
| 1509 | //Collect all nodes within a certain radius |
| 1510 | CollectNearestNodes( ent->currentOrigin, NODE_COLLECT_RADIUS, NODE_COLLECT_MAX, nodeChain ); |
| 1511 | |
| 1512 | vec3_t position; |
| 1513 | int radius; |
| 1514 | int dist, bestDist = Q3_INFINITE; |
| 1515 | CNode *node; |
| 1516 | |
| 1517 | //Look through all nodes |
| 1518 | STL_ITERATE( nci, nodeChain ) |
| 1519 | { |
| 1520 | node = m_nodes[(*nci).nodeID]; |
| 1521 | |
| 1522 | node->GetPosition( position ); |
| 1523 | |
| 1524 | radius = node->GetRadius(); |
| 1525 | |
| 1526 | if ( NodeFailed( ent, (*nci).nodeID ) ) |
| 1527 | { |
| 1528 | continue; |
| 1529 | } |
| 1530 | //Are we within the known clear radius of this node? |
| 1531 | if ( (signed)(*nci).distance < (radius*radius) ) |
| 1532 | { |
| 1533 | //Do a z-difference sanity check |
| 1534 | if ( fabs( position[2] - ent->currentOrigin[2] ) < MAX_Z_DELTA ) |
| 1535 | { |
| 1536 | //Found one |
| 1537 | return (*nci).nodeID; |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | //We're not *within* this node, so... |
no test coverage detected