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