]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Replace the data/Airports/basic.dat.gz and data/Airports/runways.dat.gz with
[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    double x_offset;           // used by ship ojects, in meters
77    double y_offset;           // used by ship ojects, in meters
78    double z_offset;           // used by ship ojects, in meters    
79 } FGAIModelEntity;
80
81
82 class FGAIBase {
83
84 public:
85
86     FGAIBase();
87     virtual ~FGAIBase();
88     virtual void update(double dt);
89     inline Point3D GetPos() { return(pos); }
90
91     enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
92                        otRocket, otStorm, otThermal, 
93                        MAX_OBJECTS };   // Needs to be last!!!
94
95     virtual bool init();
96     virtual void bind();
97     virtual void unbind();
98
99     void setPath( const char* model );
100     void setSpeed( double speed_KTAS );
101     void setAltitude( double altitude_ft );
102     void setHeading( double heading );
103     void setLatitude( double latitude );
104     void setLongitude( double longitude );
105     void setBank( double bank );
106     void setRadius ( double radius );
107     void setXoffset( double x_offset );
108     void setYoffset( double y_offset );
109     void setZoffset( double z_offset );
110
111
112     void* getID();
113     void setDie( bool die );
114     bool getDie();
115
116 protected:
117
118     SGPropertyNode *props;
119     FGAIManager* manager;
120
121     // these describe the model's actual state
122     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
123     double hdg;         // True heading in degrees
124     double roll;        // degrees, left is negative
125     double pitch;       // degrees, nose-down is negative
126     double speed;       // knots true airspeed
127     double altitude;    // meters above sea level
128     double vs;          // vertical speed, feet per minute  
129     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
130
131     // these describe the flols 
132     Point3D flolspos; // WGS84 lat & lon in degrees, elev above sea-level in meters
133     double flols_x_offset;      // longitudinal distance, in meters
134     double flols_y_offset;      // lateral distance, in meters
135     double flols_z_offset;      // height, in meters
136     
137     double ft_per_deg_lon;
138     double ft_per_deg_lat;
139
140     // these describe the model's desired state
141     double tgt_heading;  // target heading, degrees true
142     double tgt_altitude; // target altitude, *feet* above sea level
143     double tgt_speed;    // target speed, KTAS
144     double tgt_roll;
145     double tgt_pitch;
146     double tgt_yaw;
147     double tgt_vs;
148
149     // these describe radar information for the user
150     bool in_range;       // true if in range of the radar, otherwise false
151     double bearing;      // true bearing from user to this model
152     double elevation;    // elevation in degrees from user to this model
153     double range;        // range from user to this model, nm
154     double rdot;         // range rate, in knots
155     double horiz_offset; // look left/right from user to me, deg
156     double vert_offset;  // look up/down from user to me, deg
157     double x_shift;      // value used by radar display instrument
158     double y_shift;      // value used by radar display instrument
159     double rotation;     // value used by radar display instrument
160
161
162     string model_path;     //Path to the 3D model
163     ssgBranch * model;     //The 3D model object
164     SGModelPlacement aip;
165     bool delete_me;
166     bool invisible;
167     bool no_roll;
168     double life;
169     FGAIFlightPlan *fp;
170
171     void Transform();
172
173     double UpdateRadar(FGAIManager* manager);
174
175     string _type_str;
176     object_type _otype;
177     int index;
178
179 public:
180
181     object_type getType();
182     bool isa( object_type otype );
183
184     double _getVS_fps() const;
185     void _setVS_fps( double _vs );
186
187     double _getAltitude() const;
188     void _setAltitude( double _alt );
189
190     void _setLongitude( double longitude );
191     void _setLatitude ( double latitude );
192
193     double _getLongitude() const;
194     double _getLatitude () const;
195
196     double _getBearing() const;
197     double _getElevation() const;
198     double _getRdot() const;
199     double _getH_offset() const;
200     double _getV_offset() const;
201     double _getX_shift() const;
202     double _getY_shift() const;
203     double _getRotation() const;
204
205     double rho;
206     double T;                             // temperature, degs farenheit
207     double p;                             // pressure lbs/sq ft
208         double a;                             // speed of sound at altitude (ft/s)
209         double Mach;                          // Mach number
210         
211     static const double e;
212     static const double lbs_to_slugs;
213
214     int _getID() const;
215
216     inline double _getRange() { return range; };
217   ssgBranch * load3DModel(const string& fg_root, 
218                           const string &path,
219                           SGPropertyNode *prop_root, 
220                           double sim_time_sec);
221
222     static bool _isNight();
223 };
224
225
226 inline void FGAIBase::setPath( const char* model ) {
227   model_path.append(model);
228 }
229
230 inline void FGAIBase::setSpeed( double speed_KTAS ) {
231   speed = tgt_speed = speed_KTAS;
232 }
233
234 inline void FGAIBase::setRadius( double radius ) {
235   turn_radius_ft = radius;
236 }
237
238 inline void FGAIBase::setXoffset( double x_offset ) {
239   flols_x_offset = x_offset;
240 }
241
242 inline void FGAIBase::setYoffset( double y_offset ) {
243   flols_y_offset = y_offset;
244 }
245
246 inline void FGAIBase::setZoffset( double z_offset ) {
247   flols_z_offset = z_offset;
248 }
249 inline void FGAIBase::setHeading( double heading ) {
250   hdg = tgt_heading = heading;
251 }
252
253 inline void FGAIBase::setAltitude( double altitude_ft ) {
254     altitude = tgt_altitude = altitude_ft;
255     pos.setelev(altitude * SG_FEET_TO_METER);
256 }
257
258 inline void FGAIBase::setBank( double bank ) {
259   roll = tgt_roll = bank;
260   no_roll = false;
261 }
262
263 inline void FGAIBase::setLongitude( double longitude ) {
264     pos.setlon( longitude );
265 }
266 inline void FGAIBase::setLatitude ( double latitude ) {
267     pos.setlat( latitude );
268 }
269
270 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
271 inline bool FGAIBase::getDie() { return delete_me; }
272
273 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
274
275 inline void* FGAIBase::getID() { return this; }
276
277
278
279 #endif  // _FG_AIBASE_HXX
280