]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
Some preparory work for enabling the handover from ground to tower controller.
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 9d630d683df6ede500096f36e129eb3cf7bf58de..eac6cd4fa59bb8460444a16a9f2b381d5ab87731 100644 (file)
@@ -65,9 +65,10 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) :
     else
         groundOffset = 0;
 
-    fp = 0;
-    controller = 0;
-    prevController = 0;
+    fp              = 0;
+    controller      = 0;
+    prevController  = 0;
+    towerController = 0;
     dt_count = 0;
     dt_elev_count = 0;
     use_perf_vs = true;
@@ -92,6 +93,7 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) :
 
     _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
     dt = 0;
+    scheduledForTakeoff = false;
 }
 
 
@@ -413,12 +415,12 @@ const char * FGAIAircraft::_getTransponderCode() const {
 bool FGAIAircraft::loadNextLeg(double distance) {
 
     int leg;
-    if ((leg = fp->getLeg())  == 10) {
+    if ((leg = fp->getLeg())  == 9) {
         if (!trafficRef->next()) {
             return false;
         }
         setCallSign(trafficRef->getCallSign());
-        leg = 1;
+        leg = 0;
         fp->setLeg(leg);
     }
 
@@ -555,6 +557,25 @@ void FGAIAircraft::announcePositionToController() {
     }
 }
 
+void FGAIAircraft::scheduleForATCTowerDepartureControl() {
+    if (!scheduledForTakeoff) {
+        int leg = fp->getLeg();
+        if (trafficRef) {
+            if (trafficRef->getDepartureAirport()->getDynamics()) {
+                towerController = trafficRef->getDepartureAirport()->getDynamics()->getTowerController();
+            } else {
+                cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
+            }
+            if (towerController) {
+                towerController->announcePosition(getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
+                                                   _getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
+                                                    trafficRef->getRadius(), leg, this);
+            }
+        }
+    }
+    scheduledForTakeoff = true;
+}
+
 // Process ATC instructions and report back
 
 void FGAIAircraft::processATC(FGATCInstruction instruction) {
@@ -791,6 +812,9 @@ bool FGAIAircraft::handleAirportEndPoints(FGAIWaypoint* prev, time_t now) {
     if (prev->contains("legend")) {
         fp->incrementLeg();
     }
+    if (prev->contains(string("DepartureHold"))) {
+        scheduleForATCTowerDepartureControl();
+    }
 
     // This is the last taxi waypoint, and marks the the end of the flight plan
     // so, the schedule should update and wait for the next departure time.