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