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
28 class PerformanceData;
31 class FGATCController;
32 class FGATCInstruction;
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 update(double dt);
46 virtual void unbind();
48 void setPerformance(const std::string& acType, 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(const std::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 const std::string& getAcType() const { return acType; }
74 void setCompany(const std::string& comp) { company = comp;};
76 void announcePositionToController(); //TODO have to be public?
77 void processATC(const FGATCInstruction& instruction);
78 void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
79 bool getTaxiClearanceRequest() { return needsTaxiClearance; };
80 FGAISchedule * getTrafficRef() { return trafficRef; };
81 void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; };
82 void resetTakeOffStatus() { takeOffStatus = 0;};
83 void setTakeOffStatus(int status) { takeOffStatus = status; };
84 void scheduleForATCTowerDepartureControl(int state);
86 //inline bool isScheduledForTakeoff() { return scheduledForTakeoff; };
88 virtual const char* getTypeString(void) const { return "aircraft"; }
90 const std::string& GetTransponderCode() { return transponderCode; };
91 void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
93 // included as performance data needs them, who else?
94 inline PerformanceData* getPerformance() { return _performance; };
95 inline bool onGround() const { return no_roll; };
96 inline double getSpeed() const { return speed; };
97 inline double getRoll() const { return roll; };
98 inline double getPitch() const { return pitch; };
99 inline double getAltitude() const { return altitude_ft; };
100 inline double getVerticalSpeed() const { return vs; };
101 inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
102 inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
103 const std::string& atGate();
105 int getTakeOffStatus() { return takeOffStatus; };
108 double calcVerticalSpeed(double vert_ft, double dist_m, double speed, double error);
110 FGATCController * getATCController() { return controller; };
112 void clearATCController();
117 FGAISchedule *trafficRef;
118 FGATCController *controller,
120 *towerController; // Only needed to make a pre-announcement
125 double dt_elev_count;
126 double headingChangeRate;
129 double speedFraction;
130 double groundTargetSpeed;
134 SGPropertyNode_ptr refuel_node;
137 //TODO sort out which ones are better protected virtuals to allow
138 //subclasses to override specific behaviour
139 bool fpExecutable(time_t now);
140 void handleFirstWaypoint(void);
141 bool leadPointReached(FGAIWaypoint* curr);
142 bool handleAirportEndPoints(FGAIWaypoint* prev, time_t now);
143 bool reachedEndOfCruise(double&);
144 bool aiTrafficVisible(void);
145 void controlHeading(FGAIWaypoint* curr);
146 void controlSpeed(FGAIWaypoint* curr,
149 void updatePrimaryTargetValues(double dt, bool& flightplanActive, bool& aiOutOfSight);
151 void updateSecondaryTargetValues(double dt);
152 void updateHeading(double dt);
153 void updateBankAngleTarget();
154 void updateVerticalSpeedTarget(double dt);
155 void updatePitchAngleTarget();
156 void updateActualState(double dt);
157 void updateModelProperties(double dt);
158 void handleATCRequests(double dt);
159 inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
160 inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
163 double sign(double x);
167 std::string transponderCode;
171 double prev_dist_to_go;
175 const char * _getTransponderCode() const;
177 bool needsTaxiClearance;
178 bool _needsGroundElevation;
179 int takeOffStatus; // 1 = joined departure cue; 2 = Passed DepartureHold waypoint; handover control to tower; 0 = any other state.
182 PerformanceData* _performance; // the performance data for this aircraft
184 void assertSpeed(double speed);
188 double remainingLength;
189 std::string startWptName;
190 std::string finalWptName;
195 #endif // _FG_AIAircraft_HXX