]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/dynamics.cxx
Some additional changes to ensure that FlightGear at least compiles after configuring...
[flightgear.git] / src / Airports / dynamics.cxx
index 78927c820af39514de5017eae4a169ce4c6bc9f6..3e658a1473aa5effe73f158c7fe181d1e2c797b0 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <simgear/compiler.h>
 
-#include <plib/sg.h>
 #include <plib/ul.h>
 
 #include <Environment/environment_mgr.hxx>
@@ -52,18 +51,17 @@ using std::random_shuffle;
 #include "dynamics.hxx"
 
 FGAirportDynamics::FGAirportDynamics(FGAirport* ap) :
-  _ap(ap), rwyPrefs(ap) {
+  _ap(ap), rwyPrefs(ap), SIDs(ap) {
   lastUpdate = 0;
-  for (int i = 0; i < 10; i++)
-     {
-       //avWindHeading [i] = 0;
-       //avWindSpeed   [i] = 0;
-     }
+
+  // For testing only. This needs to be refined when we move ATIS functionality over.
+  atisInformation = "Sierra";
 }
 
 // Note that the ground network should also be copied
 FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) :
-  rwyPrefs(other.rwyPrefs)
+  rwyPrefs(other.rwyPrefs),
+  SIDs(other.SIDs)
 {
   for (FGParkingVecConstIterator ip= other.parkings.begin(); ip != other.parkings.end(); ip++)
     parkings.push_back(*(ip));
@@ -76,11 +74,7 @@ FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) :
   for (il = other.takeoff.begin(); il != other.takeoff.end(); il++)
     takeoff.push_back(*il);
   lastUpdate = other.lastUpdate;
-  for (int i = 0; i < 10; i++)
-    {
-      //avWindHeading [i] = other.avWindHeading[i];
-      //avWindSpeed   [i] = other.avWindSpeed  [i];
-    }
+  atisInformation = other.atisInformation; 
 }
 
 // Destructor
@@ -349,7 +343,7 @@ void FGAirportDynamics::setRwyUse(const FGRunwayPreference& ref)
   //exit(1);
 }
 
-bool FGAirportDynamics::innerGetActiveRunway(const string &trafficType, int action, string &runway)
+bool FGAirportDynamics::innerGetActiveRunway(const string &trafficType, int action, string &runway, double heading)
 {
 double windSpeed;
   double windHeading;
@@ -458,7 +452,7 @@ double windSpeed;
              // Note that the randomization below, is just a placeholder to choose between
              // multiple active runways for this action. This should be
              // under ATC control.
-             runway = takeoff[(rand() %  nr)];
+             runway = chooseRwyByHeading (takeoff, heading);
            }
          else
            { // Fallback
@@ -471,7 +465,7 @@ double windSpeed;
          int nr = landing.size();
          if (nr)
            {
-             runway = landing[(rand() % nr)];
+             runway = chooseRwyByHeading (landing, heading);
            }
          else
            {  //fallback
@@ -482,9 +476,28 @@ double windSpeed;
   return true;
 }
 
-void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, string &runway)
+string FGAirportDynamics::chooseRwyByHeading(stringVec rwys, double heading) {
+   double bestError = 360.0;
+   double rwyHeading, headingError;
+   string runway;
+   for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) {
+       FGRunway *rwy = _ap->getRunwayByIdent((*i));
+       rwyHeading = rwy->headingDeg();
+       headingError = fabs(heading - rwyHeading);
+        if (headingError > 180)
+            headingError = fabs(headingError - 360);
+        if (headingError < bestError) {
+            runway = (*i);
+            bestError = headingError;
+        }
+   }
+   //cerr << "Using active runway " << runway << " for heading " << heading << endl;
+   return runway;
+}
+
+void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, string &runway, double heading)
 {
-  bool ok = innerGetActiveRunway(trafficType, action, runway);
+  bool ok = innerGetActiveRunway(trafficType, action, runway, heading);
   if (!ok) {
     runway = chooseRunwayFallback();
   }
@@ -515,3 +528,36 @@ double FGAirportDynamics::getElevation() const {
 const string& FGAirportDynamics::getId() const {
   return _ap->getId();
 }
+
+// Experimental: Return a different ground frequency depending on the leg of the
+// Flight. Leg should always have a minimum value of two when this function is called. 
+// Note that in this scheme, the assignment of various frequencies to various ground 
+// operations is completely arbitrary. As such, is a short cut I need to take now,
+// so that at least I can start working on assigning different frequencies to different
+// operations.
+
+int FGAirportDynamics::getGroundFrequency(unsigned leg) { 
+     //return freqGround.size() ? freqGround[0] : 0; };
+     int groundFreq = 0;
+     if (leg < 2) {
+         SG_LOG(SG_ATC, SG_ALERT, "Leg value is smaller than two at " << SG_ORIGIN);
+     }
+     if (freqGround.size() == 0) {
+         return 0;
+     }
+     if ((freqGround.size() > leg-1) && (leg > 1)) {
+          groundFreq =  freqGround[leg-1];
+     }
+     if ((freqGround.size() < leg-1) && (leg > 1)) {
+          groundFreq = (freqGround.size() < (leg-1)) ? freqGround[freqGround.size()-1] : freqGround[leg-2];
+     }
+     if ((freqGround.size() >= leg-1) && (leg > 1)) {
+          groundFreq = freqGround[leg-2];
+     }
+    return groundFreq;
+}
+
+FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway, double heading)
+{
+   return SIDs.getBest(activeRunway, heading);
+}