From 8c2e595ff0d913af24ee3ef88777137163ea6d3c Mon Sep 17 00:00:00 2001 From: durk Date: Sat, 29 Jul 2006 18:17:19 +0000 Subject: [PATCH] Spectacular improvement in traffic manager initialization and preparatory 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 | 4 ++ src/AIModel/AIFlightPlan.hxx | 3 +- src/AIModel/AIFlightPlanCreate.cxx | 65 ++++++++++++------ src/AIModel/AIFlightPlanCreateCruise.cxx | 2 +- src/Airports/groundnetwork.cxx | 78 +++++++++++++++++----- src/Airports/groundnetwork.hxx | 25 +++++-- src/Traffic/SchedFlight.cxx | 4 +- src/Traffic/Schedule.cxx | 85 +++++++++++++----------- src/Traffic/Schedule.hxx | 12 ++-- src/Traffic/TrafficMgr.cxx | 44 +++++++----- src/Traffic/TrafficMgr.hxx | 1 + 11 files changed, 219 insertions(+), 104 deletions(-) diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 318d734ca..1ffc43283 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -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; } diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index 755b672ec..023ad85a0 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -112,7 +112,8 @@ private: int leg; int gateId; string activeRunway; - FGAirRoute route; + FGAirRoute airRoute; + FGTaxiRoute *taxiRoute; Point3D temp; diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx index 90403432d..1f772ccc0 100644 --- a/src/AIModel/AIFlightPlanCreate.cxx +++ b/src/AIModel/AIFlightPlanCreate.cxx @@ -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 ); diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index 03bfce80f..c60e40bb2 100755 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -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; } diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index c6632882c..54942d024 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -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; } diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index 10b0c1a7d..a67eb7266 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -104,6 +104,8 @@ public: double getLength() { return length; }; int getIndex() { return index; }; + FGTaxiSegment *getAddress() { return this;}; + }; @@ -111,21 +113,32 @@ public: typedef vector intVec; typedef vector::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); diff --git a/src/Traffic/SchedFlight.cxx b/src/Traffic/SchedFlight.cxx index 731ee6b8f..1e45921cd 100644 --- a/src/Traffic/SchedFlight.cxx +++ b/src/Traffic/SchedFlight.cxx @@ -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; } diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 3a20c9668..f80667687 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -25,6 +25,8 @@ # include "config.h" #endif +#define BOGUS 0xFFFF + #include #include #include @@ -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; +// } diff --git a/src/Traffic/Schedule.hxx b/src/Traffic/Schedule.hxx index daaa4e240..a79585e0b 100644 --- a/src/Traffic/Schedule.hxx +++ b/src/Traffic/Schedule.hxx @@ -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 diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index d9cba6e0c..99a97c9d9 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -63,7 +63,7 @@ #include #include #include -#include
// That's pretty ugly, but I need fgFindAirportID +#include
@@ -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; } } diff --git a/src/Traffic/TrafficMgr.hxx b/src/Traffic/TrafficMgr.hxx index b287ef62b..6c90effd8 100644 --- a/src/Traffic/TrafficMgr.hxx +++ b/src/Traffic/TrafficMgr.hxx @@ -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; -- 2.39.5