]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Vivian MEAZZA:
[flightgear.git] / src / AIModel / AIBase.hxx
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
5 //
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.
10 //
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.
15 //
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
22
23 #include <string>
24 #include <list>
25
26 #include <simgear/constants.h>
27 #include <simgear/math/SGMath.hxx>
28 #include <simgear/math/point3d.hxx>
29 #include <simgear/scene/model/placement.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/SGSharedPtr.hxx>
32 #include <simgear/structure/SGReferenced.hxx>
33
34 #include <Main/fg_props.hxx>
35
36
37 SG_USING_STD(string);
38 SG_USING_STD(list);
39
40 class FGAIManager;
41 class FGAIFlightPlan;
42
43 class FGAIBase : public SGReferenced {
44
45 public:
46     enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
47                        otRocket, otStorm, otThermal, otStatic, otMultiplayer,
48                        MAX_OBJECTS };   // Needs to be last!!!
49
50     FGAIBase(object_type ot);
51     virtual ~FGAIBase();
52
53     virtual void readFromScenario(SGPropertyNode* scFileNode);
54
55     virtual bool init(bool search_in_AI_path=false);
56     virtual void update(double dt);
57     virtual void bind();
58     virtual void unbind();
59     virtual void reinit() {}
60
61     void setManager(FGAIManager* mgr, SGPropertyNode* p);
62     void setPath( const char* model );
63     void setSMPath( const string& p );
64     void setSpeed( double speed_KTAS );
65     void setAltitude( double altitude_ft );
66     void setHeading( double heading );
67     void setLatitude( double latitude );
68     void setLongitude( double longitude );
69     void setBank( double bank );
70     void setPitch( double newpitch );
71     void setRadius ( double radius );
72     void setXoffset( double x_offset );
73     void setYoffset( double y_offset );
74     void setZoffset( double z_offset );
75     void setServiceable ( bool serviceable );
76     void setDie( bool die );
77     void setCollisionData( bool i, double lat, double lon, double elev );
78     void setImpactData( bool d );
79     void setImpactLat( double lat );
80     void setImpactLon( double lon );
81     void setImpactElev( double e );
82
83     int getID() const;
84     int _getSubID() const;
85
86     bool getDie();
87
88     SGVec3d getCartPosAt(const SGVec3d& off) const;
89     SGVec3d getCartPos() const;
90
91     double _getCartPosX() const;
92     double _getCartPosY() const;
93     double _getCartPosZ() const;
94
95     string _path;
96     string _callsign;
97     string _submodel;
98     string _name;
99
100 protected:
101
102     SGPropertyNode_ptr props;
103     SGPropertyNode_ptr trigger_node;
104     SGPropertyNode_ptr model_removed; // where to report model removal
105     FGAIManager* manager;
106
107     // these describe the model's actual state
108     SGGeod pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
109     double hdg;         // True heading in degrees
110     double roll;        // degrees, left is negative
111     double pitch;       // degrees, nose-down is negative
112     double speed;       // knots true airspeed
113     double altitude_ft; // feet above sea level
114     double vs;          // vertical speed, feet per minute
115     double speed_north_deg_sec;
116     double speed_east_deg_sec;
117     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
118
119     double ft_per_deg_lon;
120     double ft_per_deg_lat;
121
122     // these describe the model's desired state
123     double tgt_heading;     // target heading, degrees true
124     double tgt_altitude_ft; // target altitude, *feet* above sea level
125     double tgt_speed;       // target speed, KTAS
126     double tgt_roll;
127     double tgt_pitch;
128     double tgt_yaw;
129     double tgt_vs;
130
131     // these describe radar information for the user
132     bool in_range;       // true if in range of the radar, otherwise false
133     double bearing;      // true bearing from user to this model
134     double elevation;    // elevation in degrees from user to this model
135     double range;        // range from user to this model, nm
136     double rdot;         // range rate, in knots
137     double horiz_offset; // look left/right from user to me, deg
138     double vert_offset;  // look up/down from user to me, deg
139     double x_shift;      // value used by radar display instrument
140     double y_shift;      // value used by radar display instrument
141     double rotation;     // value used by radar display instrument
142     double ht_diff;              // value used by radar display instrument
143
144     string model_path;     //Path to the 3D model
145     osg::ref_ptr<osg::Node> model; //The 3D model object
146     SGModelPlacement aip;
147
148     bool delete_me;
149     bool invisible;
150     bool no_roll;
151     bool serviceable;
152     int _subID;
153
154     double life;
155
156     FGAIFlightPlan *fp;
157
158     bool _impact_reported;
159     bool _collision_reported;
160
161     double _impact_lat;
162     double _impact_lon;
163     double _impact_elev;
164     double _impact_hdg;
165     double _impact_pitch;
166     double _impact_roll;
167     double _impact_speed;
168
169     void Transform();
170     void CalculateMach();
171     double UpdateRadar(FGAIManager* manager);
172
173     static int _newAIModelID();
174
175 private:
176     int _refID;
177     object_type _otype;
178
179 public:
180     object_type getType();
181
182     virtual const char* getTypeString(void) const { return "null"; }
183
184     bool isa( object_type otype );
185
186     void _setVS_fps( double _vs );
187     void _setAltitude( double _alt );
188     void _setLongitude( double longitude );
189     void _setLatitude ( double latitude );
190     void _setSubID( int s );
191
192     double _getVS_fps() const;
193     double _getAltitude() const;
194     double _getLongitude() const;
195     double _getLatitude() const;
196     double _getBearing() const;
197     double _getElevationFt() const;
198     double _getRdot() const;
199     double _getH_offset() const;
200     double _getV_offset() const;
201     double _getX_shift() const;
202     double _getY_shift() const;
203     double _getRotation() const;
204     double _getSpeed() const;
205     double _getRoll() const;
206     double _getPitch() const;
207     double _getHeading() const;
208     double _get_speed_east_fps() const;
209     double _get_speed_north_fps() const;
210     double _get_SubPath() const;
211     double _getImpactLat() const;
212     double _getImpactLon() const;
213     double _getImpactElevFt() const;
214     double _getImpactHdg() const;
215     double _getImpactPitch() const;
216     double _getImpactRoll() const;
217     double _getImpactSpeed() const;
218
219     //unsigned int _getCount() const;
220
221     bool   _getServiceable() const;
222     bool   _getFirstTime() const;
223     bool   _getImpact();
224     bool   _getImpactData();
225     bool   _getCollisionData();
226
227     SGPropertyNode* _getProps() const;
228
229     const char* _getPath();
230     const char* _getCallsign();
231     const char* _getTriggerNode();
232     const char* _getName();
233     const char* _getSubmodel();
234
235
236     // These are used in the Mach number calculations
237
238     double rho;
239     double T;                             // temperature, degs farenheit
240     double p;                             // pressure lbs/sq ft
241     double a;                             // speed of sound at altitude (ft/s)
242     double Mach;                          // Mach number
243
244     static const double e;
245     static const double lbs_to_slugs;
246
247     inline double _getRange() { return range; };
248     osg::Node* load3DModel(const string& fg_root,
249                             const string &path,
250                             SGPropertyNode *prop_root,
251                             double sim_time_sec);
252
253     static bool _isNight();
254 };
255
256 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
257     manager = mgr;
258     props = p;
259 }
260
261 inline void FGAIBase::setPath(const char* model ) {
262     model_path.append(model);
263 }
264
265 inline void FGAIBase::setSMPath(const string& p) {
266     _path = p;
267 }
268
269 inline void FGAIBase::setServiceable(bool s) {
270     serviceable = s;
271 }
272
273 inline void FGAIBase::setSpeed( double speed_KTAS ) {
274     speed = tgt_speed = speed_KTAS;
275 }
276
277 inline void FGAIBase::setRadius( double radius ) {
278     turn_radius_ft = radius;
279 }
280
281 inline void FGAIBase::setHeading( double heading ) {
282     hdg = tgt_heading = heading;
283 }
284
285 inline void FGAIBase::setAltitude( double alt_ft ) {
286     altitude_ft = tgt_altitude_ft = alt_ft;
287     pos.setElevationFt(altitude_ft);
288 }
289
290 inline void FGAIBase::setBank( double bank ) {
291     roll = tgt_roll = bank;
292     no_roll = false;
293 }
294
295 inline void FGAIBase::setPitch( double newpitch ) {
296     pitch = tgt_pitch = newpitch;
297 }
298
299 inline void FGAIBase::setLongitude( double longitude ) {
300     pos.setLongitudeDeg( longitude );
301 }
302
303 inline void FGAIBase::setLatitude ( double latitude ) {
304     pos.setLatitudeDeg( latitude );
305 }
306
307 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
308
309 inline bool FGAIBase::getDie() { return delete_me; }
310
311 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
312
313 #endif  // _FG_AIBASE_HXX