Added better AI handling of replay - part of the new carrier handling in replays.
This commit is contained in:
parent
402a71100e
commit
6513dc1137
5 changed files with 63 additions and 41 deletions
|
@ -125,6 +125,7 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
|
||||||
_parent(""),
|
_parent(""),
|
||||||
props( NULL ),
|
props( NULL ),
|
||||||
model_removed( fgGetNode("/ai/models/model-removed", true) ),
|
model_removed( fgGetNode("/ai/models/model-removed", true) ),
|
||||||
|
replay_time(fgGetNode("sim/replay/time", true)),
|
||||||
manager( NULL ),
|
manager( NULL ),
|
||||||
_installed(false),
|
_installed(false),
|
||||||
_impact_lat(0),
|
_impact_lat(0),
|
||||||
|
@ -264,6 +265,8 @@ void FGAIBase::readFromScenario(SGPropertyNode* scFileNode)
|
||||||
|
|
||||||
void FGAIBase::update(double dt) {
|
void FGAIBase::update(double dt) {
|
||||||
|
|
||||||
|
if (replay_time->getDoubleValue() > 0)
|
||||||
|
return;
|
||||||
if (_otype == otStatic)
|
if (_otype == otStatic)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,7 @@ protected:
|
||||||
SGPropertyNode_ptr _selected_ac;
|
SGPropertyNode_ptr _selected_ac;
|
||||||
SGPropertyNode_ptr props;
|
SGPropertyNode_ptr props;
|
||||||
SGPropertyNode_ptr trigger_node;
|
SGPropertyNode_ptr trigger_node;
|
||||||
|
SGPropertyNode_ptr replay_time;
|
||||||
SGPropertyNode_ptr model_removed; // where to report model removal
|
SGPropertyNode_ptr model_removed; // where to report model removal
|
||||||
FGAIManager* manager;
|
FGAIManager* manager;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
#include "AICarrier.hxx"
|
#include "AICarrier.hxx"
|
||||||
|
|
||||||
FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) {
|
FGAICarrier::FGAICarrier() : FGAIShip(otCarrier), deck_altitude(65.0065) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAICarrier::~FGAICarrier() {
|
FGAICarrier::~FGAICarrier() {
|
||||||
|
@ -49,6 +49,7 @@ void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
|
||||||
|
|
||||||
setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
|
setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
|
||||||
setSign(scFileNode->getStringValue("pennant-number"));
|
setSign(scFileNode->getStringValue("pennant-number"));
|
||||||
|
setDeckAltitude(scFileNode->getDoubleValue("deck-altitude"));
|
||||||
setWind_from_east(scFileNode->getDoubleValue("wind_from_east", 0));
|
setWind_from_east(scFileNode->getDoubleValue("wind_from_east", 0));
|
||||||
setWind_from_north(scFileNode->getDoubleValue("wind_from_north", 0));
|
setWind_from_north(scFileNode->getDoubleValue("wind_from_north", 0));
|
||||||
setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID", "029Y"));
|
setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID", "029Y"));
|
||||||
|
@ -112,6 +113,11 @@ void FGAICarrier::setMinLong(double deg) {
|
||||||
min_long = fabs(deg);
|
min_long = fabs(deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAICarrier::setDeckAltitude(const double altitude_feet) {
|
||||||
|
deck_altitude = altitude_feet;
|
||||||
|
}
|
||||||
|
|
||||||
void FGAICarrier::setSign(const string& s) {
|
void FGAICarrier::setSign(const string& s) {
|
||||||
sign = s;
|
sign = s;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +253,8 @@ void FGAICarrier::bind() {
|
||||||
|
|
||||||
props->untie("velocities/true-airspeed-kt");
|
props->untie("velocities/true-airspeed-kt");
|
||||||
|
|
||||||
|
props->getNode("position/deck-altitude-feet", true)->setDoubleValue(deck_altitude);
|
||||||
|
|
||||||
tie("controls/flols/source-lights",
|
tie("controls/flols/source-lights",
|
||||||
SGRawValuePointer<int>(&source));
|
SGRawValuePointer<int>(&source));
|
||||||
tie("controls/flols/distance-m",
|
tie("controls/flols/distance-m",
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||||
|
|
||||||
void setSign(const string& );
|
void setSign(const string& );
|
||||||
|
void setDeckAltitude(const double altitude_feet);
|
||||||
void setTACANChannelID(const string &);
|
void setTACANChannelID(const string &);
|
||||||
|
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
|
@ -109,6 +110,7 @@ private:
|
||||||
|
|
||||||
double dist; // the distance of the eyepoint from the flols
|
double dist; // the distance of the eyepoint from the flols
|
||||||
double angle;
|
double angle;
|
||||||
|
double deck_altitude;
|
||||||
int source; // the flols light which is visible at the moment
|
int source; // the flols light which is visible at the moment
|
||||||
bool in_to_wind;
|
bool in_to_wind;
|
||||||
|
|
||||||
|
|
|
@ -212,50 +212,58 @@ void FGAIShip::bind() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIShip::update(double dt) {
|
void FGAIShip::update(double dt) {
|
||||||
//SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
|
if (replay_time->getDoubleValue() <= 0)
|
||||||
// For computation of rotation speeds we just use finite differences here.
|
{
|
||||||
// That is perfectly valid since this thing is not driven by accelerations
|
|
||||||
// but by just apply discrete changes at its velocity variables.
|
|
||||||
// Update the velocity information stored in those nodes.
|
|
||||||
// Transform that one to the horizontal local coordinate system.
|
|
||||||
SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
|
|
||||||
// The orientation of the ship wrt the horizontal local frame
|
|
||||||
SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
|
||||||
// and postrotate the orientation of the AIModel wrt the horizontal
|
|
||||||
// local frame
|
|
||||||
SGQuatd ec2body = ec2hl*hl2body;
|
|
||||||
// The cartesian position of the ship in the wgs84 world
|
|
||||||
//SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
|
||||||
|
|
||||||
// The simulation time this transform is meant for
|
|
||||||
aip.setReferenceTime(globals->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<double>::min() < dt) {
|
|
||||||
// Now here is the finite difference ...
|
|
||||||
|
|
||||||
|
//SG_LOG(SG_AI, SG_ALERT, "updating Ship: " << _name <<hdg<<pitch<<roll);
|
||||||
|
// For computation of rotation speeds we just use finite differences here.
|
||||||
|
// That is perfectly valid since this thing is not driven by accelerations
|
||||||
|
// but by just apply discrete changes at its velocity variables.
|
||||||
|
// Update the velocity information stored in those nodes.
|
||||||
// Transform that one to the horizontal local coordinate system.
|
// Transform that one to the horizontal local coordinate system.
|
||||||
SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos);
|
SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
|
||||||
// compute the new orientation
|
// The orientation of the ship wrt the horizontal local frame
|
||||||
SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
||||||
// The rotation difference
|
// and postrotate the orientation of the AIModel wrt the horizontal
|
||||||
SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew;
|
// local frame
|
||||||
SGVec3d dOrAngleAxis;
|
SGQuatd ec2body = ec2hl*hl2body;
|
||||||
dOr.getAngleAxis(dOrAngleAxis);
|
// The cartesian position of the ship in the wgs84 world
|
||||||
// divided by the time difference provides a rotation speed vector
|
//SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
||||||
dOrAngleAxis /= dt;
|
|
||||||
|
|
||||||
aip.setBodyAngularVelocity(dOrAngleAxis);
|
// The simulation time this transform is meant for
|
||||||
|
aip.setReferenceTime(globals->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<double>::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) {
|
void FGAIShip::Run(double dt) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue