]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/submodel.hxx
Remove range criteria, add sub-submodels to any depth, and add expiry criteria
[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                       expiry;
67         bool               impact;
68         string             impact_report;
69         double             fuse_range;
70         string             submodel;
71         int                sub_id;
72         bool               force_stabilised;
73         bool               ext_force;
74         string             force_path;
75     }   submodel;
76
77     typedef struct {
78         double     lat;
79         double     lon;
80         double     alt;
81         double     roll;
82         double     azimuth;
83         double     elevation;
84         double     speed;
85         double     wind_from_east;
86         double     wind_from_north;
87         double     speed_down_fps;
88         double     speed_east_fps;
89         double     speed_north_fps;
90         double     total_speed_down;
91         double     total_speed_east;
92         double     total_speed_north;
93         double     mass;
94         int        id;
95         bool       no_roll;
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::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         bool _expiry;
153         bool _found_sub;
154
155     SGPropertyNode_ptr _serviceable_node;
156     SGPropertyNode_ptr _user_lat_node;
157     SGPropertyNode_ptr _user_lon_node;
158     SGPropertyNode_ptr _user_heading_node;
159     SGPropertyNode_ptr _user_alt_node;
160     SGPropertyNode_ptr _user_pitch_node;
161     SGPropertyNode_ptr _user_roll_node;
162     SGPropertyNode_ptr _user_yaw_node;
163     SGPropertyNode_ptr _user_alpha_node;
164     SGPropertyNode_ptr _user_speed_node;
165     SGPropertyNode_ptr _user_wind_from_east_node;
166     SGPropertyNode_ptr _user_wind_from_north_node;
167     SGPropertyNode_ptr _user_speed_down_fps_node;
168     SGPropertyNode_ptr _user_speed_east_fps_node;
169     SGPropertyNode_ptr _user_speed_north_fps_node;
170     SGPropertyNode_ptr _contrail_altitude_node;
171     SGPropertyNode_ptr _contrail_trigger;
172     SGPropertyNode_ptr _count_node;
173     SGPropertyNode_ptr _trigger_node;
174     SGPropertyNode_ptr props;
175
176     FGAIManager* ai;
177     IC_struct  IC;
178
179     // A list of pointers to AI objects
180     typedef list <SGSharedPtr<FGAIBase> > sm_list_type;
181     typedef sm_list_type::iterator sm_list_iterator;
182     typedef sm_list_type::const_iterator sm_list_const_iterator;
183
184     sm_list_type sm_list;
185
186
187     void loadAI();
188     void loadSubmodels();
189     void setData(int id, string& path, bool serviceable);
190     void setSubData(int id, string& path, bool serviceable);
191     void valueChanged (SGPropertyNode *);
192     void transform(submodel *);
193
194     bool release(submodel *, double dt);
195
196     double getRange(double lat, double lon, double lat2, double lon2) const;
197
198     int _count;
199
200 };
201
202 #endif // __SYSTEMS_SUBMODEL_HXX