]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreateCruise.cxx
Merge branch 'maint2' into next
[flightgear.git] / src / AIModel / AIFlightPlanCreateCruise.cxx
index 28f0b8de677dc162a666f3eb4eb4e42c0a4a5c3e..d2fc62473be08e4e2b5caf54b63f29cc018a007d 100755 (executable)
  *
  *
  **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <fstream>
 #include <iostream>
 #include "AIFlightPlan.hxx"
@@ -27,6 +32,7 @@
 
 #include <Navaids/awynet.hxx>
 #include <Airports/runways.hxx>
+#include <Airports/dynamics.hxx>
 
 #include <Environment/environment_mgr.hxx>
 #include <Environment/environment.hxx>
@@ -309,59 +315,16 @@ void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
                                  double longitude, double speed, 
                                  double alt, const string& fltType)
 {
-  double wind_speed;
-  double wind_heading;
-  double heading;
-  double lat, lon, az;
-  double lat2, lon2, az2;
-  double azimuth;
   waypoint *wpt;
-
-  wpt = new waypoint;
-  wpt->name      = "Cruise"; //wpt_node->getStringValue("name", "END");
-  wpt->latitude  = latitude;
-  wpt->longitude = longitude;
-  wpt->altitude  = alt;
-  wpt->speed     = speed; 
-  wpt->crossat   = -10000;
-  wpt->gear_down = false;
-  wpt->flaps_down= false;
-  wpt->finished  = false;
-  wpt->on_ground = false;
-  wpt->routeIndex = 0;
+  wpt = createInAir("Cruise", SGGeod::fromDeg(longitude, latitude), alt, speed);
   waypoints.push_back(wpt); 
   
   string rwyClass = getRunwayClassFromTrafficType(fltType);
   arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway);
-  if (!(globals->get_runways()->search(arr->getId(), 
-                                      activeRunway, 
-                                      &rwy)))
-    {
-      SG_LOG(SG_INPUT, SG_ALERT, "Failed to find runway " << 
-            activeRunway << 
-            " at airport     " << arr->getId()<< " of class " << rwyClass << " (5)");
-      exit(1);
-    }
-  heading = rwy._heading;
-  azimuth = heading + 180.0;
-  while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
-  
+  rwy = arr->getRunwayByIdent(activeRunway);
+  // begin descent 110km out
+  SGGeod beginDescentPoint = rwy->pointOnCenterline(-110000);
   
-  geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, azimuth, 
-                     110000,
-                     &lat2, &lon2, &az2 );
-  wpt = new waypoint;
-  wpt->name      = "BOD";
-  wpt->latitude  = lat2;
-  wpt->longitude = lon2;
-  wpt->altitude  = alt;
-  wpt->speed     = speed; 
-  wpt->crossat   = alt;
-  wpt->gear_down = false;
-  wpt->flaps_down= false;
-  wpt->finished  = false;
-  wpt->on_ground = false;
-  wpt->routeIndex = 0;
+  wpt = createInAir("BOD", beginDescentPoint, alt, speed);
   waypoints.push_back(wpt); 
 }