]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/SchedFlight.cxx
Bugfix - untie property.
[flightgear.git] / src / Traffic / SchedFlight.cxx
index 4a86c98c477874baeb04edba148155e2b0df361d..5575f6ee090f924b0f5aace94b140bced3cb5c17 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *
  **************************************************************************/
  *
  * TODO:
  * - Check the code for known portability issues
- * - Find an alternative for the depricated Point3D class
  *
  *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <time.h>
 #include <iostream>
 #include <string>
 #include <vector>
 
-#include <plib/sg.h>
-
 #include <simgear/compiler.h>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
 #include <simgear/props/props.hxx>
 #include <simgear/route/waypoint.hxx>
 #include <simgear/structure/subsystem_mgr.hxx>
 
 FGScheduledFlight::FGScheduledFlight()
 {
+   initialized = false;
+   available = true;
 }
   
 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;
-  arrivalTime     = other.arrivalTime;
-  repeatPeriod    = other.repeatPeriod;
-  initialized     = other.initialized;
+  callsign          = other.callsign;
+  fltRules          = other.fltRules;
+  departurePort     = other.departurePort;
+  depId             = other.depId;
+  arrId             = other.arrId;
+  departureTime     = other.departureTime;
+  cruiseAltitude    = other.cruiseAltitude;
+  arrivalPort       = other.arrivalPort;
+  arrivalTime       = other.arrivalTime;
+  repeatPeriod      = other.repeatPeriod;
+  initialized       = other.initialized;
+  requiredAircraft  = other.requiredAircraft;
+  available         = other.available;
 }
 
-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,
+                   const string& reqAC)
 {
   callsign          = cs;
   fltRules          = fr;
@@ -110,6 +115,7 @@ FGScheduledFlight::FGScheduledFlight(string cs,
   //departureTime     = processTimeString(deptime);
   //arrivalTime       = processTimeString(arrtime);
   cruiseAltitude    = cruiseAlt;
+  requiredAircraft  = reqAC;
 
   // Process the repeat period string
   if (rep.find("WEEK",0) != string::npos)
@@ -122,19 +128,22 @@ FGScheduledFlight::FGScheduledFlight(string cs,
     }
   else
     {
-      cerr << "Unknown repeat period" << endl;
-      exit(1);
+      repeatPeriod = 365*24*60*60;
+      SG_LOG( SG_GENERAL, SG_ALERT, "Unknown repeat period in flight plan "
+                                    "of flight '" << cs << "': " << rep );
     }
 
   // What we still need to do is preprocess the departure and
   // arrival times. 
   departureTime = processTimeString(deptime);
   arrivalTime   = processTimeString(arrtime);
+  //departureTime += rand() % 300; // Make sure departure times are not limited to 5 minute increments.
   if (departureTime > arrivalTime)
     {
       departureTime -= repeatPeriod;
     }
   initialized = false;
+  available   = true;
 }
 
 
@@ -142,11 +151,10 @@ FGScheduledFlight:: ~FGScheduledFlight()
 {
 }
 
-time_t FGScheduledFlight::processTimeString(string theTime)
+time_t FGScheduledFlight::processTimeString(const string& theTime)
 {
   int weekday;
   int timeOffsetInDays;
-  int targetDate;
   int targetHour;
   int targetMinute;
   int targetSecond;
@@ -170,6 +178,7 @@ time_t FGScheduledFlight::processTimeString(string theTime)
     {
       timeOffsetInDays = 0;
     }
+  // TODO: verify status of each token.
   targetHour   = atoi(timeCopy.substr(0,2).c_str());
   targetMinute = atoi(timeCopy.substr(3,5).c_str());
   targetSecond = atoi(timeCopy.substr(6,8).c_str());
@@ -257,16 +266,16 @@ FGAirport * FGScheduledFlight::getArrivalAirport  ()
 bool FGScheduledFlight::initializeAirports()
 {
   //cerr << "Initializing using : " << depId << " " << arrId << endl;
-  departurePort = globals->get_airports()->search(depId);
+  departurePort = FGAirport::findByIdent(depId);
   if(departurePort == NULL)
     {
-      cerr << "Could not find " << depId << endl; 
+      SG_LOG( SG_GENERAL, SG_WARN, "Traffic manager could not find departure airport : " << depId);
       return false;
     }
-  arrivalPort = globals->get_airports()->search(arrId);
+  arrivalPort = FGAirport::findByIdent(arrId);
   if(arrivalPort == NULL)
     {
-      cerr << "Could not find " << arrId << endl;
+      SG_LOG( SG_GENERAL, SG_WARN, "Traffic manager could not find arrival airport   : " << arrId);
       return false;
     }
 
@@ -275,3 +284,9 @@ bool FGScheduledFlight::initializeAirports()
   initialized = true;
   return true;
 }
+
+
+bool compareScheduledFlights(FGScheduledFlight *a, FGScheduledFlight *b) 
+{ 
+  return (*a) < (*b); 
+};