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