]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIThermal.cxx
assign a unique module name to ai/mp embedded nasal (again): __model%u
[flightgear.git] / src / AIModel / AIThermal.cxx
index a8fd777b209901e3304585d638bb1f983e6ae0c3..e9ad927a137e24fc4aedb4fda5364d63e9200dc1 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-#include <simgear/math/point3d.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
 #include <string>
 #include <math.h>
 
-SG_USING_STD(string);
+using std::string;
 
 #include "AIThermal.hxx"
 
 
-FGAIThermal::FGAIThermal(FGAIManager* mgr) {
-   manager = mgr;   
-   _type_str = "thermal";
-   _otype = otThermal;
+FGAIThermal::FGAIThermal() : FGAIBase(otThermal) {
    max_strength = 6.0;
    diameter = 0.5;
    strength = factor = 0.0;
 }
 
-
 FGAIThermal::~FGAIThermal() {
 }
 
+void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
+  if (!scFileNode)
+    return;
+
+  FGAIBase::readFromScenario(scFileNode);
 
-bool FGAIThermal::init() {
+  setMaxStrength(scFileNode->getDoubleValue("strength-fps", 8.0)); 
+  setDiameter(scFileNode->getDoubleValue("diameter-ft", 0.0)/6076.11549);
+  setHeight(scFileNode->getDoubleValue("height-msl", 5000.0));
+}
+
+bool FGAIThermal::init(bool search_in_AI_path) {
    factor = 8.0 * max_strength / (diameter * diameter * diameter);
-   return FGAIBase::init();
+   setAltitude( height );
+   return FGAIBase::init(search_in_AI_path);
 }
 
 void FGAIThermal::bind() {
@@ -71,8 +77,6 @@ void FGAIThermal::update(double dt) {
 
 void FGAIThermal::Run(double dt) {
 
-   FGAIThermal::dt = dt;
-       
    //###########################//
    // do calculations for range //
    //###########################//
@@ -80,11 +84,11 @@ 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 lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat;
+   double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon;
    double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
    range = range_ft / 6076.11549;
 
@@ -96,5 +100,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);
+   }
 }