From 863b0c943251fae620406ec8983e5f69e1424731 Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 22 Jan 2004 21:13:47 +0000 Subject: [PATCH] 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. --- src/AIModel/AIAircraft.cxx | 20 ++++++++++++++- src/AIModel/AIAircraft.hxx | 13 ++++++++++ src/AIModel/AIBase.cxx | 31 +++++++++++------------ src/AIModel/AIBase.hxx | 50 ++++++++++++++++++++++++++++++++------ 4 files changed, 90 insertions(+), 24 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index afe8663ad..66360d8a5 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -33,7 +33,10 @@ SG_USING_STD(string); #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[] = { // light aircraft {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() { + _self = this; // set heading and altitude locks hdg_lock = false; @@ -56,6 +62,7 @@ FGAIAircraft::FGAIAircraft() { FGAIAircraft::~FGAIAircraft() { + _self = NULL; } @@ -65,10 +72,21 @@ bool FGAIAircraft::init() { void FGAIAircraft::bind() { FGAIBase::bind(); + + props->tie("controls/gear/gear-down", + SGRawValueFunctions(FGAIAircraft::_getGearDown)); + +/* + props->getNode("controls/lighting/landing-lights", true) + ->alias("controls/gear/gear-down"); +*/ } void FGAIAircraft::unbind() { FGAIBase::unbind(); + + props->untie("controls/gear/gear-down"); +// props->getNode("controls/lighting/landing-lights")->unalias(); } diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 8cf2a4036..8d16f381e 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -64,6 +64,9 @@ public: void YawTo(double angle); void ClimbTo(double altitude); void TurnTo(double heading); + +protected: + static FGAIAircraft *_self; private: @@ -76,6 +79,16 @@ private: void Run(double dt); 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 diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index e5d638215..0ee8c8d95 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -86,13 +86,19 @@ bool FGAIBase::init() { tgt_roll = tgt_pitch = tgt_yaw = tgt_vs = vs = roll = pitch = 0.0; setDie(false); + + return true; } void FGAIBase::bind() { props->tie("velocities/airspeed-kt", SGRawValuePointer(&speed)); - props->tie("velocities/vertical-speed-fps", SGRawValuePointer(&vs)); + props->tie("velocities/vertical-speed-fps", + SGRawValueFunctions(FGAIBase::_getVS_fps, + FGAIBase::_setVS_fps)); - props->tie("position/altitude-ft", SGRawValuePointer(&altitude)); + props->tie("position/altitude-ft", + SGRawValueFunctions(FGAIBase::_getAltitude, + FGAIBase::_setAltitude)); props->tie("position/latitude-deg", SGRawValueFunctions(FGAIBase::_getLatitude, FGAIBase::_setLatitude)); @@ -100,9 +106,14 @@ void FGAIBase::bind() { SGRawValueFunctions(FGAIBase::_getLongitude, FGAIBase::_setLongitude)); - props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); - props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); + props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); + props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); props->tie("orientation/heading-deg", SGRawValuePointer(&hdg)); + + props->tie("controls/lighting/nav-lights", + SGRawValueFunctions(FGAIBase::_isNight)); + props->setBoolValue("controls/lighting/beacon", true); + props->setBoolValue("controls/lighting/strobe", true); } void FGAIBase::unbind() { @@ -116,17 +127,7 @@ void FGAIBase::unbind() { props->untie("orientation/pitch-deg"); props->untie("orientation/roll-deg"); props->untie("orientation/heading-deg"); -} - -void FGAIBase::_setLongitude( double longitude ) { - _self->pos.setlon(longitude); + props->untie("controls/controls/lighting/nav-lights"); } -void FGAIBase::_setLatitude ( double latitude ) { - _self->pos.setlat(latitude); -} - -double FGAIBase::_getLongitude() { return _self->pos.lon(); } - -double FGAIBase::_getLatitude () { return _self->pos.lat(); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 412a6c20b..8e9e76185 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -20,10 +20,13 @@ #ifndef _FG_AIBASE_HXX #define _FG_AIBASE_HXX +#include + #include #include #include -#include + +#include
SG_USING_STD(string); @@ -80,13 +83,21 @@ protected: static FGAIBase *_self; 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 _setLatitude ( double latitude ); + static double _getLongitude(); static double _getLatitude (); + static bool _isNight(); }; @@ -98,19 +109,18 @@ inline void FGAIBase::setSpeed( double 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 ) { 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 ) { pos.setlon( longitude ); } - inline void FGAIBase::setLatitude ( double latitude ) { pos.setlat( latitude ); } @@ -118,5 +128,29 @@ inline void FGAIBase::setLatitude ( double latitude ) { inline void FGAIBase::setDie( bool die ) { delete_me = die; } 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 -- 2.39.2