]> git.mxchange.org Git - flightgear.git/blob - src/ATCDCL/ground.hxx
Tie samplegroup 'avionics' to the listener, just in case no other device is created...
[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/SGMath.hxx>
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/props/props.hxx>
31
32 #include "ATC.hxx"
33 #include "ATCProjection.hxx"
34
35 #include <string>
36
37 class FGAIEntity;
38 class FGATCMgr;
39
40 //////////////////////////////////////////////////////
41 // Types for the logical network data structure
42 enum arc_type {
43         RUNWAY,
44         TAXIWAY
45 };
46
47 enum node_type {
48         GATE,
49         APRON,
50         HOLD,
51         JUNCTION,
52         TJUNCTION
53 };
54
55 enum GateType {
56         TRANSPORT_PASSENGER,
57         TRANSPORT_PASSENGER_NARROWBODY,
58         TRANSPORT_PASSENGER_WIDEBODY,
59         TRANSPORT_CARGO,
60         GA_LOCAL,
61         GA_LOCAL_SINGLE,
62         GA_LOCAL_TWIN,
63         GA_TRANSIENT,
64         GA_TRANSIENT_SINGLE,
65         GA_TRANSIENT_TWIN,
66         OTHER   // ie. anything goes!!
67 };
68
69 enum network_element_type {
70         NODE,
71         ARC
72 };
73
74 struct ground_network_element {
75         network_element_type struct_type;
76 };
77
78 struct arc : public ground_network_element {
79         int distance;
80         std::string name;
81         arc_type type;
82         bool directed;  //false if 2-way, true if 1-way.  
83         //This is a can of worms since arcs might be one way in different directions under different circumstances
84         unsigned int n1;        // The nodeID of the first node
85         unsigned int n2;        // The nodeID of the second node
86         // If the arc is directed then flow is normally from n1 to n2.  See the above can of worms comment though.
87 };
88
89 typedef std::vector <arc*> arc_array_type;      // This was and may become again a list instead of vector
90 typedef arc_array_type::iterator arc_array_iterator;
91 typedef arc_array_type::const_iterator arc_array_const_iterator; 
92
93 struct node : public ground_network_element {
94         node();
95         ~node();
96         
97         unsigned int nodeID;    //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
98         SGGeod pos;
99         SGVec3d orthoPos;
100         std::string name;
101         node_type type;
102         arc_array_type arcs;
103         double max_turn_radius;
104 };
105
106 typedef std::vector <node*> node_array_type;
107 typedef node_array_type::iterator node_array_iterator;
108 typedef node_array_type::const_iterator node_array_const_iterator;
109
110 struct Gate : public node {
111         GateType gateType;
112         int max_weight; //units??
113         //airline_code airline; //For the future - we don't have any airline codes ATM
114         int id; // The gate number in the logical scheme of things
115         std::string name;       // The real-world gate letter/number
116         //node* pNode;
117         bool used;
118         double heading; // The direction the parked-up plane should point in degrees
119 };
120
121 typedef std::vector < Gate* > gate_vec_type;
122 typedef gate_vec_type::iterator gate_vec_iterator;
123 typedef gate_vec_type::const_iterator gate_vec_const_iterator;
124
125 // A map of gate vs. the logical (internal FGFS) gate ID
126 typedef std::map < int, Gate* > gate_map_type;
127 typedef gate_map_type::iterator gate_map_iterator;
128 typedef gate_map_type::const_iterator gate_map_const_iterator;
129
130 // Runways - all the runway stuff is likely to change in the future
131 struct Rwy {
132         int id; //note this is a very simplified scheme for now - R & L are not differentiated
133         //It should work for simple one rwy airports
134         node_array_type exits;  //Array of available exits from runway
135         // should probably add an FGRunway structure here as well eventually
136         // Eventually we will also want some encoding of real-life preferred runways
137         // This will get us up and running for single runway airports though.
138 };
139
140 typedef std::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 std::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 ////////////////////////////////////////////////
158 //
159 // Stuff for the shortest-path algorithms
160 struct a_path {
161         a_path();
162         
163         ground_network_path_type path;
164         int cost;
165 };
166
167 // Paths mapped by nodeID reached so-far
168 typedef std::map < unsigned int, a_path* > shortest_path_map_type;
169 typedef shortest_path_map_type::iterator shortest_path_map_iterator;
170
171 // Nodes mapped by their ID
172 //typedef map < unsigned int, node* > node_map_type;
173 //typedef node_map_type::iterator node_map_iterator;
174 ////////////////////////////////////////////////
175
176 // Planes active within the ground network.
177
178 // A more specialist plane rec to include ground information
179 struct GroundRec {
180     FGAIEntity* planePtr;       // This might move to the planeRec eventually
181         
182     PlaneRec plane;
183     node* destination;
184     node* last_clearance;
185     bool taxiRequestOutstanding;        // Plane has requested taxi and we haven't responded yet
186     double clearanceCounter;            // Hack for communication timing - counter since clearance requested in seconds 
187         
188     bool cleared;  // set true when the plane has been cleared to somewhere
189     bool incoming; //true for arrivals, false for departures
190     // status?
191     // Almost certainly need to add more here
192 };
193
194 typedef std::list < GroundRec* > ground_rec_list;
195 typedef ground_rec_list::iterator ground_rec_list_itr;
196 typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
197
198 ///////////////////////////////////////////////////////////////////////////////
199 //
200 // FGGround
201 //
202 ///////////////////////////////////////////////////////////////////////////////
203 class FGGround : public FGATC {
204
205 public:
206         FGGround();
207         FGGround(const std::string& id);
208         ~FGGround();
209     void Init();
210
211     void Update(double dt);
212         
213         inline const std::string& get_trans_ident() { return trans_ident; }
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 RequestDeparture(const PlaneRec& plane, FGAIEntity* requestee);
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         // Return a pointer to an unused gate
235         Gate* GetGateNode();
236         
237         // Return a pointer to a hold short node
238         node* GetHoldShortNode(const std::string& rwyID);
239         
240         // Runway stuff - this might change in the future.
241         // Get a list of exits from a given runway
242         // It is up to the calling function to check for non-zero size of returned array before use
243         node_array_type GetExits(const std::string& rwyID);
244         
245         // Get a path from one node to another
246         ground_network_path_type GetPath(node* A, node* B);
247         
248         // Get a path from a node to a runway threshold
249         ground_network_path_type GetPath(node* A, const std::string& rwyID);
250         
251         // Get a path from a node to a runway hold short point
252         // Bit of a hack this at the moment!
253         ground_network_path_type GetPathToHoldShort(node* A, const std::string& rwyID);
254
255 private:
256         FGATCMgr* ATCmgr;       
257         // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
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         FGATCAlignedProjection ortho;
276         
277         // Planes currently active
278     //ground_rec_list ground_traffic;
279
280     // Find the shortest route through the logical network between two points.
281     //FindShortestRoute(point a, point b);
282
283     // Assign a gate or parking location to a new arrival
284     //AssignGate(ground_rec &g);
285
286     // Generate the next clearance for an airplane
287     //NextClearance(ground_rec &g);
288         
289         // environment - need to make sure we're getting the surface winds and not winds aloft.
290         SGPropertyNode_ptr wind_from_hdg;       //degrees
291         SGPropertyNode_ptr wind_speed_knots;            //knots
292         
293         // for failure modeling
294         std::string trans_ident;                // transmitted ident
295         bool ground_failed;             // ground failed?
296         bool networkLoadOK;             // Indicates whether LoadNetwork returned true or false at last attempt
297         
298         // Tower control
299         bool untowered;         // True if this is an untowered airport (we still need the ground class for shortest path implementation etc
300         //FGATC* tower;         // Pointer to the tower control
301
302         // Logical runway details - this might change in the future.
303         //runway_array_type runways;    // STL way
304         Rwy runways[37];        // quick hack!
305         
306         // Physical runway details
307         double aptElev;         // Airport elevation
308         std::string activeRwy;  // Active runway number - For now we'll disregard multiple / alternate runway operation.
309         RunwayDetails rwy;      // Assumed to be the active one for now.// Figure out which runways are active.
310         
311         // For now we'll just be simple and do one active runway - eventually this will get much more complex
312         // Copied from FGTower - TODO - it would be better to implement this just once, and have ground call tower
313         // for runway operation details, but at the moment we can't guarantee that tower control at a given airport
314         // will be initialised before ground so we can't do that.
315         void DoRwyDetails();    
316         
317         // Load the logical ground network for this airport from file.
318         // Return true if successfull.
319         bool LoadNetwork();
320         
321         // Parse a runway exit string and push the supplied node pointer onto the runway exit list
322         void ParseRwyExits(node* np, char* es);
323         
324         // Return a random gate ID of an unused gate.
325         // Two error values may be returned and must be checked for by the calling function:
326         // -2 signifies that no gates exist at this airport.
327         // -1 signifies that all gates are currently full.
328         // TODO - modify to return a suitable gate based on aircraft size/weight.
329         int GetRandomGateID();
330         
331         // Return a pointer to the node at a runway threshold
332         // Returns NULL if unsuccessful.
333         node* GetThresholdNode(const std::string& rwyID);
334         
335         // A shortest path algorithm from memory (I can't find the bl&*dy book again!)
336         ground_network_path_type GetShortestPath(node* A, node* B); 
337         
338         // Planes
339         ground_rec_list ground_traffic;
340         ground_rec_list_itr ground_traffic_itr;
341 };
342
343 #endif  // _FG_GROUND_HXX
344