]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreate.cxx
std:: namespace fixes, AIBase cleanup.
[flightgear.git] / src / AIModel / AIFlightPlanCreate.cxx
index 92b901bcedc3efbfd12156b46290e6a6f68da4c0..9ec77c2c38e56f6c2be1ab4e84966701585ed35f 100644 (file)
 #endif
 
 #include <cstdlib>
+#include <cstdio>
 
 #include "AIFlightPlan.hxx"
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
 
-#include <Airports/simple.hxx>
+#include <Airports/airport.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
 #include "AIAircraft.hxx"
@@ -40,6 +41,7 @@
 #include <FDM/LaRCsim/basic_aero.h>
 #include <Navaids/navrecord.hxx>
 
+using std::string;
 
 /* FGAIFlightPlan::create()
  * dynamically create a flight plan for AI traffic, based on data provided by the
@@ -103,6 +105,7 @@ bool FGAIFlightPlan::create(FGAIAircraft * ac, FGAirport * dep,
         SG_LOG(SG_AI, SG_ALERT,
                "AIFlightPlan::create() attempting to create unknown leg"
                " this is probably an internal program error");
+        break;
     }
     wpt_iterator = waypoints.begin() + currWpt;
     //don't  increment leg right away, but only once we pass the actual last waypoint that was created.
@@ -225,7 +228,7 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight,
       }
     }
 
-    string rwyClass = getRunwayClassFromTrafficType(fltType);
+    const string& rwyClass = getRunwayClassFromTrafficType(fltType);
 
     // Only set this if it hasn't been set by ATC already.
     if (activeRunway.empty()) {
@@ -310,7 +313,7 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight,
     //cerr << "Building taxi route" << endl;
     while (taxiRoute.next(&node)) {
         char buffer[10];
-        snprintf(buffer, 10, "%lld", node);
+        snprintf(buffer, 10, "%lld", (long long int) node);
         FGTaxiNode *tn =
             apt->getDynamics()->getGroundNetwork()->findNode(node);
         FGAIWaypoint *wpt =
@@ -415,7 +418,7 @@ bool FGAIFlightPlan::createLandingTaxi(FGAIAircraft * ac, FGAirport * apt,
     for (int i = 0; i < size - 2; i++) {
         taxiRoute.next(&node);
         char buffer[10];
-        snprintf(buffer, 10, "%lld", node);
+        snprintf(buffer, 10, "%lld",  (long long int) node);
         FGTaxiNode *tn = gn->findNode(node);
         FGAIWaypoint *wpt =
             createOnGround(ac, buffer, tn->geod(), apt->getElevation(),
@@ -478,7 +481,7 @@ bool FGAIFlightPlan::createTakeOff(FGAIAircraft * ac, bool firstFlight,
     // NOTE: DT (2009-01-18: IIRC, this is currently already the case, 
     // because the getActive runway function takes care of that.
     if (firstFlight) {
-        string rwyClass = getRunwayClassFromTrafficType(fltType);
+        const string& rwyClass = getRunwayClassFromTrafficType(fltType);
         double heading = ac->getTrafficRef()->getCourse();
         apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
                                             heading);
@@ -539,7 +542,7 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight,
     double vClimb = ac->getPerformance()->vClimb();
   
     if (firstFlight) {
-        string rwyClass = getRunwayClassFromTrafficType(fltType);
+        const string& rwyClass = getRunwayClassFromTrafficType(fltType);
         double heading = ac->getTrafficRef()->getCourse();
         apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
                                             heading);
@@ -592,7 +595,7 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
     double vApproach = ac->getPerformance()->vApproach();
 
     //Beginning of Descent 
-    string rwyClass = getRunwayClassFromTrafficType(fltType);
+    const string& rwyClass = getRunwayClassFromTrafficType(fltType);
     double heading = ac->getTrafficRef()->getCourse();
     apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway,
                                         heading);
@@ -844,7 +847,7 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt,
     if (reposition) {
         double tempDistance;
         //double minDistance = HUGE_VAL;
-        string wptName;
+        //string wptName;
         tempDistance = SGGeodesy::distanceM(current, initialTarget);
         time_t eta =
             tempDistance / ((vDescent * SG_NM_TO_METER) / 3600.0) + now;
@@ -1044,21 +1047,21 @@ bool FGAIFlightPlan::createParking(FGAIAircraft * ac, FGAirport * apt,
  * - ul (ultralight: I can imagine that these may share a runway with ga on some airports)
  * - mil (all military traffic)
  */
-string FGAIFlightPlan::getRunwayClassFromTrafficType(string fltType)
+const char* FGAIFlightPlan::getRunwayClassFromTrafficType(const string& fltType)
 {
     if ((fltType == "gate") || (fltType == "cargo")) {
-        return string("com");
+        return "com";
     }
     if (fltType == "ga") {
-        return string("gen");
+        return "gen";
     }
     if (fltType == "ul") {
-        return string("ul");
+        return "ul";
     }
     if ((fltType == "mil-fighter") || (fltType == "mil-transport")) {
-        return string("mil");
+        return "mil";
     }
-    return string("com");
+    return "com";
 }