1 // ATCMgr.hxx - definition of FGATCMgr
2 // - a global management class for FlightGear generated ATC
4 // Written by David Luff, started February 2002.
6 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _FG_ATCMGR_HXX
23 #define _FG_ATCMGR_HXX
25 #include <Main/fgfs.hxx>
26 #include <Main/fg_props.hxx>
35 #include "approach.hxx"
38 #include "ATCVoice.hxx"
39 #include "transmissionlist.hxx"
45 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
46 // These can then be cross referenced with the commlists which are stored by frequency or bucket.
47 // Non-available services are denoted by a frequency of zero.
48 // These structures are only intended to be created for in-use airports, and removed when no longer needed.
61 //float approach_freq;
62 //bool approach_active;
63 //float departure_freq;
64 //bool departure_active;
66 // NOTE - the *_active flags determine whether the service is active in atc_list,
67 // *NOT* whether the tower etc is closed or not!!!!
69 // Flags to ensure the stations don't get wrongly deactivated
70 bool set_by_AI; // true when the AI manager has activated this station
71 unsigned int numAI; // Ref count of the number of AI planes registered
72 bool set_by_comm[2]; // true when the relevant comm_freq has activated this station
75 class FGATCMgr : public FGSubsystem
80 bool initDone; // Hack - guard against update getting called before init
82 // A map of airport ID vs frequencies and ATC provision
83 typedef map < string, AirportATC* > airport_atc_map_type;
84 typedef airport_atc_map_type::iterator airport_atc_map_iterator;
85 typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
87 airport_atc_map_type airport_atc_map;
88 airport_atc_map_iterator airport_atc_map_itr;
90 // A list of pointers to all currently active ATC classes
91 typedef list <FGATC*> atc_list_type;
92 typedef atc_list_type::iterator atc_list_iterator;
93 typedef atc_list_type::const_iterator atc_list_const_iterator;
95 // Everything put in this list should be created dynamically
96 // on the heap and ***DELETED WHEN REMOVED!!!!!***
97 atc_list_type atc_list;
98 atc_list_iterator atc_list_itr;
99 // Any member function of FGATCMgr is permitted to leave this iterator pointing
100 // at any point in or at the end of the list.
101 // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
103 // Position of the Users Aircraft
108 // Type of ATC control that the user's radios are tuned to.
109 atc_type comm_type[2];
111 // Pointer to the ATC station that the user is currently tuned into.
112 FGATC* comm_atc_ptr[2];
116 // Pointers to users current communication frequencies.
117 SGPropertyNode* comm_node[2];
119 // Pointers to current users position
120 SGPropertyNode* lon_node;
121 SGPropertyNode* lat_node;
122 SGPropertyNode* elev_node;
124 // Position of the ATC that the comm radios are tuned to in order to decide
125 // whether transmission will be received.
126 double comm_x[2], comm_y[2], comm_z[2], comm_lon[2], comm_lat[2], comm_elev[2];
128 double comm_range[2], comm_effective_range[2];
130 const char* comm_ident[2];
131 const char* last_comm_ident[2];
133 const char* approach_ident;
140 //FGDeparture departure;
142 // Voice related stuff
143 bool voice; // Flag - true if we are using voice
144 #ifdef ENABLE_AUDIO_SUPPORT
145 bool voiceOK; // Flag - true if at least one voice has loaded OK
160 void update(double dt);
162 // Returns true if the airport is found in the map
163 bool GetAirportATCDetails(string icao, AirportATC* a);
165 // Return a pointer to a given sort of ATC at a given airport and activate if necessary
166 // Returns NULL if service doesn't exist - calling function should check for this.
167 FGATC* GetATCPointer(string icao, atc_type type);
169 // Display a dialog box with options relevant to the currently tuned ATC service.
170 void doPopupDialog();
172 // Return a pointer to an appropriate voice for a given type of ATC
173 // creating the voice if necessary - ie. make sure exactly one copy
174 // of every voice in use exists in memory.
176 // TODO - in the future this will get more complex and dole out country/airport
177 // specific voices, and possible make sure that the same voice doesn't get used
178 // at different airports in quick succession if a large enough selection are available.
179 FGATCVoice* GetVoicePointer(atc_type type);
181 atc_type GetComm1ATCType() { return(comm_type[0]); }
182 FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); }
183 atc_type GetComm2ATCType() { return(comm_type[1]); }
184 FGATC* GetComm2ATCPointer() { return(comm_atc_ptr[1]); }
186 // Get the frequency of a given service at a given airport
187 // Returns zero if not found
188 unsigned short int GetFrequency(string ident, atc_type tp);
190 // Register the fact that the AI system wants to activate an airport
191 bool AIRegisterAirport(string ident);
193 // Register the fact that the comm radio is tuned to an airport
194 bool CommRegisterAirport(string ident, int chan);
198 // Remove a class from the atc_list and delete it from memory
199 // *if* no other comm channel or AI plane is using it.
200 void CommRemoveFromList(const char* id, atc_type tp, int chan);
202 // Remove a class from the atc_list and delete it from memory
203 // Should be called from the above - not directly!!
204 void RemoveFromList(const char* id, atc_type tp);
206 // Return a pointer to a class in the list given ICAO code and type
207 // (external interface to this is through GetATCPointer)
208 // Return NULL if the given service is not in the list
209 // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
210 FGATC* FindInList(const char* id, atc_type tp);
212 // Search the specified channel for stations on the same frequency and in range.
213 void FreqSearch(int channel);
215 // Search ATC stations by area in order that we appear 'on the radar'
220 #endif // _FG_ATCMGR_HXX