1 // trafficcontrol.hxx - classes to manage AIModels based air traffic control
2 // Written by Durk Talsma, started September 2006.
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.
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.
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.
21 #ifndef _TRAFFIC_CONTROL_HXX_
22 #define _TRAFFIC_CONTROL_HXX_
26 # error This library requires C++
30 #include <simgear/compiler.h>
31 #include <simgear/debug/logstream.hxx>
41 typedef vector<int> intVec;
42 typedef vector<int>::iterator intVecIterator;
45 class FGAIFlightPlan; // forward reference
46 class FGGroundNetwork; // forward reference
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
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; };
75 double getSpeed () { return speed; };
76 double getHeading () { return heading; };
77 double getAlt () { return alt; };
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; };
85 void setSpeed (double val) { speed = val; };
86 void setHeading (double val) { heading = val; };
87 void setAlt (double val) { alt = val; };
91 /**************************************************************************************
92 * class FGATCController
93 * NOTE: this class serves as an abstraction layer for all sorts of ATC controller.
94 *************************************************************************************/
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) = 0;
105 virtual void signOff(int id) = 0;
106 virtual void update(int id, double lat, double lon,
107 double heading, double speed, double alt, double dt) = 0;
108 virtual bool hasInstruction(int id) = 0;
109 virtual FGATCInstruction getInstruction(int id) = 0;
111 double getDt() { return dt_count; };
112 void setDt(double dt) { dt_count = dt;};
116 /**************************************************************************************
117 * class FGTrafficRecord
118 *************************************************************************************/
119 class FGTrafficRecord
126 FGATCInstruction instruction;
127 double latitude, longitude, heading, speed, altitude, radius;
132 FGTrafficRecord() {};
134 void setId(int val) { id = val; };
135 void setRadius(double rad) { radius = rad;};
136 void setPositionAndIntentions(int pos, FGAIFlightPlan *route);
137 void setRunway(string rwy) { runway = rwy;};
138 void setLeg(int lg) { leg = lg;};
139 int getId() { return id;};
140 FGATCInstruction getInstruction() { return instruction;};
141 bool hasInstruction() { return instruction.hasInstruction(); };
142 void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
143 bool checkPositionAndIntentions(FGTrafficRecord &other);
144 int crosses (FGGroundNetwork *, FGTrafficRecord &other);
145 bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
147 bool getSpeedAdjustment() { return instruction.getChangeSpeed(); };
149 double getLatitude () { return latitude ; };
150 double getLongitude() { return longitude; };
151 double getHeading () { return heading ; };
152 double getSpeed () { return speed ; };
153 double getAltitude () { return altitude ; };
154 double getRadius () { return radius ; };
156 int getWaitsForId () { return waitsForId; };
158 void setSpeedAdjustment(double spd);
159 void setHeadingAdjustment(double heading);
160 void clearSpeedAdjustment () { instruction.setChangeSpeed (false); };
161 void clearHeadingAdjustment() { instruction.setChangeHeading(false); };
163 bool hasHeadingAdjustment() { return instruction.getChangeHeading(); };
164 bool hasHoldPosition() { return instruction.getHoldPosition(); };
165 void setHoldPosition (bool inst) { instruction.setHoldPosition(inst); };
167 void setWaitsForId(int id) { waitsForId = id; };
169 string getRunway() { return runway; };
173 typedef vector<FGTrafficRecord> TrafficVector;
174 typedef vector<FGTrafficRecord>::iterator TrafficVectorIterator;
176 /***********************************************************************
177 * Active runway, a utility class to keep track of which aircraft has
178 * clearance for a given runway.
179 **********************************************************************/
184 int currentlyCleared;
186 ActiveRunway(string r, int cc) { rwy = r; currentlyCleared = cc; };
188 string getRunwayName() { return rwy; };
189 int getCleared () { return currentlyCleared; };
192 typedef vector<ActiveRunway> ActiveRunwayVec;
193 typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
195 /******************************************************************************
196 * class FGTowerControl
197 *****************************************************************************/
198 class FGTowerController : public FGATCController
201 TrafficVector activeTraffic;
202 ActiveRunwayVec activeRunways;
206 virtual ~FGTowerController() {};
207 virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
208 double lat, double lon,
209 double hdg, double spd, double alt, double radius, int leg);
210 virtual void signOff(int id);
211 virtual void update(int id, double lat, double lon,
212 double heading, double speed, double alt, double dt);
213 virtual bool hasInstruction(int id);
214 virtual FGATCInstruction getInstruction(int id);
216 bool hasActiveTraffic() { return activeTraffic.size() != 0; };
217 TrafficVector &getActiveTraffic() { return activeTraffic; };
222 #endif // _TRAFFIC_CONTROL_HXX