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 "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 **************************************************************************************/
65 FGTaxiSegment *oppositeDirection;
71 //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
73 void setIndex (int val) { index = val; };
74 void setStartNodeRef (int val) { startNode = val; };
75 void setEndNodeRef (int val) { endNode = val; };
77 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
79 void setStart(FGTaxiNodeVector *nodes);
80 void setEnd (FGTaxiNodeVector *nodes);
81 void setTrackDistance();
83 FGTaxiNode * getEnd() { return end;};
84 FGTaxiNode * getStart() { return start; };
85 double getLength() { return length; };
86 int getIndex() { return index; };
88 FGTaxiSegment *getAddress() { return this;};
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);
102 typedef vector<int> intVec;
103 typedef vector<int>::iterator intVecIterator;
107 /***************************************************************************************
109 **************************************************************************************/
117 intVecIterator currNode;
118 intVecIterator currRoute;
121 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
122 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
126 currNode = nodes.begin();
129 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
130 bool empty () { return nodes.begin() == nodes.end(); };
132 bool next(int *nde, int *rte);
133 void rewind(int legNr);
135 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
136 int size() { return nodes.size(); };
137 int getDepth() { return depth; };
140 typedef vector<FGTaxiRoute> TaxiRouteVector;
141 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
143 bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
144 bool sortByLength (FGTaxiSegment *a, FGTaxiSegment *b);
147 /**************************************************************************************
148 * class FGGroundNetWork
149 *************************************************************************************/
150 class FGGroundNetwork : public FGATCController
156 FGTaxiNodeVector nodes;
157 FGTaxiSegmentVector segments;
161 TaxiRouteVector routes;
162 TrafficVector activeTraffic;
163 TrafficVectorIterator currTraffic;
164 SGWayPoint destination;
167 double totalDistance, maxDistance;
168 FGTowerController *towerController;
172 void printRoutingError(string);
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);
183 void addNode (const FGTaxiNode& node);
184 void addNodes (FGParkingVec *parkings);
185 void addSegment(const FGTaxiSegment& seg);
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);
196 void setParent(FGAirport *par) { parent = par; };
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);
206 bool checkForCircularWaits(int id);