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 and storm objects
62 double diameter; // used by thermal and storm objects
63 double height_msl; // used by thermal and storm 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 list<Point3D> ppositions; // List of positions on a carrier where an aircraft can start.
77 Point3D flols_offset; // used by carrier objects, in meters
78 double radius; // used by ship objects, in feet
79 string name; // used by carrier objects
80 string pennant_number; // used by carrier objects
81 string acType; // used by aircraft objects
82 string company; // used by aircraft objects
92 virtual void update(double dt);
93 inline Point3D GetPos() { return(pos); }
95 enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
96 otRocket, otStorm, otThermal,
97 MAX_OBJECTS }; // Needs to be last!!!
101 virtual void unbind();
103 void setPath( const char* model );
104 void setSpeed( double speed_KTAS );
105 void setAltitude( double altitude_ft );
106 void setHeading( double heading );
107 void setLatitude( double latitude );
108 void setLongitude( double longitude );
109 void setBank( double bank );
110 void setRadius ( double radius );
111 void setXoffset( double x_offset );
112 void setYoffset( double y_offset );
113 void setZoffset( double z_offset );
117 void setDie( bool die );
122 SGPropertyNode *props;
123 FGAIManager* manager;
125 // these describe the model's actual state
126 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
127 double hdg; // True heading in degrees
128 double roll; // degrees, left is negative
129 double pitch; // degrees, nose-down is negative
130 double speed; // knots true airspeed
131 double altitude; // meters above sea level
132 double vs; // vertical speed, feet per minute
133 double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
135 double ft_per_deg_lon;
136 double ft_per_deg_lat;
138 // these describe the model's desired state
139 double tgt_heading; // target heading, degrees true
140 double tgt_altitude; // target altitude, *feet* above sea level
141 double tgt_speed; // target speed, KTAS
147 // these describe radar information for the user
148 bool in_range; // true if in range of the radar, otherwise false
149 double bearing; // true bearing from user to this model
150 double elevation; // elevation in degrees from user to this model
151 double range; // range from user to this model, nm
152 double rdot; // range rate, in knots
153 double horiz_offset; // look left/right from user to me, deg
154 double vert_offset; // look up/down from user to me, deg
155 double x_shift; // value used by radar display instrument
156 double y_shift; // value used by radar display instrument
157 double rotation; // value used by radar display instrument
160 string model_path; //Path to the 3D model
161 ssgBranch * model; //The 3D model object
162 SGModelPlacement aip;
171 double UpdateRadar(FGAIManager* manager);
179 object_type getType();
180 bool isa( object_type otype );
182 double _getVS_fps() const;
183 void _setVS_fps( double _vs );
185 double _getAltitude() const;
186 void _setAltitude( double _alt );
188 void _setLongitude( double longitude );
189 void _setLatitude ( double latitude );
191 double _getLongitude() const;
192 double _getLatitude () const;
194 double _getBearing() const;
195 double _getElevation() const;
196 double _getRdot() const;
197 double _getH_offset() const;
198 double _getV_offset() const;
199 double _getX_shift() const;
200 double _getY_shift() const;
201 double _getRotation() const;
204 double T; // temperature, degs farenheit
205 double p; // pressure lbs/sq ft
206 double a; // speed of sound at altitude (ft/s)
207 double Mach; // Mach number
209 static const double e;
210 static const double lbs_to_slugs;
214 inline double _getRange() { return range; };
215 ssgBranch * load3DModel(const string& fg_root,
217 SGPropertyNode *prop_root,
218 double sim_time_sec);
220 static bool _isNight();
224 inline void FGAIBase::setPath( const char* model ) {
225 model_path.append(model);
228 inline void FGAIBase::setSpeed( double speed_KTAS ) {
229 speed = tgt_speed = speed_KTAS;
232 inline void FGAIBase::setRadius( double radius ) {
233 turn_radius_ft = radius;
236 inline void FGAIBase::setHeading( double heading ) {
237 hdg = tgt_heading = heading;
240 inline void FGAIBase::setAltitude( double altitude_ft ) {
241 altitude = tgt_altitude = altitude_ft;
242 pos.setelev(altitude * SG_FEET_TO_METER);
245 inline void FGAIBase::setBank( double bank ) {
246 roll = tgt_roll = bank;
250 inline void FGAIBase::setLongitude( double longitude ) {
251 pos.setlon( longitude );
253 inline void FGAIBase::setLatitude ( double latitude ) {
254 pos.setlat( latitude );
257 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
258 inline bool FGAIBase::getDie() { return delete_me; }
260 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
262 inline void* FGAIBase::getID() { return this; }
266 #endif // _FG_AIBASE_HXX