#include <vector>
#include <algorithm>
-#include <plib/sg.h>
-
#include <simgear/compiler.h>
-#include <simgear/math/polar3d.hxx>
+#include <simgear/sg_inlines.h>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx>
FGAIManager *aimgr;
string airport;
-
- double courseToUser, courseToDest;
- double distanceToDest;
+
double speed;
time_t
//cerr << "About to find a flight " << endl;
if (flights.empty()) {
//execute this loop at least once.
- SG_LOG(SG_GENERAL, SG_INFO, "Scheduling for : " << modelPath << " " << registration << " " << homePort);
+ SG_LOG(SG_GENERAL, SG_BULK, "Scheduling for : " << modelPath << " " << registration << " " << homePort);
FGScheduledFlight *flight = 0;
do {
flight = findAvailableFlight(currentDestination, flightIdentifier);
depT = depT.substr(0,24);
arrT = arrT.substr(0,24);
- SG_LOG(SG_GENERAL, SG_INFO, " " << flight->getCallSign() << ":"
+ SG_LOG(SG_GENERAL, SG_BULK, " " << flight->getCallSign() << ":"
<< " " << flight->getDepartureAirport()->getId() << ":"
<< " " << depT << ":"
<< " \"" << flight->getArrivalAirport()->getId() << "\"" << ":"
flights.push_back(flight);
}
} while ((currentDestination != homePort) && (flight != 0));
- SG_LOG(SG_GENERAL, SG_INFO, cerr << " Done " << endl);
+ SG_LOG(SG_GENERAL, SG_BULK, cerr << " Done " << endl);
}
//cerr << " Done " << endl;
// No flights available for this aircraft
//cout << "a = " << a[0] << " " << a[1] << " " << a[2]
// << "b = " << b[0] << " " << b[1] << " " << b[2] << endl;
sgdMat4 matrix;
- sgdMakeRotMat4(matrix, angle, _cross.sg());
+ sgdMakeRotMat4(matrix, angle, _cross.data());
SGVec3d newPos(0, 0, 0);
for(int j = 0; j < 3; j++)
{
}
}
+ SGGeod current;
if (now > (*i)->getDepartureTime())
{
- SGGeoc geoc = SGGeoc::fromCart(newPos);
- lat = geoc.getLatitudeDeg();
- lon = geoc.getLongitudeDeg();
+ current = SGGeod::fromCart(newPos);
}
else
{
- lat = dep->getLatitude();
- lon = dep->getLongitude();
- }
+ current = dep->geod();
+ }
-
- SGWayPoint current (lon,
- lat,
- (*i)->getCruiseAlt(),
- SGWayPoint::SPHERICAL);
- SGWayPoint user ( userLongitude,
- userLatitude,
- (*i)->getCruiseAlt(),
- SGWayPoint::SPHERICAL);
- SGWayPoint dest ( arr->getLongitude(),
- arr->getLatitude(),
- (*i)->getCruiseAlt(),
- SGWayPoint::SPHERICAL);
- // We really only need distance to user
- // and course to destination
- user.CourseAndDistance(current, &courseToUser, &distanceToUser);
- dest.CourseAndDistance(current, &courseToDest, &distanceToDest);
- speed = (distanceToDest*SG_METER_TO_NM) /
+ SGGeod user = SGGeod::fromDegM(userLongitude, userLatitude, (*i)->getCruiseAlt());
+ speed = SGGeodesy::distanceNm(current, arr->geod()) /
((double) remainingTimeEnroute/3600.0);
-
+
+ distanceToUser = SGGeodesy::distanceNm(current, user);
// If distance between user and simulated aircaft is less
// then 500nm, create this flight. At jet speeds 500 nm is roughly
// to start a more detailed simulation of this aircraft.
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic manager: " << registration << " is scheduled for a flight from "
<< dep->getId() << " to " << arr->getId() << ". Current distance to user: "
- << distanceToUser*SG_METER_TO_NM);
- if ((distanceToUser*SG_METER_TO_NM) < TRAFFICTOAIDISTTOSTART)
+ << distanceToUser);
+ if (distanceToUser < TRAFFICTOAIDISTTOSTART)
{
string flightPlanName = dep->getId() + string("-") + arr->getId() +
string(".xml");
aircraft->setAltitude((*i)->getCruiseAlt()*100); // convert from FL to feet
aircraft->setSpeed(speed);
aircraft->setBank(0);
- aircraft->SetFlightPlan(new FGAIFlightPlan(flightPlanName, courseToDest, deptime,
+
+ courseToDest = SGGeodesy::courseDeg(current, arr->geod());
+ aircraft->SetFlightPlan(new FGAIFlightPlan(aircraft, flightPlanName, courseToDest, deptime,
dep, arr,true, radius,
(*i)->getCruiseAlt()*100,
lat, lon, speed, flightType, acType,
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;
}
-
+/*
bool compareSchedules(FGAISchedule*a, FGAISchedule*b)
{
//return (*a) < (*b);
}
-
+*/
// void FGAISchedule::setClosestDistanceToUser()
// {