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>
46 #include "parking.hxx"
47 #include <ATC/trafficcontrol.hxx>
50 class FGTaxiSegment; // forward reference
51 class FGAIFlightPlan; // forward reference
52 class FGAirport; // forward reference
54 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
55 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
57 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
58 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
67 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
69 int getId() { return id; };
70 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
71 const time_t getBlockTime() const { return blocktime; };
72 time_t getTimeStamp() { return touch; };
73 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
76 typedef vector<Block> BlockList;
77 typedef BlockList::iterator BlockListIterator;
79 /***************************************************************************************
81 **************************************************************************************/
96 FGTaxiSegment *oppositeDirection;
115 FGTaxiSegment (const FGTaxiSegment &other) :
116 startNode (other.startNode),
117 endNode (other.endNode),
118 length (other.length),
119 heading (other.heading),
120 center (other.center),
121 isActive (other.isActive),
122 isPushBackRoute (other.isPushBackRoute),
123 blockTimes (other.blockTimes),
127 oppositeDirection (other.oppositeDirection)
131 FGTaxiSegment& operator=(const FGTaxiSegment &other)
133 startNode = other.startNode;
134 endNode = other.endNode;
135 length = other.length;
136 heading = other.heading;
137 center = other.center;
138 isActive = other.isActive;
139 isPushBackRoute = other.isPushBackRoute;
140 blockTimes = other.blockTimes;
144 oppositeDirection = other.oppositeDirection;
148 void setIndex (int val) {
151 void setStartNodeRef (int val) {
154 void setEndNodeRef (int val) {
158 void setOpposite(FGTaxiSegment *opp) {
159 oppositeDirection = opp;
162 void setStart(FGTaxiNodeVector *nodes);
163 void setEnd (FGTaxiNodeVector *nodes);
164 void setPushBackType(bool val) {
165 isPushBackRoute = val;
167 void setDimensions(double elevation);
168 void block(int id, time_t blockTime, time_t now);
169 void unblock(time_t now);
170 bool hasBlock(time_t now);
172 FGTaxiNode * getEnd() {
175 FGTaxiNode * getStart() {
184 double getLatitude() {
185 return center.getLatitudeDeg();
187 double getLongitude() {
188 return center.getLongitudeDeg();
190 double getHeading() {
194 return isPushBackRoute;
197 int getPenalty(int nGates);
199 FGTaxiSegment *getAddress() {
203 bool operator<(const FGTaxiSegment &other) const {
204 return index < other.index;
206 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
207 FGTaxiSegment *opposite() {
208 return oppositeDirection;
210 void setCourseDiff(double crse);
220 typedef vector<int> intVec;
221 typedef vector<int>::iterator intVecIterator;
225 /***************************************************************************************
227 **************************************************************************************/
235 intVecIterator currNode;
236 intVecIterator currRoute;
241 currNode = nodes.begin();
242 currRoute = routes.begin();
244 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
248 currNode = nodes.begin();
249 currRoute = routes.begin();
253 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
255 routes = other.routes;
256 distance = other.distance;
257 // depth = other.depth;
258 currNode = nodes.begin();
259 currRoute = routes.begin();
263 FGTaxiRoute(const FGTaxiRoute& copy) :
266 distance(copy.distance),
267 // depth(copy.depth),
268 currNode(nodes.begin()),
269 currRoute(routes.begin())
272 bool operator< (const FGTaxiRoute &other) const {
273 return distance < other.distance;
276 return nodes.begin() == nodes.end();
279 bool next(int *nde, int *rte);
280 void rewind(int legNr);
283 currNode = nodes.begin();
284 currRoute = routes.begin();
290 return nodes.end() - currNode;
293 // int getDepth() { return depth; };
296 typedef vector<FGTaxiRoute> TaxiRouteVector;
297 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
299 /**************************************************************************************
300 * class FGGroundNetWork
301 *************************************************************************************/
302 class FGGroundNetwork : public FGATCController
306 bool networkInitialized;
311 FGTaxiNodeVector nodes;
312 FGTaxiNodeVector pushBackNodes;
313 FGTaxiSegmentVector segments;
316 //intVec routesStack;
317 TaxiRouteVector routes;
318 TrafficVector activeTraffic;
319 TrafficVectorIterator currTraffic;
322 double totalDistance, maxDistance;
323 FGTowerController *towerController;
327 //void printRoutingError(string);
329 void checkSpeedAdjustment(int id, double lat, double lon,
330 double heading, double speed, double alt);
331 void checkHoldPosition(int id, double lat, double lon,
332 double heading, double speed, double alt);
340 void addNode (const FGTaxiNode& node);
341 void addNodes (FGParkingVec *parkings);
342 void addSegment(const FGTaxiSegment& seg);
343 void setVersion (int v) { version = v;};
345 int getVersion() { return version; };
351 void setTowerController(FGTowerController *twrCtrlr) {
352 towerController = twrCtrlr;
355 int findNearestNode(double lat, double lon);
356 int findNearestNode(const SGGeod& aGeod);
357 int findNearestNodeOnRunway(const SGGeod& aGeod);
359 FGTaxiNode *findNode(unsigned idx);
360 FGTaxiSegment *findSegment(unsigned idx);
361 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
362 //void trace(FGTaxiNode *, int, int, double dist);
368 void setParent(FGAirport *par) {
372 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
373 double lat, double lon, double hdg, double spd, double alt,
374 double radius, int leg, FGAIAircraft *aircraft);
375 virtual void signOff(int id);
376 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
377 virtual bool hasInstruction(int id);
378 virtual FGATCInstruction getInstruction(int id);
380 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
382 bool checkForCircularWaits(int id);
383 virtual void render(bool);
384 virtual string getName();
385 virtual void update(double dt);
387 void saveElevationCache();
388 void addVersion(int v) {version = v; };