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