]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
Make the scenerio's work again (now for real) and a small number of updates.
[flightgear.git] / src / AIModel / AIManager.cxx
index 722da5aaa7cba556c65925097d186813b4a9ad75..e066b5a09135417219599e94b6550238c14cf843 100644 (file)
@@ -47,6 +47,7 @@ FGAIManager::FGAIManager() {
 FGAIManager::~FGAIManager() {
   ai_list_itr = ai_list.begin();
   while(ai_list_itr != ai_list.end()) {
+      (*ai_list_itr)->unbind();
       delete (*ai_list_itr);
       ++ai_list_itr;
     }
@@ -64,8 +65,8 @@ void FGAIManager::init() {
   wind_from_down_node = fgGetNode("/environment/wind-from-down-fps", true);
  
   scenario_filename = root->getNode("scenario", true)->getStringValue();
-
   if (scenario_filename != "") processScenario( scenario_filename );
+
   initDone = true;
 }
 
@@ -90,13 +91,14 @@ void FGAIManager::update(double dt) {
         if (!enabled)
             return;
 
-        _dt = dt;      
+        _dt = dt;
 
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
                 if ((*ai_list_itr)->getDie()) {      
                    --numObjects[(*ai_list_itr)->getType()];
                    --numObjects[0];
+                   (*ai_list_itr)->unbind();
                    delete (*ai_list_itr);
                    if ( ai_list_itr == ai_list.begin() ) {
                        ai_list.erase(ai_list_itr);
@@ -203,6 +205,8 @@ FGAIManager::createBallistic( FGAIModelEntity *entity ) {
         ai_ballistic->setWind_from_north(entity->wind_from_north);
         ai_ballistic->setWind(entity->wind);
         ai_ballistic->setRoll(entity->roll);
+        ai_ballistic->setCd(entity->cd);
+        ai_ballistic->setWeight(entity->weight);
         ai_ballistic->init();
         ai_ballistic->bind();
         return ai_ballistic;
@@ -212,7 +216,6 @@ void*
 FGAIManager::createStorm( FGAIModelEntity *entity ) {
 
         FGAIStorm* ai_storm = new FGAIStorm(this);
-        ai_list.push_back(ai_storm);
         ++numObjects[0];
         ++numObjects[FGAIBase::otStorm];
         ai_storm->setHeading(entity->heading);
@@ -223,6 +226,7 @@ FGAIManager::createStorm( FGAIModelEntity *entity ) {
         ai_storm->setLatitude(entity->latitude);
         ai_storm->init();
         ai_storm->bind();
+        ai_list.push_back(ai_storm);
         return ai_storm;
 }
 
@@ -230,7 +234,6 @@ void*
 FGAIManager::createThermal( FGAIModelEntity *entity ) {
 
         FGAIThermal* ai_thermal = new FGAIThermal(this);
-        ai_list.push_back(ai_thermal);
         ++numObjects[0];
         ++numObjects[FGAIBase::otThermal];
         ai_thermal->setLongitude(entity->longitude);
@@ -239,6 +242,7 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) {
         ai_thermal->setDiameter(entity->diameter / 6076.11549);
         ai_thermal->init();
         ai_thermal->bind();
+        ai_list.push_back(ai_thermal);
         return ai_thermal;
 }
 
@@ -248,6 +252,7 @@ void FGAIManager::destroyObject( void* ID ) {
             if ((*ai_list_itr)->getID() == ID) {
               --numObjects[0];
               --numObjects[(*ai_list_itr)->getType()];
+              (*ai_list_itr)->unbind();
               delete (*ai_list_itr);
               ai_list.erase(ai_list_itr);
 
@@ -283,31 +288,25 @@ void FGAIManager::processThermal( FGAIThermal* thermal ) {
 }
 
 
-void FGAIManager::processScenario( string filename ) {
+void FGAIManager::processScenario( string &filename ) {
   FGAIScenario* s = new FGAIScenario( filename );
-
   for (int i=0;i<s->nEntries();i++) {
     FGAIModelEntity* en = s->getNextEntry();
 
     if (en) {
-      en->fp = NULL;
-      if (en->flightplan != ""){
-        en->fp = new FGAIFlightPlan( en->flightplan );
-      }
-      if (en->m_class == "aircraft") {
+      if ( !strcmp(en->m_type, "aircraft")) {
          createAircraft( en );
 
-      } else if (en->m_class == "ship") {
+      } else if ( !strcmp(en->m_type, "ship")) {
            createShip( en );
 
-      } else if (en->m_class == "storm") {
+      } else if ( !strcmp(en->m_type, "thunderstorm")) {
         createStorm( en );
 
-      } else if (en->m_class == "thermal") {
+      } else if ( !strcmp(en->m_type, "thermal")) {
         createThermal( en );
 
-      } else if (en->m_class == "ballistic") {
+      } else if ( !strcmp(en->m_type, "ballistic")) {
         createBallistic( en );
       }      
     }
@@ -316,3 +315,4 @@ void FGAIManager::processScenario( string filename ) {
   delete s;
 }
 
+//end AIManager.cxx