1
0
Fork 0

AIEscort: Maintenance

default dtor
ensure all members are initialized
_max_speed was hiding parent member
double constants with double types
This commit is contained in:
Scott Giese 2022-01-15 17:49:10 -06:00
parent a9cb94fdbd
commit a177aa76bc
2 changed files with 40 additions and 54 deletions

View file

@ -41,28 +41,11 @@
using std::string; using std::string;
FGAIEscort::FGAIEscort() : FGAIEscort::FGAIEscort() : FGAIShip(object_type::otEscort)
FGAIShip(otEscort),
_relbrg (0),
_parent_speed(0),
_interval(0),
_stn_truebrg(0),
_stn_height(0),
_stn_speed(0),
_stn_angle_limit(0),
_stn_limit(0),
_max_speed(0),
_MPControl(false),
_patrol(false),
_stn_deg_true(false)
{ {
invisible = false; invisible = false;
} }
FGAIEscort::~FGAIEscort() {}
void FGAIEscort::readFromScenario(SGPropertyNode* scFileNode) { void FGAIEscort::readFromScenario(SGPropertyNode* scFileNode) {
if (!scFileNode) if (!scFileNode)
return; return;
@ -306,35 +289,35 @@ void FGAIEscort::setStationSpeed(){
// these are the AI rules for the manoeuvring of escorts // these are the AI rules for the manoeuvring of escorts
if (_MPControl && _tgtrange > 4 * _stn_limit) { if (_MPControl && _tgtrange > 4.0 * _stn_limit) {
SG_LOG(SG_AI, SG_ALERT, "AIEscort: " << _name SG_LOG(SG_AI, SG_ALERT, "AIEscort: " << _name
<< " re-aligning to MP pos"); << " re-aligning to MP pos");
pos = _tgtpos; pos = _tgtpos;
speed = 0; speed = 0.0;
angle = 0; angle = 0.0;
} else if ((_relbrg < -90 || _relbrg > 90) && _tgtrange > _stn_limit) { } else if ((_relbrg < -90.0 || _relbrg > 90.0) && _tgtrange > _stn_limit) {
angle =_relbrg; angle =_relbrg;
if(_tgtrange > 4 * _stn_limit) if(_tgtrange > 4.0 * _stn_limit)
speed = 4 * -_stn_speed; speed = 4.0 * -_stn_speed;
else else
speed = -_stn_speed; speed = -_stn_speed;
} else if ((_relbrg >= -90 && _relbrg <= 90) && _tgtrange > _stn_limit) { } else if ((_relbrg >= -90.0 && _relbrg <= 90.0) && _tgtrange > _stn_limit) {
angle = _relbrg; angle = _relbrg;
if(_tgtrange > 4 * _stn_limit) if(_tgtrange > 4.0 * _stn_limit)
speed = 4 * _stn_speed; speed = 4.0 * _stn_speed;
else else
speed = _stn_speed; speed = _stn_speed;
} else { } else {
if (_patrol){ if (_patrol){
angle = 15 * sg_random(); angle = 15.0 * sg_random();
speed = 5 * sg_random(); speed = 5.0 * sg_random();
} else { } else {
angle = 0; angle = 0.0;
speed = 0; speed = 0.0;
} }
} }

View file

@ -18,11 +18,10 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef _FG_AIESCORT_HXX #pragma once
#define _FG_AIESCORT_HXX
#include <string>
#include <list> #include <list>
#include <string>
#include <simgear/compiler.h> #include <simgear/compiler.h>
@ -30,14 +29,16 @@
#include "AIShip.hxx" #include "AIShip.hxx"
#include "AIManager.hxx"
#include "AIBase.hxx" #include "AIBase.hxx"
#include "AIManager.hxx"
class FGAIEscort : public FGAIShip { class FGAIEscort : public FGAIShip
{
public: public:
FGAIEscort(); FGAIEscort();
virtual ~FGAIEscort(); virtual ~FGAIEscort() = default;
const char* getTypeString(void) const override { return "escort"; }
void readFromScenario(SGPropertyNode* scFileNode) override; void readFromScenario(SGPropertyNode* scFileNode) override;
bool init(ModelSearchOrder searchOrder) override; bool init(ModelSearchOrder searchOrder) override;
@ -45,8 +46,6 @@ public:
void reinit() override; void reinit() override;
void update(double dt) override; void update(double dt) override;
const char* getTypeString(void) const override { return "escort"; }
private: private:
void setStnRange(double r); void setStnRange(double r);
void setStnBrg(double y); void setStnBrg(double y);
@ -75,22 +74,26 @@ private:
SGGeod _selectedpos; SGGeod _selectedpos;
SGGeod _tgtpos; SGGeod _tgtpos;
bool _solid; // if true ground is solid for FDMs bool _solid = true; // if true ground is solid for FDMs
double _tgtrange, _tgtbrg; double _tgtrange = 0.0;
double _ht_agl_ft; double _tgtbrg = 0.0;
double _relbrg; double _ht_agl_ft = 0.0;
double _parent_speed, _parent_hdg; double _relbrg = 0.0;
double _interval; double _parent_speed = 0.0;
double _parent_hdg = 0.0;
double _interval = 0.0;
double _stn_relbrg, _stn_truebrg, _stn_brg, _stn_range, _stn_height; double _stn_relbrg = 0.0;
double _stn_speed, _stn_angle_limit, _stn_limit; double _stn_truebrg = 0.0;
double _stn_brg = 0.0;
double _max_speed; double _stn_range = 0.0;
double _stn_height = 0.0;
bool _MPControl, _patrol, _stn_deg_true; double _stn_speed = 0.0;
double _stn_angle_limit = 0.0;
// std::string _parent; double _stn_limit = 0.0;
bool _MPControl = false;
bool _patrol = false;
bool _stn_deg_true = false;
}; };
#endif // FG_AIGROUNDVEHICLE_HXX