]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Fixed an overly ambitious checkForCircularWaits() function. AI Aircraft
[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   bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
130   bool empty () { return nodes.begin() == nodes.end(); };
131   bool next(int *nde); 
132   bool next(int *nde, int *rte);
133   void rewind(int legNr);
134   
135   void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
136   int size() { return nodes.size(); };
137   int getDepth() { return depth; };
138 };
139
140 typedef vector<FGTaxiRoute> TaxiRouteVector;
141 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
142
143 bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
144 bool sortByLength     (FGTaxiSegment *a, FGTaxiSegment *b);
145
146
147 /**************************************************************************************
148  * class FGGroundNetWork
149  *************************************************************************************/
150 class FGGroundNetwork : public FGATCController
151 {
152 private:
153   bool hasNetwork;
154   //int maxDepth;
155   int count;
156   FGTaxiNodeVector    nodes;
157   FGTaxiSegmentVector segments;
158   //intVec route;
159   intVec nodesStack;
160   intVec routesStack;
161   TaxiRouteVector routes;
162   TrafficVector activeTraffic;
163   TrafficVectorIterator currTraffic;
164   SGWayPoint destination;
165   
166   bool foundRoute;
167   double totalDistance, maxDistance;
168   FGTowerController *towerController;
169   FGAirport *parent;
170   
171
172   void printRoutingError(string);
173
174   void checkSpeedAdjustment(int id, double lat, double lon, 
175                             double heading, double speed, double alt);
176   void checkHoldPosition(int id, double lat, double lon, 
177                          double heading, double speed, double alt);
178   
179 public:
180   FGGroundNetwork();
181   ~FGGroundNetwork();
182
183   void addNode   (const FGTaxiNode& node);
184   void addNodes  (FGParkingVec *parkings);
185   void addSegment(const FGTaxiSegment& seg); 
186
187   void init();
188   bool exists() { return hasNetwork; };
189   void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
190   int findNearestNode(double lat, double lon);
191   FGTaxiNode *findNode(int idx);
192   FGTaxiSegment *findSegment(int idx);
193   FGTaxiRoute findShortestRoute(int start, int end);
194   //void trace(FGTaxiNode *, int, int, double dist);
195
196   void setParent(FGAirport *par) { parent = par; };
197
198   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, 
199                                 double lat, double lon, double hdg, double spd, double alt, 
200                                 double radius, int leg, string callsign);
201   virtual void signOff(int id);
202   virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
203   virtual bool hasInstruction(int id);
204   virtual FGATCInstruction getInstruction(int id);
205
206   bool checkForCircularWaits(int id);
207 };
208
209
210 #endif