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>
37 #include "parking.hxx"
38 #include "trafficcontrol.hxx"
42 class FGTaxiSegment; // forward reference
43 class FGAIFlightPlan; // forward reference
45 typedef vector<FGTaxiSegment*> FGTaxiSegmentVector;
46 typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentVectorIterator;
48 //typedef vector<FGTaxiSegment*> FGTaxiSegmentPointerVector;
49 //typedef vector<FGTaxiSegment*>::iterator FGTaxiSegmentPointerVectorIterator;
51 /**************************************************************************************
53 *************************************************************************************/
60 FGTaxiSegmentVector next; // a vector of pointers to all the segments leaving from this node
64 FGTaxiNode(double, double, int);
66 void setIndex(int idx) { index = idx;};
67 void setLatitude (double val) { lat = val;};
68 void setLongitude(double val) { lon = val;};
69 void setLatitude (const string& val) { lat = processPosition(val); };
70 void setLongitude(const string& val) { lon = processPosition(val); };
71 void addSegment(FGTaxiSegment *segment) { next.push_back(segment); };
73 double getLatitude() { return lat;};
74 double getLongitude(){ return lon;};
76 int getIndex() { return index; };
77 FGTaxiNode *getAddress() { return this;};
78 FGTaxiSegmentVectorIterator getBeginRoute() { return next.begin(); };
79 FGTaxiSegmentVectorIterator getEndRoute() { return next.end(); };
80 bool operator<(const FGTaxiNode &other) const { return index < other.index; };
83 typedef vector<FGTaxiNode*> FGTaxiNodeVector;
84 typedef vector<FGTaxiNode*>::iterator FGTaxiNodeVectorIterator;
86 /***************************************************************************************
88 **************************************************************************************/
98 FGTaxiSegment *oppositeDirection;
102 //FGTaxiSegment(FGTaxiNode *, FGTaxiNode *, int);
104 void setIndex (int val) { index = val; };
105 void setStartNodeRef (int val) { startNode = val; };
106 void setEndNodeRef (int val) { endNode = val; };
108 void setOpposite(FGTaxiSegment *opp) { oppositeDirection = opp; };
110 void setStart(FGTaxiNodeVector *nodes);
111 void setEnd (FGTaxiNodeVector *nodes);
112 void setTrackDistance();
114 FGTaxiNode * getEnd() { return end;};
115 FGTaxiNode * getStart() { return start; };
116 double getLength() { return length; };
117 int getIndex() { return index; };
119 FGTaxiSegment *getAddress() { return this;};
121 bool operator<(const FGTaxiSegment &other) const { return index < other.index; };
122 FGTaxiSegment *opposite() { return oppositeDirection; };
128 typedef vector<int> intVec;
129 typedef vector<int>::iterator intVecIterator;
131 /***************************************************************************************
133 **************************************************************************************/
140 intVecIterator currNode;
141 intVecIterator currRoute;
144 FGTaxiRoute() { distance = 0; currNode = nodes.begin(); currRoute = routes.begin();};
145 FGTaxiRoute(intVec nds, intVec rts, double dist) {
149 currNode = nodes.begin();
151 bool operator< (const FGTaxiRoute &other) const {return distance < other.distance; };
152 bool empty () { return nodes.begin() == nodes.end(); };
154 bool next(int *nde, int *rte);
155 void rewind(int legNr);
157 void first() { currNode = nodes.begin(); currRoute = routes.begin(); };
158 int size() { return nodes.size(); };
161 typedef vector<FGTaxiRoute> TaxiRouteVector;
162 typedef vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
167 /**************************************************************************************
168 * class FGGroundNetWork
169 *************************************************************************************/
170 class FGGroundNetwork : public FGATCController
174 FGTaxiNodeVector nodes;
175 FGTaxiSegmentVector segments;
179 TaxiRouteVector routes;
180 TrafficVector activeTraffic;
181 TrafficVectorIterator currTraffic;
184 double totalDistance, maxDistance;
185 FGTowerController *towerController;
187 void printRoutingError(string);
189 void checkSpeedAdjustment(int id, double lat, double lon,
190 double heading, double speed, double alt);
191 void checkHoldPosition(int id, double lat, double lon,
192 double heading, double speed, double alt);
198 void addNode (const FGTaxiNode& node);
199 void addNodes (FGParkingVec *parkings);
200 void addSegment(const FGTaxiSegment& seg);
203 bool exists() { return hasNetwork; };
204 void setTowerController(FGTowerController *twrCtrlr) { towerController = twrCtrlr; };
205 int findNearestNode(double lat, double lon);
206 FGTaxiNode *findNode(int idx);
207 FGTaxiSegment *findSegment(int idx);
208 FGTaxiRoute findShortestRoute(int start, int end);
209 void trace(FGTaxiNode *, int, int, double dist);
211 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
212 double lat, double lon, double hdg, double spd, double alt, double radius, int leg);
213 virtual void signOff(int id);
214 virtual void update(int id, double lat, double lon, double heading, double speed, double alt, double dt);
215 virtual bool hasInstruction(int id);
216 virtual FGATCInstruction getInstruction(int id);