]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlan.cxx
commradio: improvements for atis speech
[flightgear.git] / src / AIModel / AIFlightPlan.cxx
index 14c4de1acf3036654af47a8788a85fee5edc9b71..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;
@@ -58,7 +59,7 @@ FGAIWaypoint::FGAIWaypoint() {
   trackLength = 0;
 }
 
-bool FGAIWaypoint::contains(string target) {
+bool FGAIWaypoint::contains(const string& target) {
     size_t found = name.find(target);
     if (found == string::npos)
         return false;
@@ -96,37 +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;
-    gateId          = 0;
-    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;
-  gateId            = 0;
-  lastNodeVisited   = 0;
-  taxiRoute         = 0;
-
-
-  isValid = parseProperties(filename);
 }
 
 
@@ -151,20 +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;
-  gateId            = 0;
-  lastNodeVisited   = 0;
-  taxiRoute         = 0;
-
   if (parseProperties(p)) {
     isValid = true;
   } else {
@@ -176,16 +172,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
 FGAIFlightPlan::~FGAIFlightPlan()
 {
   deleteWaypoints();
-  delete taxiRoute;
-
-// if we're parked at a gate, release it
-  if (gateId >= 0) {
-    FGAirport* apt = (leg >= 7) ? arrival : departure;
-    if (apt) {
-      SG_LOG(SG_AI, SG_INFO, "releasing parking gate " << gateId << " at " << apt->ident());
-      apt->getDynamics()->releaseParking(gateId);
-    }
-  }
+  //delete taxiRoute;
 }
 
 void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
@@ -227,7 +214,6 @@ void FGAIFlightPlan::createWaypoints(FGAIAircraft *ac,
   isValid = create(ac, dep, arr, leg, alt, speed, lat, lon,
                    firstLeg, radius, fltType, acType, airline, dist);
   wpt_iterator = waypoints.begin();
 }
 
 bool FGAIFlightPlan::parseProperties(const std::string& filename)
@@ -301,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 )
@@ -325,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--;
         }
@@ -412,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, 
@@ -454,14 +442,6 @@ void FGAIFlightPlan::restart()
   wpt_iterator = waypoints.begin();
 }
 
-
-void FGAIFlightPlan::deleteTaxiRoute() 
-{
-  delete taxiRoute;
-  taxiRoute = 0;
-}
-
-
 int FGAIFlightPlan::getRouteIndex(int i) {
   if ((i > 0) && (i < (int)waypoints.size())) {
     return waypoints[i]->getRouteIndex();
@@ -470,8 +450,7 @@ int FGAIFlightPlan::getRouteIndex(int i) {
     return 0;
 }
 
-
-double FGAIFlightPlan::checkTrackLength(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();
@@ -494,3 +473,23 @@ void FGAIFlightPlan::shortenToFirst(unsigned int number, string name)
     }
     (waypoints.back())->setName((waypoints.back())->getName() + name);
 }
+
+void FGAIFlightPlan::setGate(const ParkingAssignment& pka)
+{
+  gate = pka;
+}
+
+FGParking* FGAIFlightPlan::getParkingGate()
+{
+  return gate.parking();
+}
+
+FGAirportRef FGAIFlightPlan::departureAirport() const
+{
+    return departure;
+}
+
+FGAirportRef FGAIFlightPlan::arrivalAirport() const
+{
+    return arrival;
+}