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