]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.cxx
Major re-work of the comm frequency storage and lookup. Only a small core amount...
[flightgear.git] / src / ATC / ATCmgr.cxx
1 // ATCmgr.cxx - Implementation of FGATCMgr - a global Flightgear ATC manager.
2 //
3 // Written by David Luff, started February 2002.
4 //
5 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 //#include <Time/event.hxx>
22
23 #include <simgear/misc/sg_path.hxx>
24 #include <simgear/misc/commands.hxx>
25 #include <simgear/debug/logstream.hxx>
26
27 #include "ATCmgr.hxx"
28 #include "commlist.hxx"
29 //#include "atislist.hxx"
30 //#include "groundlist.hxx"
31 //#include "towerlist.hxx"
32 //#include "approachlist.hxx"
33 #include "ATCdisplay.hxx"
34
35 /*
36 // periodic radio station search wrapper
37 static void fgATCSearch( void ) {
38         globals->get_ATC_mgr()->Search();
39 }
40 */ //This wouldn't compile - including Time/event.hxx breaks it :-(
41
42 static char* t0 = "Request landing clearance";
43 static char* t1 = "Request departure clearance";
44 static char* t2 = "Report Runway vacated";
45 static char** towerOptions = new char*[4];
46 static char* a0 = "Request vectors";
47 static char** approachOptions = new char*[2];
48
49 // For the ATC dialog - copied from the Autopilot new heading dialog code!
50 static puDialogBox*             atcDialog;
51 static puFrame*                 atcDialogFrame;
52 static puText*                  atcDialogMessage;
53 //static puInput*                       atcDialogInput;
54 static puOneShot*               atcDialogOkButton;
55 static puOneShot*               atcDialogCancelButton;
56 static puButtonBox*             atcDialogCommunicationOptions;
57
58 static void ATCDialogCancel(puObject *)
59 {
60     //ATCDialogInput->rejectInput();
61     FG_POP_PUI_DIALOG( atcDialog );
62 }
63
64 static void ATCDialogOK (puObject *me)
65 {
66         // Note that currently the dialog is hardwired to comm1 only here.
67         switch(globals->get_ATC_mgr()->GetComm1ATCType()) {
68         case INVALID:
69                 break;
70         case ATIS:
71                 break;
72         case TOWER: {
73                 FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
74                 switch(atcDialogCommunicationOptions->getValue()) {
75                 case 0:
76                         //cout << "Option 0 chosen\n";
77                         twr->RequestLandingClearance("golf bravo echo");
78                         break;
79                 case 1:
80                         //cout << "Option 1 chosen\n";
81                         twr->RequestDepartureClearance("golf bravo echo");
82                         break;
83                 case 2:
84                         //cout << "Option 2 chosen\n";
85                         twr->ReportRunwayVacated("golf bravo echo");
86                         break;
87                 default:
88                         break;
89                 }
90                 break;
91         }
92         case GROUND:
93                 break;
94         case APPROACH:
95                 break;
96         default:
97                 break;
98         }
99
100     ATCDialogCancel(me);
101     //if(error) mkDialog(s.c_str());
102 }
103
104 static void ATCDialog(puObject *cb)
105 {
106     //ApHeadingDialogInput   ->    setValue ( heading );
107     //ApHeadingDialogInput    -> acceptInput();
108     FG_PUSH_PUI_DIALOG(atcDialog);
109 }
110
111 static void ATCDialogInit()
112 {
113         char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
114         char *s;
115
116         // Option lists hardwired per ATC type  
117         towerOptions[0] = new char[strlen(t0)+1];
118         strcpy(towerOptions[0], t0);
119         towerOptions[1] = new char[strlen(t1)+1];
120         strcpy(towerOptions[1], t1);
121         towerOptions[2] = new char[strlen(t2)+1];
122         strcpy(towerOptions[2], t2);
123         towerOptions[3] = NULL;
124         
125         approachOptions[0] = new char[strlen(a0)+1];
126         strcpy(approachOptions[0], a0);
127         approachOptions[1] = NULL;
128
129         atcDialog = new puDialogBox (150, 50);
130         {
131                 atcDialogFrame   = new puFrame (0, 0, 500, 250);
132                 
133                 atcDialogMessage = new puText          (250, 220);
134                 atcDialogMessage    -> setDefaultValue (defaultATCLabel);
135                 atcDialogMessage    -> getDefaultValue (&s);
136                 atcDialogMessage    -> setLabel        (s);
137                 atcDialogMessage    -> setLabelPlace   (PUPLACE_TOP_CENTERED);
138
139                 atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
140                 
141                 atcDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
142                 atcDialogOkButton     ->     setLegend         (gui_msg_OK);
143                 atcDialogOkButton     ->     makeReturnDefault (TRUE);
144                 atcDialogOkButton     ->     setCallback       (ATCDialogOK);
145                 
146                 atcDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
147                 atcDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
148                 atcDialogCancelButton ->     setCallback       (ATCDialogCancel);
149                 
150         }
151         FG_FINALIZE_PUI_DIALOG(atcDialog);
152 }
153
154 // For the command manager - maybe eventually this should go in the built in command list
155 static bool do_ATC_dialog(const SGPropertyNode* arg) {
156         globals->get_ATC_mgr()->doStandardDialog();
157         return(true);
158 }
159
160
161 FGATCMgr::FGATCMgr() {
162         comm_ident[0] = "";
163         comm_ident[1] = "";
164         last_comm_ident[0] = "";
165         last_comm_ident[1] = "";
166         approach_ident = "";
167         last_in_range = false;
168         comm_type[0] = INVALID;
169         comm_type[1] = INVALID;
170         comm_atc_ptr[0] = NULL;
171         comm_atc_ptr[1] = NULL;
172 }
173
174 FGATCMgr::~FGATCMgr() {
175 }
176
177 void FGATCMgr::bind() {
178 }
179
180 void FGATCMgr::unbind() {
181 }
182
183 void FGATCMgr::init() {
184         comm_node[0] = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
185         comm_node[1] = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
186         lon_node = fgGetNode("/position/longitude-deg", true);
187         lat_node = fgGetNode("/position/latitude-deg", true);
188         elev_node = fgGetNode("/position/altitude-ft", true);
189         atc_list_itr = atc_list.begin();
190         // Search for connected ATC stations once per 0.8 seconds or so
191         // global_events.Register( "fgATCSearch()", fgATCSearch,
192         //                  fgEVENT::FG_EVENT_READY, 800);
193         // For some reason the above doesn't compile - including Time/event.hxx stops compilation.
194         
195         // Initialise the frequency search map
196     current_commlist = new FGCommList;
197     SGPath p_comm( globals->get_fg_root() );
198     current_commlist->init( p_comm );
199         
200         // Initialise the airport_atc_map - we'll cheat for now and just hardcode KEMT and any others that may be needed for development
201         AirportATC *a = new AirportATC;
202         a->lon = -118.034719;
203         a->lat = 34.086114;
204         a->elev = 296.0;
205         a->atis_freq = 118.75;
206         a->atis_active = false;
207         a->tower_freq = 121.2;
208         a->tower_active = false;
209         a->ground_freq = 125.9;
210         a->ground_active = false;
211         
212         //a->set_by_AI = true;
213         //a->set_by_comm_search = false;
214         
215         airport_atc_map[(string)"KEMT"] = a;
216
217 #ifdef ENABLE_AUDIO_SUPPORT     
218         // Load all available voices.
219         // For now we'll do one hardwired one
220         voiceOK = v1.LoadVoice("default");
221         /* I've loaded the voice even if /sim/sound/audible is false
222         *  since I know no way of forcing load of the voice if the user
223         *  subsequently switches /sim/sound/audible to true. */
224 #else
225         voice = false;
226 #endif
227
228         // Initialise the ATC Dialogs
229         ATCDialogInit();
230         
231         // Add ATC-dialog to the command list
232         globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
233 }
234
235 void FGATCMgr::update(double dt) {
236         //cout << "Entering update..." << endl;
237         //Traverse the list of active stations.
238         //Only update one class per update step to avoid the whole ATC system having to calculate between frames.
239         //Eventually we should only update every so many steps.
240         //cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
241         if(atc_list.size()) {
242                 if(atc_list_itr == atc_list.end()) {
243                         atc_list_itr = atc_list.begin();
244                 }
245                 //cout << "Updating " << (*atc_list_itr)->get_ident() << ' ' << (*atc_list_itr)->GetType() << '\n';
246                 //cout << "Freq = " << (*atc_list_itr)->get_freq() << '\n';
247                 (*atc_list_itr)->Update();
248                 //cout << "Done ATC update..." << endl;
249                 ++atc_list_itr;
250         }
251         
252         // Search the tuned frequencies every now and then - this should be done with the event scheduler
253         static int i = 0;
254         if(i == 7) {
255                 AreaSearch();
256         }
257         if(i == 15) {
258                 //cout << "About to search(1)" << endl;
259                 FreqSearch(1);
260         }
261         if(i == 30) {
262                 //cout << "About to search(2)" << endl;
263                 FreqSearch(2);
264                 i = 0;
265         }
266         ++i;
267 }
268
269 // Remove from list only if not needed by the AI system or the other comm channel
270 // TODO - implement me!!
271 void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
272         /*AirportATC a;
273         if(GetAirportATCDetails((string)id, &a)) {
274                 if(a.set_by_AI) {
275                         // Don't remove
276                         a.set_by_comm_search = false;
277                         airport_atc_map[(string)id] = a;
278                         return;
279                 } else {
280                         // remove
281                 }
282         }*/
283         
284         // Hack - need to implement this properly
285         RemoveFromList(id, tp);
286 }
287     
288
289 // Remove from list - should only be called from above or similar
290 // This function *will* remove it from the list regardless of who else might want it.
291 void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
292         //cout << "Requested type = " << tp << '\n';
293         //cout << "id = " << id << '\n';
294         atc_list_itr = atc_list.begin();
295         while(atc_list_itr != atc_list.end()) {
296                 //cout << "type = " << (*atc_list_itr)->GetType() << '\n';
297                 //cout << "Ident = " << (*atc_list_itr)->get_ident() << '\n';
298                 if( (!strcmp((*atc_list_itr)->get_ident(), id))
299                         && ((*atc_list_itr)->GetType() == tp) ) {
300                                 //Before removing it stop it transmitting!!
301                                 //cout << "OBLITERATING FROM LIST!!!\n";
302                                 (*atc_list_itr)->SetNoDisplay();
303                                 (*atc_list_itr)->Update();
304                                 delete (*atc_list_itr);
305                                 atc_list_itr = atc_list.erase(atc_list_itr);
306                                 break;
307                         }  // Note that that can upset where we are in the list but that doesn't really matter
308                 ++atc_list_itr;
309         }
310 }
311
312
313 // Find in list - return a currently active ATC pointer given ICAO code and type
314 // Return NULL if the given service is not in the list
315 // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
316 FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
317         atc_list_itr = atc_list.begin();
318         while(atc_list_itr != atc_list.end()) {
319                 if( (!strcmp((*atc_list_itr)->get_ident(), id))
320                 && ((*atc_list_itr)->GetType() == tp) ) {
321                         return(*atc_list_itr);
322                 }       // Note that that can upset where we are in the list but that shouldn't really matter
323                 ++atc_list_itr;
324         }
325         // If we get here it's not in the list
326         return(NULL);
327 }
328
329 // Returns true if the airport is found in the map
330 bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
331         if(airport_atc_map.find(icao) != airport_atc_map.end()) {
332                 *a = *airport_atc_map[icao];
333                 return(true);
334         } else {
335                 return(false);
336         }
337 }
338
339
340 // Return a pointer to a given sort of ATC at a given airport and activate if necessary
341 // ONLY CALL THIS FUNCTION AFTER FIRST CHECKING THE SERVICE EXISTS BY CALLING GetAirportATCDetails
342 // FIXME - we really ought to take out the necessity for two function calls by simply returning
343 // a NULL pointer if the service doesn't exist and requiring the caller to check for it (NULL).
344 FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
345         AirportATC *a = airport_atc_map[icao];
346         //cout << "a->lon = " << a->lon << '\n';
347         //cout << "a->elev = " << a->elev << '\n';
348         //cout << "a->tower_freq = " << a->tower_freq << '\n';
349         switch(type) {
350                 case TOWER:
351                 if(a->tower_active) {
352                         // Get the pointer from the list
353                         return(FindInList(icao.c_str(), type)); // DCL - this untested so far.
354                 } else {
355                         FGTower* t = new FGTower;
356                         ATCData data;
357                         if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->tower_freq, &data, TOWER)) {
358                                 t->SetData(&data);
359                                 atc_list.push_back(t);
360                                 a->tower_active = true;
361                                 airport_atc_map[icao] = a;
362                                 return(t);
363                         } else {
364                                 cout << "ERROR - tower that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found\n";
365                         }
366                 }
367                 break;
368                 // Lets add the rest to get rid of the compiler warnings even though we don't need them yet.
369                 case APPROACH:
370                 break;
371                 case ATIS:
372                 SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer");
373                 break;
374                 case GROUND:
375                 break;
376                 case INVALID:
377                 break;
378                 case ENROUTE:
379                 break;
380                 case DEPARTURE:
381                 break;
382         }
383         
384         SG_LOG(SG_GENERAL, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
385         
386         return(NULL);
387 }
388
389
390 // Render a transmission
391 // Outputs the transmission either on screen or as audio depending on user preference
392 // The refname is a string to identify this sample to the sound manager
393 // The repeating flag indicates whether the message should be repeated continuously or played once.
394 void FGATCMgr::Render(string msg, string refname, bool repeating) {
395 #ifdef ENABLE_AUDIO_SUPPORT
396         voice = voiceOK && fgGetBool("/sim/sound/audible");
397         if(voice) {
398                 int len;
399                 unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
400                 if(voice) {
401                         FGSimpleSound* simple = new FGSimpleSound(buf, len);
402                         // TODO - at the moment the volume is always set off comm1 
403                         // and can't be changed after the transmission has started.
404                         simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
405                         globals->get_soundmgr()->add(simple, refname);
406                         if(repeating) {
407                                 globals->get_soundmgr()->play_looped(refname);
408                         } else {
409                                 globals->get_soundmgr()->play_once(refname);
410                         }
411                 }
412                 delete[] buf;
413         }
414 #endif  // ENABLE_AUDIO_SUPPORT
415         if(!voice) {
416                 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
417                 for(unsigned int i = 0; i < msg.length(); ++i) {
418                         if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
419                                 msg[i] = ' ';
420                         }
421                 }
422                 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
423         }
424         playing = true; 
425 }
426
427
428 // Cease rendering a transmission.
429 void FGATCMgr::NoRender(string refname) {
430         if(playing) {
431                 if(voice) {
432 #ifdef ENABLE_AUDIO_SUPPORT             
433                         globals->get_soundmgr()->stop(refname);
434                         globals->get_soundmgr()->remove(refname);
435 #endif
436                 } else {
437                         globals->get_ATC_display()->CancelRepeatingMessage();
438                 }
439                 playing = false;
440         }
441 }
442
443
444 // Display a dialog box with options relevant to the currently tuned ATC service.
445 void FGATCMgr::doStandardDialog() {
446         /* DCL 2002/12/06 - This function currently in development 
447            and dosen't display anything usefull to the end-user */
448         //cout << "FGATCMgr::doStandardDialog called..." << endl;
449         
450         // First - need to determine which ATC service (if any) the user is tuned to.
451         //cout << "comm1_type = " << comm1_type << endl;
452         
453         // Second - customise the dialog box
454         switch(comm_type[0]) {
455         case INVALID:
456                 atcDialogCommunicationOptions->newList(NULL);
457                 atcDialogMessage->setLabel("Not tuned in to any ATC service.");
458                 break;
459         case ATIS:
460                 atcDialogCommunicationOptions->newList(NULL);
461                 atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
462                 break;
463         case TOWER: 
464                 atcDialogCommunicationOptions->newList(towerOptions);
465                 atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
466                 break;
467         case GROUND:
468                 atcDialogCommunicationOptions->newList(NULL);
469                 atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
470                 break;
471         case APPROACH:
472                 atcDialogCommunicationOptions->newList(approachOptions);
473                 atcDialogMessage->setLabel("Tuned in to Approach - select communication to transmit:");
474                 break;
475         default:
476                 atcDialogCommunicationOptions->newList(NULL);
477                 atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
478                 break;
479         }
480         
481         // Third - display the dialog without pausing sim.
482         ATCDialog(NULL);
483         
484         // Forth - need to direct input back from the dialog to the relevant ATC service.
485         // This is in ATCDialogOK()
486 }
487
488 // Search for ATC stations by frequency
489 void FGATCMgr::FreqSearch(int channel) {
490         int chan = channel - 1;         // Convert to zero-based for the arrays
491
492         ATCData data;   
493         double freq = comm_node[chan]->getDoubleValue();
494         lon = lon_node->getDoubleValue();
495         lat = lat_node->getDoubleValue();
496         elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
497         
498         // Query the data store and get the closest match if any
499         if(current_commlist->FindByFreq(lon, lat, elev, freq, &data)) {
500                 // We have a match
501                 // What's the logic?
502                 // If this channel not previously valid then easy - add ATC to list
503                 // If this channel was valid then - Have we tuned to a different service?
504                 // If so - de-register one and add the other
505                 if(comm_valid[chan]) {
506                         if((comm_ident[chan] == data.ident) && (comm_type[chan] == data.type)) {
507                                 // Then we're still tuned into the same service so do nought and return
508                                 return;
509                         } else {
510                                 // Something's changed - either the location or the service type
511                                 // We need to feed the channel in so we're not removing it if we're also tuned in on the other channel
512                                 CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
513                         }
514                 }
515                 // At this point we can assume that we need to add the service.
516                 comm_ident[chan] = (data.ident).c_str();
517                 comm_type[chan] = data.type;
518                 comm_x[chan] = (double)data.x;
519                 comm_y[chan] = (double)data.y;
520                 comm_z[chan] = (double)data.z;
521                 comm_lon[chan] = (double)data.lon;
522                 comm_lat[chan] = (double)data.lat;
523                 comm_elev[chan] = (double)data.elev;
524                 comm_valid[chan] = true;
525                 
526                 // This was a switch-case statement but the compiler didn't like the new variable creation with it. 
527                 if(comm_type[chan] == ATIS) {
528                         FGATIS* a = new FGATIS;
529                         a->SetData(&data);
530                         comm_atc_ptr[chan] = a;
531                         a->SetDisplay();
532                         //a->set_refname((chan) ? "atis2" : "atis1");           // FIXME - that line is limited to 2 channels
533                         atc_list.push_back(a);
534                 } else if (comm_type[chan] == TOWER) {
535                         FGATC* app = FindInList(comm_ident[chan], TOWER);
536                         if(app != NULL) {
537                                 // The station is already in the ATC list
538                                 app->SetDisplay();
539                         } else {
540                                 // Generate the station and put in the ATC list
541                                 FGTower* t = new FGTower;
542                                 t->SetData(&data);
543                                 comm_atc_ptr[chan] = t;
544                                 t->SetDisplay();
545                                 atc_list.push_back(t);
546                         }
547                 } /*else if (comm_type[chan] == APPROACH) {
548                         // We have to be a bit more carefull here since approaches are also searched by area
549                         FGATC* app = FindInList(comm_ident[chan], APPROACH);
550                         if(app != NULL) {
551                                 // The station is already in the ATC list
552                                 app->AddPlane("Player");
553                                 app->SetDisplay();
554                         } else {
555                                 // Generate the station and put in the ATC list
556                                 FGApproach* a = new FGApproach;
557                                 a->SetData(&data);
558                                 a->AddPlane("Player");
559                                 atc_list.push_back(a);
560                         }                       
561                 }*/
562         } else {
563                 if(comm_valid[chan]) {
564                         if(comm_type[chan] != APPROACH) {
565                                 // Currently approaches are removed by Alexander's out-of-range mechanism
566                                 CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
567                         }
568                         // Note that we *don't* call SetNoDisplay() here because the other comm channel
569                         // might be tuned into the same station - this is handled by CommRemoveFromList(...)
570                         comm_type[chan] = INVALID;
571                         comm_atc_ptr[chan] = NULL;
572                         comm_valid[chan] = false;
573                 }
574         }
575 }
576
577
578 // Search ATC stations by area in order that we appear 'on the radar'
579 void FGATCMgr::AreaSearch() {
580         // Search for Approach stations
581         comm_list_type approaches;
582         comm_list_iterator app_itr;
583         
584         lon = lon_node->getDoubleValue();
585         lat = lat_node->getDoubleValue();
586         elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
587         
588         // search stations in range
589         int num_app = current_commlist->FindByPos(lon, lat, elev, &approaches, APPROACH);
590         if (num_app != 0) {
591                 //cout << num_app << " approaches found in radiostack search !!!!" << endl;
592                 
593                 for(app_itr = approaches.begin(); app_itr != approaches.end(); app_itr++) {
594                         
595                         FGATC* app = FindInList((app_itr->ident).c_str(), app_itr->type);
596                         if(app != NULL) {
597                                 // The station is already in the ATC list
598                                 app->AddPlane("Player");
599                                 //app->Update();
600                         } else {
601                                 // Generate the station and put in the ATC list
602                                 FGApproach* a = new FGApproach;
603                                 a->SetData(&(*app_itr));
604                                 a->AddPlane("Player");
605                                 //a->Update();
606                                 atc_list.push_back(a);
607                         }
608                 }
609         }
610         
611         // remove planes which are out of range
612         // TODO - I'm not entirely sure that this belongs here.
613         atc_list_itr = atc_list.begin();
614         while(atc_list_itr != atc_list.end()) {
615                 if((*atc_list_itr)->GetType() == APPROACH ) {
616                         int np = (*atc_list_itr)->RemovePlane();
617                         // if approach has no planes left remove it from ATC list
618                         if ( np == 0) {
619                                 (*atc_list_itr)->SetNoDisplay();
620                                 (*atc_list_itr)->Update();
621                                 delete (*atc_list_itr);
622                                 atc_list_itr = atc_list.erase(atc_list_itr);
623                                 break;     // the other stations will be checked next time
624                         }
625                 }
626                 ++atc_list_itr;
627         }
628 }