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>
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 );
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();
69 void setAcType(const string& ac) { acType = ac; };
70 void setCompany(const string& comp) { company = comp;};
72 void announcePositionToController(); //TODO have to be public?
73 void processATC(FGATCInstruction instruction);
74 FGAISchedule * getTrafficRef() { return trafficRef; };
76 virtual const char* getTypeString(void) const { return "aircraft"; }
78 // included as performance data needs them, who else?
79 inline PerformanceData* getPerformance() { return _performance; };
80 inline bool onGround() const { return no_roll; };
81 inline double getSpeed() const { return speed; };
82 inline double getRoll() const { return roll; };
83 inline double getPitch() const { return pitch; };
84 inline double getAltitude() const { return altitude_ft; };
85 inline double getVerticalSpeed() const { return vs; };
86 inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
87 inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
94 FGAISchedule *trafficRef;
95 FGATCController *controller, *prevController;
100 double dt_elev_count;
101 double headingChangeRate;
103 double groundTargetSpeed;
108 SGPropertyNode_ptr refuel_node;
111 //TODO sort out which ones are better protected virtuals to allow
112 //subclasses to override specific behaviour
113 bool fpExecutable(time_t now);
114 void handleFirstWaypoint(void);
115 bool leadPointReached(FGAIFlightPlan::waypoint* curr);
116 bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
117 bool aiTrafficVisible(void);
118 void controlHeading(FGAIFlightPlan::waypoint* curr);
119 void controlSpeed(FGAIFlightPlan::waypoint* curr,
120 FGAIFlightPlan::waypoint* next);
121 void updatePrimaryTargetValues();
122 void updateSecondaryTargetValues();
123 void updatePosition();
124 void updateHeading();
125 void updateBankAngleTarget();
126 void updateVerticalSpeedTarget();
127 void updatePitchAngleTarget();
128 void updateActualState();
129 void handleATCRequests();
130 void checkVisibility();
132 double sign(double x);
139 double prev_dist_to_go;
143 bool _getGearDown() const;
145 bool reachedWaypoint;
148 PerformanceData* _performance; // the performance data for this aircraft
152 #endif // _FG_AIAircraft_HXX