]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
merging in topic/makej
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 7d6d0d2c58a6f14f8398f4cd54c8c11457651601..3f8bb05a871351cf1dbf559baf0e86cead70a246 100644 (file)
 #  include <config.h>
 #endif
 
-#include <simgear/math/point3d.hxx>
 #include <simgear/route/waypoint.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Main/viewer.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
+#include <Airports/dynamics.hxx>
 
 #include <string>
 #include <math.h>
@@ -158,8 +158,28 @@ void FGAIAircraft::setPerformance(const std::string& acclass) {
      updateSecondaryTargetValues(); // target roll, vertical speed, pitch
      updateActualState(); 
      UpdateRadar(manager);
+     checkVisibility();
   }
 
+void FGAIAircraft::checkVisibility() 
+{
+     double visibility_meters = fgGetDouble("/environment/visibility-m");
+
+     FGViewer* vw = globals->get_current_view();
+     double course, distance;
+
+     SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
+     SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
+     view.CourseAndDistance(current, &course, &distance);
+     if (distance > visibility_meters) {
+         //aip.getSGLocation()->set_cur_elev_m(aptElev);
+         //return;
+         invisible = true;
+      } else {
+         invisible = false;
+      }
+}
+
 
 
 void FGAIAircraft::AccelTo(double speed) {
@@ -267,7 +287,10 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         //TODO let the fp handle this (loading of next leg)
         fp->IncrementWaypoint((bool) trafficRef);
         if (!(fp->getNextWaypoint()) && trafficRef)
-            loadNextLeg();
+            if (!loadNextLeg()) {
+                setDie(true);
+                return;
+            }
 
         prev = fp->getPreviousWaypoint();
         curr = fp->getCurrentWaypoint();
@@ -322,13 +345,14 @@ bool FGAIAircraft::_getGearDown() const {
 }
 
 
-void FGAIAircraft::loadNextLeg() {
+bool FGAIAircraft::loadNextLeg() {
 
     int leg;
     if ((leg = fp->getLeg())  == 10) {
-        trafficRef->next();
+        if (!trafficRef->next()) {
+            return false;
+        }
         setCallSign(trafficRef->getCallSign());
-       //props->setStringValue("callsign", callsign.c_str());
         leg = 1;
         fp->setLeg(leg);
     }
@@ -341,10 +365,11 @@ void FGAIAircraft::loadNextLeg() {
     } else {
         double cruiseAlt = trafficRef->getCruiseAlt() * 100;
 
-        fp->create (dep,
+        fp->create (this,
+                    dep,
                     arr,
                     leg,
-                    cruiseAlt,           //(trafficRef->getCruiseAlt() * 100), // convert from FL to feet
+                    cruiseAlt,
                     trafficRef->getSpeed(),
                     _getLatitude(),
                     _getLongitude(),
@@ -353,7 +378,9 @@ void FGAIAircraft::loadNextLeg() {
                     trafficRef->getFlightType(),
                     acType,
                     company);
+       //cerr << "created  leg " << leg << " for " << trafficRef->getCallSign() << endl;
     }
+    return true;
 }
 
 
@@ -534,7 +561,10 @@ void FGAIAircraft::handleFirstWaypoint() {
     //TODO fp should handle this
     fp->IncrementWaypoint(eraseWaypoints);
     if (!(fp->getNextWaypoint()) && trafficRef)
-        loadNextLeg();
+        if (!loadNextLeg()) {
+            setDie(true);
+            return;
+        }
 
     prev = fp->getPreviousWaypoint();   //first waypoint
     curr = fp->getCurrentWaypoint();    //second waypoint
@@ -615,7 +645,11 @@ bool FGAIAircraft::leadPointReached(FGAIFlightPlan::waypoint* curr) {
 
     //prev_dist_to_go = dist_to_go;
     //if (dist_to_go < lead_dist)
-    //    cerr << trafficRef->getCallSign() << " Distance : " << dist_to_go << ": Lead distance " << lead_dist << " " << curr->name << endl;
+    //     cerr << trafficRef->getCallSign() << " Distance : " 
+    //          << dist_to_go << ": Lead distance " 
+    //          << lead_dist << " " << curr->name 
+    //          << " Ground target speed " << groundTargetSpeed << endl;
+         
     return dist_to_go < lead_dist;
 }
 
@@ -630,7 +664,7 @@ bool FGAIAircraft::aiTrafficVisible() {
 
     user.CourseAndDistance(current, &course, &distance);
 
-    return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDIST);
+    return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDISTTODIE);
 }
 
 
@@ -653,6 +687,7 @@ bool FGAIAircraft::handleAirportEndPoints(FGAIFlightPlan::waypoint* prev, time_t
 
     // This waypoint marks the fact that the aircraft has passed the initial taxi
     // departure waypoint, so it can release the parking.
+    //cerr << trafficRef->getCallSign() << " has passed waypoint " << prev->name << " at speed " << speed << endl;
     if (prev->name == "PushBackPoint") {
         dep->getDynamics()->releaseParking(fp->getGate());
         time_t holdUntil = now + 120;