]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/TrafficMgr.cxx
don't destroy iterated map entries; delete _menubar; restore closed
[flightgear.git] / src / Traffic / TrafficMgr.cxx
index 9e6dded35b48ab3e2954a262b96507f373207f6a..1e3b73a2ce8cc034f917e6790edd0e333e164fd9 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <string>
 #include <vector>
+#include <algorithm>
 
 #include <plib/sg.h>
 
@@ -53,6 +54,7 @@
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/xml/easyxml.hxx>
 
+#include <AIModel/AIAircraft.hxx>
 #include <AIModel/AIFlightPlan.hxx>
 #include <AIModel/AIBase.hxx>
 #include <Airports/simple.hxx>
@@ -62,6 +64,7 @@
 
 #include "TrafficMgr.hxx"
 
+SG_USING_STD(sort);
  
 /******************************************************************************
  * TrafficManager
@@ -72,30 +75,53 @@ FGTrafficManager::FGTrafficManager()
 
 
 void FGTrafficManager::init()
-{
+{ 
+  //cerr << "Initializing Schedules" << endl;
+  time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+  currAircraft = scheduledAircraft.begin();
+  while (currAircraft != scheduledAircraft.end())
+    {
+      if (!(currAircraft->init()))
+       {
+         currAircraft=scheduledAircraft.erase(currAircraft);
+         //cerr << "Erasing " << currAircraft->getRegistration() << endl;
+         currAircraft--;
+       }
+      else 
+       {
+         currAircraft++;
+       }
+    }
+  //cerr << "Sorting by distance " << endl;
+  sort(scheduledAircraft.begin(), scheduledAircraft.end());
   currAircraft = scheduledAircraft.begin();
+  currAircraftClosest = scheduledAircraft.begin();
+  //cerr << "Done initializing schedules" << endl;
 }
 
 void FGTrafficManager::update(double something)
 {
-
-  //static const SGPropertyNode *warp = globals->get_props()->getNode("/sim/time/warp");
-  
-  //time_t now = time(NULL) + globals->get_warp();
   time_t now = time(NULL) + fgGetLong("/sim/time/warp");
-  //  cerr << "TrafficManager update" << globals->get_warp() << endl;
-    if(currAircraft == scheduledAircraft.end())
+  if(currAircraft == scheduledAircraft.end())
+    {
+      //cerr << "resetting schedule " << endl;
       currAircraft = scheduledAircraft.begin();
-    currAircraft->update(now);
-    currAircraft++;
+    }
+  if (!(currAircraft->update(now)))
+    {
+      // after proper initialization, we shouldnt get here.
+      // But let's make sure
+      cerr << "Failed to update aircraft schedule in traffic manager" << endl;
+    }
+  currAircraft++;
 }
 
-void FGTrafficManager::release(void *id)
+void FGTrafficManager::release(int id)
 {
   releaseList.push_back(id);
 }
 
-bool FGTrafficManager::isReleased(void *id)
+bool FGTrafficManager::isReleased(int id)
 {
   IdListIterator i = releaseList.begin();
   while (i != releaseList.end())
@@ -146,6 +172,18 @@ void  FGTrafficManager::endElement (const char * name) {
     livery = value;
   else if (element == string("registration"))
     registration = value;
+  else if (element == string("airline"))
+    airline = value;
+  else if (element == string("actype"))
+    acType = value;
+  else if (element == string("flighttype"))
+    flighttype = value;
+  else if (element == string("radius"))
+    radius = atoi(value.c_str());
+  else if (element == string("offset"))
+    offset = atoi(value.c_str());
+  else if (element == string("performance-class"))
+    m_class = value;
   else if (element == string("heavy"))
     {
       if(value == string("true"))
@@ -195,10 +233,16 @@ void  FGTrafficManager::endElement (const char * name) {
     {
       //cerr << "Pushing back aircraft " << registration << endl;
       scheduledAircraft.push_back(FGAISchedule(mdl, 
-                                               livery, 
-                                               registration, 
-                                               heavy, 
-                                               flights));
+                                              livery, 
+                                              registration, 
+                                              heavy,
+                                              acType, 
+                                              airline, 
+                                              m_class, 
+                                              flighttype,
+                                              radius,
+                                              offset,
+                                              flights));
       while(flights.begin() != flights.end())
        flights.pop_back();
     }