X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FAIModel%2FAIEscort.cxx;h=765cac8dbd9e5d9cffded5605df6fbd7d4b69e11;hb=e3ad3d3a07c472ca4c2b18cd240c986499bb2128;hp=a59a07c9520587d26c447f2a37855cb2f16cac33;hpb=2758f07df0c5e7e6fa38e8577596c576d3c37277;p=flightgear.git diff --git a/src/AIModel/AIEscort.cxx b/src/AIModel/AIEscort.cxx index a59a07c95..765cac8db 100644 --- a/src/AIModel/AIEscort.cxx +++ b/src/AIModel/AIEscort.cxx @@ -27,15 +27,14 @@ #include #include -#include #include +#include #include #include
-#include
+#include #include -#include #include "AIEscort.hxx" @@ -45,14 +44,14 @@ FGAIEscort::FGAIEscort() : FGAIShip(otEscort), _relbrg (0), -_stn_truebrg(0), _parent_speed(0), -_stn_limit(0), -_stn_angle_limit(0), -_stn_speed(0), +_interval(0), +_stn_truebrg(0), _stn_height(0), +_stn_speed(0), +_stn_angle_limit(0), +_stn_limit(0), _max_speed(0), -_interval(0), _MPControl(false), _patrol(false), _stn_deg_true(false) @@ -92,62 +91,53 @@ void FGAIEscort::readFromScenario(SGPropertyNode* scFileNode) { void FGAIEscort::bind() { FGAIShip::bind(); - props->tie("station/rel-bearing-deg", + tie("station/rel-bearing-deg", SGRawValuePointer(&_stn_relbrg)); - props->tie("station/true-bearing-deg", + tie("station/true-bearing-deg", SGRawValuePointer(&_stn_truebrg)); - props->tie("station/range-nm", + tie("station/range-nm", SGRawValuePointer(&_stn_range)); - props->tie("station/range-limit-nm", + tie("station/range-limit-nm", SGRawValuePointer(&_stn_limit)); - props->tie("station/angle-limit-deg", + tie("station/angle-limit-deg", SGRawValuePointer(&_stn_angle_limit)); - props->tie("station/speed-kts", + tie("station/speed-kts", SGRawValuePointer(&_stn_speed)); - props->tie("station/height-ft", + tie("station/height-ft", SGRawValuePointer(&_stn_height)); - props->tie("controls/update-interval-sec", + tie("controls/update-interval-sec", SGRawValuePointer(&_interval)); - props->tie("controls/parent-mp-control", + tie("controls/parent-mp-control", SGRawValuePointer(&_MPControl)); - props->tie("station/target-range-nm", + tie("station/target-range-nm", SGRawValuePointer(&_tgtrange)); - props->tie("station/target-brg-deg-t", + tie("station/target-brg-deg-t", SGRawValuePointer(&_tgtbrg)); - props->tie("station/patrol", + tie("station/patrol", SGRawValuePointer(&_patrol)); } -void FGAIEscort::unbind() { - FGAIShip::unbind(); - - props->untie("station/rel-bearing-deg"); - props->untie("station/true-bearing-deg"); - props->untie("station/range-nm"); - props->untie("station/range-limit-nm"); - props->untie("station/angle-limit-deg"); - props->untie("station/speed-kts"); - props->untie("station/height-ft"); - props->untie("controls/update-interval-sec"); - -} - bool FGAIEscort::init(bool search_in_AI_path) { if (!FGAIShip::init(search_in_AI_path)) return false; + reinit(); + return true; +} +void FGAIEscort::reinit() { invisible = false; no_roll = false; props->setStringValue("controls/parent-name", _parent.c_str()); - setParentNode(); - setParent(); - pos = _tgtpos; - speed = _parent_speed; - hdg = _parent_hdg; + if (setParentNode()){ + setParent(); + pos = _tgtpos; + speed = _parent_speed; + hdg = _parent_hdg; + } - return true; + FGAIShip::reinit(); } void FGAIEscort::update(double dt) { @@ -200,13 +190,14 @@ bool FGAIEscort::getGroundElev(SGGeod inpos) { double height_m ; - if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &_material,0)){ + const SGMaterial* material = 0; + if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &material,0)){ _ht_agl_ft = inpos.getElevationFt() - height_m * SG_METER_TO_FEET; - if (_material) { - const vector& names = _material->get_names(); + if (material) { + const vector& names = material->get_names(); - _solid = _material->get_solid(); + _solid = material->get_solid(); if (!names.empty()) props->setStringValue("material/name", names[0].c_str()); @@ -229,7 +220,6 @@ bool FGAIEscort::getGroundElev(SGGeod inpos) { } - void FGAIEscort::setParent() { double lat = _selected_ac->getDoubleValue("position/latitude-deg"); @@ -277,13 +267,6 @@ void FGAIEscort::calcRangeBearing(double lat, double lon, double lat2, double lo range = distance * SG_METER_TO_NM; } -double FGAIEscort::calcRelBearingDeg(double bearing, double heading) -{ - double angle = bearing - heading; - SG_NORMALIZE_RANGE(angle, -180.0, 180.0); - return angle; -} - double FGAIEscort::calcTrueBearingDeg(double bearing, double heading) { double angle = bearing + heading; @@ -291,13 +274,6 @@ double FGAIEscort::calcTrueBearingDeg(double bearing, double heading) return angle; } -double FGAIEscort::calcRecipBearingDeg(double bearing) -{ - double angle = bearing - 180; - SG_NORMALIZE_RANGE(angle, 0.0, 360.0); - return angle; -} - SGVec3d FGAIEscort::getCartHitchPosAt(const SGVec3d& _off) const { double hdg = _selected_ac->getDoubleValue("orientation/true-heading-deg"); double pitch = _selected_ac->getDoubleValue("orientation/pitch-deg"); @@ -329,7 +305,7 @@ void FGAIEscort::setStationSpeed(){ // these are the AI rules for the manoeuvring of escorts if (_MPControl && _tgtrange > 4 * _stn_limit){ - SG_LOG(SG_GENERAL, SG_ALERT, "AIEscort: " << _name + SG_LOG(SG_AI, SG_ALERT, "AIEscort: " << _name << " re-aligning to MP pos"); pos = _tgtpos; speed = 0;