- FGRunway* rwy;
- int activeRwys = rwyList.size(); // get the number of runways active
- int nrOfPreferences;
- // bool found = true;
- // double heading;
- double hdgDiff;
- double crossWind;
- double tailWind;
- string name;
- //stringVec names;
- int bestMatch = 0, bestChoice = 0;
-
- if (activeRwys > 0)
- {
- // Now downward iterate across all the possible preferences
- // starting by the least preferred choice working toward the most preferred choice
-
- nrOfPreferences = rwyList[0].getRwyList()->size();
- bool validSelection = true;
- bool foundValidSelection = false;
- for (int i = nrOfPreferences-1; i >= 0; i--)
- {
- int match = 0;
-
-
- // Test each runway listed in the preference to see if it's possible to use
- // If one runway of the selection isn't allowed, we need to exclude this
- // preference, however, we don't want to stop right there, because we also
- // don't want to randomly swap runway preferences, unless there is a need to.
- //
- validSelection = true;
- for (int j = 0; j < activeRwys; j++)
- {
- string ident(rwyList[j].getRwyList(i));
- if (!airport->hasRunwayWithIdent(ident)) {
- SG_LOG(SG_GENERAL, SG_WARN, "no such runway:" << ident << " at " << airport->ident());
- continue;
- }
-
- rwy = airport->getRunwayByIdent(ident);
-
- //cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy->headingDeg());
- //cerr << "Wind Heading: " << windHeading << "Runway Heading: " <<rwy._heading << endl;
- //cerr << "Wind Speed : " << windSpeed << endl;
- if (hdgDiff > 180)
- hdgDiff = 360 - hdgDiff;
- //cerr << "Heading diff: " << hdgDiff << endl;
- hdgDiff *= ((2*M_PI)/360.0); // convert to radians
- crossWind = windSpeed * sin(hdgDiff);
- tailWind = -windSpeed * cos(hdgDiff);
- //cerr << ". Tailwind : " << tailWind;
- //cerr << ". Crosswnd : " << crossWind;
- if ((tailWind > maxTail) || (crossWind > maxCross))
- {
- //cerr << ". [Invalid] " << endl;
- validSelection = false;
- }
- else
- {
- //cerr << ". [Valid] ";
- }
- //cerr << endl;
- } // of active runways iteration
-
- if (validSelection)
- {
- //cerr << "Valid selection : " << i << endl;;
- foundValidSelection = true;
- for (stringVecIterator it = currentlyActive->begin();
- it != currentlyActive->end(); it++)
- {
- if ((*it) == name)
- match++;
- }
- if (match >= bestMatch) {
- bestMatch = match;
- bestChoice = i;
- }
- }
- //cerr << "Preference " << i << " bestMatch " << bestMatch << " choice " << bestChoice << endl;
- }
- if (foundValidSelection)
- {
- //cerr << "Valid runay selection : " << bestChoice << endl;
- nrActive = activeRwys;
- active = bestChoice;
- return;
- }
- // If this didn't work, due to heavy winds, try again
- // but select only one landing and one takeoff runway.
- choice[0] = 0;
- choice[1] = 0;
- for (int i = activeRwys-1; i; i--)
- {
- if (rwyList[i].getType() == string("landing"))
- choice[0] = i;
- if (rwyList[i].getType() == string("takeoff"))
- choice[1] = i;
- }
- //cerr << "Choosing " << choice[0] << " for landing and " << choice[1] << "for takeoff" << endl;
- nrOfPreferences = rwyList[0].getRwyList()->size();
- for (int i = 0; i < nrOfPreferences; i++)
- {
- bool validSelection = true;
- for (int j = 0; j < 2; j++)
- {
- name = rwyList[choice[j]].getRwyList(i);
- rwy = airport->getRunwayByIdent(name);
-
- //cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy->headingDeg());
- if (hdgDiff > 180)
- hdgDiff = 360 - hdgDiff;
- hdgDiff *= ((2*M_PI)/360.0); // convert to radians
- crossWind = windSpeed * sin(hdgDiff);
- tailWind = -windSpeed * cos(hdgDiff);
- if ((tailWind > maxTail) || (crossWind > maxCross))
- validSelection = false;
-
-
- }
- if (validSelection)
- {
- //cerr << "Valid runay selection : " << i << endl;
- active = i;
- nrActive = 2;
- return;
- }
- }
+ FGRunway *rwy;
+ int activeRwys = rwyList.size(); // get the number of runways active
+ int nrOfPreferences;
+ // bool found = true;
+ // double heading;
+ double hdgDiff;
+ double crossWind;
+ double tailWind;
+ string name;
+ //stringVec names;
+ int bestMatch = 0, bestChoice = 0;
+
+ if (activeRwys > 0) {
+ // Now downward iterate across all the possible preferences
+ // starting by the least preferred choice working toward the most preferred choice
+
+ nrOfPreferences = rwyList[0].getRwyList()->size();
+ bool validSelection = true;
+ bool foundValidSelection = false;
+ for (int i = nrOfPreferences - 1; i >= 0; i--) {
+ int match = 0;
+
+
+ // Test each runway listed in the preference to see if it's possible to use
+ // If one runway of the selection isn't allowed, we need to exclude this
+ // preference, however, we don't want to stop right there, because we also
+ // don't want to randomly swap runway preferences, unless there is a need to.
+ //
+ validSelection = true;
+
+ for (int j = 0; j < activeRwys; j++) {
+ string ident(rwyList[j].getRwyList(i));
+ if (!airport->hasRunwayWithIdent(ident)) {
+ SG_LOG(SG_GENERAL, SG_WARN,
+ "no such runway:" << ident << " at " <<
+ airport->ident());
+ continue;
+ }
+
+ rwy = airport->getRunwayByIdent(ident);
+
+ //cerr << "Succes" << endl;
+ hdgDiff = fabs(windHeading - rwy->headingDeg());
+ name = rwy->name();
+
+
+ if (hdgDiff > 180)
+ hdgDiff = 360 - hdgDiff;
+ //cerr << "Heading diff: " << hdgDiff << endl;
+ hdgDiff *= ((2 * M_PI) / 360.0); // convert to radians
+ crossWind = windSpeed * sin(hdgDiff);
+ tailWind = -windSpeed * cos(hdgDiff);
+ //cerr << "Runway : " << rwy->name() << ": " << rwy->headingDeg() << endl;
+ //cerr << ". Tailwind : " << tailWind;
+ //cerr << ". Crosswnd : " << crossWind;
+ if ((tailWind > maxTail) || (crossWind > maxCross)) {
+ //cerr << ". [Invalid] " << endl;
+ validSelection = false;
+ } else {
+ //cerr << ". [Valid] ";
+ }
+ //cerr << endl;
+ for (stringVecIterator it = currentlyActive->begin();
+ it != currentlyActive->end(); it++) {
+ //cerr << "Checking : \"" << (*it) << "\". vs \"" << name << "\"" << endl;
+ if ((*it) == name) {
+ match++;
+ }
+ }
+ } // of active runways iteration
+
+ if (validSelection) {
+ //cerr << "Valid selection : " << i << endl;;
+ foundValidSelection = true;
+ if (match >= bestMatch) {
+ bestMatch = match;
+ bestChoice = i;
+ }
+ }
+ //cerr << "Preference " << i << "Match " << match << " bestMatch " << bestMatch << " choice " << bestChoice << " valid selection " << validSelection << endl;
+ }
+ if (foundValidSelection) {
+ //cerr << "Valid runay selection : " << bestChoice << endl;
+ nrActive = activeRwys;
+ active = bestChoice;
+ return;
+ }
+ // If this didn't work, due to heavy winds, try again
+ // but select only one landing and one takeoff runway.
+ choice[0] = 0;
+ choice[1] = 0;
+ for (int i = activeRwys - 1; i; i--) {
+ if (rwyList[i].getType() == string("landing"))
+ choice[0] = i;
+ if (rwyList[i].getType() == string("takeoff"))
+ choice[1] = i;
+ }
+ //cerr << "Choosing " << choice[0] << " for landing and " << choice[1] << "for takeoff" << endl;
+ nrOfPreferences = rwyList[0].getRwyList()->size();
+ for (int i = 0; i < nrOfPreferences; i++) {
+ bool validSelection = true;
+ for (int j = 0; j < 2; j++) {
+ name = rwyList[choice[j]].getRwyList(i);
+ rwy = airport->getRunwayByIdent(name);
+
+ //cerr << "Succes" << endl;
+ hdgDiff = fabs(windHeading - rwy->headingDeg());
+ if (hdgDiff > 180)
+ hdgDiff = 360 - hdgDiff;
+ hdgDiff *= ((2 * M_PI) / 360.0); // convert to radians
+ crossWind = windSpeed * sin(hdgDiff);
+ tailWind = -windSpeed * cos(hdgDiff);
+ if ((tailWind > maxTail) || (crossWind > maxCross))
+ validSelection = false;
+
+
+ }
+ if (validSelection) {
+ //cerr << "Valid runay selection : " << i << endl;
+ active = i;
+ nrActive = 2;
+ return;
+ }
+ }