]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.hxx
Added FindByCode (airport ICAO code) to commlist. This is basically a wrapper around...
[flightgear.git] / src / ATC / ATCmgr.hxx
1 // ATCMgr.hxx - definition of FGATCMgr 
2 // - a global management class for FlightGear generated ATC
3 //
4 // Written by David Luff, started February 2002.
5 //
6 // Copyright (C) 2002  David C Luff - david.luff@nottingham.ac.uk
7 //
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.
12 //
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.
17 //
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.
21
22 #ifndef _FG_ATCMGR_HXX
23 #define _FG_ATCMGR_HXX
24
25 #include <Main/fgfs.hxx>
26 #include <Main/fg_props.hxx>
27 #include <GUI/gui.h>
28
29 #include <string>
30 #include <list>
31 #include <map>
32
33 #include "atis.hxx"
34 #include "tower.hxx"
35 #include "approach.hxx"
36 #include "ground.hxx"
37 #include "ATC.hxx"
38 #include "ATCVoice.hxx"
39 #include "transmissionlist.hxx"
40
41 SG_USING_STD(string);
42 SG_USING_STD(list);
43 SG_USING_STD(map);
44
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. 
49 struct AirportATC {
50         AirportATC();
51         
52     float lon;
53     float lat;
54     float elev;
55     float atis_freq;
56     bool atis_active;
57     float tower_freq;
58     bool tower_active;
59     float ground_freq;
60     bool ground_active;
61     //float approach_freq;
62     //bool approach_active;
63     //float departure_freq;
64     //bool departure_active;
65
66     // Flags to ensure the stations don't get wrongly deactivated
67     bool set_by_AI;     // true when the AI manager has activated this station
68         // Do we need to ref-count the number of AI planes setting this?
69     bool set_by_comm_search;    // true when the comm_search has activated this station
70         // Do we need to distingiush comm1 and comm2?
71 };
72
73 class FGATCMgr : public FGSubsystem
74 {
75
76 private:
77
78     // A map of airport ID vs frequencies and ATC provision
79     typedef map < string, AirportATC* > airport_atc_map_type;
80     typedef airport_atc_map_type::iterator airport_atc_map_iterator;
81     typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
82
83     airport_atc_map_type airport_atc_map;
84     airport_atc_map_iterator airport_atc_map_itr;
85
86     // A list of pointers to all currently active ATC classes
87     typedef list <FGATC*> atc_list_type;
88     typedef atc_list_type::iterator atc_list_iterator;
89     typedef atc_list_type::const_iterator atc_list_const_iterator;
90
91     // Everything put in this list should be created dynamically
92     // on the heap and ***DELETED WHEN REMOVED!!!!!***
93     atc_list_type atc_list;
94     atc_list_iterator atc_list_itr;
95     // Any member function of FGATCMgr is permitted to leave this iterator pointing
96     // at any point in or at the end of the list.
97     // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
98
99     // Position of the Users Aircraft
100     double lon;
101     double lat;
102     double elev;
103
104     // Type of ATC control that the user's radios are tuned to.
105     atc_type comm_type[2];
106         
107         // Pointer to the ATC station that the user is currently tuned into.
108         FGATC* comm_atc_ptr[2];
109
110     double comm_freq[2];
111
112     // Pointers to users current communication frequencies.
113     SGPropertyNode* comm_node[2];
114
115     // Pointers to current users position
116     SGPropertyNode* lon_node;
117     SGPropertyNode* lat_node;
118     SGPropertyNode* elev_node;
119
120     // Position of the ATC that the comm radios are tuned to in order to decide 
121         // whether transmission will be received.
122     double comm_x[2], comm_y[2], comm_z[2], comm_lon[2], comm_lat[2], comm_elev[2];
123
124     double comm_range[2], comm_effective_range[2];
125     bool comm_valid[2]; 
126     const char* comm_ident[2];
127     const char* last_comm_ident[2];
128
129     const char* approach_ident;
130     bool last_in_range;
131
132     //FGATIS atis;
133     //FGGround ground;
134     FGTower tower;
135     FGApproach approach;
136     //FGDeparture departure;
137         
138         // Voice related stuff
139         bool voice;                     // Flag - true if we are using voice
140 #ifdef ENABLE_AUDIO_SUPPORT
141         bool voiceOK;           // Flag - true if at least one voice has loaded OK
142         FGATCVoice* v1;
143 #endif
144
145 public:
146
147     FGATCMgr();
148     ~FGATCMgr();
149
150     void init();
151
152     void bind();
153
154     void unbind();
155
156     void update(double dt);
157
158     // Returns true if the airport is found in the map
159     bool GetAirportATCDetails(string icao, AirportATC* a);
160
161     // Return a pointer to a given sort of ATC at a given airport and activate if necessary
162     FGATC* GetATCPointer(string icao, atc_type type);
163         
164         // Display a dialog box with options relevant to the currently tuned ATC service.
165         void doPopupDialog();
166         
167         // Return a pointer to an appropriate voice for a given type of ATC
168         // creating the voice if necessary - ie. make sure exactly one copy
169         // of every voice in use exists in memory.
170         //
171         // TODO - in the future this will get more complex and dole out country/airport
172         // specific voices, and possible make sure that the same voice doesn't get used
173         // at different airports in quick succession if a large enough selection are available.
174         FGATCVoice* GetVoicePointer(atc_type type);
175         
176         atc_type GetComm1ATCType() { return(comm_type[0]); }
177         FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); }
178         atc_type GetComm2ATCType() { return(comm_type[1]); }
179         FGATC* GetComm2ATCPointer() { return(comm_atc_ptr[1]); }
180         
181 private:
182
183     // Remove a class from the atc_list and delete it from memory
184         // *if* no other comm channel or AI plane is using it.
185     void CommRemoveFromList(const char* id, atc_type tp, int chan);
186
187     // Remove a class from the atc_list and delete it from memory
188         // Should be called from the above - not directly!!
189     void RemoveFromList(const char* id, atc_type tp);
190
191     // Return a pointer to a class in the list given ICAO code and type
192         // (external interface to this is through GetATCPointer) 
193         // Return NULL if the given service is not in the list
194         // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
195     FGATC* FindInList(const char* id, atc_type tp);
196
197     // Search the specified channel for stations on the same frequency and in range.
198     void FreqSearch(int channel);
199         
200         // Search ATC stations by area in order that we appear 'on the radar'
201         void AreaSearch(); 
202
203 };
204
205 #endif  // _FG_ATCMGR_HXX