]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
ignore resets for now because every z/Z key press would trigger a call to NOAA. We...
[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 FGAIBase {
34
35 public:
36
37     FGAIBase();
38     virtual ~FGAIBase();
39     virtual void update(double dt);
40     inline Point3D GetPos() { return(pos); }
41
42     virtual bool init();
43     virtual void bind();
44     virtual void unbind();
45
46     void setPath( const char* model );
47     void setSpeed( double speed_KTAS );
48     void setAltitude( double altitude_ft );
49     void setHeading( double heading );
50     void setLatitude( double latitude );
51     void setLongitude( double longitude );
52
53     void setDie( bool die );
54     bool getDie();
55
56 protected:
57
58     SGPropertyNode *props;
59
60     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
61     double hdg;         // True heading in degrees
62     double roll;        // degrees, left is negative
63     double pitch;       // degrees, nose-down is negative
64     double speed;       // knots true airspeed
65     double altitude;    // meters above sea level
66     double vs;           // vertical speed, feet per minute   
67
68     double tgt_heading;  // target heading, degrees true
69     double tgt_altitude; // target altitude, *feet* above sea level
70     double tgt_speed;    // target speed, KTAS
71     double tgt_roll;
72     double tgt_pitch;
73     double tgt_yaw;
74     double tgt_vs;
75
76
77     string model_path;     //Path to the 3D model
78     SGModelPlacement aip;
79     bool delete_me;
80
81     void Transform();
82
83     static FGAIBase *_self;
84     const char *_type_str;
85
86 public:
87
88     static double _getVS_fps();
89     static void _setVS_fps( double _vs );
90
91     static double _getAltitude();
92     static void _setAltitude( double _alt );
93
94     static void _setLongitude( double longitude );
95     static void _setLatitude ( double latitude );
96
97     static double _getLongitude();
98     static double _getLatitude ();
99
100     static bool _isNight();
101 };
102
103
104 inline void FGAIBase::setPath( const char* model ) {
105   model_path.append(model);
106 }
107
108 inline void FGAIBase::setSpeed( double speed_KTAS ) {
109   speed = tgt_speed = speed_KTAS;
110 }
111
112 inline void FGAIBase::setHeading( double heading ) {
113   hdg = tgt_heading = heading;
114 }
115
116 inline void FGAIBase::setAltitude( double altitude_ft ) {
117     altitude = tgt_altitude = altitude_ft;
118     pos.setelev(altitude * SG_FEET_TO_METER);
119 }
120
121 inline void FGAIBase::setLongitude( double longitude ) {
122     pos.setlon( longitude );
123 }
124 inline void FGAIBase::setLatitude ( double latitude ) {
125     pos.setlat( latitude );
126 }
127
128 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
129 inline bool FGAIBase::getDie() { return delete_me; }
130
131 inline void FGAIBase::_setLongitude( double longitude ) {
132     _self->pos.setlon(longitude);
133 }
134 inline void FGAIBase::_setLatitude ( double latitude )  {
135     _self->pos.setlat(latitude);
136 }
137
138 inline double FGAIBase::_getLongitude() { return _self->pos.lon(); }
139 inline double FGAIBase::_getLatitude () { return _self->pos.lat(); }
140
141 inline double FGAIBase::_getVS_fps() { return _self->vs*60.0; }
142 inline void FGAIBase::_setVS_fps( double _vs ) { _self->vs = _vs/60.0; }
143
144 inline double FGAIBase::_getAltitude() {
145     return _self->altitude * SG_METER_TO_FEET;
146 }
147 inline void FGAIBase::_setAltitude( double _alt ) {
148     _self->setAltitude( _alt );
149 }
150
151 inline bool FGAIBase::_isNight() {
152     return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
153 }
154
155 #endif  // _FG_AIBASE_HXX
156