]> git.mxchange.org Git - flightgear.git/blob - src/Airports/trafficcontrol.hxx
Fix for refueling and radar calculations.
[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
62   double speed;
63   double heading;
64   double alt;
65 public:
66
67   FGATCInstruction();
68   bool hasInstruction   ();
69   bool getHoldPattern   () { return holdPattern;    };
70   bool getHoldPosition  () { return holdPosition;   };
71   bool getChangeSpeed   () { return changeSpeed;    };
72   bool getChangeHeading () { return changeHeading;  };
73   bool getChangeAltitude() { return changeAltitude; };
74
75   double getSpeed       () { return speed; };
76   double getHeading     () { return heading; };
77   double getAlt         () { return alt; };
78
79   void setHoldPattern   (bool val) { holdPattern    = val; };
80   void setHoldPosition  (bool val) { holdPosition   = val; };
81   void setChangeSpeed   (bool val) { changeSpeed    = val; };
82   void setChangeHeading (bool val) { changeHeading  = val; };
83   void setChangeAltitude(bool val) { changeAltitude = val; };
84
85   void setSpeed       (double val) { speed   = val; };
86   void setHeading     (double val) { heading = val; };
87   void setAlt         (double val) { alt     = val; };
88 };
89
90
91 /**************************************************************************************
92  * class FGATCController
93  * NOTE: this class serves as an abstraction layer for all sorts of ATC controller. 
94  *************************************************************************************/
95 class FGATCController
96 {
97 private:
98   double dt_count;
99 public:
100   FGATCController() { dt_count = 0;};
101   virtual ~FGATCController() {};
102   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
103                                 double lat, double lon,
104                                 double hdg, double spd, double alt, double radius, int leg,
105                                 string callsign) = 0;
106   virtual void             signOff(int id) = 0;
107   virtual void             update(int id, double lat, double lon, 
108                                   double heading, double speed, double alt, double dt) = 0;
109   virtual bool             hasInstruction(int id) = 0;
110   virtual FGATCInstruction getInstruction(int id) = 0;
111
112   double getDt() { return dt_count; };
113   void   setDt(double dt) { dt_count = dt;};
114 };
115
116
117 /**************************************************************************************
118  * class FGTrafficRecord
119  *************************************************************************************/
120 class FGTrafficRecord
121 {
122 private:
123   int id, waitsForId;
124   int currentPos;
125   int leg;
126   intVec intentions;
127   FGATCInstruction instruction;
128   double latitude, longitude, heading, speed, altitude, radius;
129   string runway;
130   string callsign;
131   
132   
133 public:
134   FGTrafficRecord() {};
135   
136   void setId(int val)  { id = val; };
137   void setRadius(double rad) { radius = rad;};
138   void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
139   void setRunway(string rwy) { runway = rwy;};
140   void setLeg(int lg) { leg = lg;};
141   int getId() { return id;};
142   FGATCInstruction getInstruction() { return instruction;};
143   bool hasInstruction() { return instruction.hasInstruction(); };
144   void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
145   bool checkPositionAndIntentions(FGTrafficRecord &other);
146   int  crosses                   (FGGroundNetwork *, FGTrafficRecord &other); 
147   bool isOpposing                (FGGroundNetwork *, FGTrafficRecord &other, int node);
148
149   bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
150
151   bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
152   
153   double getLatitude () { return latitude ; };
154   double getLongitude() { return longitude; };
155   double getHeading  () { return heading  ; };
156   double getSpeed    () { return speed    ; };
157   double getAltitude () { return altitude ; };
158   double getRadius   () { return radius   ; };
159
160   int getWaitsForId  () { return waitsForId; };
161
162   void setSpeedAdjustment(double spd);
163   void setHeadingAdjustment(double heading);
164   void clearSpeedAdjustment  () { instruction.setChangeSpeed  (false); };
165   void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
166
167   bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
168   bool hasHoldPosition() { return instruction.getHoldPosition(); };
169   void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
170
171   void setWaitsForId(int id) { waitsForId = id; };
172
173   string getRunway() { return runway; };
174   void setCallSign(string clsgn) { callsign = clsgn; };
175   string getCallSign() { return callsign; };
176 };
177
178 typedef vector<FGTrafficRecord> TrafficVector;
179 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
180
181 /***********************************************************************
182  * Active runway, a utility class to keep track of which aircraft has
183  * clearance for a given runway.
184  **********************************************************************/
185 class ActiveRunway
186 {
187 private:
188   string rwy;
189   int currentlyCleared;
190 public:
191   ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
192   
193   string getRunwayName() { return rwy; };
194   int    getCleared   () { return currentlyCleared; };
195 };
196
197 typedef vector<ActiveRunway> ActiveRunwayVec;
198 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
199
200 /******************************************************************************
201  * class FGTowerControl
202  *****************************************************************************/
203 class FGTowerController : public FGATCController
204 {
205 private:
206   TrafficVector activeTraffic;
207   ActiveRunwayVec activeRunways;
208   
209 public:
210   FGTowerController();
211   virtual ~FGTowerController() {};
212   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
213                                 double lat, double lon,
214                                 double hdg, double spd, double alt, double radius, int leg,
215                                 string callsign);
216   virtual void             signOff(int id);
217   virtual void             update(int id, double lat, double lon, 
218                                   double heading, double speed, double alt, double dt);
219   virtual bool             hasInstruction(int id);
220   virtual FGATCInstruction getInstruction(int id);
221
222   bool hasActiveTraffic() { return activeTraffic.size() != 0; };
223   TrafficVector &getActiveTraffic() { return activeTraffic; };
224 };
225
226
227
228 #endif // _TRAFFIC_CONTROL_HXX