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_
28 #include <osg/Geometry>
29 #include <osg/MatrixTransform>
33 #include <simgear/compiler.h>
34 #include <simgear/route/waypoint.hxx>
43 #include "parking.hxx"
44 #include <ATC/trafficcontrol.hxx>
47 class FGTaxiSegment; // forward reference
48 class FGAIFlightPlan; // forward reference
49 class FGAirport; // forward reference
51 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
52 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
54 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
55 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
57 /***************************************************************************************
59 **************************************************************************************/
74 FGTaxiSegment *oppositeDirection;
94 FGTaxiSegment (const FGTaxiSegment &other) :
95 startNode (other.startNode),
96 endNode (other.endNode),
97 length (other.length),
98 heading (other.heading),
99 center (other.center),
100 isActive (other.isActive),
101 isPushBackRoute (other.isPushBackRoute),
102 isBlocked (other.isBlocked),
106 oppositeDirection (other.oppositeDirection)
110 FGTaxiSegment& operator=(const FGTaxiSegment &other)
112 startNode = other.startNode;
113 endNode = other.endNode;
114 length = other.length;
115 heading = other.heading;
116 center = other.center;
117 isActive = other.isActive;
118 isPushBackRoute = other.isPushBackRoute;
119 isBlocked = other.isBlocked;
123 oppositeDirection = other.oppositeDirection;
127 void setIndex (int val) {
130 void setStartNodeRef (int val) {
133 void setEndNodeRef (int val) {
137 void setOpposite(FGTaxiSegment *opp) {
138 oppositeDirection = opp;
141 void setStart(FGTaxiNodeVector *nodes);
142 void setEnd (FGTaxiNodeVector *nodes);
143 void setPushBackType(bool val) {
144 isPushBackRoute = val;
146 void setDimensions(double elevation);
157 FGTaxiNode * getEnd() {
160 FGTaxiNode * getStart() {
169 double getLatitude() {
170 return center.getLatitudeDeg();
172 double getLongitude() {
173 return center.getLongitudeDeg();
175 double getHeading() {
179 return isPushBackRoute;
182 int getPenalty(int nGates);
184 FGTaxiSegment *getAddress() {
188 bool operator<(const FGTaxiSegment &other) const {
189 return index < other.index;
191 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
192 FGTaxiSegment *opposite() {
193 return oppositeDirection;
195 void setCourseDiff(double crse);
205 typedef vector<int> intVec;
206 typedef vector<int>::iterator intVecIterator;
210 /***************************************************************************************
212 **************************************************************************************/
220 intVecIterator currNode;
221 intVecIterator currRoute;
226 currNode = nodes.begin();
227 currRoute = routes.begin();
229 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
233 currNode = nodes.begin();
234 currRoute = routes.begin();
238 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
240 routes = other.routes;
241 distance = other.distance;
242 // depth = other.depth;
243 currNode = nodes.begin();
244 currRoute = routes.begin();
248 FGTaxiRoute(const FGTaxiRoute& copy) :
251 distance(copy.distance),
252 // depth(copy.depth),
253 currNode(nodes.begin()),
254 currRoute(routes.begin())
257 bool operator< (const FGTaxiRoute &other) const {
258 return distance < other.distance;
261 return nodes.begin() == nodes.end();
264 bool next(int *nde, int *rte);
265 void rewind(int legNr);
268 currNode = nodes.begin();
269 currRoute = routes.begin();
275 return nodes.end() - currNode;
278 // int getDepth() { return depth; };
281 typedef vector<FGTaxiRoute> TaxiRouteVector;
282 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
284 /**************************************************************************************
285 * class FGGroundNetWork
286 *************************************************************************************/
287 class FGGroundNetwork : public FGATCController
291 bool networkInitialized;
295 FGTaxiNodeVector nodes;
296 FGTaxiNodeVector pushBackNodes;
297 FGTaxiSegmentVector segments;
300 //intVec routesStack;
301 TaxiRouteVector routes;
302 TrafficVector activeTraffic;
303 TrafficVectorIterator currTraffic;
306 double totalDistance, maxDistance;
307 FGTowerController *towerController;
311 //void printRoutingError(string);
313 void checkSpeedAdjustment(int id, double lat, double lon,
314 double heading, double speed, double alt);
315 void checkHoldPosition(int id, double lat, double lon,
316 double heading, double speed, double alt);
324 void addNode (const FGTaxiNode& node);
325 void addNodes (FGParkingVec *parkings);
326 void addSegment(const FGTaxiSegment& seg);
332 void setTowerController(FGTowerController *twrCtrlr) {
333 towerController = twrCtrlr;
336 int findNearestNode(double lat, double lon);
337 int findNearestNode(const SGGeod& aGeod);
339 FGTaxiNode *findNode(unsigned idx);
340 FGTaxiSegment *findSegment(unsigned idx);
341 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
342 //void trace(FGTaxiNode *, int, int, double dist);
348 void setParent(FGAirport *par) {
352 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
353 double lat, double lon, double hdg, double spd, double alt,
354 double radius, int leg, FGAIAircraft *aircraft);
355 virtual void signOff(int id);
356 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
357 virtual bool hasInstruction(int id);
358 virtual FGATCInstruction getInstruction(int id);
360 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
362 bool checkForCircularWaits(int id);
363 virtual void render(bool);
364 virtual string getName();
365 virtual void update(double dt);
367 void saveElevationCache();