]> git.mxchange.org Git - flightgear.git/commitdiff
Harald JOHNSEN:
authorehofman <ehofman>
Sun, 24 Jul 2005 14:05:28 +0000 (14:05 +0000)
committerehofman <ehofman>
Sun, 24 Jul 2005 14:05:28 +0000 (14:05 +0000)
- AIManager.cxx :
  - we can now have multiple <scenario> entries in the sim/ai entry in preferences.xml
- AIBase.cxx :
  - added an exception handler around the loading of the 3D model to not exit FG
    if the model is not found
- AIScenario.cxx :
  - removed a duplicated read of the xml file, this was also exiting FG is the xml file
    does not exist

src/AIModel/AIBase.cxx
src/AIModel/AIManager.cxx
src/AIModel/AIScenario.cxx

index d9feab65d703a19221002a9559f1552cf90eb554..5cf5d01cfaa0c693d4ee1d89b79f4b90bebd59b5 100644 (file)
@@ -111,10 +111,14 @@ bool FGAIBase::init() {
    props = root->getNode(_type_str.c_str(), index, true);
 
    if (model_path != "") {
+    try {
       model = load3DModel( globals->get_fg_root(),
                             SGPath(model_path).c_str(),
                              props,
                             globals->get_sim_time_sec() );
+    } catch (const sg_exception &e) {
+       model = NULL;
+    }
    }
    if (model) {
      aip.init( model );
@@ -125,7 +129,7 @@ bool FGAIBase::init() {
      globals->get_scenery()->register_placement_transform(aip.getTransform());
    } else {
      if (model_path != "") { 
-       SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model.");
+       SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
      }
    } 
 
index 54bbc58dae389bea3244a3b63c0b1747e4b101c1..e0160cd5964b0e8ed224fd97b16ed79f4d03bd44 100644 (file)
@@ -82,10 +82,14 @@ void FGAIManager::init() {
   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 );
 
+  for(int i = 0 ; i < root->nChildren() ; i++) {
+    SGPropertyNode *aiEntry = root->getChild( i );
+       if( !strcmp( aiEntry->getName(), "scenario" ) ) {
+      scenario_filename = aiEntry->getStringValue();
+      if (scenario_filename != "") processScenario( scenario_filename );
+       }
+  }
   initDone = true;
 }
 
@@ -169,8 +173,8 @@ FGAIManager::createAircraft( FGAIModelEntity *entity,   FGAISchedule *ref) {
         } else {
           ai_plane->SetPerformance(&FGAIAircraft::settings[FGAIAircraft::JET_TRANSPORT]);
         }
-       ai_plane->setAcType(entity->acType);
-       ai_plane->setCompany(entity->company);
+        ai_plane->setAcType(entity->acType);
+        ai_plane->setCompany(entity->company);
         ai_plane->setHeading(entity->heading);
         ai_plane->setSpeed(entity->speed);
         ai_plane->setPath(entity->path.c_str());
@@ -437,32 +441,36 @@ bool FGAIManager::getStartPosition(const string& id, const string& pid,
       return 0;
 
   bool found = false;
-  string filename = root->getNode("scenario", true)->getStringValue();
-  FGAIScenario* s = new FGAIScenario( filename );
-  for (int i=0; i<s->nEntries(); i++) {
-    FGAIModelEntity* en = s->getNextEntry();
-    if (en && en->m_type == "carrier" &&
-        (en->pennant_number == id || en->name == id)) {
-      FGAICarrier* ai_carrier = new FGAICarrier(0);
-      ai_carrier->setHeading(en->heading);
-      ai_carrier->setSpeed(en->speed);
-      ai_carrier->setAltitude(en->altitude);
-      ai_carrier->setLongitude(en->longitude);
-      ai_carrier->setLatitude(en->latitude);
-      ai_carrier->setBank(en->rudder);
-      ai_carrier->setParkingPositions(en->ppositions);
-
-      if (ai_carrier->getParkPosition(pid, geodPos, heading, uvw)) {
-        delete ai_carrier;
-        found = true;
-        break;
-      }
+  for(int i = 0 ; (!found) && i < root->nChildren() ; i++) {
+    SGPropertyNode *aiEntry = root->getChild( i );
+       if( !strcmp( aiEntry->getName(), "scenario" ) ) {
+        string filename = aiEntry->getStringValue();
+        FGAIScenario* s = new FGAIScenario( filename );
+        for (int i=0; i<s->nEntries(); i++) {
+            FGAIModelEntity* en = s->getNextEntry();
+            if (en && en->m_type == "carrier" &&
+                (en->pennant_number == id || en->name == id)) {
+            FGAICarrier* ai_carrier = new FGAICarrier(0);
+            ai_carrier->setHeading(en->heading);
+            ai_carrier->setSpeed(en->speed);
+            ai_carrier->setAltitude(en->altitude);
+            ai_carrier->setLongitude(en->longitude);
+            ai_carrier->setLatitude(en->latitude);
+            ai_carrier->setBank(en->rudder);
+            ai_carrier->setParkingPositions(en->ppositions);
+
+            if (ai_carrier->getParkPosition(pid, geodPos, heading, uvw)) {
+                delete ai_carrier;
+                found = true;
+                break;
+            }
 
-      delete ai_carrier;
+            delete ai_carrier;
+        }
+      }
+      delete s;
     }
   }
-  delete s;
-
   return found;
 }
 
index 5f88bca45a6203828f622f365e5f665bfc92bdfa..8f4e22b8c7c8cc114b17b9e8056c6a171ffe9b41 100644 (file)
@@ -47,7 +47,6 @@ FGAIScenario::FGAIScenario(const string &filename)
   
   path.append( ("/Data/AI/" + filename + ".xml").c_str() );
   SGPropertyNode root;
-  readProperties(path.str(), &root);
   
 //   cout <<"path " << path.str() << endl;