]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Vivian MEAZZA:
[flightgear.git] / src / AIModel / AIBase.hxx
1 // FGAIBase.hxx - 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
22
23 #include <string>
24 #include <list>
25
26 #include <simgear/constants.h>
27 #include <simgear/math/SGMath.hxx>
28 #include <simgear/math/point3d.hxx>
29 #include <simgear/scene/model/placement.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/ssgSharedPtr.hxx>
32 #include <simgear/structure/SGReferenced.hxx>
33
34 #include <Main/fg_props.hxx>
35
36 SG_USING_STD(string);
37 SG_USING_STD(list);
38
39 class FGAIManager;
40 class FGAIFlightPlan;
41
42 class FGAIBase : public SGReferenced {
43
44 public:
45     enum object_type { otNull = 0, otAircraft, otShip, otCarrier, otBallistic,
46                        otRocket, otStorm, otThermal, otStatic, otMultiplayer,
47                        MAX_OBJECTS };   // Needs to be last!!!
48
49     FGAIBase(object_type ot);
50     virtual ~FGAIBase();
51     inline const Point3D& GetPos() const { return(pos); }
52
53     virtual void readFromScenario(SGPropertyNode* scFileNode);
54
55     virtual bool init();
56     virtual void update(double dt);
57     virtual void bind();
58     virtual void unbind();
59
60     void setManager(FGAIManager* mgr, SGPropertyNode* p);
61     void setPath( const char* model );
62     void setSpeed( double speed_KTAS );
63     void setAltitude( double altitude_ft );
64     void setHeading( double heading );
65     void setLatitude( double latitude );
66     void setLongitude( double longitude );
67     void setBank( double bank );
68     void setPitch( double newpitch );
69     void setRadius ( double radius );
70     void setXoffset( double x_offset );
71     void setYoffset( double y_offset );
72     void setZoffset( double z_offset );
73
74     int getID() const;
75
76     void setDie( bool die );
77     bool getDie();
78
79     SGVec3d getCartPosAt(const SGVec3d& off) const;
80
81 protected:
82
83     SGPropertyNode_ptr props;
84     FGAIManager* manager;
85
86     // these describe the model's actual state
87     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
88     double hdg;         // True heading in degrees
89     double roll;        // degrees, left is negative
90     double pitch;       // degrees, nose-down is negative
91     double speed;       // knots true airspeed
92     double altitude;    // meters above sea level
93     double vs;          // vertical speed, feet per minute  
94     double turn_radius_ft; // turn radius ft at 15 kts rudder angle 15 degrees
95
96     double ft_per_deg_lon;
97     double ft_per_deg_lat;
98
99     // these describe the model's desired state
100     double tgt_heading;  // target heading, degrees true
101     double tgt_altitude; // target altitude, *feet* above sea level
102     double tgt_speed;    // target speed, KTAS
103     double tgt_roll;
104     double tgt_pitch;
105     double tgt_yaw;
106     double tgt_vs;
107
108     // these describe radar information for the user
109     bool in_range;       // true if in range of the radar, otherwise false
110     double bearing;      // true bearing from user to this model
111     double elevation;    // elevation in degrees from user to this model
112     double range;        // range from user to this model, nm
113     double rdot;         // range rate, in knots
114     double horiz_offset; // look left/right from user to me, deg
115     double vert_offset;  // look up/down from user to me, deg
116     double x_shift;      // value used by radar display instrument
117     double y_shift;      // value used by radar display instrument
118     double rotation;     // value used by radar display instrument
119     double ht_diff;              // value used by radar display instrument
120
121     string model_path;     //Path to the 3D model
122     ssgSharedPtr<ssgBranch> model; //The 3D model object
123     SGModelPlacement aip;
124     bool delete_me;
125     bool invisible;
126     bool no_roll;
127     double life;
128     FGAIFlightPlan *fp;
129
130     void Transform();
131     void CalculateMach();
132     double UpdateRadar(FGAIManager* manager);
133
134     static int _newAIModelID();
135
136 private:
137     const int _refID;
138     object_type _otype;
139
140 public:
141
142     object_type getType();
143     virtual const char* getTypeString(void) const { return "null"; }
144     bool isa( object_type otype );
145
146     double _getVS_fps() const;
147     void _setVS_fps( double _vs );
148
149     double _getAltitude() const;
150     void _setAltitude( double _alt );
151
152     void _setLongitude( double longitude );
153     void _setLatitude ( double latitude );
154
155     double _getLongitude() const;
156     double _getLatitude () const;
157
158     double _getBearing() const;
159     double _getElevation() const;
160     double _getRdot() const;
161     double _getH_offset() const;
162     double _getV_offset() const;
163     double _getX_shift() const;
164     double _getY_shift() const;
165     double _getRotation() const;
166
167     double rho;
168     double T;                             // temperature, degs farenheit
169     double p;                             // pressure lbs/sq ft
170         double a;                             // speed of sound at altitude (ft/s)
171         double Mach;                          // Mach number
172         
173     static const double e;
174     static const double lbs_to_slugs;
175
176     inline double _getRange() { return range; };
177   ssgBranch * load3DModel(const string& fg_root, 
178                           const string &path,
179                           SGPropertyNode *prop_root, 
180                           double sim_time_sec);
181
182     static bool _isNight();
183 };
184
185 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
186   manager = mgr;
187   props = p;
188 }
189
190 inline void FGAIBase::setPath(const char* model ) {
191   model_path.append(model);
192 }
193
194 inline void FGAIBase::setSpeed( double speed_KTAS ) {
195   speed = tgt_speed = speed_KTAS;
196 }
197
198 inline void FGAIBase::setRadius( double radius ) {
199   turn_radius_ft = radius;
200 }
201
202 inline void FGAIBase::setHeading( double heading ) {
203   hdg = tgt_heading = heading;
204 }
205
206 inline void FGAIBase::setAltitude( double altitude_ft ) {
207     altitude = tgt_altitude = altitude_ft;
208     pos.setelev(altitude * SG_FEET_TO_METER);
209 }
210
211 inline void FGAIBase::setBank( double bank ) {
212   roll = tgt_roll = bank;
213   no_roll = false;
214 }
215
216 inline void FGAIBase::setPitch( double newpitch ) {
217   pitch = tgt_pitch = newpitch;
218 }
219
220 inline void FGAIBase::setLongitude( double longitude ) {
221     pos.setlon( longitude );
222 }
223 inline void FGAIBase::setLatitude ( double latitude ) {
224     pos.setlat( latitude );
225 }
226
227 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
228 inline bool FGAIBase::getDie() { return delete_me; }
229
230 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
231
232
233
234 #endif  // _FG_AIBASE_HXX
235