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>
30 #include <simgear/structure/ssgSharedPtr.hxx>
31 #include <simgear/structure/SGReferenced.hxx>
33 #include <Main/fg_props.hxx>
41 class FGAIBase : public SGReferenced {
44 enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
45 otRocket, otStorm, otThermal, otStatic, otMultiplayer,
46 MAX_OBJECTS }; // Needs to be last!!!
48 FGAIBase(object_type ot);
50 inline const Point3D& GetPos() const { return(pos); }
52 virtual void readFromScenario(SGPropertyNode* scFileNode);
55 virtual void update(double dt);
57 virtual void unbind();
59 void setManager(FGAIManager* mgr);
60 void setPath( const char* model );
61 void setSpeed( double speed_KTAS );
62 void setAltitude( double altitude_ft );
63 void setHeading( double heading );
64 void setLatitude( double latitude );
65 void setLongitude( double longitude );
66 void setBank( double bank );
67 void setPitch( double newpitch );
68 void setRadius ( double radius );
69 void setXoffset( double x_offset );
70 void setYoffset( double y_offset );
71 void setZoffset( double z_offset );
75 void setDie( bool die );
78 Point3D getCartPosAt(const Point3D& off) const;
79 Point3D getGeocPosAt(const Point3D& off) const;
83 SGPropertyNode_ptr props;
86 // these describe the model's actual state
87 Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
88 double hdg; // True heading in degrees
89 double roll; // degrees, left is negative
90 double pitch; // degrees, nose-down is negative
91 double speed; // knots true airspeed
92 double altitude; // meters above sea level
93 double vs; // vertical speed, feet per minute
94 double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
96 double ft_per_deg_lon;
97 double ft_per_deg_lat;
99 // these describe the model's desired state
100 double tgt_heading; // target heading, degrees true
101 double tgt_altitude; // target altitude, *feet* above sea level
102 double tgt_speed; // target speed, KTAS
108 // these describe radar information for the user
109 bool in_range; // true if in range of the radar, otherwise false
110 double bearing; // true bearing from user to this model
111 double elevation; // elevation in degrees from user to this model
112 double range; // range from user to this model, nm
113 double rdot; // range rate, in knots
114 double horiz_offset; // look left/right from user to me, deg
115 double vert_offset; // look up/down from user to me, deg
116 double x_shift; // value used by radar display instrument
117 double y_shift; // value used by radar display instrument
118 double rotation; // value used by radar display instrument
121 string model_path; //Path to the 3D model
122 ssgSharedPtr<ssgBranch> model; //The 3D model object
123 SGModelPlacement aip;
131 void CalculateMach();
132 double UpdateRadar(FGAIManager* manager);
136 static int _newAIModelID();
144 object_type getType();
145 virtual const char* getTypeString(void) const { return "null"; }
146 bool isa( object_type otype );
148 double _getVS_fps() const;
149 void _setVS_fps( double _vs );
151 double _getAltitude() const;
152 void _setAltitude( double _alt );
154 void _setLongitude( double longitude );
155 void _setLatitude ( double latitude );
157 double _getLongitude() const;
158 double _getLatitude () const;
160 double _getBearing() const;
161 double _getElevation() const;
162 double _getRdot() const;
163 double _getH_offset() const;
164 double _getV_offset() const;
165 double _getX_shift() const;
166 double _getY_shift() const;
167 double _getRotation() const;
170 double T; // temperature, degs farenheit
171 double p; // pressure lbs/sq ft
172 double a; // speed of sound at altitude (ft/s)
173 double Mach; // Mach number
175 static const double e;
176 static const double lbs_to_slugs;
178 inline double _getRange() { return range; };
179 ssgBranch * load3DModel(const string& fg_root,
181 SGPropertyNode *prop_root,
182 double sim_time_sec);
184 static bool _isNight();
187 inline void FGAIBase::setManager(FGAIManager* mgr) {
191 inline void FGAIBase::setPath(const char* model ) {
192 model_path.append(model);
195 inline void FGAIBase::setSpeed( double speed_KTAS ) {
196 speed = tgt_speed = speed_KTAS;
199 inline void FGAIBase::setRadius( double radius ) {
200 turn_radius_ft = radius;
203 inline void FGAIBase::setHeading( double heading ) {
204 hdg = tgt_heading = heading;
207 inline void FGAIBase::setAltitude( double altitude_ft ) {
208 altitude = tgt_altitude = altitude_ft;
209 pos.setelev(altitude * SG_FEET_TO_METER);
212 inline void FGAIBase::setBank( double bank ) {
213 roll = tgt_roll = bank;
217 inline void FGAIBase::setPitch( double newpitch ) {
218 pitch = tgt_pitch = newpitch;
221 inline void FGAIBase::setLongitude( double longitude ) {
222 pos.setlon( longitude );
224 inline void FGAIBase::setLatitude ( double latitude ) {
225 pos.setlat( latitude );
228 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
229 inline bool FGAIBase::getDie() { return delete_me; }
231 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
235 #endif // _FG_AIBASE_HXX