]> git.mxchange.org Git - flightgear.git/commitdiff
Spectacular improvement in traffic manager initialization and preparatory
authordurk <durk>
Sat, 29 Jul 2006 18:17:19 +0000 (18:17 +0000)
committerdurk <durk>
Sat, 29 Jul 2006 18:17:19 +0000 (18:17 +0000)
work for ground based distance separation of AIAircraft.

Traffic manager initialization related changes:
- Schedules initialize "on the fly", instead of during initialization
- Invalid routes are no longer deleted, but marked as BOGUS and ignored
- Changed loading order from a distance based prioritization to a point-
  score based prioritization, resulting in a much faster establisment of
  AIAircraft near the user's plane.

Preparatory work for ground-based separation of Aircraft.
- The groundnetwork findShrortestRoute function not only returns a list
  of waypoints, but also a list of taxi "segments" (a.k.a. taxiways).
- The taxiway list is stored in the Flightplan, and updated everytime
  a new taxi leg is created.

src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlan.hxx
src/AIModel/AIFlightPlanCreate.cxx
src/AIModel/AIFlightPlanCreateCruise.cxx
src/Airports/groundnetwork.cxx
src/Airports/groundnetwork.hxx
src/Traffic/SchedFlight.cxx
src/Traffic/Schedule.cxx
src/Traffic/Schedule.hxx
src/Traffic/TrafficMgr.cxx
src/Traffic/TrafficMgr.hxx

index 318d734cabd56d3d15a76f9d185bd9fb57d02eed..1ffc4328383dac203d0e49b247cee182802da06c 100644 (file)
@@ -49,6 +49,7 @@ FGAIFlightPlan::FGAIFlightPlan(const string& filename)
   start_time = 0;
   leg = 10;
   gateId = 0;
+  taxiRoute = 0;
   SGPath path( globals->get_fg_root() );
   path.append( ("/AI/FlightPlans/" + filename).c_str() );
   SGPropertyNode root;
@@ -113,6 +114,7 @@ FGAIFlightPlan::FGAIFlightPlan(const std::string& p,
   repeat = false;
   leg = 10;
   gateId=0;
+  taxiRoute = 0;
   start_time = start;
   bool useInitialWayPoint = true;
   bool useCurrentWayPoint = false;
@@ -300,6 +302,8 @@ FGAIFlightPlan::~FGAIFlightPlan()
   //    delete *(waypoints.begin());
   //    waypoints.erase (waypoints.begin());
   //  }
+  if (taxiRoute)
+    delete taxiRoute;
 }
 
 
index 755b672ecaf5e37b2b5c65dd80d8a841c9f348ec..023ad85a093f2b97e905377e8677e03ef3e13490 100644 (file)
@@ -112,7 +112,8 @@ private:
   int leg;
   int gateId;
   string activeRunway;
-  FGAirRoute route;
+  FGAirRoute airRoute;
+  FGTaxiRoute *taxiRoute;
 
 
   Point3D temp;
index 90403432dca97008ef77ef1b92adbb48b83eb9f2..1f772ccc0eac92ad2007602a965ee0ad87eef12b 100644 (file)
@@ -192,6 +192,8 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
   double lat2, lon2, az2;
   waypoint *wpt;
 
