]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ATC.hxx
Remove un-needed typedef
[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 // Possible types of ATC type that the radios may be tuned to.
40 // INVALID implies not tuned in to anything.
41 enum atc_type {
42     INVALID,
43     ATIS,
44     GROUND,
45     TOWER,
46     APPROACH,
47     DEPARTURE,
48     ENROUTE
49 }; 
50
51 // DCL - new experimental ATC data store
52 struct ATCData {
53         atc_type type;
54         float lon, lat, elev;
55         float x, y, z;
56         //int freq;
57         unsigned short int freq;
58         //int range;
59         unsigned short int range;
60         string ident;
61         string name;
62 };
63
64 ostream& operator << (ostream& os, atc_type atc);
65
66 class FGATC {
67
68 public:
69
70     virtual ~FGATC();
71
72     // Run the internal calculations
73     virtual void Update();
74
75     // Add plane to a stack
76     virtual void AddPlane(string pid);
77
78     // Remove plane from stack
79     virtual int RemovePlane();
80
81     // Indicate that this instance should output to the display if appropriate 
82     virtual void SetDisplay();
83
84     // Indicate that this instance should not output to the display
85     virtual void SetNoDisplay();
86
87     // Return the type of ATC station that the class represents
88     virtual atc_type GetType();
89         
90         // Set the core ATC data
91         void SetData(ATCData* d);
92         
93         inline double get_lon() const { return lon; }
94         inline void set_lon(const double ln) {lon = ln;}
95         inline double get_lat() const { return lat; }
96         inline void set_lat(const double lt) {lat = lt;}
97         inline double get_elev() const { return elev; }
98         inline void set_elev(const double ev) {elev = ev;}
99         inline double get_x() const { return x; }
100         inline void set_x(const double ecs) {x = ecs;}
101         inline double get_y() const { return y; }
102         inline void set_y(const double why) {y = why;}
103         inline double get_z() const { return z; }
104         inline void set_z(const double zed) {z = zed;}
105         inline int get_freq() const { return freq; }
106         inline void set_freq(const int fq) {freq = fq;}
107         inline int get_range() const { return range; }
108         inline void set_range(const int rg) {range = rg;}
109         inline const char* get_ident() { return ident.c_str(); }
110         inline void set_ident(const string id) {ident = id;}
111         inline const char* get_name() {return name.c_str();}
112         inline void set_name(const string nm) {name = nm;}
113         
114 protected:
115
116         // Render a transmission
117         // Outputs the transmission either on screen or as audio depending on user preference
118         // The refname is a string to identify this sample to the sound manager
119         // The repeating flag indicates whether the message should be repeated continuously or played once.
120         void Render(string msg, string refname, bool repeating);
121
122         // Cease rendering a transmission.
123         // Requires the sound manager refname if audio, else "".
124         void NoRender(string refname);
125
126         double lon, lat, elev;
127         double x, y, z;
128         int freq;
129         int range;
130         string ident;           // Code of the airport its at.
131         string name;            // Name transmitted in the broadcast.
132         
133         // Rendering related stuff
134         bool voice;                     // Flag - true if we are using voice
135         bool playing;           // Indicates a message in progress      
136         bool voiceOK;           // Flag - true if at least one voice has loaded OK
137         FGATCVoice* vPtr;
138 };
139
140 inline istream&
141 operator >> ( istream& fin, ATCData& a )
142 {
143         double f;
144         char ch;
145         char tp;
146
147         fin >> tp;
148         
149         switch(tp) {
150         case 'I':
151                 a.type = ATIS;
152                 break;
153         case 'T':
154                 a.type = TOWER;
155                 break;
156         case 'G':
157                 a.type = GROUND;
158                 break;
159         case 'A':
160                 a.type = APPROACH;
161                 break;
162         case '[':
163                 a.type = INVALID;
164                 return fin >> skipeol;
165         default:
166                 SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
167                 a.type = INVALID;
168                 return fin >> skipeol;
169         }
170
171         fin >> a.lat >> a.lon >> a.elev >> f >> a.range 
172         >> a.ident;
173         
174         a.name = "";
175         fin >> ch;
176         a.name += ch;
177         while(1) {
178                 //in >> noskipws
179                 fin.unsetf(ios::skipws);
180                 fin >> ch;
181                 a.name += ch;
182                 if((ch == '"') || (ch == 0x0A)) {
183                         break;
184                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
185         }
186         fin.setf(ios::skipws);
187         //cout << "Comm name = " << a.name << '\n';
188         
189         a.freq = (int)(f*100.0 + 0.5);
190         
191         // cout << a.ident << endl;
192         
193         // generate cartesian coordinates
194         Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
195         Point3D cart = sgGeodToCart( geod );
196         a.x = cart.x();
197         a.y = cart.y();
198         a.z = cart.z();
199         
200         return fin >> skipeol;
201 }
202
203
204 #endif  // _FG_ATC_HXX