]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
Some more work on AI/ATC user interaction integration:
[flightgear.git] / src / AIModel / AIAircraft.hxx
1
2 // FGAIAircraft - AIBase derived class creates an AI aircraft
3 //
4 // Written by David Culp, started October 2003.
5 //
6 // Copyright (C) 2003  David P. Culp - davidculp2@comcast.net
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #ifndef _FG_AIAircraft_HXX
23 #define _FG_AIAircraft_HXX
24
25 #include "AIManager.hxx"
26 #include "AIBase.hxx"
27
28 #include <Traffic/SchedFlight.hxx>
29 #include <Traffic/Schedule.hxx>
30 #include <ATC/trafficcontrol.hxx>
31
32 #include <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     time_t checkForArrivalTime(string wptName);
58     
59     void AccelTo(double speed);
60     void PitchTo(double angle);
61     void RollTo(double angle);
62     void YawTo(double angle);
63     void ClimbTo(double altitude);
64     void TurnTo(double heading);
65     
66     void getGroundElev(double dt); //TODO these 3 really need to be public?
67     void doGroundAltitude();
68     bool loadNextLeg  (double dist=0);
69     void resetPositionFromFlightPlan();
70     double getBearing(double crse);
71
72     void setAcType(const std::string& ac) { acType = ac; };
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
82     virtual const char* getTypeString(void) const { return "aircraft"; }
83
84     std::string GetTransponderCode() { return transponderCode; };
85     void SetTransponderCode(const std::string& tc) { transponderCode = tc;};
86
87     // included as performance data needs them, who else?
88     inline PerformanceData* getPerformance() { return _performance; };
89     inline bool onGround() const { return no_roll; };
90     inline double getSpeed() const { return speed; };
91     inline double getRoll() const { return roll; };
92     inline double getPitch() const { return pitch; };
93     inline double getAltitude() const { return altitude_ft; };
94     inline double getVerticalSpeed() const { return vs; };
95     inline double altitudeAGL() const { return props->getFloatValue("position/altitude-agl-ft");};
96     inline double airspeed() const { return props->getFloatValue("velocities/airspeed-kt");};
97     std::string atGate();
98
99     void checkTcas();
100     
101 protected:
102     void Run(double dt);
103
104 private:
105     FGAISchedule *trafficRef;
106     FGATCController *controller, *prevController; 
107
108     bool hdg_lock;
109     bool alt_lock;
110     double dt_count;
111     double dt_elev_count;
112     double headingChangeRate;
113     double headingError;
114     double minBearing;
115     double speedFraction;
116     double groundTargetSpeed;
117     double groundOffset;
118     double dt;
119
120     bool use_perf_vs;
121     SGPropertyNode_ptr refuel_node;
122
123     // helpers for Run
124     //TODO sort out which ones are better protected virtuals to allow
125     //subclasses to override specific behaviour
126     bool fpExecutable(time_t now);
127     void handleFirstWaypoint(void);
128     bool leadPointReached(FGAIFlightPlan::waypoint* curr);
129     bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
130     bool reachedEndOfCruise(double&);
131     bool aiTrafficVisible(void);
132     void controlHeading(FGAIFlightPlan::waypoint* curr);
133     void controlSpeed(FGAIFlightPlan::waypoint* curr,
134                       FGAIFlightPlan::waypoint* next);
135     
136     void updatePrimaryTargetValues(bool& flightplanActive, bool& aiOutOfSight);
137     
138     void updateSecondaryTargetValues();
139     void updatePosition();
140     void updateHeading();
141     void updateBankAngleTarget();
142     void updateVerticalSpeedTarget();
143     void updatePitchAngleTarget();
144     void updateActualState();
145     void handleATCRequests();
146     void checkVisibility();
147     inline bool isStationary() { return ((fabs(speed)<=0.0001)&&(fabs(tgt_speed)<=0.0001));}
148     inline bool needGroundElevation() { if (!isStationary()) _needsGroundElevation=true;return _needsGroundElevation;}
149
150     double sign(double x);
151
152     std::string acType;
153     std::string company;
154     std::string transponderCode;
155
156     int spinCounter;
157     double prevSpeed;
158     double prev_dist_to_go;
159
160     bool holdPos;
161
162     bool _getGearDown() const;
163
164     const char * _getTransponderCode() const;
165
166     bool reachedWaypoint;
167     bool needsTaxiClearance;
168     bool _needsGroundElevation;
169     time_t timeElapsed;
170
171     PerformanceData* _performance; // the performance data for this aircraft
172 };
173
174
175 #endif  // _FG_AIAircraft_HXX