1 // FGAILocalTraffic - AIEntity derived class with enough logic to
2 // fly and interact with the traffic pattern.
4 // Written by David Luff, started March 2002.
6 // Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _FG_AILocalTraffic_HXX
23 #define _FG_AILocalTraffic_HXX
27 #include <simgear/math/point3d.hxx>
28 #include <Main/fg_props.hxx>
31 #include "AIPlane.hxx"
32 #include "ATCProjection.hxx"
51 struct StartOfDescent {
53 double x; // Runway aligned orthopos
57 class FGAILocalTraffic : public FGAIPlane {
65 bool Init(string ICAO, OperatingState initialState = PARKED, PatternLeg initialLeg = DOWNWIND);
67 // Run the internal calculations
68 void Update(double dt);
70 // Go out and practice circuits
71 void FlyCircuits(int numCircuits, bool tag);
73 // Return what type of landing we're doing on this circuit
74 LandingType GetLandingOption();
76 // TODO - this will get more complex and moved into the main class
77 // body eventually since the position approved to taxi to will have
79 inline void ApproveTaxiRequest() {taxiRequestCleared = true;}
81 inline void DenyTaxiRequest() {taxiRequestCleared = false;}
83 void RegisterTransmission(int code);
85 // This is a hack and will probably go eventually
86 inline bool AtHoldShort() {return holdingShort;}
90 // Attempt to enter the traffic pattern in a reasonably intelligent manner
91 void EnterTrafficPattern(double dt);
93 // Do what is necessary to land and parkup at home airport
94 void ReturnToBase(double dt);
98 // This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
101 OperatingState operatingState;
102 int circuitsToFly; //Number of circuits still to do in this session NOT INCLUDING THE CURRENT ONE
103 bool touchAndGo; //True if circuits should be flown touch and go, false for full stop
105 // Its possible that this might be moved out to the ground/airport class at some point.
106 FGATCAlignedProjection ortho; // Orthogonal mapping of the local area with the threshold at the origin
107 // and the runway aligned with the y axis.
109 // Airport/runway/pattern details
110 string airportID; // The ICAO code of the airport that we're operating around
111 double aptElev; // Airport elevation
112 FGGround* ground; // A pointer to the ground control.
113 FGTower* tower; // A pointer to the tower control.
115 double patternDirection; // 1 for right, -1 for left (This is double because we multiply/divide turn rates
116 // with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
117 double glideAngle; // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
118 // Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
120 // Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
122 double best_rate_of_climb_speed;
123 double best_rate_of_climb;
124 double nominal_climb_speed;
125 double nominal_climb_rate;
126 double nominal_circuit_speed;
127 double min_circuit_speed;
128 double max_circuit_speed;
129 double nominal_descent_rate;
130 double nominal_approach_speed;
131 double nominal_final_speed;
132 double stall_speed_landing_config;
133 double nominal_taxi_speed;
135 // Physical/rendering stuff
136 double wheelOffset; // Height above ground at which we need to render the plane whilst taxiing
137 bool elevInitGood; // We have had at least one good elev reading
138 bool inAir; // True when off the ground
140 // environment - some of this might get moved into FGAIPlane
141 SGPropertyNode* wind_from_hdg; //degrees
142 SGPropertyNode* wind_speed_knots; //knots
144 // Pattern details that (may) change
145 int numInPattern; // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
146 int numAhead; // More importantly - how many of them are ahead of us?
147 double distToNext; // And even more importantly, how near are we getting to the one immediately ahead?
148 //PatternLeg leg; // Our current position in the pattern - now moved to FGAIPlane
149 StartOfDescent SoD; // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
150 bool descending; // We're in the coming down phase of the pattern
151 double targetDescentRate; // m/s
154 // At the moment this assumes that all taxiing in is to gates (a loose term that includes
155 // any permitted parking spot) and that all taxiing out is to runways.
158 bool taxiRequestPending;
159 bool taxiRequestCleared;
161 double desiredTaxiHeading;
162 double taxiTurnRadius;
163 double nominalTaxiSpeed;
165 ground_network_path_type path; // a path through the ground network for the plane to taxi
166 unsigned int taxiPathPos; // position of iterator in taxi path when applicable
167 node* nextTaxiNode; // next node in taxi path
169 //Runway out_dest; //FIXME - implement this
171 bool reportReadyForDeparture; // set true when ATC has requested that the plane report when ready for departure
172 bool clearedToLineUp;
173 bool clearedToTakeOff;
174 bool liningUp; // Set true when the turn onto the runway heading is commenced when taxiing out
175 bool contactTower; // we have been told to contact tower
176 bool contactGround; // we have been told to contact ground
177 bool changeFreq; // true when we need to change frequency
178 atc_type changeFreqType; // the service we need to change to
179 double responseCounter; // timer in seconds to allow response to requests to be a little while after them
181 void FlyTrafficPattern(double dt);
183 // TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
185 void TransmitPatternPositionReport();
187 void CalculateSoD(double base_leg_pos, double downwind_leg_pos, bool pattern_direction);
189 void ExitRunway(Point3D orthopos);
193 void Taxi(double dt);
195 void GetNextTaxiNode();
199 void GetRwyDetails();
202 #endif // _FG_AILocalTraffic_HXX