]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
submodel: Add random error for azimuth and elevation
[flightgear.git] / src / AIModel / submodel.hxx
1 // submodel.hxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 //
4 // This file is in the Public Domain and comes with no warranty.
5
6
7 #ifndef __SYSTEMS_SUBMODEL_HXX
8 #define __SYSTEMS_SUBMODEL_HXX 1
9
10 #ifndef __cplusplus
11 # error This library requires C++
12 #endif
13
14 #include <simgear/props/props.hxx>
15 #include <simgear/structure/subsystem_mgr.hxx>
16 #include <simgear/math/SGMath.hxx>
17
18 #include <Autopilot/inputvalue.hxx>
19
20 #include <vector>
21 #include <string>
22
23 class FGAIBase;
24 class FGAIManager;
25
26 class FGSubmodelMgr : public SGSubsystem, public SGPropertyChangeListener
27 {
28
29 public:
30
31     typedef struct {
32         SGPropertyNode_ptr trigger_node;
33         SGPropertyNode_ptr prop;
34         SGPropertyNode_ptr contents_node;
35         SGPropertyNode_ptr submodel_node;
36         SGPropertyNode_ptr speed_node;
37
38         std::string        name;
39         std::string        model;
40         double             speed;
41         bool               slaved;
42         bool               repeat;
43         double             delay;
44         double             timer;
45         int                count;
46         double             x_offset;
47         double             y_offset;
48         double             z_offset;
49         FGXMLAutopilot::InputValue_ptr yaw_offset;
50         FGXMLAutopilot::InputValue_ptr pitch_offset;
51         double             drag_area;
52         double             life;
53         double             buoyancy;
54         FGXMLAutopilot::InputValue_ptr azimuth_error;
55         FGXMLAutopilot::InputValue_ptr elevation_error;
56         FGXMLAutopilot::InputValue_ptr cd_randomness;
57         FGXMLAutopilot::InputValue_ptr life_randomness;
58         bool               wind;
59         bool               first_time;
60         double             cd;
61         double             weight;
62         double             mass;
63         double             contents;
64         bool               aero_stabilised;
65         int                id;
66         bool               no_roll;
67         bool               serviceable;
68         bool               random;
69         bool               collision;
70         bool               expiry;
71         bool               impact;
72         std::string        impact_report;
73         double             fuse_range;
74         std::string        submodel;
75         int                sub_id;
76         bool               force_stabilised;
77         bool               ext_force;
78         std::string        force_path;
79     }   submodel;
80
81     typedef struct {
82         double     lat;
83         double     lon;
84         double     alt;
85         double     roll;
86         double     azimuth;
87         double     elevation;
88         double     speed;
89         double     wind_from_east;
90         double     wind_from_north;
91         double     speed_down_fps;
92         double     speed_east_fps;
93         double     speed_north_fps;
94         double     total_speed_down;
95         double     total_speed_east;
96         double     total_speed_north;
97         double     mass;
98         int        id;
99         bool       no_roll;
100         int        parent_id;
101     }   IC_struct;
102
103     FGSubmodelMgr();
104     ~FGSubmodelMgr();
105
106     void load();
107     void init();
108     void postinit();
109     void bind();
110     void unbind();
111     void update(double dt);
112     void updatelat(double lat);
113
114 private:
115
116     typedef std::vector <submodel*> submodel_vector_type;
117     typedef submodel_vector_type::iterator submodel_vector_iterator;
118
119     submodel_vector_type       submodels;
120     submodel_vector_type       subsubmodels;
121     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
122
123     //double Rx, Ry, Rz;
124     //double Sx, Sy, Sz;
125     //double Tx, Ty, Tz;
126
127     float cosRx, sinRx;
128     float cosRy, sinRy;
129     float cosRz, sinRz;
130
131     int index;
132
133     double ft_per_deg_longitude;
134     double ft_per_deg_latitude;
135
136     double x_offset, y_offset, z_offset;
137     double pitch_offset, yaw_offset;
138
139     double _parent_lat;
140     double _parent_lon;
141     double _parent_elev;
142     double _parent_hdg;
143     double _parent_pitch;
144     double _parent_roll;
145     double _parent_speed;
146     //double _parent_ID;
147
148     double _x_offset;
149     double _y_offset;
150     double _z_offset;
151
152
153     static const double lbs_to_slugs; //conversion factor
154
155     double contrail_altitude;
156
157     bool _impact;
158     bool _hit;
159     bool _expiry;
160     bool _found_sub;
161
162     SGPropertyNode_ptr _serviceable_node;
163     SGPropertyNode_ptr _user_lat_node;
164     SGPropertyNode_ptr _user_lon_node;
165     SGPropertyNode_ptr _user_heading_node;
166     SGPropertyNode_ptr _user_alt_node;
167     SGPropertyNode_ptr _user_pitch_node;
168     SGPropertyNode_ptr _user_roll_node;
169     SGPropertyNode_ptr _user_yaw_node;
170     SGPropertyNode_ptr _user_alpha_node;
171     SGPropertyNode_ptr _user_speed_node;
172     SGPropertyNode_ptr _user_wind_from_east_node;
173     SGPropertyNode_ptr _user_wind_from_north_node;
174     SGPropertyNode_ptr _user_speed_down_fps_node;
175     SGPropertyNode_ptr _user_speed_east_fps_node;
176     SGPropertyNode_ptr _user_speed_north_fps_node;
177     SGPropertyNode_ptr _contrail_altitude_node;
178     SGPropertyNode_ptr _contrail_trigger;
179     SGPropertyNode_ptr _count_node;
180     SGPropertyNode_ptr _trigger_node;
181     SGPropertyNode_ptr props;
182     SGPropertyNode_ptr _model_added_node;
183     SGPropertyNode_ptr _path_node;
184     SGPropertyNode_ptr _selected_ac;
185
186     IC_struct  IC;
187     
188     /**
189      * Helper to retrieve the AI manager, if it currently exists
190      */
191     FGAIManager* aiManager();
192     
193     void loadAI();
194     void loadSubmodels();
195     void setData(int id, const std::string& path, bool serviceable, const std::string& property_path, submodel_vector_type& models);
196     void valueChanged (SGPropertyNode *);
197     void transform(submodel *);
198     void setParentNode(int parent_id);
199
200     bool release(submodel *, double dt);
201
202
203     int _count;
204
205     SGGeod userpos;
206     SGGeod offsetpos;
207     SGVec3d getCartOffsetPos() const;
208     void setOffsetPos();
209
210 };
211
212 #endif // __SYSTEMS_SUBMODEL_HXX