Replace activeTraffic iterations with a standard function
This commit is contained in:
parent
3e1dc4683b
commit
18c0613762
4 changed files with 90 additions and 245 deletions
|
@ -20,14 +20,13 @@
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <osg/Geode>
|
#include <osg/Geode>
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
|
@ -105,17 +104,10 @@ bool compare_trafficrecords(FGTrafficRecord a, FGTrafficRecord b)
|
||||||
*/
|
*/
|
||||||
TrafficVectorIterator FGGroundController::searchActiveTraffic(int id)
|
TrafficVectorIterator FGGroundController::searchActiveTraffic(int id)
|
||||||
{
|
{
|
||||||
// Possible optimization - investigate using map instead of vector
|
return std::find_if(activeTraffic.begin(), activeTraffic.end(),
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
[id] (const FGTrafficRecord& rec)
|
||||||
if (!activeTraffic.empty()) {
|
{ return rec.getId() == id; }
|
||||||
while (i != activeTraffic.end()) {
|
);
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGGroundController::announcePosition(int id,
|
void FGGroundController::announcePosition(int id,
|
||||||
|
@ -226,20 +218,10 @@ void FGGroundController::updateAircraftInformation(int id, double lat, double lo
|
||||||
// Transmit confirmation ...
|
// Transmit confirmation ...
|
||||||
// Probably use a status mechanism similar to the Engine start procedure in the startup controller.
|
// Probably use a status mechanism similar to the Engine start procedure in the startup controller.
|
||||||
|
|
||||||
// leave this here until I figure out what current, closest is all about
|
// Search the activeTraffic vector to find a traffic vector with our id
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
TrafficVectorIterator i = searchActiveTraffic(id);
|
||||||
// Search search if the current id has an entry
|
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
TrafficVectorIterator current, closest;
|
TrafficVectorIterator current, closest;
|
||||||
if (activeTraffic.size()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// update position of the current aircraft
|
// update position of the current aircraft
|
||||||
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||||
|
@ -313,20 +295,12 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
|
||||||
{
|
{
|
||||||
|
|
||||||
TrafficVectorIterator current, closest, closestOnNetwork;
|
TrafficVectorIterator current, closest, closestOnNetwork;
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
|
||||||
bool otherReasonToSlowDown = false;
|
bool otherReasonToSlowDown = false;
|
||||||
// bool previousInstruction;
|
// bool previousInstruction;
|
||||||
if (activeTraffic.size()) {
|
TrafficVectorIterator i = searchActiveTraffic(id);
|
||||||
//while ((i->getId() != id) && (i != activeTraffic.end()))
|
if (!activeTraffic.size()) {
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT,
|
SG_LOG(SG_GENERAL, SG_ALERT,
|
||||||
"AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkSpeedAdjustment at " << SG_ORIGIN);
|
"AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkSpeedAdjustment at " << SG_ORIGIN);
|
||||||
|
@ -409,10 +383,10 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Clear any active speed adjustment, check if the aircraft needs to brake
|
// Clear any active speed adjustment, check if the aircraft needs to brake
|
||||||
current->clearSpeedAdjustment();
|
current->clearSpeedAdjustment();
|
||||||
bool needBraking = false;
|
bool needBraking = false;
|
||||||
|
|
||||||
if (current->checkPositionAndIntentions(*closest)
|
if (current->checkPositionAndIntentions(*closest)
|
||||||
|| otherReasonToSlowDown) {
|
|| otherReasonToSlowDown) {
|
||||||
double maxAllowableDistance =
|
double maxAllowableDistance =
|
||||||
|
@ -423,7 +397,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
current->setWaitsForId(closest->getId());
|
current->setWaitsForId(closest->getId());
|
||||||
|
|
||||||
if (closest->getId() != current->getId()) {
|
if (closest->getId() != current->getId()) {
|
||||||
current->setSpeedAdjustment(closest->getSpeed() *
|
current->setSpeedAdjustment(closest->getSpeed() *
|
||||||
(mindist / 100));
|
(mindist / 100));
|
||||||
|
@ -438,7 +412,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
|
||||||
} else {
|
} else {
|
||||||
current->setSpeedAdjustment(0); // This can only happen when the user aircraft is the one closest
|
current->setSpeedAdjustment(0); // This can only happen when the user aircraft is the one closest
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mindist < maxAllowableDistance) {
|
if (mindist < maxAllowableDistance) {
|
||||||
//double newSpeed = (maxAllowableDistance-mindist);
|
//double newSpeed = (maxAllowableDistance-mindist);
|
||||||
//current->setSpeedAdjustment(newSpeed);
|
//current->setSpeedAdjustment(newSpeed);
|
||||||
|
@ -449,7 +423,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((closest->getId() == closestOnNetwork->getId()) && (current->getPriority() < closest->getPriority()) && needBraking) {
|
if ((closest->getId() == closestOnNetwork->getId()) && (current->getPriority() < closest->getPriority()) && needBraking) {
|
||||||
swap(current, closest);
|
swap(current, closest);
|
||||||
}
|
}
|
||||||
|
@ -1073,10 +1047,11 @@ bool FGGroundController::updateActiveTraffic(TrafficVectorIterator i,
|
||||||
FGTaxiSegment* segment = network->findSegment(pos);
|
FGTaxiSegment* segment = network->findSegment(pos);
|
||||||
length = segment->getLength();
|
length = segment->getLength();
|
||||||
if (segment->hasBlock(now)) {
|
if (segment->hasBlock(now)) {
|
||||||
//SG_LOG(SG_GENERAL, SG_ALERT, "Taxiway incursion for AI aircraft" << i->getAircraft()->getCallSign());
|
SG_LOG(SG_ATC, SG_ALERT, "Taxiway incursion for AI aircraft" << i->getAircraft()->getCallSign());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intVecIterator ivi;
|
intVecIterator ivi;
|
||||||
for (ivi = i->getIntentions().begin(); ivi != i->getIntentions().end(); ivi++) {
|
for (ivi = i->getIntentions().begin(); ivi != i->getIntentions().end(); ivi++) {
|
||||||
int segIndex = (*ivi);
|
int segIndex = (*ivi);
|
||||||
|
@ -1087,6 +1062,7 @@ bool FGGroundController::updateActiveTraffic(TrafficVectorIterator i,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//after this, ivi points just behind the last valid unblocked taxi segment.
|
//after this, ivi points just behind the last valid unblocked taxi segment.
|
||||||
for (intVecIterator j = i->getIntentions().begin(); j != ivi; j++) {
|
for (intVecIterator j = i->getIntentions().begin(); j != ivi; j++) {
|
||||||
int pos = (*j);
|
int pos = (*j);
|
||||||
|
|
|
@ -20,9 +20,7 @@
|
||||||
//
|
//
|
||||||
// $Id$
|
// $Id$
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include <config.h>
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -66,6 +64,12 @@ void clearTrafficControllers(TrafficVector& vec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrafficVectorIterator searchActiveTraffic(TrafficVector& vec, int id)
|
||||||
|
{
|
||||||
|
return std::find_if(vec.begin(), vec.end(), [id] (const FGTrafficRecord& rec)
|
||||||
|
{ return rec.getId() == id; });
|
||||||
|
}
|
||||||
|
|
||||||
} // of anonymous namespace
|
} // of anonymous namespace
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
|
@ -245,14 +249,13 @@ FGTrafficRecord::~FGTrafficRecord()
|
||||||
void FGTrafficRecord::setPositionAndIntentions(int pos,
|
void FGTrafficRecord::setPositionAndIntentions(int pos,
|
||||||
FGAIFlightPlan * route)
|
FGAIFlightPlan * route)
|
||||||
{
|
{
|
||||||
|
|
||||||
SG_LOG(SG_ATC, SG_DEBUG, "Position: " << pos);
|
SG_LOG(SG_ATC, SG_DEBUG, "Position: " << pos);
|
||||||
currentPos = pos;
|
currentPos = pos;
|
||||||
if (! intentions.empty()) {
|
if (!intentions.empty()) {
|
||||||
intVecIterator i = intentions.begin();
|
intVecIterator i = intentions.begin();
|
||||||
if ((*i) != currentPos) {
|
if ((*i) != currentPos) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"Error in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN);
|
"Error in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN << ", " << (*i));
|
||||||
}
|
}
|
||||||
intentions.erase(i);
|
intentions.erase(i);
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,15 +641,15 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
|
||||||
getName() + "-Tower";
|
getName() + "-Tower";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swap sender and receiver value in case of a ground to air transmission
|
// Swap sender and receiver value in case of a ground to air transmission
|
||||||
if (msgDir == ATC_GROUND_TO_AIR) {
|
if (msgDir == ATC_GROUND_TO_AIR) {
|
||||||
string tmp = sender;
|
string tmp = sender;
|
||||||
sender = receiver;
|
sender = receiver;
|
||||||
receiver = tmp;
|
receiver = tmp;
|
||||||
ground_to_air=1;
|
ground_to_air = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (msgId) {
|
switch (msgId) {
|
||||||
case MSG_ANNOUNCE_ENGINE_START:
|
case MSG_ANNOUNCE_ENGINE_START:
|
||||||
text = sender + ". Ready to Start up.";
|
text = sender + ". Ready to Start up.";
|
||||||
|
@ -800,7 +803,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
|
||||||
text = text + sender + ". Transmitting unknown Message.";
|
text = text + sender + ". Transmitting unknown Message.";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audible) {
|
if (audible) {
|
||||||
double onBoardRadioFreq0 =
|
double onBoardRadioFreq0 =
|
||||||
fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
|
fgGetDouble("/instrumentation/comm[0]/frequencies/selected-mhz");
|
||||||
|
@ -917,18 +920,10 @@ void FGTowerController::announcePosition(int id,
|
||||||
FGAIAircraft * ref)
|
FGAIAircraft * ref)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
|
||||||
// Search whether the current id alread has an entry
|
// Search activeTraffic for a record matching our id
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add a new TrafficRecord if no one exsists for this aircraft.
|
// Add a new TrafficRecord if no one exsists for this aircraft.
|
||||||
if (i == activeTraffic.end() || (activeTraffic.empty())) {
|
if (i == activeTraffic.end() || (activeTraffic.empty())) {
|
||||||
FGTrafficRecord rec;
|
FGTrafficRecord rec;
|
||||||
|
@ -970,20 +965,9 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
|
||||||
double heading, double speed, double alt,
|
double heading, double speed, double alt,
|
||||||
double dt)
|
double dt)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search whether the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
TrafficVectorIterator closest;
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setDt(getDt() + dt);
|
setDt(getDt() + dt);
|
||||||
|
|
||||||
if (i == activeTraffic.end() || (activeTraffic.empty())) {
|
if (i == activeTraffic.end() || (activeTraffic.empty())) {
|
||||||
|
@ -1060,18 +1044,9 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
|
||||||
|
|
||||||
void FGTowerController::signOff(int id)
|
void FGTowerController::signOff(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id alread has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If this aircraft has left the runway, we can clear the departure record for this runway
|
// If this aircraft has left the runway, we can clear the departure record for this runway
|
||||||
ActiveRunwayVecIterator rwy = activeRunways.begin();
|
ActiveRunwayVecIterator rwy = activeRunways.begin();
|
||||||
if (! activeRunways.empty()) {
|
if (! activeRunways.empty()) {
|
||||||
|
@ -1108,18 +1083,9 @@ void FGTowerController::signOff(int id)
|
||||||
// Note that this function is probably obsolete
|
// Note that this function is probably obsolete
|
||||||
bool FGTowerController::hasInstruction(int id)
|
bool FGTowerController::hasInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1132,18 +1098,9 @@ bool FGTowerController::hasInstruction(int id)
|
||||||
|
|
||||||
FGATCInstruction FGTowerController::getInstruction(int id)
|
FGATCInstruction FGTowerController::getInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1193,18 +1150,9 @@ void FGStartupController::announcePosition(int id,
|
||||||
FGAIAircraft * ref)
|
FGAIAircraft * ref)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search whether the current id alread has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add a new TrafficRecord if no one exsists for this aircraft.
|
// Add a new TrafficRecord if no one exsists for this aircraft.
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
FGTrafficRecord rec;
|
FGTrafficRecord rec;
|
||||||
|
@ -1233,18 +1181,9 @@ void FGStartupController::announcePosition(int id,
|
||||||
// Note that this function is probably obsolete
|
// Note that this function is probably obsolete
|
||||||
bool FGStartupController::hasInstruction(int id)
|
bool FGStartupController::hasInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1257,18 +1196,9 @@ bool FGStartupController::hasInstruction(int id)
|
||||||
|
|
||||||
FGATCInstruction FGStartupController::getInstruction(int id)
|
FGATCInstruction FGStartupController::getInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1280,18 +1210,9 @@ FGATCInstruction FGStartupController::getInstruction(int id)
|
||||||
|
|
||||||
void FGStartupController::signOff(int id)
|
void FGStartupController::signOff(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id alread has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
|
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
|
||||||
|
@ -1338,21 +1259,10 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
|
||||||
double heading, double speed, double alt,
|
double heading, double speed, double alt,
|
||||||
double dt)
|
double dt)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
TrafficVectorIterator current, closest;
|
||||||
TrafficVectorIterator current, closest;
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// // update position of the current aircraft
|
|
||||||
|
|
||||||
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1650,7 +1560,7 @@ FGApproachController::~FGApproachController()
|
||||||
clearTrafficControllers(activeTraffic);
|
clearTrafficControllers(activeTraffic);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
void FGApproachController::announcePosition(int id,
|
void FGApproachController::announcePosition(int id,
|
||||||
FGAIFlightPlan * intendedRoute,
|
FGAIFlightPlan * intendedRoute,
|
||||||
int currentPosition,
|
int currentPosition,
|
||||||
|
@ -1660,18 +1570,10 @@ void FGApproachController::announcePosition(int id,
|
||||||
int leg, FGAIAircraft * ref)
|
int leg, FGAIAircraft * ref)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
|
||||||
// Search whether the current id alread has an entry
|
// Search activeTraffic for a record matching our id
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add a new TrafficRecord if no one exsists for this aircraft.
|
// Add a new TrafficRecord if no one exsists for this aircraft.
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
FGTrafficRecord rec;
|
FGTrafficRecord rec;
|
||||||
|
@ -1692,20 +1594,11 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
|
||||||
double heading, double speed, double alt,
|
double heading, double speed, double alt,
|
||||||
double dt)
|
double dt)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
TrafficVectorIterator current;
|
||||||
TrafficVectorIterator current, closest;
|
|
||||||
if (! activeTraffic.empty()) {
|
// update position of the current aircraft
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// // update position of the current aircraft
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: updating aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1740,20 +1633,12 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
|
||||||
setDt(getDt() + dt);
|
setDt(getDt() + dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Search for and erase traffic record with a specific id */
|
||||||
void FGApproachController::signOff(int id)
|
void FGApproachController::signOff(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id alread has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN);
|
"AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN);
|
||||||
|
@ -1762,6 +1647,7 @@ void FGApproachController::signOff(int id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Periodically check for and remove dead traffic records */
|
||||||
void FGApproachController::update(double dt)
|
void FGApproachController::update(double dt)
|
||||||
{
|
{
|
||||||
eraseDeadTraffic(activeTraffic);
|
eraseDeadTraffic(activeTraffic);
|
||||||
|
@ -1769,18 +1655,9 @@ void FGApproachController::update(double dt)
|
||||||
|
|
||||||
bool FGApproachController::hasInstruction(int id)
|
bool FGApproachController::hasInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (! activeTraffic.empty()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
if (i == activeTraffic.end() || activeTraffic.empty()) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
@ -1793,18 +1670,9 @@ bool FGApproachController::hasInstruction(int id)
|
||||||
|
|
||||||
FGATCInstruction FGApproachController::getInstruction(int id)
|
FGATCInstruction FGApproachController::getInstruction(int id)
|
||||||
{
|
{
|
||||||
TrafficVectorIterator i = activeTraffic.begin();
|
// Search activeTraffic for a record matching our id
|
||||||
// Search search if the current id has an entry
|
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
|
||||||
// This might be faster using a map instead of a vector, but let's start by taking a safe route
|
|
||||||
if (activeTraffic.size()) {
|
|
||||||
//while ((i->getId() != id) && i != activeTraffic.end()) {
|
|
||||||
while (i != activeTraffic.end()) {
|
|
||||||
if (i->getId() == id) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
|
||||||
SG_LOG(SG_ATC, SG_ALERT,
|
SG_LOG(SG_ATC, SG_ALERT,
|
||||||
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
|
||||||
|
|
|
@ -179,16 +179,16 @@ public:
|
||||||
void setLeg(int lg) {
|
void setLeg(int lg) {
|
||||||
leg = lg;
|
leg = lg;
|
||||||
};
|
};
|
||||||
int getId() {
|
int getId() const {
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
int getState() {
|
int getState() const {
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
void setState(int s) {
|
void setState(int s) {
|
||||||
state = s;
|
state = s;
|
||||||
}
|
}
|
||||||
FGATCInstruction getInstruction() {
|
FGATCInstruction getInstruction() const {
|
||||||
return instruction;
|
return instruction;
|
||||||
};
|
};
|
||||||
bool hasInstruction() {
|
bool hasInstruction() {
|
||||||
|
|
|
@ -249,6 +249,7 @@ FGAirport *FGScheduledFlight::getDepartureAirport()
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAirport * FGScheduledFlight::getArrivalAirport ()
|
FGAirport * FGScheduledFlight::getArrivalAirport ()
|
||||||
{
|
{
|
||||||
if (!(initialized))
|
if (!(initialized))
|
||||||
|
|
Loading…
Reference in a new issue