]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
ignore resets for now because every z/Z key press would trigger a call to NOAA. We...
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 010eaffc3dbad609c1f2aedb844c09f45daa2a4d..66360d8a5c567f8da131a4db8b598393b69e3e54 100644 (file)
@@ -33,15 +33,36 @@ 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},
+    // ww2_fighter
+    {4.0, 2.0, 3000.0, 1500.0, 110.0, 180.0, 250.0, 200.0, 100.0},
+    // jet_transport
+    {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0},
+    // jet_fighter
+    {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0}
+};
+
+
+FGAIAircraft *FGAIAircraft::_self = NULL;
+
 FGAIAircraft::FGAIAircraft() {
+   _self = this;
 
    // set heading and altitude locks
    hdg_lock = false;
    alt_lock = false;
+   _type_str = "aircraft";
 }
 
 
 FGAIAircraft::~FGAIAircraft() {
+    _self = NULL;
 }
 
 
@@ -49,6 +70,25 @@ bool FGAIAircraft::init() {
    return FGAIBase::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();
+}
+
 
 void FGAIAircraft::update(double dt) {
 
@@ -57,7 +97,7 @@ void FGAIAircraft::update(double dt) {
    FGAIBase::update(dt);
 }
 
-void FGAIAircraft::SetPerformance(PERF_STRUCT ps) {
+void FGAIAircraft::SetPerformance(const PERF_STRUCT *ps) {
    
    performance = ps;
 } 
@@ -77,19 +117,21 @@ void FGAIAircraft::Run(double dt) {
    double alpha;
 
    // get size of a degree at this latitude
-   ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat() / 57.2958 );
-   ft_per_deg_lon = 365228.16 * cos(pos.lat() / 57.2958);
+   ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()/SG_RADIANS_TO_DEGREES);
+   ft_per_deg_lon = 365228.16 * cos(pos.lat() / SG_RADIANS_TO_DEGREES);
 
    // adjust speed
    double speed_diff = tgt_speed - speed;
    if (fabs(speed_diff) > 0.2) {
-     if (speed_diff > 0.0) speed += performance.accel * dt;
-     if (speed_diff < 0.0) speed -= performance.decel * dt;
+     if (speed_diff > 0.0) speed += performance->accel * dt;
+     if (speed_diff < 0.0) speed -= performance->decel * dt;
    } 
    
    // convert speed to degrees per second
-   speed_north_deg_sec = cos( hdg / 57.29577951 ) * speed * 1.686 / ft_per_deg_lat;
-   speed_east_deg_sec  = sin( hdg / 57.29577951 ) * speed * 1.686 / ft_per_deg_lon;
+   speed_north_deg_sec = cos( hdg / SG_RADIANS_TO_DEGREES )
+                          * speed * 1.686 / ft_per_deg_lat;
+   speed_east_deg_sec  = sin( hdg / SG_RADIANS_TO_DEGREES )
+                          * speed * 1.686 / ft_per_deg_lon;
 
    // set new position
    pos.setlat( pos.lat() + speed_north_deg_sec * dt);
@@ -97,8 +139,9 @@ void FGAIAircraft::Run(double dt) {
 
    // adjust heading based on current bank angle
    if (roll != 0.0) {
-     turn_radius_ft = 0.088362 * speed * speed / tan( fabs(roll) / 57.2958 );
-     turn_circum_ft = 6.2831853 * turn_radius_ft;
+     turn_radius_ft = 0.088362 * speed * speed
+                       / tan( fabs(roll) / SG_RADIANS_TO_DEGREES );
+     turn_circum_ft = SGD_2PI * turn_radius_ft;
      dist_covered_ft = speed * 1.686 * dt; 
      alpha = dist_covered_ft / turn_circum_ft * 360.0;
      hdg += alpha * sign( roll );
@@ -129,17 +172,19 @@ void FGAIAircraft::Run(double dt) {
    }
 
    // adjust altitude (meters) based on current vertical speed (fpm)
-   altitude += vs * 0.0166667 * dt * 0.3048;  
+   altitude += vs * 0.0166667 * dt * SG_FEET_TO_METER;  
 
    // find target vertical speed if altitude lock engaged
    if (alt_lock) {
-     double altitude_ft = altitude * 3.28084;
+     double altitude_ft = altitude * SG_METER_TO_FEET;
      if (altitude_ft < tgt_altitude) {
-      tgt_vs = tgt_altitude - altitude_ft;
-      if (tgt_vs > performance.climb_rate) tgt_vs = performance.climb_rate;
+       tgt_vs = tgt_altitude - altitude_ft;
+       if (tgt_vs > performance->climb_rate)
+         tgt_vs = performance->climb_rate;
      } else {
-      tgt_vs = tgt_altitude - altitude_ft;
-      if (tgt_vs  < (-performance.descent_rate)) tgt_vs = -performance.descent_rate;
+       tgt_vs = tgt_altitude - altitude_ft;
+       if (tgt_vs  < (-performance->descent_rate))
+         tgt_vs = -performance->descent_rate;
      }
    }