]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Ground network distance tracking code. AIAircraft taxiing at airports
[flightgear.git] / src / AIModel / AIBase.hxx
1 // FGAIBase.hxx - abstract base class for AI objects
2 // Written by David Culp, started Nov 2003, based on
3 // David Luff's FGAIEntity class.
4 // - davidculp2@comcast.net
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
22
23 #include <string>
24 #include <list>
25
26 #include <simgear/constants.h>
27 #include <simgear/math/SGMath.hxx>
28 #include <simgear/math/point3d.hxx>
29 #include <simgear/scene/model/placement.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/ssgSharedPtr.hxx>
32 #include <simgear/structure/SGReferenced.hxx>
33
34 #include <Main/fg_props.hxx>
35
36 SG_USING_STD(string);
37 SG_USING_STD(list);
38
39 class FGAIManager;
40 class FGAIFlightPlan;
41
42 class FGAIBase : public SGReferenced {
43
44 public:
45     enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
46                        otRocket, otStorm, otThermal, otStatic, otMultiplayer,
47                        MAX_OBJECTS };   // Needs to be last!!!
48
49     FGAIBase(object_type ot);
50     virtual ~FGAIBase();
51
52     virtual void readFromScenario(SGPropertyNode* scFileNode);
53
54     virtual bool init();
55     virtual void update(double dt);
56     virtual void bind();
57     virtual void unbind();
58
59     void setManager(FGAIManager* mgr, SGPropertyNode* p);
60     void setPath( const char* model );
61     void setSpeed( double speed_KTAS );
62     void setAltitude( double altitude_ft );
63     void setHeading( double heading );
64     void setLatitude( double latitude );
65     void setLongitude( double longitude );
66     void setBank( double bank );
67     void setPitch( double newpitch );
68     void setRadius ( double radius );
69     void setXoffset( double x_offset );
70     void setYoffset( double y_offset );
71     void setZoffset( double z_offset );
72
73     int getID() const;
74
75     void setDie( bool die );
76     bool getDie();
77
78     SGVec3d getCartPosAt(const SGVec3d& off) const;
79
80 protected:
81
82     SGPropertyNode_ptr props;
83     FGAIManager* manager;
84
85     // these describe the model's actual state
86     SGGeod pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
87     double hdg;         // True heading in degrees
88     double roll;        // degrees, left is negative
89     double pitch;       // degrees, nose-down is negative
90     double speed;       // knots true airspeed
91     double altitude_ft; // feet above sea level
92     double vs;          // vertical speed, feet per minute
93     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
94
95     double ft_per_deg_lon;
96     double ft_per_deg_lat;
97
98     // these describe the model's desired state
99     double tgt_heading;     // target heading, degrees true
100     double tgt_altitude_ft; // target altitude, *feet* above sea level
101     double tgt_speed;       // target speed, KTAS
102     double tgt_roll;
103     double tgt_pitch;
104     double tgt_yaw;
105     double tgt_vs;
106
107     // these describe radar information for the user
108     bool in_range;       // true if in range of the radar, otherwise false
109     double bearing;      // true bearing from user to this model
110     double elevation;    // elevation in degrees from user to this model
111     double range;        // range from user to this model, nm
112     double rdot;         // range rate, in knots
113     double horiz_offset; // look left/right from user to me, deg
114     double vert_offset;  // look up/down from user to me, deg
115     double x_shift;      // value used by radar display instrument
116     double y_shift;      // value used by radar display instrument
117     double rotation;     // value used by radar display instrument
118     double ht_diff;              // value used by radar display instrument
119
120     string model_path;     //Path to the 3D model
121     ssgSharedPtr<ssgBranch> model; //The 3D model object
122     SGModelPlacement aip;
123     bool delete_me;
124     bool invisible;
125     bool no_roll;
126     double life;
127     FGAIFlightPlan *fp;
128
129     void Transform();
130     void CalculateMach();
131     double UpdateRadar(FGAIManager* manager);
132
133     static int _newAIModelID();
134
135 private:
136     const int _refID;
137     object_type _otype;
138
139 public:
140
141     object_type getType();
142     virtual const char* getTypeString(void) const { return "null"; }
143     bool isa( object_type otype );
144
145     double _getVS_fps() const;
146     void _setVS_fps( double _vs );
147
148     double _getAltitude() const;
149     void _setAltitude( double _alt );
150
151     void _setLongitude( double longitude );
152     void _setLatitude ( double latitude );
153
154     double _getLongitude() const;
155     double _getLatitude () const;
156
157     double _getBearing() const;
158     double _getElevation() const;
159     double _getRdot() const;
160     double _getH_offset() const;
161     double _getV_offset() const;
162     double _getX_shift() const;
163     double _getY_shift() const;
164     double _getRotation() const;
165
166     double rho;
167     double T;                             // temperature, degs farenheit
168     double p;                             // pressure lbs/sq ft
169     double a;                             // speed of sound at altitude (ft/s)
170     double Mach;                          // Mach number
171
172     static const double e;
173     static const double lbs_to_slugs;
174
175     inline double _getRange() { return range; };
176     ssgBranch * load3DModel(const string& fg_root,
177                             const string &path,
178                             SGPropertyNode *prop_root,
179                             double sim_time_sec);
180
181     static bool _isNight();
182 };
183
184 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
185     manager = mgr;
186     props = p;
187 }
188
189 inline void FGAIBase::setPath(const char* model ) {
190     model_path.append(model);
191 }
192
193 inline void FGAIBase::setSpeed( double speed_KTAS ) {
194     speed = tgt_speed = speed_KTAS;
195 }
196
197 inline void FGAIBase::setRadius( double radius ) {
198     turn_radius_ft = radius;
199 }
200
201 inline void FGAIBase::setHeading( double heading ) {
202     hdg = tgt_heading = heading;
203 }
204
205 inline void FGAIBase::setAltitude( double alt_ft ) {
206     altitude_ft = tgt_altitude_ft = alt_ft;
207     pos.setElevationFt(altitude_ft);
208 }
209
210 inline void FGAIBase::setBank( double bank ) {
211     roll = tgt_roll = bank;
212     no_roll = false;
213 }
214
215 inline void FGAIBase::setPitch( double newpitch ) {
216     pitch = tgt_pitch = newpitch;
217 }
218
219 inline void FGAIBase::setLongitude( double longitude ) {
220     pos.setLongitudeDeg( longitude );
221 }
222 inline void FGAIBase::setLatitude ( double latitude ) {
223     pos.setLatitudeDeg( latitude );
224 }
225
226 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
227 inline bool FGAIBase::getDie() { return delete_me; }
228
229 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
230
231
232
233 #endif  // _FG_AIBASE_HXX
234