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