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 eda; // used by ballistic objects
61 double life; // life span in seconds
62 double buoyancy; // acceleration in ft per sec2
63 double wind_from_east; // in feet per second
64 double wind_from_north; // in feet per second
65 double cd; // coefficient of drag
66 bool wind; // if true, model reacts to parent wind
67 double mass; // in slugs
68 bool aero_stabilised; // if true, ballistic object aligns with trajectory
78 virtual void update(double dt);
79 inline Point3D GetPos() { return(pos); }
81 enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
82 otRocket, otStorm, otThermal,
83 MAX_OBJECTS }; // Needs to be last!!!
87 virtual void unbind();
89 void setPath( const char* model );
90 void setSpeed( double speed_KTAS );
91 void setAltitude( double altitude_ft );
92 void setHeading( double heading );
93 void setLatitude( double latitude );
94 void setLongitude( double longitude );
95 void setBank( double bank );
98 void setDie( bool die );
103 SGPropertyNode *props;
104 FGAIManager* manager;
106 // these describe the model's actual state
107 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
108 double hdg; // True heading in degrees
109 double roll; // degrees, left is negative
110 double pitch; // degrees, nose-down is negative
111 double speed; // knots true airspeed
112 double altitude; // meters above sea level
113 double vs; // vertical speed, feet per minute
115 double ft_per_deg_lon;
116 double ft_per_deg_lat;
118 // these describe the model's desired state
119 double tgt_heading; // target heading, degrees true
120 double tgt_altitude; // target altitude, *feet* above sea level
121 double tgt_speed; // target speed, KTAS
127 // these describe radar information for the user
128 bool in_range; // true if in range of the radar, otherwise false
129 double bearing; // true bearing from user to this model
130 double elevation; // elevation in degrees from user to this model
131 double range; // range from user to this model, nm
132 double rdot; // range rate, in knots
133 double horiz_offset; // look left/right from user to me, deg
134 double vert_offset; // look up/down from user to me, deg
135 double x_shift; // value used by radar display instrument
136 double y_shift; // value used by radar display instrument
137 double rotation; // value used by radar display instrument
140 string model_path; //Path to the 3D model
141 ssgBranch * model; //The 3D model object
142 SGModelPlacement aip;
151 double UpdateRadar(FGAIManager* manager);
159 object_type getType();
160 bool isa( object_type otype );
162 double _getVS_fps() const;
163 void _setVS_fps( double _vs );
165 double _getAltitude() const;
166 void _setAltitude( double _alt );
168 void _setLongitude( double longitude );
169 void _setLatitude ( double latitude );
171 double _getLongitude() const;
172 double _getLatitude () const;
174 double _getBearing() const;
175 double _getElevation() const;
176 double _getRdot() const;
177 double _getH_offset() const;
178 double _getV_offset() const;
179 double _getX_shift() const;
180 double _getY_shift() const;
181 double _getRotation() const;
184 double T; // temperature, degs farenheit
185 double p; // pressure lbs/sq ft
186 double a; // speed of sound at altitude (ft/s)
187 double Mach; // Mach number
189 static const double e;
190 static const double lbs_to_slugs;
194 inline double _getRange() { return range; };
196 static bool _isNight();
200 inline void FGAIBase::setPath( const char* model ) {
201 model_path.append(model);
204 inline void FGAIBase::setSpeed( double speed_KTAS ) {
205 speed = tgt_speed = speed_KTAS;
208 inline void FGAIBase::setHeading( double heading ) {
209 hdg = tgt_heading = heading;
212 inline void FGAIBase::setAltitude( double altitude_ft ) {
213 altitude = tgt_altitude = altitude_ft;
214 pos.setelev(altitude * SG_FEET_TO_METER);
217 inline void FGAIBase::setBank( double bank ) {
218 roll = tgt_roll = bank;
222 inline void FGAIBase::setLongitude( double longitude ) {
223 pos.setlon( longitude );
225 inline void FGAIBase::setLatitude ( double latitude ) {
226 pos.setlat( latitude );
229 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
230 inline bool FGAIBase::getDie() { return delete_me; }
232 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
234 inline void* FGAIBase::getID() { return this; }
236 #endif // _FG_AIBASE_HXX