- double heading;
- double lat, lon;
- double lat2, lon2, az2;
- waypoint *wpt;
-
- int nrWaypointsToSkip;
-
- if (direction == 1)
- {
- // If this function is called during initialization,
- // make sure we obtain a valid gate ID first
- // and place the model at the location of the gate.
- if (firstFlight)
- {
- if (!(apt->getDynamics()->getAvailableParking(&lat, &lon,
- &heading, &gateId,
- radius, fltType,
- acType, airline)))
- {
- SG_LOG(SG_INPUT, SG_WARN, "Could not find parking for a " <<
- acType <<
- " of flight type " << fltType <<
- " of airline " << airline <<
- " at airport " << apt->getId());
- }
- //waypoint *wpt = new waypoint;
- //wpt->name = "park";
- //wpt->latitude = lat;
- //wpt->longitude = lon;
- //wpt->altitude = apt->getElevation();
- //wpt->speed = -10;
- //wpt->crossat = -10000;
- //wpt->gear_down = true;
- //wpt->flaps_down= true;
- //wpt->finished = false;
- //wpt->on_ground = true;
- //waypoints.push_back(wpt);
- }
- string rwyClass = getRunwayClassFromTrafficType(fltType);
- apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway);
- if (!(globals->get_runways()->search(apt->getId(),
- activeRunway,
- &rwy)))
- {
- SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " <<
- activeRunway <<
- " at airport " << apt->getId() << " of class " << rwyClass << " (1)");
- exit(1);
- }
-
- // Determine the beginning of he runway
- heading = rwy._heading;
- double azimuth = heading + 180.0;
- while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
- geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth,
- rwy._length * SG_FEET_TO_METER * 0.5 - 5.0,
- &lat2, &lon2, &az2 );
-
- 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;
- 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);
- }