]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIThermal.cxx
Mathias Fröhölöiööhlich:
[flightgear.git] / src / AIModel / AIThermal.cxx
index c94a6e22cc1ef2606e4bf9f6d7fbe1154bb42d14..c3d2def1c32375ba74eda9039913e95d158dae02 100644 (file)
@@ -63,9 +63,9 @@ void FGAIThermal::unbind() {
 
 
 void FGAIThermal::update(double dt) {
+   FGAIBase::update(dt);
    Run(dt);
    Transform();
-   FGAIBase::update(dt);
 }
 
 
@@ -73,15 +73,6 @@ void FGAIThermal::Run(double dt) {
 
    FGAIThermal::dt = dt;
        
-   double ft_per_deg_lon;
-   double ft_per_deg_lat;
-
-   // get size of a degree at this latitude
-   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);
-
-   // double altitude_ft = altitude * SG_METER_TO_FEET;
-
    //###########################//
    // do calculations for range //
    //###########################//
@@ -89,12 +80,12 @@ void FGAIThermal::Run(double dt) {
    // copy values from the AIManager
    double user_latitude  = manager->get_user_latitude();
    double user_longitude = manager->get_user_longitude();
-   // double user_altitude  = manager->get_user_altitude();
+   double user_altitude  = manager->get_user_altitude();
 
    // calculate range to target in feet and nautical miles
    double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
    double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
-   double range_ft = sqrt( lat_range*lat_range + lon_range*lon_range );
+   double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
    range = range_ft / 6076.11549;
 
    // Calculate speed of rising air if within range. 
@@ -105,5 +96,16 @@ void FGAIThermal::Run(double dt) {
    } else {
      strength = 0.0;
    }
+
+   // Stop lift at the top of the thermal (smoothly)
+   if (user_altitude > (height + 100.0)) {
+     strength = 0.0;
+   }
+   else if (user_altitude < height) {
+     // do nothing
+   }
+   else {
+     strength -= (strength * (user_altitude - height) * 0.01);
+   }
 }