]> git.mxchange.org Git - flightgear.git/commitdiff
Make the AI models a bit more intelligent. The Gear should be extended and retracted...
authorehofman <ehofman>
Thu, 22 Jan 2004 21:13:47 +0000 (21:13 +0000)
committerehofman <ehofman>
Thu, 22 Jan 2004 21:13:47 +0000 (21:13 +0000)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx

index afe8663ad8b078fc433a619b80aeba9ba20f90c9..66360d8a5c567f8da131a4db8b598393b69e3e54 100644 (file)
@@ -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<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();
 }
 
 
index 8cf2a40364c53be58b0085269e13dd9fb448d8d2..8d16f381e57136aa1134af72c1dad05750d40c30 100644 (file)
@@ -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
index e5d63821501fe4bcf28abf4c121d246c15d3dcb9..0ee8c8d9528d2df793cdb3a7c2d53fd7763dfa96 100644 (file)
@@ -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<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));
@@ -100,9 +106,14 @@ void FGAIBase::bind() {
                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() {
@@ -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(); }
index 412a6c20b84f0773b6fa4d3ee0b68f65534bd72a..8e9e7618543881c0781d33d6309d692482483e3a 100644 (file)
 #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);
 
@@ -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