2 // FGAIAircraft - AIBase derived class creates an AI aircraft
4 // Written by David Culp, started October 2003.
6 // Copyright (C) 2003 David P. Culp - davidculp2@comcast.net
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef _FG_AIAircraft_HXX
23 #define _FG_AIAircraft_HXX
25 #include "AIManager.hxx"
28 #include <Traffic/SchedFlight.hxx>
29 #include <Traffic/Schedule.hxx>
30 #include <ATC/trafficcontrol.hxx>
34 class PerformanceData;
36 class FGAIAircraft : public FGAIBase {
39 FGAIAircraft(FGAISchedule *ref=0);
42 virtual void readFromScenario(SGPropertyNode* scFileNode);
44 // virtual bool init(bool search_in_AI_path=false);
46 virtual void unbind();
47 virtual void update(double dt);
49 void setPerformance(const std::string& perfString);
50 void setPerformance(PerformanceData *ps);
52 void setFlightPlan(const std::string& fp, bool repat = false);
53 void SetFlightPlan(FGAIFlightPlan *f);
54 void initializeFlightPlan();
55 FGAIFlightPlan* GetFlightPlan() const { return fp; };
56 void ProcessFlightPlan( double dt, time_t now );
57 time_t checkForArrivalTime(string wptName);
59 void AccelTo(double speed);
60 void PitchTo(double angle);
61 void RollTo(double angle);
62 void YawTo(double angle);
63 void ClimbTo(double altitude);
64 void TurnTo(double heading);
66 void getGroundElev(double dt); //TODO these 3 really need to be public?
67 void doGroundAltitude();
68 bool loadNextLeg (double dist=0);
69 void resetPositionFromFlightPlan();
70 double getBearing(double crse);
72 void setAcType(const std::string& ac) { acType = ac; };
73 void setCompany(const std::string& comp) { company = comp;};
75 void announcePositionToController(); //TODO have to be public?
76 void processATC(FGATCInstruction instruction);
77 void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
78 bool getTaxiClearanceRequest() { return needsTaxiClearance; };
79 FGAISchedule * getTrafficRef() { return trafficRef; };
80 void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; };
82 virtual const char* getTypeString(void) const { return "aircraft"; }
84 std::string GetTransponderCode() { return transponderCode; };
85 void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
87 // included as performance data needs them, who else?
88 inline PerformanceData* getPerformance() { return _performance; };
89 inline bool onGround() const { return no_roll; };
90 inline double getSpeed() const { return speed; };
91 inline double getRoll() const { return roll; };
92 inline double getPitch() const { return pitch; };
93 inline double getAltitude() const { return altitude_ft; };
94 inline double getVerticalSpeed() const { return vs; };
95 inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
96 inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
105 FGAISchedule *trafficRef;
106 FGATCController *controller, *prevController;
111 double dt_elev_count;
112 double headingChangeRate;
115 double speedFraction;
116 double groundTargetSpeed;
121 SGPropertyNode_ptr refuel_node;
124 //TODO sort out which ones are better protected virtuals to allow
125 //subclasses to override specific behaviour
126 bool fpExecutable(time_t now);
127 void handleFirstWaypoint(void);
128 bool leadPointReached(FGAIFlightPlan::waypoint* curr);
129 bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
130 bool reachedEndOfCruise(double&);
131 bool aiTrafficVisible(void);
132 void controlHeading(FGAIFlightPlan::waypoint* curr);
133 void controlSpeed(FGAIFlightPlan::waypoint* curr,
134 FGAIFlightPlan::waypoint* next);
136 void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
138 void updateSecondaryTargetValues();
139 void updatePosition();
140 void updateHeading();
141 void updateBankAngleTarget();
142 void updateVerticalSpeedTarget();
143 void updatePitchAngleTarget();
144 void updateActualState();
145 void handleATCRequests();
146 void checkVisibility();
147 inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
148 inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
150 double sign(double x);
154 std::string transponderCode;
158 double prev_dist_to_go;
162 bool _getGearDown() const;
164 const char * _getTransponderCode() const;
166 bool reachedWaypoint;
167 bool needsTaxiClearance;
168 bool _needsGroundElevation;
171 PerformanceData* _performance; // the performance data for this aircraft
175 #endif // _FG_AIAircraft_HXX