if (!valid) {
return false;
}
- scheduleFlights();
+ scheduleFlights(now);
if (flights.empty()) { // No flights available for this aircraft
valid = false;
return false;
if (AIManagerRef) {
// Check if this aircraft has been released.
- FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("Traffic Manager");
+ FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
if (tmgr->isReleased(AIManagerRef)) {
AIManagerRef = 0;
} else {
airline);
if (fp->isValidPlan()) {
aircraft->SetFlightPlan(fp);
- FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai_model");
+ FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
aimgr->attach(aircraft);
AIManagerRef = aircraft->getID();
return true;
courseToDest = SGGeodesy::courseDeg((*flights.begin())->getDepartureAirport()->geod(), (*flights.begin())->getArrivalAirport()->geod());
}
-void FGAISchedule::scheduleFlights()
+void FGAISchedule::scheduleFlights(time_t now)
{
- string startingPort;
if (!flights.empty()) {
return;
}
- // change back to bulk
+ //string startingPort;
+ string userPort = fgGetString("/sim/presets/airport-id");
SG_LOG(SG_GENERAL, SG_BULK, "Scheduling Flights for : " << modelPath << " " << registration << " " << homePort);
FGScheduledFlight *flight = NULL;
do {
- flight = findAvailableFlight(currentDestination, flightIdentifier);
+ if (currentDestination.empty()) {
+ flight = findAvailableFlight(userPort, flightIdentifier, now, (now+6400));
+ if (!flight)
+ flight = findAvailableFlight(currentDestination, flightIdentifier);
+ } else {
+ flight = findAvailableFlight(currentDestination, flightIdentifier);
+ }
if (!flight) {
break;
}
- if (startingPort.empty()) {
- startingPort = flight->getDepartureAirport()->getId();
- }
-
-
+ //if (startingPort.empty()) {
+ // startingPort = flight->getDepartureAirport()->getId();
+ //}
currentDestination = flight->getArrivalAirport()->getId();
+ //cerr << "Current destination " << currentDestination << endl;
if (!initialized) {
string departurePort = flight->getDepartureAirport()->getId();
//cerr << "Scheduled " << registration << " " << score << " for Flight "
// << flight-> getCallSign() << " from " << departurePort << " to " << currentDestination << endl;
- if (fgGetString("/sim/presets/airport-id") == departurePort) {
+ if (userPort == departurePort) {
+ lastRun = 1;
hits++;
+ } else {
+ lastRun = 0;
}
//runCount++;
initialized = true;
<< " " << arrT << ":");
flights.push_back(flight);
- } while (currentDestination != startingPort);
+ } while (currentDestination != homePort);
SG_LOG(SG_GENERAL, SG_BULK, " Done ");
}
}
FGScheduledFlight* FGAISchedule::findAvailableFlight (const string ¤tDestination,
- const string &req)
+ const string &req,
+ time_t min, time_t max)
{
time_t now = time(NULL) + fgGetLong("/sim/time/warp");
- FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("Traffic Manager");
+ FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
FGScheduledFlightVecIterator fltBegin, fltEnd;
fltBegin = tmgr->getFirstFlight(req);
fltEnd = tmgr->getLastFlight(req);
}
if (flights.size()) {
time_t arrival = flights.back()->getArrivalTime();
- if ((*i)->getDepartureTime() < (arrival+(20*60)))
+ int groundTime = groundTimeFromRadius();
+ if ((*i)->getDepartureTime() < (arrival+(groundTime)))
continue;
}
+ if (min != 0) {
+ time_t dep = (*i)->getDepartureTime();
+ if ((dep < min) || (dep > max))
+ continue;
+ }
// So, if we actually get here, we have a winner
//cerr << "found flight: " << req << " : " << currentDestination << " : " <<
return NULL;
}
+int FGAISchedule::groundTimeFromRadius()
+{
+ if (radius < 10)
+ return 15 * 60;
+ else if (radius < 15)
+ return 20 * 60;
+ else if (radius < 20)
+ return 30 * 60;
+ else if (radius < 25)
+ return 50 * 60;
+ else if (radius < 30)
+ return 90 * 60;
+ else
+ return 120 * 60;
+}
+
+
double FGAISchedule::getSpeed()
{
FGScheduledFlightVecIterator i = flights.begin();