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