]> git.mxchange.org Git - flightgear.git/commitdiff
Changes to the AIModel code, to prepare for the new traffic manager code:
authordurk <durk>
Sun, 16 Nov 2008 13:41:24 +0000 (13:41 +0000)
committerdurk <durk>
Sun, 16 Nov 2008 13:41:24 +0000 (13:41 +0000)
- Leg loading can fail when no additional flights are available
- Better support for waypoint interception during pushback (speed ~ 0)

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlanCreate.cxx
src/AIModel/AIFlightPlanCreatePushBack.cxx
src/AIModel/AIManager.cxx

index c9f185bf0c60920b8983273692afb369ac5e25e5..d66eaa3ea3c449d3eae62348c2e14e908c4e1dab 100644 (file)
@@ -268,7 +268,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();
@@ -323,11 +326,13 @@ 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;
@@ -354,7 +359,9 @@ void FGAIAircraft::loadNextLeg() {
                     trafficRef->getFlightType(),
                     acType,
                     company);
+       //cerr << "created  leg " << leg << " for " << trafficRef->getCallSign() << endl;
     }
+    return true;
 }
 
 
@@ -535,7 +542,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
@@ -616,7 +626,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;
 }
 
@@ -631,7 +645,7 @@ bool FGAIAircraft::aiTrafficVisible() {
 
     user.CourseAndDistance(current, &course, &distance);
 
-    return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDIST);
+    return ((distance * SG_METER_TO_NM) <= TRAFFICTOAIDISTTODIE);
 }
 
 
@@ -654,6 +668,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;
index 9722e355693f323c462c381df082360f497fbe93..a179c9d7feec63a170292226cec8d6b8143c7751 100644 (file)
@@ -64,7 +64,7 @@ public:
     
     void getGroundElev(double dt); //TODO these 3 really need to be public?
     void doGroundAltitude();
-    void loadNextLeg  ();
+    bool loadNextLeg  ();
 
     void setAcType(const string& ac) { acType = ac; };
     void setCompany(const string& comp) { company = comp;};
index e9035eddb0bb9e8fce55ac90c122e2cf33422f9f..438d9912552993126bd992e9bc62ebdfdabd8125 100644 (file)
@@ -381,6 +381,10 @@ void FGAIFlightPlan::setLeadDistance(double speed, double bearing,
   // At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn
   // So, to get an estimate of the turn radius, calculate the cicumference of the circle
   // we travel on. Get the turn radius by dividing by PI (*2).
+  if (speed < 0.5) {
+        lead_distance = 0.5;
+        return;
+  }
   if (speed < 25) {
        turn_radius = ((360/30)*15) / (2*M_PI);
   } else 
index 482d16aeef0e6b08708bfb5b313e151f64e6da0b..04ae25103c05ecfa8036affd94814901e46f83cf 100644 (file)
@@ -577,7 +577,7 @@ void FGAIFlightPlan::createTakeOff(bool firstFlight, FGAirport *apt, double spee
   wpt->latitude  = lat2;
   wpt->longitude = lon2;
   wpt->altitude  = apt->getElevation()+5000;
-  wpt->speed     = speed; 
+  wpt->speed     = speed;
   wpt->crossat   = -10000;
   wpt->gear_down = true;
   wpt->flaps_down= true;
@@ -585,6 +585,11 @@ void FGAIFlightPlan::createTakeOff(bool firstFlight, FGAirport *apt, double spee
   wpt->on_ground = false;
   wpt->routeIndex = 0;
   waypoints.push_back(wpt);  
+  //cerr << "Created takeoff plan : " << endl;
+  //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) {
+  //     cerr << "Waypoint Name: " << (*i)->name << ". Speed = " << (*i)->speed << endl;
+  //}
+
 
  //  geo_direct_wgs_84 ( 0, rwy->latitude(), rwy->longitude(), heading, 
 //   100000,
index cc2a141e8f0dfbc4c4c126fb60031552f04c41f9..3707f2b91a7d2b85f8c4db9708d1d44e698bb42f 100644 (file)
@@ -141,6 +141,9 @@ void FGAIFlightPlan::createPushBack(bool firstFlight, FGAirport *dep,
               // some special considerations for the last point:
               wpt->name = string("PushBackPoint");
               wpt->speed = 15;
+              //for (wpt_vector_iterator i = waypoints.begin(); i != waypoints.end(); i++) {
+              //    cerr << "Waypoint Name: " << (*i)->name << endl;
+              //}
         } else {
            //cerr << "Creating direct forward departure route fragment" << endl;
            double lat2, lon2, az2;
index aac54ab9bfd6f31c5079f63a84d2f70192241f76..82036872706b613ef91a2aba3ea465ffb42c8072 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/props/props_io.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <Main/globals.hxx>