]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Merge branch 'next' into durk-atc
[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 <vector>
19 #include <string>
20
21 class FGAIBase;
22 class FGAIManager;
23
24 class FGSubmodelMgr : public SGSubsystem, public SGPropertyChangeListener
25 {
26
27 public:
28
29     typedef struct {
30         SGPropertyNode_ptr trigger_node;
31         SGPropertyNode_ptr prop;
32         SGPropertyNode_ptr contents_node;
33         SGPropertyNode_ptr submodel_node;
34         SGPropertyNode_ptr speed_node;
35
36         std::string        name;
37         std::string        model;
38         double             speed;
39         bool               slaved;
40         bool               repeat;
41         double             delay;
42         double             timer;
43         int                count;
44         double             x_offset;
45         double             y_offset;
46         double             z_offset;
47         double             yaw_offset;
48         double             pitch_offset;
49         double             drag_area;
50         double             life;
51         double             buoyancy;
52         double             randomness;
53         bool               wind;
54         bool               first_time;
55         double             cd;
56         double             weight;
57         double             mass;
58         double             contents;
59         bool               aero_stabilised;
60         int                id;
61         bool               no_roll;
62         bool               serviceable;
63         bool               random;
64         bool               collision;
65         bool               expiry;
66         bool               impact;
67         std::string        impact_report;
68         double             fuse_range;
69         std::string        submodel;
70         int                sub_id;
71         bool               force_stabilised;
72         bool               ext_force;
73         std::string        force_path;
74     }   submodel;
75
76     typedef struct {
77         double     lat;
78         double     lon;
79         double     alt;
80         double     roll;
81         double     azimuth;
82         double     elevation;
83         double     speed;
84         double     wind_from_east;
85         double     wind_from_north;
86         double     speed_down_fps;
87         double     speed_east_fps;
88         double     speed_north_fps;
89         double     total_speed_down;
90         double     total_speed_east;
91         double     total_speed_north;
92         double     mass;
93         int        id;
94         bool       no_roll;
95         int        parent_id;
96     }   IC_struct;
97
98     FGSubmodelMgr();
99     ~FGSubmodelMgr();
100
101     void load();
102     void init();
103     void postinit();
104     void bind();
105     void unbind();
106     void update(double dt);
107     void updatelat(double lat);
108
109 private:
110
111     typedef std::vector <submodel*> submodel_vector_type;
112     typedef submodel_vector_type::iterator submodel_vector_iterator;
113
114     submodel_vector_type       submodels;
115     submodel_vector_type       subsubmodels;
116     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
117
118     float trans[3][3];
119     float in[3];
120     float out[3];
121
122     //double Rx, Ry, Rz;
123     //double Sx, Sy, Sz;
124     //double Tx, Ty, Tz;
125
126     float cosRx, sinRx;
127     float cosRy, sinRy;
128     float cosRz, sinRz;
129
130     int index;
131
132     double ft_per_deg_longitude;
133     double ft_per_deg_latitude;
134
135     double x_offset, y_offset, z_offset;
136     double pitch_offset, yaw_offset;
137
138     double _parent_lat;
139     double _parent_lon;
140     double _parent_elev;
141     double _parent_hdg;
142     double _parent_pitch;
143     double _parent_roll;
144     double _parent_speed;
145     double _parent_ID;
146
147     double _x_offset;
148     double _y_offset;
149     double _z_offset;
150
151
152     static const double lbs_to_slugs; //conversion factor
153
154     double contrail_altitude;
155
156     bool _impact;
157     bool _hit;
158     bool _expiry;
159     bool _found_sub;
160
161     SGPropertyNode_ptr _serviceable_node;
162     SGPropertyNode_ptr _user_lat_node;
163     SGPropertyNode_ptr _user_lon_node;
164     SGPropertyNode_ptr _user_heading_node;
165     SGPropertyNode_ptr _user_alt_node;
166     SGPropertyNode_ptr _user_pitch_node;
167     SGPropertyNode_ptr _user_roll_node;
168     SGPropertyNode_ptr _user_yaw_node;
169     SGPropertyNode_ptr _user_alpha_node;
170     SGPropertyNode_ptr _user_speed_node;
171     SGPropertyNode_ptr _user_wind_from_east_node;
172     SGPropertyNode_ptr _user_wind_from_north_node;
173     SGPropertyNode_ptr _user_speed_down_fps_node;
174     SGPropertyNode_ptr _user_speed_east_fps_node;
175     SGPropertyNode_ptr _user_speed_north_fps_node;
176     SGPropertyNode_ptr _contrail_altitude_node;
177     SGPropertyNode_ptr _contrail_trigger;
178     SGPropertyNode_ptr _count_node;
179     SGPropertyNode_ptr _trigger_node;
180     SGPropertyNode_ptr props;
181     SGPropertyNode_ptr _model_added_node;
182     SGPropertyNode_ptr _path_node;
183     SGPropertyNode_ptr _selected_ac;
184
185     IC_struct  IC;
186     
187     /**
188      * Helper to retrieve the AI manager, if it currently exists
189      */
190     FGAIManager* aiManager();
191     
192     void loadAI();
193     void loadSubmodels();
194     void setData(int id, std::string& path, bool serviceable);
195     void setSubData(int id, std::string& path, bool serviceable);
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