]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/dynamics.cxx
This should apply, and everything should build cleanly, in isolation from the
[flightgear.git] / src / Airports / dynamics.cxx
index c1958fe2d18cd102321239a581633e67976c232d..868c45cea171ed7e596bdc622f5f5def44dd7fbe 100644 (file)
@@ -40,7 +40,7 @@
 #include <Main/fg_props.hxx>
 #include <Airports/runways.hxx>
 
-#include STL_STRING
+#include <string>
 #include <vector>
 
 SG_USING_STD(string);
@@ -56,8 +56,8 @@ FGAirportDynamics::FGAirportDynamics(FGAirport* ap) :
   lastUpdate = 0;
   for (int i = 0; i < 10; i++)
      {
-       avWindHeading [i] = 0;
-       avWindSpeed   [i] = 0;
+       //avWindHeading [i] = 0;
+       //avWindSpeed   [i] = 0;
      }
 }
 
@@ -78,8 +78,8 @@ FGAirportDynamics::FGAirportDynamics(const FGAirportDynamics& other) :
   lastUpdate = other.lastUpdate;
   for (int i = 0; i < 10; i++)
     {
-      avWindHeading [i] = other.avWindHeading[i];
-      avWindSpeed   [i] = other.avWindSpeed  [i];
+      //avWindHeading [i] = other.avWindHeading[i];
+      //avWindSpeed   [i] = other.avWindSpeed  [i];
     }
 }
 
@@ -205,10 +205,10 @@ bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *he
          if (!(i->getCodes().empty()))
            {
              if ((i->getCodes().find(airline,0) == string::npos))
-         {
-           available = false;
-           continue;
-         }
+               {
+                   available = false;
+                   continue;
+               }
            }
          if (i->getType() != flType)
            {
@@ -231,7 +231,7 @@ bool FGAirportDynamics::getAvailableParking(double *lat, double *lon, double *he
              i->setAvailable(false);
              found = true;
            }
-       } 
+       }
       // And finally once more if that didn't work. Now ignore the airline codes, as a last resort
       for (i = parkings.begin(); !(i == parkings.end() || found); i++)
        {
@@ -303,18 +303,27 @@ void FGAirportDynamics::getParking (int id, double *lat, double* lon, double *he
     }
 } 
 
