]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
Make the vertical acceleration rate scale with vertical performance. The
[flightgear.git] / src / AIModel / AIManager.cxx
index af7e334ee7ac0e7198d829c7f7df544f7099dfef..207913bb1ff5aae959e33dc829126c7c8c79ddb2 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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.
 
 #include <Main/globals.hxx>
 
 #include "AIMultiplayer.hxx"
 
 FGAIManager::FGAIManager() {
-  for (int i=0; i < FGAIBase::MAX_OBJECTS; i++)
-     numObjects[i] = 0;
   _dt = 0.0;
-  scenario_filename = "";
+  mNumAiModels = 0;
+  for (unsigned i = 0; i < FGAIBase::MAX_OBJECTS; ++i)
+    mNumAiTypeModels[i] = 0;
 }
 
 FGAIManager::~FGAIManager() {
@@ -88,7 +88,8 @@ void FGAIManager::reinit() {
 
 void FGAIManager::bind() {
    root = globals->get_props()->getNode("ai/models", true);
-   root->tie("count", SGRawValuePointer<int>(&numObjects[0]));
+   root->tie("count", SGRawValueMethods<FGAIManager, int>(*this,
+             &FGAIManager::getNumAiObjects));
 }
 
 
@@ -98,71 +99,71 @@ void FGAIManager::unbind() {
 
 
 void FGAIManager::update(double dt) {
+  // initialize these for finding nearest thermals
+  range_nearest = 10000.0;
+  strength = 0.0;
+  if (!enabled)
+    return;
 
-        // initialize these for finding nearest thermals
-        range_nearest = 10000.0;
-        strength = 0.0;
-       FGTrafficManager *tmgr = (FGTrafficManager*) globals->get_subsystem("Traffic Manager");
-
-        if (!enabled)
-            return;
-
-        _dt = dt;
-
-        ai_list_iterator ai_list_itr = ai_list.begin();
-        while(ai_list_itr != ai_list.end()) {
-                if ((*ai_list_itr)->getDie()) {      
-                 tmgr->release((*ai_list_itr)->getID());
-                   --numObjects[(*ai_list_itr)->getType()];
-                   --numObjects[0];
-                   (*ai_list_itr)->unbind();
-                   if ( ai_list_itr == ai_list.begin() ) {
-                       ai_list.erase(ai_list_itr);
-                       ai_list_itr = ai_list.begin();
-                       continue;
-                   } else {
-                       ai_list.erase(ai_list_itr--);
-                   }
-                } else {
-                   fetchUserState();
-                   if ((*ai_list_itr)->isa(FGAIBase::otThermal)) {
-                       FGAIBase *base = *ai_list_itr;
-                       processThermal((FGAIThermal*)base); 
-                   } else { 
-                      (*ai_list_itr)->update(_dt);
-                   }
-                }
-                ++ai_list_itr;
-        }
-        wind_from_down_node->setDoubleValue( strength ); // for thermals
+  FGTrafficManager *tmgr = (FGTrafficManager*) globals->get_subsystem("Traffic Manager");
+  _dt = dt;
+
+  ai_list_iterator ai_list_itr = ai_list.begin();
+  while(ai_list_itr != ai_list.end()) {
+    if ((*ai_list_itr)->getDie()) {      
+      tmgr->release((*ai_list_itr)->getID());
+      --mNumAiModels;
+      --(mNumAiTypeModels[(*ai_list_itr)->getType()]);
+      (*ai_list_itr)->unbind();
+      ai_list_itr = ai_list.erase(ai_list_itr);
+    } else {
+      fetchUserState();
+      if ((*ai_list_itr)->isa(FGAIBase::otThermal)) {
+        FGAIBase *base = *ai_list_itr;
+        processThermal((FGAIThermal*)base); 
+      } else { 
+        (*ai_list_itr)->update(_dt);
+      }
+      ++ai_list_itr;
+    }
+  }
+  wind_from_down_node->setDoubleValue( strength ); // for thermals
 }
 
 void
 FGAIManager::attach(SGSharedPtr<FGAIBase> model)
 {
-  model->setManager(this);
+  unsigned idx = mNumAiTypeModels[model->getType()];
+  const char* typeString = model->getTypeString();
+  SGPropertyNode* root = globals->get_props()->getNode("ai/models", true);
+  SGPropertyNode* p = root->getNode(typeString, idx, true);
+  model->setManager(this, p);
   ai_list.push_back(model);
-  ++numObjects[0];
-  ++numObjects[model->getType()];
+  ++mNumAiModels;
+  ++(mNumAiTypeModels[model->getType()]);
   model->init();
   model->bind();
 }
 
 
 void FGAIManager::destroyObject( int ID ) {
-        ai_list_iterator ai_list_itr = ai_list.begin();
-        while(ai_list_itr != ai_list.end()) {
-            if ((*ai_list_itr)->getID() == ID) {
-              --numObjects[0];
-              --numObjects[(*ai_list_itr)->getType()];
-              (*ai_list_itr)->unbind();
-              ai_list.erase(ai_list_itr);
-              break;
-            }
-            ++ai_list_itr;
-        }
+  ai_list_iterator ai_list_itr = ai_list.begin();
+  while(ai_list_itr != ai_list.end()) {
+    if ((*ai_list_itr)->getID() == ID) {
+      --mNumAiModels;
+      --(mNumAiTypeModels[(*ai_list_itr)->getType()]);
+      (*ai_list_itr)->unbind();
+      ai_list_itr = ai_list.erase(ai_list_itr);
+    } else
+      ++ai_list_itr;
+  }
 }
 
+int
+FGAIManager::getNumAiObjects(void) const
+{
+  return mNumAiModels;
+}
 
 void FGAIManager::fetchUserState( void ) {
      user_latitude  = user_latitude_node->getDoubleValue();
@@ -174,8 +175,6 @@ void FGAIManager::fetchUserState( void ) {
      user_speed     = user_speed_node->getDoubleValue() * 0.592484;
      wind_from_east = wind_from_east_node->getDoubleValue();
      wind_from_north = wind_from_north_node->getDoubleValue();
-     
-     
 }
 
 
@@ -278,8 +277,7 @@ void FGAIManager::setModel(const string& path, ssgBranch *model)
 }
 
 bool FGAIManager::getStartPosition(const string& id, const string& pid,
-                                   Point3D& geodPos, double& heading,
-                                   sgdVec3 uvw)
+                                   SGGeod& geodPos, double& hdng, SGVec3d& uvw)
 {
   bool found = false;
   SGPropertyNode* root = fgGetNode("sim/ai", true);
@@ -303,7 +301,7 @@ bool FGAIManager::getStartPosition(const string& id, const string& pid,
               SGSharedPtr<FGAICarrier> carrier = new FGAICarrier;
               carrier->readFromScenario(scEntry);
               
-              if (carrier->getParkPosition(pid, geodPos, heading, uvw)) {
+              if (carrier->getParkPosition(pid, geodPos, hdng, uvw)) {
                 found = true;
                 break;
               }