2002-04-03 23:54:44 +00:00
// FGAILocalTraffic - AIEntity derived class with enough logic to
// fly and interact with the traffic pattern.
//
// Written by David Luff, started March 2002.
//
// Copyright (C) 2002 David C. Luff - david.luff@nottingham.ac.uk
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# ifndef _FG_AILocalTraffic_HXX
# define _FG_AILocalTraffic_HXX
# include <simgear/math/point3d.hxx>
2002-12-04 20:02:03 +00:00
# include <Main/fg_props.hxx>
2002-04-03 23:54:44 +00:00
# include "tower.hxx"
2002-10-02 15:27:49 +00:00
# include "AIPlane.hxx"
# include "ATCProjection.hxx"
2002-12-04 20:02:03 +00:00
# include "ground.hxx"
2002-04-03 23:54:44 +00:00
2003-03-05 21:38:29 +00:00
# include <string>
SG_USING_STD ( string ) ;
2003-03-19 17:46:52 +00:00
enum TaxiState {
2002-12-04 20:02:03 +00:00
TD_INBOUND ,
TD_OUTBOUND ,
2003-03-27 15:44:10 +00:00
TD_NONE ,
TD_LINING_UP
2002-12-04 20:02:03 +00:00
} ;
2003-03-19 17:46:52 +00:00
enum OperatingState {
2002-12-04 20:02:03 +00:00
IN_PATTERN ,
TAXIING ,
2004-01-23 17:18:24 +00:00
PARKED ,
EN_ROUTE
2002-04-03 23:54:44 +00:00
} ;
2003-09-05 10:26:11 +00:00
struct StartOfDescent {
2002-12-04 20:02:03 +00:00
PatternLeg leg ;
2003-09-05 10:26:11 +00:00
double x ; // Runway aligned orthopos
double y ; // ditto
2002-10-02 15:27:49 +00:00
} ;
class FGAILocalTraffic : public FGAIPlane {
2002-12-04 20:02:03 +00:00
2002-04-03 23:54:44 +00:00
public :
2002-12-04 20:02:03 +00:00
2004-01-23 17:18:24 +00:00
// At the moment we expect the expanded short form callsign - eventually we will just want the reg + type.
2002-12-04 20:02:03 +00:00
FGAILocalTraffic ( ) ;
~ FGAILocalTraffic ( ) ;
// Initialise
2004-01-23 17:18:24 +00:00
bool Init ( const string & callsign , string ICAO , OperatingState initialState = PARKED , PatternLeg initialLeg = DOWNWIND ) ;
2002-12-04 20:02:03 +00:00
// Run the internal calculations
void Update ( double dt ) ;
// Go out and practice circuits
void FlyCircuits ( int numCircuits , bool tag ) ;
2003-09-22 23:54:41 +00:00
// Return what type of landing we're doing on this circuit
LandingType GetLandingOption ( ) ;
2003-03-27 15:44:10 +00:00
// TODO - this will get more complex and moved into the main class
// body eventually since the position approved to taxi to will have
// to be passed.
inline void ApproveTaxiRequest ( ) { taxiRequestCleared = true ; }
inline void DenyTaxiRequest ( ) { taxiRequestCleared = false ; }
2003-10-15 14:09:26 +00:00
void RegisterTransmission ( int code ) ;
// Process callbacks sent by base class
// (These codes are not related to the codes above)
void ProcessCallback ( int code ) ;
2003-03-27 15:44:10 +00:00
// This is a hack and will probably go eventually
2003-04-15 22:54:11 +00:00
inline bool AtHoldShort ( ) { return holdingShort ; }
2003-03-27 15:44:10 +00:00
2002-10-02 15:27:49 +00:00
protected :
2002-12-04 20:02:03 +00:00
// Attempt to enter the traffic pattern in a reasonably intelligent manner
void EnterTrafficPattern ( double dt ) ;
2004-01-23 17:18:24 +00:00
// Set up the internal state to be consistent for a downwind entry.
void DownwindEntry ( ) ;
2002-12-04 20:02:03 +00:00
2004-01-23 17:18:24 +00:00
// Ditto for straight-in
void StraightInEntry ( bool des = false ) ;
2002-12-04 20:02:03 +00:00
2004-01-23 17:18:24 +00:00
// Do what is necessary to land and parkup at home airport
void ReturnToBase ( double dt ) ;
2002-12-04 20:02:03 +00:00
// Airport/runway/pattern details
2003-03-05 21:38:29 +00:00
string airportID ; // The ICAO code of the airport that we're operating around
double aptElev ; // Airport elevation
2003-03-07 13:58:33 +00:00
FGGround * ground ; // A pointer to the ground control.
2002-12-04 20:02:03 +00:00
FGTower * tower ; // A pointer to the tower control.
2004-01-23 17:18:24 +00:00
bool _controlled ; // Set true if we find tower control working for the airport, false otherwise.
2002-12-04 20:02:03 +00:00
RunwayDetails rwy ;
double patternDirection ; // 1 for right, -1 for left (This is double because we multiply/divide turn rates
// with it to get RH/LH turns - DON'T convert it to int under ANY circumstances!!
double glideAngle ; // Assumed to be visual glidepath angle for FGAILocalTraffic - can be found at www.airnav.com
// Its conceivable that patternDirection and glidePath could be moved into the RunwayDetails structure.
2004-01-23 17:18:24 +00:00
// Its possible that this might be moved out to the ground/airport class at some point.
FGATCAlignedProjection ortho ; // Orthogonal mapping of the local area with the threshold at the origin
// and the runway aligned with the y axis.
void GetAirportDetails ( string id ) ;
void GetRwyDetails ( string id ) ;
double responseCounter ; // timer in seconds to allow response to requests to be a little while after them
// Will almost certainly get moved to FGAIPlane.
private :
FGATCMgr * ATC ;
// This is purely for synactic convienience to avoid writing globals->get_ATC_mgr()-> all through the code!
// High-level stuff
OperatingState operatingState ;
int circuitsToFly ; //Number of circuits still to do in this session NOT INCLUDING THE CURRENT ONE
bool touchAndGo ; //True if circuits should be flown touch and go, false for full stop
bool transmitted ; // Set true when a position report for the current leg has been transmitted.
2002-12-04 20:02:03 +00:00
// Performance characteristics of the plane in knots and ft/min - some of this might get moved out into FGAIPlane
double Vr ;
double best_rate_of_climb_speed ;
double best_rate_of_climb ;
double nominal_climb_speed ;
double nominal_climb_rate ;
double nominal_circuit_speed ;
double min_circuit_speed ;
double max_circuit_speed ;
double nominal_descent_rate ;
double nominal_approach_speed ;
double nominal_final_speed ;
double stall_speed_landing_config ;
double nominal_taxi_speed ;
2003-02-26 11:24:15 +00:00
// Physical/rendering stuff
double wheelOffset ; // Height above ground at which we need to render the plane whilst taxiing
2003-03-05 21:38:29 +00:00
bool elevInitGood ; // We have had at least one good elev reading
bool inAir ; // True when off the ground
2003-02-26 11:24:15 +00:00
2002-12-04 20:02:03 +00:00
// environment - some of this might get moved into FGAIPlane
SGPropertyNode * wind_from_hdg ; //degrees
SGPropertyNode * wind_speed_knots ; //knots
// Pattern details that (may) change
int numInPattern ; // Number of planes in the pattern (this might get more complicated if high performance GA aircraft fly a higher pattern eventually)
int numAhead ; // More importantly - how many of them are ahead of us?
double distToNext ; // And even more importantly, how near are we getting to the one immediately ahead?
2003-04-15 22:54:11 +00:00
//PatternLeg leg; // Our current position in the pattern - now moved to FGAIPlane
2003-09-05 10:26:11 +00:00
StartOfDescent SoD ; // Start of descent calculated wrt wind, pattern size & altitude, glideslope etc
bool descending ; // We're in the coming down phase of the pattern
double targetDescentRate ; // m/s
2002-12-04 20:02:03 +00:00
// Taxiing details
// At the moment this assumes that all taxiing in is to gates (a loose term that includes
// any permitted parking spot) and that all taxiing out is to runways.
bool parked ;
bool taxiing ;
2003-03-27 15:44:10 +00:00
bool taxiRequestPending ;
bool taxiRequestCleared ;
2002-12-04 20:02:03 +00:00
TaxiState taxiState ;
double desiredTaxiHeading ;
double taxiTurnRadius ;
double nominalTaxiSpeed ;
2003-03-05 21:38:29 +00:00
Gate * ourGate ;
2002-12-04 20:02:03 +00:00
ground_network_path_type path ; // a path through the ground network for the plane to taxi
2003-03-05 21:38:29 +00:00
unsigned int taxiPathPos ; // position of iterator in taxi path when applicable
2002-12-04 20:02:03 +00:00
node * nextTaxiNode ; // next node in taxi path
2003-03-27 15:44:10 +00:00
node * holdShortNode ;
2002-12-04 20:02:03 +00:00
//Runway out_dest; //FIXME - implement this
2003-03-27 15:44:10 +00:00
bool holdingShort ;
bool reportReadyForDeparture ; // set true when ATC has requested that the plane report when ready for departure
bool clearedToLineUp ;
bool clearedToTakeOff ;
2004-01-23 17:18:24 +00:00
bool _clearedToLand ; // also implies cleared for the option.
2003-03-05 21:38:29 +00:00
bool liningUp ; // Set true when the turn onto the runway heading is commenced when taxiing out
2003-10-19 20:38:08 +00:00
bool goAround ; // Set true if need to go-around
bool goAroundCalled ; // Set true during go-around only after we have called our go-around on the radio
2003-03-27 15:44:10 +00:00
bool contactTower ; // we have been told to contact tower
bool contactGround ; // we have been told to contact ground
bool changeFreq ; // true when we need to change frequency
2004-01-23 17:18:24 +00:00
bool _taxiToGA ; // Temporary mega-hack indicating we are to taxi to the GA parking and disconnect from tower control.
2004-03-20 03:13:29 +00:00
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.
2003-03-27 15:44:10 +00:00
atc_type changeFreqType ; // the service we need to change to
2004-01-23 17:18:24 +00:00
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.
// Hack for getting close to the runway when atan can go pear-shaped
double _savedSlope ;
2002-12-04 20:02:03 +00:00
void FlyTrafficPattern ( double dt ) ;
// TODO - need to add something to define what option we are flying - Touch and go / Stop and go / Landing properly / others?
void TransmitPatternPositionReport ( ) ;
2003-09-05 10:26:11 +00:00
void CalculateSoD ( double base_leg_pos , double downwind_leg_pos , bool pattern_direction ) ;
2002-12-04 20:02:03 +00:00
void ExitRunway ( Point3D orthopos ) ;
void StartTaxi ( ) ;
void Taxi ( double dt ) ;
void GetNextTaxiNode ( ) ;
2003-02-26 11:24:15 +00:00
void DoGroundElev ( ) ;
2004-03-12 15:58:00 +00:00
// Set when the plane should be invisible *regardless of distance from user*.
bool _invisible ;
2002-04-03 23:54:44 +00:00
} ;
2002-04-04 01:32:00 +00:00
# endif // _FG_AILocalTraffic_HXX