X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIEscort.cxx;h=2125b6ac478659513301e975e9f0c877ed7ccfc7;hb=38226af24ec01e8f0a20d7fd73ef838a69f6ef25;hp=c9901ca24630d7e5c2ba6373c909376c7c453e48;hpb=8da2f1a31b019201d950eaed663b40a5a0b73472;p=flightgear.git diff --git a/src/AIModel/AIEscort.cxx b/src/AIModel/AIEscort.cxx index c9901ca24..2125b6ac4 100644 --- a/src/AIModel/AIEscort.cxx +++ b/src/AIModel/AIEscort.cxx @@ -35,7 +35,6 @@ #include
#include -#include #include "AIEscort.hxx" @@ -44,20 +43,18 @@ using std::string; FGAIEscort::FGAIEscort() : FGAIShip(otEscort), -_selected_ac(0), _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), -_parent("") +_stn_deg_true(false) { invisible = false; @@ -142,10 +139,13 @@ bool FGAIEscort::init(bool search_in_AI_path) { no_roll = false; props->setStringValue("controls/parent-name", _parent.c_str()); - setParent(); - pos = _tgtpos; - speed = _parent_speed; - hdg = _parent_hdg; + + if (setParentNode()){ + setParent(); + pos = _tgtpos; + speed = _parent_speed; + hdg = _parent_hdg; + } return true; } @@ -196,10 +196,6 @@ void FGAIEscort::setStnPatrol(bool p) { _patrol = p; } -void FGAIEscort::setParentName(const string& p) { - _parent = p; -} - bool FGAIEscort::getGroundElev(SGGeod inpos) { double height_m ; @@ -233,75 +229,41 @@ bool FGAIEscort::getGroundElev(SGGeod inpos) { } -void FGAIEscort::setParent() { - - const SGPropertyNode_ptr ai = fgGetNode("/ai/models", true); - - for (int i = ai->nChildren() - 1; i >= -1; i--) { - SGPropertyNode_ptr model; - - if (i < 0) { // last iteration: selected model - model = _selected_ac; - } else { - model = ai->getChild(i); - string path = ai->getPath(); - const string name = model->getStringValue("name"); - - if (!model->nChildren()){ - continue; - } - if (name == _parent) { - _selected_ac = model; // save selected model for last iteration - break; - } - - } - if (!model) - continue; - - }// end for loop - - if (_selected_ac != 0){ - const string name = _selected_ac->getStringValue("name"); - double lat = _selected_ac->getDoubleValue("position/latitude-deg"); - double lon = _selected_ac->getDoubleValue("position/longitude-deg"); - double elevation = _selected_ac->getDoubleValue("position/altitude-ft"); - _MPControl = _selected_ac->getBoolValue("controls/mp-control"); - - _selectedpos.setLatitudeDeg(lat); - _selectedpos.setLongitudeDeg(lon); - _selectedpos.setElevationFt(elevation); - - _parent_speed = _selected_ac->getDoubleValue("velocities/speed-kts"); - _parent_hdg = _selected_ac->getDoubleValue("orientation/true-heading-deg"); - - if(!_stn_deg_true){ - _stn_truebrg = calcTrueBearingDeg(_stn_brg, _parent_hdg); - _stn_relbrg = _stn_brg; - //cout << _name <<" set rel"<getDoubleValue("position/latitude-deg"); + double lon = _selected_ac->getDoubleValue("position/longitude-deg"); + double elevation = _selected_ac->getDoubleValue("position/altitude-ft"); + _MPControl = _selected_ac->getBoolValue("controls/mp-control"); + + _selectedpos.setLatitudeDeg(lat); + _selectedpos.setLongitudeDeg(lon); + _selectedpos.setElevationFt(elevation); + + _parent_speed = _selected_ac->getDoubleValue("velocities/speed-kts"); + _parent_hdg = _selected_ac->getDoubleValue("orientation/true-heading-deg"); + + if(!_stn_deg_true){ + _stn_truebrg = calcTrueBearingDeg(_stn_brg, _parent_hdg); + _stn_relbrg = _stn_brg; + //cout << _name <<" set rel"<getDoubleValue("orientation/true-heading-deg"); double pitch = _selected_ac->getDoubleValue("orientation/pitch-deg"); @@ -434,10 +382,9 @@ void FGAIEscort::RunEscort(double dt){ setParent(); setStationSpeed(); - //getGroundElev(pos); _dt_count = 0; } -// end AIGroundvehicle +// end AIEscort