props->setStringValue("submodels/path", _submodel.c_str());
// start with high value so that animations don't trigger yet
- _ht_agl_ft = 10000000;
+ _ht_agl_ft = 1e10;
hdg = _azimuth;
pitch = _elevation;
roll = _rotation;
SGRawValuePointer<bool>(&_solid));
props->tie("altitude-agl-ft",
SGRawValuePointer<double>(&_ht_agl_ft));
- props->tie("sub-id",
- SGRawValuePointer<int>(&_subID));
}
void FGAIBallistic::unbind() {
props->untie("material/load-resistance");
props->untie("material/solid");
props->untie("altitude-agl-ft");
- props->untie("sub-id");
}
void FGAIBallistic::update(double dt) {
if (_life_timer > life)
setDie(true);
- double speed_north_deg_sec;
- double speed_east_deg_sec;
- double wind_speed_from_north_deg_sec;
- double wind_speed_from_east_deg_sec;
- double Cdm; // Cd adjusted by Mach Number
- double hs;
-
//randomise Cd by +- 5%
if (_random)
_Cd = _Cd * 0.95 + (0.05 * sg_random());
// Adjust Cd by Mach number. The equations are based on curves
// for a conventional shell/bullet (no boat-tail).
+ double Cdm;
+
if (Mach < 0.7)
Cdm = 0.0125 * Mach + _Cd;
else if (Mach < 1.2 )
speed = 0.0;
double speed_fps = speed * SG_KT_TO_FPS;
+ double hs;
// calculate vertical and horizontal speed components
if (speed == 0.0) {
}
// convert horizontal speed (fps) to degrees per second
- speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
- speed_east_deg_sec = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon;
+ double speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
+ double speed_east_deg_sec = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon;
// if wind not required, set to zero
if (!_wind) {
}
// convert wind speed (fps) to degrees per second
- wind_speed_from_north_deg_sec = _wind_from_north / ft_per_deg_lat;
- wind_speed_from_east_deg_sec = _wind_from_east / ft_per_deg_lon;
+ double wind_speed_from_north_deg_sec = _wind_from_north / ft_per_deg_lat;
+ double wind_speed_from_east_deg_sec = _wind_from_east / ft_per_deg_lon;
// set new position
pos.setLatitudeDeg( pos.getLatitudeDeg()
_ht_agl_ft = pos.getElevationFt() - elevation_m * SG_METER_TO_FEET;
- // report impact by setting properties
if (_ht_agl_ft <= 0) {
SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: terrain impact");
report_impact(elevation_m);
_impact_reported = true;
+
+ // kill the AIObject if there is no subsubmodel
+ if (_subID == 0)
+ setDie(true);
}
}
void FGAIBallistic::handle_collision()
{
- const FGAIBase *collision = manager->calcCollision(pos.getElevationFt(),
+ const FGAIBase *object = manager->calcCollision(pos.getElevationFt(),
pos.getLatitudeDeg(),pos.getLongitudeDeg(), _fuse_range);
- if (collision) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: HIT!");
- report_impact(pos.getElevationM(), collision);
+ if (object) {
+ SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: object hit");
+ report_impact(pos.getElevationM(), object);
_collision_reported = true;
}
}
void FGSubmodelMgr::load()
{
- const int id = 0;
-
SGPropertyNode *path = fgGetNode("/sim/submodels/path");
- SGPropertyNode root;
if (path) {
+ const int id = 0;
string Path = path->getStringValue();
bool Seviceable =_serviceable_node->getBoolValue();
setData(id, Path, Seviceable);
SGPath config(globals->get_fg_root());
config.append(path);
- SG_LOG(SG_GENERAL, SG_DEBUG,
- "Submodels: path " << path);
+ SG_LOG(SG_GENERAL, SG_DEBUG, "Submodels: path " << path);
+
try {
SG_LOG(SG_GENERAL, SG_DEBUG,
"Submodels: Trying to read AI submodels file: " << config.str());
readProperties(config.str(), &root);
+
} catch (const sg_exception &e) {
SG_LOG(SG_GENERAL, SG_DEBUG,
"Submodels: Unable to read AI submodels file: " << config.str());