From 63d224081e5d55015b116132ee4fe263b8983479 Mon Sep 17 00:00:00 2001 From: durk Date: Sun, 4 Jan 2009 17:11:25 +0000 Subject: [PATCH] James Turner: Rewrite of the getSpeed function. Smaller and more elegant. --- src/Traffic/Schedule.cxx | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 59ae872ee..b8e023f90 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -37,10 +37,8 @@ #include #include -#include - #include -#include +#include #include #include #include @@ -577,37 +575,15 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDesti double FGAISchedule::getSpeed() { - double courseToDest; - double distanceToDest; - double speed, remainingTimeEnroute; - FGAirport *dep, *arr; - FGScheduledFlightVecIterator i = flights.begin(); - dep = (*i)->getDepartureAirport(); - arr = (*i)->getArrivalAirport (); - if (!(dep && arr)) - return 0; - SGWayPoint dest ( dep->getLongitude(), - dep->getLatitude(), - (*i)->getCruiseAlt(), - SGWayPoint::SPHERICAL); - SGWayPoint curr ( arr->getLongitude(), - arr->getLatitude(), - (*i)->getCruiseAlt(), - SGWayPoint::SPHERICAL); - remainingTimeEnroute = (*i)->getArrivalTime() - (*i)->getDepartureTime(); - dest.CourseAndDistance(curr, &courseToDest, &distanceToDest); - speed = (distanceToDest*SG_METER_TO_NM) / - ((double) remainingTimeEnroute/3600.0); - if (speed < 300) { - //cerr << "Warning : calculated speed for " << (*i)->getCallSign() << " is low : " << speed << " clamping to 300" << endl; - speed = 300.0; - } - if (speed > 500) { - //cerr << "Warning : calculated speed for " << (*i)->getCallSign() << " is high : " << speed << " clamping to 300" << endl; - speed = 500.0; - } + FGAirport* dep = (*i)->getDepartureAirport(), + *arr = (*i)->getArrivalAirport(); + double dist = SGGeodesy::distanceNm(dep->geod(), arr->geod()); + double remainingTimeEnroute = (*i)->getArrivalTime() - (*i)->getDepartureTime(); + + double speed = dist / (remainingTimeEnroute/3600.0); + SG_CLAMP_RANGE(speed, 300.0, 500.0); return speed; } /*