]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ground.hxx
Merge branch 'tbm/graphics-bug' into next
[flightgear.git] / src / ATCDCL / 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef _FG_GROUND_HXX
22 #define _FG_GROUND_HXX
23
24 #include <map>
25 #include <vector>
26 #include <list>
27
28 #include <simgear/math/point3d.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/props/props.hxx>
32
33 #include "ATC.hxx"
34 #include "ATCProjection.hxx"
35
36 #include <string>
37
38 class FGAIEntity;
39 class FGATCMgr;
40
41 //////////////////////////////////////////////////////
42 // Types for the logical network data structure
43 enum arc_type {
44         RUNWAY,
45         TAXIWAY
46 };
47
48 enum node_type {
49         GATE,
50         APRON,
51         HOLD,
52         JUNCTION,
53         TJUNCTION
54 };
55
56 enum GateType {
57         TRANSPORT_PASSENGER,
58         TRANSPORT_PASSENGER_NARROWBODY,
59         TRANSPORT_PASSENGER_WIDEBODY,
60         TRANSPORT_CARGO,
61         GA_LOCAL,
62         GA_LOCAL_SINGLE,
63         GA_LOCAL_TWIN,
64         GA_TRANSIENT,
65         GA_TRANSIENT_SINGLE,
66         GA_TRANSIENT_TWIN,
67         OTHER   // ie. anything goes!!
68 };
69
70 enum network_element_type {
71         NODE,
72         ARC
73 };
74
75 struct ground_network_element {
76         network_element_type struct_type;
77 };
78
79 struct arc : public ground_network_element {
80         int distance;
81         std::string name;
82         arc_type type;
83         bool directed;  //false if 2-way, true if 1-way.  
84         //This is a can of worms since arcs might be one way in different directions under different circumstances
85         unsigned int n1;        // The nodeID of the first node
86         unsigned int n2;        // The nodeID of the second node
87         // If the arc is directed then flow is normally from n1 to n2.  See the above can of worms comment though.
88 };
89
90 typedef std::vector <arc*> arc_array_type;      // This was and may become again a list instead of vector
91 typedef arc_array_type::iterator arc_array_iterator;
92 typedef arc_array_type::const_iterator arc_array_const_iterator; 
93
94 struct node : public ground_network_element {
95         node();
96         ~node();
97         
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         std::string name;
102         node_type type;
103         arc_array_type arcs;
104         double max_turn_radius;
105 };
106
107 typedef std::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         std::string name;       // 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 std::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 std::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 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
141 typedef std::vector < Rwy > runway_array_type;
142 typedef runway_array_type::iterator runway_array_iterator;
143 typedef runway_array_type::const_iterator runway_array_const_iterator;
144
145 // end logical network types
146 ///////////////////////////////////////////////////////
147
148 ///////////////////////////////////////////////////////
149 // Structures to use the network
150
151 // A path through the network 
152 typedef std::vector < ground_network_element* > ground_network_path_type;
153 typedef ground_network_path_type::iterator ground_network_path_iterator;
154 typedef ground_network_path_type::const_iterator ground_network_path_const_iterator;
155
156 //////////////////////////////////////////////////////////////////////////////////////////
157
158 ////////////////////////////////////////////////
159 //
160 // Stuff for the shortest-path algorithms
161 struct a_path {
162         a_path();
163         
164         ground_network_path_type path;
165         int cost;
166 };
167
168 // Paths mapped by nodeID reached so-far
169 typedef std::map < unsigned int, a_path* > shortest_path_map_type;
170 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
171
172 // Nodes mapped by their ID
173 //typedef map < unsigned int, node* > node_map_type;
174 //typedef node_map_type::iterator node_map_iterator;
175 ////////////////////////////////////////////////
176
177 // Planes active within the ground network.
178
179 // A more specialist plane rec to include ground information
180 struct GroundRec {
181         FGAIEntity* planePtr;   // This might move to the planeRec eventually
182         
183     PlaneRec plane;
184     Point3D current_pos;
185     node* destination;
186     node* last_clearance;
187         bool taxiRequestOutstanding;    // Plane has requested taxi and we haven't responded yet
188         double clearanceCounter;                // Hack for communication timing - counter since clearance requested in seconds 
189         
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 std::list < GroundRec* > 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 // Hack
203 // perhaps we could use an FGRunway instead of this
204 struct GRunwayDetails {
205         Point3D threshold_pos;
206         Point3D end1ortho;      // ortho projection end1 (the threshold ATM)
207         Point3D end2ortho;      // ortho projection end2 (the take off end in the current hardwired scheme)
208         double hdg;             // true runway heading
209         double length;  // In *METERS*
210         std::string rwyID;
211 };
212
213 ///////////////////////////////////////////////////////////////////////////////
214 //
215 // FGGround
216 //
217 ///////////////////////////////////////////////////////////////////////////////
218 class FGGround : public FGATC {
219
220 public:
221         FGGround();
222         FGGround(const std::string& id);
223         ~FGGround();
224     void Init();
225
226     void Update(double dt);
227         
228         inline const std::string& get_trans_ident() { return trans_ident; }
229
230     // Contact ground control on arrival, assumed to request any gate
231     //void NewArrival(plane_rec plane);
232
233     // Contact ground control on departure, assumed to request currently active runway.
234     void RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
235
236     // Contact ground control when the calling routine doesn't know if arrival
237     // or departure is appropriate.
238     //void NewContact(plane_rec plane);
239
240     // Make a request of ground control.
241     //void Request(ground_request request);
242         
243         // Randomly fill some of the available gates and GA parking spots with planes
244         void PopulateGates();
245         
246         // Return a suitable gate (maybe this should be a list of suitable gates so the plane or controller can choose the closest one)
247         void ReturnGate(Gate &gate, GateType type);
248         
249         // Return a pointer to an unused gate
250         Gate* GetGateNode();
251         
252         // Return a pointer to a hold short node
253         node* GetHoldShortNode(const std::string& rwyID);
254         
255         // Runway stuff - this might change in the future.
256         // Get a list of exits from a given runway
257         // It is up to the calling function to check for non-zero size of returned array before use
258         node_array_type GetExits(const std::string& rwyID);
259         
260         // Get a path from one node to another
261         ground_network_path_type GetPath(node* A, node* B);
262         
263         // Get a path from a node to a runway threshold
264         ground_network_path_type GetPath(node* A, const std::string& rwyID);
265         
266         // Get a path from a node to a runway hold short point
267         // Bit of a hack this at the moment!
268         ground_network_path_type GetPathToHoldShort(node* A, const std::string& rwyID);
269
270 private:
271         FGATCMgr* ATCmgr;       
272         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
273         
274     // Need a data structure to hold details of the various active planes
275     // Need a data structure to hold details of the logical network
276     // including which gates are filled - or possibly another data structure
277     // with the positions of the inactive planes.
278     // Need a data structure to hold outstanding communications from aircraft.
279     // Possibly need a data structure to hold outstanding communications to aircraft.
280
281         // The logical network
282         // NODES WILL BE STORED IN THE NETWORK IN ORDER OF nodeID NUMBER
283         // ie. NODE 5 WILL BE AT network[5]
284     node_array_type network;
285         
286         // A map of all the gates indexed against internal (FGFS) ID
287         gate_map_type gates;
288         gate_map_iterator gatesItr;
289
290         FGATCAlignedProjection ortho;
291         
292         // Planes currently active
293     //ground_rec_list ground_traffic;
294
295     // Find the shortest route through the logical network between two points.
296     //FindShortestRoute(point a, point b);
297
298     // Assign a gate or parking location to a new arrival
299     //AssignGate(ground_rec &g);
300
301     // Generate the next clearance for an airplane
302     //NextClearance(ground_rec &g);
303         
304         // environment - need to make sure we're getting the surface winds and not winds aloft.
305         SGPropertyNode_ptr wind_from_hdg;       //degrees
306         SGPropertyNode_ptr wind_speed_knots;            //knots
307         
308         // for failure modeling
309         std::string trans_ident;                // transmitted ident
310         bool ground_failed;             // ground failed?
311         bool networkLoadOK;             // Indicates whether LoadNetwork returned true or false at last attempt
312         
313         // Tower control
314         bool untowered;         // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
315         //FGATC* tower;         // Pointer to the tower control
316
317         // Logical runway details - this might change in the future.
318         //runway_array_type runways;    // STL way
319         Rwy runways[37];        // quick hack!
320         
321         // Physical runway details
322         double aptElev;         // Airport elevation
323         std::string activeRwy;  // Active runway number - For now we'll disregard multiple / alternate runway operation.
324         RunwayDetails rwy;      // Assumed to be the active one for now.// Figure out which runways are active.
325         
326         // For now we'll just be simple and do one active runway - eventually this will get much more complex
327         // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
328         // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
329         // will be initialised before ground so we can't do that.
330         void DoRwyDetails();    
331         
332         // Load the logical ground network for this airport from file.
333         // Return true if successfull.
334         bool LoadNetwork();
335         
336         // Parse a runway exit string and push the supplied node pointer onto the runway exit list
337         void ParseRwyExits(node* np, char* es);
338         
339         // Return a random gate ID of an unused gate.
340         // Two error values may be returned and must be checked for by the calling function:
341         // -2 signifies that no gates exist at this airport.
342         // -1 signifies that all gates are currently full.
343         // TODO - modify to return a suitable gate based on aircraft size/weight.
344         int GetRandomGateID();
345         
346         // Return a pointer to the node at a runway threshold
347         // Returns NULL if unsuccessful.
348         node* GetThresholdNode(const std::string& rwyID);
349         
350         // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
351         ground_network_path_type GetShortestPath(node* A, node* B); 
352         
353         // Planes
354         ground_rec_list ground_traffic;
355         ground_rec_list_itr ground_traffic_itr;
356 };
357
358 #endif  // _FG_GROUND_HXX
359