]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
7dc3d489905f8d1f81b24c2ce6b10c4b4ca01e72
[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 SG_USING_STD(string);
37 SG_USING_STD(list);
38
39 class FGAIManager;
40 class FGAIFlightPlan;
41
42 class FGAIBase : public SGReferenced {
43
44 public:
45     enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
46                        otRocket, otStorm, otThermal, otStatic, otMultiplayer,
47                        MAX_OBJECTS };   // Needs to be last!!!
48
49     FGAIBase(object_type ot);
50     virtual ~FGAIBase();
51
52     virtual void readFromScenario(SGPropertyNode* scFileNode);
53
54     virtual bool init(bool search_in_AI_path=false);
55     virtual void update(double dt);
56     virtual void bind();
57     virtual void unbind();
58     virtual void reinit() {}
59
60     void setManager(FGAIManager* mgr, SGPropertyNode* p);
61     void setPath( const char* model );
62     void setSpeed( double speed_KTAS );
63     void setAltitude( double altitude_ft );
64     void setHeading( double heading );
65     void setLatitude( double latitude );
66     void setLongitude( double longitude );
67     void setBank( double bank );
68     void setPitch( double newpitch );
69     void setRadius ( double radius );
70     void setXoffset( double x_offset );
71     void setYoffset( double y_offset );
72     void setZoffset( double z_offset );
73
74     int getID() const;
75
76     void setDie( bool die );
77     bool getDie();
78
79     SGVec3d getCartPosAt(const SGVec3d& off) const;
80     SGVec3d getCartPos() const;
81     double _getCartPosX() const;
82     double _getCartPosY() const;
83     double _getCartPosZ() const;
84
85 protected:
86
87     SGPropertyNode_ptr props;
88     SGPropertyNode_ptr model_removed; // where to report model removal
89     FGAIManager* manager;
90
91     // these describe the model's actual state
92     SGGeod pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
93     double hdg;         // True heading in degrees
94     double roll;        // degrees, left is negative
95     double pitch;       // degrees, nose-down is negative
96     double speed;       // knots true airspeed
97     double altitude_ft; // feet above sea level
98     double vs;          // vertical speed, feet per minute
99     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
100
101     double ft_per_deg_lon;
102     double ft_per_deg_lat;
103
104     // these describe the model's desired state
105     double tgt_heading;     // target heading, degrees true
106     double tgt_altitude_ft; // target altitude, *feet* above sea level
107     double tgt_speed;       // target speed, KTAS
108     double tgt_roll;
109     double tgt_pitch;
110     double tgt_yaw;
111     double tgt_vs;
112
113     // these describe radar information for the user
114     bool in_range;       // true if in range of the radar, otherwise false
115     double bearing;      // true bearing from user to this model
116     double elevation;    // elevation in degrees from user to this model
117     double range;        // range from user to this model, nm
118     double rdot;         // range rate, in knots
119     double horiz_offset; // look left/right from user to me, deg
120     double vert_offset;  // look up/down from user to me, deg
121     double x_shift;      // value used by radar display instrument
122     double y_shift;      // value used by radar display instrument
123     double rotation;     // value used by radar display instrument
124     double ht_diff;              // value used by radar display instrument
125
126     string model_path;     //Path to the 3D model
127     osg::ref_ptr<osg::Node> model; //The 3D model object
128     SGModelPlacement aip;
129     bool delete_me;
130     bool invisible;
131     bool no_roll;
132     double life;
133     FGAIFlightPlan *fp;
134
135     void Transform();
136     void CalculateMach();
137     double UpdateRadar(FGAIManager* manager);
138
139     static int _newAIModelID();
140
141 private:
142     const int _refID;
143     object_type _otype;
144
145 public:
146
147     object_type getType();
148     virtual const char* getTypeString(void) const { return "null"; }
149     bool isa( object_type otype );
150
151     double _getVS_fps() const;
152     void _setVS_fps( double _vs );
153
154     double _getAltitude() const;
155     void _setAltitude( double _alt );
156
157     void _setLongitude( double longitude );
158     void _setLatitude ( double latitude );
159
160     double _getLongitude() const;
161     double _getLatitude () const;
162
163     double _getBearing() const;
164     double _getElevation() const;
165     double _getRdot() const;
166     double _getH_offset() const;
167     double _getV_offset() const;
168     double _getX_shift() const;
169     double _getY_shift() const;
170     double _getRotation() const;
171
172     double rho;
173     double T;                             // temperature, degs farenheit
174     double p;                             // pressure lbs/sq ft
175     double a;                             // speed of sound at altitude (ft/s)
176     double Mach;                          // Mach number
177
178     static const double e;
179     static const double lbs_to_slugs;
180
181     inline double _getRange() { return range; };
182     osg::Node* load3DModel(const string& fg_root,
183                             const string &path,
184                             SGPropertyNode *prop_root,
185                             double sim_time_sec);
186
187     static bool _isNight();
188 };
189
190 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
191     manager = mgr;
192     props = p;
193 }
194
195 inline void FGAIBase::setPath(const char* model ) {
196     model_path.append(model);
197 }
198
199 inline void FGAIBase::setSpeed( double speed_KTAS ) {
200     speed = tgt_speed = speed_KTAS;
201 }
202
203 inline void FGAIBase::setRadius( double radius ) {
204     turn_radius_ft = radius;
205 }
206
207 inline void FGAIBase::setHeading( double heading ) {
208     hdg = tgt_heading = heading;
209 }
210
211 inline void FGAIBase::setAltitude( double alt_ft ) {
212     altitude_ft = tgt_altitude_ft = alt_ft;
213     pos.setElevationFt(altitude_ft);
214 }
215
216 inline void FGAIBase::setBank( double bank ) {
217     roll = tgt_roll = bank;
218     no_roll = false;
219 }
220
221 inline void FGAIBase::setPitch( double newpitch ) {
222     pitch = tgt_pitch = newpitch;
223 }
224
225 inline void FGAIBase::setLongitude( double longitude ) {
226     pos.setLongitudeDeg( longitude );
227 }
228 inline void FGAIBase::setLatitude ( double latitude ) {
229     pos.setLatitudeDeg( latitude );
230 }
231
232 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
233 inline bool FGAIBase::getDie() { return delete_me; }
234
235 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
236
237
238
239 #endif  // _FG_AIBASE_HXX
240