]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.hxx
Rationalisation of the ATC popup dialog code - moved it all over to AK's dynamic...
[flightgear.git] / src / ATC / ATC.hxx
1 // FGATC - abstract base class for the various actual atc classes 
2 // such as FGATIS, FGTower etc.
3 //
4 // Written by David Luff, started Feburary 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_ATC_HXX
23 #define _FG_ATC_HXX
24
25 #include <simgear/compiler.h>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <simgear/debug/logstream.hxx>
29
30 #include STL_IOSTREAM
31 #include STL_STRING
32
33 #include "ATCVoice.hxx"
34
35 SG_USING_STD(ostream);
36 SG_USING_STD(string);
37 SG_USING_STD(ios);
38
39 enum plane_type {
40         UNKNOWN,
41         GA_SINGLE,
42         GA_HP_SINGLE,
43         GA_TWIN,
44         GA_JET,
45         MEDIUM,
46         HEAVY,
47         MIL_JET
48 };
49
50 // PlaneRec - a structure holding ATC-centric details of planes under control
51 // This might move or change eventually
52 struct PlaneRec {
53         plane_type type;
54         string callsign;
55         int squawkcode;
56 };
57
58 // Possible types of ATC type that the radios may be tuned to.
59 // INVALID implies not tuned in to anything.
60 enum atc_type {
61         INVALID,
62         ATIS,
63         GROUND,
64         TOWER,
65         APPROACH,
66         DEPARTURE,
67         ENROUTE
68 };
69
70 const int ATC_NUM_TYPES = 7;
71
72 // DCL - new experimental ATC data store
73 struct ATCData {
74         atc_type type;
75         // I've deliberately used float instead of double here to keep the size down - we'll be storing thousands of these in memory.
76         // In fact, we could probably ditch x, y and z and generate on the fly as needed.
77         // On the other hand, we'll probably end up reading this data directly from the DAFIF eventually anyway!!
78         float lon, lat, elev;
79         float x, y, z;
80         //int freq;
81         unsigned short int freq;
82         //int range;
83         unsigned short int range;
84         string ident;
85         string name;
86 };
87
88 // perhaps we could use an FGRunway instead of this.
89 // That wouldn't cache the orthopos though.
90 struct RunwayDetails {
91         Point3D threshold_pos;
92         Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
93         Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
94         double hdg;             // true runway heading
95         double length;  // In *METERS*
96         double width;   // ditto
97         string rwyID;
98 };
99
100 ostream& operator << (ostream& os, atc_type atc);
101
102 class FGATC {
103         
104 public:
105         
106         FGATC();
107         virtual ~FGATC();
108         
109         // Run the internal calculations
110         // Derived classes should call this method from their own Update methods if they 
111         // wish to use the response timer functionality.
112         virtual void Update(double dt);
113         
114         // Recieve a coded callback from the ATC menu system based on the user's selection
115         virtual void ReceiveUserCallback(int code);
116         
117         // Add plane to a stack
118         virtual void AddPlane(string pid);
119         
120         // Remove plane from stack
121         virtual int RemovePlane();
122         
123         // Indicate that this instance should output to the display if appropriate 
124         virtual void SetDisplay();
125         
126         // Indicate that this instance should not output to the display
127         virtual void SetNoDisplay();
128         
129         // Returns true if OK to transmit on this frequency
130         inline bool GetFreqClear() { return freqClear; }
131         // Indicate that the frequency is in use
132         inline void SetFreqInUse() { freqClear = false; receiving = true; }
133         // Transmission to the ATC is finished and a response is required
134         void SetResponseReqd(string rid);
135         // Transmission finished - let ATC decide if a response is reqd and clear freq if necessary
136         void NotifyTransmissionFinished(string rid);
137         // Transmission finished and no response required
138         inline void ReleaseFreq() { freqClear = true; receiving = false; }      // TODO - check that the plane releasing the freq is the right one etc.
139         // The above 3 funcs under development!!
140         // The idea is that AI traffic or the user ATC dialog box calls FreqInUse() when they begin transmitting,
141         // and that the tower control sets freqClear back to true following a reply.
142         // AI traffic should check FreqClear() is true prior to transmitting.
143         // The user will just have to wait for a gap in dialog as in real life.
144         
145         // Return the type of ATC station that the class represents
146         virtual atc_type GetType();
147         
148         // Set the core ATC data
149         void SetData(ATCData* d);
150         
151         inline double get_lon() const { return lon; }
152         inline void set_lon(const double ln) {lon = ln;}
153         inline double get_lat() const { return lat; }
154         inline void set_lat(const double lt) {lat = lt;}
155         inline double get_elev() const { return elev; }
156         inline void set_elev(const double ev) {elev = ev;}
157         inline double get_x() const { return x; }
158         inline void set_x(const double ecs) {x = ecs;}
159         inline double get_y() const { return y; }
160         inline void set_y(const double why) {y = why;}
161         inline double get_z() const { return z; }
162         inline void set_z(const double zed) {z = zed;}
163         inline int get_freq() const { return freq; }
164         inline void set_freq(const int fq) {freq = fq;}
165         inline int get_range() const { return range; }
166         inline void set_range(const int rg) {range = rg;}
167         inline const char* get_ident() { return ident.c_str(); }
168         inline void set_ident(const string id) {ident = id;}
169         inline const char* get_name() {return name.c_str();}
170         inline void set_name(const string nm) {name = nm;}
171         
172 protected:
173         
174         // Render a transmission
175         // Outputs the transmission either on screen or as audio depending on user preference
176         // The refname is a string to identify this sample to the sound manager
177         // The repeating flag indicates whether the message should be repeated continuously or played once.
178         void Render(string msg, string refname, bool repeating);
179         
180         // Cease rendering a transmission.
181         // Requires the sound manager refname if audio, else "".
182         void NoRender(string refname);
183         
184         double lon, lat, elev;
185         double x, y, z;
186         int freq;
187         int range;
188         string ident;           // Code of the airport its at.
189         string name;            // Name transmitted in the broadcast.
190         
191         // Rendering related stuff
192         bool voice;                     // Flag - true if we are using voice
193         bool playing;           // Indicates a message in progress      
194         bool voiceOK;           // Flag - true if at least one voice has loaded OK
195         FGATCVoice* vPtr;
196         
197         bool freqClear;         // Flag to indicate if the frequency is clear of ongoing dialog
198         bool receiving;         // Flag to indicate we are receiving a transmission
199         bool responseReqd;      // Flag to indicate we should be responding to a request/report 
200         bool runResponseCounter;        // Flag to indicate the response counter should be run
201         double responseTime;    // Time to take from end of request transmission to beginning of response
202                                                         // The idea is that this will be slightly random.
203         double responseCounter;         // counter to implement the above
204         string responseID;      // ID of the plane to respond to
205         bool respond;   // Flag to indicate now is the time to respond - ie set following the count down of the response timer.
206         // Derived classes only need monitor this flag, and use the response ID, as long as they call FGATC::Update(...)
207 };
208
209 inline istream&
210 operator >> ( istream& fin, ATCData& a )
211 {
212         double f;
213         char ch;
214         char tp;
215         
216         fin >> tp;
217         
218         switch(tp) {
219         case 'I':
220                 a.type = ATIS;
221                 break;
222         case 'T':
223                 a.type = TOWER;
224                 break;
225         case 'G':
226                 a.type = GROUND;
227                 break;
228         case 'A':
229                 a.type = APPROACH;
230                 break;
231         case '[':
232                 a.type = INVALID;
233                 return fin >> skipeol;
234         default:
235                 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
236                 a.type = INVALID;
237                 return fin >> skipeol;
238         }
239         
240         fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
241         >> a.ident;
242         
243         a.name = "";
244         fin >> ch;
245         a.name += ch;
246         while(1) {
247                 //in >> noskipws
248                 fin.unsetf(ios::skipws);
249                 fin >> ch;
250                 a.name += ch;
251                 if((ch == '"') || (ch == 0x0A)) {
252                         break;
253                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
254         }
255         fin.setf(ios::skipws);
256         //cout << "Comm name = " << a.name << '\n';
257         
258         a.freq = (int)(f*100.0 + 0.5);
259         
260         // cout << a.ident << endl;
261         
262         // generate cartesian coordinates
263         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
264         Point3D cart = sgGeodToCart( geod );
265         a.x = cart.x();
266         a.y = cart.y();
267         a.z = cart.z();
268         
269         return fin >> skipeol;
270 }
271
272
273 #endif  // _FG_ATC_HXX