]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
Interim windows build fix
[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 "AIBase.hxx"
25
26 #include <string>
27
28 class PerformanceData;
29 class FGAISchedule;
30 class FGAIFlightPlan;
31 class FGATCController;
32 class FGATCInstruction;
33 class FGAIWaypoint;
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 update(double dt);
46     virtual void unbind();
47
48     void setPerformance(const std::string& acType, 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(const std::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     const std::string& getAcType() const { return acType; }
73   
74     void setCompany(const std::string& comp) { company = comp;};
75
76     void announcePositionToController(); //TODO have to be public?
77     void processATC(const FGATCInstruction& instruction);
78     void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };
79     bool getTaxiClearanceRequest() { return needsTaxiClearance; };
80     FGAISchedule * getTrafficRef() { return trafficRef; };
81     void setTrafficRef(FGAISchedule *ref) { trafficRef = ref; };
82     void resetTakeOffStatus() { takeOffStatus = 0;};
83     void setTakeOffStatus(int status) { takeOffStatus = status; };
84     void scheduleForATCTowerDepartureControl(int state);
85
86     //inline bool isScheduledForTakeoff() { return scheduledForTakeoff; };
87
88     virtual const char* getTypeString(void) const { return "aircraft"; }
89
90     const std::string& GetTransponderCode() { return transponderCode; };
91     void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
92
93     // included as performance data needs them, who else?
94     inline PerformanceData* getPerformance() { return _performance; };
95     inline bool onGround() const { return no_roll; };
96     inline double getSpeed() const { return speed; };
97     inline double getRoll() const { return roll; };
98     inline double getPitch() const { return pitch; };
99     inline double getAltitude() const { return altitude_ft; };
100     inline double getVerticalSpeed() const { return vs; };
101     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
102     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
103     const std::string& atGate();
104
105     int getTakeOffStatus() { return takeOffStatus; };
106
107     void checkTcas();
108     double calcVerticalSpeed(double vert_ft, double dist_m, double speed, double error);
109
110     FGATCController * getATCController() { return controller; };
111     
112     void clearATCController();
113 protected:
114     void Run(double dt);
115
116 private:
117     FGAISchedule *trafficRef;
118     FGATCController *controller,
119                     *prevController,
120                     *towerController; // Only needed to make a pre-announcement
121
122     bool hdg_lock;
123     bool alt_lock;
124     double dt_count;
125     double dt_elev_count;
126     double headingChangeRate;
127     double headingError;
128     double minBearing;
129     double speedFraction;
130     double groundTargetSpeed;
131     double groundOffset;
132     double dt;
133
134     bool use_perf_vs;
135     SGPropertyNode_ptr refuel_node;
136
137     // helpers for Run
138     //TODO sort out which ones are better protected virtuals to allow
139     //subclasses to override specific behaviour
140     bool fpExecutable(time_t now);
141     void handleFirstWaypoint(void);
142     bool leadPointReached(FGAIWaypoint* curr);
143     bool handleAirportEndPoints(FGAIWaypoint* prev, time_t now);
144     bool reachedEndOfCruise(double&);
145     bool aiTrafficVisible(void);
146     void controlHeading(FGAIWaypoint* curr);
147     void controlSpeed(FGAIWaypoint* curr,
148                       FGAIWaypoint* next);
149     
150     void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
151     
152     void updateSecondaryTargetValues();
153     void updateHeading();
154     void updateBankAngleTarget();
155     void updateVerticalSpeedTarget();
156     void updatePitchAngleTarget();
157     void updateActualState();
158     void updateModelProperties(double dt);
159     void handleATCRequests();
160     inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
161     inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
162    
163
164     double sign(double x);
165
166     std::string acType;
167     std::string company;
168     std::string transponderCode;
169
170     int spinCounter;
171     double prevSpeed;
172     double prev_dist_to_go;
173
174     bool holdPos;
175
176     const char * _getTransponderCode() const;
177
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    void assertSpeed(double speed);
186
187    struct
188    {
189        double remainingLength;
190        std::string startWptName;
191        std::string finalWptName;
192    } trackCache;
193 };
194
195
196 #endif  // _FG_AIAircraft_HXX