//----------------------------------------------------------------------------- // Purpose: Adds addRoute to the end of oldRoute //----------------------------------------------------------------------------- void AddWaypointLists(AI_Waypoint_t *oldRoute, AI_Waypoint_t *addRoute) { // Add to the end of the route AI_Waypoint_t *waypoint = oldRoute; while (waypoint->GetNext()) { waypoint = waypoint->GetNext(); } waypoint->ModifyFlags( bits_WP_TO_GOAL, false ); // Check for duplication, but copy the type if (waypoint->iNodeID != NO_NODE && waypoint->iNodeID == addRoute->iNodeID ) { // waypoint->iWPType = addRoute->iWPType; <<TODO>> found case where this was bad AI_Waypoint_t *pNext = addRoute->GetNext(); delete addRoute; waypoint->SetNext(pNext); } else { waypoint->SetNext(addRoute); } while (waypoint->GetNext()) { waypoint = waypoint->GetNext(); } waypoint->ModifyFlags( bits_WP_TO_GOAL, true ); }
//----------------------------------------------------------------------------- // Purpose: Given an array of parentID's and endID, contruct a linked // list of waypoints through those parents //----------------------------------------------------------------------------- AI_Waypoint_t* CAI_Pathfinder::MakeRouteFromParents( int *parentArray, int endID ) { AI_Waypoint_t *pOldWaypoint = NULL; AI_Waypoint_t *pNewWaypoint = NULL; int currentID = endID; CAI_Node **pAInode = GetNetwork()->AccessNodes(); while (currentID != NO_NODE) { // Try to link it to the previous waypoint int prevID = parentArray[currentID]; int destID; if (prevID != NO_NODE) { destID = prevID; } else { // If we have no previous node, then use the next node if ( !pOldWaypoint ) return NULL; destID = pOldWaypoint->iNodeID; } Navigation_t waypointType = ComputeWaypointType( pAInode, currentID, destID ); // BRJ 10/1/02 // FIXME: It appears potentially possible for us to compute waypoints // here which the NPC is not capable of traversing (because // pNPC->CapabilitiesGet() in ComputeWaypointType() above filters it out). // It's also possible if none of the lines have an appropriate DestNodeID. // Um, shouldn't such a waypoint not be allowed?!?!? Assert( waypointType != NAV_NONE ); pNewWaypoint = new AI_Waypoint_t( pAInode[currentID]->GetPosition(GetHullType()), pAInode[currentID]->GetYaw(), waypointType, bits_WP_TO_NODE, currentID ); // Link it up... pNewWaypoint->SetNext( pOldWaypoint ); pOldWaypoint = pNewWaypoint; currentID = prevID; } return pOldWaypoint; }