]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIManager.cxx
Make the AI models a bit more intelligent. The Gear should be extended and retracted...
[flightgear.git] / src / AIModel / AIManager.cxx
index 08c215aa7ed3642cbae26194ed9ca499d042eb84..1b39b9afa317f3ea893c69d8de26ee06cd7bff1c 100644 (file)
@@ -37,35 +37,34 @@ FGAIManager::FGAIManager() {
 }
 
 FGAIManager::~FGAIManager() {
-  ai_list_itr = ai_list.begin();
-  while(ai_list_itr != ai_list.end()) {
-    delete (*ai_list_itr);
-    ++ai_list_itr;
-  }
   ai_list.clear();
 }
 
 void FGAIManager::init() {
   SGPropertyNode * node = fgGetNode("sim/ai", true);
+
   for (int i = 0; i < node->nChildren(); i++) {
     const SGPropertyNode * entry = node->getChild(i);
+
     if (!strcmp(entry->getName(), "entry")) {
       if (!strcmp(entry->getStringValue("type", ""), "aircraft")) { 
         FGAIAircraft* ai_plane = new FGAIAircraft;
         ai_list.push_back(ai_plane);
-        if (!strcmp(entry->getStringValue("class", ""), "light")) {
-          PERF_STRUCT ps = {2.0, 2.0, 450.0, 1000.0, 70.0, 80.0, 100.0, 80.0, 60.0};
-          ai_plane->SetPerformance(ps);
-        } else if (!strcmp(entry->getStringValue("class", ""), "ww2_fighter")) {
-          PERF_STRUCT ps = {4.0, 2.0, 3000.0, 1500.0, 110.0, 180.0, 250.0, 200.0, 100.0};
-          ai_plane->SetPerformance(ps);
-        } else if (!strcmp(entry->getStringValue("class", ""), "jet_transport")) {
-          PERF_STRUCT ps = {5.0, 2.0, 3000.0, 1500.0, 140.0, 300.0, 430.0, 300.0, 130.0};
-          ai_plane->SetPerformance(ps);
-        } else if (!strcmp(entry->getStringValue("class", ""), "jet_fighter")) {
-          PERF_STRUCT ps = {7.0, 3.0, 4000.0, 2000.0, 150.0, 350.0, 500.0, 350.0, 150.0};
-          ai_plane->SetPerformance(ps);
+
+        string model_class = entry->getStringValue("class", "");
+        if (model_class == "light") {
+          ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::LIGHT]);
+
+        } else if (model_class == "ww2_fighter") {
+          ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::WW2_FIGHTER]);
+
+        } else if (model_class ==  "jet_transport") {
+          ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
+
+        } else if (model_class == "jet_fighter") {
+          ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_FIGHTER]);
         }
+
         ai_plane->setHeading(entry->getDoubleValue("heading"));
         ai_plane->setSpeed(entry->getDoubleValue("speed-KTAS"));
         ai_plane->setPath(entry->getStringValue("path"));
@@ -73,6 +72,7 @@ void FGAIManager::init() {
         ai_plane->setLongitude(entry->getDoubleValue("longitude"));
         ai_plane->setLatitude(entry->getDoubleValue("latitude"));
         ai_plane->init();
+        ai_plane->bind();
 
       } else if (!strcmp(entry->getStringValue("type", ""), "ship")) {
         FGAIShip* ai_ship = new FGAIShip;
@@ -84,6 +84,7 @@ void FGAIManager::init() {
         ai_ship->setLongitude(entry->getDoubleValue("longitude"));
         ai_ship->setLatitude(entry->getDoubleValue("latitude"));
         ai_ship->init();
+        ai_ship->bind();
 
       } else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) {
         FGAIBallistic* ai_ballistic = new FGAIBallistic;
@@ -96,8 +97,9 @@ void FGAIManager::init() {
         ai_ballistic->setLongitude(entry->getDoubleValue("longitude"));
         ai_ballistic->setLatitude(entry->getDoubleValue("latitude"));
         ai_ballistic->init();
+        ai_ballistic->bind();
       } 
-     }
+    }
   }
 
   initDone = true;
@@ -109,6 +111,11 @@ void FGAIManager::bind() {
 
 
 void FGAIManager::unbind() {
+    ai_list_itr = ai_list.begin();
+    while(ai_list_itr != ai_list.end()) {
+        (*ai_list_itr)->unbind();
+        ++ai_list_itr;
+    }
 }
 
 
@@ -123,8 +130,6 @@ void FGAIManager::update(double dt) {
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
                 if ((*ai_list_itr)->getDie()) {
-                // FIXME: delete object itself before removing it from the list.
-                //   delete (*ai_list_itr);
                    ai_list.erase(ai_list_itr, ai_list_itr);
                 } else {
                    (*ai_list_itr)->update(dt);