+  int nrWaypointsToSkip;
+
    if (direction == 1)
     {
       // If this function is called during initialization,
@@ -256,15 +258,18 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
          // fallback mechanism for this. 
          // Starting from gate 0 in this case is a bit of a hack
          // which requires a more proper solution later on.
-         FGTaxiRoute route;
+         //FGTaxiRoute route;
+         if (taxiRoute)
+           delete taxiRoute;
+         taxiRoute = new FGTaxiRoute;
          if (gateId >= 0)
-           route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, 
+           *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(gateId, 
                                                                              runwayId);
          else
-           route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(0, runwayId);
+           *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(0, runwayId);
          intVecIterator i;
         
-         if (route.empty()) {
+         if (taxiRoute->empty()) {
            //Add the runway startpoint;
            wpt = new waypoint;
            wpt->name      = "Airport Center";
@@ -294,34 +299,35 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
            waypoints.push_back(wpt);   
          } else {
            int node;
-           route.first();
+           taxiRoute->first();
            bool isPushBackPoint = false;
            if (firstFlight) {
              // If this is called during initialization, randomly
              // skip a number of waypoints to get a more realistic
              // taxi situation.
              isPushBackPoint = true;
-             int nrWaypoints = route.size();
-             int nrWaypointsToSkip = rand() % nrWaypoints;
+             int nrWaypoints = taxiRoute->size();
+             nrWaypointsToSkip = rand() % nrWaypoints;
              // but make sure we always keep two active waypoints
              // to prevent a segmentation fault
              for (int i = 0; i < nrWaypointsToSkip-2; i++) {
                isPushBackPoint = false;
-               route.next(&node);
+               taxiRoute->next(&node);
              }
            }
            else {
              //chop off the first two waypoints, because
              // those have already been created
              // by create pushback
-             int size = route.size();
+             int size = taxiRoute->size();
              if (size > 2) {
-               route.next(&node);
-               route.next(&node);
+               taxiRoute->next(&node);
+               taxiRoute->next(&node);
              }
            }
-           while(route.next(&node))
+           while(taxiRoute->next(&node))
              {
+               //FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findSegment(node)->getEnd();
                FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
                //ids.pop_back();  
                wpt = new waypoint;
@@ -345,7 +351,20 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
                wpt->on_ground = true;
                waypoints.push_back(wpt);
              }
-           cerr << endl;
+           //cerr << endl;
+           // finally, rewind the taxiRoute object to the point where we started
+           taxiRoute->first();
+           if (firstFlight) { 
+             for (int i = 0; i < nrWaypointsToSkip-2; i++) {
+               taxiRoute->next(&node);
+             }
+           } else {
+             int size = taxiRoute->size();
+             if (size > 2) {
+               taxiRoute->next(&node);
+               taxiRoute->next(&node);
+             }
+           }
          }
        }
       else 
@@ -399,16 +418,19 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
          // A negative gateId indicates an overflow parking, use a
          // fallback mechanism for this. 
          // Starting from gate 0 is a bit of a hack...
-         FGTaxiRoute route;
+         //FGTaxiRoute route;
+         if (taxiRoute)
+           delete taxiRoute;
+         taxiRoute = new FGTaxiRoute;
          if (gateId >= 0)
-           route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 
+           *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 
                                                                              gateId);
          else
-           route = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 0);
+           *taxiRoute = apt->getDynamics()->getGroundNetwork()->findShortestRoute(runwayId, 0);
          intVecIterator i;
         
          // No route found: go from gate directly to runway
