]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Merge branch 'maint2' into next
[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         bool               wind;
57         bool               first_time;
58         double             cd;
59         double             weight;
60         double             contents;
61         bool               aero_stabilised;
62         int                id;
63         bool               no_roll;
64         bool               serviceable;
65         bool               collision;
66         bool               impact;
67         string             impact_report;
68         double             fuse_range;
69         string             submodel;
70         int                sub_id;
71         bool               ext_force;
72         string             force_path;
73     }   submodel;
74
75     typedef struct {
76         double     lat;
77         double     lon;
78         double     alt;
79         double     roll;
80         double     azimuth;
81         double     elevation;
82         double     speed;
83         double     wind_from_east;
84         double     wind_from_north;
85         double     speed_down_fps;
86         double     speed_east_fps;
87         double     speed_north_fps;
88         double     total_speed_down;
89         double     total_speed_east;
90         double     total_speed_north;
91         double     mass;
92         int        id;
93         bool       no_roll;
94     }   IC_struct;
95
96     FGSubmodelMgr();
97     ~FGSubmodelMgr();
98
99     void load();
100     void init();
101     void postinit();
102     void bind();
103     void unbind();
104     void update(double dt);
105     void updatelat(double lat);
106
107 private:
108
109     typedef vector <submodel*> submodel_vector_type;
110     typedef submodel_vector_type::iterator submodel_vector_iterator;
111
112     submodel_vector_type       submodels;
113     submodel_vector_type       subsubmodels;
114     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
115
116     float trans[3][3];
117     float in[3];
118     float out[3];
119
120     //double Rx, Ry, Rz;
121     //double Sx, Sy, Sz;
122     //double Tx, Ty, Tz;
123
124     float cosRx, sinRx;
125     float cosRy, sinRy;
126     float cosRz, sinRz;
127
128     int index;
129
130     double ft_per_deg_longitude;
131     double ft_per_deg_latitude;
132
133     double x_offset, y_offset, z_offset;
134     double pitch_offset, yaw_offset;
135
136     double _parent_lat;
137     double _parent_lon;
138     double _parent_elev;
139     double _parent_hdg;
140     double _parent_pitch;
141     double _parent_roll;
142     double _parent_speed;
143
144     static const double lbs_to_slugs; //conversion factor
145
146     double contrail_altitude;
147
148     bool _impact;
149     bool _hit;
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
172     FGAIManager* ai;
173     IC_struct  IC;
174
175     // A list of pointers to AI objects
176     typedef list <osg::ref_ptr<FGAIBase> > sm_list_type;
177     typedef sm_list_type::iterator sm_list_iterator;
178     typedef sm_list_type::const_iterator sm_list_const_iterator;
179
180     sm_list_type sm_list;
181
182
183     void loadAI();
184     void loadSubmodels();
185     void setData(int id, string& path, bool serviceable);
186     void setSubData(int id, string& path, bool serviceable);
187     void valueChanged (SGPropertyNode *);
188     void transform(submodel *);
189
190     bool release(submodel *, double dt);
191
192     double getRange(double lat, double lon, double lat2, double lon2) const;
193
194     int _count;
195
196 };
197
198 #endif // __SYSTEMS_SUBMODEL_HXX