]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Merge commit '6c1934fcdf7dc91897e9d4dc8b8b6810b1de6a51' into next
[flightgear.git] / src / Airports / groundnetwork.hxx
1 // groundnet.hxx - A number of classes to handle taxiway
2 // assignments by the AI code
3 //
4 // Written by Durk Talsma, started June 2005.
5 //
6 // Copyright (C) 2004 Durk Talsma.
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23
24 #ifndef _GROUNDNETWORK_HXX_
25 #define _GROUNDNETWORK_HXX_
26
27 #include <simgear/compiler.h>
28
29 #include <string>
30
31 #include "gnnode.hxx"
32 #include "parking.hxx"
33 #include <ATC/trafficcontrol.hxx>
34
35 class Block
36 {
37 private:
38     int id;
39     time_t blocktime;
40     time_t touch;
41 public:
42     Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
43     ~Block() {};
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; };
49 };
50
51 /***************************************************************************************
52  * class FGTaxiSegment
53  **************************************************************************************/
54 class FGTaxiSegment
55 {
56 private:
57     const PositionedID startNode;
58     const PositionedID endNode;
59     
60     bool isActive;
61     BlockList blockTimes;
62
63     int index;
64     FGTaxiSegment *oppositeDirection;
65
66     friend class FGGroundNetwork;
67 public:
68     FGTaxiSegment(PositionedID start, PositionedID end);
69   
70     void setIndex        (int val) {
71         index     = val;
72     };
73   
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);
78
79     FGTaxiNodeRef getEnd() const;
80     FGTaxiNodeRef getStart() const;
81   
82     double getLength() const;
83   
84     // compute the center of the arc
85     SGGeod getCenter() const;
86   
87     double getHeading() const;
88     
89     int getIndex() {
90       return index;
91     };
92
93     int getPenalty(int nGates);
94
95     bool operator<(const FGTaxiSegment &other) const {
96         return index < other.index;
97     };
98
99     FGTaxiSegment *opposite() {
100         return oppositeDirection;
101     };
102 };
103
104 /***************************************************************************************
105  * class FGTaxiRoute
106  **************************************************************************************/
107 class FGTaxiRoute
108 {
109 private:
110     PositionedIDVec nodes;
111     intVec routes;
112     double distance;
113     PositionedIDVec::iterator currNode;
114     intVec::iterator currRoute;
115
116 public:
117     FGTaxiRoute() {
118         distance = 0;
119         currNode = nodes.begin();
120         currRoute = routes.begin();
121     };
122   
123     FGTaxiRoute(const PositionedIDVec& nds, intVec rts,  double dist, int dpth) {
124         nodes = nds;
125         routes = rts;
126         distance = dist;
127         currNode = nodes.begin();
128         currRoute = routes.begin();
129     };
130
131     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
132         nodes = other.nodes;
133         routes = other.routes;
134         distance = other.distance;
135         currNode = nodes.begin();
136         currRoute = routes.begin();
137         return *this;
138     };
139
140     FGTaxiRoute(const FGTaxiRoute& copy) :
141             nodes(copy.nodes),
142             routes(copy.routes),
143             distance(copy.distance),
144             currNode(nodes.begin()),
145             currRoute(routes.begin())
146     {};
147
148     bool operator< (const FGTaxiRoute &other) const {
149         return distance < other.distance;
150     };
151     bool empty () {
152         return nodes.empty();
153     };
154     bool next(PositionedID *nde, int *rte);
155   
156     void first() {
157         currNode = nodes.begin();
158         currRoute = routes.begin();
159     };
160     int size() {
161         return nodes.size();
162     };
163     int nodesLeft() {
164         return nodes.end() - currNode;
165     };
166 };
167
168 /**************************************************************************************
169  * class FGGroundNetWork
170  *************************************************************************************/
171 class FGGroundNetwork : public FGATCController
172 {
173 private:
174     bool hasNetwork;
175     bool networkInitialized;
176     time_t nextSave;
177     //int maxDepth;
178     int count;
179     int version;
180   
181     FGTaxiSegmentVector segments;
182
183     TrafficVector activeTraffic;
184     TrafficVectorIterator currTraffic;
185
186     double totalDistance, maxDistance;
187     FGTowerController *towerController;
188     FGAirport *parent;
189
190
191     //void printRoutingError(string);
192
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);
197
198
199     void parseCache();
200   
201     void loadSegments();
202 public:
203     FGGroundNetwork();
204     ~FGGroundNetwork();
205     
206     void setVersion (int v) { version = v;};
207     int getVersion() { return version; };
208
209     void init(FGAirport* pr);
210     bool exists() {
211         return hasNetwork;
212     };
213     void setTowerController(FGTowerController *twrCtrlr) {
214         towerController = twrCtrlr;
215     };
216
217     int findNearestNode(const SGGeod& aGeod) const;
218     int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
219
220     FGTaxiNodeRef findNode(PositionedID idx) const;
221     FGTaxiSegment *findSegment(unsigned idx) const;
222   
223     /**
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.
228      */
229     FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
230   
231     FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
232
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);
240
241     bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
242                                 AtcMsgDir msgDir);
243     bool checkForCircularWaits(int id);
244     virtual void render(bool);
245     virtual std::string getName();
246     virtual void update(double dt);
247
248     void saveElevationCache();
249     void addVersion(int v) {version = v; };
250 };
251
252
253 #endif