]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
bc8b2e48a51f2b965966bf6f55a0979063dae8ef
[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., 675 Mass Ave, Cambridge, MA 02139, 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/point3d.hxx>
28 #include <simgear/scene/model/placement.hxx>
29
30 #include <Main/fg_props.hxx>
31
32 SG_USING_STD(string);
33 SG_USING_STD(list);
34
35 class FGAIManager;
36 class FGAIFlightPlan;
37
38
39 typedef struct {
40    string callsign;
41
42    // can be aircraft, ship, storm, thermal or ballistic
43    string m_type;
44    string m_class;
45    string path;
46    string flightplan;
47
48    FGAIFlightPlan *fp;
49
50    double repeat;             // in seconds
51    double latitude;           // used if no flightplan defined
52    double longitude;          // used if no flightplan defined
53    double altitude;           // used if no flightplan defined
54    double speed;              // used if no flightplan defined
55    double heading;            // used if no flightplan defined
56    double roll;               // used if no flightplan defined
57    double azimuth;            // used by ballistic objects
58    double elevation;          // used by ballistic objects
59    double rudder;             // used by ship objects
60    double strength;           // used by thermal objects
61    double diameter;           // used by thermal objects
62    double height_msl;         // used by thermal objects
63    double eda;                // used by ballistic objects
64    double life;               // life span in seconds
65    double buoyancy;           // acceleration in ft per sec2
66    double wind_from_east;     // in feet per second
67    double wind_from_north;    // in feet per second
68    double cd;                 // coefficient of drag
69    bool wind;                 // if true, model reacts to parent wind
70    double mass;               // in slugs
71    bool aero_stabilised;      // if true, ballistic object aligns with trajectory
72    list<string> solid_objects;    // List of solid object names
73    list<string> wire_objects;     // List of wire object names
74    list<string> catapult_objects; // List of catapult object names
75    double radius;             // used by ship ojects, in feet
76     
77 } FGAIModelEntity;
78
79
80 class FGAIBase {
81
82 public:
83
84     FGAIBase();
85     virtual ~FGAIBase();
86     virtual void update(double dt);
87     inline Point3D GetPos() { return(pos); }
88
89     enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
90                        otRocket, otStorm, otThermal, 
91                        MAX_OBJECTS };   // Needs to be last!!!
92
93     virtual bool init();
94     virtual void bind();
95     virtual void unbind();
96
97     void setPath( const char* model );
98     void setSpeed( double speed_KTAS );
99     void setAltitude( double altitude_ft );
100     void setHeading( double heading );
101     void setLatitude( double latitude );
102     void setLongitude( double longitude );
103     void setBank( double bank );
104     void setRadius ( double radius );
105
106     void* getID();
107     void setDie( bool die );
108     bool getDie();
109
110 protected:
111
112     SGPropertyNode *props;
113     FGAIManager* manager;
114
115     // these describe the model's actual state
116     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
117     double hdg;         // True heading in degrees
118     double roll;        // degrees, left is negative
119     double pitch;       // degrees, nose-down is negative
120     double speed;       // knots true airspeed
121     double altitude;    // meters above sea level
122     double vs;          // vertical speed, feet per minute  
123     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
124
125     double ft_per_deg_lon;
126     double ft_per_deg_lat;
127
128     // these describe the model's desired state
129     double tgt_heading;  // target heading, degrees true
130     double tgt_altitude; // target altitude, *feet* above sea level
131     double tgt_speed;    // target speed, KTAS
132     double tgt_roll;
133     double tgt_pitch;
134     double tgt_yaw;
135     double tgt_vs;
136
137     // these describe radar information for the user
138     bool in_range;       // true if in range of the radar, otherwise false
139     double bearing;      // true bearing from user to this model
140     double elevation;    // elevation in degrees from user to this model
141     double range;        // range from user to this model, nm
142     double rdot;         // range rate, in knots
143     double horiz_offset; // look left/right from user to me, deg
144     double vert_offset;  // look up/down from user to me, deg
145     double x_shift;      // value used by radar display instrument
146     double y_shift;      // value used by radar display instrument
147     double rotation;     // value used by radar display instrument
148
149
150     string model_path;     //Path to the 3D model
151     ssgBranch * model;     //The 3D model object
152     SGModelPlacement aip;
153     bool delete_me;
154     bool invisible;
155     bool no_roll;
156     double life;
157     FGAIFlightPlan *fp;
158
159     void Transform();
160
161     double UpdateRadar(FGAIManager* manager);
162
163     string _type_str;
164     object_type _otype;
165     int index;
166
167 public:
168
169     object_type getType();
170     bool isa( object_type otype );
171
172     double _getVS_fps() const;
173     void _setVS_fps( double _vs );
174
175     double _getAltitude() const;
176     void _setAltitude( double _alt );
177
178     void _setLongitude( double longitude );
179     void _setLatitude ( double latitude );
180
181     double _getLongitude() const;
182     double _getLatitude () const;
183
184     double _getBearing() const;
185     double _getElevation() const;
186     double _getRdot() const;
187     double _getH_offset() const;
188     double _getV_offset() const;
189     double _getX_shift() const;
190     double _getY_shift() const;
191     double _getRotation() const;
192
193     double rho;
194     double T;                             // temperature, degs farenheit
195     double p;                             // pressure lbs/sq ft
196         double a;                             // speed of sound at altitude (ft/s)
197         double Mach;                          // Mach number
198         
199     static const double e;
200     static const double lbs_to_slugs;
201
202     int _getID() const;
203
204     inline double _getRange() { return range; };
205   ssgBranch * load3DModel(const string& fg_root, 
206                           const string &path,
207                           SGPropertyNode *prop_root, 
208                           double sim_time_sec);
209
210     static bool _isNight();
211 };
212
213
214 inline void FGAIBase::setPath( const char* model ) {
215   model_path.append(model);
216 }
217
218 inline void FGAIBase::setSpeed( double speed_KTAS ) {
219   speed = tgt_speed = speed_KTAS;
220 }
221
222 inline void FGAIBase::setRadius( double radius ) {
223   turn_radius_ft = radius;
224 }
225
226 inline void FGAIBase::setHeading( double heading ) {
227   hdg = tgt_heading = heading;
228 }
229
230 inline void FGAIBase::setAltitude( double altitude_ft ) {
231     altitude = tgt_altitude = altitude_ft;
232     pos.setelev(altitude * SG_FEET_TO_METER);
233 }
234
235 inline void FGAIBase::setBank( double bank ) {
236   roll = tgt_roll = bank;
237   no_roll = false;
238 }
239
240 inline void FGAIBase::setLongitude( double longitude ) {
241     pos.setlon( longitude );
242 }
243 inline void FGAIBase::setLatitude ( double latitude ) {
244     pos.setlat( latitude );
245 }
246
247 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
248 inline bool FGAIBase::getDie() { return delete_me; }
249
250 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
251
252 inline void* FGAIBase::getID() { return this; }
253
254 #endif  // _FG_AIBASE_HXX
255