]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATCmgr.hxx
Search ATC frequencies with both comm1 and 2 instead of just comm1 as previously
[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
41 SG_USING_STD(string);
42 SG_USING_STD(list);
43 SG_USING_STD(map);
44
45 const int max_app = 20;
46
47 // Structure for holding details of the ATC frequencies at a given airport, and whether they are in the active list or not.
48 // These can then be cross referenced with the [atis][tower][etc]lists which are stored by frequency.
49 // Non-available services are denoted by a frequency of zero.
50 // Eventually the whole ATC data structures may have to be rethought if we turn out to be massive memory hogs!!
51 struct AirportATC {
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     bool set_by_comm_search;    // true when the comm_search has activated this station
69 };
70
71 class FGATCMgr : public FGSubsystem
72 {
73
74 private:
75
76     // A map of airport ID vs frequencies and ATC provision
77     typedef map < string, AirportATC* > airport_atc_map_type;
78     typedef airport_atc_map_type::iterator airport_atc_map_iterator;
79     typedef airport_atc_map_type::const_iterator airport_atc_map_const_iterator;
80
81     airport_atc_map_type airport_atc_map;
82     airport_atc_map_iterator airport_atc_map_itr;
83
84     // A list of pointers to all currently active ATC classes
85     typedef list <FGATC*> atc_list_type;
86     typedef atc_list_type::iterator atc_list_iterator;
87     typedef atc_list_type::const_iterator atc_list_const_iterator;
88
89     // Everything put in this list should be created dynamically
90     // on the heap and ***DELETED WHEN REMOVED!!!!!***
91     atc_list_type atc_list;
92     atc_list_iterator atc_list_itr;
93     // Any member function of FGATCMgr is permitted to leave this iterator pointing
94     // at any point in or at the end of the list.
95     // Hence any new access must explicitly first check for atc_list.end() before dereferencing.
96
97     // Position of the Users Aircraft
98     double lon;
99     double lat;
100     double elev;
101
102     // Type of ATC control that the user's radios are tuned to.
103     atc_type comm1_type;
104     atc_type comm2_type;
105         
106         // Pointer to the ATC station that the user is currently tuned into.
107         FGATC* comm1_atc_ptr;
108         FGATC* comm2_atc_ptr;
109
110     double comm1_freq;
111     double comm2_freq;
112
113     // Pointers to users current communication frequencies.
114     SGPropertyNode* comm1_node;
115     SGPropertyNode* comm2_node;
116
117     // Pointers to current users position
118     SGPropertyNode* lon_node;
119     SGPropertyNode* lat_node;
120     SGPropertyNode* elev_node;
121
122     // Position of the ATC that the comm radios are tuned to in order to decide 
123         // whether transmission will be received.
124     double comm1_x, comm1_y, comm1_z, comm1_elev;
125     double comm2_x, comm2_y, comm2_z, comm2_elev;
126
127     double comm1_range, comm1_effective_range;
128     bool comm1_valid; 
129     bool comm1_atis_valid;
130     bool comm1_tower_valid;
131     bool comm1_approach_valid;
132     const char* comm1_ident;
133     const char* comm1_atis_ident;
134     const char* comm1_tower_ident;
135     const char* comm1_approach_ident;
136     const char* last_comm1_ident;
137     const char* last_comm1_atis_ident;
138     const char* last_comm1_tower_ident;
139     const char* last_comm1_approach_ident;
140         
141     double comm2_range, comm2_effective_range;
142     bool comm2_valid;
143     bool comm2_atis_valid;
144     bool comm2_tower_valid;
145     bool comm2_approach_valid;
146     const char* comm2_ident;
147     const char* comm2_atis_ident;
148     const char* comm2_tower_ident;
149     const char* comm2_approach_ident;
150     const char* last_comm2_ident;
151     const char* last_comm2_atis_ident;
152     const char* last_comm2_tower_ident;
153     const char* last_comm2_approach_ident;
154         
155     const char* approach_ident;
156     bool last_in_range;
157
158     FGATIS atis;
159     //FGGround ground;
160     FGTower tower;
161     FGApproach approaches[max_app];
162     FGApproach approach;
163     //FGDeparture departure;
164
165         // Rendering related stuff
166         bool voice;                     // Flag - true if we are using voice
167         bool playing;           // Indicates a message in progress      
168 #ifdef ENABLE_AUDIO_SUPPORT
169         bool voiceOK;           // Flag - true if at least one voice has loaded OK
170         FGATCVoice v1;
171 #endif
172
173 public:
174
175     FGATCMgr();
176     ~FGATCMgr();
177
178     void init();
179
180     void bind();
181
182     void unbind();
183
184     void update(double dt);
185
186     // Returns true if the airport is found in the map
187     bool GetAirportATCDetails(string icao, AirportATC* a);
188
189     // Return a pointer to a given sort of ATC at a given airport and activate if necessary
190     FGATC* GetATCPointer(string icao, atc_type type);
191         
192         // Render a transmission
193         // Outputs the transmission either on screen or as audio depending on user preference
194         // The refname is a string to identify this sample to the sound manager
195         // The repeating flag indicates whether the message should be repeated continuously or played once.
196         void Render(string msg, string refname, bool repeating);
197
198         // Cease rendering a transmission.
199         // Requires the sound manager refname if audio, else "".
200         void NoRender(string refname);
201         
202         // Display a dialog box with options relevant to the currently tuned ATC service.
203         void doStandardDialog();
204         
205         atc_type GetComm1ATCType() { return(comm1_type); }
206         FGATC* GetComm1ATCPointer() { return(comm1_atc_ptr); }
207         atc_type GetComm2ATCType() { return(comm2_type); }
208         FGATC* GetComm2ATCPointer() { return(comm2_atc_ptr); }
209         
210 private:
211
212     // Remove a class from the atc_list and delete it from memory
213     void RemoveFromList(const char* id, atc_type tp);
214
215     // Return a pointer to a class in the list (external interface to this is through GetATCPointer)
216     FGATC* FindInList(const char* id, atc_type tp);
217
218     // Search the specified channel for stations on the same frequency and in range.
219     void Search(int chan);
220
221 };
222
223 #endif  // _FG_ATCMGR_HXX