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