]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Airports / groundnetwork.hxx
1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma, started June 2005.
5 //
6 // Copyright (C) 2004 Durk Talsma.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
26
27 #include <simgear/compiler.h>
28 #include <simgear/route/waypoint.hxx>
29
30 #include STL_STRING
31 #include <vector>
32
33 SG_USING_STD(string);
34 SG_USING_STD(vector);
35
36 #include "gnnode.hxx"
37 #include "parking.hxx"
38 #include "trafficcontrol.hxx"
39
40 class FGTaxiSegment; // forward reference
41 class FGAIFlightPlan; // forward reference
42 class FGAirport;      // forward reference
43
44 typedef vector<FGTaxiSegment*>  FGTaxiSegmentVector;
45 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
46
47 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
48 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
49
50 /***************************************************************************************
51  * class FGTaxiSegment
52  **************************************************************************************/
53 class FGTaxiSegment
54 {
55 private:
56   int startNode;
57   int endNode;
58   double length;
59   double course;
60   double headingDiff;
61   bool isActive;
62   FGTaxiNode *start;
63   FGTaxiNode *end;
64   int index;
65   FGTaxiSegment *oppositeDirection;
66
67  
68
69 public:
70   FGTaxiSegment();
71   //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
72
73   void setIndex        (int val) { index     = val; };
74   void setStartNodeRef (int val) { startNode = val; };
75   void setEndNodeRef   (int val) { endNode   = val; };
76
77   void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
78
79   void setStart(FGTaxiNodeVector *nodes);
80   void setEnd  (FGTaxiNodeVector *nodes);
81   void setTrackDistance();
82
83   FGTaxiNode * getEnd() { return end;};
84   FGTaxiNode * getStart() { return start; };
85   double getLength() { return length; };
86   int getIndex() { return index; };
87
88  FGTaxiSegment *getAddress() { return this;};
89
90   bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
91   bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
92   FGTaxiSegment *opposite() { return oppositeDirection; };
93   void setCourseDiff(double crse);
94
95
96   
97 };
98
99
100
101
102 typedef vector<int> intVec;
103 typedef vector<int>::iterator intVecIterator;
104
105
106
107 /***************************************************************************************
108  * class FGTaxiRoute
109  **************************************************************************************/
110 class FGTaxiRoute
111 {
112 private:
113   intVec nodes;
114   intVec routes;
115   double distance;
116   int depth;
117   intVecIterator currNode;
118   intVecIterator currRoute;
119
120 public:
121   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
122   FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { 
123     nodes = nds; 
124     routes = rts;
125     distance = dist; 
126     currNode = nodes.begin();
127     depth = dpth;
128   };
129
130   FGTaxiRoute& operator= (const FGTaxiRoute &other) {
131     nodes = other.nodes;
132     routes = other.routes;
133     distance = other.distance;
134     depth = other.depth;
135     currNode = nodes.begin();
136     currRoute = routes.begin();
137     return *this;
138   };
139
140   FGTaxiRoute(const FGTaxiRoute& copy) :
141     nodes(copy.nodes),
142     routes(copy.routes),
143     distance(copy.distance),
144     depth(copy.depth),
145     currNode(nodes.begin()),
146     currRoute(routes.begin())
147   {};
148
149   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
150   bool empty () { return nodes.begin() == nodes.end(); };
151   bool next(int *nde); 
152   bool next(int *nde, int *rte);
153   void rewind(int legNr);
154   
155   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
156   int size() { return nodes.size(); };
157   int getDepth() { return depth; };
158 };
159
160 typedef vector<FGTaxiRoute> TaxiRouteVector;
161 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
162
163 /**************************************************************************************
164  * class FGGroundNetWork
165  *************************************************************************************/
166 class FGGroundNetwork : public FGATCController
167 {
168 private:
169   bool hasNetwork;
170   //int maxDepth;
171   int count;
172   FGTaxiNodeVector    nodes;
173   FGTaxiSegmentVector segments;
174   //intVec route;
175   intVec nodesStack;
176   intVec routesStack;
177   TaxiRouteVector routes;
178   TrafficVector activeTraffic;
179   TrafficVectorIterator currTraffic;
180   SGWayPoint destination;
181   
182   bool foundRoute;
183   double totalDistance, maxDistance;
184   FGTowerController *towerController;
185   FGAirport *parent;
186   
187
188   void printRoutingError(string);
189
190   void checkSpeedAdjustment(int id, double lat, double lon, 
191                             double heading, double speed, double alt);
192   void checkHoldPosition(int id, double lat, double lon, 
193                          double heading, double speed, double alt);
194   
195 public:
196   FGGroundNetwork();
197   ~FGGroundNetwork();
198
199   void addNode   (const FGTaxiNode& node);
200   void addNodes  (FGParkingVec *parkings);
201   void addSegment(const FGTaxiSegment& seg); 
202
203   void init();
204   bool exists() { return hasNetwork; };
205   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
206   int findNearestNode(double lat, double lon);
207   FGTaxiNode *findNode(int idx);
208   FGTaxiSegment *findSegment(int idx);
209   FGTaxiRoute findShortestRoute(int start, int end);
210   //void trace(FGTaxiNode *, int, int, double dist);
211
212   void setParent(FGAirport *par) { parent = par; };
213
214   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
215                                 double lat, double lon, double hdg, double spd, double alt, 
216                                 double radius, int leg, string callsign);
217   virtual void signOff(int id);
218   virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
219   virtual bool hasInstruction(int id);
220   virtual FGATCInstruction getInstruction(int id);
221
222   bool checkForCircularWaits(int id);
223 };
224
225
226 #endif