]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.cxx
First draft of an ATC dialog box, mostly copied from the autopilot new heading dialog...
[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 "atislist.hxx"
29 //#include "groundlist.hxx"
30 #include "towerlist.hxx"
31 #include "approachlist.hxx"
32 #include "ATCdisplay.hxx"
33
34 /*
35 // periodic radio station search wrapper
36 static void fgATCSearch( void ) {
37         globals->get_ATC_mgr()->Search();
38 }
39 */ //This wouldn't compile - including Time/event.hxx breaks it :-(
40
41 static char* t0 = "Request landing clearance";
42 static char* t1 = "Request departure clearance";
43 static char* t2 = "Report Runway vacated";
44 static char** towerOptions = new char*[4];
45 static char* a0 = "Request vectors";
46 static char** approachOptions = new char*[2];
47
48 // For the ATC dialog - copied from the Autopilot new heading dialog code!
49 static puDialogBox*             atcDialog;
50 static puFrame*                 atcDialogFrame;
51 static puText*                  atcDialogMessage;
52 //static puInput*                       atcDialogInput;
53 static puOneShot*               atcDialogOkButton;
54 static puOneShot*               atcDialogCancelButton;
55 static puButtonBox*             atcDialogCommunicationOptions;
56
57 static void ATCDialogCancel(puObject *)
58 {
59     //ATCDialogInput->rejectInput();
60     FG_POP_PUI_DIALOG( atcDialog );
61 }
62
63 static void ATCDialogOK (puObject *me)
64 {
65         switch(globals->get_ATC_mgr()->GetCurrentATCType()) {
66         case INVALID:
67                 break;
68         case ATIS:
69                 break;
70         case TOWER: {
71                 FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetCurrentATCPointer();
72                 switch(atcDialogCommunicationOptions->getValue()) {
73                 case 0:
74                         cout << "Option 0 chosen\n";
75                         twr->RequestLandingClearance("golf bravo echo");
76                         break;
77                 case 1:
78                         cout << "Option 1 chosen\n";
79                         twr->RequestDepartureClearance("golf bravo echo");
80                         break;
81                 case 2:
82                         cout << "Option 2 chosen\n";
83                         twr->ReportRunwayVacated("golf bravo echo");
84                         break;
85                 default:
86                         break;
87                 }
88                 break;
89         }
90         case GROUND:
91                 break;
92         case APPROACH:
93                 break;
94         default:
95                 break;
96         }
97
98     ATCDialogCancel(me);
99     //if(error) mkDialog(s.c_str());
100 }
101
102 static void ATCDialog(puObject *cb)
103 {
104     //ApHeadingDialogInput   ->    setValue ( heading );
105     //ApHeadingDialogInput    -> acceptInput();
106     FG_PUSH_PUI_DIALOG(atcDialog);
107 }
108
109 static void ATCDialogInit()
110 {
111         char defaultATCLabel[] = "Enter desired option to communicate with ATC:";
112         char *s;
113
114         // Option lists hardwired per ATC type  
115         towerOptions[0] = new char[strlen(t0)];
116         strcpy(towerOptions[0], t0);
117         towerOptions[1] = new char[strlen(t1)];
118         strcpy(towerOptions[1], t1);
119         towerOptions[2] = new char[strlen(t2)];
120         strcpy(towerOptions[2], t2);
121         towerOptions[3] = NULL;
122         
123         approachOptions[0] = new char[strlen(a0)];
124         strcpy(approachOptions[0], a0);
125         approachOptions[1] = NULL;
126
127         atcDialog = new puDialogBox (150, 50);
128         {
129                 atcDialogFrame   = new puFrame (0, 0, 500, 250);
130                 
131                 atcDialogMessage = new puText          (250, 220);
132                 atcDialogMessage    -> setDefaultValue (defaultATCLabel);
133                 atcDialogMessage    -> getDefaultValue (&s);
134                 atcDialogMessage    -> setLabel        (s);
135                 atcDialogMessage    -> setLabelPlace   (PUPLACE_TOP_CENTERED);
136
137                 atcDialogCommunicationOptions = new puButtonBox (50, 50, 450, 210, NULL, true);
138                 
139                 atcDialogOkButton     =  new puOneShot         (50, 10, 110, 50);
140                 atcDialogOkButton     ->     setLegend         (gui_msg_OK);
141                 atcDialogOkButton     ->     makeReturnDefault (TRUE);
142                 atcDialogOkButton     ->     setCallback       (ATCDialogOK);
143                 
144                 atcDialogCancelButton =  new puOneShot         (140, 10, 210, 50);
145                 atcDialogCancelButton ->     setLegend         (gui_msg_CANCEL);
146                 atcDialogCancelButton ->     setCallback       (ATCDialogCancel);
147                 
148         }
149         FG_FINALIZE_PUI_DIALOG(atcDialog);
150 }
151
152 // For the command manager - maybe eventually this should go in the built in command list
153 static bool do_ATC_dialog(const SGPropertyNode* arg) {
154         globals->get_ATC_mgr()->doStandardDialog();
155         return(true);
156 }
157
158
159 FGATCMgr::FGATCMgr() {
160         comm1_ident = "";
161         comm1_atis_ident = "";
162         comm1_tower_ident = "";
163         comm1_approach_ident = "";
164         last_comm1_ident = "";
165         last_comm1_atis_ident = "";
166         last_comm1_tower_ident = "";
167         last_comm1_approach_ident = "";
168         approach_ident = "";
169         last_in_range = false;
170         comm1_atis_valid = false;
171         comm1_tower_valid = false;
172         comm1_approach_valid = false;
173         comm1_type = INVALID;
174         tuned_atc_ptr = NULL;
175 }
176
177 FGATCMgr::~FGATCMgr() {
178 }
179
180 void FGATCMgr::bind() {
181 }
182
183 void FGATCMgr::unbind() {
184 }
185
186 void FGATCMgr::init() {
187         comm1_node = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
188         comm2_node = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
189         lon_node = fgGetNode("/position/longitude-deg", true);
190         lat_node = fgGetNode("/position/latitude-deg", true);
191         elev_node = fgGetNode("/position/altitude-ft", true);
192         atc_list_itr = atc_list.begin();
193         // Search for connected ATC stations once per 0.8 seconds or so
194         // global_events.Register( "fgATCSearch()", fgATCSearch,
195         //                  fgEVENT::FG_EVENT_READY, 800);
196         // For some reason the above doesn't compile - including Time/event.hxx stops compilation.
197         
198         // Initialise the airport_atc_map - we'll cheat for now and just hardcode KEMT and any others that may be needed for development
199         AirportATC *a = new AirportATC;
200         a->lon = -118.034719;
201         a->lat = 34.086114;
202         a->elev = 296.0;
203         a->atis_freq = 118.75;
204         a->atis_active = false;
205         a->tower_freq = 121.2;
206         a->tower_active = false;
207         a->ground_freq = 125.9;
208         a->ground_active = false;
209         
210         //a->set_by_AI = true;
211         //a->set_by_comm_search = false;
212         
213         airport_atc_map[(string)"KEMT"] = a;
214
215 #ifdef ENABLE_AUDIO_SUPPORT     
216         // Load all available voices.
217         // For now we'll do one hardwired one
218         voiceOK = v1.LoadVoice("default");
219         /* I've loaded the voice even if /sim/sound/audible is false
220         *  since I know no way of forcing load of the voice if the user
221         *  subsequently switches /sim/sound/audible to true. */
222 #else
223         voice = false;
224 #endif
225
226         // Initialise the ATC Dialogs
227         ATCDialogInit();
228         
229         // Add ATC-dialog to the command list
230         globals->get_commands()->addCommand("ATC-dialog", do_ATC_dialog);
231 }
232
233 void FGATCMgr::update(double dt) {
234         //Traverse the list of active stations.
235         //Only update one class per update step to avoid the whole ATC system having to calculate between frames.
236         //Eventually we should only update every so many steps.
237         //cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
238         if(atc_list.size()) {
239                 if(atc_list_itr == atc_list.end()) {
240                         atc_list_itr = atc_list.begin();
241                 }
242                 (*atc_list_itr)->Update();
243                 ++atc_list_itr;
244         }
245         
246         // Search the tuned frequencies every now and then - this should be done with the event scheduler
247         static int i = 0;
248         if(i == 30) {
249                 Search();
250                 i = 0;
251         }
252         ++i;
253 }
254 /*
255 // Remove from list only if not needed by the AI system
256 void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp) {
257         AirportATC a;
258         if(GetAirportATCDetails((string)id, &a)) {
259                 if(a.set_by_AI) {
260                         // Don't remove
261                         a.set_by_comm_search = false;
262                         airport_atc_map[(string)id] = a;
263                         return;
264                 } else {
265                         // remove
266                 }
267         }
268 }
269 */    
270
271 // Remove from list - should only be called from above or similar
272 void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
273         //cout << "Requested type = " << tp << '\n';
274         //cout << "id = " << id << '\n';
275         atc_list_itr = atc_list.begin();
276         while(atc_list_itr != atc_list.end()) {
277                 //cout << "type = " << (*atc_list_itr)->GetType() << '\n';
278                 //cout << "Ident = " << (*atc_list_itr)->GetIdent() << '\n';
279                 if( (!strcmp((*atc_list_itr)->GetIdent(), id))
280                         && ((*atc_list_itr)->GetType() == tp) ) {
281                                 //Before removing it stop it transmitting!!
282                                 //cout << "OBLITERATING FROM LIST!!!\n";
283                                 (*atc_list_itr)->SetNoDisplay();
284                                 (*atc_list_itr)->Update();
285                                 delete (*atc_list_itr);
286                                 atc_list_itr = atc_list.erase(atc_list_itr);
287                                 break;
288                         }  // Note that that can upset where we are in the list but that doesn't really matter
289                 ++atc_list_itr;
290         }
291 }
292
293
294 //DCL - this routine untested so far.
295 // Find in list - return a currently active ATC pointer given ICAO code and type
296 FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
297         atc_list_itr = atc_list.begin();
298         while(atc_list_itr != atc_list.end()) {
299                 if( (!strcmp((*atc_list_itr)->GetIdent(), id))
300                         && ((*atc_list_itr)->GetType() == tp) ) {
301                                 return(*atc_list_itr);
302                         }       // Note that that can upset where we are in the list but that shouldn't really matter
303                 ++atc_list_itr;
304         }
305         // We need a fallback position
306         SG_LOG(SG_GENERAL, SG_ALERT, "*** Failed to find FGATC* in FGATCMgr::FindInList - this should not happen!");
307         return(NULL);
308 }
309
310 // Returns true if the airport is found in the map
311 bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
312         if(airport_atc_map.find(icao) != airport_atc_map.end()) {
313                 *a = *airport_atc_map[icao];
314                 return(true);
315         } else {
316                 return(false);
317         }
318 }
319
320
321 // Return a pointer to a given sort of ATC at a given airport and activate if necessary
322 // ONLY CALL THIS FUNCTION AFTER FIRST CHECKING THE SERVICE EXISTS BY CALLING GetAirportATCDetails
323 // FIXME - we really ought to take out the necessity for two function calls by simply returning
324 // a NULL pointer if the service doesn't exist and requiring the caller to check for it (NULL).
325 FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
326         AirportATC *a = airport_atc_map[icao];
327         //cout << "a->lon = " << a->lon << '\n';
328         //cout << "a->elev = " << a->elev << '\n';
329         //cout << "a->tower_freq = " << a->tower_freq << '\n';
330         switch(type) {
331                 case TOWER:
332                 if(a->tower_active) {
333                         // Get the pointer from the list
334                         return(FindInList(icao.c_str(), type)); // DCL - this untested so far.
335                 } else {
336                         FGTower* t = new FGTower;
337                         if(current_towerlist->query(a->lon, a->lat, a->elev, a->tower_freq, &tower)) {
338                                 *t = tower;
339                                 atc_list.push_back(t);
340                                 a->tower_active = true;
341                                 airport_atc_map[icao] = a;
342                                 return(t);
343                         } else {
344                                 cout << "ERROR - tower that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found\n";
345                         }
346                 }
347                 break;
348                 // Lets add the rest to get rid of the compiler warnings even though we don't need them yet.
349                 case APPROACH:
350                 break;
351                 case ATIS:
352                 SG_LOG(SG_GENERAL, SG_ALERT, "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer");
353                 break;
354                 case GROUND:
355                 break;
356                 case INVALID:
357                 break;
358                 case ENROUTE:
359                 break;
360                 case DEPARTURE:
361                 break;
362         }
363         
364         SG_LOG(SG_GENERAL, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
365         
366         return(NULL);
367 }
368
369
370 // Render a transmission
371 // Outputs the transmission either on screen or as audio depending on user preference
372 // The repeating flag indicates whether the message should be repeated continuously or played once.
373 void FGATCMgr::Render(string msg, bool repeating) {
374 #ifdef ENABLE_AUDIO_SUPPORT
375         voice = voiceOK && fgGetBool("/sim/sound/audible");
376         if(voice) {
377                 int len;
378                 unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice);
379                 if(voice) {
380                         FGSimpleSound* simple = new FGSimpleSound(buf, len);
381                         simple->set_volume(2.0);
382                         globals->get_soundmgr()->add(simple, refname);
383                         if(repeating) {
384                                 globals->get_soundmgr()->play_looped(refname);
385                         } else {
386                                 globals->get_soundmgr()->play_once(refname);
387                         }
388                 }
389                 delete[] buf;
390         }
391 #endif  // ENABLE_AUDIO_SUPPORT
392         if(!voice) {
393                 // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
394                 for(unsigned int i = 0; i < msg.length(); ++i) {
395                         if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
396                                 msg[i] = ' ';
397                         }
398                 }
399                 globals->get_ATC_display()->RegisterRepeatingMessage(msg);
400         }
401         playing = true; 
402 }
403
404
405 // Cease rendering a transmission.
406 // At the moment this can handle one transmission active at a time only.
407 void FGATCMgr::NoRender() {
408         if(playing) {
409                 if(voice) {
410 #ifdef ENABLE_AUDIO_SUPPORT             
411                         globals->get_soundmgr()->stop(refname);
412                         globals->get_soundmgr()->remove(refname);
413 #endif
414                 } else {
415                         globals->get_ATC_display()->CancelRepeatingMessage();
416                 }
417                 playing = false;
418         }
419 }
420
421
422 // Display a dialog box with options relevant to the currently tuned ATC service.
423 void FGATCMgr::doStandardDialog() {
424         /* DCL 2002/12/06 - This function currently in development 
425            and dosen't display anything usefull to the end-user */
426         //cout << "FGATCMgr::doStandardDialog called..." << endl;
427         
428         // First - need to determine which ATC service (if any) the user is tuned to.
429         //cout << "comm1_type = " << comm1_type << endl;
430         
431         // Second - customise the dialog box
432         switch(comm1_type) {
433         case INVALID:
434                 atcDialogCommunicationOptions->newList(NULL);
435                 atcDialogMessage->setLabel("Not tuned in to any ATC service.");
436                 break;
437         case ATIS:
438                 atcDialogCommunicationOptions->newList(NULL);
439                 atcDialogMessage->setLabel("Tuned in to ATIS: no communication possible.");
440                 break;
441         case TOWER: 
442                 atcDialogCommunicationOptions->newList(towerOptions);
443                 atcDialogMessage->setLabel("Tuned in to Tower - select communication to transmit:");
444                 break;
445         case GROUND:
446                 atcDialogCommunicationOptions->newList(NULL);
447                 atcDialogMessage->setLabel("Tuned in to Ground - select communication to transmit:");
448                 break;
449         case APPROACH:
450                 atcDialogCommunicationOptions->newList(approachOptions);
451                 atcDialogMessage->setLabel("Tuned in to Approach - select communication to transmit:");
452                 break;
453         default:
454                 atcDialogCommunicationOptions->newList(NULL);
455                 atcDialogMessage->setLabel("Tuned in to unknown ATC service - enter transmission:");
456                 break;
457         }
458         
459         // Third - display the dialog without pausing sim.
460         ATCDialog(NULL);
461         
462         // Forth - need to direct input back from the dialog to the relevant ATC service.
463         // This is in ATCDialogOK()
464 }
465
466 void FGATCMgr::Search() {
467         
468         ////////////////////////////////////////////////////////////////////////
469         // Comm1.
470         ////////////////////////////////////////////////////////////////////////
471         //cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
472         
473         comm1_freq = comm1_node->getDoubleValue();
474         //cout << "************* comm1_freq = " << comm1_freq << '\n';
475         double lon = lon_node->getDoubleValue();
476         double lat = lat_node->getDoubleValue();
477         double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
478         
479         // Store the comm1_type
480         //atc_type old_comm1_type = comm1_type;
481         
482         // We must be able to generalise some of the repetetive searching below!
483         
484         //Search for ATIS first
485         if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
486                 //cout << "atis found in radiostack search !!!!" << endl;
487                 //cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
488                 //cout << "comm1_type " << comm1_type << '\n';
489                 comm1_atis_ident = atis.GetIdent();
490                 comm1_atis_valid = true;
491                 if(last_comm1_atis_ident != comm1_atis_ident) {
492                         if(last_comm1_atis_ident != "") {
493                                 RemoveFromList(last_comm1_atis_ident, ATIS);
494                         }
495                         last_comm1_atis_ident = comm1_atis_ident;
496                         //cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
497                         comm1_type = ATIS;
498                         comm1_elev = atis.get_elev();
499                         comm1_range = FG_ATIS_DEFAULT_RANGE;
500                         comm1_effective_range = comm1_range;
501                         comm1_x = atis.get_x();
502                         comm1_y = atis.get_y();
503                         comm1_z = atis.get_z();
504                         FGATIS* a = new FGATIS;
505                         *a = atis;
506                         tuned_atc_ptr = a;
507                         a->SetDisplay();
508                         atc_list.push_back(a);
509                         //cout << "Found a new atis station in range" << endl;
510                         //cout << " id = " << atis.GetIdent() << endl;
511                         return;  //This rather assumes that we never have more than one type of station in range.
512                 }
513         } else {
514                 if(comm1_atis_valid) {
515                         //cout << "Removing ATIS " << comm1_atis_ident << " from list\n";
516                         RemoveFromList(comm1_atis_ident, ATIS);
517                         comm1_atis_valid = false;
518                         if(comm1_type == ATIS) {
519                                 comm1_type = INVALID;
520                         }
521                         comm1_atis_ident = "";
522                         //comm1_trans_ident = "";
523                         last_comm1_atis_ident = "";
524                         tuned_atc_ptr = NULL;
525                 }
526                 //cout << "not picking up atis" << endl;
527         }
528         
529         //Next search for tower
530         //cout << "comm1_freq = " << comm1_freq << '\n';
531         if(current_towerlist->query(lon, lat, elev, comm1_freq, &tower)) {
532                 //cout << "tower found in radiostack search !!!!" << endl;
533                 comm1_tower_ident = tower.GetIdent();
534                 //cout << "comm1_tower_ident = " << comm1_tower_ident << '\n';
535                 comm1_tower_valid = true;
536                 if(last_comm1_tower_ident != comm1_tower_ident) {
537                         if(last_comm1_tower_ident != "") {
538                                 RemoveFromList(last_comm1_tower_ident, TOWER);
539                         }
540                         last_comm1_tower_ident = comm1_tower_ident;
541                         comm1_type = TOWER;
542                         comm1_elev = tower.get_elev();
543                         comm1_range = FG_TOWER_DEFAULT_RANGE;
544                         comm1_effective_range = comm1_range;
545                         comm1_x = tower.get_x();
546                         comm1_y = tower.get_y();
547                         comm1_z = tower.get_z();
548                         FGTower* t = new FGTower;
549                         *t = tower;
550                         tuned_atc_ptr = t;
551                         t->SetDisplay();
552                         atc_list.push_back(t);
553                         //cout << "Found a new tower station in range" << endl;
554                         //cout << " id = " << tower.GetIdent() << endl;
555                         return;  //This rather assumes that we never have more than one type of station in range.
556                 }
557         } else {
558                 if(comm1_tower_valid) {
559                         //cout << "removing tower\n";
560                         RemoveFromList(comm1_tower_ident, TOWER);
561                         //comm1_valid = false;
562                         if(comm1_type == TOWER) {
563                                 comm1_type = INVALID;   // Only invalidate if we haven't switched it to something else
564                         }
565                         comm1_tower_valid = false;
566                         comm1_tower_ident = "";
567                         last_comm1_tower_ident = "";
568                         tuned_atc_ptr = NULL;
569                         //comm1_ident = "";
570                         //comm1_trans_ident = "";
571                         //last_comm1_ident = "";
572                 }
573                 //cout << "not picking up tower" << endl;
574         }
575         /*
576         //Next search for Ground control
577         if(current_groundlist->query(lon, lat, elev, comm1_freq, &ground)) {
578                 //cout << "Ground Control found in radiostack search !!!!" << endl;
579                 comm1_ident = ground.GetIdent();
580                 comm1_valid = true;
581                 if((last_comm1_ident != comm1_ident) || (comm1_type != GROUND)) {
582                         if(last_comm1_ident != "") {
583                                 RemoveFromList(last_comm1_ident, GROUND);
584                         }
585                         last_comm1_ident = comm1_ident;
586                         comm1_type = GROUND;
587                         comm1_elev = ground.get_elev();
588                         comm1_range = FG_GROUND_DEFAULT_RANGE;
589                         comm1_effective_range = comm1_range;
590                         comm1_x = ground.get_x();
591                         comm1_y = ground.get_y();
592                         comm1_z = ground.get_z();
593                         FGGround* g = new FGGround;
594                         *g = ground;
595                         g->SetDisplay();
596                         atc_list.push_back(g);
597                         // For now we will automatically make contact with ground when the radio is tuned.
598                         // This rather assumes that the user tunes the radio at the appropriate place
599                         // (ie. having just turned off the runway) and only uses ground control on arrival
600                         // but its a start!
601                         g->NewArrival(current_plane);
602                         //cout << "Found a new ground station in range" << endl;
603                         //cout << " id = " << ground.GetIdent() << endl;
604                         return;  //This rather assumes that we never have more than one type of station in range.
605                 }
606         } else {
607                 if((comm1_valid) && (comm1_type == GROUND)) {
608                         RemoveFromList(comm1_ident, GROUND);
609                         comm1_valid = false;
610                         comm1_type = INVALID;
611                         comm1_ident = "";
612                         //comm1_trans_ident = "";
613                         last_comm1_ident = "";
614                 }
615                 //cout << "not picking up ground control" << endl;
616         }
617         */
618         // ================================================================================
619         // Search for Approach stations
620         // ================================================================================
621         // init number of approach stations reachable by plane
622         int  num_app = 0;
623         
624         // search stations in range
625         current_approachlist->query_bck(lon, lat, elev, approaches, max_app, num_app);
626         if (num_app != 0) {
627                 //cout << num_app << " approaches found in radiostack search !!!!" << endl;
628                 
629                 for ( int i=0; i<num_app; i++ ) {
630                         bool new_app = true;
631                         approach_ident = approaches[i].GetIdent();
632                         
633                         // check if station already exists on ATC stack
634                         atc_list_itr = atc_list.begin();
635                         while(atc_list_itr != atc_list.end()) {
636                                 //cout << "ATC list: " << (*atc_list_itr)->GetIdent() << endl;
637                                 if((!strcmp((*atc_list_itr)->GetIdent(), approach_ident))
638                                         && ((*atc_list_itr)->GetType() == APPROACH) ) {
639                                                 new_app = false;
640                                                 string pid = "Player";
641                                                 (*atc_list_itr)->AddPlane(pid);
642                                                 (*atc_list_itr)->Update();
643                                                 break;
644                                         }
645                                 ++atc_list_itr;
646                         }
647                         // generate new Approach on ATC stack
648                         if (new_app) {
649                                 FGApproach* a = new FGApproach;
650                                 *a = approaches[i];
651                                 string pid = "Player";
652                                 a->AddPlane(pid);
653                                 a->Update();
654                                 a->SetDisplay();
655                                 tuned_atc_ptr = a;
656                                 atc_list.push_back(a);
657                                 //cout << "Found a new approach station in range: Id = " 
658                                 //     << approaches[i].GetIdent() << endl;
659                         }
660                 }
661         }
662         
663         // remove planes which are out of range
664         atc_list_itr = atc_list.begin();
665         while(atc_list_itr != atc_list.end()) {
666                 if((*atc_list_itr)->GetType() == APPROACH ) {
667                         int np = (*atc_list_itr)->RemovePlane();
668                         // if approach has no planes left remove it from ATC list
669                         if ( np == 0) {
670                                 (*atc_list_itr)->SetNoDisplay();
671                                 (*atc_list_itr)->Update();
672                                 delete (*atc_list_itr);
673                                 atc_list_itr = atc_list.erase(atc_list_itr);
674                                 break;     // the other stations will be checked next time
675                         }
676                 }
677                 ++atc_list_itr;
678         }
679 }