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;
112 PositionedIDVec::iterator currNode;
117 currNode = nodes.begin();
120 FGTaxiRoute(const PositionedIDVec& nds, double dist, int dpth) {
123 currNode = nodes.begin();
126 FGTaxiRoute& operator= (const FGTaxiRoute &other) {
128 distance = other.distance;
129 currNode = nodes.begin();
133 FGTaxiRoute(const FGTaxiRoute& copy) :
135 distance(copy.distance),
136 currNode(nodes.begin())
139 bool operator< (const FGTaxiRoute &other) const {
140 return distance < other.distance;
143 return nodes.empty();
145 bool next(PositionedID *nde);
148 currNode = nodes.begin();
154 return nodes.end() - currNode;
158 /**************************************************************************************
159 * class FGGroundNetWork
160 *************************************************************************************/
161 class FGGroundNetwork : public FGATCController
165 bool networkInitialized;
171 FGTaxiSegmentVector segments;
173 TrafficVector activeTraffic;
174 TrafficVectorIterator currTraffic;
177 double totalDistance, maxDistance;
178 FGTowerController *towerController;
182 //void printRoutingError(string);
184 void checkSpeedAdjustment(int id, double lat, double lon,
185 double heading, double speed, double alt);
186 void checkHoldPosition(int id, double lat, double lon,
187 double heading, double speed, double alt);
197 void setVersion (int v) { version = v;};
198 int getVersion() { return version; };
200 void init(FGAirport* pr);
204 void setTowerController(FGTowerController *twrCtrlr) {
205 towerController = twrCtrlr;
208 int findNearestNode(const SGGeod& aGeod) const;
209 int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
211 FGTaxiNodeRef findNode(PositionedID idx) const;
212 FGTaxiSegment *findSegment(unsigned idx) const;
215 * Find the taxiway segment joining two (ground-net) nodes. Returns
216 * NULL if no such segment exists.
217 * It is permitted to pass 0 for the 'to' ID, indicating that any
218 * segment originating at 'from' is acceptable.
220 FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
222 FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
224 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
225 double lat, double lon, double hdg, double spd, double alt,
226 double radius, int leg, FGAIAircraft *aircraft);
227 virtual void signOff(int id);
228 virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
229 virtual bool hasInstruction(int id);
230 virtual FGATCInstruction getInstruction(int id);
232 bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
234 bool checkForCircularWaits(int id);
235 virtual void render(bool);
236 virtual std::string getName();
237 virtual void update(double dt);
239 void saveElevationCache();
240 void addVersion(int v) {version = v; };