1 // FGAIAircraft - AIBase derived class creates an AI aircraft
3 // Written by David Culp, started October 2003.
5 // Copyright (C) 2003 David P. Culp - davidculp2@comcast.net
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef _FG_AIAircraft_HXX
22 #define _FG_AIAircraft_HXX
24 #include "AIManager.hxx"
27 #include <Traffic/SchedFlight.hxx>
28 #include <Traffic/Schedule.hxx>
29 #include <ATC/trafficcontrol.hxx>
33 class PerformanceData;
35 class FGAIAircraft : public FGAIBase {
38 FGAIAircraft(FGAISchedule *ref=0);
41 virtual void readFromScenario(SGPropertyNode* scFileNode);
43 // virtual bool init(bool search_in_AI_path=false);
45 virtual void unbind();
46 virtual void update(double dt);
48 void setPerformance(const std::string& perfString);
49 void setPerformance(PerformanceData *ps);
51 void setFlightPlan(const std::string& fp, bool repat = false);
52 void SetFlightPlan(FGAIFlightPlan *f);
53 void initializeFlightPlan();
54 FGAIFlightPlan* GetFlightPlan() const { return fp; };
55 void ProcessFlightPlan( double dt, time_t now );
56 time_t checkForArrivalTime(string wptName);
58 void AccelTo(double speed);
59 void PitchTo(double angle);
60 void RollTo(double angle);
61 void YawTo(double angle);
62 void ClimbTo(double altitude);
63 void TurnTo(double heading);
65 void getGroundElev(double dt); //TODO these 3 really need to be public?
66 void doGroundAltitude();
67 bool loadNextLeg (double dist=0);
68 void resetPositionFromFlightPlan();
69 double getBearing(double crse);
71 void setAcType(const std::string& ac) { acType = ac; };
72 void setCompany(const std::string& comp) { company = comp;};
74 void announcePositionToController(); //TODO have to be public?
75 void processATC(FGATCInstruction instruction);
76 void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
77 bool getTaxiClearanceRequest() { return needsTaxiClearance; };
78 FGAISchedule * getTrafficRef() { return trafficRef; };
79 void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; };
80 void scheduleForATCTowerDepartureControl();
82 inline bool isScheduledForTakeoff() { return scheduledForTakeoff; };
84 virtual const char* getTypeString(void) const { return "aircraft"; }
86 std::string GetTransponderCode() { return transponderCode; };
87 void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
89 // included as performance data needs them, who else?
90 inline PerformanceData* getPerformance() { return _performance; };
91 inline bool onGround() const { return no_roll; };
92 inline double getSpeed() const { return speed; };
93 inline double getRoll() const { return roll; };
94 inline double getPitch() const { return pitch; };
95 inline double getAltitude() const { return altitude_ft; };
96 inline double getVerticalSpeed() const { return vs; };
97 inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
98 inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
103 FGATCController * getATCController() { return controller; };
109 FGAISchedule *trafficRef;
110 FGATCController *controller,
112 *towerController; // Only needed to make a pre-announcement
117 double dt_elev_count;
118 double headingChangeRate;
121 double speedFraction;
122 double groundTargetSpeed;
127 SGPropertyNode_ptr refuel_node;
130 //TODO sort out which ones are better protected virtuals to allow
131 //subclasses to override specific behaviour
132 bool fpExecutable(time_t now);
133 void handleFirstWaypoint(void);
134 bool leadPointReached(FGAIWaypoint* curr);
135 bool handleAirportEndPoints(FGAIWaypoint* prev, time_t now);
136 bool reachedEndOfCruise(double&);
137 bool aiTrafficVisible(void);
138 void controlHeading(FGAIWaypoint* curr);
139 void controlSpeed(FGAIWaypoint* curr,
142 void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
144 void updateSecondaryTargetValues();
145 void updatePosition();
146 void updateHeading();
147 void updateBankAngleTarget();
148 void updateVerticalSpeedTarget();
149 void updatePitchAngleTarget();
150 void updateActualState();
151 void handleATCRequests();
152 void checkVisibility();
153 inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
154 inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
157 double sign(double x);
161 std::string transponderCode;
165 double prev_dist_to_go;
169 bool _getGearDown() const;
171 const char * _getTransponderCode() const;
173 bool reachedWaypoint;
174 bool needsTaxiClearance;
175 bool _needsGroundElevation;
176 bool scheduledForTakeoff;
179 PerformanceData* _performance; // the performance data for this aircraft
183 #endif // _FG_AIAircraft_HXX