]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Vivian MEAZZA:
[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 SG_USING_STD(vector);
23 SG_USING_STD(string);
24 SG_USING_STD(list);
25
26 class FGAIBase;
27
28 class FGSubmodelMgr : public SGSubsystem
29 {
30
31 public:
32
33     typedef struct
34     {
35         SGPropertyNode_ptr trigger_node;
36         SGPropertyNode_ptr prop;
37         SGPropertyNode_ptr contents_node;
38         SGPropertyNode_ptr submodel_node;
39         SGPropertyNode_ptr speed_node;
40
41         string             name;
42         string             model;
43         double             speed;
44         bool               slaved;
45         bool               repeat;
46         double             delay;
47         double             timer;
48         int                count;
49         double             x_offset;
50         double             y_offset;
51         double             z_offset;
52         double             yaw_offset;
53         double             pitch_offset;
54         double             drag_area;
55         double             life;
56         double             buoyancy;
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               collision;
67         bool               impact;
68         string             impact_report;
69         double             fuse_range;
70         string             submodel;
71         int                sub_id;
72     }
73     submodel;
74
75     typedef struct
76     {
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     }
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 vector <submodel*> submodel_vector_type;
112     typedef submodel_vector_type::const_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
146     static const double lbs_to_slugs; //conversion factor
147
148     double contrail_altitude;
149
150     bool _impact;
151     bool _hit;
152
153     SGPropertyNode_ptr _serviceable_node;
154     SGPropertyNode_ptr _user_lat_node;
155     SGPropertyNode_ptr _user_lon_node;
156     SGPropertyNode_ptr _user_heading_node;
157     SGPropertyNode_ptr _user_alt_node;
158     SGPropertyNode_ptr _user_pitch_node;
159     SGPropertyNode_ptr _user_roll_node;
160     SGPropertyNode_ptr _user_yaw_node;
161     SGPropertyNode_ptr _user_alpha_node;
162     SGPropertyNode_ptr _user_speed_node;
163     SGPropertyNode_ptr _user_wind_from_east_node;
164     SGPropertyNode_ptr _user_wind_from_north_node;
165     SGPropertyNode_ptr _user_speed_down_fps_node;
166     SGPropertyNode_ptr _user_speed_east_fps_node;
167     SGPropertyNode_ptr _user_speed_north_fps_node;
168     SGPropertyNode_ptr _contrail_altitude_node;
169     SGPropertyNode_ptr _contrail_trigger;
170     SGPropertyNode_ptr _count_node;
171     SGPropertyNode_ptr _trigger_node;
172     SGPropertyNode_ptr props;
173
174     FGAIManager* ai;
175     IC_struct  IC;
176
177     // A list of pointers to AI objects
178     typedef list <SGSharedPtr<FGAIBase> > sm_list_type;
179     typedef sm_list_type::iterator sm_list_iterator;
180     typedef sm_list_type::const_iterator sm_list_const_iterator;
181
182     sm_list_type sm_list;
183
184
185     void loadAI();
186     void loadSubmodels();
187     void setData(int id, string& path, bool serviceable);
188     void setSubData(int id, string& path, bool serviceable);
189     void valueChanged (SGPropertyNode *);
190     void transform(submodel_vector_iterator);
191
192     bool release(submodel_vector_iterator, double dt);
193
194     double getRange(double lat, double lon, double lat2, double lon2) const;
195
196     int _count;
197
198 };
199
200 #endif // __SYSTEMS_SUBMODEL_HXX