#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/util/OsgMath.hxx>
+#include <simgear/timing/sg_time.hxx>
+
#include <Scenery/scenery.hxx>
#include "trafficcontrol.hxx"
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/performancedata.hxx>
-#include <AIModel/performancedb.hxx>
#include <ATC/atc_mgr.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <Airports/groundnetwork.hxx>
using std::cout;
using std::endl;
+namespace {
+
+TrafficVectorIterator findTraffic(TrafficVector& vec, int id)
+{
+ TrafficVectorIterator it = vec.begin();
+ for (; it != vec.end(); ++it) {
+ if (it->getId() == id) {
+ return it;
+ }
+ }
+
+ return it; // vec.end, effectively
+}
+
+void clearTrafficControllers(TrafficVector& vec)
+{
+ TrafficVectorIterator it = vec.begin();
+ for (; it != vec.end(); ++it) {
+ it->getAircraft()->clearATCController();
+ }
+}
+
+} // of anonymous namespace
+
/***************************************************************************
* ActiveRunway
**************************************************************************/
estimatedArrivalTimes.push_back(newEta);
sort(estimatedArrivalTimes.begin(), estimatedArrivalTimes.end());
// do some housekeeping : remove any timestamps that are past
- time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+
+ time_t now = globals->get_time_params()->get_cur_time();
+
TimeVectorIterator i = estimatedArrivalTimes.begin();
while (i != estimatedArrivalTimes.end()) {
if ((*i) < now) {
allowPushback(true),
priority(0),
timer(0),
- latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0),
- aircraft(NULL)
+ latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
+{
+}
+
+FGTrafficRecord::~FGTrafficRecord()
{
}
}
}
}
+
+void FGTrafficRecord::setAircraft(FGAIAircraft *ref)
+{
+ aircraft = ref;
+}
+
+FGAIAircraft* FGTrafficRecord::getAircraft() const
+{
+ return aircraft.ptr();
+}
+
/**
* Check if another aircraft is ahead of the current one, and on the same
* return true / false is the is/isn't the case.
bool FGTrafficRecord::isActive(int margin) const
{
- time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+ time_t now = globals->get_time_params()->get_cur_time();
time_t deptime = aircraft->getTrafficRef()->getDepartureTime();
return ((now + margin) > deptime);
}
FGATCController::~FGATCController()
{
- //cerr << "running FGATController destructor" << endl;
+ FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
+ mgr->removeController(this);
}
string FGATCController::getGateName(FGAIAircraft * ref)
parent = par;
}
+FGTowerController::~FGTowerController()
+{
+ // to avoid the exception described in:
+ // https://sourceforge.net/p/flightgear/codetickets/1864/
+ // we want to ensure AI aircraft signing-off is a no-op now
+
+ clearTrafficControllers(activeTraffic);
+}
+
//
void FGTowerController::announcePosition(int id,
FGAIFlightPlan * intendedRoute,
parent = par;
}
+FGStartupController::~FGStartupController()
+{
+ clearTrafficControllers(activeTraffic);
+}
+
void FGStartupController::announcePosition(int id,
FGAIFlightPlan * intendedRoute,
int currentPosition, double lat,
// The user controlled aircraft should have crased here, because it doesn't have a traffic reference.
// NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
- time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+ time_t now = globals->get_time_params()->get_cur_time();
+
//cerr << i->getAircraft()->getTrafficRef()->getCallSign()
// << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
// << " at parking " << getGateName(i->getAircraft()) << endl;
//for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
double dx = 0;
- time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+ time_t now = globals->get_time_params()->get_cur_time();
+
for (TrafficVectorIterator i = activeTraffic.begin(); i != activeTraffic.end(); i++) {
if (i->isActive(300)) {
// Handle start point
parent = par;
}
+FGApproachController::~FGApproachController()
+{
+ clearTrafficControllers(activeTraffic);
+}
+
//
void FGApproachController::announcePosition(int id,
FGAIFlightPlan * intendedRoute,
}
void FGApproachController::render(bool visible) {
- std::cerr << "FGApproachController::render function not yet implemented" << std::endl;
+ //std::cerr << "FGApproachController::render function not yet implemented" << std::endl;
}