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>
35 class FGAirportDynamicsXMLLoader;
44 Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
46 int getId() { return id; };
47 void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
48 const time_t getBlockTime() const { return blocktime; };
49 time_t getTimeStamp() { return touch; };
50 bool operator< (const Block &other) const { return blocktime < other.blocktime; };
53 /***************************************************************************************
55 **************************************************************************************/
59 // weak (non-owning) pointers deliberately here:
60 // the ground-network owns the nodes
61 const FGTaxiNode* startNode;
62 const FGTaxiNode* endNode;
68 FGTaxiSegment *oppositeDirection; // also deliberatley weak
70 friend class FGGroundNetwork;
72 FGTaxiSegment(FGTaxiNode* start, FGTaxiNode* end);
74 void setIndex (int val) {
78 void setDimensions(double elevation);
79 void block(int id, time_t blockTime, time_t now);
80 void unblock(time_t now);
81 bool hasBlock(time_t now);
83 FGTaxiNodeRef getEnd() const;
84 FGTaxiNodeRef getStart() const;
86 double getLength() const;
88 // compute the center of the arc
89 SGGeod getCenter() const;
91 double getHeading() const;
97 int getPenalty(int nGates);
99 bool operator<(const FGTaxiSegment &other) const {
100 return index < other.index;
103 FGTaxiSegment *opposite() {
104 return oppositeDirection;
108 /***************************************************************************************
110 **************************************************************************************/
114 FGTaxiNodeVector nodes;
117 FGTaxiNodeVector::iterator currNode;
118 intVec::iterator currRoute;
123 currNode = nodes.begin();
124 currRoute = routes.begin();
127 FGTaxiRoute(const FGTaxiNodeVector& nds, intVec rts, double dist, int dpth) {
131 currNode = nodes.begin();
132 currRoute = routes.begin();
135 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
137 routes = other.routes;
138 distance = other.distance;
139 currNode = nodes.begin();
140 currRoute = routes.begin();
144 FGTaxiRoute(const FGTaxiRoute& copy) :
147 distance(copy.distance),
148 currNode(nodes.begin()),
149 currRoute(routes.begin())
152 bool operator< (const FGTaxiRoute &other) const {
153 return distance < other.distance;
156 return nodes.empty();
158 bool next(FGTaxiNodeRef& nde, int *rte);
161 currNode = nodes.begin();
162 currRoute = routes.begin();
168 return nodes.end() - currNode;
172 /**************************************************************************************
173 * class FGGroundNetWork
174 *************************************************************************************/
175 class FGGroundNetwork : public FGATCController
178 friend class FGAirportDynamicsXMLLoader;
180 FGAirportDynamics* dynamics; // weak back-pointer to our owner
182 bool networkInitialized;
188 FGTaxiSegmentVector segments;
190 TrafficVector activeTraffic;
191 TrafficVectorIterator currTraffic;
193 double totalDistance, maxDistance;
194 FGTowerController *towerController;
197 FGParkingList m_parkings;
198 FGTaxiNodeVector m_nodes;
200 FGTaxiNodeRef findNodeByIndex(int index) const;
202 //void printRoutingError(string);
204 void checkSpeedAdjustment(int id, double lat, double lon,
205 double heading, double speed, double alt);
206 void checkHoldPosition(int id, double lat, double lon,
207 double heading, double speed, double alt);
210 void addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to);
211 void addParking(const FGParkingRef& park);
213 FGTaxiNodeVector segmentsFrom(const FGTaxiNodeRef& from) const;
219 void setVersion (int v) { version = v;};
220 int getVersion() { return version; };
222 void init(FGAirportDynamics* pr);
226 void setTowerController(FGTowerController *twrCtrlr) {
227 towerController = twrCtrlr;
230 FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const;
231 FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
233 FGTaxiSegment *findSegment(unsigned int idx) const;
235 const FGParkingList& allParkings() const;
238 * Find the taxiway segment joining two (ground-net) nodes. Returns
239 * NULL if no such segment exists.
240 * It is permitted to pass HULL for the 'to' indicating that any
241 * segment originating at 'from' is acceptable.
243 FGTaxiSegment *findSegment(const FGTaxiNode* from, const FGTaxiNode* to) const;
245 FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch=true);
247 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
248 double lat, double lon, double hdg, double spd, double alt,
249 double radius, int leg, FGAIAircraft *aircraft);
250 virtual void signOff(int id);
251 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
252 virtual bool hasInstruction(int id);
253 virtual FGATCInstruction getInstruction(int id);
255 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
257 bool checkForCircularWaits(int id);
258 virtual void render(bool);
259 virtual std::string getName();
260 virtual void update(double dt);
262 void addVersion(int v) {version = v; };