2003-11-28 15:48:05 +00:00
|
|
|
// FGAIAircraft - AIBase derived class creates an AI aircraft
|
|
|
|
//
|
|
|
|
// Written by David Culp, started October 2003.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 David P. Culp - davidculp2@comcast.net
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-11-28 15:48:05 +00:00
|
|
|
|
|
|
|
#ifndef _FG_AIAircraft_HXX
|
|
|
|
#define _FG_AIAircraft_HXX
|
|
|
|
|
|
|
|
#include "AIManager.hxx"
|
|
|
|
#include "AIBase.hxx"
|
|
|
|
|
2004-11-29 09:41:43 +00:00
|
|
|
#include <Traffic/SchedFlight.hxx>
|
|
|
|
#include <Traffic/Schedule.hxx>
|
2008-08-14 18:13:39 +00:00
|
|
|
#include <ATC/trafficcontrol.hxx>
|
2004-11-29 09:41:43 +00:00
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
#include <string>
|
2008-07-27 16:25:13 +00:00
|
|
|
using std::string;
|
2003-11-28 15:48:05 +00:00
|
|
|
|
2007-06-28 07:47:20 +00:00
|
|
|
class PerformanceData;
|
2003-11-28 15:48:05 +00:00
|
|
|
|
|
|
|
class FGAIAircraft : public FGAIBase {
|
2003-12-21 13:42:01 +00:00
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
public:
|
2006-05-13 10:02:17 +00:00
|
|
|
FGAIAircraft(FGAISchedule *ref=0);
|
|
|
|
~FGAIAircraft();
|
|
|
|
|
|
|
|
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
|
|
|
|
2007-06-09 11:49:16 +00:00
|
|
|
// virtual bool init(bool search_in_AI_path=false);
|
2006-05-13 10:02:17 +00:00
|
|
|
virtual void bind();
|
|
|
|
virtual void unbind();
|
|
|
|
virtual void update(double dt);
|
|
|
|
|
|
|
|
void setPerformance(const std::string& perfString);
|
2007-06-28 07:47:20 +00:00
|
|
|
void setPerformance(PerformanceData *ps);
|
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
void setFlightPlan(const std::string& fp, bool repat = false);
|
|
|
|
void SetFlightPlan(FGAIFlightPlan *f);
|
2006-08-26 07:22:20 +00:00
|
|
|
void initializeFlightPlan();
|
2006-05-13 10:02:17 +00:00
|
|
|
FGAIFlightPlan* GetFlightPlan() const { return fp; };
|
2007-06-28 07:47:20 +00:00
|
|
|
void ProcessFlightPlan( double dt, time_t now );
|
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
void AccelTo(double speed);
|
|
|
|
void PitchTo(double angle);
|
|
|
|
void RollTo(double angle);
|
|
|
|
void YawTo(double angle);
|
|
|
|
void ClimbTo(double altitude);
|
|
|
|
void TurnTo(double heading);
|
2007-06-28 07:47:20 +00:00
|
|
|
|
|
|
|
void getGroundElev(double dt); //TODO these 3 really need to be public?
|
2006-05-13 10:02:17 +00:00
|
|
|
void doGroundAltitude();
|
2008-11-16 13:41:24 +00:00
|
|
|
bool loadNextLeg ();
|
2006-05-13 10:02:17 +00:00
|
|
|
|
|
|
|
void setAcType(const string& ac) { acType = ac; };
|
|
|
|
void setCompany(const string& comp) { company = comp;};
|
|
|
|
|
2007-06-28 07:47:20 +00:00
|
|
|
void announcePositionToController(); //TODO have to be public?
|
2006-08-26 07:22:20 +00:00
|
|
|
void processATC(FGATCInstruction instruction);
|
2008-07-13 12:51:06 +00:00
|
|
|
FGAISchedule * getTrafficRef() { return trafficRef; };
|
2006-08-26 07:22:20 +00:00
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
virtual const char* getTypeString(void) const { return "aircraft"; }
|
2006-02-11 13:16:56 +00:00
|
|
|
|
2009-03-22 13:49:51 +00:00
|
|
|
string GetTransponderCode() { return transponderCode; };
|
|
|
|
void SetTransponderCode(string tc) { transponderCode = tc;};
|
|
|
|
|
2007-06-28 07:47:20 +00:00
|
|
|
// included as performance data needs them, who else?
|
2009-01-30 18:48:44 +00:00
|
|
|
inline PerformanceData* getPerformance() { return _performance; };
|
2007-06-28 07:47:20 +00:00
|
|
|
inline bool onGround() const { return no_roll; };
|
|
|
|
inline double getSpeed() const { return speed; };
|
|
|
|
inline double getRoll() const { return roll; };
|
|
|
|
inline double getPitch() const { return pitch; };
|
|
|
|
inline double getAltitude() const { return altitude_ft; };
|
|
|
|
inline double getVerticalSpeed() const { return vs; };
|
|
|
|
inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
|
|
|
|
inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
|
2008-07-13 12:51:06 +00:00
|
|
|
string atGate();
|
2007-06-28 07:47:20 +00:00
|
|
|
|
2007-06-09 11:49:16 +00:00
|
|
|
protected:
|
|
|
|
void Run(double dt);
|
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
private:
|
2006-05-13 10:02:17 +00:00
|
|
|
FGAISchedule *trafficRef;
|
2006-08-26 07:22:20 +00:00
|
|
|
FGATCController *controller, *prevController;
|
2006-05-13 10:02:17 +00:00
|
|
|
|
|
|
|
bool hdg_lock;
|
|
|
|
bool alt_lock;
|
|
|
|
double dt_count;
|
|
|
|
double dt_elev_count;
|
|
|
|
double headingChangeRate;
|
2008-04-02 19:01:48 +00:00
|
|
|
double headingError;
|
2006-05-13 10:02:17 +00:00
|
|
|
double groundTargetSpeed;
|
|
|
|
double groundOffset;
|
|
|
|
double dt;
|
|
|
|
|
|
|
|
bool use_perf_vs;
|
2006-05-26 05:23:40 +00:00
|
|
|
SGPropertyNode_ptr refuel_node;
|
2006-05-13 10:02:17 +00:00
|
|
|
|
2007-06-09 11:49:16 +00:00
|
|
|
// helpers for Run
|
2007-06-28 07:47:20 +00:00
|
|
|
//TODO sort out which ones are better protected virtuals to allow
|
|
|
|
//subclasses to override specific behaviour
|
2007-06-09 11:49:16 +00:00
|
|
|
bool fpExecutable(time_t now);
|
|
|
|
void handleFirstWaypoint(void);
|
|
|
|
bool leadPointReached(FGAIFlightPlan::waypoint* curr);
|
|
|
|
bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
|
|
|
|
bool aiTrafficVisible(void);
|
|
|
|
void controlHeading(FGAIFlightPlan::waypoint* curr);
|
|
|
|
void controlSpeed(FGAIFlightPlan::waypoint* curr,
|
2007-06-28 07:47:20 +00:00
|
|
|
FGAIFlightPlan::waypoint* next);
|
2008-10-19 16:22:17 +00:00
|
|
|
void updatePrimaryTargetValues();
|
2007-06-28 07:47:20 +00:00
|
|
|
void updateSecondaryTargetValues();
|
2007-06-09 11:49:16 +00:00
|
|
|
void updatePosition();
|
|
|
|
void updateHeading();
|
2007-06-28 07:47:20 +00:00
|
|
|
void updateBankAngleTarget();
|
|
|
|
void updateVerticalSpeedTarget();
|
|
|
|
void updatePitchAngleTarget();
|
|
|
|
void updateActualState();
|
|
|
|
void handleATCRequests();
|
2008-12-10 16:04:10 +00:00
|
|
|
void checkVisibility();
|
2007-06-28 07:47:20 +00:00
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
double sign(double x);
|
|
|
|
|
|
|
|
string acType;
|
|
|
|
string company;
|
2009-03-22 13:49:51 +00:00
|
|
|
string transponderCode;
|
2006-05-13 10:02:17 +00:00
|
|
|
|
|
|
|
int spinCounter;
|
|
|
|
double prevSpeed;
|
|
|
|
double prev_dist_to_go;
|
|
|
|
|
2007-06-09 11:49:16 +00:00
|
|
|
bool holdPos;
|
2006-09-19 17:04:22 +00:00
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
bool _getGearDown() const;
|
2007-07-15 14:08:31 +00:00
|
|
|
|
2009-03-22 13:49:51 +00:00
|
|
|
const char * _getTransponderCode() const;
|
|
|
|
|
2006-05-13 10:02:17 +00:00
|
|
|
bool reachedWaypoint;
|
2008-07-13 12:51:06 +00:00
|
|
|
time_t timeElapsed;
|
2007-06-28 07:47:20 +00:00
|
|
|
|
|
|
|
PerformanceData* _performance; // the performance data for this aircraft
|
2003-11-28 15:48:05 +00:00
|
|
|
};
|
|
|
|
|
2004-01-22 21:13:47 +00:00
|
|
|
|
2003-11-28 15:48:05 +00:00
|
|
|
#endif // _FG_AIAircraft_HXX
|