1 // FGAILocalTraffic - AIEntity derived class with enough logic to
\r
2 // fly and interact with the traffic pattern.
\r
4 // Written by David Luff, started March 2002.
\r
6 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
\r
8 // This program is free software; you can redistribute it and/or
\r
9 // modify it under the terms of the GNU General Public License as
\r
10 // published by the Free Software Foundation; either version 2 of the
\r
11 // License, or (at your option) any later version.
\r
13 // This program is distributed in the hope that it will be useful, but
\r
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 // General Public License for more details.
\r
18 // You should have received a copy of the GNU General Public License
\r
19 // along with this program; if not, write to the Free Software
\r
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
22 #ifndef _FG_AILocalTraffic_HXX
\r
23 #define _FG_AILocalTraffic_HXX
\r
25 #include <simgear/math/point3d.hxx>
\r
26 #include <Main/fg_props.hxx>
\r
28 #include "AIPlane.hxx"
\r
29 #include "ATCProjection.hxx"
\r
30 #include "ground.hxx"
\r
37 SG_USING_STD(string);
\r
46 enum OperatingState {
\r
53 struct StartOfDescent {
\r
55 double x; // Runway aligned orthopos
\r
59 class FGAILocalTraffic : public FGAIPlane {
\r
63 // At the moment we expect the expanded short form callsign - eventually we will just want the reg + type.
\r
65 ~FGAILocalTraffic();
\r
68 bool Init(const string& callsign, const string& ICAO, OperatingState initialState = PARKED, PatternLeg initialLeg = DOWNWIND);
\r
70 // Run the internal calculations
\r
71 void Update(double dt);
\r
73 // Go out and practice circuits
\r
74 void FlyCircuits(int numCircuits, bool tag);
\r
76 // Return what type of landing we're doing on this circuit
\r
77 LandingType GetLandingOption();
\r
79 // TODO - this will get more complex and moved into the main class
\r
80 // body eventually since the position approved to taxi to will have
\r
82 inline void ApproveTaxiRequest() {taxiRequestCleared = true;}
\r
84 inline void DenyTaxiRequest() {taxiRequestCleared = false;}
\r
86 void RegisterTransmission(int code);
\r
88 // Process callbacks sent by base class
\r
89 // (These codes are not related to the codes above)
\r
90 void ProcessCallback(int code);
\r
92 // This is a hack and will probably go eventually
\r
93 inline bool AtHoldShort() {return holdingShort;}
\r
97 // Attempt to enter the traffic pattern in a reasonably intelligent manner
\r
98 void EnterTrafficPattern(double dt);
\r
100 // Set up the internal state to be consistent for a downwind entry.
\r
101 void DownwindEntry();
\r
103 // Ditto for straight-in
\r
104 void StraightInEntry(bool des = false);
\r
106 // Do what is necessary to land and parkup at home airport
\r
107 void ReturnToBase(double dt);
\r
109 // Airport/runway/pattern details
\r
110 string airportID; // The ICAO code of the airport that we're operating around
\r
111 double aptElev; // Airport elevation
\r
112 FGGround* ground; // A pointer to the ground control.
\r
113 FGTower* tower; // A pointer to the tower control.
\r
114 bool _controlled; // Set true if we find tower control working for the airport, false otherwise.
\r
116 double patternDirection; // 1 for right, -1 for left (This is double because we multiply/divide turn rates
\r
117 // with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
\r
118 double glideAngle; // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
\r
119 // Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
\r
121 // Its possible that this might be moved out to the ground/airport class at some point.
\r
122 FGATCAlignedProjection ortho; // Orthogonal mapping of the local area with the threshold at the origin
\r
123 // and the runway aligned with the y axis.
\r
125 void GetAirportDetails(const string& id);
\r
127 void GetRwyDetails(const string& id);
\r
129 double responseCounter; // timer in seconds to allow response to requests to be a little while after them
\r
130 // Will almost certainly get moved to FGAIPlane.
\r
134 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
\r
136 // High-level stuff
\r
137 OperatingState operatingState;
\r
138 int circuitsToFly; //Number of circuits still to do in this session NOT INCLUDING THE CURRENT ONE
\r
139 bool touchAndGo; //True if circuits should be flown touch and go, false for full stop
\r
140 bool transmitted; // Set true when a position report for the current leg has been transmitted.
\r
142 // Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
\r
144 double best_rate_of_climb_speed;
\r
145 double best_rate_of_climb;
\r
146 double nominal_climb_speed;
\r
147 double nominal_climb_rate;
\r
148 double nominal_circuit_speed;
\r
149 double min_circuit_speed;
\r
150 double max_circuit_speed;
\r
151 double nominal_descent_rate;
\r
152 double nominal_approach_speed;
\r
153 double nominal_final_speed;
\r
154 double stall_speed_landing_config;
\r
155 double nominal_taxi_speed;
\r
157 // Physical/rendering stuff
\r
158 double wheelOffset; // Height above ground at which we need to render the plane whilst taxiing
\r
159 bool elevInitGood; // We have had at least one good elev reading
\r
160 bool inAir; // True when off the ground
\r
162 // environment - some of this might get moved into FGAIPlane
\r
163 SGPropertyNode* wind_from_hdg; //degrees
\r
164 SGPropertyNode* wind_speed_knots; //knots
\r
166 // Pattern details that (may) change
\r
167 int numInPattern; // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
\r
168 int numAhead; // More importantly - how many of them are ahead of us?
\r
169 double distToNext; // And even more importantly, how near are we getting to the one immediately ahead?
\r
170 //PatternLeg leg; // Our current position in the pattern - now moved to FGAIPlane
\r
171 StartOfDescent SoD; // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
\r
172 bool descending; // We're in the coming down phase of the pattern
\r
173 double targetDescentRate; // m/s
\r
176 // At the moment this assumes that all taxiing in is to gates (a loose term that includes
\r
177 // any permitted parking spot) and that all taxiing out is to runways.
\r
180 bool taxiRequestPending;
\r
181 bool taxiRequestCleared;
\r
182 TaxiState taxiState;
\r
183 double desiredTaxiHeading;
\r
184 double taxiTurnRadius;
\r
185 double nominalTaxiSpeed;
\r
187 ground_network_path_type path; // a path through the ground network for the plane to taxi
\r
188 unsigned int taxiPathPos; // position of iterator in taxi path when applicable
\r
189 node* nextTaxiNode; // next node in taxi path
\r
190 node* holdShortNode;
\r
191 //Runway out_dest; //FIXME - implement this
\r
193 bool reportReadyForDeparture; // set true when ATC has requested that the plane report when ready for departure
\r
194 bool clearedToLineUp;
\r
195 bool clearedToTakeOff;
\r
196 bool _clearedToLand; // also implies cleared for the option.
\r
197 bool liningUp; // Set true when the turn onto the runway heading is commenced when taxiing out
\r
198 bool goAround; // Set true if need to go-around
\r
199 bool goAroundCalled; // Set true during go-around only after we have called our go-around on the radio
\r
200 bool contactTower; // we have been told to contact tower
\r
201 bool contactGround; // we have been told to contact ground
\r
202 bool changeFreq; // true when we need to change frequency
\r
203 bool _taxiToGA; // Temporary mega-hack indicating we are to taxi to the GA parking and disconnect from tower control.
\r
204 bool _removeSelf; // Indicates that we wish to remove this instance. The use of a variable is a hack to allow time for messages to purge before removal, due to the fagility of the current dialog system.
\r
205 atc_type changeFreqType; // the service we need to change to
\r
206 bool freeTaxi; // False if the airport has a facilities file with a logical taxi network defined, true if we need to calculate our own taxiing points.
\r
208 // Hack for getting close to the runway when atan can go pear-shaped
\r
209 double _savedSlope;
\r
211 void FlyTrafficPattern(double dt);
\r
213 // TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
\r
215 void TransmitPatternPositionReport();
\r
217 void CalculateSoD(double base_leg_pos, double downwind_leg_pos, bool pattern_direction);
\r
219 void ExitRunway(const Point3D& orthopos);
\r
223 void Taxi(double dt);
\r
225 void GetNextTaxiNode();
\r
227 void DoGroundElev();
\r
229 // Set when the plane should be invisible *regardless of distance from user*.
\r
233 #endif // _FG_AILocalTraffic_HXX
\r