]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ground.hxx
Changes towards ground control and AI taxiing currently very hardwired to KEMT
[flightgear.git] / src / ATC / ground.hxx
1 // FGGround - a class to provide ground control at larger 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_GROUND_HXX
22 #define _FG_GROUND_HXX
23
24 #include STL_IOSTREAM
25 #include STL_STRING
26
27 SG_USING_STD(string);
28 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
29 SG_USING_STD(ios);
30 #endif
31
32 #include <map>
33 #include <vector>
34 #include <list>
35 #include <simgear/math/point3d.hxx>
36 #include <simgear/misc/sgstream.hxx>
37 #include <simgear/math/sg_geodesy.hxx>
38
39 #include "ATC.hxx"
40 #include "ATCProjection.hxx"
41
42 SG_USING_STD(map);
43 SG_USING_STD(vector);
44 SG_USING_STD(list);
45
46 //////////////////////////////////////////////////////
47 // Types for the logical network data structure
48 typedef enum arc_type {
49         RUNWAY,
50         TAXIWAY
51 };
52
53 typedef enum node_type {
54         GATE,
55         APRON,
56         HOLD,
57         JUNCTION,
58         TJUNCTION
59 };
60
61 enum GateType {
62         TRANSPORT_PASSENGER,
63         TRANSPORT_PASSENGER_NARROWBODY,
64         TRANSPORT_PASSENGER_WIDEBODY,
65         TRANSPORT_CARGO,
66         GA_LOCAL,
67         GA_LOCAL_SINGLE,
68         GA_LOCAL_TWIN,
69         GA_TRANSIENT,
70         GA_TRANSIENT_SINGLE,
71         GA_TRANSIENT_TWIN,
72         OTHER   // ie. anything goes!!
73 };
74
75 typedef enum network_element_type {
76         NODE,
77         ARC
78 };
79
80 struct ground_network_element {
81         network_element_type struct_type;
82 };
83
84 struct arc : public ground_network_element {
85         int distance;
86         char* name;
87         arc_type type;
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.
93 };
94
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; 
98
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
101         Point3D pos;
102         Point3D orthoPos;
103         char* name;
104         node_type type;
105         arc_array_type arcs;
106         double max_turn_radius;
107 };
108
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;
112
113 struct Gate : public node {
114         GateType gateType;
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
119         //node* pNode;
120         bool used;
121         double heading; // The direction the parked-up plane should point in degrees
122 };
123
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;
127
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;
132
133 // Runways - all the runway stuff is likely to change in the future
134 typedef struct Rwy {
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.
141 };
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;
145
146 // end logical network types
147 ///////////////////////////////////////////////////////
148
149 ///////////////////////////////////////////////////////
150 // Structures to use the network
151
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;
156
157 //////////////////////////////////////////////////////////////////////////////////////////
158
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
163 /*
164 // A more specialist plane rec to include ground information
165 typedef struct ground_rec {
166     plane_rec plane;
167     point current_pos;
168     node destination;
169     node last_clearance;
170     bool cleared;  // set true when the plane has been cleared to somewhere
171     bool incoming; //true for arrivals, false for departures
172     // status?
173     // Almost certainly need to add more here
174 };
175
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;
179 */
180 //////////////////////////////////////////////////////////////////////////////////////////
181
182 ///////////////////////////////////////////////////////////////////////////////
183 //
184 // FGGround
185 //
186 ///////////////////////////////////////////////////////////////////////////////
187 class FGGround : public FGATC {
188
189 public:
190         FGGround();
191         ~FGGround();
192     void Init();
193
194     void Update();
195         
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; }
209
210     inline void SetDisplay() {display = true;}
211     inline void SetNoDisplay() {display = false;}
212
213     // Its possible that NewArrival and NewDeparture should simply be rolled into Request.
214
215     // Contact ground control on arrival, assumed to request any gate
216     //void NewArrival(plane_rec plane);
217
218     // Contact ground control on departure, assumed to request currently active runway.
219     //void NewDeparture(plane_rec plane);
220
221     // Contact ground control when the calling routine doesn't know if arrival
222     // or departure is appropriate.
223     //void NewContact(plane_rec plane);
224
225     // Make a request of ground control.
226     //void Request(ground_request request);
227         
228         // Randomly fill some of the available gates and GA parking spots with planes
229         void PopulateGates();
230         
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);
233         
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);
240         
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);
244         
245         // Get a path from one node to another
246         ground_network_path_type GetPath(node* A, node* B); 
247
248 private:
249
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.
256
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;
261         
262         // A map of all the gates indexed against internal (FGFS) ID
263         gate_map_type gates;
264         gate_map_iterator gatesItr;
265         
266         // Runway stuff - this might change in the future.
267         //runway_array_type runways;    // STL way
268         Rwy runways[36];        // quick hack!
269
270         FGATCAlignedProjection ortho;
271         
272         // Planes currently active
273     //ground_rec_list ground_traffic;
274
275     // Find the shortest route through the logical network between two points.
276     //FindShortestRoute(point a, point b);
277
278     // Project a point in WGS84 lat/lon onto the local gnomonic.
279     //ConvertWGS84ToXY(sgVec3 wgs84, point xy);
280
281     // Assign a gate or parking location to a new arrival
282     //AssignGate(ground_rec &g);
283
284     // Generate the next clearance for an airplane
285     //NextClearance(ground_rec &g);
286         
287         char type;
288         double lon, lat;
289         double elev;
290         double x, y, z;
291         int freq;
292         int range;
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?
300         
301         friend istream& operator>> ( istream&, FGGround& );
302 };
303
304 inline istream&
305 operator >> ( istream& in, FGGround& g )
306 {
307         double f;
308         char ch;
309         
310         in >> g.type;
311         
312         if ( g.type == '[' )
313                 return in >> skipeol;
314         
315         in >> g.lat >> g.lon >> g.elev >> f >> g.range 
316         >> g.ident;
317         
318         g.name = "";
319         in >> ch;
320         g.name += ch;
321         while(1) {
322                 //in >> noskipws
323                 in.unsetf(ios::skipws);
324                 in >> ch;
325                 g.name += ch;
326                 if((ch == '"') || (ch == 0x0A)) {
327                         break;
328                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
329         }
330         in.setf(ios::skipws);
331         //cout << "tower.name = " << t.name << '\n';
332         
333         g.freq = (int)(f*100.0 + 0.5);
334         
335         // cout << g.ident << endl;
336         
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 );
340         g.x = cart.x();
341         g.y = cart.y();
342         g.z = cart.z();
343         
344         g.trans_ident = g.ident;
345         g.ground_failed = false;
346         
347         return in >> skipeol;
348 }
349
350 #endif  // _FG_GROUND_HXX
351