]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Vivian Meazza:
[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    const char* m_type;
42    const char* m_class;
43    const char* path;
44    const char* 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 eda;                // used by ballistic objects
61    double life;               // life span in seconds
62    double buoyancy;           // acceleration in ft per sec2
63    double wind_from_east;     // in feet per second
64    double wind_from_north;    // in feet per second
65    double cd;                 // coefficient of drag
66    bool wind;                 // if true, model reacts to parent wind
67    double mass;               // in slugs
68 } FGAIModelEntity;
69
70
71 class FGAIBase {
72
73 public:
74
75     FGAIBase();
76     virtual ~FGAIBase();
77     virtual void update(double dt);
78     inline Point3D GetPos() { return(pos); }
79
80     enum object_type { otNull = 0, otAircraft, otShip, otBallistic,
81                        otRocket, otStorm, otThermal, 
82                        MAX_OBJECTS };   // Needs to be last!!!
83
84     virtual bool init();
85     virtual void bind();
86     virtual void unbind();
87
88     void setPath( const char* model );
89     void setSpeed( double speed_KTAS );
90     void setAltitude( double altitude_ft );
91     void setHeading( double heading );
92     void setLatitude( double latitude );
93     void setLongitude( double longitude );
94     void setBank( double bank );
95
96     void* getID();
97     void setDie( bool die );
98     bool getDie();
99
100 protected:
101
102     SGPropertyNode *props;
103     FGAIManager* manager;
104
105     // these describe the model's actual state
106     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
107     double hdg;         // True heading in degrees
108     double roll;        // degrees, left is negative
109     double pitch;       // degrees, nose-down is negative
110     double speed;       // knots true airspeed
111     double altitude;    // meters above sea level
112     double vs;          // vertical speed, feet per minute   
113
114     double ft_per_deg_lon;
115     double ft_per_deg_lat;
116
117     // these describe the model's desired state
118     double tgt_heading;  // target heading, degrees true
119     double tgt_altitude; // target altitude, *feet* above sea level
120     double tgt_speed;    // target speed, KTAS
121     double tgt_roll;
122     double tgt_pitch;
123     double tgt_yaw;
124     double tgt_vs;
125
126     // these describe radar information for the user
127     bool in_range;       // true if in range of the radar, otherwise false
128     double bearing;      // true bearing from user to this model
129     double elevation;    // elevation in degrees from user to this model
130     double range;        // range from user to this model, nm
131     double rdot;         // range rate, in knots
132     double horiz_offset; // look left/right from user to me, deg
133     double vert_offset;  // look up/down from user to me, deg
134     double x_shift;      // value used by radar display instrument
135     double y_shift;      // value used by radar display instrument
136     double rotation;     // value used by radar display instrument
137
138
139     string model_path;     //Path to the 3D model
140     ssgBranch * model;     //The 3D model object
141     SGModelPlacement aip;
142     bool delete_me;
143     bool invisible;
144     bool no_roll;
145     double life;
146     FGAIFlightPlan *fp;
147
148     void Transform();
149
150     double UpdateRadar(FGAIManager* manager);
151
152     string _type_str;
153     object_type _otype;
154     int index;
155
156 public:
157
158     object_type getType();
159     bool isa( object_type otype );
160
161     double _getVS_fps() const;
162     void _setVS_fps( double _vs );
163
164     double _getAltitude() const;
165     void _setAltitude( double _alt );
166
167     void _setLongitude( double longitude );
168     void _setLatitude ( double latitude );
169
170     double _getLongitude() const;
171     double _getLatitude () const;
172
173     double _getBearing() const;
174     double _getElevation() const;
175     double _getRdot() const;
176     double _getH_offset() const;
177     double _getV_offset() const;
178     double _getX_shift() const;
179     double _getY_shift() const;
180     double _getRotation() const;
181
182     double rho;
183     double T;                             // temperature, degs farenheit
184     double p;                             // pressure lbs/sq ft
185     static const double e;
186     static const double lbs_to_slugs;
187
188     int _getID() const;
189
190     inline double _getRange() { return range; };
191
192     static bool _isNight();
193 };
194
195
196 inline void FGAIBase::setPath( const char* model ) {
197   model_path.append(model);
198 }
199
200 inline void FGAIBase::setSpeed( double speed_KTAS ) {
201   speed = tgt_speed = speed_KTAS;
202 }
203
204 inline void FGAIBase::setHeading( double heading ) {
205   hdg = tgt_heading = heading;
206 }
207
208 inline void FGAIBase::setAltitude( double altitude_ft ) {
209     altitude = tgt_altitude = altitude_ft;
210     pos.setelev(altitude * SG_FEET_TO_METER);
211 }
212
213 inline void FGAIBase::setBank( double bank ) {
214   roll = tgt_roll = bank;
215   no_roll = false;
216 }
217
218 inline void FGAIBase::setLongitude( double longitude ) {
219     pos.setlon( longitude );
220 }
221 inline void FGAIBase::setLatitude ( double latitude ) {
222     pos.setlat( latitude );
223 }
224
225 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
226 inline bool FGAIBase::getDie() { return delete_me; }
227
228 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
229
230 inline void* FGAIBase::getID() { return this; }
231
232 #endif  // _FG_AIBASE_HXX
233