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