]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.hxx
Patches from Erik Hofman for SGI compatibility:
[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 SG_USING_STD(ios);
35
36 #include "ATC.hxx"
37 //#include "ATCmgr.hxx"
38 #include "ground.hxx"
39
40 //DCL - a complete guess for now.
41 #define FG_TOWER_DEFAULT_RANGE 30
42
43 // Structure for holding details of a plane under tower control.
44 // Not fixed yet - may include more stuff later.
45 class TowerPlaneRec {
46         
47         public:
48         
49         TowerPlaneRec();
50         TowerPlaneRec(string ID);
51         TowerPlaneRec(Point3D pt);
52         TowerPlaneRec(string ID, Point3D pt);
53         
54         string id;
55         Point3D pos;
56         double eta;             // minutes
57         double dist_out;        // miles from theshold
58         bool clearedToLand;
59         bool clearedToDepart;
60         // ought to add time cleared to depart so we can nag if necessary
61         bool longFinalReported;
62         bool longFinalAcknowledged;
63         bool finalReported;
64         bool finalAcknowledged;
65         bool onRwy;
66         // enum type - light, medium, heavy etc - we need someway of approximating the aircraft type and performance.
67 };
68
69 typedef list < TowerPlaneRec* > tower_plane_rec_list_type;
70 typedef list < TowerPlaneRec* >::iterator tower_plane_rec_list_iterator;
71 typedef list < TowerPlaneRec* >::const_iterator tower_plane_rec_list_const_iterator;
72
73
74 class FGTower : public FGATC {
75
76         public:
77         
78         FGTower();
79         ~FGTower();
80         
81         void Init();
82         
83         void Update();
84
85         void RequestLandingClearance(string ID);
86         void RequestDepartureClearance(string ID);      
87         void ReportFinal(string ID);
88         void ReportLongFinal(string ID);
89         void ReportOuterMarker(string ID);
90         void ReportMiddleMarker(string ID);
91         void ReportInnerMarker(string ID);
92         void ReportGoingAround(string ID);
93         void ReportRunwayVacated(string ID);
94         
95         // Parse a literal message to decide which of above it represents. 
96         // (a long term project that eventually will hopefully receive the output from voice recognition software.)
97         void LiteralTransmission(string trns, string ID);
98         
99         inline void SetDisplay() {display = true;}
100         inline void SetNoDisplay() {display = false;}
101         
102         inline char get_type() const { return type; }
103         inline double get_lon() const { return lon; }
104         inline double get_lat() const { return lat; }
105         inline double get_elev() const { return elev; }
106         inline double get_x() const { return x; }
107         inline double get_y() const { return y; }
108         inline double get_z() const { return z; }
109         inline int get_freq() const { return freq; }
110         inline int get_range() const { return range; }
111         inline const char* GetIdent() { return ident.c_str(); }
112         inline string get_trans_ident() { return trans_ident; }
113         inline string get_name() { return name; }
114         inline atc_type GetType() { return TOWER; }
115         
116         // Make a request of tower control
117         //void Request(tower_request request);
118         
119         private:
120         
121         void IssueLandingClearance(TowerPlaneRec* tpr);
122         void IssueGoAround(TowerPlaneRec* tpr);
123         void IssueDepartureClearance(TowerPlaneRec* tpr);
124         
125         char type;
126         double lon, lat;
127         double elev;
128         double x, y, z;
129         int freq;
130         int range;
131         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
132         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
133         string ident;           // Code of the airport its at.
134         string name;            // Name generally used in transmissions.
135
136         
137         // Need a data structure to hold details of the various active planes
138         // or possibly another data structure with the positions of the inactive planes.
139         // Need a data structure to hold outstanding communications from aircraft.
140         
141         // Linked-list of planes on approach ordered with nearest first (timewise).
142         // Includes planes that have landed but not yet vacated runway.
143         // Somewhat analagous to the paper strips used (used to be used?) in real life.
144         tower_plane_rec_list_type appList;
145         
146         // List of departed planes
147         tower_plane_rec_list_type depList;
148         
149         // List of planes waiting to depart
150         tower_plane_rec_list_type holdList;
151         
152         // List of planes on rwy
153         tower_plane_rec_list_type rwyList;
154
155         // Ground can be separate or handled by tower in real life.
156         // In the program we will always use a separate FGGround class, but we need to know
157         // whether it is supposed to be separate or not to give the correct instructions.
158         bool separateGround;    // true if ground control is separate
159         FGGround* groundPtr;    // The ground control associated with this airport.
160         
161         
162         // for failure modeling
163         string trans_ident;             // transmitted ident
164         bool tower_failed;              // tower failed?
165         
166         friend istream& operator>> ( istream&, FGTower& );
167 };
168
169
170 inline istream&
171 operator >> ( istream& in, FGTower& t )
172 {
173         double f;
174         char ch;
175         
176         in >> t.type;
177         
178         if ( t.type == '[' )
179                 return in >> skipeol;
180         
181         in >> t.lat >> t.lon >> t.elev >> f >> t.range 
182         >> t.ident;
183         
184         t.name = "";
185         in >> ch;
186         t.name += ch;
187         while(1) {
188                 //in >> noskipws
189                 in.unsetf(ios::skipws);
190                 in >> ch;
191                 t.name += ch;
192                 if((ch == '"') || (ch == 0x0A)) {
193                         break;
194                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
195         }
196         in.setf(ios::skipws);
197         //cout << "tower.name = " << t.name << '\n';
198         
199         t.freq = (int)(f*100.0 + 0.5);
200         
201         // cout << t.ident << endl;
202         
203         // generate cartesian coordinates
204         Point3D geod( t.lon * SGD_DEGREES_TO_RADIANS, t.lat * SGD_DEGREES_TO_RADIANS, t.elev );
205         Point3D cart = sgGeodToCart( geod );
206         t.x = cart.x();
207         t.y = cart.y();
208         t.z = cart.z();
209         
210         t.trans_ident = t.ident;
211         t.tower_failed = false;
212         
213         return in >> skipeol;
214 }
215
216
217 #endif  //_FG_TOWER_HXX