]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
941ac87fab48ce684ca2f84551c8d262ad58fabd
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
22
23 #include <string>
24
25 #include <simgear/constants.h>
26 #include <simgear/math/point3d.hxx>
27 #include <simgear/scene/model/placement.hxx>
28
29 #include <Main/fg_props.hxx>
30
31 SG_USING_STD(string);
32
33 class FGAIManager;
34 class FGAIFlightPlan;
35
36
37 typedef struct {
38    string callsign;
39
40    // can be aircraft, ship, storm, thermal or ballistic
41    string m_type;
42    string m_class;
43    string path;
44    string flightplan;
45
46    FGAIFlightPlan *fp;
47
48    double repeat;             // in seconds
49    double latitude;           // used if no flightplan defined
50    double longitude;          // used if no flightplan defined
51    double altitude;           // used if no flightplan defined
52    double speed;              // used if no flightplan defined
53    double heading;            // used if no flightplan defined
54    double roll;               // used if no flightplan defined
55    double azimuth;            // used by ballistic objects
56    double elevation;          // used by ballistic objects
57    double rudder;             // used by ship objects
58    double strength;           // used by thermal objects
59    double diameter;           // used by thermal objects
60    double height_msl;         // used by thermal objects
61    double eda;                // used by ballistic objects
62    double life;               // life span in seconds
63    double buoyancy;           // acceleration in ft per sec2
64    double wind_from_east;     // in feet per second
65    double wind_from_north;    // in feet per second
66    double cd;                 // coefficient of drag
67    bool wind;                 // if true, model reacts to parent wind
68    double mass;               // in slugs
69    bool aero_stabilised;      // if true, ballistic object aligns with trajectory
70 } FGAIModelEntity;
71
72
73 class FGAIBase {
74
75 public:
76
77     FGAIBase();
78     virtual ~FGAIBase();
79     virtual void update(double dt);
80     inline Point3D GetPos() { return(pos); }
81
82     enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
83                        otRocket, otStorm, otThermal, 
84                        MAX_OBJECTS };   // Needs to be last!!!
85
86     virtual bool init();
87     virtual void bind();
88     virtual void unbind();
89
90     void setPath( const char* model );
91     void setSpeed( double speed_KTAS );
92     void setAltitude( double altitude_ft );
93     void setHeading( double heading );
94     void setLatitude( double latitude );
95     void setLongitude( double longitude );
96     void setBank( double bank );
97
98     void* getID();
99     void setDie( bool die );
100     bool getDie();
101
102 protected:
103
104     SGPropertyNode *props;
105     FGAIManager* manager;
106
107     // these describe the model's actual state
108     Point3D 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;    // meters above sea level
114     double vs;          // vertical speed, feet per minute   
115
116     double ft_per_deg_lon;
117     double ft_per_deg_lat;
118
119     // these describe the model's desired state
120     double tgt_heading;  // target heading, degrees true
121     double tgt_altitude; // target altitude, *feet* above sea level
122     double tgt_speed;    // target speed, KTAS
123     double tgt_roll;
124     double tgt_pitch;
125     double tgt_yaw;
126     double tgt_vs;
127
128     // these describe radar information for the user
129     bool in_range;       // true if in range of the radar, otherwise false
130     double bearing;      // true bearing from user to this model
131     double elevation;    // elevation in degrees from user to this model
132     double range;        // range from user to this model, nm
133     double rdot;         // range rate, in knots
134     double horiz_offset; // look left/right from user to me, deg
135     double vert_offset;  // look up/down from user to me, deg
136     double x_shift;      // value used by radar display instrument
137     double y_shift;      // value used by radar display instrument
138     double rotation;     // value used by radar display instrument
139
140
141     string model_path;     //Path to the 3D model
142     ssgBranch * model;     //The 3D model object
143     SGModelPlacement aip;
144     bool delete_me;
145     bool invisible;
146     bool no_roll;
147     double life;
148     FGAIFlightPlan *fp;
149
150     void Transform();
151
152     double UpdateRadar(FGAIManager* manager);
153
154     string _type_str;
155     object_type _otype;
156     int index;
157
158 public:
159
160     object_type getType();
161     bool isa( object_type otype );
162
163     double _getVS_fps() const;
164     void _setVS_fps( double _vs );
165
166     double _getAltitude() const;
167     void _setAltitude( double _alt );
168
169     void _setLongitude( double longitude );
170     void _setLatitude ( double latitude );
171
172     double _getLongitude() const;
173     double _getLatitude () const;
174
175     double _getBearing() const;
176     double _getElevation() const;
177     double _getRdot() const;
178     double _getH_offset() const;
179     double _getV_offset() const;
180     double _getX_shift() const;
181     double _getY_shift() const;
182     double _getRotation() const;
183
184     double rho;
185     double T;                             // temperature, degs farenheit
186     double p;                             // pressure lbs/sq ft
187         double a;                             // speed of sound at altitude (ft/s)
188         double Mach;                          // Mach number
189         
190     static const double e;
191     static const double lbs_to_slugs;
192
193     int _getID() const;
194
195     inline double _getRange() { return range; };
196
197     static bool _isNight();
198 };
199
200
201 inline void FGAIBase::setPath( const char* model ) {
202   model_path.append(model);
203 }
204
205 inline void FGAIBase::setSpeed( double speed_KTAS ) {
206   speed = tgt_speed = speed_KTAS;
207 }
208
209 inline void FGAIBase::setHeading( double heading ) {
210   hdg = tgt_heading = heading;
211 }
212
213 inline void FGAIBase::setAltitude( double altitude_ft ) {
214     altitude = tgt_altitude = altitude_ft;
215     pos.setelev(altitude * SG_FEET_TO_METER);
216 }
217
218 inline void FGAIBase::setBank( double bank ) {
219   roll = tgt_roll = bank;
220   no_roll = false;
221 }
222
223 inline void FGAIBase::setLongitude( double longitude ) {
224     pos.setlon( longitude );
225 }
226 inline void FGAIBase::setLatitude ( double latitude ) {
227     pos.setlat( latitude );
228 }
229
230 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
231 inline bool FGAIBase::getDie() { return delete_me; }
232
233 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
234
235 inline void* FGAIBase::getID() { return this; }
236
237 #endif  // _FG_AIBASE_HXX
238