]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
e602f9094845e58218c3e010a422bf37b0466cce
[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 <string>
31 #include <vector>
32
33 using std::string;
34 using std::vector;
35
36 #include "gnnode.hxx"
37 #include "parking.hxx"
38 #include <ATC/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   bool isPushBackRoute;
63   FGTaxiNode *start;
64   FGTaxiNode *end;
65   int index;
66   FGTaxiSegment *oppositeDirection;
67
68  
69
70 public:
71   FGTaxiSegment() :
72       startNode(0),
73       endNode(0),
74       length(0),
75       course(0),
76       headingDiff(0),
77       isActive(0),
78       isPushBackRoute(0),
79       start(0),
80       end(0),
81       index(0),
82       oppositeDirection(0)
83   {
84   };
85
86   FGTaxiSegment         (const FGTaxiSegment &other) :
87       startNode         (other.startNode),
88       endNode           (other.endNode),
89       length            (other.length),
90       course            (other.course),
91       headingDiff       (other.headingDiff),
92       isActive          (other.isActive),
93       isPushBackRoute   (other.isPushBackRoute),
94       start             (other.start),
95       end               (other.end),
96       index             (other.index),
97       oppositeDirection (other.oppositeDirection)
98   {
99   };
100
101   FGTaxiSegment& operator=(const FGTaxiSegment &other)
102   {
103       startNode          = other.startNode;
104       endNode            = other.endNode;
105       length             = other.length;
106       course             = other.course;
107       headingDiff        = other.headingDiff;
108       isActive           = other.isActive;
109       isPushBackRoute    = other.isPushBackRoute;
110       start              = other.start;
111       end                = other.end;
112       index              = other.index;
113       oppositeDirection  = other.oppositeDirection;
114       return *this;
115   };
116
117   void setIndex        (int val) { index     = val; };
118   void setStartNodeRef (int val) { startNode = val; };
119   void setEndNodeRef   (int val) { endNode   = val; };
120
121   void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
122
123   void setStart(FGTaxiNodeVector *nodes);
124   void setEnd  (FGTaxiNodeVector *nodes);
125   void setPushBackType(bool val) { isPushBackRoute = val; };
126   void setTrackDistance();
127
128   FGTaxiNode * getEnd() { return end;};
129   FGTaxiNode * getStart() { return start; };
130   double getLength() { return length; };
131   int getIndex() { return index; };
132   
133   bool isPushBack() { return isPushBackRoute; };
134
135   int getPenalty(int nGates);
136
137   FGTaxiSegment *getAddress() { return this;};
138
139   bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
140   bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
141   FGTaxiSegment *opposite() { return oppositeDirection; };
142   void setCourseDiff(double crse);
143
144
145   
146 };
147
148
149
150
151 typedef vector<int> intVec;
152 typedef vector<int>::iterator intVecIterator;
153
154
155
156 /***************************************************************************************
157  * class FGTaxiRoute
158  **************************************************************************************/
159 class FGTaxiRoute
160 {
161 private:
162   intVec nodes;
163   intVec routes;
164   double distance;
165   int depth;
166   intVecIterator currNode;
167   intVecIterator currRoute;
168
169 public:
170   FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
171   FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) { 
172     nodes = nds; 
173     routes = rts;
174     distance = dist; 
175     currNode = nodes.begin();
176     depth = dpth;
177   };
178
179   FGTaxiRoute& operator= (const FGTaxiRoute &other) {
180     nodes = other.nodes;
181     routes = other.routes;
182     distance = other.distance;
183     depth = other.depth;
184     currNode = nodes.begin();
185     currRoute = routes.begin();
186     return *this;
187   };
188
189   FGTaxiRoute(const FGTaxiRoute& copy) :
190     nodes(copy.nodes),
191     routes(copy.routes),
192     distance(copy.distance),
193     depth(copy.depth),
194     currNode(nodes.begin()),
195     currRoute(routes.begin())
196   {};
197
198   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
199   bool empty () { return nodes.begin() == nodes.end(); };
200   bool next(int *nde); 
201   bool next(int *nde, int *rte);
202   void rewind(int legNr);
203   
204   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
205   int size() { return nodes.size(); };
206   int getDepth() { return depth; };
207 };
208
209 typedef vector<FGTaxiRoute> TaxiRouteVector;
210 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
211
212 /**************************************************************************************
213  * class FGGroundNetWork
214  *************************************************************************************/
215 class FGGroundNetwork : public FGATCController
216 {
217 private:
218   bool hasNetwork;
219   //int maxDepth;
220   int count;
221   FGTaxiNodeVector    nodes;
222   FGTaxiNodeVector    pushBackNodes;
223   FGTaxiSegmentVector segments;
224   //intVec route;
225   //intVec nodesStack;
226   //intVec routesStack;
227   TaxiRouteVector routes;
228   TrafficVector activeTraffic;
229   TrafficVectorIterator currTraffic;
230   SGWayPoint destination;
231
232   bool foundRoute;
233   double totalDistance, maxDistance;
234   FGTowerController *towerController;
235   FGAirport *parent;
236
237
238   //void printRoutingError(string);
239
240   void checkSpeedAdjustment(int id, double lat, double lon, 
241                             double heading, double speed, double alt);
242   void checkHoldPosition(int id, double lat, double lon, 
243                          double heading, double speed, double alt);
244
245 public:
246   FGGroundNetwork();
247   ~FGGroundNetwork();
248
249   void addNode   (const FGTaxiNode& node);
250   void addNodes  (FGParkingVec *parkings);
251   void addSegment(const FGTaxiSegment& seg); 
252
253   void init();
254   bool exists() { return hasNetwork; };
255   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
256   
257   int findNearestNode(double lat, double lon);
258   int findNearestNode(const SGGeod& aGeod);
259   
260   FGTaxiNode *findNode(int idx);
261   FGTaxiSegment *findSegment(int idx);
262   FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
263   //void trace(FGTaxiNode *, int, int, double dist);
264
265   int getNrOfNodes() { return nodes.size(); };
266
267   void setParent(FGAirport *par) { parent = par; };
268
269   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
270                                 double lat, double lon, double hdg, double spd, double alt, 
271                                 double radius, int leg, FGAIAircraft *aircraft);
272   virtual void signOff(int id);
273   virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
274   virtual bool hasInstruction(int id);
275   virtual FGATCInstruction getInstruction(int id);
276
277   bool checkForCircularWaits(int id);
278 };
279
280
281 #endif