- // Erase all existing waypoints.
- // wpt_vector_iterator i= waypoints.begin();
- //resetWaypoints();
- //int currWpt = wpt_iterator - waypoints.begin();
- if (direction == 1)
- {
- //string name;
- // "NOTE: this is currently fixed to "com" for commercial traffic
- // Should be changed to be used dynamically to allow "gen" and "mil"
- // as well
- apt->getDynamics()->getActiveRunway("com", 1, activeRunway);
- if (!(globals->get_runways()->search(apt->getId(),
- activeRunway,
- &rwy)))
- {
- cout << "Failed to find runway for " << apt->getId() << endl;
- // Hmm, how do we handle a potential error like this?
- exit(1);
- }
- //string test;
- //apt->getActiveRunway(string("com"), 1, test);
- //exit(1);
-
- 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);
- //int currId = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
- //exit(1);
-
- // A negative gateId indicates an overflow parking, use a
- // fallback mechanism for this.
- // Starting from gate 0 is a bit of a hack...
- FGTaxiRoute route;
- if (gateId >= 0)
- route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, runwayId);
- else
- route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(0, runwayId);
- intVecIterator i;
- //cerr << "creating route : ";
- // No route found: go from gate directly to runway
- if (route.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;
- 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;
- waypoints.push_back(wpt);
- } else {
- int node;
- route.first();
- while(route.next(&node))
- {
- //i = ids.end()-1;
- //cerr << "Creating Node: " << node << endl;
- FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
- //ids.pop_back();
- wpt = new waypoint;
- wpt->name = "taxiway"; // fixme: should be the name of the taxiway
- wpt->latitude = tn->getLatitude();
- wpt->longitude = tn->getLongitude();
- wpt->altitude = apt->getElevation(); // should maybe be tn->elev too
- wpt->speed = 15;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- waypoints.push_back(wpt);
- }
- cerr << endl;
- }
- //exit(1);
- }
- else
- {
- //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;
- 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;
- waypoints.push_back(wpt);
- //wpt = new waypoint;
- //wpt->finished = false;
- //waypoints.push_back(wpt); // add one more to prevent a segfault.
- }
- }
- else // Landing taxi
- {
- //string name;
- // "NOTE: this is currently fixed to "com" for commercial traffic
- // Should be changed to be used dynamically to allow "gen" and "mil"
- // as well
- //apt->getActiveRunway("com", 1, name);
- //if (!(globals->get_runways()->search(apt->getId(),
- // name,
- // &rwy)))
- //{//
- //cout << "Failed to find runway for " << apt->getId() << endl;
- // Hmm, how do we handle a potential error like this?
- // exit(1);
- // }
- //string test;
- //apt->getActiveRunway(string("com"), 1, test);
- //exit(1);
-
- //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 );
- apt->getDynamics()->getAvailableParking(&lat, &lon, &heading, &gateId, radius, fltType, acType, airline);
- heading += 180.0;
- if (heading > 360)
- heading -= 360;
- geo_direct_wgs_84 ( 0, lat, lon, heading,
- 100,
- &lat2, &lon2, &az2 );
- double lat3 = (*(waypoints.end()-1))->latitude;
- double lon3 = (*(waypoints.end()-1))->longitude;
- cerr << (*(waypoints.end()-1))->name << endl;
- if (apt->getDynamics()->getGroundNetwork()->exists())
- {
- intVec ids;
- int runwayId = apt->getDynamics()->getGroundNetwork()->findNearestNode(lat3, lon3);
- //int currId = apt->getGroundNetwork()->findNearestNode(latitude,longitude);
- //exit(1);
-
- // A negative gateId indicates an overflow parking, use a
- // fallback mechanism for this.
- // Starting from gate 0 is a bit of a hack...
- FGTaxiRoute route;
- if (gateId >= 0)
- route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, gateId);
- else
- route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 0);
- intVecIterator i;
- //cerr << "creating route : ";
- // No route found: go from gate directly to runway
- if (route.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;
- 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;
- waypoints.push_back(wpt);
- } else {
- int node;
- route.first();
- while(route.next(&node))
- {
- //i = ids.end()-1;
- //cerr << "Creating Node: " << node << endl;
- FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
- //ids.pop_back();
- wpt = new waypoint;
- wpt->name = "taxiway"; // fixme: should be the name of the taxiway
- wpt->latitude = tn->getLatitude();
- wpt->longitude = tn->getLongitude();
- wpt->altitude = apt->getElevation(); // should maybe be tn->elev too
- wpt->speed = 15;
- wpt->crossat = -10000;
- wpt->gear_down = true;
- wpt->flaps_down= true;
- wpt->finished = false;
- wpt->on_ground = true;
- waypoints.push_back(wpt);
- }
- cerr << endl;
- }
- //exit(1);
- }
- else
- {
- //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;
- waypoints.push_back(wpt);
-
- }
-
-
-
-
- // Add the final destination waypoint
- wpt = new waypoint;
- wpt->name = "Begin Parking"; //apt->getId(); //wpt_node->getStringValue("name", "END");
- 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;
- waypoints.push_back(wpt);