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>
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 );
57 void AccelTo(double speed);
58 void PitchTo(double angle);
59 void RollTo(double angle);
60 void YawTo(double angle);
61 void ClimbTo(double altitude);
62 void TurnTo(double heading);
64 void getGroundElev(double dt); //TODO these 3 really need to be public?
65 void doGroundAltitude();
68 void setAcType(const string& ac) { acType = ac; };
69 void setCompany(const string& comp) { company = comp;};
71 void announcePositionToController(); //TODO have to be public?
72 void processATC(FGATCInstruction instruction);
74 virtual const char* getTypeString(void) const { return "aircraft"; }
76 // included as performance data needs them, who else?
77 inline bool onGround() const { return no_roll; };
78 inline double getSpeed() const { return speed; };
79 inline double getRoll() const { return roll; };
80 inline double getPitch() const { return pitch; };
81 inline double getAltitude() const { return altitude_ft; };
82 inline double getVerticalSpeed() const { return vs; };
83 inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
84 inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
90 FGAISchedule *trafficRef;
91 FGATCController *controller, *prevController;
97 double headingChangeRate;
98 double groundTargetSpeed;
103 SGPropertyNode_ptr refuel_node;
106 //TODO sort out which ones are better protected virtuals to allow
107 //subclasses to override specific behaviour
108 bool fpExecutable(time_t now);
109 void handleFirstWaypoint(void);
110 bool leadPointReached(FGAIFlightPlan::waypoint* curr);
111 bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
112 bool aiTrafficVisible(void);
113 void controlHeading(FGAIFlightPlan::waypoint* curr);
114 void controlSpeed(FGAIFlightPlan::waypoint* curr,
115 FGAIFlightPlan::waypoint* next);
116 void updatePrimaryTargetValues();
117 void updateSecondaryTargetValues();
118 void updatePosition();
119 void updateHeading();
120 void updateBankAngleTarget();
121 void updateVerticalSpeedTarget();
122 void updatePitchAngleTarget();
123 void updateActualState();
124 void handleATCRequests();
126 double sign(double x);
133 double prev_dist_to_go;
137 bool _getGearDown() const;
139 bool reachedWaypoint;
141 PerformanceData* _performance; // the performance data for this aircraft
145 #endif // _FG_AIAircraft_HXX