]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
Make FGTaxiNode and FGParking inherit FGPositioned.
[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 #include <vector>
31 #include <list>
32 #include <map>
33
34 class Block;
35
36 #include "gnnode.hxx"
37 #include "parking.hxx"
38 #include <ATC/trafficcontrol.hxx>
39
40
41 class FGTaxiSegment; // forward reference
42 class FGAIFlightPlan; // forward reference
43 class FGAirport;      // forward reference
44
45 typedef std::vector<FGTaxiSegment*>  FGTaxiSegmentVector;
46 typedef FGTaxiSegmentVector::iterator FGTaxiSegmentVectorIterator;
47
48 typedef std::map<int, FGTaxiNode_ptr> IndexTaxiNodeMap;
49
50 class Block
51 {
52 private:
53     int id;
54     time_t blocktime;
55     time_t touch;
56 public:
57     Block(int i, time_t bt, time_t curr) { id = i; blocktime= bt; touch = curr; };
58     ~Block() {};
59     int getId() { return id; };
60     void updateTimeStamps(time_t bt, time_t now) { blocktime = (bt < blocktime) ? bt : blocktime; touch = now; };
61     const time_t getBlockTime() const { return blocktime; };
62     time_t getTimeStamp() { return touch; };
63     bool operator< (const Block &other) const { return blocktime < other.blocktime; };
64 };
65
66 typedef std::vector<Block> BlockList;
67 typedef BlockList::iterator BlockListIterator;
68
69 /***************************************************************************************
70  * class FGTaxiSegment
71  **************************************************************************************/
72 class FGTaxiSegment
73 {
74 private:
75     int startNode;
76     int endNode;
77     double length;
78     double heading;
79     bool isActive;
80     bool isPushBackRoute;
81     BlockList blockTimes;
82     FGTaxiNode *start;
83     FGTaxiNode *end;
84     int index;
85     FGTaxiSegment *oppositeDirection;
86
87 public:
88   FGTaxiSegment(int start, int end, bool isPushBack);
89   
90     void setIndex        (int val) {
91         index     = val;
92     };
93
94     void setOpposite(FGTaxiSegment *opp) {
95         oppositeDirection = opp;
96     };
97
98     bool bindToNodes(const IndexTaxiNodeMap& nodes);
99   
100     void setDimensions(double elevation);
101     void block(int id, time_t blockTime, time_t now);
102     void unblock(time_t now); 
103     bool hasBlock(time_t now);
104
105     FGTaxiNode * getEnd() {
106         return end;
107     };
108     FGTaxiNode * getStart() {
109         return start;
110     };
111     double getLength() {
112         return length;
113     };
114     int getIndex() {
115         return index;
116     };
117   
118     // compute the center of the arc
119     SGGeod getCenter() const;
120   
121     double getHeading()   {
122         return heading;
123     };
124     bool isPushBack() {
125         return isPushBackRoute;
126     };
127
128     int getPenalty(int nGates);
129
130     bool operator<(const FGTaxiSegment &other) const {
131         return index < other.index;
132     };
133     //bool hasSmallerHeadingDiff (const FGTaxiSegment &other) const { return headingDiff < other.headingDiff; };
134     FGTaxiSegment *opposite() {
135         return oppositeDirection;
136     };
137 };
138
139
140
141
142 typedef std::vector<int> intVec;
143 typedef std::vector<int>::iterator intVecIterator;
144
145
146
147 /***************************************************************************************
148  * class FGTaxiRoute
149  **************************************************************************************/
150 class FGTaxiRoute
151 {
152 private:
153     intVec nodes;
154     intVec routes;
155     double distance;
156 //  int depth;
157     intVecIterator currNode;
158     intVecIterator currRoute;
159
160 public:
161     FGTaxiRoute() {
162         distance = 0;
163         currNode = nodes.begin();
164         currRoute = routes.begin();
165     };
166     FGTaxiRoute(intVec nds, intVec rts, double dist, int dpth) {
167         nodes = nds;
168         routes = rts;
169         distance = dist;
170         currNode = nodes.begin();
171         currRoute = routes.begin();
172 //    depth = dpth;
173     };
174
175     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
176         nodes = other.nodes;
177         routes = other.routes;
178         distance = other.distance;
179 //    depth = other.depth;
180         currNode = nodes.begin();
181         currRoute = routes.begin();
182         return *this;
183     };
184
185     FGTaxiRoute(const FGTaxiRoute& copy) :
186             nodes(copy.nodes),
187             routes(copy.routes),
188             distance(copy.distance),
189 //    depth(copy.depth),
190             currNode(nodes.begin()),
191             currRoute(routes.begin())
192     {};
193
194     bool operator< (const FGTaxiRoute &other) const {
195         return distance < other.distance;
196     };
197     bool empty () {
198         return nodes.begin() == nodes.end();
199     };
200     bool next(int *nde);
201     bool next(int *nde, int *rte);
202     void rewind(int legNr);
203
204     void first() {
205         currNode = nodes.begin();
206         currRoute = routes.begin();
207     };
208     int size() {
209         return nodes.size();
210     };
211     int nodesLeft() {
212         return nodes.end() - currNode;
213     };
214
215 //  int getDepth() { return depth; };
216 };
217
218 typedef std::vector<FGTaxiRoute> TaxiRouteVector;
219 typedef std::vector<FGTaxiRoute>::iterator TaxiRouteVectorIterator;
220
221 /**************************************************************************************
222  * class FGGroundNetWork
223  *************************************************************************************/
224 class FGGroundNetwork : public FGATCController
225 {
226 private:
227     bool hasNetwork;
228     bool networkInitialized;
229     time_t nextSave;
230     //int maxDepth;
231     int count;
232     int version;
233   
234     IndexTaxiNodeMap nodes;
235     FGTaxiNodeVector pushBackNodes;
236   
237     FGTaxiSegmentVector segments;
238
239     TaxiRouteVector routes;
240     TrafficVector activeTraffic;
241     TrafficVectorIterator currTraffic;
242
243     bool foundRoute;
244     double totalDistance, maxDistance;
245     FGTowerController *towerController;
246     FGAirport *parent;
247
248
249     //void printRoutingError(string);
250
251     void checkSpeedAdjustment(int id, double lat, double lon,
252                               double heading, double speed, double alt);
253     void checkHoldPosition(int id, double lat, double lon,
254                            double heading, double speed, double alt);
255
256
257     void parseCache();
258 public:
259     FGGroundNetwork();
260     ~FGGroundNetwork();
261
262     void addNode   (FGTaxiNode* node);
263     void addNodes  (FGParkingVec *parkings);
264     void addSegment(FGTaxiSegment* seg);
265     void setVersion (int v) { version = v;};
266     
267     int getVersion() { return version; };
268
269     void init();
270     bool exists() {
271         return hasNetwork;
272     };
273     void setTowerController(FGTowerController *twrCtrlr) {
274         towerController = twrCtrlr;
275     };
276
277     int findNearestNode(const SGGeod& aGeod);
278     int findNearestNodeOnRunway(const SGGeod& aGeod);
279
280     FGTaxiNode *findNode(unsigned idx);
281     FGTaxiSegment *findSegment(unsigned idx);
282     FGTaxiRoute findShortestRoute(int start, int end, bool fullSearch=true);
283     //void trace(FGTaxiNode *, int, int, double dist);
284
285     int getNrOfNodes() {
286         return nodes.size();
287     };
288
289     void setParent(FGAirport *par) {
290         parent = par;
291     };
292
293     virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
294                                   double lat, double lon, double hdg, double spd, double alt,
295                                   double radius, int leg, FGAIAircraft *aircraft);
296     virtual void signOff(int id);
297     virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
298     virtual bool hasInstruction(int id);
299     virtual FGATCInstruction getInstruction(int id);
300
301     bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
302                                 AtcMsgDir msgDir);
303     bool checkForCircularWaits(int id);
304     virtual void render(bool);
305     virtual std::string getName();
306     virtual void update(double dt);
307
308     void saveElevationCache();
309     void addVersion(int v) {version = v; };
310 };
311
312
313 #endif