1
0
Fork 0

Maintenance: GroundController

reduce variable scope.
++prefix for complex types.
eliminate variable shadowing of outer scope.
This commit is contained in:
scttgs0 2023-05-26 09:19:00 -05:00
parent 48c6afea53
commit 3b5e7ad935

View file

@ -230,7 +230,6 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
{ {
TrafficVectorIterator current, closest, closestOnNetwork; TrafficVectorIterator current, closest, closestOnNetwork;
bool otherReasonToSlowDown = false;
// bool previousInstruction; // bool previousInstruction;
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id); TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
if (!activeTraffic.size()) { if (!activeTraffic.size()) {
@ -248,50 +247,51 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
// First check all our activeTraffic // First check all our activeTraffic
if (activeTraffic.size()) { if (activeTraffic.size()) {
bool otherReasonToSlowDown = false;
double course, dist, bearing, az2; // minbearing, double course, dist, bearing, az2; // minbearing,
SGGeod curr(SGGeod::fromDegM(lon, lat, alt)); SGGeod curr(SGGeod::fromDegM(lon, lat, alt));
//TrafficVector iterator closest;
closest = current; closest = current;
closestOnNetwork = current; closestOnNetwork = current;
for (TrafficVectorIterator i = activeTraffic.begin();
i != activeTraffic.end(); i++) { for (TrafficVectorIterator iter = activeTraffic.begin();
if (i == current) { iter != activeTraffic.end(); ++iter) {
if (iter == current) {
continue; continue;
} }
SGGeod other = i->getPos(); SGGeod other = iter->getPos();
SGGeodesy::inverse(curr, other, course, az2, dist); SGGeodesy::inverse(curr, other, course, az2, dist);
bearing = fabs(heading - course); bearing = fabs(heading - course);
if (bearing > 180) if (bearing > 180)
bearing = 360 - bearing; bearing = 360 - bearing;
if ((dist < mindist) && (bearing < 60.0)) { if ((dist < mindist) && (bearing < 60.0)) {
mindist = dist; mindist = dist;
closest = i; closest = iter;
closestOnNetwork = i; closestOnNetwork = iter;
// minbearing = bearing; // minbearing = bearing;
} }
} }
// Next check with the tower controller // Next check with the tower controller
if (towerController->hasActiveTraffic()) { if (towerController->hasActiveTraffic()) {
for (TrafficVectorIterator i = for (TrafficVectorIterator iter =
towerController->getActiveTraffic().begin(); towerController->getActiveTraffic().begin();
i != towerController->getActiveTraffic().end(); i++) { iter != towerController->getActiveTraffic().end(); ++iter) {
if( current->getId() == i->getId()) { if( current->getId() == iter->getId()) {
continue; continue;
} }
SG_LOG(SG_ATC, SG_BULK, current->getCallsign() << "| Comparing with " << i->getCallsign() << " Id: " << i->getId()); SG_LOG(SG_ATC, SG_BULK, current->getCallsign() << "| Comparing with " << iter->getCallsign() << " Id: " << iter->getId());
SGGeod other = i->getPos(); SGGeod other = iter->getPos();
SGGeodesy::inverse(curr, other, course, az2, dist); SGGeodesy::inverse(curr, other, course, az2, dist);
bearing = fabs(heading - course); bearing = fabs(heading - course);
if (bearing > 180) if (bearing > 180)
bearing = 360 - bearing; bearing = 360 - bearing;
if ((dist < mindist) && (bearing < 60.0)) { if ((dist < mindist) && (bearing < 60.0)) {
//SG_LOG(SG_ATC, SG_BULK, "Current aircraft " << current->getAircraft()->getTrafficRef()->getCallSign() //SG_LOG(SG_ATC, SG_BULK, "Current aircraft " << current->getAircraft()->getTrafficRef()->getCallSign()
// << " is closest to " << i->getAircraft()->getTrafficRef()->getCallSign() // << " is closest to " << iter->getAircraft()->getTrafficRef()->getCallSign()
// << ", which has status " << i->getAircraft()->isScheduledForTakeoff()); // << ", which has status " << iter->getAircraft()->isScheduledForTakeoff());
mindist = dist; mindist = dist;
closest = i; closest = iter;
// minbearing = bearing; // minbearing = bearing;
otherReasonToSlowDown = true; otherReasonToSlowDown = true;
} }
@ -299,7 +299,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
} }
// Finally, check UserPosition // Finally, check UserPosition
// Note, as of 2011-08-01, this should no longer be necessecary. // Note, as of 2011-08-01, this should no longer be necessary.
/* /*
double userLatitude = fgGetDouble("/position/latitude-deg"); double userLatitude = fgGetDouble("/position/latitude-deg");
double userLongitude = fgGetDouble("/position/longitude-deg"); double userLongitude = fgGetDouble("/position/longitude-deg");
@ -505,8 +505,6 @@ void FGGroundController::checkHoldPosition(int id, double lat,
if (checkTransmissionState(ATCMessageState::ACK_SWITCH_GROUND_TOWER, ATCMessageState::ACK_SWITCH_GROUND_TOWER, current, now, MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY, ATC_AIR_TO_GROUND)) { if (checkTransmissionState(ATCMessageState::ACK_SWITCH_GROUND_TOWER, ATCMessageState::ACK_SWITCH_GROUND_TOWER, current, now, MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY, ATC_AIR_TO_GROUND)) {
} }
//current->setState(0); //current->setState(0);
} }
@ -559,26 +557,26 @@ bool FGGroundController::checkForCircularWaits(int id)
while ((target > 0) && (target != id) && counter++ < trafficSize) { while ((target > 0) && (target != id) && counter++ < trafficSize) {
//printed = true; //printed = true;
TrafficVectorIterator i = activeTraffic.begin(); TrafficVectorIterator iter = activeTraffic.begin();
if (trafficSize) { if (trafficSize) {
while (i != activeTraffic.end()) { while (iter != activeTraffic.end()) {
if (i->getId() == target) { if (iter->getId() == target) {
break; break;
} }
i++; ++iter;
} }
} else { } else {
return false; return false;
} }
if (i == activeTraffic.end()) { if (iter == activeTraffic.end()) {
SG_LOG(SG_ATC, SG_DEBUG, "[Waiting for traffic at Runway: DONE] "); SG_LOG(SG_ATC, SG_DEBUG, "[Waiting for traffic at Runway: DONE] ");
// The target id is not found on the current network, which means it's at the tower // The target id is not found on the current network, which means it's at the tower
SG_LOG(SG_ATC, SG_ALERT, "AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkForCircularWaits"); SG_LOG(SG_ATC, SG_ALERT, "AI error: Trying to access non-existing aircraft in FGGroundNetwork::checkForCircularWaits");
return false; return false;
} }
other = i; other = iter;
target = other->getWaitsForId(); target = other->getWaitsForId();
// actually this trap isn't as impossible as it first seemed: // actually this trap isn't as impossible as it first seemed:
@ -893,8 +891,9 @@ void FGGroundController::updateStartupTraffic(TrafficVectorIterator i,
length = seg->getLength(); length = seg->getLength();
network->blockSegmentsEndingAt(seg, i->getId(), now, now); network->blockSegmentsEndingAt(seg, i->getId(), now, now);
} }
for (intVecIterator j = i->getIntentions().begin(); j != i->getIntentions().end(); j++) { for (intVecIterator j = i->getIntentions().begin(); j != i->getIntentions().end(); j++) {
int pos = (*j); pos = (*j);
if (pos > 0) { if (pos > 0) {
FGTaxiSegment *seg = network->findSegment(pos); FGTaxiSegment *seg = network->findSegment(pos);
length += seg->getLength(); length += seg->getLength();
@ -956,7 +955,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); pos = (*j);
if (pos > 0) { if (pos > 0) {
FGTaxiSegment *seg = network->findSegment(pos); FGTaxiSegment *seg = network->findSegment(pos);
length += seg->getLength(); length += seg->getLength();