]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlan.cxx
#545: Fix ATC chatter sound settings being ignored
[flightgear.git] / src / AIModel / AIFlightPlan.cxx
index a0487c2736f45765c6a8b4cce7a4bb9c18cbd696..09d1eb746548aab78c99373fb443caa093da37f2 100644 (file)
@@ -101,7 +101,7 @@ FGAIFlightPlan::FGAIFlightPlan(const string& filename)
   try {
       readProperties(path.str(), &root);
   } catch (const sg_exception &) {
-      SG_LOG(SG_GENERAL, SG_ALERT,
+      SG_LOG(SG_AI, SG_ALERT,
        "Error reading AI flight plan: " << path.str());
        // cout << path.str() << endl;
      return;
@@ -127,7 +127,7 @@ FGAIFlightPlan::FGAIFlightPlan(const string& filename)
      if (wpt->getName() == "END") wpt->setFinished(true);
      else wpt->setFinished(false);
 
-     waypoints.push_back( wpt );
+     pushBackWaypoint( wpt );
    }
 
   wpt_iterator = waypoints.begin();
@@ -192,7 +192,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
          
          SGPropertyNode * node = root.getNode("flightplan");
          
-         //waypoints.push_back( init_waypoint );
+         //pushBackWaypoint( init_waypoint );
          for (int i = 0; i < node->nChildren(); i++) { 
            //cout << "Reading waypoint " << i << endl;
            FGAIWaypoint* wpt = new FGAIWaypoint;
@@ -208,11 +208,11 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
            
            if (wpt->getName() == "END") wpt->setFinished(true);
            else wpt->setFinished(false);
-           waypoints.push_back(wpt);
+           pushBackWaypoint(wpt);
          } // of node loop
           wpt_iterator = waypoints.begin();
        } catch (const sg_exception &e) {
-      SG_LOG(SG_GENERAL, SG_WARN, "Error reading AI flight plan: " << 
+      SG_LOG(SG_AI, SG_WARN, "Error reading AI flight plan: " <<
         e.getMessage() << " from " << e.getOrigin());
     }
   } else {
@@ -237,7 +237,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
       if (timeDiff >= 2000)
           leg = 5;
       */
-      SG_LOG(SG_GENERAL, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg << " " << ac->getTrafficRef()->getCallSign());
+      SG_LOG(SG_AI, SG_INFO, "Route from " << dep->getId() << " to " << arr->getId() << ". Set leg to : " << leg << " " << ac->getTrafficRef()->getCallSign());
       wpt_iterator = waypoints.begin();
       bool dist = 0;
       isValid = create(ac, dep,arr, leg, alt, speed, lat, lon,
@@ -305,7 +305,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
        {
          if ((dist > 100.0) && (useInitialWayPoint))
            {
-             //waypoints.push_back(init_waypoint);;
+             //pushBackWaypoint(init_waypoint);;
              waypoints.insert(i, init_waypoint);
              //cerr << "Using waypoint : " << init_waypoint->name <<  endl;
            }
@@ -313,7 +313,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac,
          // {
          //    (*i)->speed = dist; // A hack
          //  }
-         //waypoints.push_back( wpt );
+         //pushBackWaypoint( wpt );
          //cerr << "Using waypoint : " << (*i)->name 
          //  << ": course diff : " << crsDiff 
          //   << "Course = " << course
@@ -513,10 +513,20 @@ void FGAIFlightPlan::resetWaypoints()
       wpt->setOn_ground   ( (*i)->getOn_ground()  );
       //cerr << "Recycling waypoint " << wpt->name << endl;
       deleteWaypoints();
-      waypoints.push_back(wpt);
+      pushBackWaypoint(wpt);
     }
 }
 
+void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt)
+{
+  // std::vector::push_back invalidates waypoints
+  //  so we should restore wpt_iterator after push_back
+  //  (or it could be an index in the vector)
+  size_t pos = wpt_iterator - waypoints.begin();
+  waypoints.push_back(wpt);
+  wpt_iterator = waypoints.begin() + pos;
+}
+
 // Start flightplan over from the beginning
 void FGAIFlightPlan::restart()
 {