Maintenance: dynamics
initialize member variables. explicit ctor. move lastUpdate to initializer-list. reduce scope visibility of variables. ++prefix for complex types.
This commit is contained in:
parent
571018265f
commit
6b40b1474e
2 changed files with 200 additions and 211 deletions
src/Airports
|
@ -14,131 +14,127 @@
|
|||
#include <simgear/compiler.h>
|
||||
#include <simgear/structure/SGWeakPtr.hxx>
|
||||
|
||||
#include <Environment/environment_mgr.hxx>
|
||||
#include <AIModel/AIBase.hxx>
|
||||
#include <AIModel/AIManager.hxx>
|
||||
#include <Airports/groundnetwork.hxx>
|
||||
#include <Airports/runways.hxx>
|
||||
#include <Environment/environment.hxx>
|
||||
#include <Environment/environment_mgr.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/locale.hxx>
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
#include <Main/locale.hxx>
|
||||
#include <Airports/runways.hxx>
|
||||
#include <Airports/groundnetwork.hxx>
|
||||
#include <Navaids/NavDataCache.hxx>
|
||||
#include <AIModel/AIManager.hxx>
|
||||
#include <AIModel/AIBase.hxx>
|
||||
|
||||
#include "airport.hxx"
|
||||
#include "dynamics.hxx"
|
||||
|
||||
using std::sort;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::sort;
|
||||
|
||||
// #define RUNWAY_FALLBACK_DEBUG
|
||||
|
||||
class ParkingAssignment::ParkingAssignmentPrivate
|
||||
{
|
||||
public:
|
||||
ParkingAssignmentPrivate(FGParking* pk, FGAirportDynamics* dyn) :
|
||||
refCount(0),
|
||||
parking(pk),
|
||||
dynamics(dyn)
|
||||
{
|
||||
assert(pk);
|
||||
assert(dyn);
|
||||
retain(); // initial count of 1
|
||||
}
|
||||
|
||||
~ParkingAssignmentPrivate()
|
||||
{
|
||||
FGAirportDynamicsRef strongRef = dynamics.lock();
|
||||
if (strongRef) {
|
||||
strongRef->releaseParking(parking);
|
||||
}
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
if ((--refCount) == 0) {
|
||||
delete this;
|
||||
ParkingAssignmentPrivate(FGParking* pk, FGAirportDynamics* dyn) : refCount(0),
|
||||
parking(pk),
|
||||
dynamics(dyn)
|
||||
{
|
||||
assert(pk);
|
||||
assert(dyn);
|
||||
retain(); // initial count of 1
|
||||
}
|
||||
}
|
||||
|
||||
void retain()
|
||||
{
|
||||
++refCount;
|
||||
}
|
||||
~ParkingAssignmentPrivate()
|
||||
{
|
||||
FGAirportDynamicsRef strongRef = dynamics.lock();
|
||||
if (strongRef) {
|
||||
strongRef->releaseParking(parking);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int refCount;
|
||||
FGParkingRef parking;
|
||||
void release()
|
||||
{
|
||||
if ((--refCount) == 0) {
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
// we don't want an owning ref here, otherwise we
|
||||
// have a circular ownership from AirportDynamics -> us
|
||||
SGWeakPtr<FGAirportDynamics> dynamics;
|
||||
void retain()
|
||||
{
|
||||
++refCount;
|
||||
}
|
||||
|
||||
unsigned int refCount;
|
||||
FGParkingRef parking;
|
||||
|
||||
// we don't want an owning ref here, otherwise we
|
||||
// have a circular ownership from AirportDynamics -> us
|
||||
SGWeakPtr<FGAirportDynamics> dynamics;
|
||||
};
|
||||
|
||||
ParkingAssignment::ParkingAssignment() :
|
||||
_sharedData(NULL)
|
||||
ParkingAssignment::ParkingAssignment() : _sharedData(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ParkingAssignment::~ParkingAssignment()
|
||||
{
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
}
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
}
|
||||
}
|
||||
|
||||
ParkingAssignment::ParkingAssignment(FGParking* pk, FGAirportDynamics* dyn) :
|
||||
_sharedData(NULL)
|
||||
ParkingAssignment::ParkingAssignment(FGParking* pk, FGAirportDynamics* dyn) : _sharedData(NULL)
|
||||
{
|
||||
if (pk) {
|
||||
_sharedData = new ParkingAssignmentPrivate(pk, dyn);
|
||||
}
|
||||
if (pk) {
|
||||
_sharedData = new ParkingAssignmentPrivate(pk, dyn);
|
||||
}
|
||||
}
|
||||
|
||||
ParkingAssignment::ParkingAssignment(const ParkingAssignment& aOther) :
|
||||
_sharedData(aOther._sharedData)
|
||||
ParkingAssignment::ParkingAssignment(const ParkingAssignment& aOther) : _sharedData(aOther._sharedData)
|
||||
{
|
||||
if (_sharedData) {
|
||||
_sharedData->retain();
|
||||
}
|
||||
if (_sharedData) {
|
||||
_sharedData->retain();
|
||||
}
|
||||
}
|
||||
|
||||
void ParkingAssignment::operator=(const ParkingAssignment& aOther)
|
||||
{
|
||||
if (_sharedData == aOther._sharedData) {
|
||||
return; // self-assignment, special case
|
||||
}
|
||||
if (_sharedData == aOther._sharedData) {
|
||||
return; // self-assignment, special case
|
||||
}
|
||||
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
}
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
}
|
||||
|
||||
_sharedData = aOther._sharedData;
|
||||
if (_sharedData) {
|
||||
_sharedData->retain();
|
||||
}
|
||||
_sharedData = aOther._sharedData;
|
||||
if (_sharedData) {
|
||||
_sharedData->retain();
|
||||
}
|
||||
}
|
||||
|
||||
void ParkingAssignment::release()
|
||||
{
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
_sharedData = NULL;
|
||||
}
|
||||
if (_sharedData) {
|
||||
_sharedData->release();
|
||||
_sharedData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool ParkingAssignment::isValid() const
|
||||
{
|
||||
return (_sharedData != NULL);
|
||||
return (_sharedData != NULL);
|
||||
}
|
||||
|
||||
FGParking* ParkingAssignment::parking() const
|
||||
{
|
||||
return _sharedData ? _sharedData->parking.ptr() : NULL;
|
||||
return _sharedData ? _sharedData->parking.ptr() : NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -152,9 +148,9 @@ FGParking* ParkingAssignment::parking() const
|
|||
class NearbyAIObjectCache
|
||||
{
|
||||
public:
|
||||
NearbyAIObjectCache(FGAirportRef apt) :
|
||||
m_airport(apt)
|
||||
{}
|
||||
explicit NearbyAIObjectCache(FGAirportRef apt) : m_airport(apt)
|
||||
{
|
||||
}
|
||||
|
||||
bool isAnythingNear(const SGVec3d& cart, double radiusM)
|
||||
{
|
||||
|
@ -197,17 +193,15 @@ private:
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FGAirportDynamics::FGAirportDynamics(FGAirport * ap):
|
||||
_ap(ap), rwyPrefs(ap),
|
||||
startupController (this),
|
||||
towerController (this),
|
||||
approachController (this),
|
||||
groundController (this),
|
||||
atisSequenceIndex(-1),
|
||||
atisSequenceTimeStamp(0.0)
|
||||
|
||||
FGAirportDynamics::FGAirportDynamics(FGAirport* ap) : _ap(ap), rwyPrefs(ap),
|
||||
startupController(this),
|
||||
towerController(this),
|
||||
approachController(this),
|
||||
groundController(this),
|
||||
lastUpdate{0},
|
||||
atisSequenceIndex(-1),
|
||||
atisSequenceTimeStamp(0.0)
|
||||
{
|
||||
lastUpdate = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
|
@ -223,16 +217,16 @@ void FGAirportDynamics::init()
|
|||
groundController.init();
|
||||
}
|
||||
|
||||
FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std::string & flType,
|
||||
const std::string & airline,
|
||||
bool skipEmptyAirlineCode)
|
||||
FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std::string& flType,
|
||||
const std::string& airline,
|
||||
bool skipEmptyAirlineCode)
|
||||
{
|
||||
NearbyAIObjectCache nearCache(parent());
|
||||
const FGParkingList& parkings(parent()->groundNetwork()->allParkings());
|
||||
FGParkingList candidates;
|
||||
for (auto parking : parkings) {
|
||||
if (!isParkingAvailable(parking)) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parking->getRadius() < radius) {
|
||||
|
@ -244,13 +238,13 @@ FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std:
|
|||
}
|
||||
|
||||
if (skipEmptyAirlineCode && parking->getCodes().empty()) {
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!airline.empty() && !parking->getCodes().empty()) {
|
||||
if (parking->getCodes().find(airline, 0) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
if (parking->getCodes().find(airline, 0) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (nearCache.isAnythingNear(parking->cart(), parking->getRadius())) {
|
||||
|
@ -278,9 +272,8 @@ FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const std:
|
|||
bool FGAirportDynamics::hasParking(FGParking* parking) const
|
||||
{
|
||||
return std::find(parent()->groundNetwork()->allParkings().begin(),
|
||||
parent()->groundNetwork()->allParkings().end(),
|
||||
parking)
|
||||
!= parent()->groundNetwork()->allParkings().end();
|
||||
parent()->groundNetwork()->allParkings().end(),
|
||||
parking) != parent()->groundNetwork()->allParkings().end();
|
||||
}
|
||||
|
||||
bool FGAirportDynamics::hasParkings() const
|
||||
|
@ -288,28 +281,28 @@ bool FGAirportDynamics::hasParkings() const
|
|||
return !parent()->groundNetwork()->allParkings().empty();
|
||||
}
|
||||
|
||||
ParkingAssignment FGAirportDynamics::getAvailableParking(double radius,
|
||||
const std::string & flType,
|
||||
const std::string & acType,
|
||||
const std::string & airline)
|
||||
ParkingAssignment FGAirportDynamics::getAvailableParking(double radius,
|
||||
const std::string& flType,
|
||||
const std::string& acType,
|
||||
const std::string& airline)
|
||||
{
|
||||
SG_UNUSED(acType); // sadly not used at the moment
|
||||
SG_UNUSED(acType); // sadly not used at the moment
|
||||
|
||||
// most exact seach - airline codes must be present and match
|
||||
FGParking* result = innerGetAvailableParking(radius, flType, airline, true);
|
||||
if (result) {
|
||||
return ParkingAssignment(result, this);
|
||||
}
|
||||
// most exact seach - airline codes must be present and match
|
||||
FGParking* result = innerGetAvailableParking(radius, flType, airline, true);
|
||||
if (result) {
|
||||
return ParkingAssignment(result, this);
|
||||
}
|
||||
|
||||
// more tolerant - gates with empty airline codes are permitted
|
||||
result = innerGetAvailableParking(radius, flType, airline, false);
|
||||
if (result) {
|
||||
return ParkingAssignment(result, this);
|
||||
}
|
||||
// more tolerant - gates with empty airline codes are permitted
|
||||
result = innerGetAvailableParking(radius, flType, airline, false);
|
||||
if (result) {
|
||||
return ParkingAssignment(result, this);
|
||||
}
|
||||
|
||||
// fallback - ignore the airline code entirely
|
||||
result = innerGetAvailableParking(radius, flType, std::string(), false);
|
||||
return result ? ParkingAssignment(result, this) : ParkingAssignment();
|
||||
// fallback - ignore the airline code entirely
|
||||
result = innerGetAvailableParking(radius, flType, std::string(), false);
|
||||
return result ? ParkingAssignment(result, this) : ParkingAssignment();
|
||||
}
|
||||
|
||||
ParkingAssignment FGAirportDynamics::getParkingByName(const std::string& name) const
|
||||
|
@ -325,12 +318,12 @@ ParkingAssignment FGAirportDynamics::getParkingByName(const std::string& name) c
|
|||
return ParkingAssignment();
|
||||
}
|
||||
|
||||
ParkingAssignment FGAirportDynamics::getAvailableParkingByName(const std::string & name)
|
||||
ParkingAssignment FGAirportDynamics::getAvailableParkingByName(const std::string& name)
|
||||
{
|
||||
const FGParkingList& parkings(parent()->groundNetwork()->allParkings());
|
||||
auto it = std::find_if(parkings.begin(), parkings.end(), [this, name] (FGParkingRef parking){
|
||||
if (parking->name() != name)
|
||||
return false;
|
||||
auto it = std::find_if(parkings.begin(), parkings.end(), [this, name](FGParkingRef parking) {
|
||||
if (parking->name() != name)
|
||||
return false;
|
||||
|
||||
return this->isParkingAvailable(parking);
|
||||
});
|
||||
|
@ -354,26 +347,26 @@ FGParkingRef FGAirportDynamics::getOccupiedParkingByName(const std::string& name
|
|||
|
||||
void FGAirportDynamics::setParkingAvailable(FGParking* park, bool available)
|
||||
{
|
||||
if (available) {
|
||||
releaseParking(park);
|
||||
} else {
|
||||
occupiedParkings.insert(park);
|
||||
}
|
||||
if (available) {
|
||||
releaseParking(park);
|
||||
} else {
|
||||
occupiedParkings.insert(park);
|
||||
}
|
||||
}
|
||||
|
||||
bool FGAirportDynamics::isParkingAvailable(FGParking* parking) const
|
||||
{
|
||||
return (occupiedParkings.find(parking) == occupiedParkings.end());
|
||||
return (occupiedParkings.find(parking) == occupiedParkings.end());
|
||||
}
|
||||
|
||||
void FGAirportDynamics::releaseParking(FGParking* id)
|
||||
{
|
||||
ParkingSet::iterator it = occupiedParkings.find(id);
|
||||
if (it == occupiedParkings.end()) {
|
||||
return;
|
||||
}
|
||||
ParkingSet::iterator it = occupiedParkings.find(id);
|
||||
if (it == occupiedParkings.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
occupiedParkings.erase(it);
|
||||
occupiedParkings.erase(it);
|
||||
}
|
||||
|
||||
class GetParkingsPredicate
|
||||
|
@ -381,12 +374,13 @@ class GetParkingsPredicate
|
|||
bool mustBeAvailable;
|
||||
std::string type;
|
||||
const FGAirportDynamics* dynamics;
|
||||
|
||||
public:
|
||||
GetParkingsPredicate(bool b, const std::string& ty, const FGAirportDynamics* dyn) :
|
||||
mustBeAvailable(b),
|
||||
type(ty),
|
||||
dynamics(dyn)
|
||||
{}
|
||||
GetParkingsPredicate(bool b, const std::string& ty, const FGAirportDynamics* dyn) : mustBeAvailable(b),
|
||||
type(ty),
|
||||
dynamics(dyn)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()(const FGParkingRef& park) const
|
||||
{
|
||||
|
@ -401,7 +395,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
FGParkingList FGAirportDynamics::getParkings(bool onlyAvailable, const std::string &type) const
|
||||
FGParkingList FGAirportDynamics::getParkings(bool onlyAvailable, const std::string& type) const
|
||||
{
|
||||
FGParkingList result(parent()->groundNetwork()->allParkings());
|
||||
|
||||
|
@ -411,7 +405,7 @@ FGParkingList FGAirportDynamics::getParkings(bool onlyAvailable, const std::stri
|
|||
return result;
|
||||
}
|
||||
|
||||
void FGAirportDynamics::setRwyUse(const FGRunwayPreference & ref)
|
||||
void FGAirportDynamics::setRwyUse(const FGRunwayPreference& ref)
|
||||
{
|
||||
rwyPrefs = ref;
|
||||
}
|
||||
|
@ -446,8 +440,7 @@ typedef std::vector<FGRunwayRef> RunwayVec;
|
|||
class FallbackRunwayGroup
|
||||
{
|
||||
public:
|
||||
FallbackRunwayGroup(const FGRunwayRef& rwy) :
|
||||
_groupScore(0.0)
|
||||
explicit FallbackRunwayGroup(const FGRunwayRef& rwy) : _groupScore(0.0)
|
||||
{
|
||||
runways.push_back(rwy);
|
||||
_leadRunwayScore = runwayScore(rwy);
|
||||
|
@ -493,7 +486,7 @@ public:
|
|||
|
||||
void getRunways(FGRunwayList& arrivals, FGRunwayList& departures)
|
||||
{
|
||||
// make the common cases very obvious
|
||||
// make the common cases very obvious
|
||||
if (runways.size() == 1) {
|
||||
arrivals.push_back(runways.front());
|
||||
departures.push_back(runways.front());
|
||||
|
@ -501,9 +494,9 @@ public:
|
|||
}
|
||||
|
||||
|
||||
// because runways were sorted by score when building, they were added
|
||||
// by score also, so we can use a simple algorithm to assign
|
||||
for (unsigned int r=0; r < runways.size(); ++r) {
|
||||
// because runways were sorted by score when building, they were added
|
||||
// by score also, so we can use a simple algorithm to assign
|
||||
for (unsigned int r = 0; r < runways.size(); ++r) {
|
||||
if ((r % 2) == 0) {
|
||||
arrivals.push_back(runways[r]);
|
||||
} else {
|
||||
|
@ -516,7 +509,7 @@ public:
|
|||
{
|
||||
std::ostringstream os;
|
||||
os << runways.front()->ident();
|
||||
for (unsigned int r=1; r <runways.size(); ++r) {
|
||||
for (unsigned int r = 1; r < runways.size(); ++r) {
|
||||
os << ", " << runways[r]->ident();
|
||||
}
|
||||
|
||||
|
@ -528,22 +521,22 @@ private:
|
|||
RunwayVec runways;
|
||||
double _groupScore,
|
||||
_leadRunwayScore;
|
||||
double _basicScore;
|
||||
|
||||
double _basicScore{0.0};
|
||||
};
|
||||
|
||||
class WindExclusionCheck
|
||||
{
|
||||
public:
|
||||
WindExclusionCheck(double windHeading, double windSpeedKts) :
|
||||
_windSpeedKts(windSpeedKts),
|
||||
_windHeading(windHeading)
|
||||
{}
|
||||
WindExclusionCheck(double windHeading, double windSpeedKts) : _windSpeedKts(windSpeedKts),
|
||||
_windHeading(windHeading)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()(const FGRunwayRef& rwy) const
|
||||
{
|
||||
return (runwayWindScore(rwy, _windHeading, _windSpeedKts) > 30);
|
||||
}
|
||||
|
||||
private:
|
||||
double _windSpeedKts,
|
||||
_windHeading;
|
||||
|
@ -577,7 +570,7 @@ std::string FGAirportDynamics::fallbackGetActiveRunway(int action, double headin
|
|||
}
|
||||
|
||||
if (updateNeeded) {
|
||||
double windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt");
|
||||
double windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt");
|
||||
double windHeading = fgGetInt("/environment/metar/base-wind-dir-deg");
|
||||
|
||||
// discount runways based on cross / tail-wind
|
||||
|
@ -647,17 +640,17 @@ std::string FGAirportDynamics::fallbackGetActiveRunway(int action, double headin
|
|||
#if defined(RUNWAY_FALLBACK_DEBUG)
|
||||
ostringstream os;
|
||||
os << "\tArrival:" << _fallbackArrivalRunways.front()->ident();
|
||||
for (unsigned int r=1; r <_fallbackArrivalRunways.size(); ++r) {
|
||||
for (unsigned int r = 1; r < _fallbackArrivalRunways.size(); ++r) {
|
||||
os << ", " << _fallbackArrivalRunways[r]->ident();
|
||||
}
|
||||
os << "\n\tDeparture:" << _fallbackDepartureRunways.front()->ident();
|
||||
for (unsigned int r=1; r <_fallbackDepartureRunways.size(); ++r) {
|
||||
for (unsigned int r = 1; r < _fallbackDepartureRunways.size(); ++r) {
|
||||
os << ", " << _fallbackDepartureRunways[r]->ident();
|
||||
}
|
||||
|
||||
std::string s = os.str();
|
||||
SG_LOG(SG_AI, SG_INFO, parent()->ident() << " fallback runways assignments for "
|
||||
<< static_cast<int>(windHeading) << "@" << static_cast<int>(windSpeed) << "\n" << s);
|
||||
SG_LOG(SG_AI, SG_INFO, parent()->ident() << " fallback runways assignments for " << static_cast<int>(windHeading) << "@" << static_cast<int>(windSpeed) << "\n"
|
||||
<< s);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -673,27 +666,17 @@ std::string FGAirportDynamics::fallbackGetActiveRunway(int action, double headin
|
|||
return r->ident();
|
||||
}
|
||||
|
||||
bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
||||
int action, std::string & runway,
|
||||
bool FGAirportDynamics::innerGetActiveRunway(const std::string& trafficType,
|
||||
int action, std::string& runway,
|
||||
double heading)
|
||||
{
|
||||
double windSpeed;
|
||||
double windHeading;
|
||||
double maxTail;
|
||||
double maxCross;
|
||||
std::string name;
|
||||
std::string type;
|
||||
|
||||
if (!rwyPrefs.available()) {
|
||||
runway = fallbackGetActiveRunway(action, heading);
|
||||
return !runway.empty();
|
||||
}
|
||||
|
||||
RunwayGroup *currRunwayGroup = 0;
|
||||
int nrActiveRunways = 0;
|
||||
time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
|
||||
if ((std::abs((long) (dayStart - lastUpdate)) > 600)
|
||||
|| trafficType != prevTrafficType) {
|
||||
if ((std::abs((long)(dayStart - lastUpdate)) > 600) || trafficType != prevTrafficType) {
|
||||
landing.clear();
|
||||
takeoff.clear();
|
||||
lastUpdate = dayStart;
|
||||
|
@ -705,8 +688,8 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
->getEnvironment(getLatitude(), getLongitude(),
|
||||
getElevation());
|
||||
*/
|
||||
windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt"); //stationweather.get_wind_speed_kt();
|
||||
windHeading = fgGetInt("/environment/metar/base-wind-dir-deg");
|
||||
double windSpeed = fgGetInt("/environment/metar/base-wind-speed-kt"); //stationweather.get_wind_speed_kt();
|
||||
double windHeading = fgGetInt("/environment/metar/base-wind-dir-deg");
|
||||
//stationweather.get_wind_from_heading_deg();
|
||||
std::string scheduleName;
|
||||
//cerr << "finding active Runway for : " << _ap->getId() << endl;
|
||||
|
@ -715,24 +698,23 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
|
||||
//cerr << "Nr of seconds since day start << " << dayStart << endl;
|
||||
|
||||
ScheduleTime *currSched;
|
||||
ScheduleTime* currSched;
|
||||
//cerr << "A"<< endl;
|
||||
currSched = rwyPrefs.getSchedule(trafficType.c_str());
|
||||
if (!(currSched))
|
||||
return false;
|
||||
//cerr << "B"<< endl;
|
||||
scheduleName = currSched->getName(dayStart);
|
||||
maxTail = currSched->getTailWind();
|
||||
maxCross = currSched->getCrossWind();
|
||||
double maxTail = currSched->getTailWind();
|
||||
double maxCross = currSched->getCrossWind();
|
||||
//cerr << "Current Schedule = : " << scheduleName << endl;
|
||||
if (scheduleName.empty())
|
||||
return false;
|
||||
//cerr << "C"<< endl;
|
||||
currRunwayGroup = rwyPrefs.getGroup(scheduleName);
|
||||
RunwayGroup* currRunwayGroup = rwyPrefs.getGroup(scheduleName);
|
||||
//cerr << "D"<< endl;
|
||||
if (!(currRunwayGroup))
|
||||
return false;
|
||||
nrActiveRunways = currRunwayGroup->getNrActiveRunways();
|
||||
|
||||
// Keep a history of the currently active runways, to ensure
|
||||
// that an already established selection of runways will not
|
||||
|
@ -748,12 +730,12 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
currentlyActive = &ulActive;
|
||||
}
|
||||
|
||||
//cerr << "Durrently active selection for " << trafficType << ": ";
|
||||
//cerr << "Currently active selection for " << trafficType << ": ";
|
||||
for (stringVecIterator it = currentlyActive->begin();
|
||||
it != currentlyActive->end(); it++) {
|
||||
//cerr << (*it) << " ";
|
||||
}
|
||||
//cerr << endl;
|
||||
it != currentlyActive->end(); ++it) {
|
||||
//cerr << (*it) << " ";
|
||||
}
|
||||
//cerr << endl;
|
||||
|
||||
currRunwayGroup->setActive(_ap,
|
||||
windSpeed,
|
||||
|
@ -764,10 +746,12 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
// general aviation, one for commercial and one for military
|
||||
// traffic.
|
||||
currentlyActive->clear();
|
||||
nrActiveRunways = currRunwayGroup->getNrActiveRunways();
|
||||
int nrActiveRunways = currRunwayGroup->getNrActiveRunways();
|
||||
//cerr << "Choosing runway for " << trafficType << endl;
|
||||
for (int i = 0; i < nrActiveRunways; i++) {
|
||||
type = "unknown"; // initialize to something other than landing or takeoff
|
||||
std::string name;
|
||||
std::string type = "unknown"; // initialize to something other than landing or takeoff
|
||||
|
||||
currRunwayGroup->getActive(i, name, type);
|
||||
if (type == "landing") {
|
||||
landing.push_back(name);
|
||||
|
@ -783,7 +767,7 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
//cerr << endl;
|
||||
}
|
||||
|
||||
if (action == 1) // takeoff
|
||||
if (action == 1) // takeoff
|
||||
{
|
||||
int nr = takeoff.size();
|
||||
if (nr) {
|
||||
|
@ -791,12 +775,12 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
// multiple active runways for this action. This should be
|
||||
// under ATC control.
|
||||
runway = chooseRwyByHeading(takeoff, heading);
|
||||
} else { // Fallback
|
||||
} else { // Fallback
|
||||
runway = chooseRunwayFallback();
|
||||
}
|
||||
}
|
||||
|
||||
if (action == 2) // landing
|
||||
if (action == 2) // landing
|
||||
{
|
||||
if (!landing.empty()) {
|
||||
runway = chooseRwyByHeading(landing, heading);
|
||||
|
@ -811,19 +795,18 @@ bool FGAirportDynamics::innerGetActiveRunway(const std::string & trafficType,
|
|||
}
|
||||
|
||||
std::string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
|
||||
double heading)
|
||||
double heading)
|
||||
{
|
||||
double bestError = 360.0;
|
||||
double rwyHeading, headingError;
|
||||
std::string runway;
|
||||
for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) {
|
||||
for (stringVecIterator i = rwys.begin(); i != rwys.end(); ++i) {
|
||||
if (!_ap->hasRunwayWithIdent(*i)) {
|
||||
SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i <<
|
||||
" not found at " << _ap->ident());
|
||||
continue;
|
||||
SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i << " not found at " << _ap->ident());
|
||||
continue;
|
||||
}
|
||||
|
||||
FGRunway *rwy = _ap->getRunwayByIdent((*i));
|
||||
FGRunway* rwy = _ap->getRunwayByIdent((*i));
|
||||
rwyHeading = rwy->headingDeg();
|
||||
headingError = fabs(heading - rwyHeading);
|
||||
if (headingError > 180)
|
||||
|
@ -837,8 +820,8 @@ std::string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
|
|||
return runway;
|
||||
}
|
||||
|
||||
void FGAirportDynamics::getActiveRunway(const std::string & trafficType,
|
||||
int action, std::string & runway,
|
||||
void FGAirportDynamics::getActiveRunway(const std::string& trafficType,
|
||||
int action, std::string& runway,
|
||||
double heading)
|
||||
{
|
||||
bool ok = innerGetActiveRunway(trafficType, action, runway, heading);
|
||||
|
@ -849,7 +832,7 @@ void FGAirportDynamics::getActiveRunway(const std::string & trafficType,
|
|||
|
||||
std::string FGAirportDynamics::chooseRunwayFallback()
|
||||
{
|
||||
FGRunway *rwy = _ap->getActiveRunwayForUsage();
|
||||
FGRunway* rwy = _ap->getActiveRunwayForUsage();
|
||||
if (!rwy) {
|
||||
SG_LOG(SG_AI, SG_WARN, "FGAirportDynamics::chooseRunwayFallback failed at " << _ap->ident());
|
||||
|
||||
|
@ -895,8 +878,10 @@ int FGAirportDynamics::getApproachFrequency(unsigned nr)
|
|||
if ((freqApproach.size() < nr - 1) && (nr > 1)) {
|
||||
approachFreq =
|
||||
(freqApproach.size() <
|
||||
(nr - 1)) ? freqApproach[freqApproach.size() -
|
||||
1] : freqApproach[nr - 2];
|
||||
(nr - 1))
|
||||
? freqApproach[freqApproach.size() -
|
||||
1]
|
||||
: freqApproach[nr - 2];
|
||||
}
|
||||
if ((freqApproach.size() >= nr - 1) && (nr > 1)) {
|
||||
approachFreq = freqApproach[nr - 2];
|
||||
|
@ -923,8 +908,10 @@ int FGAirportDynamics::getGroundFrequency(unsigned leg)
|
|||
if ((freqGround.size() < leg) && (leg > 0)) {
|
||||
groundFreq =
|
||||
(freqGround.size() <=
|
||||
(leg - 1)) ? freqGround[freqGround.size() -
|
||||
1] : freqGround[leg - 1];
|
||||
(leg - 1))
|
||||
? freqGround[freqGround.size() -
|
||||
1]
|
||||
: freqGround[leg - 1];
|
||||
}
|
||||
if ((freqGround.size() >= leg) && (leg > 0)) {
|
||||
groundFreq = freqGround[leg - 1];
|
||||
|
@ -951,8 +938,10 @@ int FGAirportDynamics::getTowerFrequency(unsigned nr)
|
|||
if ((freqTower.size() < nr - 1) && (nr > 1)) {
|
||||
towerFreq =
|
||||
(freqTower.size() <
|
||||
(nr - 1)) ? freqTower[freqTower.size() -
|
||||
1] : freqTower[nr - 2];
|
||||
(nr - 1))
|
||||
? freqTower[freqTower.size() -
|
||||
1]
|
||||
: freqTower[nr - 2];
|
||||
}
|
||||
if ((freqTower.size() >= nr - 1) && (nr > 1)) {
|
||||
towerFreq = freqTower[nr - 2];
|
||||
|
@ -962,15 +951,15 @@ int FGAirportDynamics::getTowerFrequency(unsigned nr)
|
|||
|
||||
const std::string FGAirportDynamics::getAtisSequence()
|
||||
{
|
||||
if (atisSequenceIndex == -1) {
|
||||
updateAtisSequence(1, false);
|
||||
}
|
||||
if (atisSequenceIndex == -1) {
|
||||
updateAtisSequence(1, false);
|
||||
}
|
||||
|
||||
char atisSequenceString[2];
|
||||
atisSequenceString[0] = 'a' + atisSequenceIndex;
|
||||
atisSequenceString[1] = 0;
|
||||
char atisSequenceString[2];
|
||||
atisSequenceString[0] = 'a' + atisSequenceIndex;
|
||||
atisSequenceString[1] = 0;
|
||||
|
||||
return globals->get_locale()->getLocalizedString(atisSequenceString, "atc", "unknown");
|
||||
return globals->get_locale()->getLocalizedString(atisSequenceString, "atc", "unknown");
|
||||
}
|
||||
|
||||
int FGAirportDynamics::updateAtisSequence(int interval, bool forceUpdate)
|
||||
|
@ -991,5 +980,5 @@ int FGAirportDynamics::updateAtisSequence(int interval, bool forceUpdate)
|
|||
|
||||
atisSequenceIndex = (atisSequenceIndex + steps) % 26;
|
||||
// return a huge value if no update occurred
|
||||
return (atisSequenceIndex + (steps ? 0 : 26*1000));
|
||||
return (atisSequenceIndex + (steps ? 0 : 26 * 1000));
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
stringVec landing;
|
||||
stringVec takeoff;
|
||||
stringVec milActive, comActive, genActive, ulActive;
|
||||
stringVec* currentlyActive;
|
||||
stringVec* currentlyActive{nullptr};
|
||||
|
||||
int atisSequenceIndex;
|
||||
double atisSequenceTimeStamp;
|
||||
|
@ -86,7 +86,7 @@ private:
|
|||
SGTimeStamp _lastFallbackUpdate;
|
||||
FGRunwayList _fallbackDepartureRunways,
|
||||
_fallbackArrivalRunways;
|
||||
unsigned int _fallbackRunwayCounter;
|
||||
unsigned int _fallbackRunwayCounter{0};
|
||||
|
||||
public:
|
||||
explicit FGAirportDynamics(FGAirport* ap);
|
||||
|
|
Loading…
Add table
Reference in a new issue