-FGParking *FGAirportDynamics::getParking(int i) 
+FGParking *FGAirportDynamics::getParking(int id
 { 
-  if (i < (int)parkings.size()) 
-    return &(parkings[i]); 
-  else 
+    FGParkingVecIterator i = parkings.begin();
+    for (i = parkings.begin(); i != parkings.end(); i++)
+       {
+         if (id == i->getIndex()) {
+               return &(*i);
+          }
+        }
     return 0;
 }
-string FGAirportDynamics::getParkingName(int i) 
+string FGAirportDynamics::getParkingName(int id
 { 
-  if (i < (int)parkings.size() && i >= 0) 
-    return (parkings[i].getName()); 
-  else 
+    FGParkingVecIterator i = parkings.begin();
+    for (i = parkings.begin(); i != parkings.end(); i++)
+       {
+         if (id == i->getIndex()) {
+               return i->getName();
+          }
+        }
+
     return string("overflow");
 }
 void FGAirportDynamics::releaseParking(int id)
@@ -373,57 +382,6 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
          
          windSpeed = stationweather.get_wind_speed_kt();
          windHeading = stationweather.get_wind_from_heading_deg();
-        //  double averageWindSpeed   = 0;
-//       double averageWindHeading = 0;
-//       double cosHeading         = 0;
-//       double sinHeading         = 0;
-//       // Initialize at the beginning of the next day or startup
-//       if ((lastUpdate == 0) || (dayStart < lastUpdate))
-//         {
-//           for (int i = 0; i < 10; i++)
-//             {
-//               avWindHeading [i] = windHeading;
-//               avWindSpeed   [i] = windSpeed;
-//             }
-//         }
-//       else
-//         {
-//           if (windSpeed != avWindSpeed[9]) // update if new metar data 
-//             {
-//               // shift the running average
-//               for (int i = 0; i < 9 ; i++)
-//                 {
-//                   avWindHeading[i] = avWindHeading[i+1];
-//                   avWindSpeed  [i] = avWindSpeed  [i+1];
-//                 }
-//             } 
-//           avWindHeading[9] = windHeading;
-//           avWindSpeed  [9] = windSpeed;
-//         }
-         
-//       for (int i = 0; i < 10; i++)
-//         {
-//           averageWindSpeed   += avWindSpeed   [i];
-//           //averageWindHeading += avWindHeading [i];
-//           cosHeading += cos(avWindHeading[i] * SG_DEGREES_TO_RADIANS);
-//           sinHeading += sin(avWindHeading[i] * SG_DEGREES_TO_RADIANS);
-//         }
-//       averageWindSpeed   /= 10;
-//       //averageWindHeading /= 10;
-//       cosHeading /= 10;
-//       sinHeading /= 10;
-//       averageWindHeading = atan2(sinHeading, cosHeading) *SG_RADIANS_TO_DEGREES;
-//       if (averageWindHeading < 0)
-//         averageWindHeading += 360.0;
-//       //cerr << "Wind Heading " << windHeading << " average " << averageWindHeading << endl;
-//       //cerr << "Wind Speed   " << windSpeed   << " average " << averageWindSpeed   << endl;
-//       lastUpdate = dayStart;
-//           //if (wind_speed == 0) {
-//       //  wind_heading = 270;        This forces West-facing rwys to be used in no-wind situations
-//         // which is consistent with Flightgear's initial setup.
-//       //}
-         
-         //string rwy_no = globals->get_runways()->search(apt->getId(), int(wind_heading));
          string scheduleName;
          //cerr << "finding active Runway for" << _ap->getId() << endl;
          //cerr << "Nr of seconds since day start << " << dayStart << endl;
@@ -432,7 +390,7 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
          //cerr << "A"<< endl;
          currSched = rwyPrefs.getSchedule(trafficType.c_str());
          if (!(currSched))
-           return;   
+           return;
          //cerr << "B"<< endl;
          scheduleName = currSched->getName(dayStart);
          maxTail  = currSched->getTailWind  ();
@@ -446,21 +404,34 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
          if (!(currRunwayGroup))
            return;
          nrActiveRunways = currRunwayGroup->getNrActiveRunways();
-         //cerr << "Nr of Active Runways = " << nrActiveRunways << endl; 
 
+        // Keep a history of the currently active runways, to ensure
+        // that an already established selection of runways will not
+        // be overridden once a more preferred selection becomes 
+        // available as that can lead to random runway swapping.
+       if (trafficType == "com") {
+          currentlyActive = &comActive;
+        } else if (trafficType == "gen") {
+          currentlyActive = &genActive;
+        } else if (trafficType == "mil") {
+          currentlyActive = &milActive;
+        } else if (trafficType == "ul") {
+          currentlyActive = &ulActive;
+        }
          // 
          currRunwayGroup->setActive(_ap->getId(), 
                                     windSpeed, 
                                     windHeading, 
                                     maxTail, 
                                     maxCross, 
-                                    &currentlyActive); 
+                                    currentlyActive); 
 
-         // Note that I SHOULD keep three lists in memory, one for 
+         // Note that I SHOULD keep multiple lists in memory, one for 
          // general aviation, one for commercial and one for military
          // traffic.
-         currentlyActive.clear();
+         currentlyActive->clear();
          nrActiveRunways = currRunwayGroup->getNrActiveRunways();
+          //cerr << "Choosing runway for " << trafficType << endl;
          for (int i = 0; i < nrActiveRunways; i++)
            {
              type = "unknown"; // initialize to something other than landing or takeoff
@@ -468,16 +439,17 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
              if (type == "landing")
                {
                  landing.push_back(name);
-                 currentlyActive.push_back(name);
+                 currentlyActive->push_back(name);
                  //cerr << "Landing " << name << endl; 
                }
              if (type == "takeoff")
                {
                  takeoff.push_back(name);
-                 currentlyActive.push_back(name);
+                 currentlyActive->push_back(name);
                  //cerr << "takeoff " << name << endl;
                }
            }
+          //cerr << endl;
        }
       if (action == 1) // takeoff 
        {
@@ -505,8 +477,7 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
            {  //fallback
               runway = chooseRunwayFallback();
            }
-       }
-      
+       } 
       //runway = globals->get_runways()->search(_ap->getId(), int(windHeading));
       //cerr << "Seleceted runway: " << runway << endl;
     }