]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIAircraft.hxx
035b44bc724667e150436149b7a953daf56aaa34
[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
30 #include <string>
31 SG_USING_STD(string);
32
33
34 class FGAIAircraft : public FGAIBase {
35
36 private:
37     typedef struct {
38         double accel;
39         double decel;
40         double climb_rate;
41         double descent_rate;
42         double takeoff_speed;
43         double climb_speed;
44         double cruise_speed;
45         double descent_speed;
46         double land_speed;
47     } PERF_STRUCT;
48
49 public:
50     enum aircraft_e {
51         LIGHT = 0,
52         WW2_FIGHTER,
53         JET_TRANSPORT,
54         JET_FIGHTER,
55         TANKER,
56         UFO
57     };
58     static const PERF_STRUCT settings[];
59
60     FGAIAircraft(FGAISchedule *ref=0);
61     ~FGAIAircraft();
62
63     virtual void readFromScenario(SGPropertyNode* scFileNode);
64
65     // virtual bool init(bool search_in_AI_path=false);
66     virtual void bind();
67     virtual void unbind();
68     virtual void update(double dt);
69
70     void setPerformance(const std::string& perfString);
71     void SetPerformance(const PERF_STRUCT *ps);
72     void setFlightPlan(const std::string& fp, bool repat = false);
73     void SetFlightPlan(FGAIFlightPlan *f);
74     void initializeFlightPlan();
75     FGAIFlightPlan* GetFlightPlan() const { return fp; };
76     void AccelTo(double speed);
77     void PitchTo(double angle);
78     void RollTo(double angle);
79     void YawTo(double angle);
80     void ClimbTo(double altitude);
81     void TurnTo(double heading);
82     void ProcessFlightPlan( double dt, time_t now );
83     void setCallSign(const string& );
84
85     void getGroundElev(double dt);
86     void doGroundAltitude();
87     void loadNextLeg  ();
88
89     void setAcType(const string& ac) { acType = ac; };
90     void setCompany(const string& comp) { company = comp;};
91
92     void announcePositionToController();
93     void processATC(FGATCInstruction instruction);
94
95     virtual const char* getTypeString(void) const { return "aircraft"; }
96
97 protected:
98     void Run(double dt);
99
100 private:
101     FGAISchedule *trafficRef;
102     FGATCController *controller, *prevController; 
103
104     bool hdg_lock;
105     bool alt_lock;
106     double dt_count;
107     double dt_elev_count;
108     double headingChangeRate;
109     double groundTargetSpeed;
110     double groundOffset;
111     double dt;
112
113     const PERF_STRUCT *performance;
114     bool use_perf_vs;
115     SGPropertyNode_ptr refuel_node;
116
117     // helpers for Run
118     bool fpExecutable(time_t now);
119     void handleFirstWaypoint(void);
120     bool leadPointReached(FGAIFlightPlan::waypoint* curr);
121     bool handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t now);
122     bool aiTrafficVisible(void);
123     void controlHeading(FGAIFlightPlan::waypoint* curr);
124     void controlSpeed(FGAIFlightPlan::waypoint* curr,
125                         FGAIFlightPlan::waypoint* next);
126     bool updateTargetValues();
127     void adjustSpeed(double tgt_speed);
128     void updatePosition();
129     void updateHeading();
130     void updateBankAngles();
131     void updateAltitudes();
132     void updateVerticalSpeed();
133     void matchPitchAngle();
134             
135     double sign(double x);
136
137     string acType;
138     string company;
139
140     int spinCounter;
141     double prevSpeed;
142     double prev_dist_to_go;
143
144     bool holdPos;
145
146     bool _getGearDown() const;
147     bool reachedWaypoint;
148     string callsign;             // The callsign of this tanker.
149 };
150
151
152 #endif  // _FG_AIAircraft_HXX