]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
Add a small bit of nan/fpe protection. It's possible that this routine
[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     time_t checkForArrivalTime(string wptName);
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  (double dist=0);
68     void resetPositionFromFlightPlan();
69     double getBearing(double crse);
70
71     void setAcType(const std::string& ac) { acType = ac; };
72     void setCompany(const std::string& comp) { company = comp;};
73
74     void announcePositionToController(); //TODO have to be public?
75     void processATC(FGATCInstruction instruction);
76     void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
77     bool getTaxiClearanceRequest() { return needsTaxiClearance; };
78     FGAISchedule * getTrafficRef() { return trafficRef; };
79
80     virtual const char* getTypeString(void) const { return "aircraft"; }
81
82     std::string GetTransponderCode() { return transponderCode; };
83     void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
84
85     // included as performance data needs them, who else?
86     inline PerformanceData* getPerformance() { return _performance; };
87     inline bool onGround() const { return no_roll; };
88     inline double getSpeed() const { return speed; };
89     inline double getRoll() const { return roll; };
90     inline double getPitch() const { return pitch; };
91     inline double getAltitude() const { return altitude_ft; };
92     inline double getVerticalSpeed() const { return vs; };
93     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
94     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
95     std::string atGate();
96
97     
98 protected:
99     void Run(double dt);
100
101 private:
102     FGAISchedule *trafficRef;
103     FGATCController *controller, *prevController; 
104
105     bool hdg_lock;
106     bool alt_lock;
107     double dt_count;
108     double dt_elev_count;
109     double headingChangeRate;
110     double headingError;
111     double minBearing;
112     double speedFraction;
113     double groundTargetSpeed;
114     double groundOffset;
115     double dt;
116
117     bool use_perf_vs;
118     SGPropertyNode_ptr refuel_node;
119
120     // helpers for Run
121     //TODO sort out which ones are better protected virtuals to allow
122     //subclasses to override specific behaviour
123     bool fpExecutable(time_t now);
124     void handleFirstWaypoint(void);
125     bool leadPointReached(FGAIFlightPlan::waypoint* curr);
126     bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
127     bool reachedEndOfCruise(double&);
128     bool aiTrafficVisible(void);
129     void controlHeading(FGAIFlightPlan::waypoint* curr);
130     void controlSpeed(FGAIFlightPlan::waypoint* curr,
131                       FGAIFlightPlan::waypoint* next);
132     
133     void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
134     
135     void updateSecondaryTargetValues();
136     void updatePosition();
137     void updateHeading();
138     void updateBankAngleTarget();
139     void updateVerticalSpeedTarget();
140     void updatePitchAngleTarget();
141     void updateActualState();
142     void handleATCRequests();
143     void checkVisibility();
144
145     double sign(double x);
146
147     std::string acType;
148     std::string company;
149     std::string transponderCode;
150
151     int spinCounter;
152     double prevSpeed;
153     double prev_dist_to_go;
154
155     bool holdPos;
156
157     bool _getGearDown() const;
158
159     const char * _getTransponderCode() const;
160
161     bool reachedWaypoint;
162     bool needsTaxiClearance;
163     time_t timeElapsed;
164
165     PerformanceData* _performance; // the performance data for this aircraft
166 };
167
168
169 #endif  // _FG_AIAircraft_HXX