+
+ if (apt->getDynamics()->getGroundNetwork()->exists())
+ {
+ intVec ids;
+ int runwayId = apt->getDynamics()->getGroundNetwork()->findNearestNode(lat2,
+ lon2);
+
+
+ // A negative gateId indicates an overflow parking, use a
+ // fallback mechanism for this.
+ // Starting from gate 0 in this case is a bit of a hack
+ // which requires a more proper solution later on.
+ //FGTaxiRoute route;
+ if (taxiRoute)
+ delete taxiRoute;
+ taxiRoute = new FGTaxiRoute;
+ if (gateId >= 0)
+ *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(gateId,
+ runwayId);
+ else
+ *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(0, runwayId);
+ intVecIterator i;
+
+ if (taxiRoute->empty()) {
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = latitude;
+ wpt->longitude = longitude;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ wpt->routeIndex = 0;
+ waypoints.push_back(wpt);
+
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Runway Takeoff";
+ wpt->latitude = lat2;
+ wpt->longitude = lon2;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ wpt->routeIndex = 0;
+ waypoints.push_back(wpt);
+ } else {
+ int node;
+ taxiRoute->first();
+ bool isPushBackPoint = false;
+ if (firstFlight) {
+ // If this is called during initialization, randomly
+ // skip a number of waypoints to get a more realistic
+ // taxi situation.
+ isPushBackPoint = true;
+ int nrWaypoints = taxiRoute->size();
+ nrWaypointsToSkip = rand() % nrWaypoints;
+ // but make sure we always keep two active waypoints
+ // to prevent a segmentation fault
+ for (int i = 0; i < nrWaypointsToSkip-2; i++) {
+ isPushBackPoint = false;
+ taxiRoute->next(&node);
+ }
+ } else {
+ //chop off the first two waypoints, because
+ // those have already been created
+ // by create pushback
+ int size = taxiRoute->size();
+ if (size > 2) {
+ taxiRoute->next(&node);
+ taxiRoute->next(&node);
+ }
+ }
+ int route;
+ while(taxiRoute->next(&node, &route))
+ {
+ //FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findSegment(node)->getEnd();
+ char buffer[10];
+ snprintf (buffer, 10, "%d", node);
+ FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
+ //ids.pop_back();
+ wpt = new waypoint;
+ wpt->name = string(buffer); // fixme: should be the name of the taxiway
+ wpt->latitude = tn->getLatitude();
+ wpt->longitude = tn->getLongitude();
+ // Elevation is currently disregarded when on_ground is true
+ // because the AIModel obtains a periodic ground elevation estimate.
+ wpt->altitude = apt->getElevation();
+ if (isPushBackPoint) {
+ wpt->speed = -10;
+ isPushBackPoint = false;
+ }
+ else {
+ wpt->speed = 15;
+ }
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ wpt->routeIndex = route;
+ waypoints.push_back(wpt);
+ }
+ //cerr << endl;
+ // finally, rewind the taxiRoute object to the point where we started
+ // generating the Flightplan, for AI use.
+ // This is a bit tricky, because the
+ taxiRoute->first();
+ if (firstFlight) {
+ for (int i = 0; i < nrWaypointsToSkip-1; i++) {
+ taxiRoute->next(&node);
+ }
+ } else {
+ int size = taxiRoute->size();
+ if (size > 2) {
+ //taxiRoute->next(&node);
+ //taxiRoute->next(&node);
+ //taxiRoute->next(&node);
+ }
+ }
+ } // taxiRoute not empty
+ }
+ else
+ {
+ // This is the fallback mechanism, in case no ground network is available
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Airport Center";
+ wpt->latitude = apt->getLatitude();
+ wpt->longitude = apt->getLongitude();
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ wpt->routeIndex = 0;
+ waypoints.push_back(wpt);
+
+ //Add the runway startpoint;
+ wpt = new waypoint;
+ wpt->name = "Runway Takeoff";
+ wpt->latitude = lat2;
+ wpt->longitude = lon2;
+ wpt->altitude = apt->getElevation();
+ wpt->speed = 15;
+ wpt->crossat = -10000;
+ wpt->gear_down = true;
+ wpt->flaps_down= true;
+ wpt->finished = false;
+ wpt->on_ground = true;
+ wpt->routeIndex = 0;
+ waypoints.push_back(wpt);
+ }