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