diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index e878a9b45..6ea7b0071 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -125,6 +125,7 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) : _parent(""), props( NULL ), model_removed( fgGetNode("/ai/models/model-removed", true) ), + replay_time(fgGetNode("sim/replay/time", true)), manager( NULL ), _installed(false), _impact_lat(0), @@ -264,6 +265,8 @@ void FGAIBase::readFromScenario(SGPropertyNode* scFileNode) void FGAIBase::update(double dt) { + if (replay_time->getDoubleValue() > 0) + return; if (_otype == otStatic) return; diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 5f2ae1e25..4f455d4d3 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -168,6 +168,7 @@ protected: SGPropertyNode_ptr _selected_ac; SGPropertyNode_ptr props; SGPropertyNode_ptr trigger_node; + SGPropertyNode_ptr replay_time; SGPropertyNode_ptr model_removed; // where to report model removal FGAIManager* manager; diff --git a/src/AIModel/AICarrier.cxx b/src/AIModel/AICarrier.cxx index 1514b4b3c..5eda5af58 100644 --- a/src/AIModel/AICarrier.cxx +++ b/src/AIModel/AICarrier.cxx @@ -35,7 +35,7 @@ #include "AICarrier.hxx" -FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) { +FGAICarrier::FGAICarrier() : FGAIShip(otCarrier), deck_altitude(65.0065) { } FGAICarrier::~FGAICarrier() { @@ -49,6 +49,7 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) { setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000)); setSign(scFileNode->getStringValue("pennant-number")); + setDeckAltitude(scFileNode->getDoubleValue("deck-altitude")); setWind_from_east(scFileNode->getDoubleValue("wind_from_east", 0)); setWind_from_north(scFileNode->getDoubleValue("wind_from_north", 0)); setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID", "029Y")); @@ -112,6 +113,11 @@ void FGAICarrier::setMinLong(double deg) { min_long = fabs(deg); } + +void FGAICarrier::setDeckAltitude(const double altitude_feet) { + deck_altitude = altitude_feet; +} + void FGAICarrier::setSign(const string& s) { sign = s; } @@ -247,6 +253,8 @@ void FGAICarrier::bind() { props->untie("velocities/true-airspeed-kt"); + props->getNode("position/deck-altitude-feet", true)->setDoubleValue(deck_altitude); + tie("controls/flols/source-lights", SGRawValuePointer(&source)); tie("controls/flols/distance-m", diff --git a/src/AIModel/AICarrier.hxx b/src/AIModel/AICarrier.hxx index d7194f914..75dfdba16 100644 --- a/src/AIModel/AICarrier.hxx +++ b/src/AIModel/AICarrier.hxx @@ -46,6 +46,7 @@ public: virtual void readFromScenario(SGPropertyNode* scFileNode); void setSign(const string& ); + void setDeckAltitude(const double altitude_feet); void setTACANChannelID(const string &); virtual void bind(); @@ -109,6 +110,7 @@ private: double dist; // the distance of the eyepoint from the flols double angle; + double deck_altitude; int source; // the flols light which is visible at the moment bool in_to_wind; diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index ad89c223f..ab91ddc2b 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -212,50 +212,58 @@ void FGAIShip::bind() { } void FGAIShip::update(double dt) { - //SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <get_sim_time_sec()); - - // Compute the velocity in m/s in the body frame - aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0)); - - FGAIBase::update(dt); - Run(dt); - Transform(); - if (fp) - setXTrackError(); - - // Only change these values if we are able to compute them safely - if (SGLimits::min() < dt) { - // Now here is the finite difference ... + if (replay_time->getDoubleValue() <= 0) + { + //SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <get_sim_time_sec()); + + // Compute the velocity in m/s in the body frame + aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0)); + + FGAIBase::update(dt); + Run(dt); + Transform(); + + if (fp) + setXTrackError(); + + // Only change these values if we are able to compute them safely + if (SGLimits::min() < dt) { + // Now here is the finite difference ... + + // Transform that one to the horizontal local coordinate system. + SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos); + // compute the new orientation + SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll); + // The rotation difference + SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew; + SGVec3d dOrAngleAxis; + dOr.getAngleAxis(dOrAngleAxis); + // divided by the time difference provides a rotation speed vector + dOrAngleAxis /= dt; + + aip.setBodyAngularVelocity(dOrAngleAxis); + } } + else + Transform(); + } void FGAIShip::Run(double dt) {