Allow flights that arrive at their departure airport.
This commit is contained in:
parent
6fcd9f967b
commit
bfd3efde5c
1 changed files with 54 additions and 59 deletions
|
@ -205,6 +205,9 @@ bool FGAISchedule::update(time_t now)
|
||||||
userLatitude,
|
userLatitude,
|
||||||
userLongitude;
|
userLongitude;
|
||||||
|
|
||||||
|
SGVec3d newPos(0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
if (fgGetBool("/sim/traffic-manager/enabled") == false)
|
if (fgGetBool("/sim/traffic-manager/enabled") == false)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -302,68 +305,60 @@ bool FGAISchedule::update(time_t now)
|
||||||
if (!(dep && arr))
|
if (!(dep && arr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(dep->getLongitude(),
|
if (dep != arr) {
|
||||||
dep->getLatitude(), 1));
|
SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(dep->getLongitude(),
|
||||||
SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arr->getLongitude(),
|
dep->getLatitude(), 1));
|
||||||
arr->getLatitude(), 1));
|
SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arr->getLongitude(),
|
||||||
SGVec3d _cross = cross(b, a);
|
arr->getLatitude(), 1));
|
||||||
|
SGVec3d _cross = cross(b, a);
|
||||||
|
|
||||||
angle = sgACos(dot(a, b));
|
angle = sgACos(dot(a, b));
|
||||||
|
|
||||||
// Okay, at this point we have the angle between departure and
|
// Okay, at this point we have the angle between departure and
|
||||||
// arrival airport, in degrees. From here we can interpolate the
|
// arrival airport, in degrees. From here we can interpolate the
|
||||||
// position of the aircraft by calculating the ratio between
|
// position of the aircraft by calculating the ratio between
|
||||||
// total time enroute and elapsed time enroute.
|
// total time enroute and elapsed time enroute.
|
||||||
|
|
||||||
totalTimeEnroute = (*i)->getArrivalTime() - (*i)->getDepartureTime();
|
totalTimeEnroute = (*i)->getArrivalTime() - (*i)->getDepartureTime();
|
||||||
if (now > (*i)->getDepartureTime())
|
if (now > (*i)->getDepartureTime())
|
||||||
{
|
{
|
||||||
//err << "Lat = " << lat << ", lon = " << lon << endl;
|
//err << "Lat = " << lat << ", lon = " << lon << endl;
|
||||||
//cerr << "Time diff: " << now-i->getDepartureTime() << endl;
|
//cerr << "Time diff: " << now-i->getDepartureTime() << endl;
|
||||||
elapsedTimeEnroute = now - (*i)->getDepartureTime();
|
elapsedTimeEnroute = now - (*i)->getDepartureTime();
|
||||||
remainingTimeEnroute = (*i)->getArrivalTime() - now;
|
remainingTimeEnroute = (*i)->getArrivalTime() - now;
|
||||||
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager: Flight is in progress.");
|
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager: Flight is in progress.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lat = dep->getLatitude();
|
lat = dep->getLatitude();
|
||||||
lon = dep->getLongitude();
|
lon = dep->getLongitude();
|
||||||
elapsedTimeEnroute = 0;
|
elapsedTimeEnroute = 0;
|
||||||
remainingTimeEnroute = totalTimeEnroute;
|
remainingTimeEnroute = totalTimeEnroute;
|
||||||
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager: Flight is pending.");
|
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager: Flight is pending.");
|
||||||
}
|
}
|
||||||
|
angle *= ( (double) elapsedTimeEnroute/ (double) totalTimeEnroute);
|
||||||
angle *= ( (double) elapsedTimeEnroute/ (double) totalTimeEnroute);
|
//cout << "a = " << a[0] << " " << a[1] << " " << a[2]
|
||||||
|
// << "b = " << b[0] << " " << b[1] << " " << b[2] << endl;
|
||||||
|
sgdMat4 matrix;
|
||||||
//cout << "a = " << a[0] << " " << a[1] << " " << a[2]
|
sgdMakeRotMat4(matrix, angle, _cross.data());
|
||||||
// << "b = " << b[0] << " " << b[1] << " " << b[2] << endl;
|
for(int j = 0; j < 3; j++) {
|
||||||
sgdMat4 matrix;
|
for (int k = 0; k<3; k++) {
|
||||||
sgdMakeRotMat4(matrix, angle, _cross.data());
|
newPos[j] += matrix[j][k]*a[k];
|
||||||
SGVec3d newPos(0, 0, 0);
|
}
|
||||||
for(int j = 0; j < 3; j++)
|
}
|
||||||
{
|
}
|
||||||
for (int k = 0; k<3; k++)
|
SGGeod current;
|
||||||
{
|
if ((now > (*i)->getDepartureTime() && (dep != arr))) {
|
||||||
newPos[j] += matrix[j][k]*a[k];
|
current = SGGeod::fromCart(newPos);
|
||||||
}
|
speed = SGGeodesy::distanceNm(current, arr->geod()) /
|
||||||
}
|
((double) remainingTimeEnroute/3600.0);
|
||||||
|
} else {
|
||||||
SGGeod current;
|
current = dep->geod();
|
||||||
if (now > (*i)->getDepartureTime())
|
speed = 450;
|
||||||
{
|
}
|
||||||
current = SGGeod::fromCart(newPos);
|
SGGeod user = SGGeod::fromDegM(userLongitude, userLatitude, (*i)->getCruiseAlt());
|
||||||
}
|
|
||||||
else
|
distanceToUser = SGGeodesy::distanceNm(current, user);
|
||||||
{
|
|
||||||
current = dep->geod();
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// If distance between user and simulated aircaft is less
|
||||||
// then 500nm, create this flight. At jet speeds 500 nm is roughly
|
// then 500nm, create this flight. At jet speeds 500 nm is roughly
|
||||||
|
|
Loading…
Add table
Reference in a new issue