]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Checkpoint - ground-net skips the cache
[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 FGAirportDynamicsXMLLoader;
36
37 class Block
38 {
39 private:
40     int id;
41     time_t blocktime;
42     time_t touch;
43 public:
44     Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
45     ~Block() {};
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; };
51 };
52
53 /***************************************************************************************
54  * class FGTaxiSegment
55  **************************************************************************************/
56 class FGTaxiSegment
57 {
58 private:
59     // weak (non-owning) pointers deliberately here:
60     // the ground-network owns the nodes
61     const FGTaxiNode* startNode;
62     const FGTaxiNode* endNode;
63     
64     bool isActive;
65     BlockList blockTimes;
66
67     int index;
68     FGTaxiSegment *oppositeDirection; // also deliberatley weak
69
70     friend class FGGroundNetwork;
71 public:
72     FGTaxiSegment(FGTaxiNode* start, FGTaxiNode* end);
73   
74     void setIndex        (int val) {
75         index     = val;
76     };
77   
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);
82
83     FGTaxiNodeRef getEnd() const;
84     FGTaxiNodeRef getStart() const;
85   
86     double getLength() const;
87   
88     // compute the center of the arc
89     SGGeod getCenter() const;
90   
91     double getHeading() const;
92     
93     int getIndex() {
94       return index;
95     };
96
97     int getPenalty(int nGates);
98
99     bool operator<(const FGTaxiSegment &other) const {
100         return index < other.index;
101     };
102
103     FGTaxiSegment *opposite() {
104         return oppositeDirection;
105     };
106 };
107
108 /***************************************************************************************
109  * class FGTaxiRoute
110  **************************************************************************************/
111 class FGTaxiRoute
112 {
113 private:
114     FGTaxiNodeVector nodes;
115     intVec routes;
116     double distance;
117     FGTaxiNodeVector::iterator currNode;
118     intVec::iterator currRoute;
119
120 public:
121     FGTaxiRoute() {
122         distance = 0;
123         currNode = nodes.begin();
124         currRoute = routes.begin();
125     };
126   
127     FGTaxiRoute(const FGTaxiNodeVector& nds, intVec rts,  double dist, int dpth) {
128         nodes = nds;
129         routes = rts;
130         distance = dist;
131         currNode = nodes.begin();
132         currRoute = routes.begin();
133     };
134
135     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
136         nodes = other.nodes;
137         routes = other.routes;
138         distance = other.distance;
139         currNode = nodes.begin();
140         currRoute = routes.begin();
141         return *this;
142     };
143
144     FGTaxiRoute(const FGTaxiRoute& copy) :
145             nodes(copy.nodes),
146             routes(copy.routes),
147             distance(copy.distance),
148             currNode(nodes.begin()),
149             currRoute(routes.begin())
150     {};
151
152     bool operator< (const FGTaxiRoute &other) const {
153         return distance < other.distance;
154     };
155     bool empty () {
156         return nodes.empty();
157     };
158     bool next(FGTaxiNodeRef& nde, int *rte);
159   
160     void first() {
161         currNode = nodes.begin();
162         currRoute = routes.begin();
163     };
164     int size() {
165         return nodes.size();
166     };
167     int nodesLeft() {
168         return nodes.end() - currNode;
169     };
170 };
171
172 /**************************************************************************************
173  * class FGGroundNetWork
174  *************************************************************************************/
175 class FGGroundNetwork : public FGATCController
176 {
177 private:
178     friend class FGAirportDynamicsXMLLoader;
179
180     bool hasNetwork;
181     bool networkInitialized;
182     time_t nextSave;
183     //int maxDepth;
184     int count;
185     int version;
186   
187     FGTaxiSegmentVector segments;
188
189     TrafficVector activeTraffic;
190     TrafficVectorIterator currTraffic;
191
192     double totalDistance, maxDistance;
193     FGTowerController *towerController;
194     FGAirport *parent;
195
196     FGParkingList m_parkings;
197     FGTaxiNodeVector m_nodes;
198
199     FGTaxiNodeRef findNodeByIndex(int index) const;
200
201     //void printRoutingError(string);
202
203     void checkSpeedAdjustment(int id, double lat, double lon,
204                               double heading, double speed, double alt);
205     void checkHoldPosition(int id, double lat, double lon,
206                            double heading, double speed, double alt);
207
208
209     void addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to);
210     void addParking(const FGParkingRef& park);
211
212     FGTaxiNodeVector segmentsFrom(const FGTaxiNodeRef& from) const;
213
214 public:
215     FGGroundNetwork();
216     ~FGGroundNetwork();
217     
218     void setVersion (int v) { version = v;};
219     int getVersion() { return version; };
220
221     void init(FGAirport* pr);
222     bool exists() {
223         return hasNetwork;
224     };
225     void setTowerController(FGTowerController *twrCtrlr) {
226         towerController = twrCtrlr;
227     };
228
229     FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const;
230     FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
231
232     FGTaxiSegment *findSegment(unsigned int idx) const;
233
234     const FGParkingList& allParkings() const;
235
236     /**
237      * Find the taxiway segment joining two (ground-net) nodes. Returns
238      * NULL if no such segment exists.
239      * It is permitted to pass HULL for the 'to' indicating that any
240      * segment originating at 'from' is acceptable.
241      */
242     FGTaxiSegment *findSegment(const FGTaxiNode* from, const FGTaxiNode* to) const;
243   
244     FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch=true);
245
246     virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
247                                   double lat, double lon, double hdg, double spd, double alt,
248                                   double radius, int leg, FGAIAircraft *aircraft);
249     virtual void signOff(int id);
250     virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
251     virtual bool hasInstruction(int id);
252     virtual FGATCInstruction getInstruction(int id);
253
254     bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
255                                 AtcMsgDir msgDir);
256     bool checkForCircularWaits(int id);
257     virtual void render(bool);
258     virtual std::string getName();
259     virtual void update(double dt);
260
261     void addVersion(int v) {version = v; };
262 };
263
264
265 #endif