]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlan.cxx
commradio: improvements for atis speech
[flightgear.git] / src / AIModel / AIFlightPlan.cxx
index 23401fe111591c216dfe286b589aefe0183cf653..eb0e6cc1f4dc03cbd3149682b64c98469d708bd1 100644 (file)
@@ -33,7 +33,7 @@
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/fg_init.hxx>
-#include <Airports/simple.hxx>
+#include <Airports/airport.hxx>
 #include <Airports/dynamics.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/groundnetwork.hxx>
@@ -45,6 +45,7 @@
 #include "AIAircraft.hxx"
 
 using std::cerr;
+using std::string;
 
 FGAIWaypoint::FGAIWaypoint() {
   speed       = 0;
@@ -96,35 +97,33 @@ void FGAIWaypoint::setAltitude(double alt)
   pos.setElevationFt(alt);
 }
 
-FGAIFlightPlan::FGAIFlightPlan()
+FGAIFlightPlan::FGAIFlightPlan() :
+    sid(NULL),
+    repeat(false),
+    distance_to_go(0),
+    lead_distance(0),
+    leadInAngle(0),
+    start_time(0),
+    arrivalTime(0),
+    leg(0),
+    lastNodeVisited(0),
+    isValid(true)
 {
-    sid             = 0;
-    repeat          = false;
-    distance_to_go  = 0;
-    lead_distance   = 0;
-    start_time      = 0;
-    arrivalTime     = 0;
-    leg             = 10;
-    lastNodeVisited = 0;
-  //  taxiRoute       = 0;
     wpt_iterator    = waypoints.begin();
-    isValid         = true;
 }
 
-FGAIFlightPlan::FGAIFlightPlan(const string& filename)
+FGAIFlightPlan::FGAIFlightPlan(const string& filename) :
+    sid(NULL),
+    repeat(false),
+    distance_to_go(0),
+    lead_distance(0),
+    leadInAngle(0),
+    start_time(0),
+    arrivalTime(0),
+    leg(10),
+    lastNodeVisited(0),
+    isValid(parseProperties(filename))
 {
-  sid               = 0;
-  repeat            = false;
-  distance_to_go    = 0;
-  lead_distance     = 0;
-  start_time        = 0;
-  arrivalTime       = 0;
-  leg               = 10;
-  lastNodeVisited   = 0;
-//  taxiRoute         = 0;
-
-
-  isValid = parseProperties(filename);
 }
 
 
@@ -149,19 +148,19 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
                                const string& fltType,
                                const string& acType,
                                const string& airline) :
-  departure(dep),
-  arrival(arr)
+    sid(NULL),
+    repeat(false),
+    distance_to_go(0),
+    lead_distance(0),
+    leadInAngle(0),
+    start_time(start),
+    arrivalTime(0),
+    leg(10),
+    lastNodeVisited(0),
+    isValid(false),
+    departure(dep),
+    arrival(arr)
 {
-  sid               = 0;
-  repeat            = false;
-  distance_to_go    = 0;
-  lead_distance     = 0;
-  start_time        = start;
-  arrivalTime       = 0;
-  leg               = 10;
-  lastNodeVisited   = 0;
- // taxiRoute         = 0;
-
   if (parseProperties(p)) {
     isValid = true;
   } else {
@@ -288,21 +287,21 @@ FGAIWaypoint* const FGAIFlightPlan::getNextWaypoint( void ) const
 
 void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
 {
-  if (eraseWaypoints)
+    if (eraseWaypoints)
     {
-      if (wpt_iterator == waypoints.begin())
-       wpt_iterator++;
-      else
-       {
-         delete *(waypoints.begin());
-         waypoints.erase(waypoints.begin());
-         wpt_iterator = waypoints.begin();
-         wpt_iterator++;
-       }
+        if (wpt_iterator == waypoints.begin())
+            wpt_iterator++;
+        else
+        if (!waypoints.empty())
+        {
+            delete *(waypoints.begin());
+            waypoints.erase(waypoints.begin());
+            wpt_iterator = waypoints.begin();
+            wpt_iterator++;
+        }
     }
-  else
-    wpt_iterator++;
-
+    else
+        wpt_iterator++;
 }
 
 void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
@@ -312,9 +311,10 @@ void FGAIFlightPlan::DecrementWaypoint(bool eraseWaypoints )
         if (wpt_iterator == waypoints.end())
             wpt_iterator--;
         else
+        if (!waypoints.empty())
         {
-            delete *(waypoints.end());
-            waypoints.erase(waypoints.end());
+            delete *(waypoints.end()-1);
+            waypoints.erase(waypoints.end()-1);
             wpt_iterator = waypoints.end();
             wpt_iterator--;
         }
@@ -399,6 +399,7 @@ void FGAIFlightPlan::deleteWaypoints()
   for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end();i++)
     delete (*i);
   waypoints.clear();
+  wpt_iterator = waypoints.begin();
 }
 
 // Delete all waypoints except the last, 
@@ -449,7 +450,7 @@ int FGAIFlightPlan::getRouteIndex(int i) {
     return 0;
 }
 
-double FGAIFlightPlan::checkTrackLength(const string& wptName) {
+double FGAIFlightPlan::checkTrackLength(const string& wptName) const {
     // skip the first two waypoints: first one is behind, second one is partially done;
     double trackDistance = 0;
     wpt_vector_iterator wptvec = waypoints.begin();
@@ -473,7 +474,7 @@ void FGAIFlightPlan::shortenToFirst(unsigned int number, string name)
     (waypoints.back())->setName((waypoints.back())->getName() + name);
 }
 
-void FGAIFlightPlan::setGate(ParkingAssignment pka)
+void FGAIFlightPlan::setGate(const ParkingAssignment& pka)
 {
   gate = pka;
 }
@@ -482,3 +483,13 @@ FGParking* FGAIFlightPlan::getParkingGate()
 {
   return gate.parking();
 }
+
+FGAirportRef FGAIFlightPlan::departureAirport() const
+{
+    return departure;
+}
+
+FGAirportRef FGAIFlightPlan::arrivalAirport() const
+{
+    return arrival;
+}