]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.hxx
Alexander's new files added to Makefile.am
[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 <Sound/soundmgr.hxx>
28 #include <GUI/gui.h>
29
30 #include <string>
31 #include <list>
32 #include <map>
33
34 #include "atis.hxx"
35 #include "tower.hxx"
36 #include "approach.hxx"
37 #include "ground.hxx"
38 #include "ATC.hxx"
39 #include "ATCVoice.hxx"
40 #include "transmissionlist.hxx"
41
42 SG_USING_STD(string);
43 SG_USING_STD(list);
44 SG_USING_STD(map);
45
46 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
47 // These can then be cross referenced with the [atis][tower][etc]lists which are stored by frequency.
48 // Non-available services are denoted by a frequency of zero.
49 // Eventually the whole ATC data structures may have to be rethought if we turn out to be massive memory hogs!!
50 struct AirportATC {
51     float lon;
52     float lat;
53     float elev;
54     float atis_freq;
55     bool atis_active;
56     float tower_freq;
57     bool tower_active;
58     float ground_freq;
59     bool ground_active;
60     //float approach_freq;
61     //bool approach_active;
62     //float departure_freq;
63     //bool departure_active;
64
65     // Flags to ensure the stations don't get wrongly deactivated
66     bool set_by_AI;     // true when the AI manager has activated this station
67     bool set_by_comm_search;    // true when the comm_search has activated this station
68 };
69
70 class FGATCMgr : public FGSubsystem
71 {
72
73 private:
74
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;
79
80     airport_atc_map_type airport_atc_map;
81     airport_atc_map_iterator airport_atc_map_itr;
82
83     // A list of pointers to all currently active ATC classes
84     typedef list <FGATC*> atc_list_type;
85     typedef atc_list_type::iterator atc_list_iterator;
86     typedef atc_list_type::const_iterator atc_list_const_iterator;
87
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.
95
96     // Position of the Users Aircraft
97     double lon;
98     double lat;
99     double elev;
100
101     // Type of ATC control that the user's radios are tuned to.
102     atc_type comm_type[2];
103         
104         // Pointer to the ATC station that the user is currently tuned into.
105         FGATC* comm_atc_ptr[2];
106
107     double comm_freq[2];
108
109     // Pointers to users current communication frequencies.
110     SGPropertyNode* comm_node[2];
111
112     // Pointers to current users position
113     SGPropertyNode* lon_node;
114     SGPropertyNode* lat_node;
115     SGPropertyNode* elev_node;
116
117     // Position of the ATC that the comm radios are tuned to in order to decide 
118         // whether transmission will be received.
119     double comm_x[2], comm_y[2], comm_z[2], comm_lon[2], comm_lat[2], comm_elev[2];
120
121     double comm_range[2], comm_effective_range[2];
122     bool comm_valid[2]; 
123     const char* comm_ident[2];
124     const char* last_comm_ident[2];
125
126     const char* approach_ident;
127     bool last_in_range;
128
129     //FGATIS atis;
130     //FGGround ground;
131     FGTower tower;
132     FGApproach approach;
133     //FGDeparture departure;
134
135         // Rendering related stuff
136         bool voice;                     // Flag - true if we are using voice
137         bool playing;           // Indicates a message in progress      
138 #ifdef ENABLE_AUDIO_SUPPORT
139         bool voiceOK;           // Flag - true if at least one voice has loaded OK
140         FGATCVoice v1;
141 #endif
142
143 public:
144
145     FGATCMgr();
146     ~FGATCMgr();
147
148     void init();
149
150     void bind();
151
152     void unbind();
153
154     void update(double dt);
155
156     // Returns true if the airport is found in the map
157     bool GetAirportATCDetails(string icao, AirportATC* a);
158
159     // Return a pointer to a given sort of ATC at a given airport and activate if necessary
160     FGATC* GetATCPointer(string icao, atc_type type);
161         
162         // Render a transmission
163         // Outputs the transmission either on screen or as audio depending on user preference
164         // The refname is a string to identify this sample to the sound manager
165         // The repeating flag indicates whether the message should be repeated continuously or played once.
166         void Render(string msg, string refname, bool repeating);
167
168         // Cease rendering a transmission.
169         // Requires the sound manager refname if audio, else "".
170         void NoRender(string refname);
171         
172         // Display a dialog box with options relevant to the currently tuned ATC service.
173         void doPopupDialog();
174         
175         atc_type GetComm1ATCType() { return(comm_type[0]); }
176         FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); }
177         atc_type GetComm2ATCType() { return(comm_type[1]); }
178         FGATC* GetComm2ATCPointer() { return(comm_atc_ptr[1]); }
179         
180 private:
181
182     // Remove a class from the atc_list and delete it from memory
183         // *if* no other comm channel or AI plane is using it.
184     void CommRemoveFromList(const char* id, atc_type tp, int chan);
185
186     // Remove a class from the atc_list and delete it from memory
187         // Should be called from the above - not directly!!
188     void RemoveFromList(const char* id, atc_type tp);
189
190     // Return a pointer to a class in the list given ICAO code and type
191         // (external interface to this is through GetATCPointer) 
192         // Return NULL if the given service is not in the list
193         // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
194     FGATC* FindInList(const char* id, atc_type tp);
195
196     // Search the specified channel for stations on the same frequency and in range.
197     void FreqSearch(int channel);
198         
199         // Search ATC stations by area in order that we appear 'on the radar'
200         void AreaSearch(); 
201
202 };
203
204 #endif  // _FG_ATCMGR_HXX