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
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.
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.
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.
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
26 #include <simgear/constants.h>
27 #include <simgear/math/point3d.hxx>
28 #include <simgear/scene/model/placement.hxx>
29 #include <simgear/misc/sg_path.hxx>
31 #include <Main/fg_props.hxx>
43 // can be aircraft, ship, storm, thermal or ballistic
51 double repeat; // in seconds
52 double latitude; // used if no flightplan defined
53 double longitude; // used if no flightplan defined
54 double altitude; // used if no flightplan defined
55 double speed; // used if no flightplan defined
56 double heading; // used if no flightplan defined
57 double roll; // used if no flightplan defined
58 double azimuth; // used by ballistic objects
59 double elevation; // used by ballistic objects
60 double rudder; // used by ship objects
61 double strength; // used by thermal objects
62 double diameter; // used by thermal objects
63 double height_msl; // used by thermal objects
64 double eda; // used by ballistic objects
65 double life; // life span in seconds
66 double buoyancy; // acceleration in ft per sec2
67 double wind_from_east; // in feet per second
68 double wind_from_north; // in feet per second
69 double cd; // coefficient of drag
70 bool wind; // if true, model reacts to parent wind
71 double mass; // in slugs
72 bool aero_stabilised; // if true, ballistic object aligns with trajectory
73 list<string> solid_objects; // List of solid object names
74 list<string> wire_objects; // List of wire object names
75 list<string> catapult_objects; // List of catapult object names
76 double radius; // used by ship ojects, in feet
77 double x_offset; // used by ship ojects, in meters
78 double y_offset; // used by ship ojects, in meters
79 double z_offset; // used by ship ojects, in meters
80 string acType; // used by aircraft objects
81 string company; // used by aircraft objects
91 virtual void update(double dt);
92 inline Point3D GetPos() { return(pos); }
94 enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
95 otRocket, otStorm, otThermal,
96 MAX_OBJECTS }; // Needs to be last!!!
100 virtual void unbind();
102 void setPath( const char* model );
103 void setSpeed( double speed_KTAS );
104 void setAltitude( double altitude_ft );
105 void setHeading( double heading );
106 void setLatitude( double latitude );
107 void setLongitude( double longitude );
108 void setBank( double bank );
109 void setRadius ( double radius );
110 void setXoffset( double x_offset );
111 void setYoffset( double y_offset );
112 void setZoffset( double z_offset );
116 void setDie( bool die );
121 SGPropertyNode *props;
122 FGAIManager* manager;
124 // these describe the model's actual state
125 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
126 double hdg; // True heading in degrees
127 double roll; // degrees, left is negative
128 double pitch; // degrees, nose-down is negative
129 double speed; // knots true airspeed
130 double altitude; // meters above sea level
131 double vs; // vertical speed, feet per minute
132 double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
134 // these describe the flols
135 Point3D flolspos; // WGS84 lat & lon in degrees, elev above sea-level in meters
136 double flols_x_offset; // longitudinal distance, in meters
137 double flols_y_offset; // lateral distance, in meters
138 double flols_z_offset; // height, in meters
140 double ft_per_deg_lon;
141 double ft_per_deg_lat;
143 // these describe the model's desired state
144 double tgt_heading; // target heading, degrees true
145 double tgt_altitude; // target altitude, *feet* above sea level
146 double tgt_speed; // target speed, KTAS
152 // these describe radar information for the user
153 bool in_range; // true if in range of the radar, otherwise false
154 double bearing; // true bearing from user to this model
155 double elevation; // elevation in degrees from user to this model
156 double range; // range from user to this model, nm
157 double rdot; // range rate, in knots
158 double horiz_offset; // look left/right from user to me, deg
159 double vert_offset; // look up/down from user to me, deg
160 double x_shift; // value used by radar display instrument
161 double y_shift; // value used by radar display instrument
162 double rotation; // value used by radar display instrument
165 string model_path; //Path to the 3D model
166 ssgBranch * model; //The 3D model object
167 SGModelPlacement aip;
176 double UpdateRadar(FGAIManager* manager);
184 object_type getType();
185 bool isa( object_type otype );
187 double _getVS_fps() const;
188 void _setVS_fps( double _vs );
190 double _getAltitude() const;
191 void _setAltitude( double _alt );
193 void _setLongitude( double longitude );
194 void _setLatitude ( double latitude );
196 double _getLongitude() const;
197 double _getLatitude () const;
199 double _getBearing() const;
200 double _getElevation() const;
201 double _getRdot() const;
202 double _getH_offset() const;
203 double _getV_offset() const;
204 double _getX_shift() const;
205 double _getY_shift() const;
206 double _getRotation() const;
209 double T; // temperature, degs farenheit
210 double p; // pressure lbs/sq ft
211 double a; // speed of sound at altitude (ft/s)
212 double Mach; // Mach number
214 static const double e;
215 static const double lbs_to_slugs;
219 inline double _getRange() { return range; };
220 ssgBranch * load3DModel(const string& fg_root,
222 SGPropertyNode *prop_root,
223 double sim_time_sec);
225 static bool _isNight();
229 inline void FGAIBase::setPath( const char* model ) {
230 model_path.append(model);
233 inline void FGAIBase::setSpeed( double speed_KTAS ) {
234 speed = tgt_speed = speed_KTAS;
237 inline void FGAIBase::setRadius( double radius ) {
238 turn_radius_ft = radius;
241 inline void FGAIBase::setXoffset( double x_offset ) {
242 flols_x_offset = x_offset;
245 inline void FGAIBase::setYoffset( double y_offset ) {
246 flols_y_offset = y_offset;
249 inline void FGAIBase::setZoffset( double z_offset ) {
250 flols_z_offset = z_offset;
252 inline void FGAIBase::setHeading( double heading ) {
253 hdg = tgt_heading = heading;
256 inline void FGAIBase::setAltitude( double altitude_ft ) {
257 altitude = tgt_altitude = altitude_ft;
258 pos.setelev(altitude * SG_FEET_TO_METER);
261 inline void FGAIBase::setBank( double bank ) {
262 roll = tgt_roll = bank;
266 inline void FGAIBase::setLongitude( double longitude ) {
267 pos.setlon( longitude );
269 inline void FGAIBase::setLatitude ( double latitude ) {
270 pos.setlat( latitude );
273 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
274 inline bool FGAIBase::getDie() { return delete_me; }
276 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
278 inline void* FGAIBase::getID() { return this; }
282 #endif // _FG_AIBASE_HXX