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