From 3b5512f573ab0a1fc3ff107db77d5e2f7c2b9a28 Mon Sep 17 00:00:00 2001
From: ehofman <ehofman>
Date: Tue, 19 Apr 2005 12:52:26 +0000
Subject: [PATCH] David Culp:

I'm looking through the AI code, trying to find the bug that's killing the
thermals.  The following things don't look right:

1)  AIManager::101  ,   the Traffic Manager pointer is searched for by name at
every dt.   I'll leave this for you to look at.

2)  AIManager::295  ,  the thermal height is not being set.  We need to
restore the line:         ai_thermal->setHeight(entity->height_msl);
This fixes the thermal problem.

3)  AIManager::328  ,  I changed the fetching of the user state to occur every
sim cycle, and changed the fetching function from by-name lookup to a lookup
by node pointer.  It should be faster now, and more accurate too.  This helps
the air-refueling.
---
 src/AIModel/AIManager.cxx | 28 ++++++++++++++++------------
 src/AIModel/AIManager.hxx |  8 ++++++++
 src/Traffic/Schedule.cxx  |  3 +++
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx
index 6fc225e37..e0dd2aca0 100644
--- a/src/AIModel/AIManager.cxx
+++ b/src/AIModel/AIManager.cxx
@@ -74,6 +74,13 @@ void FGAIManager::init() {
       return;
 
   wind_from_down_node = fgGetNode("/environment/wind-from-down-fps", true);
+  user_latitude_node  = fgGetNode("/position/latitude-deg", true);
+  user_longitude_node = fgGetNode("/position/longitude-deg", true);
+  user_altitude_node  = fgGetNode("/position/altitude-ft", true);
+  user_heading_node   = fgGetNode("/orientation/heading-deg", true);
+  user_pitch_node     = fgGetNode("/orientation/pitch-deg", true);
+  user_yaw_node       = fgGetNode("/orientation/side-slip-deg", true);
+  user_speed_node     = fgGetNode("/velocities/uBody-fps", true);
  
   scenario_filename = root->getNode("scenario", true)->getStringValue();
   if (scenario_filename != "") processScenario( scenario_filename );
@@ -293,6 +300,7 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) {
         ai_thermal->setLatitude(entity->latitude);
         ai_thermal->setMaxStrength(entity->strength);
         ai_thermal->setDiameter(entity->diameter / 6076.11549);
+        ai_thermal->setHeight(entity->height_msl);
         ai_thermal->init();
         ai_thermal->bind();
         ai_list.push_back(ai_thermal);
@@ -315,19 +323,15 @@ void FGAIManager::destroyObject( void* ID ) {
         }
 }
 
-// fetch the user's state every 10 sim cycles
+
 void FGAIManager::fetchUserState( void ) {
-   ++dt_count;
-   if (dt_count == 10) {
-     user_latitude  = fgGetDouble("/position/latitude-deg");
-     user_longitude = fgGetDouble("/position/longitude-deg");
-     user_altitude  = fgGetDouble("/position/altitude-ft");
-     user_heading   = fgGetDouble("/orientation/heading-deg");
-     user_pitch     = fgGetDouble("/orientation/pitch-deg");
-     user_yaw       = fgGetDouble("/orientation/side-slip-deg");
-     user_speed     = fgGetDouble("/velocities/uBody-fps") * 0.592484;
-     dt_count = 0;
-   }
+     user_latitude  = user_latitude_node->getDoubleValue();
+     user_longitude = user_longitude_node->getDoubleValue();
+     user_altitude  = user_altitude_node->getDoubleValue();
+     user_heading   = user_heading_node->getDoubleValue();
+     user_pitch     = user_pitch_node->getDoubleValue();
+     user_yaw       = user_yaw_node->getDoubleValue();
+     user_speed     = user_speed_node->getDoubleValue() * 0.592484;
 }
 
 
diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx
index 9874859aa..cc18831ab 100644
--- a/src/AIModel/AIManager.hxx
+++ b/src/AIModel/AIManager.hxx
@@ -114,6 +114,14 @@ private:
     int numObjects[FGAIBase::MAX_OBJECTS];
     SGPropertyNode* root;
     SGPropertyNode* wind_from_down_node;
+    SGPropertyNode* user_latitude_node;
+    SGPropertyNode* user_longitude_node;
+    SGPropertyNode* user_altitude_node;
+    SGPropertyNode* user_heading_node;
+    SGPropertyNode* user_pitch_node;
+    SGPropertyNode* user_yaw_node;
+    SGPropertyNode* user_speed_node;
+
     string scenario_filename;
 
     double user_latitude;
diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx
index 2bb86393e..a643c8eb7 100644
--- a/src/Traffic/Schedule.cxx
+++ b/src/Traffic/Schedule.cxx
@@ -391,6 +391,9 @@ bool FGAISchedule::update(time_t now)
 	  return true;
 	} 
     }
+
+    // EMH: prevent a warning, should this be 'true' instead?
+    return false;
 }