-         if (route.empty()) {
+         if (taxiRoute->empty()) {
            //Add the runway startpoint;
            wpt = new waypoint;
            wpt->name      = "Airport Center";
@@ -438,13 +460,14 @@ void FGAIFlightPlan::createTaxi(bool firstFlight, int direction,
            waypoints.push_back(wpt);   
          } else {
            int node;
-           route.first();
-           int size = route.size();
+           taxiRoute->first();
+           int size = taxiRoute->size();
            // Omit the last two waypoints, as 
            // those are created by createParking()
            for (int i = 0; i < size-2; i++)
              {
-               route.next(&node);
+               taxiRoute->next(&node);
+               //FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
                FGTaxiNode *tn = apt->getDynamics()->getGroundNetwork()->findNode(node);
                wpt = new waypoint;
                wpt->name      = "taxiway"; // fixme: should be the name of the taxiway
@@ -636,7 +659,7 @@ void FGAIFlightPlan::createClimb(bool firstFlight, FGAirport *apt, double speed,
   heading = rwy._heading;
   double azimuth = heading + 180.0;
   while ( azimuth >= 360.0 ) { azimuth -= 360.0; }
-  cerr << "Creating climb at : " << rwy._id << " " << rwy._rwy_no << endl;
+  //cerr << "Creating climb at : " << rwy._id << " " << rwy._rwy_no << endl;
   geo_direct_wgs_84 ( 0, rwy._lat, rwy._lon, heading, 
                      10*SG_NM_TO_METER,
                      &lat2, &lon2, &az2 );
index 03bfce80f600c0256c247a38753e9d58a8516033..c60e40bb207d3bddb370100b37a9b1ae53b94b38 100755 (executable)
@@ -119,7 +119,7 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
                        FGAirRoute routePart = globals->get_airwaynet()->findShortestRoute(*i, *j);
                        if (!(routePart.empty()))
                        {
-                               route.add(routePart);
+                               airRoute.add(routePart);
                                i = j;
                                break;
                        }
index c6632882c7262d3d850d5e951fca93d8930f0043..54942d02440e0b1a814a837b84021261f55c153d 100644 (file)
@@ -102,10 +102,9 @@ void FGTaxiSegment::setTrackDistance()
                     end->getLatitude(),
                     0);
   first.CourseAndDistance(second, &course, &length);
-  
 }
 
-bool FGTaxiRoute::next(int *val
+bool FGTaxiRoute::next(int *nde
 { 
   //for (intVecIterator i = nodes.begin(); i != nodes.end(); i++)
   //  cerr << "FGTaxiRoute contains : " << *(i) << endl;
@@ -114,11 +113,35 @@ bool FGTaxiRoute::next(int *val)
   //  cerr << "true" << endl;
   //else
   //  cerr << "false" << endl;
+  //if (nodes.size() != (routes.size()) +1)
+  //  cerr << "ALERT: Misconfigured TaxiRoute : " << nodes.size() << " " << routes.size() << endl;
       
   if (currNode == nodes.end())
     return false;
-  *val = *(currNode); 
+  *nde = *(currNode); 
   currNode++;
+  currRoute++;
+  return true;
+};
+
+bool FGTaxiRoute::next(int *nde, int *rte) 
+{ 
+  //for (intVecIterator i = nodes.begin(); i != nodes.end(); i++)
+  //  cerr << "FGTaxiRoute contains : " << *(i) << endl;
+  //cerr << "Offset from end: " << nodes.end() - currNode << endl;
+  //if (currNode != nodes.end())
+  //  cerr << "true" << endl;
+  //else
+  //  cerr << "false" << endl;
+  //if (nodes.size() != (routes.size()) +1)
+  //  cerr << "ALERT: Misconfigured TaxiRoute : " << nodes.size() << " " << routes.size() << endl;
+      
+  if (currNode == nodes.end())
+    return false;
+  *nde = *(currNode); 
+  *rte = *(currRoute);
+  currNode++;
+  currRoute++;
   return true;
 };
 /***************************************************************************
@@ -163,12 +186,14 @@ void FGGroundNetwork::addNodes(FGParkingVec *parkings)
 void FGGroundNetwork::init()
 {
   hasNetwork = true;
+  int index = 0;
   FGTaxiSegmentVectorIterator i = segments.begin();
   while(i != segments.end()) {
     //cerr << "initializing node " << i->getIndex() << endl;
     i->setStart(&nodes);
     i->setEnd  (&nodes);
     i->setTrackDistance();
+    i->setIndex(index++);
     //cerr << "Track distance = " << i->getLength() << endl;
     //cerr << "Track ends at"      << i->getEnd()->getIndex() << endl;
     i++;
@@ -216,6 +241,18 @@ FGTaxiNode *FGGroundNetwork::findNode(int idx)
   return 0;
 }
 
+FGTaxiSegment *FGGroundNetwork::findSegment(int idx)
+{
+  for (FGTaxiSegmentVectorIterator 
+        itr = segments.begin();
+       itr != segments.end(); itr++)
+    {
+      if (itr->getIndex() == idx)
+       return itr->getAddress();
+    }
+  return 0;
+}
+
 FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end) 
 {
   foundRoute = false;
@@ -225,7 +262,9 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end)
   //prevNode = prevPrevNode = -1;
   //prevNode = start;
   routes.clear();
-  traceStack.clear();
+  nodesStack.clear();
+  routesStack.clear();
+
   trace(firstNode, end, 0, 0);
   FGTaxiRoute empty;
   
@@ -249,7 +288,7 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end)
 
 void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double distance)
 {
-  traceStack.push_back(currNode->getIndex());
+  nodesStack.push_back(currNode->getIndex());
   totalDistance += distance;
   //cerr << "Starting trace " << depth << " total distance: " << totalDistance<< endl;
   //<< currNode->getIndex() << endl;
@@ -258,9 +297,10 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
   // So we can add this to the routing table
   if (currNode->getIndex() == end)
     {
-      //cerr << "Found route : " <<  totalDistance << "" << " " << *(traceStack.end()-1) << endl;
-      routes.push_back(FGTaxiRoute(traceStack,totalDistance));
-      traceStack.pop_back();
+      //cerr << "Found route : " <<  totalDistance << "" << " " << *(nodesStack.end()-1) << endl;
+      routes.push_back(FGTaxiRoute(nodesStack,routesStack,totalDistance));
+      nodesStack.pop_back();
+      routesStack.pop_back();
       if (!(foundRoute))
        maxDistance = totalDistance;
       else
@@ -276,18 +316,19 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
   // if so, we should step back one level, because it is
   // rather rediculous to proceed further from here. 
   // if the current node has not been encountered before,
-  // i should point to traceStack.end()-1; and we can continue
-  // if i is not traceStack.end, the previous node was found, 
+  // i should point to nodesStack.end()-1; and we can continue
+  // if i is not nodesStack.end, the previous node was found, 
   // and we should return. 
   // This only works at trace levels of 1 or higher though
   if (depth > 0) {
-    intVecIterator i = traceStack.begin();
+    intVecIterator i = nodesStack.begin();
     while ((*i) != currNode->getIndex()) {
       //cerr << "Route so far : " << (*i) << endl;
       i++;
     }
-    if (i != traceStack.end()-1) {
-      traceStack.pop_back();
+    if (i != nodesStack.end()-1) {
+      nodesStack.pop_back();
+      routesStack.pop_back();
       totalDistance -= distance;
       return;
     }
@@ -297,7 +338,8 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
     if ((totalDistance > maxDistance) && foundRoute)
       {
        //cerr << "Stopping rediculously long trace: " << totalDistance << endl;
-       traceStack.pop_back();
+       nodesStack.pop_back();
+       routesStack.pop_back();
        totalDistance -= distance;
        return;
       }
@@ -312,7 +354,10 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
           i != currNode->getEndRoute();
           i++)
        {
-         //cerr << (*i)->getLenght() << endl;
+         //cerr << (*i)->getLength() << endl;
+         //cerr << (*i)->getIndex() << endl;
+         int idx = (*i)->getIndex();
+         routesStack.push_back((*i)->getIndex());
          trace((*i)->getEnd(), end, depth+1, (*i)->getLength());
        //  {
        //      // cerr << currNode -> getIndex() << " ";
@@ -325,7 +370,8 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
     {
       SG_LOG( SG_GENERAL, SG_DEBUG, "4" );
     }
-  traceStack.pop_back();
+  nodesStack.pop_back();
+  routesStack.pop_back();
   totalDistance -= distance;
   return;
 }
index 10b0c1a7d784104156cb533d3cffba9aa44abb88..a67eb7266fa73d76ed5d581198e23a0c38cae133 100644 (file)
@@ -104,6 +104,8 @@ public:
   double getLength() { return length; };
   int getIndex() { return index; };
 
+ FGTaxiSegment *getAddress() { return this;};
+
   
 };
 
@@ -111,21 +113,32 @@ public:
 typedef vector<int> intVec;
 typedef vector<int>::iterator intVecIterator;
 
+/***************************************************************************************
+ * class FGTaxiRoute
+ **************************************************************************************/
 class FGTaxiRoute
 {
 private:
   intVec nodes;
+  intVec routes;
   double distance;
   intVecIterator currNode;
+  intVecIterator currRoute;
 
 public:
-  FGTaxiRoute() { distance = 0; currNode = nodes.begin(); };
-  FGTaxiRoute(intVec nds, double dist) { nodes = nds; distance = dist; currNode = nodes.begin();};
+  FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
+  FGTaxiRoute(intVec nds, intVec rts, double dist) { 
+    nodes = nds; 
+    routes = rts;
+    distance = dist; 
+    currNode = nodes.begin();
+  };
   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
   bool empty () { return nodes.begin() == nodes.end(); };
-  bool next(int *val); 
+  bool next(int *nde); 
+  bool next(int *nde, int *rte);
   
-  void first() { currNode = nodes.begin(); };
+  void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
   int size() { return nodes.size(); };
 };
 
@@ -142,7 +155,8 @@ private:
   FGTaxiNodeVector    nodes;
   FGTaxiSegmentVector segments;
   //intVec route;
-  intVec traceStack;
+  intVec nodesStack;
+  intVec routesStack;
   TaxiRouteVector routes;
   
   bool foundRoute;
@@ -159,6 +173,7 @@ public:
   bool exists() { return hasNetwork; };
   int findNearestNode(double lat, double lon);
   FGTaxiNode *findNode(int idx);
+  FGTaxiSegment *findSegment(int idx);
   FGTaxiRoute findShortestRoute(int start, int end);
   void trace(FGTaxiNode *, int, int, double dist);
  
index 731ee6b8fefe3be576f5b6f602dcd9f1486831f3..1e45921cd47c5a06e36b37af29ac593def98b13a 100644 (file)
@@ -265,13 +265,13 @@ bool FGScheduledFlight::initializeAirports()
   departurePort = globals->get_airports()->search(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);
   if(arrivalPort == NULL)
     {
-      cerr << "Could not find " << arrId << endl;
+      SG_LOG( SG_GENERAL, SG_WARN, "Traffic manager could not find arrival airort   : " << arrId);
       return false;
     }
 
index 3a20c96685d988d3aa5d270a25e4ef14b2cb888f..f80667687c434cca0c91ff871659817cc5007d25 100644 (file)
@@ -25,6 +25,8 @@
 #  include "config.h"
 #endif
 
+#define BOGUS 0xFFFF
+
 #include <stdlib.h>
 #include <time.h>
 #include <iostream>
@@ -72,6 +74,7 @@ FGAISchedule::FGAISchedule()
   radius = 0;
   groundOffset = 0;
   distanceToUser = 0;
+  score = 0;
 }
 
 FGAISchedule::FGAISchedule(string    mdl, 
@@ -84,6 +87,7 @@ FGAISchedule::FGAISchedule(string    mdl,
                           string fltpe,
                           double rad,
                           double grnd,
+                          int    scre,
                           FGScheduledFlightVec flt)
 {
   modelPath    = mdl; 
@@ -104,6 +108,7 @@ FGAISchedule::FGAISchedule(string    mdl,
        i++)
     flights.push_back(FGScheduledFlight((*i)));
   AIManagerRef = 0;
+  score    = scre;
   firstRun = true;
 }
 
@@ -124,6 +129,7 @@ FGAISchedule::FGAISchedule(const FGAISchedule &other)
   radius       = other.radius;
   groundOffset = other.groundOffset;
   flightType   = other.flightType;
+  score        = other.score;
   distanceToUser = other.distanceToUser;
 }
 
@@ -155,7 +161,7 @@ bool FGAISchedule::init()
   // Since time isn't initialized yet when this function is called,
   // Find the closest possible airport.
   // This should give a reasonable initialization order. 
-  setClosestDistanceToUser();
+  //setClosestDistanceToUser();
   return true;
 }
 
@@ -203,6 +209,9 @@ bool FGAISchedule::update(time_t now)
   // finally kicks in. 
   if (firstRun)
     {
+      if (init() == false)
+       AIManagerRef = BOGUS;
+       
       for (FGScheduledFlightVecIterator i = flights.begin(); 
           i != flights.end(); 
           i++)
@@ -460,47 +469,47 @@ double FGAISchedule::getSpeed()
 }
 
 
-void FGAISchedule::setClosestDistanceToUser()
-{
+// void FGAISchedule::setClosestDistanceToUser()
+// {
   
   
-  double course;
-  double dist;
+//   double course;
+//   double dist;
 
-  Point3D temp;
-  time_t 
-    totalTimeEnroute, 
-    elapsedTimeEnroute;
+//   Point3D temp;
+//   time_t 
+//     totalTimeEnroute, 
+//     elapsedTimeEnroute;
  
-  double userLatitude  = fgGetDouble("/position/latitude-deg");
-  double userLongitude = fgGetDouble("/position/longitude-deg");
+//   double userLatitude  = fgGetDouble("/position/latitude-deg");
+//   double userLongitude = fgGetDouble("/position/longitude-deg");
 
-  FGAirport *dep;
+//   FGAirport *dep;
   
-#if defined( __CYGWIN__) || defined( __MINGW32__)
-  #define HUGE HUGE_VAL
-#endif
-  distanceToUser = HUGE;
-  FGScheduledFlightVecIterator i = flights.begin();
-  while (i != flights.end())
-    {
-      dep = i->getDepartureAirport();
-      //if (!(dep))
-      //return HUGE;
+// #if defined( __CYGWIN__) || defined( __MINGW32__)
+//   #define HUGE HUGE_VAL
+// #endif
+//   distanceToUser = HUGE;
+//   FGScheduledFlightVecIterator i = flights.begin();
+//   while (i != flights.end())
+//     {
+//       dep = i->getDepartureAirport();
+//       //if (!(dep))
+//       //return HUGE;
       
-      SGWayPoint user (   userLongitude,
-                         userLatitude,
-                         i->getCruiseAlt());
-      SGWayPoint current (dep->getLongitude(),
-                         dep->getLatitude(),
-                         0);
-      user.CourseAndDistance(current, &course, &dist);
-      if (dist < distanceToUser)
-       {
-         distanceToUser = dist;
-         //cerr << "Found closest distance to user for " << registration << " to be " << distanceToUser << " at airport " << dep->getId() << endl;
-       }
-      i++;
-    }
-  //return distToUser;
-}
+//       SGWayPoint user (   userLongitude,
+//                       userLatitude,
+//                       i->getCruiseAlt());
+//       SGWayPoint current (dep->getLongitude(),
+//                       dep->getLatitude(),
+//                       0);
+//       user.CourseAndDistance(current, &course, &dist);
+//       if (dist < distanceToUser)
+//     {
+//       distanceToUser = dist;
+//       //cerr << "Found closest distance to user for " << registration << " to be " << distanceToUser << " at airport " << dep->getId() << endl;
+//     }
+//       i++;
+//     }
+//   //return distToUser;
+// }
index daaa4e2406c250a81a6a0acd847c22c87706f985..a79585e0bf12ddc2a81fa1482a089deb371504d8 100644 (file)
@@ -50,13 +50,15 @@ class FGAISchedule
   double groundOffset;
   double distanceToUser;
   int AIManagerRef;
+  int score;
   bool firstRun;
 
 
  public:
   FGAISchedule();                                           // constructor
-  FGAISchedule(string, string, string, bool, string, string, string, string, double, double, FGScheduledFlightVec);  // construct & init
-  FGAISchedule(const FGAISchedule &other);             // copy constructor
+  FGAISchedule(string, string, string, bool, string, string, string, string, double, double, 
+              int, FGScheduledFlightVec);                  // construct & init
+  FGAISchedule(const FGAISchedule &other);                  // copy constructor
 
   ~FGAISchedule(); //destructor
 
@@ -64,7 +66,7 @@ class FGAISchedule
   bool init();
 
   double getSpeed         ();
-  void setClosestDistanceToUser();
+  //void setClosestDistanceToUser();
   void next();   // forces the schedule to move on to the next flight.
 
   time_t      getDepartureTime    () { return flights.begin()->getDepartureTime   (); };
@@ -79,7 +81,9 @@ class FGAISchedule
   const string& getCallSign       () { return flights.begin()->getCallSign (); };
   const string& getRegistration   () { return registration;};
   bool getHeavy                   () { return heavy; };
-  bool operator< (const FGAISchedule &other) const { return (distanceToUser < other.distanceToUser); };
+  // used to sort in decending order of score: I've probably found a better way to
+  // decending order sorting, but still need to test that.
+  bool operator< (const FGAISchedule &other) const { return (score > other.score); };
   //void * getAiRef                 () { return AIManagerRef; };
   //FGAISchedule* getAddress        () { return this;};
   // More member functions follow later
index d9cba6e0c847616909692611af6891952ea88f69..99a97c9d98899c5b09d01ffa483c9bf63db2edbb 100644 (file)
@@ -63,7 +63,7 @@
 #include <AIModel/AIFlightPlan.hxx>
 #include <AIModel/AIBase.hxx>
 #include <Airports/simple.hxx>
-#include <Main/fg_init.hxx>   // That's pretty ugly, but I need fgFindAirportID
+#include <Main/fg_init.hxx>
 
 
 
@@ -76,26 +76,27 @@ SG_USING_STD(sort);
  *****************************************************************************/
 FGTrafficManager::FGTrafficManager()
 {
+  score = 0;
 }
 
 
 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;
-       }
-      else 
-       {
-         currAircraft++;
-       }
-    }
+  //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;
+  //   }
+  //   else 
+  //   {
+  //     currAircraft++;
+  //   }
+  //   }
   //cerr << "Sorting by distance " << endl;
   sort(scheduledAircraft.begin(), scheduledAircraft.end());
   currAircraft = scheduledAircraft.begin();
@@ -107,7 +108,7 @@ void FGTrafficManager::update(double something)
 {
   time_t now = time(NULL) + fgGetLong("/sim/time/warp");
   if (scheduledAircraft.size() == 0)
-         return;
+    return;
   if(currAircraft == scheduledAircraft.end())
     {
       //cerr << "resetting schedule " << endl;
@@ -226,6 +227,11 @@ void  FGTrafficManager::endElement (const char * name) {
       //cerr << "Pusing back flight " << callsign << endl;
       //cerr << callsign  <<  " " << fltrules     << " "<< departurePort << " " <<  arrivalPort << " "
       //   << cruiseAlt <<  " " << departureTime<< " "<< arrivalTime   << " " << repeat << endl;
+
+      //Prioritize aircraft 
+      string apt = fgGetString("/sim/presets/airport-id");
+      //cerr << "Airport information: " << apt << " " << departurePort << " " << arrivalPort << endl;
+      if (departurePort == apt) score++;
       flights.push_back(FGScheduledFlight(callsign,
                                          fltrules,
                                          departurePort,
@@ -248,9 +254,15 @@ void  FGTrafficManager::endElement (const char * name) {
                                               flighttype,
                                               radius,
                                               offset,
+                                              score,
                                               flights));
       while(flights.begin() != flights.end())
        flights.pop_back();
+      SG_LOG( SG_GENERAL, SG_BULK, "Reading aircraft : " 
+             << registration 
+             << " with prioritization score " 
+             << score);
+      score = 0;
     }
 }
 
index b287ef62bfcbdd784b25c0f80c8519dde87a329f..6c90effd8fc094ad50ce75ec79341db14b514202 100644 (file)
@@ -49,6 +49,7 @@ private:
     port, timeString, departurePort, departureTime, arrivalPort, arrivalTime,
     repeat, acType, airline, m_class, flighttype;
   int cruiseAlt;
+  int score;
   double radius, offset;
   bool heavy;