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>
35 #include "parking.hxx"
36 #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 **************************************************************************************/
75 const PositionedID startNode;
76 const PositionedID endNode;
82 FGTaxiSegment *oppositeDirection;
84 friend class FGGroundNetwork;
86 FGTaxiSegment(PositionedID start, PositionedID end);
88 void setIndex (int val) {
92 void setDimensions(double elevation);
93 void block(int id, time_t blockTime, time_t now);
94 void unblock(time_t now);
95 bool hasBlock(time_t now);
97 FGTaxiNode * getEnd() const;
98 FGTaxiNode * getStart() const;
100 double getLength() const;
102 // compute the center of the arc
103 SGGeod getCenter() const;
105 double getHeading() const;
111 int getPenalty(int nGates);
113 bool operator<(const FGTaxiSegment &other) const {
114 return index < other.index;
117 FGTaxiSegment *opposite() {
118 return oppositeDirection;
125 typedef std::vector<int> intVec;
126 typedef std::vector<int>::iterator intVecIterator;
130 /***************************************************************************************
132 **************************************************************************************/
136 PositionedIDVec nodes;
138 PositionedIDVec::iterator currNode;
143 currNode = nodes.begin();
146 FGTaxiRoute(const PositionedIDVec& nds, double dist, int dpth) {
149 currNode = nodes.begin();
152 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
154 distance = other.distance;
155 currNode = nodes.begin();
159 FGTaxiRoute(const FGTaxiRoute& copy) :
161 distance(copy.distance),
162 currNode(nodes.begin())
165 bool operator< (const FGTaxiRoute &other) const {
166 return distance < other.distance;
169 return nodes.empty();
171 bool next(PositionedID *nde);
174 currNode = nodes.begin();
180 return nodes.end() - currNode;
184 typedef std::vector<FGTaxiRoute> TaxiRouteVector;
185 typedef std::vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
187 /**************************************************************************************
188 * class FGGroundNetWork
189 *************************************************************************************/
190 class FGGroundNetwork : public FGATCController
194 bool networkInitialized;
200 FGTaxiSegmentVector segments;
202 TrafficVector activeTraffic;
203 TrafficVectorIterator currTraffic;
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);
226 void setVersion (int v) { version = v;};
227 int getVersion() { return version; };
229 void init(FGAirport* pr);
233 void setTowerController(FGTowerController *twrCtrlr) {
234 towerController = twrCtrlr;
237 int findNearestNode(const SGGeod& aGeod) const;
238 int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
240 FGTaxiNode *findNode(PositionedID idx) const;
241 FGTaxiSegment *findSegment(unsigned idx) const;
244 * Find the taxiway segment joining two (ground-net) nodes. Returns
245 * NULL if no such segment exists.
246 * It is permitted to pass 0 for the 'to' ID, indicating that any
247 * segment originating at 'from' is acceptable.
249 FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
251 FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
253 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
254 double lat, double lon, double hdg, double spd, double alt,
255 double radius, int leg, FGAIAircraft *aircraft);
256 virtual void signOff(int id);
257 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
258 virtual bool hasInstruction(int id);
259 virtual FGATCInstruction getInstruction(int id);
261 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
263 bool checkForCircularWaits(int id);
264 virtual void render(bool);
265 virtual std::string getName();
266 virtual void update(double dt);
268 void saveElevationCache();
269 void addVersion(int v) {version = v; };