1
0
Fork 0

Schedflight logging

This commit is contained in:
portree_kid 2021-03-19 21:47:59 +01:00 committed by James Turner
parent 3318e09441
commit 47ca5c251f
2 changed files with 49 additions and 26 deletions

View file

@ -100,6 +100,13 @@ FGScheduledFlight::FGScheduledFlight(const FGScheduledFlight &other)
available = other.available;
}
/**
* @param cs The callsign
* @param fr The flightrules
* @param depPrt The departure ICAO
* @param arrPrt The arrival ICAO
*/
FGScheduledFlight::FGScheduledFlight(const string& cs,
const string& fr,
const string& depPrt,
@ -137,7 +144,14 @@ FGScheduledFlight::FGScheduledFlight(const string& cs,
SG_LOG( SG_AI, SG_ALERT, "Unknown repeat period in flight plan "
"of flight '" << cs << "': " << rep );
}
if (!repeatPeriod) {
SG_LOG( SG_AI, SG_ALERT, "Zero repeat period in flight plan "
"of flight '" << cs << "': " << rep );
available = false;
return;
}
// What we still need to do is preprocess the departure and
// arrival times.
departureTime = processTimeString(deptime);
@ -218,26 +232,26 @@ void FGScheduledFlight::update()
arrivalTime += repeatPeriod;
}
/**
* //FIXME Doesn't have to be an iteration / when sitting at departure why adjust based on arrival
*/
void FGScheduledFlight::adjustTime(time_t now)
{
//cerr << "1: Adjusting schedule please wait: " << now
// << " " << arrivalTime << " " << arrivalTime+repeatPeriod << endl;
// Make sure that the arrival time is in between
// the current time and the next repeat period.
while ((arrivalTime < now) || (arrivalTime > now+repeatPeriod))
{
if (arrivalTime < now)
{
departureTime += repeatPeriod;
arrivalTime += repeatPeriod;
}
else if (arrivalTime > now+repeatPeriod)
{
departureTime -= repeatPeriod;
arrivalTime -= repeatPeriod;
}
// cerr << "2: Adjusting schedule please wait: " << now
// << " " << arrivalTime << " " << arrivalTime+repeatPeriod << endl;
// Make sure that the arrival time is in between
// the current time and the next repeat period.
while ((arrivalTime < now) || (arrivalTime > now + repeatPeriod)) {
if (arrivalTime < now) {
departureTime += repeatPeriod;
arrivalTime += repeatPeriod;
SG_LOG(SG_AI, SG_BULK, "Adjusted schedule forward : " << callsign << " " << now << " " << departureTime << " " << arrivalTime);
} else if (arrivalTime > now + repeatPeriod) {
departureTime -= repeatPeriod;
arrivalTime -= repeatPeriod;
SG_LOG(SG_AI, SG_BULK, "Adjusted schedule backward : " << callsign << " " << now << " " << departureTime << " " << arrivalTime);
} else {
SG_LOG(SG_AI, SG_BULK, "Not Adjusted schedule : " << now);
}
}
}

View file

@ -579,12 +579,12 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
fltEnd = tmgr->getLastFlight(req);
//cerr << "Finding available flight " << endl;
SG_LOG (SG_AI, SG_BULK, "Finding available flight for " << req);
// For Now:
// Traverse every registered flight
if (fltBegin == fltEnd) {
//cerr << "No Flights Scheduled for " << req << endl;
}
if (fltBegin == fltEnd) {
SG_LOG (SG_AI, SG_BULK, "No Flights Scheduled for " << req );
}
int counter = 0;
for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
(*i)->adjustTime(now);
@ -596,10 +596,13 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
//bool valid = true;
counter++;
if (!(*i)->isAvailable()) {
SG_LOG(SG_AI, SG_BULK, "" << (*i)->getCallSign() << "is no longer available");
//cerr << (*i)->getCallSign() << "is no longer available" << endl;
continue;
}
if (!((*i)->getRequirement() == req)) {
SG_LOG(SG_AI, SG_BULK, "" << (*i)->getCallSign() << " no requirement " << (*i)->getRequirement() << " " << req);
continue;
}
if (!(((*i)->getArrivalAirport()) && ((*i)->getDepartureAirport()))) {
@ -607,17 +610,23 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
}
if (!(currentDestination.empty())) {
if (currentDestination != (*i)->getDepartureAirport()->getId()) {
SG_LOG(SG_AI, SG_BULK, (*i)->getCallSign() << " not matching departure.");
//cerr << (*i)->getCallSign() << "Doesn't match destination" << endl;
//cerr << "Current Destination " << currentDestination << "Doesnt match flight's " <<
// (*i)->getArrivalAirport()->getId() << endl;
continue;
}
}
if (! flights.empty()) {
if (!flights.empty()) {
time_t arrival = flights.back()->getArrivalTime();
time_t departure = (*i)->getDepartureTime();
int groundTime = groundTimeFromRadius();
if ((*i)->getDepartureTime() < (arrival+(groundTime)))
continue;
if (departure < (arrival+(groundTime))) {
SG_LOG (SG_AI, SG_BULK, "Not flight candidate : " << (*i)->getCallSign() << " Arrival : " << arrival << " Planned Departure " << departure << " < " << (arrival+groundTime) << " Diff : " << (arrival+groundTime-departure));
continue;
} else {
SG_LOG (SG_AI, SG_BULK, "Next flight candidate : " << (*i)->getCallSign() );
}
}
if (min != 0) {
time_t dep = (*i)->getDepartureTime();