1 // FGTower - a class to provide tower control at towered airports.
3 // Written by David Luff, started March 2002.
5 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
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.
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.
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.
24 #include <simgear/compiler.h>
25 #include <simgear/math/point3d.hxx>
26 #include <simgear/misc/sgstream.hxx>
27 //#include <simgear/math/sg_geodesy.hxx>
29 //#include <Airports/runways.hxx>
38 //#include "ATCmgr.hxx"
40 #include "ATCProjection.hxx"
42 //DCL - a complete guess for now.
43 #define FG_TOWER_DEFAULT_RANGE 30
45 enum tower_traffic_type {
50 // Umm - what's the difference between INBOUND and STRAIGHT_IN ?
53 // Much simplified compared to AILocalTraffic
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)
72 double hdg; // true runway heading
73 double length; // In *METERS*
77 // Structure for holding details of a plane under tower control.
78 // Not fixed yet - may include more stuff later.
84 TowerPlaneRec(PlaneRec p);
85 TowerPlaneRec(Point3D pt);
86 TowerPlaneRec(PlaneRec p, Point3D pt);
88 FGAIEntity* planePtr; // This might move to the planeRec eventually
92 double eta; // seconds
93 double dist_out; // meters from theshold
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;
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
106 double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
108 // Type of operation the plane is doing
109 tower_traffic_type opType;
111 // Whereabouts in circuit if doing circuits
114 bool isUser; // true if this plane is the user
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;
123 class FGTower : public FGATC {
132 void Update(double dt);
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);
145 // Contact tower when at a hold short for departure
146 void ContactAtHoldShort(PlaneRec plane, FGAIEntity* requestee, tower_traffic_type operation);
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; }
153 inline void SetDisplay() { display = true; }
154 inline void SetNoDisplay() { display = false; }
156 inline string get_trans_ident() { return trans_ident; }
157 inline atc_type GetType() { return TOWER; }
159 inline FGGround* GetGroundPtr() { return ground; }
163 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
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);
169 // Figure out if a given position lies on a runway or not
170 bool OnAnyRunway(Point3D pt);
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();
177 // Order the list of traffic as per expected threshold use and flag any conflicts
178 bool doThresholdUseOrder();
180 void doCommunication();
182 void IssueLandingClearance(TowerPlaneRec* tpr);
183 void IssueGoAround(TowerPlaneRec* tpr);
184 void IssueDepartureClearance(TowerPlaneRec* tpr);
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.
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
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
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
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.
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;
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;
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;
223 // List of planes waiting to depart
224 tower_plane_rec_list_type holdList;
225 tower_plane_rec_list_iterator holdListItr;
227 // List of planes on rwy
228 tower_plane_rec_list_type rwyList;
229 tower_plane_rec_list_iterator rwyListItr;
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;
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.
241 // for failure modeling
242 string trans_ident; // transmitted ident
243 bool tower_failed; // tower failed?
245 // Pointers to current users position
246 SGPropertyNode* user_lon_node;
247 SGPropertyNode* user_lat_node;
248 SGPropertyNode* user_elev_node;
250 friend istream& operator>> ( istream&, FGTower& );
253 #endif //_FG_TOWER_HXX