]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
assign a unique module name to ai/mp embedded nasal (again): __model%u
[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 using std::string;
33
34 class PerformanceData;
35
36 class FGAIAircraft : public FGAIBase {
37
38 public:
39     FGAIAircraft(FGAISchedule *ref=0);
40     ~FGAIAircraft();
41
42     virtual void readFromScenario(SGPropertyNode* scFileNode);
43
44     // virtual bool init(bool search_in_AI_path=false);
45     virtual void bind();
46     virtual void unbind();
47     virtual void update(double dt);
48
49     void setPerformance(const std::string& perfString);
50     void setPerformance(PerformanceData *ps);
51
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 );
57     
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);
64     
65     void getGroundElev(double dt); //TODO these 3 really need to be public?
66     void doGroundAltitude();
67     bool loadNextLeg  ();
68
69     void setAcType(const string& ac) { acType = ac; };
70     void setCompany(const string& comp) { company = comp;};
71
72     void announcePositionToController(); //TODO have to be public?
73     void processATC(FGATCInstruction instruction);
74     FGAISchedule * getTrafficRef() { return trafficRef; };
75
76     virtual const char* getTypeString(void) const { return "aircraft"; }
77
78     string GetTransponderCode() { return transponderCode; };
79     void SetTransponderCode(string tc) { transponderCode = tc;};
80
81     // included as performance data needs them, who else?
82     inline PerformanceData* getPerformance() { return _performance; };
83     inline bool onGround() const { return no_roll; };
84     inline double getSpeed() const { return speed; };
85     inline double getRoll() const { return roll; };
86     inline double getPitch() const { return pitch; };
87     inline double getAltitude() const { return altitude_ft; };
88     inline double getVerticalSpeed() const { return vs; };
89     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
90     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
91     string atGate();
92     
93 protected:
94     void Run(double dt);
95
96 private:
97     FGAISchedule *trafficRef;
98     FGATCController *controller, *prevController; 
99
100     bool hdg_lock;
101     bool alt_lock;
102     double dt_count;
103     double dt_elev_count;
104     double headingChangeRate;
105     double headingError;
106     double groundTargetSpeed;
107     double groundOffset;
108     double dt;
109
110     bool use_perf_vs;
111     SGPropertyNode_ptr refuel_node;
112
113     // helpers for Run
114     //TODO sort out which ones are better protected virtuals to allow
115     //subclasses to override specific behaviour
116     bool fpExecutable(time_t now);
117     void handleFirstWaypoint(void);
118     bool leadPointReached(FGAIFlightPlan::waypoint* curr);
119     bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
120     bool aiTrafficVisible(void);
121     void controlHeading(FGAIFlightPlan::waypoint* curr);
122     void controlSpeed(FGAIFlightPlan::waypoint* curr,
123                       FGAIFlightPlan::waypoint* next);
124     void updatePrimaryTargetValues();
125     void updateSecondaryTargetValues();
126     void updatePosition();
127     void updateHeading();
128     void updateBankAngleTarget();
129     void updateVerticalSpeedTarget();
130     void updatePitchAngleTarget();
131     void updateActualState();
132     void handleATCRequests();
133     void checkVisibility();
134
135     double sign(double x);
136
137     string acType;
138     string company;
139     string transponderCode;
140
141     int spinCounter;
142     double prevSpeed;
143     double prev_dist_to_go;
144
145     bool holdPos;
146
147     bool _getGearDown() const;
148
149     const char * _getTransponderCode() const;
150
151     bool reachedWaypoint;
152     time_t timeElapsed;
153
154     PerformanceData* _performance; // the performance data for this aircraft
155 };
156
157
158 #endif  // _FG_AIAircraft_HXX