]> git.mxchange.org Git - flightgear.git/blob - src/Airports/groundnetwork.hxx
commradio: improvements for atis speech
[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     double distance;
112     PositionedIDVec::iterator currNode;
113
114 public:
115     FGTaxiRoute() {
116         distance = 0;
117         currNode = nodes.begin();
118     };
119   
120     FGTaxiRoute(const PositionedIDVec& nds, double dist, int dpth) {
121         nodes = nds;
122         distance = dist;
123         currNode = nodes.begin();
124     };
125
126     FGTaxiRoute& operator= (const FGTaxiRoute &other) {
127         nodes = other.nodes;
128         distance = other.distance;
129         currNode = nodes.begin();
130         return *this;
131     };
132
133     FGTaxiRoute(const FGTaxiRoute& copy) :
134             nodes(copy.nodes),
135             distance(copy.distance),
136             currNode(nodes.begin())
137     {};
138
139     bool operator< (const FGTaxiRoute &other) const {
140         return distance < other.distance;
141     };
142     bool empty () {
143         return nodes.empty();
144     };
145     bool next(PositionedID *nde);
146   
147     void first() {
148         currNode = nodes.begin();
149     };
150     int size() {
151         return nodes.size();
152     };
153     int nodesLeft() {
154         return nodes.end() - currNode;
155     };
156 };
157
158 /**************************************************************************************
159  * class FGGroundNetWork
160  *************************************************************************************/
161 class FGGroundNetwork : public FGATCController
162 {
163 private:
164     bool hasNetwork;
165     bool networkInitialized;
166     time_t nextSave;
167     //int maxDepth;
168     int count;
169     int version;
170   
171     FGTaxiSegmentVector segments;
172
173     TrafficVector activeTraffic;
174     TrafficVectorIterator currTraffic;
175
176     double totalDistance, maxDistance;
177     FGTowerController *towerController;
178     FGAirport *parent;
179
180
181     //void printRoutingError(string);
182
183     void checkSpeedAdjustment(int id, double lat, double lon,
184                               double heading, double speed, double alt);
185     void checkHoldPosition(int id, double lat, double lon,
186                            double heading, double speed, double alt);
187
188
189     void parseCache();
190   
191     void loadSegments();
192 public:
193     FGGroundNetwork();
194     ~FGGroundNetwork();
195     
196     void setVersion (int v) { version = v;};
197     int getVersion() { return version; };
198
199     void init(FGAirport* pr);
200     bool exists() {
201         return hasNetwork;
202     };
203     void setTowerController(FGTowerController *twrCtrlr) {
204         towerController = twrCtrlr;
205     };
206
207     int findNearestNode(const SGGeod& aGeod) const;
208     int findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const;
209
210     FGTaxiNodeRef findNode(PositionedID idx) const;
211     FGTaxiSegment *findSegment(unsigned idx) const;
212   
213     /**
214      * Find the taxiway segment joining two (ground-net) nodes. Returns
215      * NULL if no such segment exists.
216      * It is permitted to pass 0 for the 'to' ID, indicating that any
217      * segment originating at 'from' is acceptable.
218      */
219     FGTaxiSegment* findSegment(PositionedID from, PositionedID to) const;
220   
221     FGTaxiRoute findShortestRoute(PositionedID start, PositionedID end, bool fullSearch=true);
222
223     virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
224                                   double lat, double lon, double hdg, double spd, double alt,
225                                   double radius, int leg, FGAIAircraft *aircraft);
226     virtual void signOff(int id);
227     virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
228     virtual bool hasInstruction(int id);
229     virtual FGATCInstruction getInstruction(int id);
230
231     bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
232                                 AtcMsgDir msgDir);
233     bool checkForCircularWaits(int id);
234     virtual void render(bool);
235     virtual std::string getName();
236     virtual void update(double dt);
237
238     void saveElevationCache();
239     void addVersion(int v) {version = v; };
240 };
241
242
243 #endif