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