#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},
};
+FGAIAircraft *FGAIAircraft::_self = NULL;
+
FGAIAircraft::FGAIAircraft() {
+ _self = this;
// set heading and altitude locks
hdg_lock = false;
FGAIAircraft::~FGAIAircraft() {
+ _self = NULL;
}
void FGAIAircraft::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() {
FGAIBase::unbind();
+
+ props->untie("controls/gear/gear-down");
+// props->getNode("controls/lighting/landing-lights")->unalias();
}
void YawTo(double angle);
void ClimbTo(double altitude);
void TurnTo(double heading);
+
+protected:
+ static FGAIAircraft *_self;
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
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<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",
SGRawValueFunctions<double>(FGAIBase::_getLatitude,
FGAIBase::_setLatitude));
SGRawValueFunctions<double>(FGAIBase::_getLongitude,
FGAIBase::_setLongitude));
- props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
- props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
+ props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
+ props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
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() {
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(); }
#ifndef _FG_AIBASE_HXX
#define _FG_AIBASE_HXX
+#include <string>
+
#include <simgear/constants.h>
#include <simgear/math/point3d.hxx>
#include <simgear/scene/model/placement.hxx>
-#include <string>
+
+#include <Main/fg_props.hxx>
SG_USING_STD(string);
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();
};
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 );
}
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