]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/groundnetwork.cxx
Fixed an overly ambitious checkForCircularWaits() function. AI Aircraft
[flightgear.git] / src / Airports / groundnetwork.cxx
index d6cdc68ac6ad0faf6f1dccede458183d8dc78005..397671cbb167c99a8061dcf5b39fd939b7f607ea 100644 (file)
@@ -41,7 +41,6 @@
 //#include <Main/fg_props.hxx>
 //#include <Airports/runways.hxx>
 
-
 #include <AIModel/AIFlightPlan.hxx>
 
 //#include STL_STRING
 
 SG_USING_STD(sort);
 
-
+/*****************************************************************************
+ * Helper function for parsing position string
+ ****************************************************************************/
+double processPosition(const string &pos)
+{
+  string prefix;
+  string subs;
+  string degree;
+  string decimal;
+  int sign = 1;
+  double value;
+  subs = pos;
+  prefix= subs.substr(0,1);
+  if (prefix == string("S") || (prefix == string("W")))
+    sign = -1;
+  subs    = subs.substr(1, subs.length());
+  degree  = subs.substr(0, subs.find(" ",0));
+  decimal = subs.substr(subs.find(" ",0), subs.length());
+  
+             
+  //cerr << sign << " "<< degree << " " << decimal << endl;
+  value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
+  //cerr << value <<endl;
+  //exit(1);
+  return value;
+}
 
 /**************************************************************************
  * FGTaxiNode
@@ -1039,7 +1063,6 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
    TrafficVectorIterator i = activeTraffic.begin();
    int trafficSize = activeTraffic.size();
    if (trafficSize)  {
-        //while ((i->getId() != id) && i != activeTraffic.end()) 
         while (i != activeTraffic.end()) {
         if (i->getId() == id) {
            break;
@@ -1049,7 +1072,7 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
   }
   else {
       return false;
-  } 
+  }
   if (i == activeTraffic.end() || (trafficSize == 0)) {
     SG_LOG(SG_GENERAL, SG_ALERT, "AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkForCircularWaits");
   }
@@ -1058,6 +1081,13 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
    target = current->getWaitsForId();
    //bool printed = false; // Note that this variable is for debugging purposes only.
    int counter = 0;
+
+   if (id == target) {
+       //cerr << "aircraft waits for user" << endl;
+       return false;
+   }
+
+
    while ((target > 0) && (target != id) && counter++ < trafficSize) {
     //printed = true;
      TrafficVectorIterator i = activeTraffic.begin();
@@ -1102,10 +1132,18 @@ bool FGGroundNetwork::checkForCircularWaits(int id)
     //     << " (" << other->getId()  << "); " << endl;;
     //current = other;
    }
+
+
+
+
+
+
    //if (printed)
    //   cerr << "[done] " << endl << endl;;
    if (id == target) {
-       SG_LOG(SG_GENERAL, SG_INFO, "Detected circular wait condition");
+       SG_LOG(SG_GENERAL, SG_ALERT, "Detected circular wait condition");
+       cerr << "Id = " << id << endl;
+       cerr << "target = " << target << endl;
        return true;
    } else {
    return false;