]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIThermal.cxx
apt.dat parser: clearer log and exception messages
[flightgear.git] / src / AIModel / AIThermal.cxx
index da9987fb8b65524929e9897b9775cba1cb66de5f..4e8e63b2e43d9c326d22358d08ce8eae9da4873c 100644 (file)
@@ -1,6 +1,6 @@
 // FGAIThermal - FGAIBase-derived class creates an AI thermal
 //
-// Original by Written by David Culp
+// Copyright (C) 2004  David P. Culp - davidculp2@comcast.net
 //
 // An attempt to refine the thermal shape and behaviour by WooT 2009
 //
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
 #include <string>
-#include <math.h>
+#include <cmath>
 
 using std::string;
 
 #include "AIThermal.hxx"
 
 
-FGAIThermal::FGAIThermal() : FGAIBase(otThermal) {
+FGAIThermal::FGAIThermal() :
+   FGAIBase(otThermal, false)
+{
    max_strength = 6.0;
    diameter = 0.5;
    strength = factor = 0.0;
@@ -75,38 +77,25 @@ bool FGAIThermal::init(bool search_in_AI_path) {
 }
 
 void FGAIThermal::bind() {
-       props->tie("position/altitude-agl-ft", // for debug and tweak
+    FGAIBase::bind();
+    tie("position/altitude-agl-ft", // for debug and tweak
                 SGRawValuePointer<double>(&altitude_agl_ft));
-       props->tie("alt-rel", // for debug and tweak
+    tie("alt-rel", // for debug and tweak
                 SGRawValuePointer<double>(&alt_rel));
-       props->tie("time", // for debug and tweak
+    tie("time", // for debug and tweak
                 SGRawValuePointer<double>(&time));
-       props->tie("xx", // for debug and tweak
+    tie("xx", // for debug and tweak
                 SGRawValuePointer<double>(&xx));
-       props->tie("is-forming", // for debug abd tweak
+    tie("is-forming", // for debug abd tweak
                 SGRawValuePointer<bool>(&is_forming));
-       props->tie("is-formed", // for debug abd tweak
+    tie("is-formed", // for debug abd tweak
                 SGRawValuePointer<bool>(&is_formed));
-       props->tie("is-dying", // for debug abd tweak
+    tie("is-dying", // for debug abd tweak
                 SGRawValuePointer<bool>(&is_dying));
-       props->tie("is-dead", // for debug abd tweak
+    tie("is-dead", // for debug abd tweak
                 SGRawValuePointer<bool>(&is_dead));
-    FGAIBase::bind();
-}
-
-void FGAIThermal::unbind() {
-       props->untie("position/altitude-agl-ft");
-       props->untie("alt-rel");
-       props->untie("time");   
-       props->untie("is-forming");
-       props->untie("is-formed");
-       props->untie("is-dying");
-       props->untie("is-dead");
-       props->untie("xx");
-    FGAIBase::unbind();
 }
 
-
 void FGAIThermal::update(double dt) {
    FGAIBase::update(dt);
    Run(dt);
@@ -120,27 +109,23 @@ void FGAIThermal::update(double dt) {
 double FGAIThermal::get_strength_fac(double alt_frac) {
 
 double PI = 4.0 * atan(1.0);
-double fac;
+double fac = 0.0;
 if ( alt_frac <=0.0 ) { // do submarines get thermals ?
        fac = 0.0;
-       return fac;
        }
 else if ( ( alt_frac>0.0 ) && (alt_frac<=0.1) ) { // ground layer
        fac = ( 0.1*( pow( (10.0*alt_frac),10.0) ) );
-       return fac;
        }
 else if ( ( alt_frac>0.1 ) && (alt_frac<=1.0) ) {   // main body of the thermal
        fac = 0.4175 - 0.5825* ( cos ( PI*  (1.0-sqrt(alt_frac) ) +PI) ) ;
-       return fac;
        }
 else if ( ( alt_frac >1.0 ) && (alt_frac < 1.1 ) ) {  //above the ceiling, but not above the cloud
        fac = (0.5 * ( 1.0 + cos ( PI*( (-2.0*alt_frac)*5.0 ) ) ) );
-       return fac;
        }
 else if ( alt_frac >= 1.1 ) {  //above the cloud
        fac = 0.0;
-       return fac;
        }
+return fac;
 }
 
 
@@ -216,14 +201,6 @@ double slice_center_lat;
 
 
 
-// **************************************
-// various variables relative to the user
-// **************************************
-
-double user_latitude  = manager->get_user_latitude();
-double user_longitude = manager->get_user_longitude();
-double user_altitude  = manager->get_user_altitude(); // MSL
-
 //we need to know the thermal foot AGL altitude
 
 
@@ -233,7 +210,7 @@ double user_altitude  = manager->get_user_altitude(); // MSL
 dt_count += dt;
 if (dt_count >= 10.0 ) {
        //double alt;
-       if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(pos, 20000), alt, 0)){    
+       if (getGroundElevationM(SGGeod::fromGeodM(pos, 20000), alt, 0)) {
        ground_elev_ft =  alt * SG_METER_TO_FEET;
        do_agl_calc = 0;
        altitude_agl_ft = height - ground_elev_ft ;
@@ -242,6 +219,9 @@ if (dt_count >= 10.0 ) {
 }
 
 //user altitude relative to the thermal height, seen AGL from the thermal foot
+    
+
+double user_altitude = globals->get_aircraft_position().getElevationFt();
 if ( user_altitude < 1.0 ) { user_altitude = 1.0 ;}; // an ugly way to avoid NaNs for users at alt 0
 double user_altitude_agl= ( user_altitude - ground_elev_ft ) ;
 alt_rel = user_altitude_agl / altitude_agl_ft;
@@ -255,12 +235,7 @@ double Vup;
 // environment variables
 // *********************
 
-// the  windspeed at the user alt in KT
-double windspeed;
-
 // the  wind heading at the user alt
-double wind_heading;
-double wind_heading_deg;
 double wind_heading_rad;
 
 // the "ambient" sink outside thermals
@@ -363,14 +338,9 @@ double dt_slice_lat = dt_slice_lat_FT / ft_per_deg_lat;
 slice_center_lon = thermal_foot_lon + dt_slice_lon;
 slice_center_lat = thermal_foot_lat + dt_slice_lat;
 
-double dist_center_lon = fabs(slice_center_lon - user_longitude)* ft_per_deg_lon;
-double dist_center_lat = fabs(slice_center_lat - user_latitude)* ft_per_deg_lat;
-
-double dist_center_FT = sqrt ( dist_center_lon*dist_center_lon + dist_center_lat*dist_center_lat ); // feet
-
-dist_center = dist_center_FT/ 6076.11549; //nautic miles
-
-
+dist_center = SGGeodesy::distanceNm(SGGeod::fromDeg(slice_center_lon, slice_center_lat),
+                                    globals->get_aircraft_position());
+    
 // Now we can calculate Vup
 
 if ( max_strength >=0.0 ) { // this is a thermal