]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlan.cxx
Ground network distance tracking code. AIAircraft taxiing at airports
[flightgear.git] / src / AIModel / AIFlightPlan.cxx
index 19321f2bfd7c24746601ffb1624bc2b4bb929d53..8f03b93a7d4e58037af1ba7e6f664a8b0f861e4b 100644 (file)
 //
 // 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.
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/debug/logstream.hxx>
 #include "AIFlightPlan.hxx"
 
 
-FGAIFlightPlan::FGAIFlightPlan(string filename)
+FGAIFlightPlan::FGAIFlightPlan(const string& filename)
 {
   int i;
   start_time = 0;
   leg = 10;
   gateId = 0;
+  taxiRoute = 0;
   SGPath path( globals->get_fg_root() );
-  path.append( ("/Data/AI/FlightPlans/" + filename).c_str() );
+  path.append( ("/AI/FlightPlans/" + filename).c_str() );
   SGPropertyNode root;
+  repeat = false;
 
   try {
       readProperties(path.str(), &root);
@@ -92,25 +96,32 @@ FGAIFlightPlan::FGAIFlightPlan(string filename)
 // Position computed by the traffic manager, as well
 // as setting speeds and altitude computed by the
 // traffic manager. 
-FGAIFlightPlan::FGAIFlightPlan(FGAIModelEntity *entity,
+FGAIFlightPlan::FGAIFlightPlan(const std::string& p,
                               double course,
                               time_t start,
                               FGAirport *dep,
                               FGAirport *arr,
                               bool firstLeg,
                               double radius,
-                              string fltType,
-                              string acType,
-                              string airline)
+                               double alt,
+                               double lat,
+                               double lon,
+                               double speed,
+                              const string& fltType,
+                              const string& acType,
+                              const string& airline)
 {
+  repeat = false;
   leg = 10;
   gateId=0;
+  taxiRoute = 0;
   start_time = start;
   bool useInitialWayPoint = true;
   bool useCurrentWayPoint = false;
   SGPath path( globals->get_fg_root() );
-  path.append( "/Data/AI/FlightPlans" );
-  path.append( entity->path );
+  path.append( "/AI/FlightPlans" );
+  path.append( p );
+  
   SGPropertyNode root;
   
   // This is a bit of a hack:
@@ -154,7 +165,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIModelEntity *entity,
          }
        }
       catch (const sg_exception &e) {
-       SG_LOG(SG_GENERAL, SG_ALERT,
+       SG_LOG(SG_GENERAL, SG_WARN,
               "Error reading AI flight plan: ");
        cerr << "Errno = " << errno << endl;
        if (errno == ENOENT)
@@ -182,7 +193,7 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIModelEntity *entity,
       
       //cerr << "Set leg to : " << leg << endl;  
       wpt_iterator = waypoints.begin();
-      create(dep,arr, leg, entity->altitude, entity->speed, entity->latitude, entity->longitude,
+      create(dep,arr, leg, alt, speed, lat, lon,
             firstLeg, radius, fltType, acType, airline);
       wpt_iterator = waypoints.begin();
       //cerr << "after create: " << (*wpt_iterator)->name << endl;
@@ -285,17 +296,13 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIModelEntity *entity,
 FGAIFlightPlan::~FGAIFlightPlan()
 {
   deleteWaypoints();
-  //waypoints.clear();
-  //while (waypoints.begin() != waypoints.end())
-  //  {
-  //    delete *(waypoints.begin());
-  //    waypoints.erase (waypoints.begin());
-  //  }
+  if (taxiRoute)
+    delete taxiRoute;
 }
 
 
-FGAIFlightPlan::waypoint*
-FGAIFlightPlan::getPreviousWaypoint( void )
+FGAIFlightPlan::waypoint* const
+FGAIFlightPlan::getPreviousWaypoint( void ) const
 {
   if (wpt_iterator == waypoints.begin()) {
     return 0;
@@ -305,14 +312,14 @@ FGAIFlightPlan::getPreviousWaypoint( void )
   }
 }
 
-FGAIFlightPlan::waypoint*
-FGAIFlightPlan::getCurrentWaypoint( void )
+FGAIFlightPlan::waypoint* const
+FGAIFlightPlan::getCurrentWaypoint( void ) const
 {
   return *wpt_iterator;
 }
 
-FGAIFlightPlan::waypoint*
-FGAIFlightPlan::getNextWaypoint( void )
+FGAIFlightPlan::waypoint* const
+FGAIFlightPlan::getNextWaypoint( void ) const
 {
   wpt_vector_iterator i = waypoints.end();
   i--;  // end() points to one element after the last one. 
@@ -343,7 +350,7 @@ void FGAIFlightPlan::IncrementWaypoint(bool eraseWaypoints )
 }
 
 // gives distance in feet from a position to a waypoint
-double FGAIFlightPlan::getDistanceToGo(double lat, double lon, waypoint* wp){
+double FGAIFlightPlan::getDistanceToGo(double lat, double lon, waypoint* wp) const{
    // get size of a degree2 at the present latitude
    // this won't work over large distances
    double ft_per_deg_lat = 366468.96 - 3717.12 * cos(lat / SG_RADIANS_TO_DEGREES);
@@ -385,12 +392,12 @@ void FGAIFlightPlan::setLeadDistance(double distance_ft){
 }
 
 
-double FGAIFlightPlan::getBearing(waypoint* first, waypoint* second){
+double FGAIFlightPlan::getBearing(waypoint* first, waypoint* second) const{
   return getBearing(first->latitude, first->longitude, second);
 }
 
 
-double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp){
+double FGAIFlightPlan::getBearing(double lat, double lon, waypoint* wp) const{
   double course, distance;
  //  double latd = lat;
 //   double lond = lon;
@@ -472,3 +479,26 @@ void FGAIFlightPlan::resetWaypoints()
       waypoints.push_back(wpt);
     }
 }
+
+// Start flightplan over from the beginning
+void FGAIFlightPlan::restart()
+{
+  wpt_iterator = waypoints.begin();
+}
+
+
+void FGAIFlightPlan::deleteTaxiRoute() 
+{
+  if (taxiRoute)
+    delete taxiRoute;
+  taxiRoute = 0;
+}
+
+
+int FGAIFlightPlan::getRouteIndex(int i) {
+  if ((i > 0) && (i < waypoints.size())) {
+    return waypoints[i]->routeIndex;
+  }
+  else
+    return 0;
+}