1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
4 // Written by Durk Talsma, started June 2005.
6 // Copyright (C) 2004 Durk Talsma.
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.
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.
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.
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
27 #include <simgear/compiler.h>
28 #include <simgear/route/waypoint.hxx>
37 #include "parking.hxx"
38 #include <ATC/trafficcontrol.hxx>
40 class FGTaxiSegment; // forward reference
41 class FGAIFlightPlan; // forward reference
42 class FGAirport; // forward reference
44 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
45 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
47 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
48 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
50 /***************************************************************************************
52 **************************************************************************************/
66 FGTaxiSegment *oppositeDirection;
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),
97 oppositeDirection (other.oppositeDirection)
101 FGTaxiSegment& operator=(const FGTaxiSegment &other)
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;
113 oppositeDirection = other.oppositeDirection;
117 void setIndex (int val) { index = val; };
118 void setStartNodeRef (int val) { startNode = val; };
119 void setEndNodeRef (int val) { endNode = val; };
121 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
123 void setStart(FGTaxiNodeVector *nodes);
124 void setEnd (FGTaxiNodeVector *nodes);
125 void setPushBackType(bool val) { isPushBackRoute = val; };
126 void setTrackDistance();
128 FGTaxiNode * getEnd() { return end;};
129 FGTaxiNode * getStart() { return start; };
130 double getLength() { return length; };
131 int getIndex() { return index; };
133 bool isPushBack() { return isPushBackRoute; };
135 int getPenalty(int nGates);
137 FGTaxiSegment *getAddress() { return this;};
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);
151 typedef vector<int> intVec;
152 typedef vector<int>::iterator intVecIterator;
156 /***************************************************************************************
158 **************************************************************************************/
166 intVecIterator currNode;
167 intVecIterator currRoute;
170 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
171 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
175 currNode = nodes.begin();
179 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
181 routes = other.routes;
182 distance = other.distance;
184 currNode = nodes.begin();
185 currRoute = routes.begin();
189 FGTaxiRoute(const FGTaxiRoute& copy) :
192 distance(copy.distance),
194 currNode(nodes.begin()),
195 currRoute(routes.begin())
198 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
199 bool empty () { return nodes.begin() == nodes.end(); };
201 bool next(int *nde, int *rte);
202 void rewind(int legNr);
204 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
205 int size() { return nodes.size(); };
206 int getDepth() { return depth; };
209 typedef vector<FGTaxiRoute> TaxiRouteVector;
210 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
212 /**************************************************************************************
213 * class FGGroundNetWork
214 *************************************************************************************/
215 class FGGroundNetwork : public FGATCController
221 FGTaxiNodeVector nodes;
222 FGTaxiNodeVector pushBackNodes;
223 FGTaxiSegmentVector segments;
226 //intVec routesStack;
227 TaxiRouteVector routes;
228 TrafficVector activeTraffic;
229 TrafficVectorIterator currTraffic;
230 SGWayPoint destination;
233 double totalDistance, maxDistance;
234 FGTowerController *towerController;
238 //void printRoutingError(string);
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);
249 void addNode (const FGTaxiNode& node);
250 void addNodes (FGParkingVec *parkings);
251 void addSegment(const FGTaxiSegment& seg);
254 bool exists() { return hasNetwork; };
255 void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
256 int findNearestNode(double lat, double lon);
257 FGTaxiNode *findNode(int idx);
258 FGTaxiSegment *findSegment(int idx);
259 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
260 //void trace(FGTaxiNode *, int, int, double dist);
262 int getNrOfNodes() { return nodes.size(); };
264 void setParent(FGAirport *par) { parent = par; };
266 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
267 double lat, double lon, double hdg, double spd, double alt,
268 double radius, int leg, FGAIAircraft *aircraft);
269 virtual void signOff(int id);
270 virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
271 virtual bool hasInstruction(int id);
272 virtual FGATCInstruction getInstruction(int id);
274 bool checkForCircularWaits(int id);