1 // FGGround - a class to provide ground control at larger 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.
21 #ifndef _FG_GROUND_HXX
22 #define _FG_GROUND_HXX
28 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
35 #include <simgear/math/point3d.hxx>
36 #include <simgear/misc/sgstream.hxx>
37 #include <simgear/math/sg_geodesy.hxx>
40 #include "ATCProjection.hxx"
46 //////////////////////////////////////////////////////
47 // Types for the logical network data structure
48 typedef enum arc_type {
53 typedef enum node_type {
63 TRANSPORT_PASSENGER_NARROWBODY,
64 TRANSPORT_PASSENGER_WIDEBODY,
72 OTHER // ie. anything goes!!
75 typedef enum network_element_type {
80 struct ground_network_element {
81 network_element_type struct_type;
84 struct arc : public ground_network_element {
88 bool directed; //false if 2-way, true if 1-way.
89 //This is a can of worms since arcs might be one way in different directions under different circumstances
90 unsigned int n1; // The nodeID of the first node
91 unsigned int n2; // The nodeID of the second node
92 // If the arc is directed then flow is normally from n1 to n2. See the above can of worms comment though.
95 typedef vector <arc*> arc_array_type; // This was and may become again a list instead of vector
96 typedef arc_array_type::iterator arc_array_iterator;
97 typedef arc_array_type::const_iterator arc_array_const_iterator;
99 struct node : public ground_network_element {
100 unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
106 double max_turn_radius;
109 typedef vector <node*> node_array_type;
110 typedef node_array_type::iterator node_array_iterator;
111 typedef node_array_type::const_iterator node_array_const_iterator;
113 struct Gate : public node {
115 int max_weight; //units??
116 //airline_code airline; //For the future - we don't have any airline codes ATM
117 int id; // The gate number in the logical scheme of things
118 string sid; // The real-world gate letter/number
121 double heading; // The direction the parked-up plane should point in degrees
124 typedef vector < Gate > gate_vec_type;
125 typedef gate_vec_type::iterator gate_vec_iterator;
126 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
128 // A map of gate vs. the logical (internal FGFS) gate ID
129 typedef map < int, Gate > gate_map_type;
130 typedef gate_map_type::iterator gate_map_iterator;
131 typedef gate_map_type::const_iterator gate_map_const_iterator;
133 // Runways - all the runway stuff is likely to change in the future
135 int id; //note this is a very simplified scheme for now - R & L are not differentiated
136 //It should work for simple one rwy airports
137 node_array_type exits; //Array of available exits from runway
138 // should probably add an FGRunway structure here as well eventually
139 // Eventually we will also want some encoding of real-life preferred runways
140 // This will get us up and running for single runway airports though.
142 typedef vector < Rwy > runway_array_type;
143 typedef runway_array_type::iterator runway_array_iterator;
144 typedef runway_array_type::const_iterator runway_array_const_iterator;
146 // end logical network types
147 ///////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////
150 // Structures to use the network
152 // A path through the network
153 typedef vector < ground_network_element* > ground_network_path_type;
154 typedef ground_network_path_type::iterator ground_network_path_iterator;
155 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
157 //////////////////////////////////////////////////////////////////////////////////////////
159 // Planes active within the ground network.
160 // somewhere in the ATC/AI system we are going to have defined something like
161 // typedef struct plane_rec
162 // list <PlaneRec> plane_rec_list_type
164 // A more specialist plane rec to include ground information
165 typedef struct ground_rec {
170 bool cleared; // set true when the plane has been cleared to somewhere
171 bool incoming; //true for arrivals, false for departures
173 // Almost certainly need to add more here
176 typedef list<ground_rec*> ground_rec_list;
177 typedef ground_rec_list::iterator ground_rec_list_itr;
178 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
180 //////////////////////////////////////////////////////////////////////////////////////////
182 ///////////////////////////////////////////////////////////////////////////////
186 ///////////////////////////////////////////////////////////////////////////////
187 class FGGround : public FGATC {
196 inline char get_type() const { return type; }
197 inline double get_lon() const { return lon; }
198 inline double get_lat() const { return lat; }
199 inline double get_elev() const { return elev; }
200 inline double get_x() const { return x; }
201 inline double get_y() const { return y; }
202 inline double get_z() const { return z; }
203 inline int get_freq() const { return freq; }
204 inline int get_range() const { return range; }
205 inline const char* GetIdent() { return ident.c_str(); }
206 inline string get_trans_ident() { return trans_ident; }
207 inline string get_name() { return name; }
208 inline atc_type GetType() { return GROUND; }
210 inline void SetDisplay() {display = true;}
211 inline void SetNoDisplay() {display = false;}
213 // Its possible that NewArrival and NewDeparture should simply be rolled into Request.
215 // Contact ground control on arrival, assumed to request any gate
216 //void NewArrival(plane_rec plane);
218 // Contact ground control on departure, assumed to request currently active runway.
219 //void NewDeparture(plane_rec plane);
221 // Contact ground control when the calling routine doesn't know if arrival
222 // or departure is appropriate.
223 //void NewContact(plane_rec plane);
225 // Make a request of ground control.
226 //void Request(ground_request request);
228 // Randomly fill some of the available gates and GA parking spots with planes
229 void PopulateGates();
231 // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
232 void ReturnGate(Gate &gate, GateType type);
234 //The following two functions have been made public for now but may go private with a higher level accessor at some point
235 // Return the internal ID of a random, suitable, unused gate
236 // For now we are simply implementing as any random unused gate
237 int GetRandomGateID();
238 // Return a pointer to a node based on the gate ID
239 Gate* GetGateNode(int gateID);
241 // Runway stuff - this might change in the future.
242 // Get a list of exits from a given runway
243 node_array_type GetExits(int rwyID);
245 // Get a path from one node to another
246 ground_network_path_type GetPath(node* A, node* B);
250 // Need a data structure to hold details of the various active planes
251 // Need a data structure to hold details of the logical network
252 // including which gates are filled - or possibly another data structure
253 // with the positions of the inactive planes.
254 // Need a data structure to hold outstanding communications from aircraft.
255 // Possibly need a data structure to hold outstanding communications to aircraft.
257 // The logical network
258 // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
259 // ie. NODE 5 WILL BE AT network[5]
260 node_array_type network;
262 // A map of all the gates indexed against internal (FGFS) ID
264 gate_map_iterator gatesItr;
266 // Runway stuff - this might change in the future.
267 //runway_array_type runways; // STL way
268 Rwy runways[36]; // quick hack!
270 FGATCAlignedProjection ortho;
272 // Planes currently active
273 //ground_rec_list ground_traffic;
275 // Find the shortest route through the logical network between two points.
276 //FindShortestRoute(point a, point b);
278 // Project a point in WGS84 lat/lon onto the local gnomonic.
279 //ConvertWGS84ToXY(sgVec3 wgs84, point xy);
281 // Assign a gate or parking location to a new arrival
282 //AssignGate(ground_rec &g);
284 // Generate the next clearance for an airplane
285 //NextClearance(ground_rec &g);
293 bool display; // Flag to indicate whether we should be outputting to the ATC display.
294 bool displaying; // Flag to indicate whether we are outputting to the ATC display.
295 string ident; // Code of the airport its at.
296 string name; // Name generally used in transmissions.
297 // for failure modeling
298 string trans_ident; // transmitted ident
299 bool ground_failed; // ground failed?
301 friend istream& operator>> ( istream&, FGGround& );
305 operator >> ( istream& in, FGGround& g )
313 return in >> skipeol;
315 in >> g.lat >> g.lon >> g.elev >> f >> g.range
323 in.unsetf(ios::skipws);
326 if((ch == '"') || (ch == 0x0A)) {
328 } // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
330 in.setf(ios::skipws);
331 //cout << "tower.name = " << t.name << '\n';
333 g.freq = (int)(f*100.0 + 0.5);
335 // cout << g.ident << endl;
337 // generate cartesian coordinates
338 Point3D geod( g.lon * SGD_DEGREES_TO_RADIANS, g.lat * SGD_DEGREES_TO_RADIANS, g.elev );
339 Point3D cart = sgGeodToCart( geod );
344 g.trans_ident = g.ident;
345 g.ground_failed = false;
347 return in >> skipeol;
350 #endif // _FG_GROUND_HXX