]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.cxx
Fix a problem where older IRIX compilers needed a typecast for certain opperations
[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 <simgear/misc/sg_path.hxx>
22 #include <simgear/debug/logstream.hxx>
23 #include <Airports/simple.hxx>
24
25 #include "ATCmgr.hxx"
26 #include "commlist.hxx"
27 #include "ATCdisplay.hxx"
28 #include "ATCDialog.hxx"
29 #include "ATCutils.hxx"
30
31 /*
32 // periodic radio station search wrapper
33 static void fgATCSearch( void ) {
34         globals->get_ATC_mgr()->Search();
35 }
36 */ //This wouldn't compile - including Time/event.hxx breaks it :-(
37    // Is this still true?? -EMH-
38
39 AirportATC::AirportATC() :
40     lon(0.0),
41     lat(0.0),
42     elev(0.0),
43     atis_freq(0.0),
44     atis_active(false),
45     tower_freq(0.0),
46     tower_active(false),
47     ground_freq(0.0),
48     ground_active(false),
49     set_by_AI(false),
50         numAI(0)
51 {
52         for(int i=0; i<ATC_NUM_TYPES; ++i) {
53                 set_by_comm[0][i] = false;
54                 set_by_comm[1][i] = false;
55         }
56 }
57
58 FGATCMgr::FGATCMgr() {
59         comm_ident[0] = "";
60         comm_ident[1] = "";
61         last_comm_ident[0] = "";
62         last_comm_ident[1] = "";
63         approach_ident = "";
64         last_in_range = false;
65         comm_type[0] = INVALID;
66         comm_type[1] = INVALID;
67         comm_atc_ptr[0] = NULL;
68         comm_atc_ptr[1] = NULL;
69         comm_valid[0] = false;
70         comm_valid[1] = false;
71         
72         initDone = false;
73 }
74
75 FGATCMgr::~FGATCMgr() {
76         delete v1;
77 }
78
79 void FGATCMgr::bind() {
80 }
81
82 void FGATCMgr::unbind() {
83 }
84
85 void FGATCMgr::init() {
86         comm_node[0] = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
87         comm_node[1] = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
88         lon_node = fgGetNode("/position/longitude-deg", true);
89         lat_node = fgGetNode("/position/latitude-deg", true);
90         elev_node = fgGetNode("/position/altitude-ft", true);
91         atc_list_itr = atc_list.begin();
92         
93         // Search for connected ATC stations once per 0.8 seconds or so
94         // globals->get_event_mgr()->add( "fgATCSearch()", fgATCSearch,
95         //                                 FGEvent::FG_EVENT_READY, 800);
96         //  
97         // For some reason the above doesn't compile - including Time/event.hxx stops compilation.
98         // Is this still true after the reorganization of the event managar??
99         // -EMH-
100         
101         // Initialise the frequency search map
102     current_commlist = new FGCommList;
103     SGPath p_comm( globals->get_fg_root() );
104     current_commlist->init( p_comm );
105
106 #ifdef ENABLE_AUDIO_SUPPORT     
107         // Load all available voices.
108         // For now we'll do one hardwired one
109         
110         v1 = new FGATCVoice;
111         voiceOK = v1->LoadVoice("default");
112         voice = true;
113         
114         /* I've loaded the voice even if /sim/sound/audible is false
115         *  since I know no way of forcing load of the voice if the user
116         *  subsequently switches /sim/sound/audible to true. */
117 #else
118         voice = false;
119 #endif
120
121         // Initialise the ATC Dialogs
122         //cout << "Initing Transmissions..." << endl;
123     SG_LOG(SG_ATC, SG_INFO, "  ATC Transmissions");
124     current_transmissionlist = new FGTransmissionList;
125     SGPath p_transmission( globals->get_fg_root() );
126     p_transmission.append( "ATC/default.transmissions" );
127     current_transmissionlist->init( p_transmission );
128         //cout << "Done Transmissions" << endl;
129
130     SG_LOG(SG_ATC, SG_INFO, "  ATC Dialog System");
131     current_atcdialog = new FGATCDialog;
132     current_atcdialog->Init();
133
134         ATCDialogInit();
135         
136         // DCL - testing
137         //current_atcdialog->add_entry( "EGNX", "Request vectoring for approach", "Request Vectors" );
138         //current_atcdialog->add_entry( "EGNX", "Mayday, Mayday", "Declare Emergency" );
139         
140         initDone = true;
141 }
142
143 void FGATCMgr::update(double dt) {
144         if(!initDone) {
145                 init();
146                 SG_LOG(SG_ATC, SG_WARN, "Warning - ATCMgr::update(...) called before ATCMgr::init()");
147         }
148         
149         //cout << "Entering update..." << endl;
150         //Traverse the list of active stations.
151         //Only update one class per update step to avoid the whole ATC system having to calculate between frames.
152         //Eventually we should only update every so many steps.
153         //cout << "In FGATCMgr::update - atc_list.size = " << atc_list.size() << '\n';
154         if(atc_list.size()) {
155                 if(atc_list_itr == atc_list.end()) {
156                         atc_list_itr = atc_list.begin();
157                 }
158                 //cout << "Updating " << (*atc_list_itr)->get_ident() << ' ' << (*atc_list_itr)->GetType() << '\n';
159                 //cout << "Freq = " << (*atc_list_itr)->get_freq() << '\n';
160                 (*atc_list_itr)->Update(dt * atc_list.size());
161                 //cout << "Done ATC update..." << endl;
162                 ++atc_list_itr;
163         }
164         
165         // Search the tuned frequencies every now and then - this should be done with the event scheduler
166         static int i = 0;       // Very ugly - but there should only ever be one instance of FGATCMgr.
167         /*
168         if(i == 7) {
169                 //cout << "About to AreaSearch()" << endl;
170                 AreaSearch();
171         }
172         */
173         if(i == 15) {
174                 //cout << "About to search(1)" << endl;
175                 FreqSearch(1);
176         }
177         if(i == 30) {
178                 //cout << "About to search(2)" << endl;
179                 FreqSearch(2);
180                 i = 0;
181         }
182         ++i;
183         
184         //cout << "comm1 type = " << comm_type[0] << '\n';
185         //cout << "Leaving update..." << endl;
186 }
187
188
189 // Returns frequency in KHz - should I alter this to return in MHz?
190 unsigned short int FGATCMgr::GetFrequency(string ident, atc_type tp) {
191         ATCData test;
192         bool ok = current_commlist->FindByCode(ident, test, tp);
193         return(ok ? test.freq : 0);
194 }       
195
196
197 // Register the fact that the AI system wants to activate an airport
198 // Might need more sophistication in this in the future - eg registration by aircraft call-sign.
199 bool FGATCMgr::AIRegisterAirport(string ident) {
200         SG_LOG(SG_ATC, SG_BULK, "AI registered airport " << ident << " with the ATC system");
201         if(airport_atc_map.find(ident) != airport_atc_map.end()) {
202                 airport_atc_map[ident]->set_by_AI = true;
203                 airport_atc_map[ident]->numAI++;
204                 return(true);
205         } else {
206                 FGAirport ap;
207                 if(dclFindAirportID(ident, &ap)) {
208                         //cout << "ident = " << ident << '\n';
209                         AirportATC *a = new AirportATC;
210                         // I'm not entirely sure that this AirportATC structure business is actually needed - it just duplicates what we can find out anyway!
211                         a->lon = ap.longitude;
212                         a->lat = ap.latitude;
213                         a->elev = ap.elevation;
214                         a->atis_freq = GetFrequency(ident, ATIS);
215                         //cout << "ATIS freq = " << a->atis_freq << '\n';
216                         a->atis_active = false;
217                         a->tower_freq = GetFrequency(ident, TOWER);
218                         //cout << "Tower freq = " << a->tower_freq << '\n';
219                         a->tower_active = false;
220                         a->ground_freq = GetFrequency(ident, GROUND);
221                         //cout << "Ground freq = " << a->ground_freq << '\n';
222                         a->ground_active = false;
223                         // TODO - some airports will have a tower/ground frequency but be inactive overnight.
224                         a->set_by_AI = true;
225                         a->numAI = 1;
226                         airport_atc_map[ident] = a;
227                         return(true);
228                 }
229         }
230         return(false);
231 }
232
233
234 // Register the fact that the comm radio is tuned to an airport
235 // Channel is zero based
236 bool FGATCMgr::CommRegisterAirport(string ident, int chan, atc_type tp) {
237         SG_LOG(SG_ATC, SG_BULK, "Comm channel " << chan << " registered airport " << ident);
238         if(airport_atc_map.find(ident) != airport_atc_map.end()) {
239                 //cout << "IN MAP - flagging set by comm..." << endl;
240                 airport_atc_map[ident]->set_by_comm[chan][tp] = true;
241                 return(true);
242         } else {
243                 //cout << "NOT IN MAP - creating new..." << endl;
244                 FGAirport ap;
245                 if(dclFindAirportID(ident, &ap)) {
246                         AirportATC *a = new AirportATC;
247                         // I'm not entirely sure that this AirportATC structure business is actually needed - it just duplicates what we can find out anyway!
248                         a->lon = ap.longitude;
249                         a->lat = ap.latitude;
250                         a->elev = ap.elevation;
251                         a->atis_freq = GetFrequency(ident, ATIS);
252                         a->atis_active = false;
253                         a->tower_freq = GetFrequency(ident, TOWER);
254                         a->tower_active = false;
255                         a->ground_freq = GetFrequency(ident, GROUND);
256                         a->ground_active = false;
257                         // TODO - some airports will have a tower/ground frequency but be inactive overnight.
258                         a->set_by_AI = false;
259                         a->numAI = 0;
260                         a->set_by_comm[chan][tp] = true;                        
261                         airport_atc_map[ident] = a;
262                         return(true);
263                 }
264         }
265         return(false);
266 }
267
268
269 // Remove from list only if not needed by the AI system or the other comm channel
270 // Note that chan is zero based.
271 void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
272         SG_LOG(SG_ATC, SG_BULK, "CommRemoveFromList called for airport " << id << " " << tp << " by channel " << chan);
273         if(airport_atc_map.find(id) != airport_atc_map.end()) {
274                 AirportATC* a = airport_atc_map[id];
275                 //cout << "In CommRemoveFromList, a->ground_freq = " << a->ground_freq << endl;
276                 if(a->set_by_AI && tp != ATIS) {
277                         // Set by AI, so don't remove simply because user isn't tuned in any more - just stop displaying
278                         SG_LOG(SG_ATC, SG_BULK, "In CommRemoveFromList, service was set by AI\n");
279                         FGATC* aptr = GetATCPointer(id, tp);
280                         switch(chan) {
281                         case 0:
282                                 //cout << "chan 1\n";
283                                 a->set_by_comm[0][tp] = false;
284                                 if(!a->set_by_comm[1][tp]) {
285                                         //cout << "not set by comm2\n";
286                                         if(aptr != NULL) {
287                                                 //cout << "Got pointer\n";
288                                                 aptr->SetNoDisplay();
289                                                 //cout << "Setting no display...\n";
290                                         } else {
291                                                 //cout << "Not got pointer\n";
292                                         }
293                                 }
294                                 break;
295                         case 1:
296                                 a->set_by_comm[1][tp] = false;
297                                 if(!a->set_by_comm[0][tp]) {
298                                         if(aptr != NULL) {
299                                                 aptr->SetNoDisplay();
300                                                 //cout << "Setting no display...\n";
301                                         }
302                                 }
303                                 break;
304                         }
305                         airport_atc_map[id] = a;
306                         return;
307                 } else {
308                         switch(chan) {
309                         case 0:
310                                 a->set_by_comm[0][tp] = false;
311                                 // Remove only if not also set by the other comm channel
312                                 if(!a->set_by_comm[1][tp]) {
313                                         RemoveFromList(id, tp);
314                                 }
315                                 break;
316                         case 1:
317                                 a->set_by_comm[1][tp] = false;
318                                 if(!a->set_by_comm[0][tp]) {
319                                         RemoveFromList(id, tp);
320                                 }
321                                 break;
322                         }
323                 }
324         }
325 }
326     
327
328 // Remove from list - should only be called from above or similar
329 // This function *will* remove it from the list regardless of who else might want it.
330 void FGATCMgr::RemoveFromList(const char* id, atc_type tp) {
331         //cout << "Requested type = " << tp << '\n';
332         //cout << "id = " << id << '\n';
333         atc_list_itr = atc_list.begin();
334         while(atc_list_itr != atc_list.end()) {
335                 //cout << "type = " << (*atc_list_itr)->GetType() << '\n';
336                 //cout << "Ident = " << (*atc_list_itr)->get_ident() << '\n';
337                 if( (!strcmp((*atc_list_itr)->get_ident(), id))
338                         && ((*atc_list_itr)->GetType() == tp) ) {
339                                 //Before removing it stop it transmitting!!
340                                 //cout << "OBLITERATING FROM LIST!!!\n";
341                                 (*atc_list_itr)->SetNoDisplay();
342                                 (*atc_list_itr)->Update(0.00833);
343                                 delete (*atc_list_itr);
344                                 atc_list_itr = atc_list.erase(atc_list_itr);
345                                 break;
346                         }  // Note that that can upset where we are in the list but that doesn't really matter
347                 ++atc_list_itr;
348         }
349 }
350
351
352 // Find in list - return a currently active ATC pointer given ICAO code and type
353 // Return NULL if the given service is not in the list
354 // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
355 FGATC* FGATCMgr::FindInList(const char* id, atc_type tp) {
356         atc_list_itr = atc_list.begin();
357         while(atc_list_itr != atc_list.end()) {
358                 if( (!strcmp((*atc_list_itr)->get_ident(), id))
359                 && ((*atc_list_itr)->GetType() == tp) ) {
360                         return(*atc_list_itr);
361                 }       // Note that that can upset where we are in the list but that shouldn't really matter
362                 ++atc_list_itr;
363         }
364         // If we get here it's not in the list
365         return(NULL);
366 }
367
368 // Returns true if the airport is found in the map
369 bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
370         if(airport_atc_map.find(icao) != airport_atc_map.end()) {
371                 *a = *airport_atc_map[icao];
372                 return(true);
373         } else {
374                 return(false);
375         }
376 }
377
378
379 // Return a pointer to a given sort of ATC at a given airport and activate if necessary
380 // Returns NULL if service doesn't exist - calling function should check for this.
381 // We really ought to make this private and call it from the CommRegisterAirport / AIRegisterAirport functions
382 // - at the moment all these GetATC... functions exposed are just too complicated.
383 FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
384         if(airport_atc_map.find(icao) == airport_atc_map.end()) {
385                 return NULL;
386         }
387         AirportATC *a = airport_atc_map[icao];
388         //cout << "a->lon = " << a->lon << '\n';
389         //cout << "a->elev = " << a->elev << '\n';
390         //cout << "a->tower_freq = " << a->tower_freq << '\n';
391         switch(type) {
392         case TOWER:
393                 if(a->tower_active) {
394                         // Get the pointer from the list
395                         return(FindInList(icao.c_str(), type));
396                 } else {
397                         ATCData data;
398                         if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->tower_freq, &data, TOWER)) {
399                                 FGTower* t = new FGTower;
400                                 t->SetData(&data);
401                                 atc_list.push_back(t);
402                                 a->tower_active = true;
403                                 airport_atc_map[icao] = a;
404                                 t->Init();
405                                 return(t);
406                         } else {
407                                 SG_LOG(SG_ATC, SG_ALERT, "ERROR - tower that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found");
408                         }
409                 }
410                 break;
411         case APPROACH:
412                 break;
413         case ATIS:
414                 SG_LOG(SG_ATC, SG_ALERT, "ERROR - ATIS station should not be requested from FGATCMgr::GetATCPointer");
415                 break;
416         case GROUND:
417                 //cout << "IN CASE GROUND" << endl;
418                 if(a->ground_active) {
419                         // Get the pointer from the list
420                         return(FindInList(icao.c_str(), type));
421                 } else {
422                         ATCData data;
423                         if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->ground_freq, &data, GROUND)) {
424                                 FGGround* g = new FGGround;
425                                 g->SetData(&data);
426                                 atc_list.push_back(g);
427                                 a->ground_active = true;
428                                 airport_atc_map[icao] = a;
429                                 g->Init();
430                                 return(g);
431                         } else {
432                                 SG_LOG(SG_ATC, SG_ALERT, "ERROR - ground control that should exist in FGATCMgr::GetATCPointer for airport " << icao << " not found");
433                         }
434                 }
435                 break;
436                 case INVALID:
437                 break;
438                 case ENROUTE:
439                 break;
440                 case DEPARTURE:
441                 break;
442         }
443         
444         SG_LOG(SG_ATC, SG_ALERT, "ERROR IN FGATCMgr - reached end of GetATCPointer");
445         
446         return(NULL);
447 }
448
449 // Return a pointer to an appropriate voice for a given type of ATC
450 // creating the voice if necessary - ie. make sure exactly one copy
451 // of every voice in use exists in memory.
452 //
453 // TODO - in the future this will get more complex and dole out country/airport
454 // specific voices, and possible make sure that the same voice doesn't get used
455 // at different airports in quick succession if a large enough selection are available.
456 FGATCVoice* FGATCMgr::GetVoicePointer(atc_type type) {
457         // TODO - implement me better - maintain a list of loaded voices and other voices!!
458         if(voice) {
459                 switch(type) {
460                 case ATIS:
461                         if(voiceOK) {
462                                 return(v1);
463                         }
464                 case TOWER:
465                         return(NULL);
466                 case APPROACH:
467                         return(NULL);
468                 case GROUND:
469                         return(NULL);
470                 default:
471                         return(NULL);
472                 }
473                 return(NULL);
474         } else {
475                 return(NULL);
476         }
477 }
478
479 // Display a dialog box with options relevant to the currently tuned ATC service.
480 void FGATCMgr::doPopupDialog() {
481         ATCDoDialog(comm_type[0]);      // FIXME - currently hardwired to comm1
482 }
483
484 // Search for ATC stations by frequency
485 void FGATCMgr::FreqSearch(int channel) {
486         int chan = channel - 1;         // Convert to zero-based for the arrays
487
488         ATCData data;   
489         double freq = comm_node[chan]->getDoubleValue();
490         lon = lon_node->getDoubleValue();
491         lat = lat_node->getDoubleValue();
492         elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
493         
494         // Query the data store and get the closest match if any
495         if(current_commlist->FindByFreq(lon, lat, elev, freq, &data)) {
496                 // We have a match
497                 // What's the logic?
498                 // If this channel not previously valid then easy - add ATC to list
499                 // If this channel was valid then - Have we tuned to a different service?
500                 // If so - de-register one and add the other
501                 if(comm_valid[chan]) {
502                         if((comm_ident[chan] == data.ident) && (comm_type[chan] == data.type)) {
503                                 // Then we're still tuned into the same service so do nought and return
504                                 return;
505                         } else {
506                                 // Something's changed - either the location or the service type
507                                 // We need to feed the channel in so we're not removing it if we're also tuned in on the other channel
508                                 CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
509                         }
510                 }
511                 // At this point we can assume that we need to add the service.
512                 comm_ident[chan] = (data.ident).c_str();
513                 comm_type[chan] = data.type;
514                 comm_x[chan] = (double)data.x;
515                 comm_y[chan] = (double)data.y;
516                 comm_z[chan] = (double)data.z;
517                 comm_lon[chan] = (double)data.lon;
518                 comm_lat[chan] = (double)data.lat;
519                 comm_elev[chan] = (double)data.elev;
520                 comm_valid[chan] = true;
521                 
522                 // This was a switch-case statement but the compiler didn't like the new variable creation with it. 
523                 if(comm_type[chan] == ATIS) {
524                         CommRegisterAirport(comm_ident[chan], chan, ATIS);
525                         FGATC* app = FindInList(comm_ident[chan], ATIS);
526                         if(app != NULL) {
527                                 // The station is already in the ATC list
528                                 //cout << "In list - flagging SetDisplay..." << endl;
529                                 app->SetDisplay();
530                         } else {
531                                 // Generate the station and put in the ATC list
532                                 //cout << "Not in list - generating..." << endl;
533                                 FGATIS* a = new FGATIS;
534                                 a->SetData(&data);
535                                 comm_atc_ptr[chan] = a;
536                                 a->SetDisplay();
537                                 //a->Init();
538                                 atc_list.push_back(a);
539                         }
540                 } else if (comm_type[chan] == TOWER) {
541                         CommRegisterAirport(comm_ident[chan], chan, TOWER);
542                         //cout << "Done (TOWER)" << endl;
543                         FGATC* app = FindInList(comm_ident[chan], TOWER);
544                         if(app != NULL) {
545                                 // The station is already in the ATC list
546                                 //cout << "In list - flagging SetDisplay..." << endl;
547                                 app->SetDisplay();
548                         } else {
549                                 // Generate the station and put in the ATC list
550                                 //cout << "Not in list - generating..." << endl;
551                                 FGTower* t = new FGTower;
552                                 t->SetData(&data);
553                                 comm_atc_ptr[chan] = t;
554                                 t->SetDisplay();
555                                 t->Init();
556                                 atc_list.push_back(t);
557                         }
558                 }  else if (comm_type[chan] == GROUND) {
559                         CommRegisterAirport(comm_ident[chan], chan, GROUND);
560                         //cout << "Done (GROUND)" << endl;
561                         FGATC* app = FindInList(comm_ident[chan], GROUND);
562                         if(app != NULL) {
563                                 // The station is already in the ATC list
564                                 app->SetDisplay();
565                         } else {
566                                 // Generate the station and put in the ATC list
567                                 FGGround* g = new FGGround;
568                                 g->SetData(&data);
569                                 comm_atc_ptr[chan] = g;
570                                 g->SetDisplay();
571                                 g->Init();
572                                 atc_list.push_back(g);
573                         }
574                 } else if (comm_type[chan] == APPROACH) {
575                         // We have to be a bit more carefull here since approaches are also searched by area
576                         CommRegisterAirport(comm_ident[chan], chan, APPROACH);
577                         //cout << "Done (APPROACH)" << endl;
578                         FGATC* app = FindInList(comm_ident[chan], APPROACH);
579                         if(app != NULL) {
580                                 // The station is already in the ATC list
581                                 app->AddPlane("Player");
582                                 app->SetDisplay();
583                                 comm_atc_ptr[chan] = app;
584                         } else {
585                                 // Generate the station and put in the ATC list
586                                 FGApproach* a = new FGApproach;
587                                 a->SetData(&data);
588                                 comm_atc_ptr[chan] = a;
589                                 a->SetDisplay();
590                                 a->Init();
591                                 a->AddPlane("Player");
592                                 atc_list.push_back(a);
593                         }                       
594                 }
595         } else {
596                 if(comm_valid[chan]) {
597                         if(comm_type[chan] != APPROACH) {
598                                 // Currently approaches are removed by Alexander's out-of-range mechanism
599                                 CommRemoveFromList(comm_ident[chan], comm_type[chan], chan);
600                         }
601                         // Note that we *don't* call SetNoDisplay() here because the other comm channel
602                         // might be tuned into the same station - this is handled by CommRemoveFromList(...)
603                         comm_type[chan] = INVALID;
604                         comm_atc_ptr[chan] = NULL;
605                         comm_valid[chan] = false;
606                 }
607         }
608 }
609
610 // Search ATC stations by area in order that we appear 'on the radar'
611 void FGATCMgr::AreaSearch() {
612         // Search for Approach stations
613         comm_list_type approaches;
614         comm_list_iterator app_itr;
615         
616         lon = lon_node->getDoubleValue();
617         lat = lat_node->getDoubleValue();
618         elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
619         
620         // search stations in range
621         int num_app = current_commlist->FindByPos(lon, lat, elev, 100.0, &approaches, APPROACH);
622         if (num_app != 0) {
623                 //cout << num_app << " approaches found in radiostack search !!!!" << endl;
624                 
625                 for(app_itr = approaches.begin(); app_itr != approaches.end(); app_itr++) {
626                         
627                         FGATC* app = FindInList((app_itr->ident).c_str(), app_itr->type);
628                         if(app != NULL) {
629                                 // The station is already in the ATC list
630                                 //cout << "In list adding player\n";
631                                 app->AddPlane("Player");
632                                 //app->Update();
633                         } else {
634                                 // Generate the station and put in the ATC list
635                                 FGApproach* a = new FGApproach;
636                                 a->SetData(&(*app_itr));
637                                 //cout << "Adding player\n";
638                                 a->AddPlane("Player");
639                                 //a->Update();
640                                 atc_list.push_back(a);
641                         }
642                 }
643         }
644         
645         // remove planes which are out of range
646         // TODO - I'm not entirely sure that this belongs here.
647         atc_list_itr = atc_list.begin();
648         while(atc_list_itr != atc_list.end()) {
649                 if((*atc_list_itr)->GetType() == APPROACH ) {
650                         int np = (*atc_list_itr)->RemovePlane();
651                         // if approach has no planes left remove it from ATC list
652                         if ( np == 0) {
653                                 (*atc_list_itr)->SetNoDisplay();
654                                 (*atc_list_itr)->Update(0.00833);
655                                 delete (*atc_list_itr);
656                                 atc_list_itr = atc_list.erase(atc_list_itr);
657                                 break;     // the other stations will be checked next time
658                         }
659                 }
660                 ++atc_list_itr;
661         }
662 }