]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
fix #416: reciprocal filter broken
[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     void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; };
80     void resetTakeOffStatus() { takeOffStatus = 0;};
81     void setTakeOffStatus(int status) { takeOffStatus = status; };
82     void scheduleForATCTowerDepartureControl(int state);
83
84     //inline bool isScheduledForTakeoff() { return scheduledForTakeoff; };
85
86     virtual const char* getTypeString(void) const { return "aircraft"; }
87
88     std::string GetTransponderCode() { return transponderCode; };
89     void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
90
91     // included as performance data needs them, who else?
92     inline PerformanceData* getPerformance() { return _performance; };
93     inline bool onGround() const { return no_roll; };
94     inline double getSpeed() const { return speed; };
95     inline double getRoll() const { return roll; };
96     inline double getPitch() const { return pitch; };
97     inline double getAltitude() const { return altitude_ft; };
98     inline double getVerticalSpeed() const { return vs; };
99     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
100     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
101     std::string atGate();
102
103     int getTakeOffStatus() { return takeOffStatus; };
104
105     void checkTcas();
106
107     FGATCController * getATCController() { return controller; };
108     
109 protected:
110     void Run(double dt);
111
112 private:
113     FGAISchedule *trafficRef;
114     FGATCController *controller, 
115                     *prevController,
116                     *towerController; // Only needed to make a pre-announcement
117
118     bool hdg_lock;
119     bool alt_lock;
120     double dt_count;
121     double dt_elev_count;
122     double headingChangeRate;
123     double headingError;
124     double minBearing;
125     double speedFraction;
126     double groundTargetSpeed;
127     double groundOffset;
128     double dt;
129
130     bool use_perf_vs;
131     SGPropertyNode_ptr refuel_node;
132
133     // helpers for Run
134     //TODO sort out which ones are better protected virtuals to allow
135     //subclasses to override specific behaviour
136     bool fpExecutable(time_t now);
137     void handleFirstWaypoint(void);
138     bool leadPointReached(FGAIWaypoint* curr);
139     bool handleAirportEndPoints(FGAIWaypoint* prev, time_t now);
140     bool reachedEndOfCruise(double&);
141     bool aiTrafficVisible(void);
142     void controlHeading(FGAIWaypoint* curr);
143     void controlSpeed(FGAIWaypoint* curr,
144                       FGAIWaypoint* next);
145     
146     void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
147     
148     void updateSecondaryTargetValues();
149     void updatePosition();
150     void updateHeading();
151     void updateBankAngleTarget();
152     void updateVerticalSpeedTarget();
153     void updatePitchAngleTarget();
154     void updateActualState();
155     void handleATCRequests();
156     void checkVisibility();
157     inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
158     inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
159    
160
161     double sign(double x);
162
163     std::string acType;
164     std::string company;
165     std::string transponderCode;
166
167     int spinCounter;
168     double prevSpeed;
169     double prev_dist_to_go;
170
171     bool holdPos;
172
173     bool _getGearDown() const;
174
175     const char * _getTransponderCode() const;
176
177     bool reachedWaypoint;
178     bool needsTaxiClearance;
179     bool _needsGroundElevation;
180     int  takeOffStatus; // 1 = joined departure cue; 2 = Passed DepartureHold waypoint; handover control to tower; 0 = any other state. 
181     time_t timeElapsed;
182
183     PerformanceData* _performance; // the performance data for this aircraft
184 };
185
186
187 #endif  // _FG_AIAircraft_HXX