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