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>
30 #include <Main/fg_props.hxx>
42 // can be aircraft, ship, storm, thermal or ballistic
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
88 virtual void update(double dt);
89 inline Point3D GetPos() { return(pos); }
91 enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
92 otRocket, otStorm, otThermal,
93 MAX_OBJECTS }; // Needs to be last!!!
97 virtual void unbind();
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 );
113 void setDie( bool die );
118 SGPropertyNode *props;
119 FGAIManager* manager;
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
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
137 double ft_per_deg_lon;
138 double ft_per_deg_lat;
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
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
162 string model_path; //Path to the 3D model
163 ssgBranch * model; //The 3D model object
164 SGModelPlacement aip;
173 double UpdateRadar(FGAIManager* manager);
181 object_type getType();
182 bool isa( object_type otype );
184 double _getVS_fps() const;
185 void _setVS_fps( double _vs );
187 double _getAltitude() const;
188 void _setAltitude( double _alt );
190 void _setLongitude( double longitude );
191 void _setLatitude ( double latitude );
193 double _getLongitude() const;
194 double _getLatitude () const;
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;
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
211 static const double e;
212 static const double lbs_to_slugs;
216 inline double _getRange() { return range; };
217 ssgBranch * load3DModel(const string& fg_root,
219 SGPropertyNode *prop_root,
220 double sim_time_sec);
222 static bool _isNight();
226 inline void FGAIBase::setPath( const char* model ) {
227 model_path.append(model);
230 inline void FGAIBase::setSpeed( double speed_KTAS ) {
231 speed = tgt_speed = speed_KTAS;
234 inline void FGAIBase::setRadius( double radius ) {
235 turn_radius_ft = radius;
238 inline void FGAIBase::setXoffset( double x_offset ) {
239 flols_x_offset = x_offset;
242 inline void FGAIBase::setYoffset( double y_offset ) {
243 flols_y_offset = y_offset;
246 inline void FGAIBase::setZoffset( double z_offset ) {
247 flols_z_offset = z_offset;
249 inline void FGAIBase::setHeading( double heading ) {
250 hdg = tgt_heading = heading;
253 inline void FGAIBase::setAltitude( double altitude_ft ) {
254 altitude = tgt_altitude = altitude_ft;
255 pos.setelev(altitude * SG_FEET_TO_METER);
258 inline void FGAIBase::setBank( double bank ) {
259 roll = tgt_roll = bank;
263 inline void FGAIBase::setLongitude( double longitude ) {
264 pos.setlon( longitude );
266 inline void FGAIBase::setLatitude ( double latitude ) {
267 pos.setlat( latitude );
270 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
271 inline bool FGAIBase::getDie() { return delete_me; }
273 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
275 inline void* FGAIBase::getID() { return this; }
279 #endif // _FG_AIBASE_HXX