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