1 //// submodel.cxx - models a releasable submodel.
2 // Written by Dave Culp, started Aug 2004
3 // With major additions by Vivian Meaaza 2004 - 2007
5 // This file is in the Public Domain and comes with no warranty.
11 #include "submodel.hxx"
13 #include <simgear/structure/exception.hxx>
14 #include <simgear/misc/sg_path.hxx>
15 #include <simgear/math/sg_geodesy.hxx>
17 #include <Main/fg_props.hxx>
18 #include <Main/util.hxx>
22 #include "AIManager.hxx"
23 #include "AIBallistic.hxx"
26 const double FGSubmodelMgr::lbs_to_slugs = 0.031080950172;
28 FGSubmodelMgr::FGSubmodelMgr()
30 x_offset = y_offset = 0.0;
35 out[0] = out[1] = out[2] = 0;
37 contrail_altitude = 30000;
41 FGSubmodelMgr::~FGSubmodelMgr()
45 void FGSubmodelMgr::init()
49 _serviceable_node = fgGetNode("/sim/submodels/serviceable", true);
50 _serviceable_node->setBoolValue(true);
52 _user_lat_node = fgGetNode("/position/latitude-deg", true);
53 _user_lon_node = fgGetNode("/position/longitude-deg", true);
54 _user_alt_node = fgGetNode("/position/altitude-ft", true);
56 _user_heading_node = fgGetNode("/orientation/heading-deg", true);
57 _user_pitch_node = fgGetNode("/orientation/pitch-deg", true);
58 _user_roll_node = fgGetNode("/orientation/roll-deg", true);
59 _user_yaw_node = fgGetNode("/orientation/yaw-deg", true);
60 _user_alpha_node = fgGetNode("/orientation/alpha-deg", true);
62 _user_speed_node = fgGetNode("/velocities/uBody-fps", true);
64 _user_wind_from_east_node = fgGetNode("/environment/wind-from-east-fps", true);
65 _user_wind_from_north_node = fgGetNode("/environment/wind-from-north-fps", true);
67 _user_speed_down_fps_node = fgGetNode("/velocities/speed-down-fps", true);
68 _user_speed_east_fps_node = fgGetNode("/velocities/speed-east-fps", true);
69 _user_speed_north_fps_node = fgGetNode("/velocities/speed-north-fps", true);
71 _contrail_altitude_node = fgGetNode("/environment/params/contrail-altitude", true);
72 contrail_altitude = _contrail_altitude_node->getDoubleValue();
73 _contrail_trigger = fgGetNode("ai/submodels/contrails", true);
74 _contrail_trigger->setBoolValue(false);
76 ai = (FGAIManager*)globals->get_subsystem("ai_model");
81 void FGSubmodelMgr::postinit() {
82 // postinit, so that the AI list is populated
86 //TODO reload submodels if an MP ac joins
89 void FGSubmodelMgr::bind()
92 void FGSubmodelMgr::unbind()
94 submodel_iterator = submodels.begin();
95 while (submodel_iterator != submodels.end()) {
96 (*submodel_iterator)->prop->untie("count");
101 void FGSubmodelMgr::update(double dt)
103 if (!_serviceable_node->getBoolValue())
109 // check if the submodel hit an object or terrain
110 sm_list = ai->get_ai_list();
111 sm_list_iterator sm_list_itr = sm_list.begin();
112 sm_list_iterator end = sm_list.end();
114 for (; sm_list_itr != end; ++sm_list_itr) {
115 _impact = (*sm_list_itr)->_getImpactData();
116 _hit = (*sm_list_itr)->_getCollisionData();
117 int parent_subID = (*sm_list_itr)->_getSubID();
118 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! "
119 << _hit <<" parent_subID " << parent_subID);
120 if ( parent_subID == 0) // this entry in the list has no associated submodel
121 continue; // so we can continue
123 if (_impact || _hit) {
124 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodel: Impact " << _impact << " hit! " << _hit );
126 submodel_iterator = submodels.begin();
128 while (submodel_iterator != submodels.end()) {
129 int child_ID = (*submodel_iterator)->id;
130 //cout << "Impact: parent SubID " << parent_subID << " child_ID " << child_ID << endl;
132 if ( parent_subID == child_ID ) {
133 _parent_lat = (*sm_list_itr)->_getImpactLat();
134 _parent_lon = (*sm_list_itr)->_getImpactLon();
135 _parent_elev = (*sm_list_itr)->_getImpactElevFt();
136 _parent_hdg = (*sm_list_itr)->_getImpactHdg();
137 _parent_pitch = (*sm_list_itr)->_getImpactPitch();
138 _parent_roll = (*sm_list_itr)->_getImpactRoll();
139 _parent_speed = (*sm_list_itr)->_getImpactSpeed();
140 (*submodel_iterator)->first_time = true;
142 if (release(*submodel_iterator, dt))
143 (*sm_list_itr)->setDie(true);
151 _contrail_trigger->setBoolValue(_user_alt_node->getDoubleValue() > contrail_altitude);
154 bool in_range = true;
155 bool trigger = false;
158 submodel_iterator = submodels.begin();
159 while (submodel_iterator != submodels.end()) {
163 SG_LOG(SG_GENERAL, SG_DEBUG,
164 "Submodels: " << (*submodel_iterator)->id
165 << " name " << (*submodel_iterator)->name
166 << " in range " << in_range);
168 if ((*submodel_iterator)->trigger_node != 0) {
169 _trigger_node = (*submodel_iterator)->trigger_node;
170 trigger = _trigger_node->getBoolValue();
171 //cout << "trigger node found " << trigger << endl;
174 //cout << (*submodel_iterator)->name << "trigger node not found " << trigger << endl;
178 int id = (*submodel_iterator)->id;
179 string name = (*submodel_iterator)->name;
180 // don't release submodels from AI Objects if they are
181 // too far away to be seen. id 0 is not an AI model,
182 // so we can skip the whole process
183 sm_list_iterator sm_list_itr = sm_list.begin();
184 sm_list_iterator end = sm_list.end();
186 while (sm_list_itr != end) {
189 SG_LOG(SG_GENERAL, SG_DEBUG,
190 "Submodels: continuing: " << id << " name " << name );
196 int parent_id = (*submodel_iterator)->id;
198 if (parent_id == id) {
199 double parent_lat = (*sm_list_itr)->_getLatitude();
200 double parent_lon = (*sm_list_itr)->_getLongitude();
201 double own_lat = _user_lat_node->getDoubleValue();
202 double own_lon = _user_lon_node->getDoubleValue();
203 double range_nm = getRange(parent_lat, parent_lon, own_lat, own_lon);
204 // cout << "parent " << parent_id << ", "<< parent_lat << ", " << parent_lon << endl;
205 //cout << "own " << own_lat << ", " << own_lon << " range " << range_nm << endl;
208 SG_LOG(SG_GENERAL, SG_DEBUG,
209 "Submodels: skipping release: " << id);
217 SG_LOG(SG_GENERAL, SG_DEBUG,
218 "Submodels end: " << (*submodel_iterator)->id
219 << " name " << (*submodel_iterator)->name
220 << " count " << (*submodel_iterator)->count
221 << " in range " << in_range);
223 if ((*submodel_iterator)->count != 0 && in_range)
224 release(*submodel_iterator, dt);
227 (*submodel_iterator)->first_time = true;
233 bool FGSubmodelMgr::release(submodel *sm, double dt)
235 //cout << "release id " << sm->id << " name " << sm->name
236 //<< " first time " << sm->first_time << " repeat " << sm->repeat <<
239 // only run if first time or repeat is set to true
240 if (!sm->first_time && !sm->repeat) {
241 //cout<< "not first time " << sm->first_time<< " repeat " << sm->repeat <<endl;
247 if (sm->timer < sm->delay) {
248 //cout << "not yet: timer" << sm->timer << " delay " << sm->delay<< endl;
254 if (sm->first_time) {
256 sm->first_time = false;
259 transform(sm); // calculate submodel's initial conditions in world-coordinates
261 FGAIBallistic* ballist = new FGAIBallistic;
262 ballist->setPath(sm->model.c_str());
263 ballist->setLatitude(IC.lat);
264 ballist->setLongitude(IC.lon);
265 ballist->setAltitude(IC.alt);
266 ballist->setAzimuth(IC.azimuth);
267 ballist->setElevation(IC.elevation);
268 ballist->setRoll(IC.roll);
269 ballist->setSpeed(IC.speed / SG_KT_TO_FPS);
270 ballist->setWind_from_east(IC.wind_from_east);
271 ballist->setWind_from_north(IC.wind_from_north);
272 ballist->setMass(IC.mass);
273 ballist->setDragArea(sm->drag_area);
274 ballist->setLife(sm->life);
275 ballist->setBuoyancy(sm->buoyancy);
276 ballist->setWind(sm->wind);
277 ballist->setCd(sm->cd);
278 ballist->setStabilisation(sm->aero_stabilised);
279 ballist->setNoRoll(sm->no_roll);
280 ballist->setName(sm->name);
281 ballist->setCollision(sm->collision);
282 ballist->setImpact(sm->impact);
283 ballist->setImpactReportNode(sm->impact_report);
284 ballist->setFuseRange(sm->fuse_range);
285 ballist->setSubmodel(sm->submodel.c_str());
286 ballist->setSubID(sm->sub_id);
295 void FGSubmodelMgr::load()
297 SGPropertyNode *path = fgGetNode("/sim/submodels/path");
301 string Path = path->getStringValue();
302 bool Seviceable =_serviceable_node->getBoolValue();
303 setData(id, Path, Seviceable);
307 void FGSubmodelMgr::transform(submodel *sm)
309 // set initial conditions
310 if (sm->contents_node != 0) {
311 // get the weight of the contents (lbs) and convert to mass (slugs)
312 sm->contents = sm->contents_node->getDoubleValue();
313 IC.mass = (sm->weight + sm->contents) * lbs_to_slugs;
315 // set contents to 0 in the parent
316 sm->contents_node->setDoubleValue(0);
318 IC.mass = sm->weight * lbs_to_slugs;
321 // cout << "mass " << IC.mass << endl;
323 if (sm->speed_node != 0)
324 sm->speed = sm->speed_node->getDoubleValue();
327 //int sub_id = (*submodel)->sub_id;
328 string name = sm->name;
330 //cout << " name " << name << " id " << id << " sub id" << sub_id << endl;
332 if (_impact || _hit) {
333 // set the data for a submodel tied to a submodel
335 //cout << "Submodels: release sub sub " << _count<< endl;
336 //cout << " id " << sm->id
337 // << " lat " << _parent_lat
338 // << " lon " << _parent_lon
339 // << " elev " << _parent_elev
340 // << " name " << sm->name
343 IC.lat = _parent_lat;
344 IC.lon = _parent_lon;
345 IC.alt = _parent_elev;
346 IC.roll = _parent_roll; // rotation about x axis
347 IC.elevation = _parent_pitch; // rotation about y axis
348 IC.azimuth = _parent_hdg; // rotation about z axis
349 IC.speed = _parent_speed;
350 IC.speed_down_fps = 0;
351 IC.speed_east_fps = 0;
352 IC.speed_north_fps = 0;
354 } else if (id == 0) {
355 //set the data for a submodel tied to the main model
356 /*cout << "Submodels: release main sub " << endl;
357 cout << " name " << sm->name
360 IC.lat = _user_lat_node->getDoubleValue();
361 IC.lon = _user_lon_node->getDoubleValue();
362 IC.alt = _user_alt_node->getDoubleValue();
363 IC.roll = _user_roll_node->getDoubleValue(); // rotation about x axis
364 IC.elevation = _user_pitch_node->getDoubleValue(); // rotation about y axis
365 IC.azimuth = _user_heading_node->getDoubleValue(); // rotation about z axis
366 IC.speed = _user_speed_node->getDoubleValue();
367 IC.speed_down_fps = _user_speed_down_fps_node->getDoubleValue();
368 IC.speed_east_fps = _user_speed_east_fps_node->getDoubleValue();
369 IC.speed_north_fps = _user_speed_north_fps_node->getDoubleValue();
372 // set the data for a submodel tied to an AI Object
373 sm_list_iterator sm_list_itr = sm_list.begin();
374 sm_list_iterator end = sm_list.end();
376 while (sm_list_itr != end) {
377 int parent_id = (*sm_list_itr)->getID();
379 if (id != parent_id) {
384 //cout << "found id " << id << endl;
385 IC.lat = (*sm_list_itr)->_getLatitude();
386 IC.lon = (*sm_list_itr)->_getLongitude();
387 IC.alt = (*sm_list_itr)->_getAltitude();
388 IC.roll = (*sm_list_itr)->_getRoll();
389 IC.elevation = (*sm_list_itr)->_getPitch();
390 IC.azimuth = (*sm_list_itr)->_getHeading();
391 IC.alt = (*sm_list_itr)->_getAltitude();
392 IC.speed = (*sm_list_itr)->_getSpeed() * SG_KT_TO_FPS;
393 IC.speed_down_fps = -(*sm_list_itr)->_getVS_fps();
394 IC.speed_east_fps = (*sm_list_itr)->_get_speed_east_fps();
395 IC.speed_north_fps = (*sm_list_itr)->_get_speed_north_fps();
401 /*cout << "heading " << IC.azimuth << endl ;
402 cout << "speed down " << IC.speed_down_fps << endl ;
403 cout << "speed east " << IC.speed_east_fps << endl ;
404 cout << "speed north " << IC.speed_north_fps << endl ;
405 cout << "parent speed fps in" << IC.speed << "sm speed in " << sm->speed << endl ;*/
407 IC.wind_from_east = _user_wind_from_east_node->getDoubleValue();
408 IC.wind_from_north = _user_wind_from_north_node->getDoubleValue();
410 in[0] = sm->x_offset;
411 in[1] = sm->y_offset;
412 in[2] = sm->z_offset;
414 // pre-process the trig functions
415 cosRx = cos(-IC.roll * SG_DEGREES_TO_RADIANS);
416 sinRx = sin(-IC.roll * SG_DEGREES_TO_RADIANS);
417 cosRy = cos(-IC.elevation * SG_DEGREES_TO_RADIANS);
418 sinRy = sin(-IC.elevation * SG_DEGREES_TO_RADIANS);
419 cosRz = cos(IC.azimuth * SG_DEGREES_TO_RADIANS);
420 sinRz = sin(IC.azimuth * SG_DEGREES_TO_RADIANS);
422 // set up the transform matrix
423 trans[0][0] = cosRy * cosRz;
424 trans[0][1] = -1 * cosRx * sinRz + sinRx * sinRy * cosRz ;
425 trans[0][2] = sinRx * sinRz + cosRx * sinRy * cosRz;
427 trans[1][0] = cosRy * sinRz;
428 trans[1][1] = cosRx * cosRz + sinRx * sinRy * sinRz;
429 trans[1][2] = -1 * sinRx * cosRx + cosRx * sinRy * sinRz;
431 trans[2][0] = -1 * sinRy;
432 trans[2][1] = sinRx * cosRy;
433 trans[2][2] = cosRx * cosRy;
436 // multiply the input and transform matrices
437 out[0] = in[0] * trans[0][0] + in[1] * trans[0][1] + in[2] * trans[0][2];
438 out[1] = in[0] * trans[1][0] + in[1] * trans[1][1] + in[2] * trans[1][2];
439 out[2] = in[0] * trans[2][0] + in[1] * trans[2][1] + in[2] * trans[2][2];
441 // convert ft to degrees of latitude
442 out[0] = out[0] / (366468.96 - 3717.12 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
444 // convert ft to degrees of longitude
445 out[1] = out[1] / (365228.16 * cos(IC.lat * SG_DEGREES_TO_RADIANS));
447 // set submodel initial position
452 // get aircraft velocity vector angles in XZ and XY planes
453 //double alpha = _user_alpha_node->getDoubleValue();
454 //double velXZ = IC.elevation - alpha * cosRx;
455 //double velXY = IC.azimuth - (IC.elevation - alpha * sinRx);
457 // Get submodel initial velocity vector angles in XZ and XY planes.
458 // This needs to be fixed. This vector should be added to aircraft's vector.
459 IC.elevation += (sm->yaw_offset * sinRx) + (sm->pitch_offset * cosRx);
460 IC.azimuth += (sm->yaw_offset * cosRx) - (sm->pitch_offset * sinRx);
462 // calculate the total speed north
463 IC.total_speed_north = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
464 * cos(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_north_fps;
466 // calculate the total speed east
467 IC.total_speed_east = sm->speed * cos(IC.elevation * SG_DEGREES_TO_RADIANS)
468 * sin(IC.azimuth * SG_DEGREES_TO_RADIANS) + IC.speed_east_fps;
470 // calculate the total speed down
471 IC.total_speed_down = sm->speed * -sin(IC.elevation * SG_DEGREES_TO_RADIANS)
474 // re-calculate speed, elevation and azimuth
475 IC.speed = sqrt(IC.total_speed_north * IC.total_speed_north
476 + IC.total_speed_east * IC.total_speed_east
477 + IC.total_speed_down * IC.total_speed_down);
479 // if speeds are low this calculation can become unreliable
481 IC.azimuth = atan2(IC.total_speed_east , IC.total_speed_north) * SG_RADIANS_TO_DEGREES;
482 // cout << "azimuth1 " << IC.azimuth<<endl;
484 // rationalise the output
487 else if (IC.azimuth >= 360)
489 // cout << "azimuth2 " << IC.azimuth<<endl;
491 IC.elevation = -atan(IC.total_speed_down / sqrt(IC.total_speed_north
492 * IC.total_speed_north + IC.total_speed_east * IC.total_speed_east))
493 * SG_RADIANS_TO_DEGREES;
497 void FGSubmodelMgr::updatelat(double lat)
499 ft_per_deg_latitude = 366468.96 - 3717.12 * cos(lat / SG_RADIANS_TO_DEGREES);
500 ft_per_deg_longitude = 365228.16 * cos(lat / SG_RADIANS_TO_DEGREES);
503 void FGSubmodelMgr::loadAI()
505 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading AI submodels ");
507 sm_list = ai->get_ai_list();
509 if (sm_list.empty()) {
510 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Unable to read AI submodel list");
514 sm_list_iterator sm_list_itr = sm_list.begin();
515 sm_list_iterator end = sm_list.end();
517 while (sm_list_itr != end) {
518 string path = (*sm_list_itr)->_getSMPath();
525 int id = (*sm_list_itr)->getID();
526 bool serviceable = (*sm_list_itr)->_getServiceable();
527 setData(id, path, serviceable);
533 double FGSubmodelMgr::getRange(double lat, double lon, double lat2, double lon2) const
535 double course, distance, az2;
537 //calculate the bearing and range of the second pos from the first
538 geo_inverse_wgs_84(lat, lon, lat2, lon2, &course, &az2, &distance);
539 distance *= SG_METER_TO_NM;
543 void FGSubmodelMgr::setData(int id, string& path, bool serviceable)
547 SGPath config(globals->get_fg_root());
549 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: path " << path);
551 SG_LOG(SG_GENERAL, SG_DEBUG,
552 "Submodels: Trying to read AI submodels file: " << config.str());
553 readProperties(config.str(), &root);
554 } catch (const sg_exception &e) {
555 SG_LOG(SG_GENERAL, SG_DEBUG,
556 "Submodels: Unable to read AI submodels file: " << config.str());
560 vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
561 vector<SGPropertyNode_ptr>::iterator it = children.begin();
562 vector<SGPropertyNode_ptr>::iterator end = children.end();
564 for (int i = 0; it != end; ++it, i++) {
565 //cout << "Reading AI submodel " << (*it)->getPath() << endl;
566 submodel* sm = new submodel;
567 SGPropertyNode * entry_node = *it;
568 sm->name = entry_node->getStringValue("name", "none_defined");
569 sm->model = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
570 sm->speed = entry_node->getDoubleValue("speed", 2329.4);
571 sm->repeat = entry_node->getBoolValue("repeat", false);
572 sm->delay = entry_node->getDoubleValue("delay", 0.25);
573 sm->count = entry_node->getIntValue("count", 1);
574 sm->slaved = entry_node->getBoolValue("slaved", false);
575 sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0);
576 sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0);
577 sm->z_offset = entry_node->getDoubleValue("z-offset", 0.0);
578 sm->yaw_offset = entry_node->getDoubleValue("yaw-offset", 0.0);
579 sm->pitch_offset = entry_node->getDoubleValue("pitch-offset", 0.0);
580 sm->drag_area = entry_node->getDoubleValue("eda", 0.034);
581 sm->life = entry_node->getDoubleValue("life", 900.0);
582 sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
583 sm->wind = entry_node->getBoolValue("wind", false);
584 sm->cd = entry_node->getDoubleValue("cd", 0.193);
585 sm->weight = entry_node->getDoubleValue("weight", 0.25);
586 sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
587 sm->no_roll = entry_node->getBoolValue("no-roll", false);
588 sm->collision = entry_node->getBoolValue("collision", false);
589 sm->impact = entry_node->getBoolValue("impact", false);
590 sm->impact_report = entry_node->getStringValue("impact-reports");
591 sm->fuse_range = entry_node->getDoubleValue("fuse-range", 0.0);
592 sm->contents_node = fgGetNode(entry_node->getStringValue("contents", "none"), false);
593 sm->speed_node = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
594 sm->submodel = entry_node->getStringValue("submodel-path", "");
596 //cout << "sm->contents_node " << sm->contents_node << endl;
597 if (sm->contents_node != 0)
598 sm->contents = sm->contents_node->getDoubleValue();
600 const char *trigger_path = entry_node->getStringValue("trigger", 0);
602 sm->trigger_node = fgGetNode(trigger_path, true);
603 sm->trigger_node->setBoolValue(sm->trigger_node->getBoolValue());
605 sm->trigger_node = 0;
608 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: trigger " << sm->trigger_node->getBoolValue() );
609 if (sm->speed_node != 0)
610 sm->speed = sm->speed_node->getDoubleValue();
612 sm->timer = sm->delay;
614 sm->first_time = false;
615 sm->serviceable = serviceable;
618 sm->prop = fgGetNode("/ai/submodels/submodel", index, true);
619 sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
620 sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
621 sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
622 sm->prop->tie("sub-id", SGRawValuePointer<int>(&(sm->sub_id)));
624 sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
625 string name = sm->name;
626 sm->prop->setStringValue("name", name.c_str());
628 string submodel = sm->submodel;
629 sm->prop->setStringValue("submodel", submodel.c_str());
630 //cout << " set submodel path " << submodel << endl;
632 if (sm->contents_node != 0)
633 sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
636 submodels.push_back(sm);
640 void FGSubmodelMgr::setSubData(int id, string& path, bool serviceable)
644 SGPath config(globals->get_fg_root());
646 SG_LOG(SG_GENERAL, SG_DEBUG,
647 "Submodels: path " << path);
649 SG_LOG(SG_GENERAL, SG_DEBUG,
650 "Submodels: Trying to read AI submodels file: " << config.str());
651 readProperties(config.str(), &root);
653 } catch (const sg_exception &e) {
654 SG_LOG(SG_GENERAL, SG_DEBUG,
655 "Submodels: Unable to read AI submodels file: " << config.str());
659 vector<SGPropertyNode_ptr> children = root.getChildren("submodel");
660 vector<SGPropertyNode_ptr>::iterator it = children.begin();
661 vector<SGPropertyNode_ptr>::iterator end = children.end();
663 for (int i = 0; it != end; ++it, i++) {
664 //cout << "Reading AI submodel " << (*it)->getPath() << endl;
665 submodel* sm = new submodel;
666 SGPropertyNode * entry_node = *it;
667 sm->name = entry_node->getStringValue("name", "none_defined");
668 sm->model = entry_node->getStringValue("model", "Models/Geometry/rocket.ac");
669 sm->speed = entry_node->getDoubleValue("speed", 2329.4);
670 sm->repeat = entry_node->getBoolValue("repeat", false);
671 sm->delay = entry_node->getDoubleValue("delay", 0.25);
672 sm->count = entry_node->getIntValue("count", 1);
673 sm->slaved = entry_node->getBoolValue("slaved", false);
674 sm->x_offset = entry_node->getDoubleValue("x-offset", 0.0);
675 sm->y_offset = entry_node->getDoubleValue("y-offset", 0.0);
676 sm->z_offset = entry_node->getDoubleValue("z-offset", 0.0);
677 sm->yaw_offset = entry_node->getDoubleValue("yaw-offset", 0.0);
678 sm->pitch_offset = entry_node->getDoubleValue("pitch-offset", 0.0);
679 sm->drag_area = entry_node->getDoubleValue("eda", 0.034);
680 sm->life = entry_node->getDoubleValue("life", 900.0);
681 sm->buoyancy = entry_node->getDoubleValue("buoyancy", 0);
682 sm->wind = entry_node->getBoolValue("wind", false);
683 sm->cd = entry_node->getDoubleValue("cd", 0.193);
684 sm->weight = entry_node->getDoubleValue("weight", 0.25);
685 sm->aero_stabilised = entry_node->getBoolValue("aero-stabilised", true);
686 sm->no_roll = entry_node->getBoolValue("no-roll", false);
687 sm->collision = entry_node->getBoolValue("collision", false);
688 sm->impact = entry_node->getBoolValue("impact", false);
689 sm->impact_report = entry_node->getStringValue("impact-reports");
690 sm->fuse_range = entry_node->getDoubleValue("fuse-range", 0.0);
691 sm->contents_node = fgGetNode(entry_node->getStringValue("contents", "none"), false);
692 sm->speed_node = fgGetNode(entry_node->getStringValue("speed-node", "none"), false);
693 sm->submodel = entry_node->getStringValue("submodel-path", "");
695 //cout << "sm->contents_node " << sm->contents_node << endl;
696 if (sm->contents_node != 0)
697 sm->contents = sm->contents_node->getDoubleValue();
699 const char *trigger_path = entry_node->getStringValue("trigger", 0);
701 sm->trigger_node = fgGetNode(trigger_path, true);
702 sm->trigger_node->setBoolValue(sm->trigger_node->getBoolValue());
704 sm->trigger_node = 0;
707 if (sm->speed_node != 0)
708 sm->speed = sm->speed_node->getDoubleValue();
710 sm->timer = sm->delay;
712 sm->first_time = false;
713 sm->serviceable = serviceable;
716 sm->prop = fgGetNode("/ai/submodels/subsubmodel", index, true);
717 sm->prop->tie("count", SGRawValuePointer<int>(&(sm->count)));
718 sm->prop->tie("repeat", SGRawValuePointer<bool>(&(sm->repeat)));
719 sm->prop->tie("id", SGRawValuePointer<int>(&(sm->id)));
720 sm->prop->tie("sub-id", SGRawValuePointer<int>(&(sm->sub_id)));
721 sm->prop->tie("serviceable", SGRawValuePointer<bool>(&(sm->serviceable)));
722 string name = sm->name;
723 sm->prop->setStringValue("name", name.c_str());
725 string submodel = sm->submodel;
726 sm->prop->setStringValue("submodel", submodel.c_str());
727 // cout << " set submodel path " << submodel<< endl;
729 if (sm->contents_node != 0)
730 sm->prop->tie("contents-lbs", SGRawValuePointer<double>(&(sm->contents)));
733 subsubmodels.push_back(sm);
737 void FGSubmodelMgr::loadSubmodels()
739 SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: Loading sub submodels");
741 submodel_iterator = submodels.begin();
743 while (submodel_iterator != submodels.end()) {
744 string submodel = (*submodel_iterator)->submodel;
745 if (!submodel.empty()) {
746 //int id = (*submodel_iterator)->id;
747 bool serviceable = true;
748 SG_LOG(SG_GENERAL, SG_DEBUG, "found path sub sub "
750 << " index " << index
751 << "name " << (*submodel_iterator)->name);
753 (*submodel_iterator)->sub_id = index;
754 setSubData(index, submodel, serviceable);
760 subsubmodel_iterator = subsubmodels.begin();
762 while (subsubmodel_iterator != subsubmodels.end()) {
763 submodels.push_back(*subsubmodel_iterator);
764 ++subsubmodel_iterator;
767 submodel_iterator = submodels.begin();
769 while (submodel_iterator != submodels.end()) {
770 int id = (*submodel_iterator)->id;
771 SG_LOG(SG_GENERAL, SG_DEBUG,"after pusback "
773 << " name " << (*submodel_iterator)->name
774 << " sub id " << (*submodel_iterator)->sub_id);
780 // end of submodel.cxx