]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Even more imlicit includes becoming explicit.
[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 <AIModel/AIBase.hxx>
17 #include <vector>
18 #include <string>
19
20 #include <Main/fg_props.hxx>
21
22 using std::vector;
23 using std::string;
24 using std::list;
25
26 class FGAIBase;
27
28 class FGSubmodelMgr : public SGSubsystem
29 {
30
31 public:
32
33     typedef struct {
34         SGPropertyNode_ptr trigger_node;
35         SGPropertyNode_ptr prop;
36         SGPropertyNode_ptr contents_node;
37         SGPropertyNode_ptr submodel_node;
38         SGPropertyNode_ptr speed_node;
39
40         string             name;
41         string             model;
42         double             speed;
43         bool               slaved;
44         bool               repeat;
45         double             delay;
46         double             timer;
47         int                count;
48         double             x_offset;
49         double             y_offset;
50         double             z_offset;
51         double             yaw_offset;
52         double             pitch_offset;
53         double             drag_area;
54         double             life;
55         double             buoyancy;
56                 double                     randomness;
57         bool               wind;
58         bool               first_time;
59         double             cd;
60         double             weight;
61         double             contents;
62         bool               aero_stabilised;
63         int                id;
64         bool               no_roll;
65         bool               serviceable;
66                 bool               random;
67         bool               collision;
68                 bool                       expiry;
69         bool               impact;
70         string             impact_report;
71         double             fuse_range;
72         string             submodel;
73         int                sub_id;
74         bool               force_stabilised;
75         bool               ext_force;
76         string             force_path;
77     }   submodel;
78
79     typedef struct {
80         double     lat;
81         double     lon;
82         double     alt;
83         double     roll;
84         double     azimuth;
85         double     elevation;
86         double     speed;
87         double     wind_from_east;
88         double     wind_from_north;
89         double     speed_down_fps;
90         double     speed_east_fps;
91         double     speed_north_fps;
92         double     total_speed_down;
93         double     total_speed_east;
94         double     total_speed_north;
95         double     mass;
96         int        id;
97         bool       no_roll;
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 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     float trans[3][3];
121     float in[3];
122     float out[3];
123
124     //double Rx, Ry, Rz;
125     //double Sx, Sy, Sz;
126     //double Tx, Ty, Tz;
127
128     float cosRx, sinRx;
129     float cosRy, sinRy;
130     float cosRz, sinRz;
131
132     int index;
133
134     double ft_per_deg_longitude;
135     double ft_per_deg_latitude;
136
137     double x_offset, y_offset, z_offset;
138     double pitch_offset, yaw_offset;
139
140     double _parent_lat;
141     double _parent_lon;
142     double _parent_elev;
143     double _parent_hdg;
144     double _parent_pitch;
145     double _parent_roll;
146     double _parent_speed;
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
182     FGAIManager* ai;
183     IC_struct  IC;
184
185     // A list of pointers to AI objects
186     typedef list <SGSharedPtr<FGAIBase> > sm_list_type;
187     typedef sm_list_type::iterator sm_list_iterator;
188     typedef sm_list_type::const_iterator sm_list_const_iterator;
189
190     sm_list_type sm_list;
191
192
193     void loadAI();
194     void loadSubmodels();
195     void setData(int id, string& path, bool serviceable);
196     void setSubData(int id, string& path, bool serviceable);
197     void valueChanged (SGPropertyNode *);
198     void transform(submodel *);
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