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;
85 FGTaxiSegment (const FGTaxiSegment &other) :
86 startNode (other.startNode),
87 endNode (other.endNode),
88 length (other.length),
89 heading (other.heading),
90 center (other.center),
91 isActive (other.isActive),
92 isPushBackRoute (other.isPushBackRoute),
96 oppositeDirection (other.oppositeDirection)
100 FGTaxiSegment& operator=(const FGTaxiSegment &other)
102 startNode = other.startNode;
103 endNode = other.endNode;
104 length = other.length;
105 heading = other.heading;
106 center = other.center;
107 isActive = other.isActive;
108 isPushBackRoute = other.isPushBackRoute;
112 oppositeDirection = other.oppositeDirection;
116 void setIndex (int val) { index = val; };
117 void setStartNodeRef (int val) { startNode = val; };
118 void setEndNodeRef (int val) { endNode = val; };
120 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
122 void setStart(FGTaxiNodeVector *nodes);
123 void setEnd (FGTaxiNodeVector *nodes);
124 void setPushBackType(bool val) { isPushBackRoute = val; };
125 void setDimensions(double elevation);
127 FGTaxiNode * getEnd() { return end;};
128 FGTaxiNode * getStart() { return start; };
129 double getLength() { return length; };
130 int getIndex() { return index; };
131 double getLatitude() { return center.getLatitudeDeg(); };
132 double getLongitude() { return center.getLongitudeDeg(); };
133 double getHeading() { return heading; };
134 bool isPushBack() { return isPushBackRoute; };
136 int getPenalty(int nGates);
138 FGTaxiSegment *getAddress() { return this;};
140 bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
141 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
142 FGTaxiSegment *opposite() { return oppositeDirection; };
143 void setCourseDiff(double crse);
152 typedef vector<int> intVec;
153 typedef vector<int>::iterator intVecIterator;
157 /***************************************************************************************
159 **************************************************************************************/
167 intVecIterator currNode;
168 intVecIterator currRoute;
171 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
172 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
176 currNode = nodes.begin();
180 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
182 routes = other.routes;
183 distance = other.distance;
184 // depth = other.depth;
185 currNode = nodes.begin();
186 currRoute = routes.begin();
190 FGTaxiRoute(const FGTaxiRoute& copy) :
193 distance(copy.distance),
194 // depth(copy.depth),
195 currNode(nodes.begin()),
196 currRoute(routes.begin())
199 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
200 bool empty () { return nodes.begin() == nodes.end(); };
202 bool next(int *nde, int *rte);
203 void rewind(int legNr);
205 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
206 int size() { return nodes.size(); };
207 // int getDepth() { return depth; };
210 typedef vector<FGTaxiRoute> TaxiRouteVector;
211 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
213 /**************************************************************************************
214 * class FGGroundNetWork
215 *************************************************************************************/
216 class FGGroundNetwork : public FGATCController
222 FGTaxiNodeVector nodes;
223 FGTaxiNodeVector pushBackNodes;
224 FGTaxiSegmentVector segments;
227 //intVec routesStack;
228 TaxiRouteVector routes;
229 TrafficVector activeTraffic;
230 TrafficVectorIterator currTraffic;
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; };
257 int findNearestNode(double lat, double lon);
258 int findNearestNode(const SGGeod& aGeod);
260 FGTaxiNode *findNode(unsigned idx);
261 FGTaxiSegment *findSegment(unsigned idx);
262 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
263 //void trace(FGTaxiNode *, int, int, double dist);
265 int getNrOfNodes() { return nodes.size(); };
267 void setParent(FGAirport *par) { parent = par; };
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 updateAircraftInformation(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);
277 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
279 bool checkForCircularWaits(int id);
280 osg::Node* getRenderNode();