]> git.mxchange.org Git - flightgear.git/blob - src/ATC/ground.hxx
Compiler warning fixes and small updates
[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 enum arc_type {
47         RUNWAY,
48         TAXIWAY
49 };
50
51 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 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         node();
99         ~node();
100         
101         unsigned int nodeID;    //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
102         Point3D pos;
103         Point3D orthoPos;
104         string name;
105         node_type type;
106         arc_array_type arcs;
107         double max_turn_radius;
108 };
109
110 typedef vector <node*> node_array_type;
111 typedef node_array_type::iterator node_array_iterator;
112 typedef node_array_type::const_iterator node_array_const_iterator;
113
114 struct Gate : public node {
115         GateType gateType;
116         int max_weight; //units??
117         //airline_code airline; //For the future - we don't have any airline codes ATM
118         int id; // The gate number in the logical scheme of things
119         string name;    // The real-world gate letter/number
120         //node* pNode;
121         bool used;
122         double heading; // The direction the parked-up plane should point in degrees
123 };
124
125 typedef vector < Gate* > gate_vec_type;
126 typedef gate_vec_type::iterator gate_vec_iterator;
127 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
128
129 // A map of gate vs. the logical (internal FGFS) gate ID
130 typedef map < int, Gate* > gate_map_type;
131 typedef gate_map_type::iterator gate_map_iterator;
132 typedef gate_map_type::const_iterator gate_map_const_iterator;
133
134 // Runways - all the runway stuff is likely to change in the future
135 typedef struct Rwy {
136         int id; //note this is a very simplified scheme for now - R & L are not differentiated
137         //It should work for simple one rwy airports
138         node_array_type exits;  //Array of available exits from runway
139         // should probably add an FGRunway structure here as well eventually
140         // Eventually we will also want some encoding of real-life preferred runways
141         // This will get us up and running for single runway airports though.
142 };
143 typedef vector < Rwy > runway_array_type;
144 typedef runway_array_type::iterator runway_array_iterator;
145 typedef runway_array_type::const_iterator runway_array_const_iterator;
146
147 // end logical network types
148 ///////////////////////////////////////////////////////
149
150 ///////////////////////////////////////////////////////
151 // Structures to use the network
152
153 // A path through the network 
154 typedef vector < ground_network_element* > ground_network_path_type;
155 typedef ground_network_path_type::iterator ground_network_path_iterator;
156 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
157
158 //////////////////////////////////////////////////////////////////////////////////////////
159
160 ////////////////////////////////////////////////
161 //
162 // Stuff for the shortest-path algorithms
163 struct a_path {
164         a_path();
165         
166         ground_network_path_type path;
167         int cost;
168 };
169
170 // Paths mapped by nodeID reached so-far
171 typedef map < unsigned int, a_path* > shortest_path_map_type;
172 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
173
174 // Nodes mapped by their ID
175 //typedef map < unsigned int, node* > node_map_type;
176 //typedef node_map_type::iterator node_map_iterator;
177 ////////////////////////////////////////////////
178
179 // Planes active within the ground network.
180 // somewhere in the ATC/AI system we are going to have defined something like
181 // typedef struct plane_rec
182 // list <PlaneRec> plane_rec_list_type
183 /*
184 // A more specialist plane rec to include ground information
185 typedef struct ground_rec {
186     plane_rec plane;
187     point current_pos;
188     node destination;
189     node last_clearance;
190     bool cleared;  // set true when the plane has been cleared to somewhere
191     bool incoming; //true for arrivals, false for departures
192     // status?
193     // Almost certainly need to add more here
194 };
195
196 typedef list<ground_rec*> ground_rec_list;
197 typedef ground_rec_list::iterator ground_rec_list_itr;
198 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
199 */
200 //////////////////////////////////////////////////////////////////////////////////////////
201
202 ///////////////////////////////////////////////////////////////////////////////
203 //
204 // FGGround
205 //
206 ///////////////////////////////////////////////////////////////////////////////
207 class FGGround : public FGATC {
208
209 public:
210         FGGround();
211         FGGround(string id);
212         ~FGGround();
213     void Init();
214
215     void Update();
216         
217         inline string get_trans_ident() { return trans_ident; }
218         inline atc_type GetType() { return GROUND; }
219     inline void SetDisplay() {display = true;}
220     inline void SetNoDisplay() {display = false;}
221
222     // Its possible that NewArrival and NewDeparture should simply be rolled into Request.
223
224     // Contact ground control on arrival, assumed to request any gate
225     //void NewArrival(plane_rec plane);
226
227     // Contact ground control on departure, assumed to request currently active runway.
228     //void NewDeparture(plane_rec plane);
229
230     // Contact ground control when the calling routine doesn't know if arrival
231     // or departure is appropriate.
232     //void NewContact(plane_rec plane);
233
234     // Make a request of ground control.
235     //void Request(ground_request request);
236         
237         // Randomly fill some of the available gates and GA parking spots with planes
238         void PopulateGates();
239         
240         // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
241         void ReturnGate(Gate &gate, GateType type);
242         
243         // Return a pointer to an unused gate
244         Gate* GetGateNode();
245         
246         // Runway stuff - this might change in the future.
247         // Get a list of exits from a given runway
248         // It is up to the calling function to check for non-zero size of returned array before use
249         node_array_type GetExits(int rwyID);
250         
251         // Get a path from one node to another
252         ground_network_path_type GetPath(node* A, node* B);
253         
254         // Get a path from a node to a runway threshold
255         ground_network_path_type GetPath(node* A, string rwyID);
256
257 private:
258
259     // Need a data structure to hold details of the various active planes
260     // Need a data structure to hold details of the logical network
261     // including which gates are filled - or possibly another data structure
262     // with the positions of the inactive planes.
263     // Need a data structure to hold outstanding communications from aircraft.
264     // Possibly need a data structure to hold outstanding communications to aircraft.
265
266         // The logical network
267         // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
268         // ie. NODE 5 WILL BE AT network[5]
269     node_array_type network;
270         
271         // A map of all the gates indexed against internal (FGFS) ID
272         gate_map_type gates;
273         gate_map_iterator gatesItr;
274         
275         // Runway stuff - this might change in the future.
276         //runway_array_type runways;    // STL way
277         Rwy runways[36];        // quick hack!
278
279         FGATCAlignedProjection ortho;
280         
281         // Planes currently active
282     //ground_rec_list ground_traffic;
283
284     // Find the shortest route through the logical network between two points.
285     //FindShortestRoute(point a, point b);
286
287     // Project a point in WGS84 lat/lon onto the local gnomonic.
288     //ConvertWGS84ToXY(sgVec3 wgs84, point xy);
289
290     // Assign a gate or parking location to a new arrival
291     //AssignGate(ground_rec &g);
292
293     // Generate the next clearance for an airplane
294     //NextClearance(ground_rec &g);
295         
296         bool display;           // Flag to indicate whether we should be outputting to the ATC display.
297         bool displaying;                // Flag to indicate whether we are outputting to the ATC display.
298         // for failure modeling
299         string trans_ident;             // transmitted ident
300         bool ground_failed;             // ground failed?
301         bool networkLoadOK;             // Indicates whether LoadNetwork returned true or false at last attempt
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         // Return a random gate ID of an unused gate.
311         // Two error values may be returned and must be checked for by the calling function:
312         // -2 signifies that no gates exist at this airport.
313         // -1 signifies that all gates are currently full.
314         // TODO - modify to return a suitable gate based on aircraft size/weight.
315         int GetRandomGateID();
316         
317         // Return a pointer to the node at a runway threshold
318         // Returns NULL if unsuccessful.
319         node* GetThresholdNode(string rwyID);
320         
321         // A shortest path algorithm sort of from memory (I can't find the bl&*dy book again!)
322         ground_network_path_type GetShortestPath(node* A, node* B); 
323 };
324
325 #endif  // _FG_GROUND_HXX
326