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>
32 #include "parking.hxx"
33 #include <ATC/trafficcontrol.hxx>
42 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
44 int getId() { return id; };
45 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
46 const time_t getBlockTime() const { return blocktime; };
47 time_t getTimeStamp() { return touch; };
48 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
51 /***************************************************************************************
53 **************************************************************************************/
57 const PositionedID startNode;
58 const PositionedID endNode;
64 FGTaxiSegment *oppositeDirection;
66 friend class FGGroundNetwork;
68 FGTaxiSegment(PositionedID start, PositionedID end);
70 void setIndex (int val) {
74 void setDimensions(double elevation);
75 void block(int id, time_t blockTime, time_t now);
76 void unblock(time_t now);
77 bool hasBlock(time_t now);
79 FGTaxiNodeRef getEnd() const;
80 FGTaxiNodeRef getStart() const;
82 double getLength() const;
84 // compute the center of the arc
85 SGGeod getCenter() const;
87 double getHeading() const;
93 int getPenalty(int nGates);
95 bool operator<(const FGTaxiSegment &other) const {
96 return index < other.index;
99 FGTaxiSegment *opposite() {
100 return oppositeDirection;
104 /***************************************************************************************
106 **************************************************************************************/
110 PositionedIDVec nodes;
113 PositionedIDVec::iterator currNode;
114 intVec::iterator currRoute;
119 currNode = nodes.begin();
120 currRoute = routes.begin();
123 FGTaxiRoute(const PositionedIDVec& nds, intVec rts, double dist, int dpth) {
127 currNode = nodes.begin();
128 currRoute = routes.begin();
131 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
133 routes = other.routes;
134 distance = other.distance;
135 currNode = nodes.begin();
136 currRoute = routes.begin();
140 FGTaxiRoute(const FGTaxiRoute& copy) :
143 distance(copy.distance),
144 currNode(nodes.begin()),
145 currRoute(routes.begin())
148 bool operator< (const FGTaxiRoute &other) const {
149 return distance < other.distance;
152 return nodes.empty();
154 bool next(PositionedID *nde, int *rte);
157 currNode = nodes.begin();
158 currRoute = routes.begin();
164 return nodes.end() - currNode;
168 /**************************************************************************************
169 * class FGGroundNetWork
170 *************************************************************************************/
171 class FGGroundNetwork : public FGATCController
175 bool networkInitialized;
181 FGTaxiSegmentVector segments;
183 TrafficVector activeTraffic;
184 TrafficVectorIterator currTraffic;
186 double totalDistance, maxDistance;
187 FGTowerController *towerController;
191 //void printRoutingError(string);
193 void checkSpeedAdjustment(int id, double lat, double lon,
194 double heading, double speed, double alt);
195 void checkHoldPosition(int id, double lat, double lon,
196 double heading, double speed, double alt);
206 void setVersion (int v) { version = v;};
207 int getVersion() { return version; };
209 void init(FGAirport* pr);
213 void setTowerController(FGTowerController *twrCtrlr) {
214 towerController = twrCtrlr;
217 int findNearestNode(const SGGeod& aGeod) const;
218 int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
220 FGTaxiNodeRef findNode(PositionedID idx) const;
221 FGTaxiSegment *findSegment(unsigned idx) const;
224 * Find the taxiway segment joining two (ground-net) nodes. Returns
225 * NULL if no such segment exists.
226 * It is permitted to pass 0 for the 'to' ID, indicating that any
227 * segment originating at 'from' is acceptable.
229 FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
231 FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
233 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
234 double lat, double lon, double hdg, double spd, double alt,
235 double radius, int leg, FGAIAircraft *aircraft);
236 virtual void signOff(int id);
237 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
238 virtual bool hasInstruction(int id);
239 virtual FGATCInstruction getInstruction(int id);
241 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
243 bool checkForCircularWaits(int id);
244 virtual void render(bool);
245 virtual std::string getName();
246 virtual void update(double dt);
248 void saveElevationCache();
249 void addVersion(int v) {version = v; };