]> git.mxchange.org Git - flightgear.git/blob - src/ATC/tower.hxx
Some fixes to Alexander's pop-up dialog box
[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 //#include <Airports/runways.hxx>
30
31 #include STL_IOSTREAM
32 #include STL_STRING
33
34 SG_USING_STD(string);
35 SG_USING_STD(ios);
36
37 #include "ATC.hxx"
38 //#include "ATCmgr.hxx"
39 #include "ground.hxx"
40 #include "ATCProjection.hxx"
41
42 //DCL - a complete guess for now.
43 #define FG_TOWER_DEFAULT_RANGE 30
44
45 enum tower_traffic_type {
46         CIRCUIT,
47         INBOUND,
48         OUTBOUND,
49         STRAIGHT_IN
50         // Umm - what's the difference between INBOUND and STRAIGHT_IN ?
51 };
52
53 // Much simplified compared to AILocalTraffic
54 enum TwrPatternLeg {
55         TWR_LANDING_ROLL,
56         TWR_FINAL,
57         TWR_BASE,
58         TWR_DOWNWIND,
59         TWR_CROSSWIND,
60         TWR_CLIMBOUT,
61         TWR_TAKEOFF_ROLL,
62         TWR_UNKNOWN
63 };
64
65 // perhaps we could use an FGRunway instead of this
66 struct RunwayDetails {
67         Point3D threshold_pos;
68         Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
69         Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
70         //double mag_hdg;
71         //double mag_var;
72         double hdg;             // true runway heading
73         double length;  // In *METERS*
74         string rwyID;
75 };
76
77 // Structure for holding details of a plane under tower control.
78 // Not fixed yet - may include more stuff later.
79 class TowerPlaneRec {
80         
81 public:
82         
83         TowerPlaneRec();
84         TowerPlaneRec(PlaneRec p);
85         TowerPlaneRec(Point3D pt);
86         TowerPlaneRec(PlaneRec p, Point3D pt);
87         
88         FGAIEntity* planePtr;   // This might move to the planeRec eventually
89         PlaneRec plane;
90         
91         Point3D pos;
92         double eta;             // seconds
93         double dist_out;        // meters from theshold
94         bool clearedToLand;
95         bool clearedToLineUp;
96         bool clearedToTakeOff;
97         // ought to add time cleared to depart so we can nag if necessary
98         bool holdShortReported;
99         bool longFinalReported;
100         bool longFinalAcknowledged;
101         bool finalReported;
102         bool finalAcknowledged;
103         bool onRwy;             // is physically on the runway
104         bool nextOnRwy;         // currently projected by tower to be the next on the runway
105
106         double clearanceCounter;                // Hack for communication timing - counter since clearance requested in seconds 
107         
108         // Type of operation the plane is doing
109         tower_traffic_type opType;
110         
111         // Whereabouts in circuit if doing circuits
112         TwrPatternLeg leg;
113         
114         bool isUser;    // true if this plane is the user
115 };
116
117
118 typedef list < TowerPlaneRec* > tower_plane_rec_list_type;
119 typedef tower_plane_rec_list_type::iterator tower_plane_rec_list_iterator;
120 typedef tower_plane_rec_list_type::const_iterator tower_plane_rec_list_const_iterator;
121
122
123 class FGTower : public FGATC {
124
125 public:
126         
127         FGTower();
128         ~FGTower();
129         
130         void Init();
131         
132         void Update(double dt);
133
134         void RequestLandingClearance(string ID);
135         void RequestDepartureClearance(string ID);      
136         void ReportFinal(string ID);
137         void ReportLongFinal(string ID);
138         void ReportOuterMarker(string ID);
139         void ReportMiddleMarker(string ID);
140         void ReportInnerMarker(string ID);
141         void ReportGoingAround(string ID);
142         void ReportRunwayVacated(string ID);
143         void ReportReadyForDeparture(string ID);
144         
145         // Contact tower when at a hold short for departure
146         void ContactAtHoldShort(PlaneRec plane, FGAIEntity* requestee, tower_traffic_type operation);
147         
148         // Public interface to the active runway - this will get more complex 
149         // in the future and consider multi-runway use, airplane weight etc.
150         inline string GetActiveRunway() { return activeRwy; }
151         inline RunwayDetails* GetActiveRunwayDetails() { return &rwy; }
152         
153         inline void SetDisplay() { display = true; }
154         inline void SetNoDisplay() { display = false; }
155         
156         inline string get_trans_ident() { return trans_ident; }
157         inline atc_type GetType() { return TOWER; }
158         
159         inline FGGround* GetGroundPtr() { return ground; }
160
161 private:
162         FGATCMgr* ATCmgr;       
163         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
164
165         // Figure out if a given position lies on the active runway
166         // Might have to change when we consider more than one active rwy.
167         bool OnActiveRunway(Point3D pt);
168         
169         // Figure out if a given position lies on a runway or not
170         bool OnAnyRunway(Point3D pt);
171         
172         // Calculate the eta of each plane to the threshold.
173         // For ground traffic this is the fastest they can get there.
174         // For air traffic this is the middle approximation.
175         void doThresholdETACalc();
176         
177         // Order the list of traffic as per expected threshold use and flag any conflicts
178         bool doThresholdUseOrder();
179         
180         void doCommunication();
181         
182         void IssueLandingClearance(TowerPlaneRec* tpr);
183         void IssueGoAround(TowerPlaneRec* tpr);
184         void IssueDepartureClearance(TowerPlaneRec* tpr);
185         
186         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
187         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
188         
189         // environment - need to make sure we're getting the surface winds and not winds aloft.
190         SGPropertyNode* wind_from_hdg;  //degrees
191         SGPropertyNode* wind_speed_knots;               //knots
192         
193         double aptElev;         // Airport elevation
194         string activeRwy;       // Active runway number - For now we'll disregard multiple / alternate runway operation.
195         RunwayDetails rwy;      // Assumed to be the active one for now.
196         bool rwyOccupied;       // Active runway occupied flag.  For now we'll disregard land-and-hold-short operations.
197         FGATCAlignedProjection ortho;   // Orthogonal mapping of the local area with the active runway threshold at the origin
198         
199         // Figure out which runways are active.
200         // For now we'll just be simple and do one active runway - eventually this will get much more complex
201         // This is a private function - public interface to the results of this is through GetActiveRunway
202         void DoRwyDetails();
203         
204         // Need a data structure to hold details of the various active planes
205         // or possibly another data structure with the positions of the inactive planes.
206         // Need a data structure to hold outstanding communications from aircraft.
207         
208         // Linked-list of planes on approach ordered with nearest first (timewise).
209         // Includes planes that have landed but not yet vacated runway.
210         // Somewhat analagous to the paper strips used (used to be used?) in real life.
211         // Doesn't include planes in circuit until they turn onto base/final?
212         tower_plane_rec_list_type appList;
213         tower_plane_rec_list_iterator appListItr;
214         
215         // List of departed planes (planes doing circuits go into circuitList not depList after departure)
216         tower_plane_rec_list_type depList;
217         tower_plane_rec_list_iterator depListItr;
218         
219         // List of planes in the circuit (ordered by nearest to landing first)
220         tower_plane_rec_list_type circuitList;
221         tower_plane_rec_list_iterator circuitListItr;
222         
223         // List of planes waiting to depart
224         tower_plane_rec_list_type holdList;
225         tower_plane_rec_list_iterator holdListItr;
226                 
227         // List of planes on rwy
228         tower_plane_rec_list_type rwyList;
229         tower_plane_rec_list_iterator rwyListItr;
230
231         // List of all planes due to use a given rwy arranged in projected order of rwy use
232         tower_plane_rec_list_type trafficList;  // TODO - needs to be expandable to more than one rwy
233         tower_plane_rec_list_iterator trafficListItr;
234
235         // Ground can be separate or handled by tower in real life.
236         // In the program we will always use a separate FGGround class, but we need to know
237         // whether it is supposed to be separate or not to give the correct instructions.
238         bool separateGround;    // true if ground control is separate
239         FGGround* ground;       // The ground control associated with this airport.
240         
241         // for failure modeling
242         string trans_ident;             // transmitted ident
243         bool tower_failed;              // tower failed?
244         
245     // Pointers to current users position
246     SGPropertyNode* user_lon_node;
247     SGPropertyNode* user_lat_node;
248     SGPropertyNode* user_elev_node;
249         
250         friend istream& operator>> ( istream&, FGTower& );
251 };
252
253 #endif  //_FG_TOWER_HXX