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
25 #include <simgear/constants.h>
26 #include <simgear/math/point3d.hxx>
27 #include <simgear/scene/model/placement.hxx>
29 #include <Main/fg_props.hxx>
40 // can be aircraft, ship, storm, thermal or ballistic
48 double repeat; // in seconds
49 double latitude; // used if no flightplan defined
50 double longitude; // used if no flightplan defined
51 double altitude; // used if no flightplan defined
52 double speed; // used if no flightplan defined
53 double heading; // used if no flightplan defined
54 double roll; // used if no flightplan defined
55 double azimuth; // used by ballistic objects
56 double elevation; // used by ballistic objects
57 double rudder; // used by ship objects
58 double strength; // used by thermal objects
59 double diameter; // used by thermal objects
60 double height_msl; // used by thermal objects
61 double eda; // used by ballistic objects
62 double life; // life span in seconds
63 double buoyancy; // acceleration in ft per sec2
64 double wind_from_east; // in feet per second
65 double wind_from_north; // in feet per second
66 double cd; // coefficient of drag
67 bool wind; // if true, model reacts to parent wind
68 double mass; // in slugs
69 bool aero_stabilised; // if true, ballistic object aligns with trajectory
70 double radius; // used by ship ojects, in feet
81 virtual void update(double dt);
82 inline Point3D GetPos() { return(pos); }
84 enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
85 otRocket, otStorm, otThermal,
86 MAX_OBJECTS }; // Needs to be last!!!
90 virtual void unbind();
92 void setPath( const char* model );
93 void setSpeed( double speed_KTAS );
94 void setAltitude( double altitude_ft );
95 void setHeading( double heading );
96 void setLatitude( double latitude );
97 void setLongitude( double longitude );
98 void setBank( double bank );
99 void setRadius ( double radius );
102 void setDie( bool die );
107 SGPropertyNode *props;
108 FGAIManager* manager;
110 // these describe the model's actual state
111 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
112 double hdg; // True heading in degrees
113 double roll; // degrees, left is negative
114 double pitch; // degrees, nose-down is negative
115 double speed; // knots true airspeed
116 double altitude; // meters above sea level
117 double vs; // vertical speed, feet per minute
118 double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
120 double ft_per_deg_lon;
121 double ft_per_deg_lat;
123 // these describe the model's desired state
124 double tgt_heading; // target heading, degrees true
125 double tgt_altitude; // target altitude, *feet* above sea level
126 double tgt_speed; // target speed, KTAS
132 // these describe radar information for the user
133 bool in_range; // true if in range of the radar, otherwise false
134 double bearing; // true bearing from user to this model
135 double elevation; // elevation in degrees from user to this model
136 double range; // range from user to this model, nm
137 double rdot; // range rate, in knots
138 double horiz_offset; // look left/right from user to me, deg
139 double vert_offset; // look up/down from user to me, deg
140 double x_shift; // value used by radar display instrument
141 double y_shift; // value used by radar display instrument
142 double rotation; // value used by radar display instrument
145 string model_path; //Path to the 3D model
146 ssgBranch * model; //The 3D model object
147 SGModelPlacement aip;
156 double UpdateRadar(FGAIManager* manager);
164 object_type getType();
165 bool isa( object_type otype );
167 double _getVS_fps() const;
168 void _setVS_fps( double _vs );
170 double _getAltitude() const;
171 void _setAltitude( double _alt );
173 void _setLongitude( double longitude );
174 void _setLatitude ( double latitude );
176 double _getLongitude() const;
177 double _getLatitude () const;
179 double _getBearing() const;
180 double _getElevation() const;
181 double _getRdot() const;
182 double _getH_offset() const;
183 double _getV_offset() const;
184 double _getX_shift() const;
185 double _getY_shift() const;
186 double _getRotation() const;
189 double T; // temperature, degs farenheit
190 double p; // pressure lbs/sq ft
191 double a; // speed of sound at altitude (ft/s)
192 double Mach; // Mach number
194 static const double e;
195 static const double lbs_to_slugs;
199 inline double _getRange() { return range; };
201 static bool _isNight();
205 inline void FGAIBase::setPath( const char* model ) {
206 model_path.append(model);
209 inline void FGAIBase::setSpeed( double speed_KTAS ) {
210 speed = tgt_speed = speed_KTAS;
213 inline void FGAIBase::setRadius( double radius ) {
214 turn_radius_ft = radius;
217 inline void FGAIBase::setHeading( double heading ) {
218 hdg = tgt_heading = heading;
221 inline void FGAIBase::setAltitude( double altitude_ft ) {
222 altitude = tgt_altitude = altitude_ft;
223 pos.setelev(altitude * SG_FEET_TO_METER);
226 inline void FGAIBase::setBank( double bank ) {
227 roll = tgt_roll = bank;
231 inline void FGAIBase::setLongitude( double longitude ) {
232 pos.setlon( longitude );
234 inline void FGAIBase::setLatitude ( double latitude ) {
235 pos.setlat( latitude );
238 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
239 inline bool FGAIBase::getDie() { return delete_me; }
241 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
243 inline void* FGAIBase::getID() { return this; }
245 #endif // _FG_AIBASE_HXX