1
0
Fork 0

Time moving

This commit is contained in:
portree_kid 2021-05-24 16:50:37 +02:00 committed by James Turner
parent 3db8351928
commit 45ac50d2b7
7 changed files with 116 additions and 755 deletions

View file

@ -224,8 +224,9 @@ void FGAIAircraft::setPerformance(const std::string& acType, const std::string&
void FGAIAircraft::AccelTo(double speed) { void FGAIAircraft::AccelTo(double speed) {
tgt_speed = speed; tgt_speed = speed;
if (!isStationary()) if (!isStationary()) {
_needsGroundElevation = true; _needsGroundElevation = true;
}
} }
@ -853,6 +854,7 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr, FGAIWaypoint* next, int
} }
if (fp->getPreviousWaypoint()->getSpeed() < tgt_speed) { if (fp->getPreviousWaypoint()->getSpeed() < tgt_speed) {
SG_LOG(SG_AI, SG_BULK, "Set speed of WP from " << fp->getPreviousWaypoint()->getSpeed() << " to " << tgt_speed);
fp->getPreviousWaypoint()->setSpeed(tgt_speed); fp->getPreviousWaypoint()->setSpeed(tgt_speed);
} }
} }
@ -1236,6 +1238,14 @@ const string& FGAIAircraft::atGate()
void FGAIAircraft::handleATCRequests(double dt) void FGAIAircraft::handleATCRequests(double dt)
{ {
time_t startTime = this->getTrafficRef()->getDepartureTime();
time_t now = globals->get_time_params()->get_cur_time();
if ((startTime-now)>0) {
SG_LOG(SG_AI, SG_BULK, this->getCallSign()
<< " is scheduled to depart in " << startTime-now << " seconds.");
}
//TODO implement NullController for having no ATC to save the conditionals //TODO implement NullController for having no ATC to save the conditionals
if (controller) { if (controller) {
controller->updateAircraftInformation(getID(), controller->updateAircraftInformation(getID(),
@ -1462,6 +1472,7 @@ void FGAIAircraft::dumpCSVHeader(std::ofstream& o) {
o << "Index\t"; o << "Index\t";
o << "Lat\t"; o << "Lat\t";
o << "Lon\t"; o << "Lon\t";
o << "Callsign\t";
o << "heading change rate\t"; o << "heading change rate\t";
o << "headingErr\t"; o << "headingErr\t";
o << "hdg\t"; o << "hdg\t";
@ -1477,13 +1488,16 @@ void FGAIAircraft::dumpCSVHeader(std::ofstream& o) {
o << "Bearing\t"; o << "Bearing\t";
o << "headingChangeRate\t"; o << "headingChangeRate\t";
o << "headingError\t"; o << "headingError\t";
o << "Name\t"; o << "Name\t";
o << "WP Lat\t"; o << "WP Lat\t";
o << "WP Lon\t"; o << "WP Lon\t";
o << "Dist\t"; o << "Dist\t";
o << "Departuretime\t";
o << "Time\t"; o << "Time\t";
o << "Leg\t"; o << "Leg\t";
o << "Num WP\t"; o << "Num WP\t";
o << "Leaddistance\t";
o << endl; o << endl;
} }
@ -1491,6 +1505,7 @@ void FGAIAircraft::dumpCSV(std::ofstream& o, int lineIndex) {
o << lineIndex << "\t"; o << lineIndex << "\t";
o << this->getGeodPos().getLatitudeDeg() << "\t"; o << this->getGeodPos().getLatitudeDeg() << "\t";
o << this->getGeodPos().getLongitudeDeg() << "\t"; o << this->getGeodPos().getLongitudeDeg() << "\t";
o << this->getCallSign() << "\t";
o << headingChangeRate << "\t"; o << headingChangeRate << "\t";
o << headingError << "\t"; o << headingError << "\t";
o << hdg << "\t"; o << hdg << "\t";
@ -1504,23 +1519,26 @@ void FGAIAircraft::dumpCSV(std::ofstream& o, int lineIndex) {
o << groundTargetSpeed << "\t"; o << groundTargetSpeed << "\t";
o << round(this->getVerticalSpeedFPM()) << "\t"; o << round(this->getVerticalSpeedFPM()) << "\t";
o << this->getTrueHeadingDeg() << "\t"; o << this->getTrueHeadingDeg() << "\t";
o << this->GetFlightPlan()->getBearing(this->getGeodPos(), this->GetFlightPlan()->getCurrentWaypoint()) << "\t"; FGAIFlightPlan* fp = this->GetFlightPlan();
o << headingChangeRate << "\t"; o << headingChangeRate << "\t";
o << headingError << "\t"; o << headingError << "\t";
FGAIWaypoint* currentWP = this->GetFlightPlan()->getCurrentWaypoint(); FGAIWaypoint* currentWP = this->GetFlightPlan()->getCurrentWaypoint();
if (currentWP) { if (currentWP) {
o << this->GetFlightPlan()->getBearing(this->getGeodPos(), this->GetFlightPlan()->getCurrentWaypoint()) << "\t";
o << currentWP->getName() << "\t"; o << currentWP->getName() << "\t";
o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLatitudeDeg() << "\t"; o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLatitudeDeg() << "\t";
o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLongitudeDeg() << "\t"; o << this->GetFlightPlan()->getCurrentWaypoint()->getPos().getLongitudeDeg() << "\t";
o << SGGeodesy::distanceM(this->getGeodPos(), currentWP->getPos()) << "\t"; o << SGGeodesy::distanceM(this->getGeodPos(), currentWP->getPos()) << "\t";
o << this->GetFlightPlan()->getStartTime() << "\t"; o << this->GetFlightPlan()->getStartTime() << "\t";
o << globals->get_time_params()->get_cur_time() << "\t";
o << this->GetFlightPlan()->getStartTime() - globals->get_time_params()->get_cur_time() << "\t";
} else { } else {
o << "\t\t\t\t"; o << "\t\t\t\t\t\t\t";
} }
FGAIFlightPlan* fp = this->GetFlightPlan();
if (fp->isValidPlan()) { if (fp->isValidPlan()) {
o << fp->getLeg() << "\t"; o << fp->getLeg() << "\t";
o << fp->getNrOfWayPoints() << "\t"; o << fp->getNrOfWayPoints() << "\t";
o << fp->getLeadDistance() << "\t";
} else { } else {
o << "NotValid\t\t"; o << "NotValid\t\t";
} }

View file

@ -435,6 +435,7 @@ void FGAIFlightPlan::setLeadDistance(double speed, double bearing,
// At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn // At a turn rate of 30 degrees per second, it takes 12 seconds to do a full 360 degree turn
// So, to get an estimate of the turn radius, calculate the cicumference of the circle // So, to get an estimate of the turn radius, calculate the cicumference of the circle
// we travel on. Get the turn radius by dividing by PI (*2). // we travel on. Get the turn radius by dividing by PI (*2).
// FIXME Why when going backwards? No fabs
if (speed < 0.5) { if (speed < 0.5) {
lead_distance = 0.5; lead_distance = 0.5;
return; return;
@ -535,7 +536,7 @@ void FGAIFlightPlan::pushBackWaypoint(FGAIWaypoint *wpt)
size_t pos = wpt_iterator - waypoints.begin(); size_t pos = wpt_iterator - waypoints.begin();
waypoints.push_back(wpt); waypoints.push_back(wpt);
wpt_iterator = waypoints.begin() + pos; wpt_iterator = waypoints.begin() + pos;
SG_LOG(SG_AI, SG_BULK, "Added WP : \t" << wpt->getName() << "\t" << wpt->getPos()); SG_LOG(SG_AI, SG_BULK, "Added WP : \t" << wpt->getName() << "\t" << wpt->getPos() << "\t" << wpt->getSpeed());
} }
// Start flightplan over from the beginning // Start flightplan over from the beginning

View file

@ -300,7 +300,7 @@ update its state.
update. On first update, delta time will be 0. update. On first update, delta time will be 0.
*/ */
void FGATCManager::update ( double time ) { void FGATCManager::update ( double time ) {
SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time); // SG_LOG(SG_ATC, SG_BULK, "ATC update code is running at time: " << time);
// Test code: let my virtual co-pilot handle ATC // Test code: let my virtual co-pilot handle ATC
FGAIManager* aiManager = globals->get_subsystem<FGAIManager>(); FGAIManager* aiManager = globals->get_subsystem<FGAIManager>();

View file

@ -579,7 +579,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
fltEnd = tmgr->getLastFlight(req); fltEnd = tmgr->getLastFlight(req);
SG_LOG (SG_AI, SG_BULK, "Finding available flight for " << req); SG_LOG (SG_AI, SG_BULK, "Finding available flight for " << req << " at " << now);
// For Now: // For Now:
// Traverse every registered flight // Traverse every registered flight
if (fltBegin == fltEnd) { if (fltBegin == fltEnd) {
@ -622,7 +622,7 @@ FGScheduledFlight* FGAISchedule::findAvailableFlight (const string &currentDesti
time_t departure = (*i)->getDepartureTime(); time_t departure = (*i)->getDepartureTime();
int groundTime = groundTimeFromRadius(); int groundTime = groundTimeFromRadius();
if (departure < (arrival+(groundTime))) { 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)); SG_LOG (SG_AI, SG_BULK, "Not flight candidate : " << (*i)->getCallSign() << " Flight Arrival : " << arrival << " Planned Departure : " << departure << " < " << (arrival+groundTime) << " Diff between arrival + groundtime and departure : " << (arrival+groundTime-departure) << " Groundtime : " << groundTime);
continue; continue;
} else { } else {
SG_LOG (SG_AI, SG_BULK, "Next flight candidate : " << (*i)->getCallSign() ); SG_LOG (SG_AI, SG_BULK, "Next flight candidate : " << (*i)->getCallSign() );

View file

@ -59,439 +59,4 @@
</arrival> </arrival>
<repeat>WEEK</repeat> <repeat>WEEK</repeat>
</flight> </flight>
<flight>
<callsign>Hebridean_1002</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/08:25:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>4/08:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1003</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/14:10:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>4/15:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1004</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>6/09:45:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>6/10:10:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1005</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>0/15:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>0/15:25:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1006</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>2/08:25:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>2/09:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1007</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>2/14:10:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>2/14:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1008</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/08:25:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>4/09:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1009</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/14:10:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>4/14:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1017</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>2/14:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPU</port>
<time>2/14:35:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1018</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/08:40:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPU</port>
<time>4/09:35:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1019</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEO</port>
<time>4/14:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPU</port>
<time>4/14:35:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1020</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>2/09:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>2/09:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1021</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>4/09:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGPI</port>
<time>4/09:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1022</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>2/09:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/10:05:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1023</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>4/09:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/10:05:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1024</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>2/15:30:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/15:55:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1025</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>4/15:30:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/15:55:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1026</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>6/10:20:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>6/10:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1027</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGEY</port>
<time>0/15:35:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>0/16:00:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1036</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>2/15:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>2/15:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1037</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>4/15:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEY</port>
<time>4/15:20:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1038</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>2/09:30:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/10:05:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1039</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>4/09:30:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/10:05:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1040</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>2/15:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/15:55:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1041</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPI</port>
<time>4/15:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/15:55:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1044</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPU</port>
<time>2/09:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/10:25:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1045</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPU</port>
<time>4/09:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/10:25:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1046</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPU</port>
<time>2/14:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>2/15:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
<flight>
<callsign>Hebridean_1047</callsign>
<required-aircraft>HBR_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>EGPU</port>
<time>4/14:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>EGEO</port>
<time>4/15:50:00</time>
</arrival>
<repeat>WEEK</repeat>
</flight>
</trafficlist> </trafficlist>

View file

@ -6,11 +6,10 @@
<livery>TST</livery> <livery>TST</livery>
<airline>TST</airline> <airline>TST</airline>
<home-port>YSSY</home-port> <home-port>YSSY</home-port>
<required-aircraft>TST_BN_2</required-aircraft> <required-aircraft>TST_BN_1</required-aircraft>
<actype>BN2</actype> <actype>BN2</actype>
<offset>0</offset> <offset>0</offset>
<radius>8</radius> <radius>8</radius>
<flighttype>ga</flighttype>
<performance-class>turboprop_transport</performance-class> <performance-class>turboprop_transport</performance-class>
<registration>G-HEBO</registration> <registration>G-HEBO</registration>
<heavy>false</heavy> <heavy>false</heavy>
@ -24,294 +23,53 @@
<actype>BN2</actype> <actype>BN2</actype>
<offset>0</offset> <offset>0</offset>
<radius>8</radius> <radius>8</radius>
<flighttype>ga</flighttype>
<performance-class>turboprop_transport</performance-class> <performance-class>turboprop_transport</performance-class>
<registration>G-HEBS</registration> <registration>G-HEBY</registration>
<heavy>false</heavy> <heavy>false</heavy>
</aircraft> </aircraft>
<flight> <flight>
<callsign>Test_0001</callsign> <callsign>Test_YBBN_0001</callsign>
<required-aircraft>TST_BN_2</required-aircraft> <required-aircraft>TST_BN_1</required-aircraft>
<fltrules>VFR</fltrules> <fltrules>VFR</fltrules>
<departure> <departure>
<port>YBBN</port> <port>YBBN</port>
<time>00:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YSSY</port>
<time>00:10:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1001</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>00:20:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1001</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:05:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>00:25:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1002</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:10:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>00:30:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1002</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:15:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>00:35:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1003</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:20:00</time> <time>00:20:00</time>
</departure> </departure>
<cruise-alt>50</cruise-alt> <cruise-alt>50</cruise-alt>
<arrival> <arrival>
<port>YBBN</port> <port>YSSY</port>
<time>00:40:00</time> <time>00:50:00</time>
</arrival> </arrival>
<repeat>02Hr</repeat> <repeat>01Hr</repeat>
</flight> </flight>
<flight> <flight>
<callsign>Test_1003</callsign> <callsign>Test_YSSY_1001</callsign>
<required-aircraft>TST_BN_2</required-aircraft> <required-aircraft>TST_BN_1</required-aircraft>
<fltrules>VFR</fltrules> <fltrules>VFR</fltrules>
<departure> <departure>
<port>YSSY</port> <port>YSSY</port>
<time>00:25:00</time> <time>00:12:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>00:45:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1004</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:30:00</time>
</departure> </departure>
<cruise-alt>50</cruise-alt> <cruise-alt>50</cruise-alt>
<arrival> <arrival>
<port>YBBN</port> <port>YBBN</port>
<time>00:50:00</time> <time>00:50:00</time>
</arrival> </arrival>
<repeat>02Hr</repeat> <repeat>01Hr</repeat>
</flight> </flight>
<flight> <flight>
<callsign>Test_1004</callsign> <callsign>Test_YSSY_1002</callsign>
<required-aircraft>TST_BN_2</required-aircraft> <required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules> <fltrules>VFR</fltrules>
<departure> <departure>
<port>YSSY</port> <port>YSSY</port>
<time>00:35:00</time> <time>00:48:00</time>
</departure> </departure>
<cruise-alt>50</cruise-alt> <cruise-alt>50</cruise-alt>
<arrival> <arrival>
<port>YBBN</port> <port>YBBN</port>
<time>00:55:00</time> <time>00:49:00</time>
</arrival> </arrival>
<repeat>02Hr</repeat> <repeat>03Hr</repeat>
</flight>
<flight>
<callsign>Test_1005</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:40:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:00:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1005</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:45:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:05:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1006</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:10:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1006</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:55:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:15:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1007</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:20:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1008</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:10:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:30:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1009</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:20:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:40:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1010</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:30:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:50:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1011</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:40:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>02:00:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight>
<flight>
<callsign>Test_1012</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>01:50:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>02:10:00</time>
</arrival>
<repeat>02Hr</repeat>
</flight> </flight>
</trafficlist> </trafficlist>

View file

@ -41,7 +41,9 @@
#include <Scenery/scenery.hxx> #include <Scenery/scenery.hxx>
#include <Time/TimeManager.hxx> #include <Time/TimeManager.hxx>
#include <Traffic/TrafficMgr.hxx> #include <Traffic/TrafficMgr.hxx>
#include <simgear/math/sg_geodesy.hxx> #include <simgear/math/sg_geodesy.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/timing/sg_time.hxx> #include <simgear/timing/sg_time.hxx>
@ -50,11 +52,17 @@
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Set up function for each test. // Set up function for each test.
void TrafficTests::setUp() void TrafficTests::setUp()
{ {
time_t t = time(0); // get time now
time_t lastDay = t - t%86400 + 86400 + 9 * 60;
FGTestApi::setUp::initTestGlobals("Traffic"); FGTestApi::setUp::initTestGlobals("Traffic");
FGTestApi::setUp::initNavDataCache(); FGTestApi::setUp::initNavDataCache();
@ -77,6 +85,7 @@ void TrafficTests::setUp()
FGAirportRef ybbn = FGAirport::getByIdent("YBBN"); FGAirportRef ybbn = FGAirport::getByIdent("YBBN");
ybbn->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YBBN.groundnet.xml"); ybbn->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YBBN.groundnet.xml");
globals->add_new_subsystem<TimeManager>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<PerformanceDB>(SGSubsystemMgr::GENERAL); globals->add_new_subsystem<PerformanceDB>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGATCManager>(SGSubsystemMgr::GENERAL); globals->add_new_subsystem<FGATCManager>(SGSubsystemMgr::GENERAL);
globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL); globals->add_new_subsystem<FGAIManager>(SGSubsystemMgr::GENERAL);
@ -86,6 +95,8 @@ void TrafficTests::setUp()
globals->get_subsystem_mgr()->bind(); globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init(); globals->get_subsystem_mgr()->init();
globals->get_subsystem_mgr()->postinit(); globals->get_subsystem_mgr()->postinit();
// This means time is always 00:09
globals->get_subsystem<TimeManager>()->setTimeOffset("system", lastDay);
} }
// Clean up after each test. // Clean up after each test.
@ -133,9 +144,8 @@ void TrafficTests::testPushback()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -191,9 +201,8 @@ void TrafficTests::testPushbackCargo()
const int cruiseSpeedKnots = 80; const int cruiseSpeedKnots = 80;
const double crs = SGGeodesy::courseDeg(egph->geod(), egpf->geod()); // direct course const double crs = SGGeodesy::courseDeg(egph->geod(), egpf->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -251,9 +260,8 @@ void TrafficTests::testChangeRunway()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -309,9 +317,8 @@ void TrafficTests::testPushforward()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -366,9 +373,8 @@ void TrafficTests::testPushforwardSpeedy()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -424,9 +430,8 @@ void TrafficTests::testPushforwardParkYBBN()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -472,7 +477,7 @@ void TrafficTests::testPushforwardParkYBBNRepeatGa()
fgSetString("/sim/presets/airport-id", arrivalAirport->getId()); fgSetString("/sim/presets/airport-id", arrivalAirport->getId());
// Time to depart // Time to depart
std::string dep = getTimeString(60); std::string dep = getTimeString(120);
// Time to arrive // Time to arrive
std::string arr = getTimeString(3260); std::string arr = getTimeString(3260);
// Time to arrive back // Time to arrive back
@ -484,11 +489,11 @@ void TrafficTests::testPushforwardParkYBBNRepeatGa()
const char* flighttype = "ga"; const char* flighttype = "ga";
FGAISchedule* schedule = new FGAISchedule( FGAISchedule* schedule = new FGAISchedule(
"B737", "KLM", departureAirport->getId(), "G-BLA", "TST_BN_2", false, "B737", "KLM", "N", flighttype, radius, 8); "B737", "KLM", departureAirport->getId(), "G-BLA", "TST_BN_1", false, "B737", "KLM", "N", flighttype, radius, 8);
FGScheduledFlight* flight = new FGScheduledFlight("gaParkYSSY", "VFR", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "TST_BN_2"); FGScheduledFlight* flight = new FGScheduledFlight("gaParkYSSY", "VFR", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "TST_BN_1");
schedule->assign(flight); schedule->assign(flight);
FGScheduledFlight* returnFlight = new FGScheduledFlight("gaParkYSSY", "", arrivalAirport->getId(), departureAirport->getId(), 24, arr, ret, "WEEK", "TST_BN_2"); FGScheduledFlight* returnFlight = new FGScheduledFlight("gaParkYSSY", "", arrivalAirport->getId(), departureAirport->getId(), 24, arr, ret, "WEEK", "TST_BN_1");
schedule->assign(returnFlight); schedule->assign(returnFlight);
FGAIAircraft* aiAircraft = new FGAIAircraft{schedule}; FGAIAircraft* aiAircraft = new FGAIAircraft{schedule};
@ -505,9 +510,8 @@ void TrafficTests::testPushforwardParkYBBNRepeatGa()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -550,7 +554,7 @@ void TrafficTests::testPushforwardParkYBBNRepeatGate()
fgSetString("/sim/presets/airport-id", arrivalAirport->getId()); fgSetString("/sim/presets/airport-id", arrivalAirport->getId());
// Time to depart // Time to depart
std::string dep = getTimeString(60); std::string dep = getTimeString(10);
// Time to arrive // Time to arrive
std::string arr = getTimeString(3260); std::string arr = getTimeString(3260);
// Time to arrive back // Time to arrive back
@ -563,17 +567,17 @@ void TrafficTests::testPushforwardParkYBBNRepeatGate()
FGAISchedule* schedule = new FGAISchedule( FGAISchedule* schedule = new FGAISchedule(
"B737", "KLM", departureAirport->getId(), "G-BLA", "TST_BN_2", false, "B737", "KLM", "N", flighttype, radius, 8); "B737", "KLM", departureAirport->getId(), "G-BLA", "TST_BN_2", false, "B737", "KLM", "N", flighttype, radius, 8);
FGScheduledFlight* flight = new FGScheduledFlight("gaParkYSSY", "VFR", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "TST_BN_2"); FGScheduledFlight* flight = new FGScheduledFlight("gateParkYSSY", "VFR", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "TST_BN_1");
schedule->assign(flight); schedule->assign(flight);
FGScheduledFlight* returnFlight = new FGScheduledFlight("gaParkYSSY", "", arrivalAirport->getId(), departureAirport->getId(), 24, arr, ret, "WEEK", "TST_BN_2"); FGScheduledFlight* returnFlight = new FGScheduledFlight("gateParkYSSY", "", arrivalAirport->getId(), departureAirport->getId(), 24, arr, ret, "WEEK", "TST_BN_1");
schedule->assign(returnFlight); schedule->assign(returnFlight);
FGAIAircraft* aiAircraft = new FGAIAircraft{schedule};
const SGGeod position = departureAirport->geod(); const SGGeod position = departureAirport->geod();
FGTestApi::setPositionAndStabilise(position); FGTestApi::setPositionAndStabilise(position);
FGAIAircraft* aiAircraft = new FGAIAircraft{schedule};
aiAircraft->setPerformance("gate", ""); aiAircraft->setPerformance("gate", "");
aiAircraft->setCompany("KLM"); aiAircraft->setCompany("KLM");
aiAircraft->setAcType("B737"); aiAircraft->setAcType("B737");
@ -583,9 +587,8 @@ void TrafficTests::testPushforwardParkYBBNRepeatGate()
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml"; const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime; time_t departureTime = globals->get_time_params()->get_cur_time();
time(&departureTime); // now departureTime = departureTime - 90;
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft, std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime, flightPlanName, crs, departureTime,
@ -600,6 +603,8 @@ void TrafficTests::testPushforwardParkYBBNRepeatGate()
aiAircraft->FGAIBase::setFlightPlan(std::move(fp)); aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft); globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
CPPUNIT_ASSERT_EQUAL(aiAircraft->GetFlightPlan()->isValidPlan(), true);
aiAircraft = flyAI(aiAircraft, "flight_gate_YSSY_YBBN_park_repeat" + std::to_string(departureTime)); aiAircraft = flyAI(aiAircraft, "flight_gate_YSSY_YBBN_park_repeat" + std::to_string(departureTime));
int shortestDistance = 10000; int shortestDistance = 10000;
@ -627,37 +632,43 @@ void TrafficTests::testPushforwardParkYBBNRepeatGate()
FGAIAircraft * TrafficTests::flyAI(FGAIAircraft * aiAircraft, std::string fName) { FGAIAircraft * TrafficTests::flyAI(FGAIAircraft * aiAircraft, std::string fName) {
int lineIndex = 0; int lineIndex = 0;
time_t t = time(0); // get time now
time_t lastTenMinutes = t%600; CPPUNIT_ASSERT_EQUAL(aiAircraft->GetFlightPlan()->isValidPlan(), true);
// We move to stable time
int timeDiff = 900 - (t - lastTenMinutes);
globals->inc_sim_time_sec(timeDiff);
const long t2 = (long)globals->get_sim_time_sec(); time_t now = globals->get_time_params()->get_cur_time();
tm* startTime = localtime(&t2); tm* startTime = localtime(&now);
cout << "Start Time " << sgTimeFormatTime(startTime) << endl; time_t departureTime = aiAircraft->GetFlightPlan()->getStartTime();
char buffer[50];
char buffer2[50];
strftime (buffer,50,"%FT%TZ",startTime);
strftime (buffer2,50,"%FT%TZ", localtime(&departureTime));
SG_LOG(SG_AI, SG_DEBUG, "Start Time " << buffer << " First Departure " << buffer2);
char fname [160]; char fname [160];
time_t t = time(0); // get time now
sprintf (fname, "./LOGS/flightgear_%ld.csv", t); sprintf (fname, "./LOGS/flightgear_%ld.csv", t);
std::ofstream csvFile (fname, ios::trunc | ios::out); std::ofstream csvFile (fname, ios::trunc | ios::out);
if(!csvFile.is_open()) { if(!csvFile.is_open()) {
std::cerr << "File couldn't be opened" << endl; std::cerr << "File couldn't be opened" << endl;
} }
aiAircraft->dumpCSVHeader(csvFile);
if (sglog().get_log_priority() <= SG_DEBUG) { if (sglog().get_log_priority() <= SG_DEBUG) {
FGTestApi::setUp::logLinestringsToKML(fName); aiAircraft->dumpCSVHeader(csvFile);
FGTestApi::setUp::logLinestringsToKML(fName);
} }
flightgear::SGGeodVec geods = flightgear::SGGeodVec(); flightgear::SGGeodVec geods = flightgear::SGGeodVec();
char buffer[50];
int iteration = 1; int iteration = 1;
int lastLeg = -1; int lastLeg = -1;
double lastHeading = -500; double lastHeading = -500;
double headingSum = 0; double headingSum = 0;
int startSpeed = aiAircraft->GetFlightPlan()->getCurrentWaypoint()->getSpeed();
aiAircraft->AccelTo(startSpeed);
int timeOffset = 0;
for (size_t i = 0; i < 12000000 && !(aiAircraft->getDie()) && aiAircraft->GetFlightPlan()->getLeg() < 10; i++) { for (size_t i = 0; i < 12000000 && !(aiAircraft->getDie()) && aiAircraft->GetFlightPlan()->getLeg() < 10; i++) {
CPPUNIT_ASSERT_EQUAL(aiAircraft->GetFlightPlan()->isValidPlan(), true);
if (!aiAircraft->getDie()) { if (!aiAircraft->getDie()) {
// collect position // collect position
if (geods.empty() || if (geods.empty() ||
@ -697,12 +708,21 @@ FGAIAircraft * TrafficTests::flyAI(FGAIAircraft * aiAircraft, std::string fName)
// A flight without loops should never reach 400° // A flight without loops should never reach 400°
CPPUNIT_ASSERT_LESSEQUAL(400.0, headingSum); CPPUNIT_ASSERT_LESSEQUAL(400.0, headingSum);
CPPUNIT_ASSERT_LESSEQUAL(10, aiAircraft->GetFlightPlan()->getLeg()); CPPUNIT_ASSERT_LESSEQUAL(10, aiAircraft->GetFlightPlan()->getLeg());
CPPUNIT_ASSERT_MESSAGE( "Aircraft has not completed test in time.", i < 30000); CPPUNIT_ASSERT_MESSAGE( "Aircraft has not completed test in time.", i < 3000000);
time_t now = globals->get_time_params()->get_cur_time(); if (iteration > 1
&& aiAircraft->GetFlightPlan()->getLeg() == 1
&& aiAircraft->getSpeed() == 0 ) {
// Arrived at a parking
int beforeNextDepTime = aiAircraft->getTrafficRef()->getDepartureTime() - 30;
int seconds = beforeNextDepTime - globals->get_time_params()->get_cur_time();
if (seconds > 0) {
// Next departure
timeOffset += seconds;
globals->get_time_params()->update(globals->get_view_position(), globals->get_time_params()->get_cur_time(), seconds);
SG_LOG(SG_AI, SG_BULK, "time leap " << seconds );
}
}
FGTestApi::runForTime(1); FGTestApi::runForTime(1);
time_t after = globals->get_time_params()->get_cur_time();
// Make sure time is progressing
CPPUNIT_ASSERT_LESS(after, now);
} }
lastLeg = aiAircraft->GetFlightPlan()->getLeg(); lastLeg = aiAircraft->GetFlightPlan()->getLeg();
sprintf(buffer, "AI Leg %d Callsign %s Iteration %d", lastLeg, aiAircraft->getCallSign().c_str(), iteration); sprintf(buffer, "AI Leg %d Callsign %s Iteration %d", lastLeg, aiAircraft->getCallSign().c_str(), iteration);
@ -717,8 +737,7 @@ FGAIAircraft * TrafficTests::flyAI(FGAIAircraft * aiAircraft, std::string fName)
std::string TrafficTests::getTimeString(int timeOffset) std::string TrafficTests::getTimeString(int timeOffset)
{ {
char ret[11]; char ret[11];
time_t rawtime; time_t rawtime = globals->get_time_params()->get_cur_time();
time (&rawtime);
rawtime = rawtime + timeOffset; rawtime = rawtime + timeOffset;
tm* timeinfo = gmtime(&rawtime); tm* timeinfo = gmtime(&rawtime);
strftime(ret, 11, "%w/%H:%M:%S", timeinfo); strftime(ret, 11, "%w/%H:%M:%S", timeinfo);