]> git.mxchange.org Git - flightgear.git/blob - src/Airports/trafficcontrol.hxx
Change tower location to an SGGeod. Include taxiways too.
[flightgear.git] / src / Airports / trafficcontrol.hxx
1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //
18 // $Id$
19
20
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
23
24
25 #ifndef __cplusplus
26 # error This library requires C++
27 #endif
28
29
30 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
32
33
34 #include STL_STRING
35 #include <vector>
36
37 SG_USING_STD(string);
38 SG_USING_STD(vector);
39
40
41 typedef vector<int> intVec;
42 typedef vector<int>::iterator intVecIterator;
43
44
45 class FGAIFlightPlan;  // forward reference
46 class FGGroundNetwork; // forward reference
47
48 /**************************************************************************************
49  * class FGATCInstruction
50  * like class FGATC Controller, this class definition should go into its own file
51  * and or directory... For now, just testing this stuff out though...
52  *************************************************************************************/
53 class FGATCInstruction
54 {
55 private:
56   bool holdPattern;
57   bool holdPosition;
58   bool changeSpeed;
59   bool changeHeading;
60   bool changeAltitude;
61   bool resolveCircularWait;
62
63   double speed;
64   double heading;
65   double alt;
66 public:
67
68   FGATCInstruction();
69   bool hasInstruction   ();
70   bool getHoldPattern   () { return holdPattern;    };
71   bool getHoldPosition  () { return holdPosition;   };
72   bool getChangeSpeed   () { return changeSpeed;    };
73   bool getChangeHeading () { return changeHeading;  };
74   bool getChangeAltitude() { return changeAltitude; };
75
76   double getSpeed       () { return speed; };
77   double getHeading     () { return heading; };
78   double getAlt         () { return alt; };
79
80   bool getCheckForCircularWait() { return resolveCircularWait; };
81
82   void setHoldPattern   (bool val) { holdPattern    = val; };
83   void setHoldPosition  (bool val) { holdPosition   = val; };
84   void setChangeSpeed   (bool val) { changeSpeed    = val; };
85   void setChangeHeading (bool val) { changeHeading  = val; };
86   void setChangeAltitude(bool val) { changeAltitude = val; };
87
88   void setResolveCircularWait (bool val) { resolveCircularWait = val; }; 
89
90   void setSpeed       (double val) { speed   = val; };
91   void setHeading     (double val) { heading = val; };
92   void setAlt         (double val) { alt     = val; };
93 };
94
95
96 /**
97  * class FGATCController
98  * NOTE: this class serves as an abstraction layer for all sorts of ATC controller. 
99  *************************************************************************************/
100 class FGATCController
101 {
102 private:
103   double dt_count;
104 public:
105   FGATCController() { dt_count = 0;};
106   virtual ~FGATCController() {};
107   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
108                                 double lat, double lon,
109                                 double hdg, double spd, double alt, double radius, int leg,
110                                 string callsign) = 0;
111   virtual void             signOff(int id) = 0;
112   virtual void             update(int id, double lat, double lon, 
113                                   double heading, double speed, double alt, double dt) = 0;
114   virtual bool             hasInstruction(int id) = 0;
115   virtual FGATCInstruction getInstruction(int id) = 0;
116
117   double getDt() { return dt_count; };
118   void   setDt(double dt) { dt_count = dt;};
119 };
120
121
122 /**************************************************************************************
123  * class FGTrafficRecord
124  *************************************************************************************/
125 class FGTrafficRecord
126 {
127 private:
128   int id, waitsForId;
129   int currentPos;
130   int leg;
131   intVec intentions;
132   FGATCInstruction instruction;
133   double latitude, longitude, heading, speed, altitude, radius;
134   string runway;
135   string callsign;
136   
137   
138 public:
139   FGTrafficRecord();
140   
141   void setId(int val)  { id = val; };
142   void setRadius(double rad) { radius = rad;};
143   void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
144   void setRunway(string rwy) { runway = rwy;};
145   void setLeg(int lg) { leg = lg;};
146   int getId() { return id;};
147   FGATCInstruction getInstruction() { return instruction;};
148   bool hasInstruction() { return instruction.hasInstruction(); };
149   void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
150   bool checkPositionAndIntentions(FGTrafficRecord &other);
151   int  crosses                   (FGGroundNetwork *, FGTrafficRecord &other); 
152   bool isOpposing                (FGGroundNetwork *, FGTrafficRecord &other, int node);
153
154   bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
155
156   bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
157   
158   double getLatitude () { return latitude ; };
159   double getLongitude() { return longitude; };
160   double getHeading  () { return heading  ; };
161   double getSpeed    () { return speed    ; };
162   double getAltitude () { return altitude ; };
163   double getRadius   () { return radius   ; };
164
165   int getWaitsForId  () { return waitsForId; };
166
167   void setSpeedAdjustment(double spd);
168   void setHeadingAdjustment(double heading);
169   void clearSpeedAdjustment  () { instruction.setChangeSpeed  (false); };
170   void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
171
172   bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
173   bool hasHoldPosition() { return instruction.getHoldPosition(); };
174   void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
175
176   void setWaitsForId(int id) { waitsForId = id; };
177
178   void setResolveCircularWait()   { instruction.setResolveCircularWait(true);  };
179   void clearResolveCircularWait() { instruction.setResolveCircularWait(false); };
180
181   string getRunway() { return runway; };
182   void setCallSign(string clsgn) { callsign = clsgn; };
183   string getCallSign() { return callsign; };
184 };
185
186 typedef vector<FGTrafficRecord> TrafficVector;
187 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
188
189 /***********************************************************************
190  * Active runway, a utility class to keep track of which aircraft has
191  * clearance for a given runway.
192  **********************************************************************/
193 class ActiveRunway
194 {
195 private:
196   string rwy;
197   int currentlyCleared;
198 public:
199   ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
200   
201   string getRunwayName() { return rwy; };
202   int    getCleared   () { return currentlyCleared; };
203 };
204
205 typedef vector<ActiveRunway> ActiveRunwayVec;
206 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
207
208 /******************************************************************************
209  * class FGTowerControl
210  *****************************************************************************/
211 class FGTowerController : public FGATCController
212 {
213 private:
214   TrafficVector activeTraffic;
215   ActiveRunwayVec activeRunways;
216   
217 public:
218   FGTowerController();
219   virtual ~FGTowerController() {};
220   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
221                                 double lat, double lon,
222                                 double hdg, double spd, double alt, double radius, int leg,
223                                 string callsign);
224   virtual void             signOff(int id);
225   virtual void             update(int id, double lat, double lon, 
226                                   double heading, double speed, double alt, double dt);
227   virtual bool             hasInstruction(int id);
228   virtual FGATCInstruction getInstruction(int id);
229
230   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
231   TrafficVector &getActiveTraffic() { return activeTraffic; };
232 };
233
234
235
236 #endif // _TRAFFIC_CONTROL_HXX