X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FATC%2Ftrafficcontrol.cxx;h=6b77890a0acc5d461ea85eb97c2c7fce92e53010;hb=c15e4753ac22a8a003336fd3f75587eaf6ed1ca3;hp=a25f9195646b2f5da7915b6f010cedba82a6cfb3;hpb=10d2d9477813406eb18580a90856e774de3002ea;p=flightgear.git diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index a25f91956..6b77890a0 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -25,6 +25,7 @@ #endif #include +#include #include #include @@ -34,6 +35,9 @@ #include #include #include +#include +#include + #include #include "trafficcontrol.hxx" @@ -41,16 +45,42 @@ #include #include #include -#include #include #include #include #include -#include +#include #include #include using std::sort; +using std::string; +using std::cout; +using std::endl; + +namespace { + +TrafficVectorIterator findTraffic(TrafficVector& vec, int id) +{ + TrafficVectorIterator it = vec.begin(); + for (; it != vec.end(); ++it) { + if (it->getId() == id) { + return it; + } + } + + return it; // vec.end, effectively +} + +void clearTrafficControllers(TrafficVector& vec) +{ + TrafficVectorIterator it = vec.begin(); + for (; it != vec.end(); ++it) { + it->getAircraft()->clearATCController(); + } +} + +} // of anonymous namespace /*************************************************************************** * ActiveRunway @@ -60,7 +90,7 @@ time_t ActiveRunway::requestTimeSlot(time_t eta) time_t newEta; time_t separation = 90; bool found = false; - if (estimatedArrivalTimes.size() == 0) { + if (estimatedArrivalTimes.empty()) { estimatedArrivalTimes.push_back(eta); return eta; } else { @@ -128,7 +158,9 @@ time_t ActiveRunway::requestTimeSlot(time_t eta) estimatedArrivalTimes.push_back(newEta); sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end()); // do some housekeeping : remove any timestamps that are past - time_t now = time(NULL) + fgGetLong("/sim/time/warp"); + + time_t now = globals->get_time_params()->get_cur_time(); + TimeVectorIterator i = estimatedArrivalTimes.begin(); while (i != estimatedArrivalTimes.end()) { if ((*i) < now) { @@ -175,16 +207,21 @@ FGTrafficRecord::FGTrafficRecord(): allowTransmission(true), allowPushback(true), priority(0), + timer(0), latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0) { } +FGTrafficRecord::~FGTrafficRecord() +{ +} + void FGTrafficRecord::setPositionAndIntentions(int pos, FGAIFlightPlan * route) { currentPos = pos; - if (intentions.size()) { + if (! intentions.empty()) { intVecIterator i = intentions.begin(); if ((*i) != pos) { SG_LOG(SG_ATC, SG_ALERT, @@ -202,6 +239,17 @@ void FGTrafficRecord::setPositionAndIntentions(int pos, } } } + +void FGTrafficRecord::setAircraft(FGAIAircraft *ref) +{ + aircraft = ref; +} + +FGAIAircraft* FGTrafficRecord::getAircraft() const +{ + return aircraft.ptr(); +} + /** * Check if another aircraft is ahead of the current one, and on the same * return true / false is the is/isn't the case. @@ -216,7 +264,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other) //cerr << callsign << ": Check Position and intentions: we are on the same taxiway" << other.callsign << "Index = " << currentPos << endl; result = true; } - // else if (other.intentions.size()) + // else if (! other.intentions.empty()) // { // cerr << "Start check 2" << endl; // intVecIterator i = other.intentions.begin(); @@ -226,7 +274,7 @@ bool FGTrafficRecord::checkPositionAndIntentions(FGTrafficRecord & other) // cerr << "Check Position and intentions: current matches other.intentions" << endl; // result = true; // } - else if (intentions.size()) { + else if (! intentions.empty()) { //cerr << "Start check 3" << endl; intVecIterator i = intentions.begin(); //while (!((i == intentions.end()) || ((*i) == other.currentPos))) @@ -270,7 +318,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, otherTargetNode = net->findSegment(other.currentPos)->getEnd()->getIndex(); // OKAY,... if ((currentTargetNode == otherTargetNode) && currentTargetNode > 0) return currentTargetNode; - if (intentions.size()) { + if (! intentions.empty()) { for (i = intentions.begin(); i != intentions.end(); i++) { if ((*i) > 0) { if (currentTargetNode == @@ -281,7 +329,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, } } } - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (i = other.intentions.begin(); i != other.intentions.end(); i++) { if ((*i) > 0) { @@ -293,7 +341,7 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net, } } } - if (intentions.size() && other.intentions.size()) { + if (! intentions.empty() && ! other.intentions.empty()) { for (i = intentions.begin(); i != intentions.end(); i++) { for (j = other.intentions.begin(); j != other.intentions.end(); j++) { @@ -325,7 +373,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net, net->findSegment(other.currentPos)->getEnd()->getIndex(); if ((node == othernode) && (node != -1)) return true; - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (intVecIterator i = other.intentions.begin(); i != other.intentions.end(); i++) { if (*i > 0) { @@ -337,7 +385,7 @@ bool FGTrafficRecord::onRoute(FGGroundNetwork * net, } //if (other.currentPos > 0) // othernode = net->findSegment(other.currentPos)->getEnd()->getIndex(); - //if (intentions.size()) + //if (! intentions.empty()) // { // for (intVecIterator i = intentions.begin(); i != intentions.end(); i++) // { @@ -381,7 +429,7 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net, } } } - if (other.intentions.size()) { + if (! other.intentions.empty()) { for (intVecIterator j = other.intentions.begin(); j != other.intentions.end(); j++) { // cerr << "Current segment 1 " << (*i) << endl; @@ -409,9 +457,9 @@ bool FGTrafficRecord::isOpposing(FGGroundNetwork * net, return false; } -bool FGTrafficRecord::isActive(int margin) +bool FGTrafficRecord::isActive(int margin) const { - time_t now = time(NULL) + fgGetLong("/sim/time/warp"); + time_t now = globals->get_time_params()->get_cur_time(); time_t deptime = aircraft->getTrafficRef()->getDepartureTime(); return ((now + margin) > deptime); } @@ -429,7 +477,7 @@ void FGTrafficRecord::setHeadingAdjustment(double heading) instruction.setHeading(heading); } -bool FGTrafficRecord::pushBackAllowed() +bool FGTrafficRecord::pushBackAllowed() const { return allowPushback; } @@ -456,7 +504,7 @@ FGATCInstruction::FGATCInstruction() } -bool FGATCInstruction::hasInstruction() +bool FGATCInstruction::hasInstruction() const { return (holdPattern || holdPosition || changeSpeed || changeHeading || changeAltitude || resolveCircularWait); @@ -477,11 +525,14 @@ FGATCController::FGATCController() available = true; lastTransmission = 0; initialized = false; + lastTransmissionDirection = ATC_AIR_TO_GROUND; + group = NULL; } FGATCController::~FGATCController() { - //cerr << "running FGATController destructor" << endl; + FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC"); + mgr->removeController(this); } string FGATCController::getGateName(FGAIAircraft * ref) @@ -588,8 +639,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent, getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, heading); rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway); - fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()-> - getDynamics()->getSID(activeRunway, heading); + fp = NULL; rec->getAircraft()->GetFlightPlan()->setSID(fp); if (fp) { SID = fp->getName() + " departure"; @@ -736,11 +786,8 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent, SGGeod sender_pos; double sender_alt_ft, sender_alt; if(ground_to_air) { - sender_alt_ft = parent->getElevation(); - sender_alt = sender_alt_ft * SG_FEET_TO_METER; - sender_pos= SGGeod::fromDegM( parent->getLongitude(), - parent->getLatitude(), sender_alt ); - } + sender_pos = parent->parent()->geod(); + } else { sender_alt_ft = rec->getAltitude(); sender_alt = sender_alt_ft * SG_FEET_TO_METER; @@ -771,7 +818,7 @@ string FGATCController::formatATCFrequency3_2(int freq) // TODO: Set transponder codes according to real-world routes. // The current version just returns a random string of four octal numbers. -string FGATCController::genTransponderCode(string fltRules) +string FGATCController::genTransponderCode(const string& fltRules) { if (fltRules == "VFR") { return string("1200"); @@ -802,6 +849,15 @@ FGTowerController::FGTowerController(FGAirportDynamics *par) : parent = par; } +FGTowerController::~FGTowerController() +{ + // to avoid the exception described in: + // https://sourceforge.net/p/flightgear/codetickets/1864/ + // we want to ensure AI aircraft signing-off is a no-op now + + clearTrafficControllers(activeTraffic); +} + // void FGTowerController::announcePosition(int id, FGAIFlightPlan * intendedRoute, @@ -815,7 +871,7 @@ void FGTowerController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -825,7 +881,7 @@ void FGTowerController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { FGTrafficRecord rec; rec.setId(id); @@ -838,7 +894,7 @@ void FGTowerController::announcePosition(int id, activeTraffic.push_back(rec); // Don't just schedule the aircraft for the tower controller, also assign if to the correct active runway. ActiveRunwayVecIterator rwy = activeRunways.begin(); - if (activeRunways.size()) { + if (! activeRunways.empty()) { while (rwy != activeRunways.end()) { if (rwy->getRunwayName() == intendedRoute->getRunway()) { break; @@ -869,7 +925,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon // Search whether the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -879,7 +935,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon } } // // update position of the current aircraft - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { SG_LOG(SG_ATC, SG_ALERT, "AI error: updating aircraft without traffic record at " << SG_ORIGIN); } else { @@ -952,7 +1008,7 @@ void FGTowerController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -963,7 +1019,7 @@ void FGTowerController::signOff(int id) } // If this aircraft has left the runway, we can clear the departure record for this runway ActiveRunwayVecIterator rwy = activeRunways.begin(); - if (activeRunways.size()) { + if (! activeRunways.empty()) { //while ((rwy->getRunwayName() != i->getRunway()) && (rwy != activeRunways.end())) { while (rwy != activeRunways.end()) { if (rwy->getRunwayName() == i->getRunway()) { @@ -979,7 +1035,7 @@ void FGTowerController::signOff(int id) "AI error: Attempting to erase non-existing runway clearance record in FGTowerController::signoff at " << SG_ORIGIN); } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || (activeTraffic.empty())) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN); } else { @@ -1000,7 +1056,7 @@ bool FGTowerController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1009,7 +1065,7 @@ bool FGTowerController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1024,7 +1080,7 @@ FGATCInstruction FGTowerController::getInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1033,7 +1089,7 @@ FGATCInstruction FGTowerController::getInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1043,7 +1099,7 @@ FGATCInstruction FGTowerController::getInstruction(int id) } void FGTowerController::render(bool visible) { - //cerr << "FGTowerController::render function not yet implemented" << endl; + //std::cerr << "FGTowerController::render function not yet implemented" << std::endl; } string FGTowerController::getName() { @@ -1067,6 +1123,11 @@ FGStartupController::FGStartupController(FGAirportDynamics *par): parent = par; } +FGStartupController::~FGStartupController() +{ + clearTrafficControllers(activeTraffic); +} + void FGStartupController::announcePosition(int id, FGAIFlightPlan * intendedRoute, int currentPosition, double lat, @@ -1079,7 +1140,7 @@ void FGStartupController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1089,7 +1150,7 @@ void FGStartupController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { FGTrafficRecord rec; rec.setId(id); @@ -1119,7 +1180,7 @@ bool FGStartupController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1128,7 +1189,7 @@ bool FGStartupController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1143,7 +1204,7 @@ FGATCInstruction FGStartupController::getInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1152,7 +1213,7 @@ FGATCInstruction FGStartupController::getInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1166,7 +1227,7 @@ void FGStartupController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1175,7 +1236,7 @@ void FGStartupController::signOff(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN); } else { @@ -1192,7 +1253,7 @@ bool FGStartupController::checkTransmissionState(int st, time_t now, time_t star if ((msgDir == ATC_AIR_TO_GROUND) && isUserAircraft(i->getAircraft())) { //cerr << "Checking state " << st << " for " << i->getAircraft()->getCallSign() << endl; - static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true); + SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true); int n = trans_num->getIntValue(); if (n == 0) { trans_num->setIntValue(-1); @@ -1225,7 +1286,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1250,7 +1311,8 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l // The user controlled aircraft should have crased here, because it doesn't have a traffic reference. // NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight. time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime(); - time_t now = time(NULL) + fgGetLong("/sim/time/warp"); + time_t now = globals->get_time_params()->get_cur_time(); + //cerr << i->getAircraft()->getTrafficRef()->getCallSign() // << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available // << " at parking " << getGateName(i->getAircraft()) << endl; @@ -1310,7 +1372,7 @@ static void WorldCoordinate(osg::Matrix& obj_pos, double lat, void FGStartupController::render(bool visible) { - + //std::cerr << "Rendering startup controller" << std::endl; SGMaterialLib *matlib = globals->get_matlib(); if (group) { //int nr = ; @@ -1333,7 +1395,8 @@ void FGStartupController::render(bool visible) //for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) { double dx = 0; - time_t now = time(NULL) + fgGetLong("/sim/time/warp"); + time_t now = globals->get_time_params()->get_cur_time(); + for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) { if (i->isActive(300)) { // Handle start point @@ -1342,10 +1405,10 @@ void FGStartupController::render(bool visible) if (pos > 0) { FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(pos); SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude()))); - SGGeod end (SGGeod::fromDeg(segment->getEnd()->getLongitude(), segment->getEnd()->getLatitude())); + SGGeod end (segment->getEnd()->geod()); double length = SGGeodesy::distanceM(start, end); - //heading = SGGeodesy::headingDeg(start->getGeod(), end->getGeod()); + //heading = SGGeodesy::headingDeg(start->geod(), end->geod()); double az2, heading; //, distanceM; SGGeodesy::inverse(start, end, heading, az2, length); @@ -1365,7 +1428,7 @@ void FGStartupController::render(bool visible) } else { elevationStart = ((i)->getAircraft()->_getAltitude() * SG_FEET_TO_METER); } - double elevationEnd = segment->getEnd()->getElevationM(parent->getElevation()*SG_FEET_TO_METER); + double elevationEnd = segment->getEnd()->getElevationM(); if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) { SGGeod center2 = end; center2.setElevationM(SG_MAX_ELEVATION_M); @@ -1404,9 +1467,9 @@ void FGStartupController::render(bool visible) //osg::Node *custom_obj; SGMaterial *mat; if (segment->hasBlock(now)) { - mat = matlib->find("UnidirectionalTaperRed"); + mat = matlib->find("UnidirectionalTaperRed", center); } else { - mat = matlib->find("UnidirectionalTaperGreen"); + mat = matlib->find("UnidirectionalTaperGreen", center); } if (mat) geode->setEffect(mat->get_effect()); @@ -1427,10 +1490,10 @@ void FGStartupController::render(bool visible) obj_trans->setDataVariance(osg::Object::STATIC); FGTaxiSegment *segment = parent->getGroundNetwork()->findSegment(k); - double elevationStart = segment->getStart()->getElevationM(parent->getElevation()*SG_FEET_TO_METER); - double elevationEnd = segment->getEnd ()->getElevationM(parent->getElevation()*SG_FEET_TO_METER); + double elevationStart = segment->getStart()->getElevationM(); + double elevationEnd = segment->getEnd ()->getElevationM(); if ((elevationStart == 0) || (elevationStart == parent->getElevation())) { - SGGeod center2 = segment->getStart()->getGeod(); + SGGeod center2 = segment->getStart()->geod(); center2.setElevationM(SG_MAX_ELEVATION_M); if (local_scenery->get_elevation_m( center2, elevationStart, NULL )) { //elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5; @@ -1442,7 +1505,7 @@ void FGStartupController::render(bool visible) segment->getStart()->setElevation(elevationStart); } if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) { - SGGeod center2 = segment->getEnd()->getGeod(); + SGGeod center2 = segment->getEnd()->geod(); center2.setElevationM(SG_MAX_ELEVATION_M); if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) { //elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5; @@ -1461,8 +1524,9 @@ void FGStartupController::render(bool visible) //cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl; - - WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope ); + SGGeod segCenter(segment->getCenter()); + WorldCoordinate( obj_pos, segCenter.getLatitudeDeg(), + segCenter.getLongitudeDeg(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope ); //WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) ); @@ -1481,9 +1545,9 @@ void FGStartupController::render(bool visible) //osg::Node *custom_obj; SGMaterial *mat; if (segment->hasBlock(now)) { - mat = matlib->find("UnidirectionalTaperRed"); + mat = matlib->find("UnidirectionalTaperRed", segCenter); } else { - mat = matlib->find("UnidirectionalTaperGreen"); + mat = matlib->find("UnidirectionalTaperGreen", segCenter); } if (mat) geode->setEffect(mat->get_effect()); @@ -1523,6 +1587,11 @@ FGApproachController::FGApproachController(FGAirportDynamics *par): parent = par; } +FGApproachController::~FGApproachController() +{ + clearTrafficControllers(activeTraffic); +} + // void FGApproachController::announcePosition(int id, FGAIFlightPlan * intendedRoute, @@ -1536,7 +1605,7 @@ void FGApproachController::announcePosition(int id, TrafficVectorIterator i = activeTraffic.begin(); // Search whether the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1546,7 +1615,7 @@ void FGApproachController::announcePosition(int id, } } // Add a new TrafficRecord if no one exsists for this aircraft. - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { FGTrafficRecord rec; rec.setId(id); @@ -1569,7 +1638,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route TrafficVectorIterator current, closest; - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1579,7 +1648,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double } } // // update position of the current aircraft - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: updating aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1618,7 +1687,7 @@ void FGApproachController::signOff(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id alread has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1627,7 +1696,7 @@ void FGApproachController::signOff(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN); } else { @@ -1647,7 +1716,7 @@ bool FGApproachController::hasInstruction(int id) TrafficVectorIterator i = activeTraffic.begin(); // Search search if the current id has an entry // This might be faster using a map instead of a vector, but let's start by taking a safe route - if (activeTraffic.size()) { + if (! activeTraffic.empty()) { //while ((i->getId() != id) && i != activeTraffic.end()) { while (i != activeTraffic.end()) { if (i->getId() == id) { @@ -1656,7 +1725,7 @@ bool FGApproachController::hasInstruction(int id) i++; } } - if (i == activeTraffic.end() || (activeTraffic.size() == 0)) { + if (i == activeTraffic.end() || activeTraffic.empty()) { SG_LOG(SG_ATC, SG_ALERT, "AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN); } else { @@ -1690,7 +1759,7 @@ FGATCInstruction FGApproachController::getInstruction(int id) } -ActiveRunway *FGApproachController::getRunway(string name) +ActiveRunway *FGApproachController::getRunway(const string& name) { ActiveRunwayVecIterator rwy = activeRunways.begin(); if (activeRunways.size()) { @@ -1710,7 +1779,7 @@ ActiveRunway *FGApproachController::getRunway(string name) } void FGApproachController::render(bool visible) { - //cerr << "FGApproachController::render function not yet implemented" << endl; + //std::cerr << "FGApproachController::render function not yet implemented" << std::endl; }