]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ground.hxx
Fix compiler warning
[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 SG_USING_STD(ios);
29
30 #include <map>
31 #include <vector>
32 #include <list>
33 #include <simgear/math/point3d.hxx>
34 #include <simgear/misc/sgstream.hxx>
35 #include <simgear/math/sg_geodesy.hxx>
36
37 #include "ATC.hxx"
38 #include "ATCProjection.hxx"
39
40 SG_USING_STD(map);
41 SG_USING_STD(vector);
42 SG_USING_STD(list);
43
44 //////////////////////////////////////////////////////
45 // Types for the logical network data structure
46 typedef enum arc_type {
47         RUNWAY,
48         TAXIWAY
49 };
50
51 typedef enum node_type {
52         GATE,
53         APRON,
54         HOLD,
55         JUNCTION,
56         TJUNCTION
57 };
58
59 enum GateType {
60         TRANSPORT_PASSENGER,
61         TRANSPORT_PASSENGER_NARROWBODY,
62         TRANSPORT_PASSENGER_WIDEBODY,
63         TRANSPORT_CARGO,
64         GA_LOCAL,
65         GA_LOCAL_SINGLE,
66         GA_LOCAL_TWIN,
67         GA_TRANSIENT,
68         GA_TRANSIENT_SINGLE,
69         GA_TRANSIENT_TWIN,
70         OTHER   // ie. anything goes!!
71 };
72
73 typedef enum network_element_type {
74         NODE,
75         ARC
76 };
77
78 struct ground_network_element {
79         network_element_type struct_type;
80 };
81
82 struct arc : public ground_network_element {
83         int distance;
84         string name;
85         arc_type type;
86         bool directed;  //false if 2-way, true if 1-way.  
87         //This is a can of worms since arcs might be one way in different directions under different circumstances
88         unsigned int n1;        // The nodeID of the first node
89         unsigned int n2;        // The nodeID of the second node
90         // If the arc is directed then flow is normally from n1 to n2.  See the above can of worms comment though.
91 };
92
93 typedef vector <arc*> arc_array_type;   // This was and may become again a list instead of vector
94 typedef arc_array_type::iterator arc_array_iterator;
95 typedef arc_array_type::const_iterator arc_array_const_iterator; 
96
97 struct node : public ground_network_element {
98         unsigned int nodeID;    //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
99         Point3D pos;
100         Point3D orthoPos;
101         char* name;
102         node_type type;
103         arc_array_type arcs;
104         double max_turn_radius;
105 };
106
107 typedef vector <node*> node_array_type;
108 typedef node_array_type::iterator node_array_iterator;
109 typedef node_array_type::const_iterator node_array_const_iterator;
110
111 struct Gate : public node {
112         GateType gateType;
113         int max_weight; //units??
114         //airline_code airline; //For the future - we don't have any airline codes ATM
115         int id; // The gate number in the logical scheme of things
116         string sid;     // The real-world gate letter/number
117         //node* pNode;
118         bool used;
119         double heading; // The direction the parked-up plane should point in degrees
120 };
121
122 typedef vector < Gate > gate_vec_type;
123 typedef gate_vec_type::iterator gate_vec_iterator;
124 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
125
126 // A map of gate vs. the logical (internal FGFS) gate ID
127 typedef map < int, Gate > gate_map_type;
128 typedef gate_map_type::iterator gate_map_iterator;
129 typedef gate_map_type::const_iterator gate_map_const_iterator;
130
131 // Runways - all the runway stuff is likely to change in the future
132 typedef struct Rwy {
133         int id; //note this is a very simplified scheme for now - R & L are not differentiated
134         //It should work for simple one rwy airports
135         node_array_type exits;  //Array of available exits from runway
136         // should probably add an FGRunway structure here as well eventually
137         // Eventually we will also want some encoding of real-life preferred runways
138         // This will get us up and running for single runway airports though.
139 };
140 typedef vector < Rwy > runway_array_type;
141 typedef runway_array_type::iterator runway_array_iterator;
142 typedef runway_array_type::const_iterator runway_array_const_iterator;
143
144 // end logical network types
145 ///////////////////////////////////////////////////////
146
147 ///////////////////////////////////////////////////////
148 // Structures to use the network
149
150 // A path through the network 
151 typedef vector < ground_network_element* > ground_network_path_type;
152 typedef ground_network_path_type::iterator ground_network_path_iterator;
153 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
154
155 //////////////////////////////////////////////////////////////////////////////////////////
156
157 // Planes active within the ground network.
158 // somewhere in the ATC/AI system we are going to have defined something like
159 // typedef struct plane_rec
160 // list <PlaneRec> plane_rec_list_type
161 /*
162 // A more specialist plane rec to include ground information
163 typedef struct ground_rec {
164     plane_rec plane;
165     point current_pos;
166     node destination;
167     node last_clearance;
168     bool cleared;  // set true when the plane has been cleared to somewhere
169     bool incoming; //true for arrivals, false for departures
170     // status?
171     // Almost certainly need to add more here
172 };
173
174 typedef list<ground_rec*> ground_rec_list;
175 typedef ground_rec_list::iterator ground_rec_list_itr;
176 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
177 */
178 //////////////////////////////////////////////////////////////////////////////////////////
179
180 ///////////////////////////////////////////////////////////////////////////////
181 //
182 // FGGround
183 //
184 ///////////////////////////////////////////////////////////////////////////////
185 class FGGround : public FGATC {
186
187 public:
188         FGGround();
189         ~FGGround();
190     void Init();
191
192     void Update();
193         
194         inline char get_type() const { return type; }
195         inline double get_lon() const { return lon; }
196         inline double get_lat() const { return lat; }
197         inline double get_elev() const { return elev; }
198         inline double get_x() const { return x; }
199         inline double get_y() const { return y; }
200         inline double get_z() const { return z; }
201         inline int get_freq() const { return freq; }
202         inline int get_range() const { return range; }
203         inline const char* GetIdent() { return ident.c_str(); }
204         inline string get_trans_ident() { return trans_ident; }
205         inline string get_name() { return name; }
206         inline atc_type GetType() { return GROUND; }
207
208     inline void SetDisplay() {display = true;}
209     inline void SetNoDisplay() {display = false;}
210
211     // Its possible that NewArrival and NewDeparture should simply be rolled into Request.
212
213     // Contact ground control on arrival, assumed to request any gate
214     //void NewArrival(plane_rec plane);
215
216     // Contact ground control on departure, assumed to request currently active runway.
217     //void NewDeparture(plane_rec plane);
218
219     // Contact ground control when the calling routine doesn't know if arrival
220     // or departure is appropriate.
221     //void NewContact(plane_rec plane);
222
223     // Make a request of ground control.
224     //void Request(ground_request request);
225         
226         // Randomly fill some of the available gates and GA parking spots with planes
227         void PopulateGates();
228         
229         // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
230         void ReturnGate(Gate &gate, GateType type);
231         
232         //The following two functions have been made public for now but may go private with a higher level accessor at some point
233         // Return the internal ID of a random, suitable, unused gate
234         // For now we are simply implementing as any random unused gate
235         int GetRandomGateID();
236         // Return a pointer to a node based on the gate ID
237         Gate* GetGateNode(int gateID);
238         
239         // Runway stuff - this might change in the future.
240         // Get a list of exits from a given runway
241         // It is up to the calling function to check for non-zero size of returned array before use
242         node_array_type GetExits(int rwyID);
243         
244         // Get a path from one node to another
245         ground_network_path_type GetPath(node* A, node* B); 
246
247 private:
248
249     // Need a data structure to hold details of the various active planes
250     // Need a data structure to hold details of the logical network
251     // including which gates are filled - or possibly another data structure
252     // with the positions of the inactive planes.
253     // Need a data structure to hold outstanding communications from aircraft.
254     // Possibly need a data structure to hold outstanding communications to aircraft.
255
256         // The logical network
257         // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
258         // ie. NODE 5 WILL BE AT network[5]
259     node_array_type network;
260         
261         // A map of all the gates indexed against internal (FGFS) ID
262         gate_map_type gates;
263         gate_map_iterator gatesItr;
264         
265         // Runway stuff - this might change in the future.
266         //runway_array_type runways;    // STL way
267         Rwy runways[36];        // quick hack!
268
269         FGATCAlignedProjection ortho;
270         
271         // Planes currently active
272     //ground_rec_list ground_traffic;
273
274     // Find the shortest route through the logical network between two points.
275     //FindShortestRoute(point a, point b);
276
277     // Project a point in WGS84 lat/lon onto the local gnomonic.
278     //ConvertWGS84ToXY(sgVec3 wgs84, point xy);
279
280     // Assign a gate or parking location to a new arrival
281     //AssignGate(ground_rec &g);
282
283     // Generate the next clearance for an airplane
284     //NextClearance(ground_rec &g);
285         
286         char type;
287         double lon, lat;
288         double elev;
289         double x, y, z;
290         int freq;
291         int range;
292         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
293         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
294         string ident;           // Code of the airport its at.
295         string name;            // Name generally used in transmissions.
296         // for failure modeling
297         string trans_ident;             // transmitted ident
298         bool ground_failed;             // ground failed?
299         bool networkLoadOK;             // Indicates whether LoadNetwork returned true or false at last attempt
300         
301         friend istream& operator>> ( istream&, FGGround& );
302         
303         // Load the logical ground network for this airport from file.
304         // Return true if successfull.
305         bool LoadNetwork();
306         
307         // Parse a runway exit string and push the supplied node pointer onto the runway exit list
308         void ParseRwyExits(node* np, char* es);
309 };
310
311 inline istream&
312 operator >> ( istream& in, FGGround& g )
313 {
314         double f;
315         char ch;
316         
317         in >> g.type;
318         
319         if ( g.type == '[' )
320                 return in >> skipeol;
321         
322         in >> g.lat >> g.lon >> g.elev >> f >> g.range 
323         >> g.ident;
324         
325         g.name = "";
326         in >> ch;
327         g.name += ch;
328         while(1) {
329                 //in >> noskipws
330                 in.unsetf(ios::skipws);
331                 in >> ch;
332                 g.name += ch;
333                 if((ch == '"') || (ch == 0x0A)) {
334                         break;
335                 }   // we shouldn't need the 0x0A but it makes a nice safely in case someone leaves off the "
336         }
337         in.setf(ios::skipws);
338         //cout << "tower.name = " << t.name << '\n';
339         
340         g.freq = (int)(f*100.0 + 0.5);
341         
342         // cout << g.ident << endl;
343         
344         // generate cartesian coordinates
345         Point3D geod( g.lon * SGD_DEGREES_TO_RADIANS, g.lat * SGD_DEGREES_TO_RADIANS, g.elev );
346         Point3D cart = sgGeodToCart( geod );
347         g.x = cart.x();
348         g.y = cart.y();
349         g.z = cart.z();
350         
351         g.trans_ident = g.ident;
352         g.ground_failed = false;
353         
354         return in >> skipeol;
355 }
356
357 #endif  // _FG_GROUND_HXX
358