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 <ATC/trafficcontrol.hxx>
41 class FGTaxiSegment; // forward reference
42 class FGAIFlightPlan; // forward reference
43 class FGAirport; // forward reference
45 typedef std::vector<FGTaxiSegment*> FGTaxiSegmentVector;
46 typedef FGTaxiSegmentVector::iterator FGTaxiSegmentVectorIterator;
48 typedef std::map<int, FGTaxiNode_ptr> IndexTaxiNodeMap;
57 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
59 int getId() { return id; };
60 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
61 const time_t getBlockTime() const { return blocktime; };
62 time_t getTimeStamp() { return touch; };
63 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
66 typedef std::vector<Block> BlockList;
67 typedef BlockList::iterator BlockListIterator;
69 /***************************************************************************************
71 **************************************************************************************/
85 FGTaxiSegment *oppositeDirection;
88 FGTaxiSegment(int start, int end, bool isPushBack);
90 void setIndex (int val) {
94 void setOpposite(FGTaxiSegment *opp) {
95 oppositeDirection = opp;
98 bool bindToNodes(const IndexTaxiNodeMap& nodes);
100 void setDimensions(double elevation);
101 void block(int id, time_t blockTime, time_t now);
102 void unblock(time_t now);
103 bool hasBlock(time_t now);
105 FGTaxiNode * getEnd() {
108 FGTaxiNode * getStart() {
118 // compute the center of the arc
119 SGGeod getCenter() const;
121 double getHeading() {
125 return isPushBackRoute;
128 int getPenalty(int nGates);
130 bool operator<(const FGTaxiSegment &other) const {
131 return index < other.index;
133 //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
134 FGTaxiSegment *opposite() {
135 return oppositeDirection;
142 typedef std::vector<int> intVec;
143 typedef std::vector<int>::iterator intVecIterator;
147 /***************************************************************************************
149 **************************************************************************************/
157 intVecIterator currNode;
158 intVecIterator currRoute;
163 currNode = nodes.begin();
164 currRoute = routes.begin();
166 FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
170 currNode = nodes.begin();
171 currRoute = routes.begin();
175 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
177 routes = other.routes;
178 distance = other.distance;
179 // depth = other.depth;
180 currNode = nodes.begin();
181 currRoute = routes.begin();
185 FGTaxiRoute(const FGTaxiRoute& copy) :
188 distance(copy.distance),
189 // depth(copy.depth),
190 currNode(nodes.begin()),
191 currRoute(routes.begin())
194 bool operator< (const FGTaxiRoute &other) const {
195 return distance < other.distance;
198 return nodes.begin() == nodes.end();
201 bool next(int *nde, int *rte);
202 void rewind(int legNr);
205 currNode = nodes.begin();
206 currRoute = routes.begin();
212 return nodes.end() - currNode;
215 // int getDepth() { return depth; };
218 typedef std::vector<FGTaxiRoute> TaxiRouteVector;
219 typedef std::vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
221 /**************************************************************************************
222 * class FGGroundNetWork
223 *************************************************************************************/
224 class FGGroundNetwork : public FGATCController
228 bool networkInitialized;
234 IndexTaxiNodeMap nodes;
235 FGTaxiNodeVector pushBackNodes;
237 FGTaxiSegmentVector segments;
239 TaxiRouteVector routes;
240 TrafficVector activeTraffic;
241 TrafficVectorIterator currTraffic;
244 double totalDistance, maxDistance;
245 FGTowerController *towerController;
249 //void printRoutingError(string);
251 void checkSpeedAdjustment(int id, double lat, double lon,
252 double heading, double speed, double alt);
253 void checkHoldPosition(int id, double lat, double lon,
254 double heading, double speed, double alt);
262 void addNode (FGTaxiNode* node);
263 void addNodes (FGParkingVec *parkings);
264 void addSegment(FGTaxiSegment* seg);
265 void setVersion (int v) { version = v;};
267 int getVersion() { return version; };
273 void setTowerController(FGTowerController *twrCtrlr) {
274 towerController = twrCtrlr;
277 int findNearestNode(const SGGeod& aGeod);
278 int findNearestNodeOnRunway(const SGGeod& aGeod);
280 FGTaxiNode *findNode(unsigned idx);
281 FGTaxiSegment *findSegment(unsigned idx);
282 FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
283 //void trace(FGTaxiNode *, int, int, double dist);
289 void setParent(FGAirport *par) {
293 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
294 double lat, double lon, double hdg, double spd, double alt,
295 double radius, int leg, FGAIAircraft *aircraft);
296 virtual void signOff(int id);
297 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
298 virtual bool hasInstruction(int id);
299 virtual FGATCInstruction getInstruction(int id);
301 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
303 bool checkForCircularWaits(int id);
304 virtual void render(bool);
305 virtual std::string getName();
306 virtual void update(double dt);
308 void saveElevationCache();
309 void addVersion(int v) {version = v; };