]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/SchedFlight.cxx
don't destroy iterated map entries; delete _menubar; restore closed
[flightgear.git] / src / Traffic / SchedFlight.cxx
index b05c7a6a8f4118932b352e72d1e1d5cd4c42fc36..a65adad8c0b45fee2a4a2317f0feb1b024b0a321 100644 (file)
@@ -81,6 +81,8 @@ FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other)
   callsign        = other.callsign;
   fltRules        = other.fltRules;
   departurePort   = other.departurePort;
+  depId           = other.depId;
+  arrId           = other.arrId;
   departureTime   = other.departureTime;
   cruiseAltitude  = other.cruiseAltitude;
   arrivalPort     = other.arrivalPort;
@@ -89,19 +91,22 @@ FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other)
   initialized     = other.initialized;
 }
 
-FGScheduledFlight::FGScheduledFlight(string cs,
-                  string fr,
-                  string depPrt,
-                  string arrPrt,
+FGScheduledFlight::FGScheduledFlight(const string& cs,
+                  const string& fr,
+                  const string& depPrt,
+                  const string& arrPrt,
                   int cruiseAlt,
-                  string deptime,
-                  string arrtime,
-                  string rep)
+                  const string& deptime,
+                  const string& arrtime,
+                  const string& rep)
 {
   callsign          = cs;
   fltRules          = fr;
-  departurePort.id  = depPrt;
-  arrivalPort.id    = arrPrt;
+  //departurePort.setId(depPrt);
+  //arrivalPort.setId(arrPrt);
+  depId = depPrt;
+  arrId = arrPrt;
+  //cerr << "Constructor: departure " << depId << ". arrival " << arrId << endl;
   //departureTime     = processTimeString(deptime);
   //arrivalTime       = processTimeString(arrtime);
   cruiseAltitude    = cruiseAlt;
@@ -137,7 +142,7 @@ FGScheduledFlight:: ~FGScheduledFlight()
 {
 }
 
-time_t FGScheduledFlight::processTimeString(string theTime)
+time_t FGScheduledFlight::processTimeString(const string& theTime)
 {
   int weekday;
   int timeOffsetInDays;
@@ -225,7 +230,10 @@ FGAirport *FGScheduledFlight::getDepartureAirport()
     {
       initializeAirports();
     }
-  return &departurePort;
+  if (initialized)
+    return departurePort;
+  else
+    return 0;
 }
 FGAirport * FGScheduledFlight::getArrivalAirport  ()
 {
@@ -233,7 +241,10 @@ FGAirport * FGScheduledFlight::getArrivalAirport  ()
     {
       initializeAirports();
     }
-  return &arrivalPort;
+   if (initialized)
+     return arrivalPort;
+   else
+     return 0;
 }
 
 // Upon the first time of requesting airport information
@@ -243,15 +254,24 @@ FGAirport * FGScheduledFlight::getArrivalAirport  ()
 // but we should improve that. The best idea is probably to cancel
 // this flight entirely by removing it from the schedule, if one
 // of the airports cannot be found. 
-void FGScheduledFlight::initializeAirports()
+bool FGScheduledFlight::initializeAirports()
 {
-  if(!(fgFindAirportID(arrivalPort.id, &arrivalPort  )))
+  //cerr << "Initializing using : " << depId << " " << arrId << endl;
+  departurePort = globals->get_airports()->search(depId);
+  if(departurePort == NULL)
     {
-      //cerr << ": Could not find " << arrivalPort.id << endl; 
+      cerr << "Could not find " << depId << endl; 
+      return false;
     }
-  if(!(fgFindAirportID(departurePort.id, &departurePort)))
+  arrivalPort = globals->get_airports()->search(arrId);
+  if(arrivalPort == NULL)
     {
-      //cerr << ": Could not find " << departurePort.id << endl;
+      cerr << "Could not find " << arrId << endl;
+      return false;
     }
+
+  //cerr << "Found : " << departurePort->getId() << endl;
+  //cerr << "Found : " << arrivalPort->getId() << endl;
   initialized = true;
+  return true;
 }