#endif
#include <math.h>
-//#include <algorithm>
#include <simgear/compiler.h>
-//#include <plib/sg.h>
-//#include <plib/ul.h>
-
-//#include <Environment/environment_mgr.hxx>
-//#include <Environment/environment.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 <Airports/runways.hxx>
#include "runwayprefs.hxx"
return *this;
}
-void RunwayGroup::setActive(const string &aptId,
+void RunwayGroup::setActive(const FGAirport* airport,
double windSpeed,
double windHeading,
double maxTail,
stringVec *currentlyActive)
{
- FGRunway rwy;
+ FGRunway* rwy;
int activeRwys = rwyList.size(); // get the number of runways active
int nrOfPreferences;
// bool found = true;
//
validSelection = true;
for (int j = 0; j < activeRwys; j++)
- {
-
- name = rwyList[j].getRwyList(i);
- //cerr << "Name of Runway: " << name;
- if (globals->get_runways()->search( aptId,
- name,
- &rwy))
- {
- //cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy._heading);
+ {
+ 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)
{
//cerr << ". [Valid] ";
}
- }else {
- SG_LOG( SG_GENERAL, SG_INFO, "Failed to find runway " << name << " at " << aptId );
- exit(1);
- }
- //cerr << endl;
- }
+ //cerr << endl;
+ } // of active runways iteration
+
if (validSelection)
{
//cerr << "Valid selection : " << i << endl;;
bool validSelection = true;
for (int j = 0; j < 2; j++)
{
- //cerr << "I J " << i << " " << j << endl;
- name = rwyList[choice[j]].getRwyList(i);
- //cerr << "Name of Runway: " << name << endl;
- if (globals->get_runways()->search( aptId,
- name,
- &rwy))
- {
+ name = rwyList[choice[j]].getRwyList(i);
+ rwy = airport->getRunwayByIdent(name);
+
//cerr << "Succes" << endl;
- hdgDiff = fabs(windHeading - rwy._heading);
+ hdgDiff = fabs(windHeading - rwy->headingDeg());
if (hdgDiff > 180)
hdgDiff = 360 - hdgDiff;
hdgDiff *= ((2*M_PI)/360.0); // convert to radians
tailWind = -windSpeed * cos(hdgDiff);
if ((tailWind > maxTail) || (crossWind > maxCross))
validSelection = false;
- }else {
- SG_LOG( SG_GENERAL, SG_INFO, "Failed to find runway " << name << " at " << aptId );
- exit(1);
- }
+
}
if (validSelection)