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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef _FG_ATCMGR_HXX
23 #define _FG_ATCMGR_HXX
25 #include <simgear/structure/subsystem_mgr.hxx>
27 #include <Main/fg_props.hxx>
40 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
41 // These can then be cross referenced with the commlists which are stored by frequency or bucket.
42 // Non-available services are denoted by a frequency of zero.
43 // These structures are only intended to be created for in-use airports, and removed when no longer needed.
54 //float approach_freq;
55 //bool approach_active;
56 //float departure_freq;
57 //bool departure_active;
59 // NOTE - the *_active flags determine whether the service is active in atc_list,
60 // *NOT* whether the tower etc is closed or not!!!!
62 // Flags to ensure the stations don't get wrongly deactivated
63 bool set_by_AI; // true when the AI manager has activated this station
64 unsigned int numAI; // Ref count of the number of AI planes registered
65 //xx bool set_by_comm[2][ATC_NUM_TYPES]; // true when the relevant comm_freq has activated this station and type
68 class FGATCMgr : public SGSubsystem
73 bool initDone; // Hack - guard against update getting called before init
75 // A map of airport ID vs frequencies and ATC provision
76 typedef map < string, AirportATC* > airport_atc_map_type;
77 typedef airport_atc_map_type::iterator airport_atc_map_iterator;
78 typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
80 airport_atc_map_type airport_atc_map;
81 airport_atc_map_iterator airport_atc_map_itr;
83 // A list of pointers to all currently active ATC classes
84 typedef map<string,FGATC*> atc_list_type;
85 typedef atc_list_type::iterator atc_list_iterator;
86 typedef atc_list_type::const_iterator atc_list_const_iterator;
88 // Everything put in this list should be created dynamically
89 // on the heap and ***DELETED WHEN REMOVED!!!!!***
90 atc_list_type* atc_list;
91 atc_list_iterator atc_list_itr;
92 // Any member function of FGATCMgr is permitted to leave this iterator pointing
93 // at any point in or at the end of the list.
94 // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
96 // Position of the Users Aircraft
99 // Pointers to current users position
100 SGPropertyNode_ptr lon_node;
101 SGPropertyNode_ptr lat_node;
102 SGPropertyNode_ptr elev_node;
104 //string approach_ident;
111 // Voice related stuff
112 bool voice; // Flag - true if we are using voice
113 #ifdef ENABLE_AUDIO_SUPPORT
114 bool voiceOK; // Flag - true if at least one voice has loaded OK
129 void update(double dt);
131 // Returns true if the airport is found in the map
132 bool GetAirportATCDetails(const string& icao, AirportATC* a);
134 // Return a pointer to a given sort of ATC at a given airport and activate if necessary
135 // Returns NULL if service doesn't exist - calling function should check for this.
136 FGATC* GetATCPointer(const string& icao, const atc_type& type);
138 // Return a pointer to an appropriate voice for a given type of ATC
139 // creating the voice if necessary - ie. make sure exactly one copy
140 // of every voice in use exists in memory.
142 // TODO - in the future this will get more complex and dole out country/airport
143 // specific voices, and possible make sure that the same voice doesn't get used
144 // at different airports in quick succession if a large enough selection are available.
145 FGATCVoice* GetVoicePointer(const atc_type& type);
147 atc_type GetComm1ATCType() { return(INVALID/* kludge */); }
148 FGATC* GetComm1ATCPointer() { return(0/* kludge */); }
149 atc_type GetComm2ATCType() { return(INVALID); }
150 FGATC* GetComm2ATCPointer() { return(0/* kludge */); }
152 // Get the frequency of a given service at a given airport
153 // Returns zero if not found
154 unsigned short int GetFrequency(const string& ident, const atc_type& tp);
156 // Register the fact that the comm radio is tuned to an airport
157 bool CommRegisterAirport(const string& ident, int chan, const atc_type& tp);
161 // Remove a class from the atc_list and delete it from memory
162 // *if* no other comm channel or AI plane is using it.
163 void ZapOtherService(const string ncunit, const string svc_name);
165 // Return a pointer to a class in the list given ICAO code and type
166 // (external interface to this is through GetATCPointer)
167 // Return NULL if the given service is not in the list
168 // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
169 FGATC* FindInList(const string& id, const atc_type& tp);
171 // Search the specified radio for stations on the same frequency and in range.
172 void FreqSearch(const string navcomm, const int unit);
175 #endif // _FG_ATCMGR_HXX