Make the AI models a bit more intelligent. The Gear should be extended and retracted automatically, the navigation lights turn on when sun-angle-rad > 1.57, strobe and beacon are always on and make sure all properties are returned in the right unit format.
This commit is contained in:
parent
6ba351cfc6
commit
863b0c9432
4 changed files with 91 additions and 25 deletions
|
@ -33,7 +33,10 @@ SG_USING_STD(string);
|
||||||
|
|
||||||
#include "AIAircraft.hxx"
|
#include "AIAircraft.hxx"
|
||||||
|
|
||||||
|
//
|
||||||
|
// accel, decel, climb_rate, descent_rate, takeoff_speed, climb_speed,
|
||||||
|
// cruise_speed, descent_speed, land_speed
|
||||||
|
//
|
||||||
const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
|
const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
|
||||||
// light aircraft
|
// light aircraft
|
||||||
{2.0, 2.0, 450.0, 1000.0, 70.0, 80.0, 100.0, 80.0, 60.0},
|
{2.0, 2.0, 450.0, 1000.0, 70.0, 80.0, 100.0, 80.0, 60.0},
|
||||||
|
@ -46,7 +49,10 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FGAIAircraft *FGAIAircraft::_self = NULL;
|
||||||
|
|
||||||
FGAIAircraft::FGAIAircraft() {
|
FGAIAircraft::FGAIAircraft() {
|
||||||
|
_self = this;
|
||||||
|
|
||||||
// set heading and altitude locks
|
// set heading and altitude locks
|
||||||
hdg_lock = false;
|
hdg_lock = false;
|
||||||
|
@ -56,6 +62,7 @@ FGAIAircraft::FGAIAircraft() {
|
||||||
|
|
||||||
|
|
||||||
FGAIAircraft::~FGAIAircraft() {
|
FGAIAircraft::~FGAIAircraft() {
|
||||||
|
_self = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,10 +72,21 @@ bool FGAIAircraft::init() {
|
||||||
|
|
||||||
void FGAIAircraft::bind() {
|
void FGAIAircraft::bind() {
|
||||||
FGAIBase::bind();
|
FGAIBase::bind();
|
||||||
|
|
||||||
|
props->tie("controls/gear/gear-down",
|
||||||
|
SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown));
|
||||||
|
|
||||||
|
/*
|
||||||
|
props->getNode("controls/lighting/landing-lights", true)
|
||||||
|
->alias("controls/gear/gear-down");
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIAircraft::unbind() {
|
void FGAIAircraft::unbind() {
|
||||||
FGAIBase::unbind();
|
FGAIBase::unbind();
|
||||||
|
|
||||||
|
props->untie("controls/gear/gear-down");
|
||||||
|
// props->getNode("controls/lighting/landing-lights")->unalias();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,9 @@ public:
|
||||||
void YawTo(double angle);
|
void YawTo(double angle);
|
||||||
void ClimbTo(double altitude);
|
void ClimbTo(double altitude);
|
||||||
void TurnTo(double heading);
|
void TurnTo(double heading);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static FGAIAircraft *_self;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -76,6 +79,16 @@ private:
|
||||||
|
|
||||||
void Run(double dt);
|
void Run(double dt);
|
||||||
double sign(double x);
|
double sign(double x);
|
||||||
|
|
||||||
|
static bool _getGearDown();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool FGAIAircraft::_getGearDown() {
|
||||||
|
return ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
|
||||||
|
&& (fgGetFloat("/orientation/pitch-deg") < 0.0)
|
||||||
|
&& (fgGetFloat("/velocities/airspeed-kt")
|
||||||
|
< _self->performance->land_speed*1.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // _FG_AIAircraft_HXX
|
#endif // _FG_AIAircraft_HXX
|
||||||
|
|
|
@ -86,13 +86,19 @@ bool FGAIBase::init() {
|
||||||
|
|
||||||
tgt_roll = tgt_pitch = tgt_yaw = tgt_vs = vs = roll = pitch = 0.0;
|
tgt_roll = tgt_pitch = tgt_yaw = tgt_vs = vs = roll = pitch = 0.0;
|
||||||
setDie(false);
|
setDie(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBase::bind() {
|
void FGAIBase::bind() {
|
||||||
props->tie("velocities/airspeed-kt", SGRawValuePointer<double>(&speed));
|
props->tie("velocities/airspeed-kt", SGRawValuePointer<double>(&speed));
|
||||||
props->tie("velocities/vertical-speed-fps", SGRawValuePointer<double>(&vs));
|
props->tie("velocities/vertical-speed-fps",
|
||||||
|
SGRawValueFunctions<double>(FGAIBase::_getVS_fps,
|
||||||
|
FGAIBase::_setVS_fps));
|
||||||
|
|
||||||
props->tie("position/altitude-ft", SGRawValuePointer<double>(&altitude));
|
props->tie("position/altitude-ft",
|
||||||
|
SGRawValueFunctions<double>(FGAIBase::_getAltitude,
|
||||||
|
FGAIBase::_setAltitude));
|
||||||
props->tie("position/latitude-deg",
|
props->tie("position/latitude-deg",
|
||||||
SGRawValueFunctions<double>(FGAIBase::_getLatitude,
|
SGRawValueFunctions<double>(FGAIBase::_getLatitude,
|
||||||
FGAIBase::_setLatitude));
|
FGAIBase::_setLatitude));
|
||||||
|
@ -100,9 +106,14 @@ void FGAIBase::bind() {
|
||||||
SGRawValueFunctions<double>(FGAIBase::_getLongitude,
|
SGRawValueFunctions<double>(FGAIBase::_getLongitude,
|
||||||
FGAIBase::_setLongitude));
|
FGAIBase::_setLongitude));
|
||||||
|
|
||||||
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
|
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
|
||||||
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
|
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
|
||||||
props->tie("orientation/heading-deg", SGRawValuePointer<double>(&hdg));
|
props->tie("orientation/heading-deg", SGRawValuePointer<double>(&hdg));
|
||||||
|
|
||||||
|
props->tie("controls/lighting/nav-lights",
|
||||||
|
SGRawValueFunctions<bool>(FGAIBase::_isNight));
|
||||||
|
props->setBoolValue("controls/lighting/beacon", true);
|
||||||
|
props->setBoolValue("controls/lighting/strobe", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBase::unbind() {
|
void FGAIBase::unbind() {
|
||||||
|
@ -116,17 +127,7 @@ void FGAIBase::unbind() {
|
||||||
props->untie("orientation/pitch-deg");
|
props->untie("orientation/pitch-deg");
|
||||||
props->untie("orientation/roll-deg");
|
props->untie("orientation/roll-deg");
|
||||||
props->untie("orientation/heading-deg");
|
props->untie("orientation/heading-deg");
|
||||||
|
|
||||||
|
props->untie("controls/controls/lighting/nav-lights");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FGAIBase::_setLongitude( double longitude ) {
|
|
||||||
_self->pos.setlon(longitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FGAIBase::_setLatitude ( double latitude ) {
|
|
||||||
_self->pos.setlat(latitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
double FGAIBase::_getLongitude() { return _self->pos.lon(); }
|
|
||||||
|
|
||||||
double FGAIBase::_getLatitude () { return _self->pos.lat(); }
|
|
||||||
|
|
|
@ -20,10 +20,13 @@
|
||||||
#ifndef _FG_AIBASE_HXX
|
#ifndef _FG_AIBASE_HXX
|
||||||
#define _FG_AIBASE_HXX
|
#define _FG_AIBASE_HXX
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
#include <simgear/math/point3d.hxx>
|
#include <simgear/math/point3d.hxx>
|
||||||
#include <simgear/scene/model/placement.hxx>
|
#include <simgear/scene/model/placement.hxx>
|
||||||
#include <string>
|
|
||||||
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
SG_USING_STD(string);
|
SG_USING_STD(string);
|
||||||
|
|
||||||
|
@ -80,13 +83,21 @@ protected:
|
||||||
static FGAIBase *_self;
|
static FGAIBase *_self;
|
||||||
const char *_type_str;
|
const char *_type_str;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
|
|
||||||
|
static double _getVS_fps();
|
||||||
|
static void _setVS_fps( double _vs );
|
||||||
|
|
||||||
|
static double _getAltitude();
|
||||||
|
static void _setAltitude( double _alt );
|
||||||
|
|
||||||
static void _setLongitude( double longitude );
|
static void _setLongitude( double longitude );
|
||||||
static void _setLatitude ( double latitude );
|
static void _setLatitude ( double latitude );
|
||||||
|
|
||||||
static double _getLongitude();
|
static double _getLongitude();
|
||||||
static double _getLatitude ();
|
static double _getLatitude ();
|
||||||
|
|
||||||
|
static bool _isNight();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,19 +109,18 @@ inline void FGAIBase::setSpeed( double speed_KTAS ) {
|
||||||
speed = tgt_speed = speed_KTAS;
|
speed = tgt_speed = speed_KTAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setAltitude( double altitude_ft ) {
|
|
||||||
altitude = tgt_altitude = altitude_ft;
|
|
||||||
pos.setelev(altitude * SG_FEET_TO_METER);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void FGAIBase::setHeading( double heading ) {
|
inline void FGAIBase::setHeading( double heading ) {
|
||||||
hdg = tgt_heading = heading;
|
hdg = tgt_heading = heading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void FGAIBase::setAltitude( double altitude_ft ) {
|
||||||
|
altitude = tgt_altitude = altitude_ft;
|
||||||
|
pos.setelev(altitude * SG_FEET_TO_METER);
|
||||||
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setLongitude( double longitude ) {
|
inline void FGAIBase::setLongitude( double longitude ) {
|
||||||
pos.setlon( longitude );
|
pos.setlon( longitude );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setLatitude ( double latitude ) {
|
inline void FGAIBase::setLatitude ( double latitude ) {
|
||||||
pos.setlat( latitude );
|
pos.setlat( latitude );
|
||||||
}
|
}
|
||||||
|
@ -118,5 +128,29 @@ inline void FGAIBase::setLatitude ( double latitude ) {
|
||||||
inline void FGAIBase::setDie( bool die ) { delete_me = die; }
|
inline void FGAIBase::setDie( bool die ) { delete_me = die; }
|
||||||
inline bool FGAIBase::getDie() { return delete_me; }
|
inline bool FGAIBase::getDie() { return delete_me; }
|
||||||
|
|
||||||
|
inline void FGAIBase::_setLongitude( double longitude ) {
|
||||||
|
_self->pos.setlon(longitude);
|
||||||
|
}
|
||||||
|
inline void FGAIBase::_setLatitude ( double latitude ) {
|
||||||
|
_self->pos.setlat(latitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double FGAIBase::_getLongitude() { return _self->pos.lon(); }
|
||||||
|
inline double FGAIBase::_getLatitude () { return _self->pos.lat(); }
|
||||||
|
|
||||||
|
inline double FGAIBase::_getVS_fps() { return _self->vs*60.0; }
|
||||||
|
inline void FGAIBase::_setVS_fps( double _vs ) { _self->vs = _vs/60.0; }
|
||||||
|
|
||||||
|
inline double FGAIBase::_getAltitude() {
|
||||||
|
return _self->altitude * SG_METER_TO_FEET;
|
||||||
|
}
|
||||||
|
inline void FGAIBase::_setAltitude( double _alt ) {
|
||||||
|
_self->setAltitude( _alt );
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool FGAIBase::_isNight() {
|
||||||
|
return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _FG_AIBASE_HXX
|
#endif // _FG_AIBASE_HXX
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue