#include "AIBallistic.hxx"
#include <Main/util.hxx>
+#include <Environment/gravity.hxx>
using namespace simgear;
const double FGAIBallistic::slugs_to_lbs = 32.1740485564;
FGAIBallistic::FGAIBallistic(object_type ot) :
-FGAIBase(ot),
+FGAIBase(ot, false),
_height(0.0),
_speed(0),
_ht_agl_ft(0.0),
_aero_stabilised(false),
_drag_area(0.007),
_life_timer(0.0),
-_gravity(32.1740485564),
_buoyancy(0),
_wind(true),
_mass(0),
bool FGAIBallistic::init(bool search_in_AI_path) {
FGAIBase::init(search_in_AI_path);
+ reinit();
+ return true;
+}
+void FGAIBallistic::reinit() {
_impact_reported = false;
_collision_reported = false;
_expiry_reported = false;
setParentNodes(_selected_ac);
- return true;
+ FGAIBase::reinit();
}
void FGAIBallistic::bind() {
if (invisible)
return;
- double hdg, pch, rll, agl = 0;
+ double hdg, pch, rll;//, agl = 0;
if (_pnode != 0) {
setParentPos();
hdg = _p_hdg_node->getDoubleValue();
pch = _p_pch_node->getDoubleValue();
rll = _p_rll_node->getDoubleValue();
- agl = _p_agl_node->getDoubleValue();
+// agl = _p_agl_node->getDoubleValue();
setOffsetPos(_parentpos, hdg, pch, rll);
setSpeed(_p_spd_node->getDoubleValue());
}else {
hdg = manager->get_user_heading();
pch = manager->get_user_pitch();
rll = manager->get_user_roll();
- agl = manager->get_user_agl();
+// agl = manager->get_user_agl();
setOffsetPos(userpos, hdg, pch, rll);
setSpeed(manager->get_user_speed());
}
if (_life_timer > life && life != -1){
if (_report_expiry && !_expiry_reported && !_impact_reported && !_collision_reported){
- //cout<<"AIBallistic run: name " << _name.c_str() << " expiry " << " pass " << _pass <<endl;
+ //cout<<"AIBallistic run: name " << _name.c_str() << " expiry "
+ //<< " _life_timer " << _life_timer<< endl;
handle_expiry();
} else{
//cout<<"AIBallistic run: name " << _name.c_str()
- // << " die " << " _life_timer " << _life_timer << " pass " << _pass << endl;
+ // << " die " << " _life_timer " << _life_timer << endl;
setDie(true);
- setTime(0);
}
+ setTime(0);
}
//set the contents in the appropriate tank or other property in the parent to zero
if ( speed < 0.0 )
speed = 0.0;
- double speed_fps = speed * SG_KT_TO_FPS;
+// double speed_fps = speed * SG_KT_TO_FPS;
// calculate vertical and horizontal speed components
calcVSHS();
hs = 0;
// adjust vertical speed for acceleration of gravity, buoyancy, and vertical force
- vs -= (_gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt;
+ double gravity = SG_METER_TO_FEET * (Environment::Gravity::instance()->getGravity(pos));
+ vs -= (gravity - _buoyancy - v_force_acc_fpss - normal_force_fpss) * dt;
if (vs <= 0.00001 && vs >= -0.00001)
vs = 0;
return;
if (_ht_agl_ft <= 0) {
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: terrain impact material" << _mat_name);
+ SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: terrain impact material" << _mat_name);
report_impact(_elevation_m);
_impact_reported = true;
void FGAIBallistic::handle_expiry() {
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: handle_expiry " << pos.getElevationM());
+ //SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: handle_expiry " << pos.getElevationM());
report_impact(pos.getElevationM());
_expiry_reported = true;
else
n->setStringValue("type", "terrain");
- SG_LOG(SG_GENERAL, SG_DEBUG, "AIBallistic: object impact " << _name
+ SG_LOG(SG_AI, SG_DEBUG, "AIBallistic: object impact " << _name
<< " lon " <<_impact_lon << " lat " <<_impact_lat << " sec " << _life_timer);
n->setDoubleValue("longitude-deg", _impact_lon);