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