]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
Make sure that takeoff distance calculations are done in the correct frame of referen...
[flightgear.git] / src / AIModel / AIAircraft.hxx
1 // FGAIAircraft - AIBase derived class creates an AI aircraft
2 //
3 // Written by David Culp, started October 2003.
4 //
5 // Copyright (C) 2003  David P. Culp - davidculp2@comcast.net
6 //
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.
11 //
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.
16 //
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.
20
21 #ifndef _FG_AIAircraft_HXX
22 #define _FG_AIAircraft_HXX
23
24 #include "AIManager.hxx"
25 #include "AIBase.hxx"
26
27 #include <Traffic/SchedFlight.hxx>
28 #include <Traffic/Schedule.hxx>
29 #include <ATC/trafficcontrol.hxx>
30
31 #include <string>
32
33 class PerformanceData;
34
35 class FGAIAircraft : public FGAIBase {
36
37 public:
38     FGAIAircraft(FGAISchedule *ref=0);
39     ~FGAIAircraft();
40
41     virtual void readFromScenario(SGPropertyNode* scFileNode);
42
43     // virtual bool init(bool search_in_AI_path=false);
44     virtual void bind();
45     virtual void unbind();
46     virtual void update(double dt);
47
48     void setPerformance(const std::string& perfString);
49     void setPerformance(PerformanceData *ps);
50
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     
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);
63     
64     void getGroundElev(double dt); //TODO these 3 really need to be public?
65     void doGroundAltitude();
66     bool loadNextLeg  ();
67
68     void setAcType(const std::string& ac) { acType = ac; };
69     void setCompany(const std::string& comp) { company = comp;};
70
71     void announcePositionToController(); //TODO have to be public?
72     void processATC(FGATCInstruction instruction);
73     void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
74     bool getTaxiClearanceRequest() { return needsTaxiClearance; };
75     FGAISchedule * getTrafficRef() { return trafficRef; };
76
77     virtual const char* getTypeString(void) const { return "aircraft"; }
78
79     std::string GetTransponderCode() { return transponderCode; };
80     void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
81
82     // included as performance data needs them, who else?
83     inline PerformanceData* getPerformance() { return _performance; };
84     inline bool onGround() const { return no_roll; };
85     inline double getSpeed() const { return speed; };
86     inline double getRoll() const { return roll; };
87     inline double getPitch() const { return pitch; };
88     inline double getAltitude() const { return altitude_ft; };
89     inline double getVerticalSpeed() const { return vs; };
90     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
91     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
92     std::string atGate();
93     
94 protected:
95     void Run(double dt);
96
97 private:
98     FGAISchedule *trafficRef;
99     FGATCController *controller, *prevController; 
100
101     bool hdg_lock;
102     bool alt_lock;
103     double dt_count;
104     double dt_elev_count;
105     double headingChangeRate;
106     double headingError;
107     double groundTargetSpeed;
108     double groundOffset;
109     double dt;
110
111     bool use_perf_vs;
112     SGPropertyNode_ptr refuel_node;
113
114     // helpers for Run
115     //TODO sort out which ones are better protected virtuals to allow
116     //subclasses to override specific behaviour
117     bool fpExecutable(time_t now);
118     void handleFirstWaypoint(void);
119     bool leadPointReached(FGAIFlightPlan::waypoint* curr);
120     bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
121     bool aiTrafficVisible(void);
122     void controlHeading(FGAIFlightPlan::waypoint* curr);
123     void controlSpeed(FGAIFlightPlan::waypoint* curr,
124                       FGAIFlightPlan::waypoint* next);
125     
126     void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
127     
128     void updateSecondaryTargetValues();
129     void updatePosition();
130     void updateHeading();
131     void updateBankAngleTarget();
132     void updateVerticalSpeedTarget();
133     void updatePitchAngleTarget();
134     void updateActualState();
135     void handleATCRequests();
136     void checkVisibility();
137
138     double sign(double x);
139
140     std::string acType;
141     std::string company;
142     std::string transponderCode;
143
144     int spinCounter;
145     double prevSpeed;
146     double prev_dist_to_go;
147
148     bool holdPos;
149
150     bool _getGearDown() const;
151
152     const char * _getTransponderCode() const;
153
154     bool reachedWaypoint;
155     bool needsTaxiClearance;
156     time_t timeElapsed;
157
158     PerformanceData* _performance; // the performance data for this aircraft
159 };
160
161
162 #endif  // _FG_AIAircraft_HXX