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
86 virtual void update(double dt);
87 inline Point3D GetPos() { return(pos); }
89 enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
90 otRocket, otStorm, otThermal,
91 MAX_OBJECTS }; // Needs to be last!!!
95 virtual void unbind();
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 );
107 void setDie( bool die );
112 SGPropertyNode *props;
113 FGAIManager* manager;
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
125 double ft_per_deg_lon;
126 double ft_per_deg_lat;
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
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
150 string model_path; //Path to the 3D model
151 ssgBranch * model; //The 3D model object
152 SGModelPlacement aip;
161 double UpdateRadar(FGAIManager* manager);
169 object_type getType();
170 bool isa( object_type otype );
172 double _getVS_fps() const;
173 void _setVS_fps( double _vs );
175 double _getAltitude() const;
176 void _setAltitude( double _alt );
178 void _setLongitude( double longitude );
179 void _setLatitude ( double latitude );
181 double _getLongitude() const;
182 double _getLatitude () const;
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;
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
199 static const double e;
200 static const double lbs_to_slugs;
204 inline double _getRange() { return range; };
205 ssgBranch * load3DModel(const string& fg_root,
207 SGPropertyNode *prop_root,
208 double sim_time_sec);
210 static bool _isNight();
214 inline void FGAIBase::setPath( const char* model ) {
215 model_path.append(model);
218 inline void FGAIBase::setSpeed( double speed_KTAS ) {
219 speed = tgt_speed = speed_KTAS;
222 inline void FGAIBase::setRadius( double radius ) {
223 turn_radius_ft = radius;
226 inline void FGAIBase::setHeading( double heading ) {
227 hdg = tgt_heading = heading;
230 inline void FGAIBase::setAltitude( double altitude_ft ) {
231 altitude = tgt_altitude = altitude_ft;
232 pos.setelev(altitude * SG_FEET_TO_METER);
235 inline void FGAIBase::setBank( double bank ) {
236 roll = tgt_roll = bank;
240 inline void FGAIBase::setLongitude( double longitude ) {
241 pos.setlon( longitude );
243 inline void FGAIBase::setLatitude ( double latitude ) {
244 pos.setlat( latitude );
247 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
248 inline bool FGAIBase::getDie() { return delete_me; }
250 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
252 inline void* FGAIBase::getID() { return this; }
254 #endif // _FG_AIBASE_HXX