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"
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
44 class FGAirport; // forward reference
46 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
47 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
49 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
50 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
52 /**************************************************************************************
54 *************************************************************************************/
61 FGTaxiSegmentVector next; // a vector of pointers to all the segments leaving from this node
65 FGTaxiNode(double, double, int);
67 void setIndex(int idx) { index = idx;};
68 void setLatitude (double val) { lat = val;};
69 void setLongitude(double val) { lon = val;};
70 void setLatitude (const string& val) { lat = processPosition(val); };
71 void setLongitude(const string& val) { lon = processPosition(val); };
72 void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
74 double getLatitude() { return lat;};
75 double getLongitude(){ return lon;};
77 int getIndex() { return index; };
78 FGTaxiNode *getAddress() { return this;};
79 FGTaxiSegmentVectorIterator getBeginRoute() { return next.begin(); };
80 FGTaxiSegmentVectorIterator getEndRoute() { return next.end(); };
81 bool operator<(const FGTaxiNode &other) const { return index < other.index; };
83 void sortEndSegments(bool);
86 typedef vector<FGTaxiNode*> FGTaxiNodeVector;
87 typedef vector<FGTaxiNode*>::iterator FGTaxiNodeVectorIterator;
89 /***************************************************************************************
91 **************************************************************************************/
104 FGTaxiSegment *oppositeDirection;
110 //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
112 void setIndex (int val) { index = val; };
113 void setStartNodeRef (int val) { startNode = val; };
114 void setEndNodeRef (int val) { endNode = val; };
116 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
118 void setStart(FGTaxiNodeVector *nodes);
119 void setEnd (FGTaxiNodeVector *nodes);
120 void setTrackDistance();
122 FGTaxiNode * getEnd() { return end;};
123 FGTaxiNode * getStart() { return start; };
124 double getLength() { return length; };
125 int getIndex() { return index; };
127 FGTaxiSegment *getAddress() { return this;};
129 bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
130 bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
131 FGTaxiSegment *opposite() { return oppositeDirection; };
132 void setCourseDiff(double crse);
141 typedef vector<int> intVec;
142 typedef vector<int>::iterator intVecIterator;
146 /***************************************************************************************
148 **************************************************************************************/
156 intVecIterator currNode;
157 intVecIterator currRoute;
160 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
161 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
165 currNode = nodes.begin();
168 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
169 bool empty () { return nodes.begin() == nodes.end(); };
171 bool next(int *nde, int *rte);
172 void rewind(int legNr);
174 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
175 int size() { return nodes.size(); };
176 int getDepth() { return depth; };
179 typedef vector<FGTaxiRoute> TaxiRouteVector;
180 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
182 bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b);
183 bool sortByLength (FGTaxiSegment *a, FGTaxiSegment *b);
186 /**************************************************************************************
187 * class FGGroundNetWork
188 *************************************************************************************/
189 class FGGroundNetwork : public FGATCController
195 FGTaxiNodeVector nodes;
196 FGTaxiSegmentVector segments;
200 TaxiRouteVector routes;
201 TrafficVector activeTraffic;
202 TrafficVectorIterator currTraffic;
203 SGWayPoint destination;
206 double totalDistance, maxDistance;
207 FGTowerController *towerController;
211 void printRoutingError(string);
213 void checkSpeedAdjustment(int id, double lat, double lon,
214 double heading, double speed, double alt);
215 void checkHoldPosition(int id, double lat, double lon,
216 double heading, double speed, double alt);
222 void addNode (const FGTaxiNode& node);
223 void addNodes (FGParkingVec *parkings);
224 void addSegment(const FGTaxiSegment& seg);
227 bool exists() { return hasNetwork; };
228 void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
229 int findNearestNode(double lat, double lon);
230 FGTaxiNode *findNode(int idx);
231 FGTaxiSegment *findSegment(int idx);
232 FGTaxiRoute findShortestRoute(int start, int end);
233 void trace(FGTaxiNode *, int, int, double dist);
235 void setParent(FGAirport *par) { parent = par; };
237 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
238 double lat, double lon, double hdg, double spd, double alt,
239 double radius, int leg, string callsign);
240 virtual void signOff(int id);
241 virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
242 virtual bool hasInstruction(int id);
243 virtual FGATCInstruction getInstruction(int id);