]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.hxx
First draft of an ATC dialog box, mostly copied from the autopilot new heading dialog...
[flightgear.git] / src / ATC / tower.hxx
1 // FGTower - a class to provide tower control at towered airports.
2 //
3 // Written by David Luff, started March 2002.
4 //
5 // Copyright (C) 2002  David C. Luff - david.luff@nottingham.ac.uk
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 #ifndef _FG_TOWER_HXX
22 #define _FG_TOWER_HXX
23
24 #include <simgear/compiler.h>
25 #include <simgear/math/point3d.hxx>
26 #include <simgear/misc/sgstream.hxx>
27 #include <simgear/math/sg_geodesy.hxx>
28 #include <plib/sg.h>
29
30 #include STL_IOSTREAM
31 #include STL_STRING
32
33 SG_USING_STD(string);
34 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
35 SG_USING_STD(ios);
36 #endif
37
38 #include "ATC.hxx"
39 //#include "ATCmgr.hxx"
40 #include "ground.hxx"
41
42 //DCL - a complete guess for now.
43 #define FG_TOWER_DEFAULT_RANGE 30
44
45 // Structure for holding details of a plane under tower control.
46 // Not fixed yet - may include more stuff later.
47 class TowerPlaneRec {
48         
49         public:
50         
51         TowerPlaneRec();
52         TowerPlaneRec(string ID);
53         TowerPlaneRec(Point3D pt);
54         TowerPlaneRec(string ID, Point3D pt);
55         
56         string id;
57         Point3D pos;
58         double eta;             // minutes
59         double dist_out;        // miles from theshold
60         bool clearedToLand;
61         bool clearedToDepart;
62         // ought to add time cleared to depart so we can nag if necessary
63         bool longFinalReported;
64         bool longFinalAcknowledged;
65         bool finalReported;
66         bool finalAcknowledged;
67         bool onRwy;
68         // enum type - light, medium, heavy etc - we need someway of approximating the aircraft type and performance.
69 };
70
71 typedef list < TowerPlaneRec* > tower_plane_rec_list_type;
72 typedef list < TowerPlaneRec* >::iterator tower_plane_rec_list_iterator;
73 typedef list < TowerPlaneRec* >::const_iterator tower_plane_rec_list_const_iterator;
74
75
76 class FGTower : public FGATC {
77
78         public:
79         
80         FGTower();
81         ~FGTower();
82         
83         void Init();
84         
85         void Update();
86
87         void RequestLandingClearance(string ID);
88         void RequestDepartureClearance(string ID);      
89         void ReportFinal(string ID);
90         void ReportLongFinal(string ID);
91         void ReportOuterMarker(string ID);
92         void ReportMiddleMarker(string ID);
93         void ReportInnerMarker(string ID);
94         void ReportGoingAround(string ID);
95         void ReportRunwayVacated(string ID);
96         
97         // Parse a literal message to decide which of above it represents. 
98         // (a long term project that eventually will hopefully receive the output from voice recognition software.)
99         void LiteralTransmission(string trns, string ID);
100         
101         inline void SetDisplay() {display = true;}
102         inline void SetNoDisplay() {display = false;}
103         
104         inline char get_type() const { return type; }
105         inline double get_lon() const { return lon; }
106         inline double get_lat() const { return lat; }
107         inline double get_elev() const { return elev; }
108         inline double get_x() const { return x; }
109         inline double get_y() const { return y; }
110         inline double get_z() const { return z; }
111         inline int get_freq() const { return freq; }
112         inline int get_range() const { return range; }
113         inline const char* GetIdent() { return ident.c_str(); }
114         inline string get_trans_ident() { return trans_ident; }
115         inline string get_name() { return name; }
116         inline atc_type GetType() { return TOWER; }
117         
118         // Make a request of tower control
119         //void Request(tower_request request);
120         
121         private:
122         
123         void IssueLandingClearance(TowerPlaneRec* tpr);
124         void IssueGoAround(TowerPlaneRec* tpr);
125         void IssueDepartureClearance(TowerPlaneRec* tpr);
126         
127         char type;
128         double lon, lat;
129         double elev;
130         double x, y, z;
131         int freq;
132         int range;
133         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
134         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
135         string ident;           // Code of the airport its at.
136         string name;            // Name generally used in transmissions.
137
138         
139         // Need a data structure to hold details of the various active planes
140         // or possibly another data structure with the positions of the inactive planes.
141         // Need a data structure to hold outstanding communications from aircraft.
142         
143         // Linked-list of planes on approach ordered with nearest first (timewise).
144         // Includes planes that have landed but not yet vacated runway.
145         // Somewhat analagous to the paper strips used (used to be used?) in real life.
146         tower_plane_rec_list_type appList;
147         
148         // List of departed planes
149         tower_plane_rec_list_type depList;
150         
151         // List of planes waiting to depart
152         tower_plane_rec_list_type holdList;
153         
154         // List of planes on rwy
155         tower_plane_rec_list_type rwyList;
156
157         // Ground can be separate or handled by tower in real life.
158         // In the program we will always use a separate FGGround class, but we need to know
159         // whether it is supposed to be separate or not to give the correct instructions.
160         bool separateGround;    // true if ground control is separate
161         FGGround* groundPtr;    // The ground control associated with this airport.
162         
163         
164         // for failure modeling
165         string trans_ident;             // transmitted ident
166         bool tower_failed;              // tower failed?
167         
168         friend istream& operator>> ( istream&, FGTower& );
169 };
170
171
172 inline istream&
173 operator >> ( istream& in, FGTower& t )
174 {
175         double f;
176         char ch;
177         
178         in >> t.type;
179         
180         if ( t.type == '[' )
181                 return in >> skipeol;
182         
183         in >> t.lat >> t.lon >> t.elev >> f >> t.range 
184         >> t.ident;
185         
186         t.name = "";
187         in >> ch;
188         t.name += ch;
189         while(1) {
190                 //in >> noskipws
191                 in.unsetf(ios::skipws);
192                 in >> ch;
193                 t.name += ch;
194                 if((ch == '"') || (ch == 0x0A)) {
195                         break;
196                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
197         }
198         in.setf(ios::skipws);
199         //cout << "tower.name = " << t.name << '\n';
200         
201         t.freq = (int)(f*100.0 + 0.5);
202         
203         // cout << t.ident << endl;
204         
205         // generate cartesian coordinates
206         Point3D geod( t.lon * SGD_DEGREES_TO_RADIANS, t.lat * SGD_DEGREES_TO_RADIANS, t.elev );
207         Point3D cart = sgGeodToCart( geod );
208         t.x = cart.x();
209         t.y = cart.y();
210         t.z = cart.z();
211         
212         t.trans_ident = t.ident;
213         t.tower_failed = false;
214         
215         return in >> skipeol;
216 }
217
218
219 #endif  //_FG_TOWER_HXX