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