]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
- Added ultra-light traffic is now a separate traffic class that can have its
[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         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     }   submodel;
72
73     typedef struct {
74         double     lat;
75         double     lon;
76         double     alt;
77         double     roll;
78         double     azimuth;
79         double     elevation;
80         double     speed;
81         double     wind_from_east;
82         double     wind_from_north;
83         double     speed_down_fps;
84         double     speed_east_fps;
85         double     speed_north_fps;
86         double     total_speed_down;
87         double     total_speed_east;
88         double     total_speed_north;
89         double     mass;
90         int        id;
91         bool       no_roll;
92     }   IC_struct;
93
94     FGSubmodelMgr();
95     ~FGSubmodelMgr();
96
97     void load();
98     void init();
99     void postinit();
100     void bind();
101     void unbind();
102     void update(double dt);
103     void updatelat(double lat);
104
105 private:
106
107     typedef vector <submodel*> submodel_vector_type;
108     typedef submodel_vector_type::iterator submodel_vector_iterator;
109
110     submodel_vector_type       submodels;
111     submodel_vector_type       subsubmodels;
112     submodel_vector_iterator   submodel_iterator, subsubmodel_iterator;
113
114     float trans[3][3];
115     float in[3];
116     float out[3];
117
118     double Rx, Ry, Rz;
119     double Sx, Sy, Sz;
120     double Tx, Ty, Tz;
121
122     float cosRx, sinRx;
123     float cosRy, sinRy;
124     float cosRz, sinRz;
125
126     int index;
127
128     double ft_per_deg_longitude;
129     double ft_per_deg_latitude;
130
131     double x_offset, y_offset, z_offset;
132     double pitch_offset, yaw_offset;
133
134     double _parent_lat;
135     double _parent_lon;
136     double _parent_elev;
137     double _parent_hdg;
138     double _parent_pitch;
139     double _parent_roll;
140     double _parent_speed;
141
142     static const double lbs_to_slugs; //conversion factor
143
144     double contrail_altitude;
145
146     bool _impact;
147     bool _hit;
148
149     SGPropertyNode_ptr _serviceable_node;
150     SGPropertyNode_ptr _user_lat_node;
151     SGPropertyNode_ptr _user_lon_node;
152     SGPropertyNode_ptr _user_heading_node;
153     SGPropertyNode_ptr _user_alt_node;
154     SGPropertyNode_ptr _user_pitch_node;
155     SGPropertyNode_ptr _user_roll_node;
156     SGPropertyNode_ptr _user_yaw_node;
157     SGPropertyNode_ptr _user_alpha_node;
158     SGPropertyNode_ptr _user_speed_node;
159     SGPropertyNode_ptr _user_wind_from_east_node;
160     SGPropertyNode_ptr _user_wind_from_north_node;
161     SGPropertyNode_ptr _user_speed_down_fps_node;
162     SGPropertyNode_ptr _user_speed_east_fps_node;
163     SGPropertyNode_ptr _user_speed_north_fps_node;
164     SGPropertyNode_ptr _contrail_altitude_node;
165     SGPropertyNode_ptr _contrail_trigger;
166     SGPropertyNode_ptr _count_node;
167     SGPropertyNode_ptr _trigger_node;
168     SGPropertyNode_ptr props;
169
170     FGAIManager* ai;
171     IC_struct  IC;
172
173     // A list of pointers to AI objects
174     typedef list <SGSharedPtr<FGAIBase> > sm_list_type;
175     typedef sm_list_type::iterator sm_list_iterator;
176     typedef sm_list_type::const_iterator sm_list_const_iterator;
177
178     sm_list_type sm_list;
179
180
181     void loadAI();
182     void loadSubmodels();
183     void setData(int id, string& path, bool serviceable);
184     void setSubData(int id, string& path, bool serviceable);
185     void valueChanged (SGPropertyNode *);
186     void transform(submodel *);
187
188     bool release(submodel *, double dt);
189
190     double getRange(double lat, double lon, double lat2, double lon2) const;
191
192     int _count;
193
194 };
195
196 #endif // __SYSTEMS_SUBMODEL_HXX