]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Small refactoring of the submodel patch from onox
[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         double             randomness;
55         bool               wind;
56         bool               first_time;
57         double             cd;
58         double             weight;
59         double             mass;
60         double             contents;
61         bool               aero_stabilised;
62         int                id;
63         bool               no_roll;
64         bool               serviceable;
65         bool               random;
66         bool               collision;
67         bool               expiry;
68         bool               impact;
69         std::string        impact_report;
70         double             fuse_range;
71         std::string        submodel;
72         int                sub_id;
73         bool               force_stabilised;
74         bool               ext_force;
75         std::string        force_path;
76     }   submodel;
77
78     typedef struct {
79         double     lat;
80         double     lon;
81         double     alt;
82         double     roll;
83         double     azimuth;
84         double     elevation;
85         double     speed;
86         double     wind_from_east;
87         double     wind_from_north;
88         double     speed_down_fps;
89         double     speed_east_fps;
90         double     speed_north_fps;
91         double     total_speed_down;
92         double     total_speed_east;
93         double     total_speed_north;
94         double     mass;
95         int        id;
96         bool       no_roll;
97         int        parent_id;
98     }   IC_struct;
99
100     FGSubmodelMgr();
101     ~FGSubmodelMgr();
102
103     void load();
104     void init();
105     void postinit();
106     void bind();
107     void unbind();
108     void update(double dt);
109     void updatelat(double lat);
110
111 private:
112
113     typedef std::vector <submodel*> submodel_vector_type;
114     typedef submodel_vector_type::iterator submodel_vector_iterator;
115
116     submodel_vector_type       submodels;
117     submodel_vector_type       subsubmodels;
118     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
119
120     //double Rx, Ry, Rz;
121     //double Sx, Sy, Sz;
122     //double Tx, Ty, Tz;
123
124     float cosRx, sinRx;
125     float cosRy, sinRy;
126     float cosRz, sinRz;
127
128     int index;
129
130     double ft_per_deg_longitude;
131     double ft_per_deg_latitude;
132
133     double x_offset, y_offset, z_offset;
134     double pitch_offset, yaw_offset;
135
136     double _parent_lat;
137     double _parent_lon;
138     double _parent_elev;
139     double _parent_hdg;
140     double _parent_pitch;
141     double _parent_roll;
142     double _parent_speed;
143     //double _parent_ID;
144
145     double _x_offset;
146     double _y_offset;
147     double _z_offset;
148
149
150     static const double lbs_to_slugs; //conversion factor
151
152     double contrail_altitude;
153
154     bool _impact;
155     bool _hit;
156     bool _expiry;
157     bool _found_sub;
158
159     SGPropertyNode_ptr _serviceable_node;
160     SGPropertyNode_ptr _user_lat_node;
161     SGPropertyNode_ptr _user_lon_node;
162     SGPropertyNode_ptr _user_heading_node;
163     SGPropertyNode_ptr _user_alt_node;
164     SGPropertyNode_ptr _user_pitch_node;
165     SGPropertyNode_ptr _user_roll_node;
166     SGPropertyNode_ptr _user_yaw_node;
167     SGPropertyNode_ptr _user_alpha_node;
168     SGPropertyNode_ptr _user_speed_node;
169     SGPropertyNode_ptr _user_wind_from_east_node;
170     SGPropertyNode_ptr _user_wind_from_north_node;
171     SGPropertyNode_ptr _user_speed_down_fps_node;
172     SGPropertyNode_ptr _user_speed_east_fps_node;
173     SGPropertyNode_ptr _user_speed_north_fps_node;
174     SGPropertyNode_ptr _contrail_altitude_node;
175     SGPropertyNode_ptr _contrail_trigger;
176     SGPropertyNode_ptr _count_node;
177     SGPropertyNode_ptr _trigger_node;
178     SGPropertyNode_ptr props;
179     SGPropertyNode_ptr _model_added_node;
180     SGPropertyNode_ptr _path_node;
181     SGPropertyNode_ptr _selected_ac;
182
183     IC_struct  IC;
184     
185     /**
186      * Helper to retrieve the AI manager, if it currently exists
187      */
188     FGAIManager* aiManager();
189     
190     void loadAI();
191     void loadSubmodels();
192     void setData(int id, const std::string& path, bool serviceable);
193     void setSubData(int id, const std::string& path, bool serviceable);
194     void valueChanged (SGPropertyNode *);
195     void transform(submodel *);
196     void setParentNode(int parent_id);
197
198     bool release(submodel *, double dt);
199
200
201     int _count;
202
203     SGGeod userpos;
204     SGGeod offsetpos;
205     SGVec3d getCartOffsetPos() const;
206     void setOffsetPos();
207
208 };
209
210 #endif // __SYSTEMS_SUBMODEL_HXX