1 // FGTower - a class to provide tower control at towered airports.
3 // Written by David Luff, started March 2002.
5 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
6 // Copyright (C) 2008 Daniyar Atadjanov (ground clearance, gear check, weather, etc.)
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 # include <strings.h> // bcopy()
29 # include <string.h> // MSVC doesn't have strings.h
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/math/sg_geodesy.hxx>
37 #include <simgear/math/sg_random.h>
38 #include <simgear/misc/sg_path.hxx>
40 #include <Main/globals.hxx>
41 #include <Airports/runways.hxx>
45 #include "ATCutils.hxx"
46 #include "ATCDialog.hxx"
47 #include "commlist.hxx"
48 #include "AILocalTraffic.hxx"
55 TowerPlaneRec::TowerPlaneRec() :
58 clearedToLineUp(false),
59 clearedToTakeOff(false),
60 holdShortReported(false),
61 lineUpReported(false),
62 downwindReported(false),
63 longFinalReported(false),
64 longFinalAcknowledged(false),
66 finalAcknowledged(false),
67 rwyVacatedReported(false),
68 rwyVacatedAcknowledged(false),
69 goAroundReported(false),
70 instructedToGoAround(false),
73 vfrArrivalReported(false),
74 vfrArrivalAcknowledged(false),
77 landingType(AIP_LT_UNKNOWN),
79 gearUpReported(false),
82 plane.callsign = "UNKNOWN";
85 TowerPlaneRec::TowerPlaneRec(const PlaneRec& p) :
88 clearedToLineUp(false),
89 clearedToTakeOff(false),
90 holdShortReported(false),
91 lineUpReported(false),
92 downwindReported(false),
93 longFinalReported(false),
94 longFinalAcknowledged(false),
96 finalAcknowledged(false),
97 rwyVacatedReported(false),
98 rwyVacatedAcknowledged(false),
99 goAroundReported(false),
100 instructedToGoAround(false),
103 vfrArrivalReported(false),
104 vfrArrivalAcknowledged(false),
107 landingType(AIP_LT_UNKNOWN),
109 gearUpReported(false),
115 TowerPlaneRec::TowerPlaneRec(const Point3D& pt) :
117 clearedToLand(false),
118 clearedToLineUp(false),
119 clearedToTakeOff(false),
120 holdShortReported(false),
121 lineUpReported(false),
122 downwindReported(false),
123 longFinalReported(false),
124 longFinalAcknowledged(false),
125 finalReported(false),
126 finalAcknowledged(false),
127 rwyVacatedReported(false),
128 rwyVacatedAcknowledged(false),
129 goAroundReported(false),
130 instructedToGoAround(false),
133 vfrArrivalReported(false),
134 vfrArrivalAcknowledged(false),
137 landingType(AIP_LT_UNKNOWN),
139 gearUpReported(false),
142 plane.callsign = "UNKNOWN";
146 TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const Point3D& pt) :
148 clearedToLand(false),
149 clearedToLineUp(false),
150 clearedToTakeOff(false),
151 holdShortReported(false),
152 lineUpReported(false),
153 downwindReported(false),
154 longFinalReported(false),
155 longFinalAcknowledged(false),
156 finalReported(false),
157 finalAcknowledged(false),
158 rwyVacatedReported(false),
159 rwyVacatedAcknowledged(false),
160 goAroundReported(false),
161 instructedToGoAround(false),
164 vfrArrivalReported(false),
165 vfrArrivalAcknowledged(false),
168 landingType(AIP_LT_UNKNOWN),
170 gearUpReported(false),
180 /*******************************************
183 Currently user is assumed to have taken off again when leaving the runway - check speed/elev for taxiing-in. (MAJOR)
185 Use track instead of heading to determine what leg of the circuit the user is flying. (MINOR)
187 Use altitude as well as position to try to determine if the user has left the circuit. (MEDIUM - other issues as well).
189 Currently HoldShortReported code assumes there will be only one plane holding for the runway at once and
190 will break when planes start queueing. (CRITICAL)
192 Report-Runway-Vacated is left as only user ATC option following a go-around. (MAJOR)
194 Report-Downwind is not added as ATC option when user takes off to fly a circuit. (MAJOR)
196 eta of USER can be calculated very wrongly in circuit if flying straight out and turn4 etc are with +ve ortho y.
197 This can then screw up circuit ordering for other planes (MEDIUM)
199 USER leaving circuit needs to be more robustly considered when intentions unknown
200 Currently only considered during climbout and breaks when user turns (MEDIUM).
202 GetPos() of the AI planes is called erratically - either too much or not enough. (MINOR)
204 GO-AROUND is instructed very late at < 12s to landing - possibly make more dependent on chance of rwy clearing before landing (FEATURE)
206 Need to make clear when TowerPlaneRecs do or don't get deleted in RemoveFromCircuitList etc. (MINOR until I misuse it - then CRITICAL!)
208 FGTower::RemoveAllUserDialogOptions() really ought to be replaced by an ATCDialog::clear_entries() function. (MINOR - efficiency).
210 At the moment planes in the lists are not guaranteed to always have a sensible ETA - it should be set as part of AddList functions, and lists should only be accessed this way. (FAIRLY MAJOR).
211 *******************************************/
214 separateGround(true),
217 ATCmgr = globals->get_ATC_mgr();
221 // Init the property nodes - TODO - need to make sure we're getting surface winds.
222 wind_from_hdg = fgGetNode("/environment/wind-from-heading-deg", true);
223 wind_speed_knots = fgGetNode("/environment/wind-speed-kt", true);
226 update_count_max = 15;
228 holdListItr = holdList.begin();
229 appListItr = appList.begin();
230 depListItr = depList.begin();
231 rwyListItr = rwyList.begin();
232 circuitListItr = circuitList.begin();
233 trafficListItr = trafficList.begin();
234 vacatedListItr = vacatedList.begin();
238 timeSinceLastDeparture = 9999;
241 nominal_downwind_leg_pos = 1000.0;
242 nominal_base_leg_pos = -1000.0;
243 // TODO - set nominal crosswind leg pos based on minimum distance from takeoff end of rwy.
245 _departureControlled = false;
248 FGTower::~FGTower() {
249 if(!separateGround) {
254 void FGTower::Init() {
255 //cout << "Initialising tower " << ident << '\n';
257 // Pointers to user's position
258 user_lon_node = fgGetNode("/position/longitude-deg", true);
259 user_lat_node = fgGetNode("/position/latitude-deg", true);
260 user_elev_node = fgGetNode("/position/altitude-ft", true);
261 user_hdg_node = fgGetNode("/orientation/heading-deg", true);
263 // Need some way to initialise rwyOccupied flag correctly if the user is on the runway and to know its the user.
264 // I'll punt the startup issue for now though!!!
267 // Setup the ground control at this airport
269 //cout << "Tower ident = " << ident << '\n';
270 if(ATCmgr->GetAirportATCDetails(ident, &a)) {
271 if(a.ground_freq) { // Ground control
272 ground = (FGGround*)ATCmgr->GetATCPointer(ident, GROUND);
273 separateGround = true;
275 // Something has gone wrong :-(
276 SG_LOG(SG_ATC, SG_WARN, "ERROR - ground has frequency but can't get ground pointer :-(");
277 ground = new FGGround(ident);
278 separateGround = false;
281 ground->SetDisplay();
283 ground->SetNoDisplay();
287 // Initialise ground anyway to do the shortest path stuff!
288 // Note that we're now responsible for updating and deleting this - NOT the ATCMgr.
289 ground = new FGGround(ident);
290 separateGround = false;
293 ground->SetDisplay();
295 ground->SetNoDisplay();
299 SG_LOG(SG_ATC, SG_ALERT, "Unable to find airport details for " << ident << " in FGTower::Init()");
300 // Initialise ground anyway to avoid segfault later
301 ground = new FGGround(ident);
302 separateGround = false;
305 ground->SetDisplay();
307 ground->SetNoDisplay();
311 RemoveAllUserDialogOptions();
313 // TODO - attempt to get a departure control pointer to see if we need to hand off departing traffic to departure.
315 // Get the airport elevation
316 aptElev = fgGetAirportElev(ident.c_str());
318 // TODO - this function only assumes one active rwy.
321 // TODO - this currently assumes only one active runway.
322 rwyOccupied = OnActiveRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0));
324 if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
325 //cout << ident << " ADD 0\n";
326 current_atcdialog->add_entry(ident, "@AP Tower, @CS @MI miles @CD of the airport for full stop@AT",
327 "Contact tower for VFR arrival (full stop)", TOWER,
328 (int)USER_REQUEST_VFR_ARRIVAL_FULL_STOP);
330 //cout << "User found on active runway\n";
331 // Assume the user is started at the threshold ready to take-off
332 TowerPlaneRec* t = new TowerPlaneRec;
333 t->plane.callsign = fgGetString("/sim/user/callsign");
334 t->plane.type = GA_SINGLE; // FIXME - hardwired!!
335 t->opType = TTT_UNKNOWN; // We don't know if the user wants to do circuits or a departure...
336 t->landingType = AIP_LT_UNKNOWN;
337 t->leg = TAKEOFF_ROLL;
340 t->clearedToTakeOff = false;
341 rwyList.push_back(t);
342 rwyListItr = rwyList.begin();
344 current_atcdialog->add_entry(ident, "@CS @TO", "Request departure / take-off clearance",
345 TOWER, (int)USER_REQUEST_TAKE_OFF);
349 void FGTower::Update(double dt) {
350 //cout << "T" << endl;
351 // Each time step, what do we need to do?
352 // We need to go through the list of outstanding requests and acknowedgements
353 // and process at least one of them.
354 // We need to go through the list of planes under our control and check if
355 // any need to be addressed.
356 // We need to check for planes not under our control coming within our
357 // control area and address if necessary.
359 // TODO - a lot of the below probably doesn't need to be called every frame and should be staggered.
361 // Sort the arriving planes
364 if(ident == "KEMT") {
365 cout << update_count << "\ttL: " << trafficList.size() << " cL: " << circuitList.size() << " hL: " << holdList.size() << " aL: " << appList.size() << '\n';
368 //if(ident == "EGNX") cout << display << '\n';
370 if(departed != false) {
371 timeSinceLastDeparture += dt;
372 //if(ident == "KEMT")
373 // cout << " dt = " << dt << " timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
376 //cout << ident << " respond = " << respond << " responseReqd = " << responseReqd << '\n';
378 if(!responseReqd) SG_LOG(SG_ATC, SG_ALERT, "ERROR - respond is true and responseReqd is false in FGTower::Update(...)");
381 responseReqd = false;
384 // Calculate the eta of each plane to the threshold.
385 // For ground traffic this is the fastest they can get there.
386 // For air traffic this is the middle approximation.
387 if(update_count == 1) {
388 doThresholdETACalc();
391 // Order the list of traffic as per expected threshold use and flag any conflicts
392 if(update_count == 2) {
393 //bool conflicts = doThresholdUseOrder();
394 doThresholdUseOrder();
397 // sortConficts() !!!
399 if(update_count == 4) {
403 // Uggh - HACK - why have we got rwyOccupied - wouldn't simply testing rwyList.size() do?
410 if(update_count == 5 && rwyOccupied) {
414 if(update_count == 6) {
415 CheckCircuitList(dt);
418 if(update_count == 7) {
419 CheckApproachList(dt);
422 if(update_count == 8) {
423 CheckDepartureList(dt);
426 // TODO - do one plane from the departure list and set departed = false when out of consideration
430 if(!separateGround) {
431 // The display stuff might have to get more clever than this when not separate
432 // since the tower and ground might try communicating simultaneously even though
433 // they're mean't to be the same contoller/frequency!!
434 // We could also get rid of this by overloading FGATC's Set(No)Display() functions.
436 ground->SetDisplay();
438 ground->SetNoDisplay();
444 // How big should ii get - ie how long should the update cycle interval stretch?
445 if(update_count >= update_count_max) {
449 // Call the base class update for the response time handling.
453 if(ident == "KEMT") {
454 // For AI debugging convienience - may be removed
456 user_pos.setlon(user_lon_node->getDoubleValue());
457 user_pos.setlat(user_lat_node->getDoubleValue());
458 user_pos.setelev(user_elev_node->getDoubleValue());
459 Point3D user_ortho_pos = ortho.ConvertToLocal(user_pos);
460 fgSetDouble("/AI/user/ortho-x", user_ortho_pos.x());
461 fgSetDouble("/AI/user/ortho-y", user_ortho_pos.y());
462 fgSetDouble("/AI/user/elev", user_elev_node->getDoubleValue());
466 //cout << "Done T" << endl;
469 void FGTower::ReceiveUserCallback(int code) {
470 if(code == (int)USER_REQUEST_VFR_DEPARTURE) {
471 RequestDepartureClearance("USER");
472 } else if(code == (int)USER_REQUEST_VFR_ARRIVAL) {
473 VFRArrivalContact("USER");
474 } else if(code == (int)USER_REQUEST_VFR_ARRIVAL_FULL_STOP) {
475 VFRArrivalContact("USER", FULL_STOP);
476 } else if(code == (int)USER_REQUEST_VFR_ARRIVAL_TOUCH_AND_GO) {
477 VFRArrivalContact("USER", TOUCH_AND_GO);
478 } else if(code == (int)USER_REPORT_DOWNWIND) {
479 ReportDownwind("USER");
480 } else if(code == (int)USER_REPORT_3_MILE_FINAL) {
481 // For now we'll just call report final instead of report long final to avoid having to alter the response code
483 } else if(code == (int)USER_REPORT_RWY_VACATED) {
484 ReportRunwayVacated("USER");
485 } else if(code == (int)USER_REPORT_GOING_AROUND) {
486 ReportGoingAround("USER");
487 } else if(code == (int)USER_REQUEST_TAKE_OFF) {
488 RequestTakeOffClearance("USER");
492 // **************** RESPONSE FUNCTIONS ****************
494 void FGTower::Respond() {
495 //cout << "\nEntering Respond, responseID = " << responseID << endl;
496 TowerPlaneRec* t = FindPlane(responseID);
499 if(t->vfrArrivalReported && !t->vfrArrivalAcknowledged) {
500 //cout << "Tower " << ident << " is responding to VFR arrival reported...\n";
501 // Testing - hardwire straight in for now
502 string trns = t->plane.callsign;
506 // Should we clear staight in or for downwind entry?
507 // For now we'll clear straight in if greater than 1km from a line drawn through the threshold perpendicular to the rwy.
508 // Later on we might check the actual heading and direct some of those to enter on downwind or base.
509 Point3D op = ortho.ConvertToLocal(t->pos);
510 float gp = fgGetFloat("/gear/gear/position-norm");
512 t->gearWasUp = true; // This will be needed on final to tell "Gear down, ready to land."
514 trns += " Report three mile straight-in runway ";
515 t->opType = STRAIGHT_IN;
517 current_atcdialog->add_entry(ident, "@CS @MI mile final runway @RW@GR", "Report Final", TOWER, (int)USER_REPORT_3_MILE_FINAL);
519 t->planePtr->RegisterTransmission(14);
522 // For now we'll just request reporting downwind.
523 // TODO - In real life something like 'report 2 miles southwest right downwind rwy 19R' might be used
524 // but I'm not sure how to handle all permutations of which direction to tell to report from yet.
526 //cout << "Responding, rwy.patterDirection is " << rwy.patternDirection << '\n';
527 trns += ((rwy.patternDirection == 1) ? "right " : "left ");
528 trns += "downwind runway ";
530 // leave it in the app list until it gets into pattern though.
532 current_atcdialog->add_entry(ident, "@AP Tower, @CS Downwind @RW", "Report Downwind", TOWER, (int)USER_REPORT_DOWNWIND);
534 t->planePtr->RegisterTransmission(15);
537 trns += ConvertRwyNumToSpokenString(activeRwy);
539 pending_transmission = trns;
542 //cout << "Not displaying, trns was " << trns << '\n';
544 t->vfrArrivalAcknowledged = true;
545 } else if(t->downwindReported) {
546 //cout << "Tower " << ident << " is responding to downwind reported...\n";
547 ProcessDownwindReport(t);
548 t->downwindReported = false;
549 } else if(t->lineUpReported) {
550 string trns = t->plane.callsign;
552 double f = globals->get_ATC_mgr()->GetFrequency(ident, ATIS) / 100.0;
555 wtr = ", " + GetWeather();
557 trns += " Cleared for take-off" + wtr;
558 t->clearedToTakeOff = true;
560 if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), true)) {
561 // TODO: Check if any AI Planes on final and tell something like: "After the landing CALLSIGN line up runway two eight right"
562 trns += " Line up runway " + ConvertRwyNumToSpokenString(activeRwy);
563 t->clearedToTakeOff = false;
564 current_atcdialog->add_entry(ident, "@CS @TO", "Report ready for take-off", TOWER, (int)USER_REQUEST_TAKE_OFF);
568 if((int(sg_random() * 10) + 1) != 3) {
569 t->clearedToTakeOff = true;
570 trns += " Cleared immediate take-off ";
572 t->clearedToTakeOff = false;
573 trns += " Negative, departure runway " + ConvertRwyNumToSpokenString(activeRwy);
578 pending_transmission = trns;
581 //cout << "Not displaying, trns was " << trns << '\n';
583 t->lineUpReported = false;
584 } else if(t->holdShortReported) {
585 //cout << "Tower " << ident << " is reponding to holdShortReported...\n";
587 if(rwyOccupied) { // TODO - ought to add a sanity check that it isn't this plane only on the runway (even though it shouldn't be!!)
588 // Do nothing for now - consider acknowloging hold short eventually
590 ClearHoldingPlane(t);
591 t->leg = TAKEOFF_ROLL;
592 rwyList.push_back(t);
593 rwyListItr = rwyList.begin();
595 // WARNING - WE ARE ASSUMING ONLY ONE PLANE REPORTING HOLD AT A TIME BELOW
596 // FIXME TODO - FIX THIS!!!
597 if(!holdList.empty()) {
598 if(holdListItr == holdList.end()) {
599 holdListItr = holdList.begin();
601 holdList.erase(holdListItr);
602 holdListItr = holdList.begin();
606 // Tell him to hold and what position he is.
607 // Not currently sure under which circumstances we do or don't bother transmitting this.
608 string trns = t->plane.callsign;
609 trns += " hold position";
611 pending_transmission = trns;
614 // TODO - add some idea of what traffic is blocking him.
616 t->holdShortReported = false;
617 } else if(t->finalReported && !(t->finalAcknowledged)) {
618 //cout << "Tower " << ident << " is responding to finalReported...\n";
620 string trns = t->plane.callsign;
621 //cout << (t->nextOnRwy ? "Next on rwy " : "Not next!! ");
622 //cout << (rwyOccupied ? "RWY OCCUPIED!!\n" : "Rwy not occupied\n");
623 if(t->nextOnRwy && !rwyOccupied && !(t->instructedToGoAround)) {
624 if(t->landingType == FULL_STOP) {
625 trns += " cleared to land ";
627 double f = globals->get_ATC_mgr()->GetFrequency(ident, ATIS) / 100.0;
630 wtr = ", " + GetWeather();
632 wtr = ", runway " + ConvertRwyNumToSpokenString(activeRwy);
634 trns += " cleared to land" + wtr;
637 t->clearedToLand = true;
638 // Maybe remove report downwind from menu here as well incase user didn't bother to?
640 //cout << "ADD VACATED B\n";
641 // Put going around at the top (and hence default) since that'll be more desperate,
642 // or put rwy vacated at the top since that'll be more common?
643 current_atcdialog->add_entry(ident, "@CS Going Around", "Report going around", TOWER, USER_REPORT_GOING_AROUND);
644 current_atcdialog->add_entry(ident, "@CS Clear of the runway", "Report runway vacated", TOWER, USER_REPORT_RWY_VACATED);
646 t->planePtr->RegisterTransmission(7);
648 } else if(t->eta < 20) {
649 // Do nothing - we'll be telling it to go around in less than 10 seconds if the
650 // runway doesn't clear so no point in calling "continue approach".
653 trns += " continue approach";
654 trns += " and report ";
655 trns += ((rwy.patternDirection == 1) ? "right " : "left ");
656 trns += "downwind runway " + ConvertRwyNumToSpokenString(activeRwy);
659 current_atcdialog->add_entry(ident, "@AP Tower, @CS Downwind @RW", "Report Downwind", TOWER, (int)USER_REPORT_DOWNWIND);
661 t->planePtr->RegisterTransmission(15);
663 t->clearedToLand = false;
665 if(_display && disp) {
666 pending_transmission = trns;
669 t->finalAcknowledged = true;
670 } else if(t->rwyVacatedReported && !(t->rwyVacatedAcknowledged)) {
671 ProcessRunwayVacatedReport(t);
672 t->rwyVacatedAcknowledged = true;
675 //freqClear = true; // FIXME - set this to come true after enough time to render the message
676 _releaseCounter = 0.0;
678 _runReleaseCounter = true;
679 //cout << "Done Respond\n" << endl;
682 void FGTower::ProcessDownwindReport(TowerPlaneRec* t) {
684 int a = 0; // Count of preceding planes on approach
685 bool cf = false; // conflicting traffic on final
686 bool cc = false; // preceding traffic in circuit
687 TowerPlaneRec* tc = NULL;
688 for(tower_plane_rec_list_iterator twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
689 if((*twrItr)->plane.callsign == responseID) break;
693 if(i > 1) { cc = true; }
694 doThresholdETACalc();
695 TowerPlaneRec* tf = NULL;
696 for(tower_plane_rec_list_iterator twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
697 if((*twrItr)->eta < (t->eta + 45) && strcmp((*twrItr)->plane.callsign.c_str(), t->plane.callsign.c_str()) != 0) { // don't let ATC ask you to follow yourself
701 // This should set the flagged plane to be the last conflicting one, and hence the one to follow.
702 // It ignores the fact that we might have problems slotting into the approach traffic behind it -
703 // eventually we'll need some fancy algorithms for that!
706 string trns = t->plane.callsign;
708 trns += ConvertNumToSpokenDigits(i + a);
709 // This assumes that the number spoken is landing position, not circuit position, since some of the traffic might be on straight-in final.
711 TowerPlaneRec* tt = NULL;
712 if((i == 1) && rwyList.empty() && (t->nextOnRwy) && (!cf)) { // Unfortunately nextOnRwy currently doesn't handle circuit/straight-in ordering properly at present, hence the cf check below.
713 trns += "Cleared to land"; // TODO - clear for the option if appropriate
714 t->clearedToLand = true;
715 if(!t->isUser) t->planePtr->RegisterTransmission(7);
716 } else if((i+a) > 1) {
717 //First set tt to point to the correct preceding plane - final or circuit
719 tt = (tf->eta < tc->eta ? tf : tc);
725 // We should never get here!
726 SG_LOG(SG_ATC, SG_ALERT, "ALERT - Logic error in FGTower::ProcessDownwindReport");
729 trns += "Follow the ";
730 string s = tt->plane.callsign;
734 if((tt->opType) == CIRCUIT) {
739 leg = tt->planePtr->GetLeg();
743 } else if(leg == TURN4) {
744 trns += " turning final";
745 } else if(leg == BASE) {
747 } else if(leg == TURN3) {
748 trns += " turning base";
751 double miles_out = CalcDistOutMiles(tt);
753 trns += " on short final";
756 trns += ConvertNumToSpokenDigits((int)miles_out);
757 trns += " mile final";
762 pending_transmission = trns;
766 if(t->opType == TTT_UNKNOWN) t->opType = CIRCUIT;
767 //cout << "ADD VACATED A\n";
768 // Put going around at the top (and hence default) since that'll be more desperate,
769 // or put rwy vacated at the top since that'll be more common?
770 //cout << "ident = " << ident << ", adding go-around option\n";
771 current_atcdialog->add_entry(ident, "@CS Going Around", "Report going around", TOWER, USER_REPORT_GOING_AROUND);
772 current_atcdialog->add_entry(ident, "@CS Clear of the runway", "Report runway vacated", TOWER, USER_REPORT_RWY_VACATED);
776 void FGTower::ProcessRunwayVacatedReport(TowerPlaneRec* t) {
777 //cout << "Processing rwy vacated...\n";
778 if(t->isUser) current_atcdialog->remove_entry(ident, USER_REPORT_GOING_AROUND, TOWER);
779 string trns = t->plane.callsign;
781 trns += " Contact ground on ";
782 double f = globals->get_ATC_mgr()->GetFrequency(ident, GROUND) / 100.0;
784 sprintf(buf, "%.2f", f);
787 if(!t->isUser) t->planePtr->RegisterTransmission(5);
790 trns += " cleared for taxi to general aviation parking";
791 if(!t->isUser) t->planePtr->RegisterTransmission(6); // TODO - this is a mega-hack!!
793 //cout << "trns = " << trns << '\n';
795 pending_transmission = trns;
798 RemoveFromRwyList(t->plane.callsign);
800 // Maybe we should check that the plane really *has* vacated the runway!
803 // *********** END RESPONSE FUNCTIONS *****************
805 // Currently this assumes we *are* next on the runway and doesn't check for planes about to land -
806 // this should be done prior to calling this function.
807 void FGTower::ClearHoldingPlane(TowerPlaneRec* t) {
808 //cout << "Entering ClearHoldingPlane..." << endl;
810 string trns = t->plane.callsign;
811 //if(departed plane < some threshold in time away) {
813 //if(timeSinceLastDeparture <= 60.0 && departed == true) {
814 trns += " line up runway " + ConvertRwyNumToSpokenString(activeRwy);
815 t->clearedToLineUp = true;
816 t->planePtr->RegisterTransmission(3); // cleared to line-up
817 //} else if(arriving plane < some threshold away) {
818 } else if(GetTrafficETA(2) < 150.0 && (timeSinceLastDeparture > 60.0 || departed == false)) { // Hack - hardwired time
819 trns += " cleared immediate take-off";
820 if(trafficList.size()) {
821 tower_plane_rec_list_iterator trfcItr = trafficList.begin();
822 trfcItr++; // At the moment the holding plane should be first in trafficList.
823 // Note though that this will break if holding planes aren't put in trafficList in the future.
824 TowerPlaneRec* trfc = *trfcItr;
825 trns += "... traffic is";
826 switch(trfc->plane.type) {
830 trns += " a Cessna"; // TODO - add ability to specify actual plane type somewhere
836 trns += " a King-air";
839 trns += " a Learjet";
842 trns += " a Regional";
851 //if(trfc->opType == STRAIGHT_IN || trfc->opType == TTT_UNKNOWN) {
852 if(trfc->opType == STRAIGHT_IN) {
853 double miles_out = CalcDistOutMiles(trfc);
858 trns += ConvertNumToSpokenDigits((int)miles_out);
859 trns += " mile final";
861 } else if(trfc->opType == CIRCUIT) {
862 //cout << "Getting leg of " << trfc->plane.callsign << '\n';
868 trns += " turning final";
874 trns += " turning base";
877 trns += " in circuit"; // At the moment the user plane is generally flagged as unknown opType when downwind incase its a downwind departure which means we won't get here.
879 // And to eliminate compiler warnings...
880 case TAKEOFF_ROLL: break;
881 case CLIMBOUT: break;
883 case CROSSWIND: break;
885 case LANDING_ROLL: break;
886 case LEG_UNKNOWN: break;
890 // By definition there should be some arriving traffic if we're cleared for immediate takeoff
891 SG_LOG(SG_ATC, SG_WARN, "Warning: Departing traffic cleared for *immediate* take-off despite no arriving traffic in FGTower");
893 t->clearedToTakeOff = true;
894 t->planePtr->RegisterTransmission(4); // cleared to take-off - TODO differentiate between immediate and normal take-off
896 timeSinceLastDeparture = 0.0;
898 //} else if(timeSinceLastDeparture > 60.0 || departed == false) { // Hack - test for timeSinceLastDeparture should be in lineup block eventually
899 trns += " cleared for take-off";
900 // TODO - add traffic is... ?
901 t->clearedToTakeOff = true;
902 t->planePtr->RegisterTransmission(4); // cleared to take-off
904 timeSinceLastDeparture = 0.0;
907 pending_transmission = trns;
910 //cout << "Done ClearHoldingPlane " << endl;
914 // ***************************************************************************************
915 // ********** Functions to periodically check what the various traffic is doing **********
917 // Do one plane from the hold list
918 void FGTower::CheckHoldList(double dt) {
919 //cout << "Entering CheckHoldList..." << endl;
920 if(!holdList.empty()) {
921 //cout << "*holdListItr = " << *holdListItr << endl;
922 if(holdListItr == holdList.end()) {
923 holdListItr = holdList.begin();
925 //cout << "*holdListItr = " << *holdListItr << endl;
926 //Process(*holdListItr);
927 TowerPlaneRec* t = *holdListItr;
928 //cout << "t = " << t << endl;
929 if(t->holdShortReported) {
930 // NO-OP - leave it to the response handler.
931 } else { // not responding to report, but still need to clear if clear
933 //cout << "departed = " << departed << '\n';
934 //cout << "timeSinceLastDeparture = " << timeSinceLastDeparture << '\n';
936 RemoveAllUserDialogOptions();
937 current_atcdialog->add_entry(ident, "@CS Ready for take-off", "Request take-off clearance", TOWER, (int)USER_REQUEST_TAKE_OFF);
938 } else if(timeSinceLastDeparture <= 60.0 && departed == true) {
939 // Do nothing - this is a bit of a hack - should maybe do line up be ready here
941 ClearHoldingPlane(t);
942 t->leg = TAKEOFF_ROLL;
943 rwyList.push_back(t);
944 rwyListItr = rwyList.begin();
946 holdList.erase(holdListItr);
947 holdListItr = holdList.begin();
948 if (holdList.empty())
952 // TODO - rationalise the considerable code duplication above!
956 //cout << "Done CheckHoldList" << endl;
959 // do the ciruit list
960 void FGTower::CheckCircuitList(double dt) {
961 //cout << "Entering CheckCircuitList..." << endl;
962 // Clear the constraints - we recalculate here.
964 downwind_leg_pos = 0.0;
965 crosswind_leg_pos = 0.0;
967 if(!circuitList.empty()) { // Do one plane from the circuit
968 if(circuitListItr == circuitList.end()) {
969 circuitListItr = circuitList.begin();
971 TowerPlaneRec* t = *circuitListItr;
972 //cout << ident << ' ' << circuitList.size() << ' ' << t->plane.callsign << " " << t->leg << " eta " << t->eta << '\n';
974 t->pos.setlon(user_lon_node->getDoubleValue());
975 t->pos.setlat(user_lat_node->getDoubleValue());
976 t->pos.setelev(user_elev_node->getDoubleValue());
977 //cout << ident << ' ' << circuitList.size() << ' ' << t->plane.callsign << " " << t->leg << " eta " << t->eta << '\n';
979 t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
980 t->landingType = t->planePtr->GetLandingOption();
981 //cout << "AI plane landing option is " << t->landingType << '\n';
983 Point3D tortho = ortho.ConvertToLocal(t->pos);
985 // Need to figure out which leg he's on
986 //cout << "rwy.hdg = " << rwy.hdg << " user hdg = " << user_hdg_node->getDoubleValue();
987 double ho = GetAngleDiff_deg(user_hdg_node->getDoubleValue(), rwy.hdg);
988 //cout << " ho = " << ho << " abs(ho = " << abs(ho) << '\n';
989 // TODO FIXME - get the wind and convert this to track, or otherwise use track somehow!!!
990 // If it's gusty might need to filter the value, although we are leaving 30 degrees each way leeway!
992 // could be either takeoff, climbout or landing - check orthopos.y
993 //cout << "tortho.y = " << tortho.y() << '\n';
994 if((tortho.y() < 0) || (t->leg == TURN4) || (t->leg == FINAL)) {
998 t->leg = CLIMBOUT; // TODO - check elev wrt. apt elev to differentiate takeoff roll and climbout
999 //cout << "Climbout\n";
1000 // If it's the user we may be unsure of his/her intentions.
1001 // (Hopefully the AI planes won't try confusing the sim!!!)
1002 //cout << "tortho.y = " << tortho.y() << '\n';
1003 if(t->opType == TTT_UNKNOWN) {
1004 if(tortho.y() > 5000) {
1005 // 5 km out from threshold - assume it's a departure
1006 t->opType = OUTBOUND; // TODO - could check if the user has climbed significantly above circuit altitude as well.
1007 // Since we are unknown operation we should be in depList already.
1008 //cout << ident << " Removing user from circuitList (TTT_UNKNOWN)\n";
1009 circuitListItr = circuitList.erase(circuitListItr);
1010 RemoveFromTrafficList(t->plane.callsign);
1011 if (circuitList.empty())
1014 } else if(t->opType == CIRCUIT) {
1015 if(tortho.y() > 10000) {
1016 // 10 km out - assume the user has abandoned the circuit!!
1017 t->opType = OUTBOUND;
1018 depList.push_back(t);
1019 depListItr = depList.begin();
1020 //cout << ident << " removing user from circuitList (CIRCUIT)\n";
1021 circuitListItr = circuitList.erase(circuitListItr);
1022 if (circuitList.empty())
1027 } else if(fabs(ho) < 60) {
1029 // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
1030 if((t->leg == CLIMBOUT) || (t->leg == TURN1)) {
1032 //cout << "Turn1\n";
1035 //cout << "Turn4\n";
1037 } else if(fabs(ho) < 120) {
1038 // crosswind or base
1039 // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
1040 if((t->leg == TURN1) || (t->leg == CROSSWIND)) {
1042 //cout << "Crosswind\n";
1047 } else if(fabs(ho) < 150) {
1049 // TODO - either fix or doublecheck this hack by looking at heading and pattern direction
1050 if((t->leg == CROSSWIND) || (t->leg == TURN2)) {
1052 //cout << "Turn2\n";
1055 // Probably safe now to assume the user is flying a circuit
1056 t->opType = CIRCUIT;
1057 //cout << "Turn3\n";
1062 //cout << "Downwind\n";
1064 if(t->leg == FINAL) {
1065 if(OnActiveRunway(t->pos)) {
1066 t->leg = LANDING_ROLL;
1070 t->leg = t->planePtr->GetLeg();
1073 // Set the constraints IF this is the first plane in the circuit
1074 // TODO - at the moment we're constraining plane 2 based on plane 1 - this won't (or might not) work for 3 planes in the circuit!!
1075 if(circuitListItr == circuitList.begin()) {
1078 // Base leg must be at least as far out as the plane is - actually possibly not necessary for separation, but we'll use that for now.
1079 base_leg_pos = tortho.y();
1080 //cout << "base_leg_pos = " << base_leg_pos << '\n';
1083 // Fall through to base
1085 base_leg_pos = tortho.y();
1086 //cout << "base_leg_pos = " << base_leg_pos << '\n';
1089 // Fall through to downwind
1091 // Only have the downwind leg pos as turn-to-base constraint if more negative than we already have.
1092 base_leg_pos = (tortho.y() < base_leg_pos ? tortho.y() : base_leg_pos);
1093 //cout << "base_leg_pos = " << base_leg_pos;
1094 downwind_leg_pos = tortho.x(); // Assume that a following plane can simply be constrained by the immediately in front downwind plane
1095 //cout << " downwind_leg_pos = " << downwind_leg_pos << '\n';
1098 // Fall through to crosswind
1100 crosswind_leg_pos = tortho.y();
1101 //cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n';
1102 t->instructedToGoAround = false;
1105 // Fall through to climbout
1107 // Only use current by constraint as largest
1108 crosswind_leg_pos = (tortho.y() > crosswind_leg_pos ? tortho.y() : crosswind_leg_pos);
1109 //cout << "crosswind_leg_pos = " << crosswind_leg_pos << '\n';
1122 if(t->leg == FINAL && !(t->instructedToGoAround)) {
1123 doThresholdETACalc();
1124 doThresholdUseOrder();
1127 cout << "Checking USER on final... ";
1128 cout << "eta " << t->eta;
1129 if(t->clearedToLand) cout << " cleared to land\n";
1132 //cout << "YES FINAL, t->eta = " << t->eta << ", rwyList.size() = " << rwyList.size() << '\n';
1133 if(t->landingType == FULL_STOP) {
1134 t->opType = INBOUND;
1135 //cout << "\n******** SWITCHING TO INBOUND AT POINT AAA *********\n\n";
1137 if(t->eta < 12 && rwyList.size()) {
1138 // TODO - need to make this more sophisticated
1139 // eg. is the plane accelerating down the runway taking off [OK],
1140 // or stationary near the start [V. BAD!!].
1141 // For now this should stop the AI plane landing on top of the user.
1142 tower_plane_rec_list_iterator twrItr;
1143 twrItr = rwyList.begin();
1144 TowerPlaneRec* tpr = *twrItr;
1145 if(strcmp(tpr->plane.callsign.c_str(), t->plane.callsign.c_str()) == 0
1146 && rwyList.size() == 1) {
1147 // Fixing bug when ATC says that we must go around because of traffic on rwy
1148 // but that traffic is our plane! In future we can use this expression
1149 // for other ATC-messages like "On ground at 46, vacate left."
1152 string trns = t->plane.callsign;
1153 trns += " GO AROUND TRAFFIC ON RUNWAY I REPEAT GO AROUND";
1154 pending_transmission = trns;
1155 ImmediateTransmit();
1156 t->instructedToGoAround = true;
1157 t->clearedToLand = false;
1158 // Assume it complies!!!
1159 t->opType = CIRCUIT;
1162 //cout << "Registering Go-around transmission with AI plane\n";
1163 t->planePtr->RegisterTransmission(13);
1166 } else if(!t->clearedToLand) {
1167 // The whip through the appList is a hack since currently t->nextOnRwy doesn't always work
1170 for(tower_plane_rec_list_iterator twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
1171 if((*twrItr)->eta < t->eta) {
1175 if(t->nextOnRwy && !cf) {
1176 if(!rwyList.size()) {
1177 string trns = t->plane.callsign;
1178 trns += " Cleared to land";
1179 pending_transmission = trns;
1181 //if(t->isUser) cout << "Transmitting cleared to Land!!!\n";
1182 t->clearedToLand = true;
1184 t->planePtr->RegisterTransmission(7);
1188 //if(t->isUser) cout << "Not next\n";
1191 } else if(t->leg == LANDING_ROLL) {
1192 //cout << t->plane.callsign << " has landed - adding to rwyList\n";
1193 rwyList.push_front(t);
1194 // TODO - if(!clearedToLand) shout something!!
1195 t->clearedToLand = false;
1196 RemoveFromTrafficList(t->plane.callsign);
1198 t->opType = TTT_UNKNOWN;
1199 } // TODO - allow the user to specify opType via ATC menu
1200 //cout << ident << " Removing " << t->plane.callsign << " from circuitList..." << endl;
1201 circuitListItr = circuitList.erase(circuitListItr);
1202 if(circuitListItr == circuitList.end() ) {
1203 circuitListItr = circuitList.begin();
1204 // avoid increment of circuitListItr (would increment to second element, or crash if no element left)
1210 //cout << "Done CheckCircuitList" << endl;
1213 // Do the runway list - we'll do the whole runway list since it's important and there'll never be many planes on the rwy at once!!
1214 // FIXME - at the moment it looks like we're only doing the first plane from the rwy list.
1215 // (However, at the moment there should only be one airplane on the rwy at once, until we
1216 // start allowing planes to line up whilst previous arrival clears the rwy.)
1217 void FGTower::CheckRunwayList(double dt) {
1218 //cout << "Entering CheckRunwayList..." << endl;
1220 if(!rwyList.size()) {
1221 rwyOccupied = false;
1223 rwyListItr = rwyList.begin();
1224 TowerPlaneRec* t = *rwyListItr;
1226 t->pos.setlon(user_lon_node->getDoubleValue());
1227 t->pos.setlat(user_lat_node->getDoubleValue());
1228 t->pos.setelev(user_elev_node->getDoubleValue());
1230 t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
1232 bool on_rwy = OnActiveRunway(t->pos);
1234 // TODO - for all of these we need to check what the user is *actually* doing!
1235 if((t->opType == INBOUND) || (t->opType == STRAIGHT_IN)) {
1236 //cout << "Tower " << ident << " is removing plane " << t->plane.callsign << " from rwy list (vacated)\n";
1237 //cout << "Size of rwylist was " << rwyList.size() << '\n';
1238 //cout << "Size of vacatedList was " << vacatedList.size() << '\n';
1239 RemoveFromRwyList(t->plane.callsign);
1240 AddToVacatedList(t);
1241 //cout << "Size of rwylist is " << rwyList.size() << '\n';
1242 //cout << "Size of vacatedList is " << vacatedList.size() << '\n';
1243 // At the moment we wait until Runway Vacated is reported by the plane before telling to contact ground etc.
1244 // It's possible we could be a bit more proactive about this.
1245 } else if(t->opType == OUTBOUND) {
1246 depList.push_back(t);
1247 depListItr = depList.begin();
1248 rwyList.pop_front();
1250 timeSinceLastDeparture = 0.0;
1251 } else if(t->opType == CIRCUIT) {
1252 //cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
1253 circuitList.push_back(t);
1254 circuitListItr = circuitList.begin();
1255 AddToTrafficList(t);
1256 rwyList.pop_front();
1258 timeSinceLastDeparture = 0.0;
1259 } else if(t->opType == TTT_UNKNOWN) {
1260 depList.push_back(t);
1261 depListItr = depList.begin();
1262 //cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
1263 circuitList.push_back(t);
1264 circuitListItr = circuitList.begin();
1265 AddToTrafficList(t);
1266 rwyList.pop_front();
1268 timeSinceLastDeparture = 0.0; // TODO - we need to take into account that the user might taxi-in when flagged opType UNKNOWN - check speed/altitude etc to make decision as to what user is up to.
1270 // HELP - we shouldn't ever get here!!!
1275 //cout << "Done CheckRunwayList" << endl;
1278 // Do one plane from the approach list
1279 void FGTower::CheckApproachList(double dt) {
1280 //cout << "CheckApproachList called for " << ident << endl;
1281 //cout << "AppList.size is " << appList.size() << endl;
1282 if(!appList.empty()) {
1283 if(appListItr == appList.end()) {
1284 appListItr = appList.begin();
1286 TowerPlaneRec* t = *appListItr;
1287 //cout << "t = " << t << endl;
1288 //cout << "Checking " << t->plane.callsign << endl;
1290 t->pos.setlon(user_lon_node->getDoubleValue());
1291 t->pos.setlat(user_lat_node->getDoubleValue());
1292 t->pos.setelev(user_elev_node->getDoubleValue());
1294 // TODO - set/update the position if it's an AI plane
1296 doThresholdETACalc(); // We need this here because planes in the lists are not guaranteed to *always* have the correct ETA
1297 //cout << "eta is " << t->eta << ", rwy is " << (rwyList.size() ? "occupied " : "clear ") << '\n';
1298 Point3D tortho = ortho.ConvertToLocal(t->pos);
1299 if(t->eta < 12 && rwyList.size() && !(t->instructedToGoAround)) {
1300 // TODO - need to make this more sophisticated
1301 // eg. is the plane accelerating down the runway taking off [OK],
1302 // or stationary near the start [V. BAD!!].
1303 // For now this should stop the AI plane landing on top of the user.
1304 tower_plane_rec_list_iterator twrItr;
1305 twrItr = rwyList.begin();
1306 TowerPlaneRec* tpr = *twrItr;
1307 if(strcmp ( tpr->plane.callsign.c_str(), t->plane.callsign.c_str() ) == 0 && rwyList.size() == 1) {
1308 // Fixing bug when ATC says that we must go around because of traffic on rwy
1309 // but that traffic is we! In future we can use this expression
1310 // for other ATC-messages like "On ground at 46, vacate left."
1313 string trns = t->plane.callsign;
1314 trns += " GO AROUND TRAFFIC ON RUNWAY I REPEAT GO AROUND";
1315 pending_transmission = trns;
1316 ImmediateTransmit();
1317 t->instructedToGoAround = true;
1318 t->clearedToLand = false;
1319 t->nextOnRwy = false; // But note this is recalculated so don't rely on it
1320 // Assume it complies!!!
1321 t->opType = CIRCUIT;
1325 //cout << "Registering Go-around transmission with AI plane\n";
1326 t->planePtr->RegisterTransmission(13);
1329 // TODO - add Go-around ack to comm options,
1330 // remove report rwy vacated. (possibly).
1333 } else if(t->isUser && t->eta < 90 && tortho.y() > -2500 && t->clearedToLand && t->gearUpReported == false) {
1334 // Check if gear up or down
1335 double gp = fgGetFloat("/gear/gear/position-norm");
1337 string trnsm = t->plane.callsign;
1339 int rnd = int(sg_random() * 2) + 1;
1340 if(rnd == 2) { // Random message for more realistic ATC ;)
1341 trnsm += ", LANDING GEAR APPEARS UP!";
1343 trnsm += ", Check wheels down and locked.";
1345 pending_transmission = trnsm;
1346 ImmediateTransmit();
1347 t->gearUpReported = true;
1349 } else if(t->eta < 90 && !t->clearedToLand) {
1350 //doThresholdETACalc();
1351 doThresholdUseOrder();
1352 // The whip through the appList is a hack since currently t->nextOnRwy doesn't always work
1355 for(tower_plane_rec_list_iterator twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
1356 if((*twrItr)->eta < t->eta) {
1360 if(t->nextOnRwy && !cf) {
1361 if(!rwyList.size()) {
1362 string trns = t->plane.callsign;
1363 trns += " Cleared to land";
1364 pending_transmission = trns;
1366 //if(t->isUser) cout << "Transmitting cleared to Land!!!\n";
1367 t->clearedToLand = true;
1369 t->planePtr->RegisterTransmission(7);
1373 //if(t->isUser) cout << "Not next\n";
1377 // Check for landing...
1378 bool landed = false;
1381 if(t->planePtr->GetLeg() == LANDING_ROLL) {
1385 SG_LOG(SG_ATC, SG_ALERT, "WARNING - not user and null planePtr in CheckApproachList!");
1388 if(OnActiveRunway(t->pos)) {
1394 // Duplicated in CheckCircuitList - must be able to rationalise this somehow!
1395 //cout << "A " << t->plane.callsign << " has landed, adding to rwyList...\n";
1396 rwyList.push_front(t);
1397 // TODO - if(!clearedToLand) shout something!!
1398 t->clearedToLand = false;
1399 RemoveFromTrafficList(t->plane.callsign);
1401 // t->opType = TTT_UNKNOWN;
1402 //} // TODO - allow the user to specify opType via ATC menu
1403 appListItr = appList.erase(appListItr);
1404 if(appListItr == appList.end() ) {
1405 appListItr = appList.begin();
1407 if (appList.empty())
1414 //cout << "Done" << endl;
1417 // Do one plane from the departure list
1418 void FGTower::CheckDepartureList(double dt) {
1419 if(!depList.empty()) {
1420 if(depListItr == depList.end()) {
1421 depListItr = depList.begin();
1423 TowerPlaneRec* t = *depListItr;
1424 //cout << "Dep list, checking " << t->plane.callsign;
1426 double distout; // meters
1427 if(t->isUser) distout = dclGetHorizontalSeparation(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
1428 else distout = dclGetHorizontalSeparation(Point3D(lon, lat, elev), t->planePtr->GetPos());
1429 //cout << " distout = " << distout << '\n';
1430 if(t->isUser && !(t->clearedToTakeOff)) { // HACK - we use clearedToTakeOff to check if ATC already contacted with plane (and cleared take-off) or not
1431 if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
1432 current_atcdialog->remove_entry(ident, USER_REQUEST_TAKE_OFF, TOWER);
1433 t->clearedToTakeOff = true; // FIXME
1436 if(distout > 10000) {
1437 string trns = t->plane.callsign;
1438 trns += " You are now clear of my airspace, good day";
1439 pending_transmission = trns;
1442 // Change the communication options
1443 RemoveAllUserDialogOptions();
1444 //cout << "ADD A\n";
1445 current_atcdialog->add_entry(ident, "@AP Tower, @CS @MI miles @CD of the airport for full stop@AT", "Contact tower for VFR arrival (full stop)", TOWER, (int)USER_REQUEST_VFR_ARRIVAL_FULL_STOP);
1447 // Send a clear-of-airspace signal
1448 // TODO - implement this once we actually have departing AI traffic (currently all circuits or arrivals).
1450 RemovePlane(t->plane.callsign);
1457 // ********** End periodic check functions ***********************************************
1458 // ***************************************************************************************
1461 // Remove all dialog options for this tower.
1462 void FGTower::RemoveAllUserDialogOptions() {
1463 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_DEPARTURE, TOWER);
1464 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL, TOWER);
1465 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_FULL_STOP, TOWER);
1466 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_TOUCH_AND_GO, TOWER);
1467 current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
1468 current_atcdialog->remove_entry(ident, USER_REPORT_DOWNWIND, TOWER);
1469 current_atcdialog->remove_entry(ident, USER_REPORT_RWY_VACATED, TOWER);
1470 current_atcdialog->remove_entry(ident, USER_REPORT_GOING_AROUND, TOWER);
1471 current_atcdialog->remove_entry(ident, USER_REQUEST_TAKE_OFF, TOWER);
1474 // Returns true if positions of crosswind/downwind/base leg turns should be constrained by previous traffic
1475 // plus the constraint position as a rwy orientated orthopos (meters)
1476 bool FGTower::GetCrosswindConstraint(double& cpos) {
1477 if(crosswind_leg_pos != 0.0) {
1478 cpos = crosswind_leg_pos;
1485 bool FGTower::GetDownwindConstraint(double& dpos) {
1486 if(fabs(downwind_leg_pos) > nominal_downwind_leg_pos) {
1487 dpos = downwind_leg_pos;
1494 bool FGTower::GetBaseConstraint(double& bpos) {
1495 if(base_leg_pos < nominal_base_leg_pos) {
1496 bpos = base_leg_pos;
1499 bpos = nominal_base_leg_pos;
1505 // Figure out which runways are active.
1506 // For now we'll just be simple and do one active runway - eventually this will get much more complex
1507 // This is a private function - public interface to the results of this is through GetActiveRunway
1508 void FGTower::DoRwyDetails() {
1509 //cout << "GetRwyDetails called" << endl;
1511 // Based on the airport-id and wind get the active runway
1514 double hdg = wind_from_hdg->getDoubleValue();
1515 double speed = wind_speed_knots->getDoubleValue();
1516 hdg = (speed == 0.0 ? 270.0 : hdg);
1517 //cout << "Heading = " << hdg << '\n';
1520 bool rwyGood = globals->get_runways()->search(ident, int(hdg), &runway);
1522 //cout << "RUNWAY GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD\n";
1523 activeRwy = runway._rwy_no;
1524 rwy.rwyID = runway._rwy_no;
1525 SG_LOG(SG_ATC, SG_INFO, "Active runway for airport " << ident << " is " << activeRwy);
1527 // Get the threshold position
1528 double other_way = runway._heading - 180.0;
1529 while(other_way <= 0.0) {
1532 // move to the +l end/center of the runway
1533 //cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
1534 Point3D origin = Point3D(runway._lon, runway._lat, aptElev);
1535 Point3D ref = origin;
1536 double tshlon, tshlat, tshr;
1537 double tolon, tolat, tor;
1538 rwy.length = runway._length * SG_FEET_TO_METER;
1539 rwy.width = runway._width * SG_FEET_TO_METER;
1540 geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way,
1541 rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
1542 geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway._heading,
1543 rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
1544 // Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
1545 // now copy what we need out of runway into rwy
1546 rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev);
1547 Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
1548 //cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
1549 //cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
1550 rwy.hdg = runway._heading;
1551 // Set the projection for the local area based on this active runway
1552 ortho.Init(rwy.threshold_pos, rwy.hdg);
1553 rwy.end1ortho = ortho.ConvertToLocal(rwy.threshold_pos); // should come out as zero
1554 rwy.end2ortho = ortho.ConvertToLocal(takeoff_end);
1556 // Set the pattern direction
1557 // TODO - we'll check for a facilities file with this in eventually - for now assume left traffic except
1558 // for certain circumstances (RH parallel rwy).
1559 rwy.patternDirection = -1; // Left
1560 if(rwy.rwyID.size() == 3) {
1561 rwy.patternDirection = (rwy.rwyID.substr(2,1) == "R" ? 1 : -1);
1563 //cout << "Doing details, rwy.patterDirection is " << rwy.patternDirection << '\n';
1565 SG_LOG(SG_ATC, SG_ALERT, "Help - can't get good runway in FGTower!!");
1571 // Figure out if a given position lies on the active runway
1572 // Might have to change when we consider more than one active rwy.
1573 bool FGTower::OnActiveRunway(const Point3D& pt) {
1574 // TODO - check that the centre calculation below isn't confused by displaced thesholds etc.
1575 Point3D xyc((rwy.end1ortho.x() + rwy.end2ortho.x())/2.0, (rwy.end1ortho.y() + rwy.end2ortho.y())/2.0, 0.0);
1576 Point3D xyp = ortho.ConvertToLocal(pt);
1578 //cout << "Length offset = " << fabs(xyp.y() - xyc.y()) << '\n';
1579 //cout << "Width offset = " << fabs(xyp.x() - xyc.x()) << '\n';
1581 double rlen = rwy.length/2.0 + 5.0;
1582 double rwidth = rwy.width/2.0;
1583 double ldiff = fabs(xyp.y() - xyc.y());
1584 double wdiff = fabs(xyp.x() - xyc.x());
1586 return((ldiff < rlen) && (wdiff < rwidth));
1589 // Figure out if a given position lies on any runway or not
1590 // Only call this at startup - reading the runways database is expensive and needs to be fixed!
1591 bool FGTower::OnAnyRunway(const Point3D& pt, bool onGround) {
1593 double dist = current_commlist->FindClosest(lon, lat, elev, ad, TOWER, 7.0);
1598 // Based on the airport-id, go through all the runways and check for a point in them
1600 // TODO - do we actually need to search for the airport - surely we already know our ident and
1601 // can just search runways of our airport???
1602 //cout << "Airport ident is " << ad.ident << '\n';
1604 bool rwyGood = globals->get_runways()->search(ad.ident, &runway);
1606 SG_LOG(SG_ATC, SG_WARN, "Unable to find any runways for airport ID " << ad.ident << " in FGTower");
1609 while(runway._id == ad.ident) {
1610 on = OnRunway(pt, runway);
1611 //cout << "Runway " << runway._rwy_no << ": On = " << (on ? "true\n" : "false\n");
1613 if(onGround == false)
1615 if(runway._rwy_no != "xx")
1618 globals->get_runways()->next(&runway);
1624 // Returns true if successful
1625 bool FGTower::RemoveFromTrafficList(const string& id) {
1626 tower_plane_rec_list_iterator twrItr;
1627 for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
1628 TowerPlaneRec* tpr = *twrItr;
1629 if(tpr->plane.callsign == id) {
1630 trafficList.erase(twrItr);
1631 trafficListItr = trafficList.begin();
1635 SG_LOG(SG_ATC, SG_WARN, "Warning - unable to remove aircraft " << id << " from trafficList in FGTower");
1640 // Returns true if successful
1641 bool FGTower::RemoveFromAppList(const string& id) {
1642 tower_plane_rec_list_iterator twrItr;
1643 for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
1644 TowerPlaneRec* tpr = *twrItr;
1645 if(tpr->plane.callsign == id) {
1646 appList.erase(twrItr);
1647 appListItr = appList.begin();
1651 //SG_LOG(SG_ATC, SG_WARN, "Warning - unable to remove aircraft " << id << " from appList in FGTower");
1655 // Returns true if successful
1656 bool FGTower::RemoveFromRwyList(const string& id) {
1657 tower_plane_rec_list_iterator twrItr;
1658 for(twrItr = rwyList.begin(); twrItr != rwyList.end(); twrItr++) {
1659 TowerPlaneRec* tpr = *twrItr;
1660 if(tpr->plane.callsign == id) {
1661 rwyList.erase(twrItr);
1662 rwyListItr = rwyList.begin();
1666 //SG_LOG(SG_ATC, SG_WARN, "Warning - unable to remove aircraft " << id << " from rwyList in FGTower");
1671 // Add a tower plane rec with ETA to the traffic list in the correct position ETA-wise
1672 // and set nextOnRwy if so.
1673 // Returns true if this could cause a threshold ETA conflict with other traffic, false otherwise.
1674 // For planes holding they are put in the first position with time to go, and the return value is
1675 // true if in the first position (nextOnRwy) and false otherwise.
1676 // See the comments in FGTower::doThresholdUseOrder for notes on the ordering
1677 bool FGTower::AddToTrafficList(TowerPlaneRec* t, bool holding) {
1678 //cout << "ADD: " << trafficList.size();
1679 //cout << "AddToTrafficList called, currently size = " << trafficList.size() << ", holding = " << holding << endl;
1680 double separation_time = 90.0; // seconds - this is currently a guess for light plane separation, and includes a few seconds for a holding plane to taxi onto the rwy.
1681 double departure_sep_time = 60.0; // Separation time behind departing airplanes. Comments above also apply.
1682 bool conflict = false;
1683 double lastETA = 0.0;
1684 bool firstTime = true;
1685 // FIXME - make this more robust for different plane types eg. light following heavy.
1686 tower_plane_rec_list_iterator twrItr;
1687 //twrItr = trafficList.begin();
1689 for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
1690 //if(twrItr == trafficList.end()) {
1692 // trafficList.push_back(t);
1693 // return(holding ? firstTime : conflict);
1695 TowerPlaneRec* tpr = *twrItr;
1697 //cout << (tpr->isUser ? "USER!\n" : "NOT user\n");
1698 //cout << "tpr->eta - lastETA = " << tpr->eta - lastETA << '\n';
1699 double dep_allowance = (timeSinceLastDeparture < departure_sep_time ? departure_sep_time - timeSinceLastDeparture : 0.0);
1700 double slot_time = (firstTime ? separation_time + dep_allowance : separation_time + departure_sep_time);
1701 // separation_time + departure_sep_time in the above accounts for the fact that the arrival could be touch and go,
1702 // and if not needs time to clear the rwy anyway.
1703 if(tpr->eta - lastETA > slot_time) {
1704 t->nextOnRwy = firstTime;
1705 trafficList.insert(twrItr, t);
1706 //cout << "\tH\t" << trafficList.size() << '\n';
1711 if(t->eta < tpr->eta) {
1712 // Ugg - this one's tricky.
1713 // It depends on what the two planes are doing and whether there's a conflict what we do.
1714 if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
1715 if(tpr->nextOnRwy) {
1716 tpr->nextOnRwy = false;
1717 t->nextOnRwy = true;
1719 trafficList.insert(twrItr, t);
1720 } else { // Ooops - this ones tricky - we have a potential conflict!
1722 // HACK - just add anyway for now and flag conflict - TODO - FIX THIS using CIRCUIT/STRAIGHT_IN and VFR/IFR precedence rules.
1723 if(tpr->nextOnRwy) {
1724 tpr->nextOnRwy = false;
1725 t->nextOnRwy = true;
1727 trafficList.insert(twrItr, t);
1729 //cout << "\tC\t" << trafficList.size() << '\n';
1736 // If we get here we must be at the end of the list, or maybe the list is empty.
1737 if(!trafficList.size()) {
1738 t->nextOnRwy = true;
1739 // conflict and firstTime should be false and true respectively in this case anyway.
1741 t->nextOnRwy = false;
1743 trafficList.push_back(t);
1744 //cout << "\tE\t" << trafficList.size() << endl;
1745 return(holding ? firstTime : conflict);
1748 // Add a tower plane rec with ETA to the circuit list in the correct position ETA-wise
1749 // Returns true if this might cause a separation conflict (based on ETA) with other traffic, false otherwise.
1750 // Safe to add a plane that is already in - planes with the same callsign are not added.
1751 bool FGTower::AddToCircuitList(TowerPlaneRec* t) {
1753 //cout << "**********************************************\n";
1754 //cout << "AddToCircuitList called with NULL pointer!!!!!\n";
1755 //cout << "**********************************************\n";
1758 //cout << "ADD: " << circuitList.size();
1759 //cout << ident << " AddToCircuitList called for " << t->plane.callsign << ", currently size = " << circuitList.size() << endl;
1760 double separation_time = 60.0; // seconds - this is currently a guess for light plane separation, and includes a few seconds for a holding plane to taxi onto the rwy.
1761 bool conflict = false;
1762 tower_plane_rec_list_iterator twrItr;
1763 // First check if the plane is already in the list
1764 //cout << "A" << endl;
1765 //cout << "Checking whether " << t->plane.callsign << " is already in circuit list..." << endl;
1766 //cout << "B" << endl;
1767 for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
1768 if((*twrItr)->plane.callsign == t->plane.callsign) {
1769 //cout << "In list - returning...\n";
1773 //cout << "Not in list - adding..." << endl;
1775 for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
1776 TowerPlaneRec* tpr = *twrItr;
1777 //cout << tpr->plane.callsign << " eta is " << tpr->eta << '\n';
1778 //cout << "New eta is " << t->eta << '\n';
1779 if(t->eta < tpr->eta) {
1780 // Ugg - this one's tricky.
1781 // It depends on what the two planes are doing and whether there's a conflict what we do.
1782 if(tpr->eta - t->eta > separation_time) { // No probs, plane 2 can squeeze in before plane 1 with no apparent conflict
1783 circuitList.insert(twrItr, t);
1784 circuitListItr = circuitList.begin();
1785 } else { // Ooops - this ones tricky - we have a potential conflict!
1787 // HACK - just add anyway for now and flag conflict.
1788 circuitList.insert(twrItr, t);
1789 circuitListItr = circuitList.begin();
1791 //cout << "\tC\t" << circuitList.size() << '\n';
1795 // If we get here we must be at the end of the list, or maybe the list is empty.
1796 //cout << ident << " adding " << t->plane.callsign << " to circuitList" << endl;
1797 circuitList.push_back(t); // TODO - check the separation with the preceding plane for the conflict flag.
1798 circuitListItr = circuitList.begin();
1799 //cout << "\tE\t" << circuitList.size() << endl;
1803 // Add to vacated list only if not already present
1804 void FGTower::AddToVacatedList(TowerPlaneRec* t) {
1805 tower_plane_rec_list_iterator twrItr;
1807 for(twrItr = vacatedList.begin(); twrItr != vacatedList.end(); twrItr++) {
1808 if((*twrItr)->plane.callsign == t->plane.callsign) {
1813 vacatedList.push_back(t);
1816 void FGTower::AddToHoldingList(TowerPlaneRec* t) {
1817 tower_plane_rec_list_iterator it, end = holdList.end();
1818 for (it = holdList.begin(); it != end; ++it) {
1819 if ((*it)->plane.callsign == t->plane.callsign)
1822 holdList.push_back(t);
1826 // Calculate the eta of a plane to the threshold.
1827 // For ground traffic this is the fastest they can get there.
1828 // For air traffic this is the middle approximation.
1829 void FGTower::CalcETA(TowerPlaneRec* tpr, bool printout) {
1830 // For now we'll be very crude and hardwire expected speeds to C172-like values
1831 // The speeds below are specified in knots IAS and then converted to m/s
1832 double app_ias = 100.0 * 0.514444; // Speed during straight-in approach
1833 double circuit_ias = 80.0 * 0.514444; // Speed around circuit
1834 double final_ias = 70.0 * 0.514444; // Speed during final approach
1837 //cout << "In CalcETA, airplane ident = " << tpr->plane.callsign << '\n';
1838 //cout << (tpr->isUser ? "USER\n" : "AI\n");
1842 // Sign convention - dist_out is -ve for approaching planes and +ve for departing planes
1843 // dist_across is +ve in the pattern direction - ie a plane correctly on downwind will have a +ve dist_across
1845 Point3D op = ortho.ConvertToLocal(tpr->pos);
1847 //if(!tpr->isUser) cout << "Orthopos is " << op.x() << ", " << op.y() << ' ';
1848 //cout << "opType is " << tpr->opType << '\n';
1850 double dist_out_m = op.y();
1851 double dist_across_m = fabs(op.x()); // The fabs is a hack to cope with the fact that we don't know the circuit direction yet
1852 //cout << "Doing ETA calc for " << tpr->plane.callsign << '\n';
1854 if(tpr->opType == STRAIGHT_IN || tpr->opType == INBOUND) {
1855 //cout << "CASE 1\n";
1856 double dist_to_go_m = sqrt((dist_out_m * dist_out_m) + (dist_across_m * dist_across_m));
1857 if(dist_to_go_m < 1000) {
1858 tpr->eta = dist_to_go_m / final_ias;
1860 tpr->eta = (1000.0 / final_ias) + ((dist_to_go_m - 1000.0) / app_ias);
1862 } else if(tpr->opType == CIRCUIT || tpr->opType == TTT_UNKNOWN) { // Hack alert - UNKNOWN has sort of been added here as a temporary hack.
1863 //cout << "CASE 2\n";
1864 // It's complicated - depends on if base leg is delayed or not
1866 //cout << "Leg = " << tpr->leg << '\n';
1868 if(tpr->leg == LANDING_ROLL) {
1870 } else if((tpr->leg == FINAL) || (tpr->leg == TURN4)) {
1871 //cout << "dist_out_m = " << dist_out_m << '\n';
1872 tpr->eta = fabs(dist_out_m) / final_ias;
1873 } else if((tpr->leg == BASE) || (tpr->leg == TURN3)) {
1874 tpr->eta = (fabs(dist_out_m) / final_ias) + (dist_across_m / circuit_ias);
1876 // Need to calculate where base leg is likely to be
1877 // FIXME - for now I'll hardwire it to 1000m which is what AILocalTraffic uses!!!
1878 // TODO - as a matter of design - AILocalTraffic should get the nominal no-traffic base turn distance from Tower, since in real life the published pattern might differ from airport to airport
1879 double nominal_base_dist_out_m = -1000;
1880 double current_base_dist_out_m;
1881 if(!GetBaseConstraint(current_base_dist_out_m)) {
1882 current_base_dist_out_m = nominal_base_dist_out_m;
1884 //cout << "current_base_dist_out_m = " << current_base_dist_out_m << '\n';
1885 double nominal_dist_across_m = 1000; // Hardwired value from AILocalTraffic
1886 double current_dist_across_m;
1887 if(!GetDownwindConstraint(current_dist_across_m)) {
1888 current_dist_across_m = nominal_dist_across_m;
1890 double nominal_cross_dist_out_m = 2000; // Bit of a guess - AI plane turns to crosswind at 700ft agl.
1891 tpr->eta = fabs(current_base_dist_out_m) / final_ias; // final
1892 //cout << "a = " << tpr->eta << '\n';
1893 if((tpr->leg == DOWNWIND) || (tpr->leg == TURN2)) {
1894 tpr->eta += dist_across_m / circuit_ias;
1895 //cout << "b = " << tpr->eta << '\n';
1896 tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
1897 //cout << "c = " << tpr->eta << '\n';
1898 } else if((tpr->leg == CROSSWIND) || (tpr->leg == TURN1)) {
1899 //cout << "CROSSWIND calc: ";
1900 //cout << tpr->eta << ' ';
1901 if(dist_across_m > nominal_dist_across_m) {
1902 tpr->eta += dist_across_m / circuit_ias;
1905 tpr->eta += nominal_dist_across_m / circuit_ias;
1908 //cout << tpr->eta << ' ';
1909 // should we use the dist across of the previous plane if there is previous still on downwind?
1910 //if(printout) cout << "bb = " << tpr->eta << '\n';
1911 if(dist_out_m > nominal_cross_dist_out_m) {
1912 tpr->eta += fabs(current_base_dist_out_m - dist_out_m) / circuit_ias;
1915 tpr->eta += fabs(current_base_dist_out_m - nominal_cross_dist_out_m) / circuit_ias;
1918 //cout << tpr->eta << ' ';
1919 //if(printout) cout << "cc = " << tpr->eta << '\n';
1920 if(nominal_dist_across_m > dist_across_m) {
1921 tpr->eta += (nominal_dist_across_m - dist_across_m) / circuit_ias;
1927 //cout << tpr->eta << '\n';
1928 //if(printout) cout << "dd = " << tpr->eta << '\n';
1930 // We've only just started - why not use a generic estimate?
1935 // cout << "ETA = " << tpr->eta << '\n';
1937 //if(!tpr->isUser) cout << tpr->plane.callsign << '\t' << tpr->eta << '\n';
1944 // Calculate the distance of a plane to the threshold in meters
1945 // TODO - Modify to calculate flying distance of a plane in the circuit
1946 double FGTower::CalcDistOutM(TowerPlaneRec* tpr) {
1947 return(dclGetHorizontalSeparation(rwy.threshold_pos, tpr->pos));
1951 // Calculate the distance of a plane to the threshold in miles
1952 // TODO - Modify to calculate flying distance of a plane in the circuit
1953 double FGTower::CalcDistOutMiles(TowerPlaneRec* tpr) {
1954 return(CalcDistOutM(tpr) / 1600.0); // FIXME - use a proper constant if possible.
1958 // Iterate through all the lists, update the position of, and call CalcETA for all the planes.
1959 void FGTower::doThresholdETACalc() {
1960 //cout << "Entering doThresholdETACalc..." << endl;
1961 tower_plane_rec_list_iterator twrItr;
1962 // Do the approach list first
1963 for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
1964 TowerPlaneRec* tpr = *twrItr;
1965 if(!(tpr->isUser)) tpr->pos = tpr->planePtr->GetPos();
1969 // Then the circuit list
1970 //cout << "Circuit list size is " << circuitList.size() << '\n';
1971 for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
1972 TowerPlaneRec* tpr = *twrItr;
1973 if(!(tpr->isUser)) tpr->pos = tpr->planePtr->GetPos();
1977 //cout << "Done doThresholdETCCalc" << endl;
1981 // Check that the planes in traffic list are correctly ordered,
1982 // that the nearest (timewise) is flagged next on rwy, and return
1983 // true if any threshold use conflicts are detected, false otherwise.
1984 bool FGTower::doThresholdUseOrder() {
1985 //cout << "Entering doThresholdUseOrder..." << endl;
1986 bool conflict = false;
1988 // Wipe out traffic list, go through circuit, app and hold list, and reorder them in traffic list.
1989 // Here's the rather simplistic assumptions we're using:
1990 // Currently all planes are assumed to be GA light singles with corresponding speeds and separation times.
1991 // In order of priority for runway use:
1992 // STRAIGHT_IN > CIRCUIT > HOLDING_FOR_DEPARTURE
1993 // No modification of planes speeds occurs - conflicts are resolved by delaying turn for base,
1994 // and holding planes until a space.
1995 // When calculating if a holding plane can use the runway, time clearance from last departure
1996 // as well as time clearance to next arrival must be considered.
1998 trafficList.clear();
2000 tower_plane_rec_list_iterator twrItr;
2001 // Do the approach list first
2002 //if(ident == "KRHV") cout << "A" << flush;
2003 for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
2004 TowerPlaneRec* tpr = *twrItr;
2005 //if(ident == "KRHV") cout << tpr->plane.callsign << '\n';
2006 conflict = AddToTrafficList(tpr);
2008 // Then the circuit list
2009 //if(ident == "KRHV") cout << "C" << flush;
2010 for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
2011 TowerPlaneRec* tpr = *twrItr;
2012 //if(ident == "KRHV") cout << tpr->plane.callsign << '\n';
2013 conflict = AddToTrafficList(tpr);
2015 // And finally the hold list
2016 //cout << "H" << endl;
2017 for(twrItr = holdList.begin(); twrItr != holdList.end(); twrItr++) {
2018 TowerPlaneRec* tpr = *twrItr;
2019 AddToTrafficList(tpr, true);
2024 //if(ident == "KRHV") {
2026 for(twrItr = trafficList.begin(); twrItr != trafficList.end(); twrItr++) {
2027 TowerPlaneRec* tpr = *twrItr;
2028 cout << tpr->plane.callsign << '\t' << tpr->eta << '\t';
2033 //cout << "Done doThresholdUseOrder" << endl;
2038 // Return the ETA of plane no. list_pos (1-based) in the traffic list.
2039 // i.e. list_pos = 1 implies next to use runway.
2040 double FGTower::GetTrafficETA(unsigned int list_pos, bool printout) {
2041 if(trafficList.size() < list_pos) {
2045 tower_plane_rec_list_iterator twrItr;
2046 twrItr = trafficList.begin();
2047 for(unsigned int i = 1; i < list_pos; i++, twrItr++);
2048 TowerPlaneRec* tpr = *twrItr;
2049 CalcETA(tpr, printout);
2050 //cout << "ETA returned = " << tpr->eta << '\n';
2055 void FGTower::ContactAtHoldShort(const PlaneRec& plane, FGAIPlane* requestee, tower_traffic_type operation) {
2056 // HACK - assume that anything contacting at hold short is new for now - FIXME LATER
2057 TowerPlaneRec* t = new TowerPlaneRec;
2059 t->planePtr = requestee;
2060 t->holdShortReported = true;
2061 t->clearedToLineUp = false;
2062 t->clearedToTakeOff = false;
2063 t->opType = operation;
2064 t->pos = requestee->GetPos();
2066 //cout << "Hold Short reported by " << plane.callsign << '\n';
2067 SG_LOG(SG_ATC, SG_BULK, "Hold Short reported by " << plane.callsign);
2070 bool next = AddToTrafficList(t, true);
2072 double teta = GetTrafficETA(2);
2074 t->clearanceCounter = 7.0; // This reduces the delay before response to 3 secs if an immediate takeoff is reqd
2075 //cout << "Reducing response time to request due imminent traffic\n";
2080 // TODO - possibly add the reduced interval to clearance when immediate back in under the new scheme
2082 holdList.push_back(t);
2084 responseReqd = true;
2087 // Register the presence of an AI plane at a point where contact would already have been made in real life
2088 // CAUTION - currently it is assumed that this plane's callsign is unique - it is up to AIMgr to generate unique callsigns.
2089 void FGTower::RegisterAIPlane(const PlaneRec& plane, FGAIPlane* ai, const tower_traffic_type& op, const PatternLeg& lg) {
2090 // At the moment this is only going to be tested with inserting an AI plane on downwind
2091 TowerPlaneRec* t = new TowerPlaneRec;
2096 t->pos = ai->GetPos();
2100 if(op == CIRCUIT && lg != LEG_UNKNOWN) {
2101 AddToCircuitList(t);
2106 doThresholdUseOrder();
2109 void FGTower::DeregisterAIPlane(const string& id) {
2113 // Contact tower for VFR approach
2114 // eg "Cessna Charlie Foxtrot Golf Foxtrot Sierra eight miles South of the airport for full stop with Bravo"
2115 // This function probably only called via user interaction - AI planes will have an overloaded function taking a planerec.
2116 // opt defaults to AIP_LT_UNKNOWN
2117 void FGTower::VFRArrivalContact(const string& ID, const LandingType& opt) {
2118 //cout << "USER Request Landing Clearance called for ID " << ID << '\n';
2120 // For now we'll assume that the user is a light plane and can get him/her to join the circuit if necessary.
2123 string usercall = fgGetString("/sim/user/callsign");
2124 if(ID == "USER" || ID == usercall) {
2125 t = FindPlane(usercall);
2127 //cout << "NOT t\n";
2128 t = new TowerPlaneRec;
2130 t->pos.setlon(user_lon_node->getDoubleValue());
2131 t->pos.setlat(user_lat_node->getDoubleValue());
2132 t->pos.setelev(user_elev_node->getDoubleValue());
2135 // Oops - the plane is already registered with this tower - maybe we took off and flew a giant circuit without
2136 // quite getting out of tower airspace - just ignore for now and treat as new arrival.
2137 // TODO - Maybe should remove from departure and circuit list if in there though!!
2140 // Oops - something has gone wrong - put out a warning
2141 cout << "WARNING - FGTower::VFRContact(string ID, LandingType lt) called with ID " << ID << " which does not appear to be the user.\n";
2147 // Calculate where the plane is in relation to the active runway and it's circuit
2148 // and set the op-type as appropriate.
2150 // HACK - to get up and running I'm going to assume that the user contacts tower on a staight-in final for now.
2151 t->opType = STRAIGHT_IN;
2153 t->plane.type = GA_SINGLE; // FIXME - Another assumption!
2154 t->plane.callsign = usercall;
2156 t->vfrArrivalReported = true;
2157 responseReqd = true;
2159 appList.push_back(t); // Not necessarily permanent
2160 appListItr = appList.begin();
2161 AddToTrafficList(t);
2163 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL, TOWER);
2164 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_FULL_STOP, TOWER);
2165 current_atcdialog->remove_entry(ident, USER_REQUEST_VFR_ARRIVAL_TOUCH_AND_GO, TOWER);
2168 // landingType defaults to AIP_LT_UNKNOWN
2169 void FGTower::VFRArrivalContact(const PlaneRec& plane, FGAIPlane* requestee, const LandingType& lt) {
2170 //cout << "VFRArrivalContact called for plane " << plane.callsign << " at " << ident << '\n';
2171 // Possible hack - assume this plane is new for now - TODO - should check really
2172 TowerPlaneRec* t = new TowerPlaneRec;
2174 t->planePtr = requestee;
2175 t->landingType = lt;
2176 t->pos = requestee->GetPos();
2178 //cout << "Hold Short reported by " << plane.callsign << '\n';
2179 SG_LOG(SG_ATC, SG_BULK, "VFR arrival contact made by " << plane.callsign);
2180 //cout << "VFR arrival contact made by " << plane.callsign << '\n';
2182 // HACK - to get up and running I'm going to assume a staight-in final for now.
2183 t->opType = STRAIGHT_IN;
2185 t->vfrArrivalReported = true;
2186 responseReqd = true;
2188 //cout << "Before adding, appList.size = " << appList.size() << " at " << ident << '\n';
2189 appList.push_back(t); // Not necessarily permanent
2190 appListItr = appList.begin();
2191 //cout << "After adding, appList.size = " << appList.size() << " at " << ident << '\n';
2192 AddToTrafficList(t);
2195 void FGTower::RequestDepartureClearance(const string& ID) {
2196 //cout << "Request Departure Clearance called...\n";
2199 void FGTower::RequestTakeOffClearance(const string& ID) {
2202 uid = fgGetString("/sim/user/callsign");
2203 current_atcdialog->remove_entry(ident, USER_REQUEST_TAKE_OFF, TOWER);
2205 TowerPlaneRec* t = FindPlane(uid);
2207 if(!(t->clearedToTakeOff)) {
2209 t->lineUpReported=true;
2210 responseReqd = true;
2214 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::RequestTakeOffClearance(...)");
2218 void FGTower::ReportFinal(const string& ID) {
2219 //cout << "Report Final Called at tower " << ident << " by plane " << ID << '\n';
2222 uid = fgGetString("/sim/user/callsign");
2223 current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
2225 TowerPlaneRec* t = FindPlane(uid);
2227 t->finalReported = true;
2228 t->finalAcknowledged = false;
2229 if(!(t->clearedToLand)) {
2230 responseReqd = true;
2232 // possibly respond with wind even if already cleared to land?
2233 t->finalReported = false;
2234 t->finalAcknowledged = true;
2235 // HACK!! - prevents next reporting being misinterpreted as this one.
2238 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportFinal(...)");
2242 void FGTower::ReportLongFinal(const string& ID) {
2245 uid = fgGetString("/sim/user/callsign");
2246 current_atcdialog->remove_entry(ident, USER_REPORT_3_MILE_FINAL, TOWER);
2248 TowerPlaneRec* t = FindPlane(uid);
2250 t->longFinalReported = true;
2251 t->longFinalAcknowledged = false;
2252 if(!(t->clearedToLand)) {
2253 responseReqd = true;
2254 } // possibly respond with wind even if already cleared to land?
2256 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportLongFinal(...)");
2260 //void FGTower::ReportOuterMarker(string ID);
2261 //void FGTower::ReportMiddleMarker(string ID);
2262 //void FGTower::ReportInnerMarker(string ID);
2264 void FGTower::ReportRunwayVacated(const string& ID) {
2265 //cout << "Report Runway Vacated Called at tower " << ident << " by plane " << ID << '\n';
2268 uid = fgGetString("/sim/user/callsign");
2269 current_atcdialog->remove_entry(ident, USER_REPORT_RWY_VACATED, TOWER);
2271 TowerPlaneRec* t = FindPlane(uid);
2273 //cout << "Found it...\n";
2274 t->rwyVacatedReported = true;
2275 responseReqd = true;
2277 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportRunwayVacated(...)");
2278 SG_LOG(SG_ATC, SG_ALERT, "A WARNING: Unable to find plane " << ID << " in FGTower::ReportRunwayVacated(...)");
2279 //cout << "WARNING: Unable to find plane " << ID << " in FGTower::ReportRunwayVacated(...)\n";
2283 TowerPlaneRec* FGTower::FindPlane(const string& ID) {
2284 //cout << "FindPlane called for " << ID << "...\n";
2285 tower_plane_rec_list_iterator twrItr;
2286 // Do the approach list first
2287 for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
2288 //cout << "appList callsign is " << (*twrItr)->plane.callsign << '\n';
2289 if((*twrItr)->plane.callsign == ID) return(*twrItr);
2291 // Then the circuit list
2292 for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
2293 //cout << "circuitList callsign is " << (*twrItr)->plane.callsign << '\n';
2294 if((*twrItr)->plane.callsign == ID) return(*twrItr);
2296 // Then the runway list
2297 //cout << "rwyList.size() is " << rwyList.size() << '\n';
2298 for(twrItr = rwyList.begin(); twrItr != rwyList.end(); twrItr++) {
2299 //cout << "rwyList callsign is " << (*twrItr)->plane.callsign << '\n';
2300 if((*twrItr)->plane.callsign == ID) return(*twrItr);
2303 for(twrItr = holdList.begin(); twrItr != holdList.end(); twrItr++) {
2304 if((*twrItr)->plane.callsign == ID) return(*twrItr);
2306 // And finally the vacated list
2307 for(twrItr = vacatedList.begin(); twrItr != vacatedList.end(); twrItr++) {
2308 //cout << "vacatedList callsign is " << (*twrItr)->plane.callsign << '\n';
2309 if((*twrItr)->plane.callsign == ID) return(*twrItr);
2311 SG_LOG(SG_ATC, SG_WARN, "Unable to find " << ID << " in FGTower::FindPlane(...)");
2316 void FGTower::RemovePlane(const string& ID) {
2317 //cout << ident << " RemovePlane called for " << ID << '\n';
2318 // We have to be careful here - we want to erase the plane from all lists it is in,
2319 // but we can only delete it once, AT THE END.
2320 TowerPlaneRec* t = NULL;
2321 tower_plane_rec_list_iterator twrItr;
2322 for(twrItr = appList.begin(); twrItr != appList.end();) {
2323 if((*twrItr)->plane.callsign == ID) {
2325 twrItr = appList.erase(twrItr);
2326 appListItr = appList.begin();
2327 // HACK: aircraft are sometimes more than once in a list, so we need to
2328 // remove them all before we can delete the TowerPlaneRec class
2333 for(twrItr = depList.begin(); twrItr != depList.end();) {
2334 if((*twrItr)->plane.callsign == ID) {
2336 twrItr = depList.erase(twrItr);
2337 depListItr = depList.begin();
2341 for(twrItr = circuitList.begin(); twrItr != circuitList.end();) {
2342 if((*twrItr)->plane.callsign == ID) {
2344 twrItr = circuitList.erase(twrItr);
2345 circuitListItr = circuitList.begin();
2349 for(twrItr = holdList.begin(); twrItr != holdList.end();) {
2350 if((*twrItr)->plane.callsign == ID) {
2352 twrItr = holdList.erase(twrItr);
2353 holdListItr = holdList.begin();
2357 for(twrItr = rwyList.begin(); twrItr != rwyList.end();) {
2358 if((*twrItr)->plane.callsign == ID) {
2360 twrItr = rwyList.erase(twrItr);
2361 rwyListItr = rwyList.begin();
2365 for(twrItr = vacatedList.begin(); twrItr != vacatedList.end();) {
2366 if((*twrItr)->plane.callsign == ID) {
2368 twrItr = vacatedList.erase(twrItr);
2369 vacatedListItr = vacatedList.begin();
2373 for(twrItr = trafficList.begin(); twrItr != trafficList.end();) {
2374 if((*twrItr)->plane.callsign == ID) {
2376 twrItr = trafficList.erase(twrItr);
2377 trafficListItr = trafficList.begin();
2381 // And finally, delete the record.
2385 void FGTower::ReportDownwind(const string& ID) {
2386 //cout << "ReportDownwind(...) called\n";
2389 uid = fgGetString("/sim/user/callsign");
2390 current_atcdialog->remove_entry(ident, USER_REPORT_DOWNWIND, TOWER);
2392 TowerPlaneRec* t = FindPlane(uid);
2394 t->downwindReported = true;
2395 responseReqd = true;
2396 // If the plane is in the app list, remove it and put it in the circuit list instead.
2397 // Ideally we might want to do this at the 2 mile report prior to 45 deg entry, but at
2398 // the moment that would b&gg?r up the constraint position calculations.
2399 RemoveFromAppList(ID);
2402 t->pos.setlon(user_lon_node->getDoubleValue());
2403 t->pos.setlat(user_lat_node->getDoubleValue());
2404 t->pos.setelev(user_elev_node->getDoubleValue());
2406 // ASSERT(t->planePtr != NULL);
2407 t->pos = t->planePtr->GetPos();
2410 AddToCircuitList(t);
2412 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportDownwind(...)");
2416 void FGTower::ReportGoingAround(const string& ID) {
2419 uid = fgGetString("/sim/user/callsign");
2420 RemoveAllUserDialogOptions(); // TODO - it would be much more efficient if ATCDialog simply had a clear() function!!!
2421 current_atcdialog->add_entry(ident, "@AP Tower, @CS Downwind @RW", "Report Downwind", TOWER, (int)USER_REPORT_DOWNWIND);
2423 TowerPlaneRec* t = FindPlane(uid);
2425 //t->goAroundReported = true; // No need to set this until we start responding to it.
2426 responseReqd = false; // might change in the future but for now we'll not distract them during the go-around.
2427 // If the plane is in the app list, remove it and put it in the circuit list instead.
2428 RemoveFromAppList(ID);
2431 t->pos.setlon(user_lon_node->getDoubleValue());
2432 t->pos.setlat(user_lat_node->getDoubleValue());
2433 t->pos.setelev(user_elev_node->getDoubleValue());
2435 // ASSERT(t->planePtr != NULL);
2436 t->pos = t->planePtr->GetPos();
2439 AddToCircuitList(t);
2441 SG_LOG(SG_ATC, SG_WARN, "WARNING: Unable to find plane " << ID << " in FGTower::ReportDownwind(...)");
2445 string FGTower::GenText(const string& m, int c) {
2446 const int cmax = 300;
2456 string usercall = fgGetString("/sim/user/callsign");
2457 TowerPlaneRec* t = FindPlane(responseID);
2459 //transmission_list_type tmissions = transmissionlist_station[station];
2460 //transmission_list_iterator current = tmissions.begin();
2461 //transmission_list_iterator last = tmissions.end();
2463 //for ( ; current != last ; ++current ) {
2464 // if ( current->get_code().c1 == code.c1 &&
2465 // current->get_code().c2 == code.c2 &&
2466 // current->get_code().c3 == code.c3 ) {
2468 //if ( ttext ) message = current->get_transtext();
2469 //else message = current->get_menutext();
2470 strcpy( &mes[0], m.c_str() );
2472 // Replace all the '@' parameters with the actual text.
2473 int check = 0; // If mes gets overflowed the while loop can go infinite
2474 double gp = fgGetFloat("/gear/gear/position-norm");
2475 while ( strchr(&mes[0], crej) != NULL ) { // ie. loop until no more occurances of crej ('@') found
2476 pos = strchr( &mes[0], crej );
2477 memmove(&tag[0], pos, 3);
2481 for ( i=0; i<cmax; i++ ) {
2482 if ( mes[i] == crej ) {
2487 strncpy( &dum[0], &mes[0], len );
2490 if ( strcmp ( tag, "@ST" ) == 0 )
2491 //strcat( &dum[0], tpars.station.c_str() );
2492 strcat(&dum[0], ident.c_str());
2493 else if ( strcmp ( tag, "@AP" ) == 0 )
2494 //strcat( &dum[0], tpars.airport.c_str() );
2495 strcat(&dum[0], name.c_str());
2496 else if ( strcmp ( tag, "@CS" ) == 0 )
2497 //strcat( &dum[0], tpars.callsign.c_str() );
2498 strcat(&dum[0], usercall.c_str());
2499 else if ( strcmp ( tag, "@TD" ) == 0 ) {
2501 if ( tpars.tdir == 1 ) {
2502 char buf[] = "left";
2503 strcat( &dum[0], &buf[0] );
2506 char buf[] = "right";
2507 strcat( &dum[0], &buf[0] );
2511 else if ( strcmp ( tag, "@HE" ) == 0 ) {
2514 sprintf( buf, "%i", (int)(tpars.heading) );
2515 strcat( &dum[0], &buf[0] );
2518 else if ( strcmp ( tag, "@AT" ) == 0 ) { // ATIS ID
2521 sprintf( buf, "%i", (int)(tpars.heading) );
2522 strcat( &dum[0], &buf[0] );
2524 double f = globals->get_ATC_mgr()->GetFrequency(ident, ATIS) / 100.0;
2527 atis_id = ", information " + GetATISID();
2528 strcat( &dum[0], atis_id.c_str() );
2531 else if ( strcmp ( tag, "@VD" ) == 0 ) {
2533 if ( tpars.VDir == 1 ) {
2534 char buf[] = "Descend and maintain";
2535 strcat( &dum[0], &buf[0] );
2537 else if ( tpars.VDir == 2 ) {
2538 char buf[] = "Maintain";
2539 strcat( &dum[0], &buf[0] );
2541 else if ( tpars.VDir == 3 ) {
2542 char buf[] = "Climb and maintain";
2543 strcat( &dum[0], &buf[0] );
2547 else if ( strcmp ( tag, "@AL" ) == 0 ) {
2550 sprintf( buf, "%i", (int)(tpars.alt) );
2551 strcat( &dum[0], &buf[0] );
2554 else if ( strcmp ( tag, "@TO" ) == 0 ) { // Requesting take-off or departure clearance
2557 tmp = "Ready for take-off";
2559 if (OnAnyRunway(Point3D(user_lon_node->getDoubleValue(),
2560 user_lat_node->getDoubleValue(), 0.0),true)) {
2561 tmp = "Request take-off clearance";
2563 tmp = "Request departure clearance";
2566 strcat(&dum[0], tmp.c_str());
2568 else if ( strcmp ( tag, "@MI" ) == 0 ) {
2570 //sprintf( buf, "%3.1f", tpars.miles );
2571 int dist_miles = (int)dclGetHorizontalSeparation(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
2572 sprintf(buf, "%i", dist_miles);
2573 strcat( &dum[0], &buf[0] );
2575 else if ( strcmp ( tag, "@FR" ) == 0 ) {
2578 sprintf( buf, "%6.2f", tpars.freq );
2579 strcat( &dum[0], &buf[0] );
2582 else if ( strcmp ( tag, "@RW" ) == 0 ) {
2583 strcat(&dum[0], ConvertRwyNumToSpokenString(activeRwy).c_str());
2585 else if ( strcmp ( tag, "@GR" ) == 0 ) { // Gear position (on final)
2586 if(t->gearWasUp && gp > 0.99) {
2587 strcat(&dum[0], ", gear down, ready to land.");
2590 else if(strcmp(tag, "@CD") == 0) { // @CD = compass direction
2591 double h = GetHeadingFromTo(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
2592 while(h < 0.0) h += 360.0;
2593 while(h > 360.0) h -= 360.0;
2594 if(h < 22.5 || h > 337.5) {
2595 strcat(&dum[0], "North");
2596 } else if(h < 67.5) {
2597 strcat(&dum[0], "North-East");
2598 } else if(h < 112.5) {
2599 strcat(&dum[0], "East");
2600 } else if(h < 157.5) {
2601 strcat(&dum[0], "South-East");
2602 } else if(h < 202.5) {
2603 strcat(&dum[0], "South");
2604 } else if(h < 247.5) {
2605 strcat(&dum[0], "South-West");
2606 } else if(h < 292.5) {
2607 strcat(&dum[0], "West");
2609 strcat(&dum[0], "North-West");
2612 cout << "Tag " << tag << " not found" << endl;
2615 strcat( &dum[0], &mes[len+3] );
2616 strcpy( &mes[0], &dum[0] );
2620 SG_LOG(SG_ATC, SG_WARN, "WARNING: Possibly endless loop terminated in FGTransmissionlist::gen_text(...)");
2625 //cout << mes << endl;
2629 return mes[0] ? mes : "No transmission found";
2632 string FGTower::GetWeather() {
2633 std::ostringstream msg;
2636 double hdg = wind_from_hdg->getDoubleValue();
2637 double speed = wind_speed_knots->getDoubleValue();
2641 msg << "wind " << int(hdg) << " degrees at " << int(speed) << " knots";
2644 double visibility = fgGetDouble("/environment/visibility-m");
2645 if (visibility < 10000)
2646 msg << ", visibility " << int(visibility / 1609) << " miles";
2648 // pressure / altimeter
2649 double pressure = fgGetDouble("/environment/pressure-sea-level-inhg");
2650 msg << ", QFE " << fixed << setprecision(2) << pressure << ".";
2655 string FGTower::GetATISID() {
2656 int hours = fgGetInt("/sim/time/utc/hour");
2657 int phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
2658 return GetPhoneticIdent(phonetic_id);
2661 ostream& operator << (ostream& os, tower_traffic_type ttt) {
2663 case(CIRCUIT): return(os << "CIRCUIT");
2664 case(INBOUND): return(os << "INBOUND");
2665 case(OUTBOUND): return(os << "OUTBOUND");
2666 case(TTT_UNKNOWN): return(os << "UNKNOWN");
2667 case(STRAIGHT_IN): return(os << "STRAIGHT_IN");
2669 return(os << "ERROR - Unknown switch in tower_traffic_type operator << ");