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>
40 ParkPosition(const ParkPosition& pp)
41 : name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
43 ParkPosition(const string& n, const Point3D& off = Point3D(), double heading = 0)
44 : name(n), offset(off), heading_deg(heading)
54 // can be aircraft, ship, storm, thermal, static or ballistic
62 double repeat; // in seconds
63 double latitude; // used if no flightplan defined
64 double longitude; // used if no flightplan defined
65 double altitude; // used if no flightplan defined
66 double speed; // used if no flightplan defined
67 double heading; // used if no flightplan defined
68 double roll; // used if no flightplan defined
69 double azimuth; // used by ballistic objects
70 double elevation; // used by ballistic objects
71 double rudder; // used by ship objects
72 double strength; // used by thermal and storm objects
73 double diameter; // used by thermal and storm objects
74 double height_msl; // used by thermal and storm objects
75 double eda; // used by ballistic objects
76 double life; // life span in seconds
77 double buoyancy; // acceleration in ft per sec2
78 double wind_from_east; // in feet per second
79 double wind_from_north; // in feet per second
80 double cd; // coefficient of drag
81 bool wind; // if true, model reacts to parent wind
82 double mass; // in slugs
83 bool aero_stabilised; // if true, ballistic object aligns with trajectory
84 list<string> solid_objects; // List of solid object names
85 list<string> wire_objects; // List of wire object names
86 list<string> catapult_objects; // List of catapult object names
87 list<ParkPosition> ppositions; // List of positions on a carrier where an aircraft can start.
88 Point3D flols_offset; // used by carrier objects, in meters
89 double radius; // used by ship objects, in feet
90 string name; // used by carrier objects
91 string pennant_number; // used by carrier objects
92 string acType; // used by aircraft objects
93 string company; // used by aircraft objects
103 virtual void update(double dt);
104 inline Point3D GetPos() { return(pos); }
106 enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
107 otRocket, otStorm, otThermal, otStatic,
108 MAX_OBJECTS }; // Needs to be last!!!
112 virtual void unbind();
114 void setPath( const char* model );
115 void setSpeed( double speed_KTAS );
116 void setAltitude( double altitude_ft );
117 void setHeading( double heading );
118 void setLatitude( double latitude );
119 void setLongitude( double longitude );
120 void setBank( double bank );
121 void setRadius ( double radius );
122 void setXoffset( double x_offset );
123 void setYoffset( double y_offset );
124 void setZoffset( double z_offset );
128 void setDie( bool die );
131 Point3D getCartPosAt(const Point3D& off) const;
132 Point3D getGeocPosAt(const Point3D& off) const;
136 SGPropertyNode_ptr props;
137 FGAIManager* manager;
139 // these describe the model's actual state
140 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
141 double hdg; // True heading in degrees
142 double roll; // degrees, left is negative
143 double pitch; // degrees, nose-down is negative
144 double speed; // knots true airspeed
145 double altitude; // meters above sea level
146 double vs; // vertical speed, feet per minute
147 double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
149 double ft_per_deg_lon;
150 double ft_per_deg_lat;
152 // these describe the model's desired state
153 double tgt_heading; // target heading, degrees true
154 double tgt_altitude; // target altitude, *feet* above sea level
155 double tgt_speed; // target speed, KTAS
161 // these describe radar information for the user
162 bool in_range; // true if in range of the radar, otherwise false
163 double bearing; // true bearing from user to this model
164 double elevation; // elevation in degrees from user to this model
165 double range; // range from user to this model, nm
166 double rdot; // range rate, in knots
167 double horiz_offset; // look left/right from user to me, deg
168 double vert_offset; // look up/down from user to me, deg
169 double x_shift; // value used by radar display instrument
170 double y_shift; // value used by radar display instrument
171 double rotation; // value used by radar display instrument
174 string model_path; //Path to the 3D model
175 ssgBranch * model; //The 3D model object
176 SGModelPlacement aip;
184 void CalculateMach();
185 double UpdateRadar(FGAIManager* manager);
193 object_type getType();
194 bool isa( object_type otype );
196 double _getVS_fps() const;
197 void _setVS_fps( double _vs );
199 double _getAltitude() const;
200 void _setAltitude( double _alt );
202 void _setLongitude( double longitude );
203 void _setLatitude ( double latitude );
205 double _getLongitude() const;
206 double _getLatitude () const;
208 double _getBearing() const;
209 double _getElevation() const;
210 double _getRdot() const;
211 double _getH_offset() const;
212 double _getV_offset() const;
213 double _getX_shift() const;
214 double _getY_shift() const;
215 double _getRotation() const;
218 double T; // temperature, degs farenheit
219 double p; // pressure lbs/sq ft
220 double a; // speed of sound at altitude (ft/s)
221 double Mach; // Mach number
223 static const double e;
224 static const double lbs_to_slugs;
228 inline double _getRange() { return range; };
229 ssgBranch * load3DModel(const string& fg_root,
231 SGPropertyNode *prop_root,
232 double sim_time_sec);
234 static bool _isNight();
238 inline void FGAIBase::setPath( const char* model ) {
239 model_path.append(model);
242 inline void FGAIBase::setSpeed( double speed_KTAS ) {
243 speed = tgt_speed = speed_KTAS;
246 inline void FGAIBase::setRadius( double radius ) {
247 turn_radius_ft = radius;
250 inline void FGAIBase::setHeading( double heading ) {
251 hdg = tgt_heading = heading;
254 inline void FGAIBase::setAltitude( double altitude_ft ) {
255 altitude = tgt_altitude = altitude_ft;
256 pos.setelev(altitude * SG_FEET_TO_METER);
259 inline void FGAIBase::setBank( double bank ) {
260 roll = tgt_roll = bank;
264 inline void FGAIBase::setLongitude( double longitude ) {
265 pos.setlon( longitude );
267 inline void FGAIBase::setLatitude ( double latitude ) {
268 pos.setlat( latitude );
271 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
272 inline bool FGAIBase::getDie() { return delete_me; }
274 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
276 inline void* FGAIBase::getID() { return this; }
280 #endif // _FG_AIBASE_HXX