]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreatePushBack.cxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / AIModel / AIFlightPlanCreatePushBack.cxx
index d97e30da22eea2b37eef3bc372cc1a72a0386c46..de2d83eeb3ce56a2e2260452c24af061c76b7e9a 100644 (file)
@@ -23,6 +23,8 @@
 #endif
 
 #include <simgear/math/sg_geodesy.hxx>
+
+#include <Airports/simple.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
 
@@ -35,7 +37,7 @@
 
 
 // TODO: Use James Turner's createOnGround functions.
-void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
+bool FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
                                     bool firstFlight, FGAirport *dep, 
                                    double latitude,
                                    double longitude,
@@ -69,6 +71,7 @@ void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
                                               " of flight type " << fltType << 
                                               " of airline     " << airline <<
                                               " at airport     " << dep->getId());
+                    return false;
                     char buffer[10];
                     snprintf (buffer, 10, "%d", gateId);
                     //FGTaxiNode *tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
@@ -102,7 +105,7 @@ void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
         if (gateId < 0) {
              createPushBackFallBack(ac, firstFlight, dep, latitude, longitude,
                                     radius, fltType, aircraftType, airline);
-             return;
+             return true;
 
         }
        //cerr << "getting parking " << gateId;
@@ -162,7 +165,66 @@ void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
               //    cerr << "Waypoint Name: " << (*i)->name << endl;
               //}
         } else {
+           /*
+           string rwyClass = getRunwayClassFromTrafficType(fltType);
+
+           // Only set this if it hasn't been set by ATC already.
+          if (activeRunway.empty()) {
+               //cerr << "Getting runway for " << ac->getTrafficRef()->getCallSign() << " at " << apt->getId() << endl;
+              double depHeading = ac->getTrafficRef()->getCourse();
+             dep->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
+                                                 depHeading);
+           }
+           rwy = dep->getRunwayByIdent(activeRunway);
+           SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0);
+
+          FGGroundNetwork *gn = dep->getDynamics()->getGroundNetwork();
+          if (!gn->exists()) {
+              createDefaultTakeoffTaxi(ac, dep, rwy);
+              return true;
+          }
+          int runwayId = gn->findNearestNode(runwayTakeoff);
+          int node = 0;
+           // Find out which node to start from
+          FGParking *park = dep->getDynamics()->getParking(gateId);
+        if (park) {
+            node = park->getPushBackPoint();
+        }
+
+        if (node == -1) {
+            node = gateId;
+        }
+        // HAndle case where parking doens't have a node
+        if ((node == 0) && park) {
+            if (firstFlight) {
+                node = gateId;
+            } else {
+                node = gateId;
+            }
+        }
+        //delete taxiRoute;
+        //taxiRoute = new FGTaxiRoute;
+        FGTaxiRoute tr = gn->findShortestRoute(node, runwayId);
+        int route;
+        FGTaxiNode *tn;
+        waypoint *wpt;
+        int nr = 0;
+        cerr << "Creating taxiroute from gate: " << gateId << " at " << dep->getId() << endl;
+        while (tr.next(&node, &route) && (nr++ < 3)) {
+            char buffer[10];
+            snprintf(buffer, 10, "%d", node);
+             tn = dep->getDynamics()->getGroundNetwork()->findNode(node);
+             wpt = createOnGround(ac, buffer, tn->getGeod(), dep->getElevation(),
+                               vTaxiReduced);
+            wpt->routeIndex = route;
+            waypoints.push_back(wpt);
+        }
+        wpt->name      = "PushBackPoint";
+        lastNodeVisited = tn->getIndex();
+           //FGTaxiNode *firstNode = findNode(gateId);
+           //FGTaxiNode *lastNode =  findNode(runwayId);
            //cerr << "Creating direct forward departure route fragment" << endl;
+           */
            double lat2 = 0.0, lon2 = 0.0, az2 = 0.0;
            waypoint *wpt;
            geo_direct_wgs_84 ( 0, lat, lon, heading, 
@@ -224,11 +286,10 @@ void FGAIFlightPlan::createPushBack(FGAIAircraft *ac,
            wpt->on_ground = true;
            wpt->routeIndex = (*ts)->getIndex();
            waypoints.push_back(wpt);
-
-
         }
 
     }
+    return true;
 }
 /*******************************************************************
  * createPushBackFallBack