]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/dynamics.cxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / Airports / dynamics.cxx
index a323d809c97e4d5abd7b4d63c40db02da914c9fe..398920f329e99cb0ec04fc31256ae1bc375a8f1a 100644 (file)
@@ -26,8 +26,6 @@
 
 #include <simgear/compiler.h>
 
-#include <plib/ul.h>
-
 #include <Environment/environment_mgr.hxx>
 #include <Environment/environment.hxx>
 #include <simgear/misc/sg_path.hxx>
@@ -51,7 +49,7 @@ using std::random_shuffle;
 #include "dynamics.hxx"
 
 FGAirportDynamics::FGAirportDynamics(FGAirport * ap):
-_ap(ap), rwyPrefs(ap), SIDs(ap)
+_ap(ap), rwyPrefs(ap), SIDs(ap),startupController(this) 
 {
     lastUpdate = 0;
 
@@ -63,7 +61,7 @@ _ap(ap), rwyPrefs(ap), SIDs(ap)
 FGAirportDynamics::
 FGAirportDynamics(const FGAirportDynamics & other):rwyPrefs(other.
                                                             rwyPrefs),
-SIDs(other.SIDs)
+SIDs(other.SIDs), startupController(other.startupController)
 {
     for (FGParkingVecConstIterator ip = other.parkings.begin();
          ip != other.parkings.end(); ip++)
@@ -98,10 +96,11 @@ void FGAirportDynamics::init()
     random_shuffle(parkings.begin(), parkings.end());
     sort(parkings.begin(), parkings.end());
     // add the gate positions to the ground network. 
+    groundNetwork.setParent(_ap);
     groundNetwork.addNodes(&parkings);
     groundNetwork.init();
     groundNetwork.setTowerController(&towerController);
-    groundNetwork.setParent(_ap);
+    
 }
 
 bool FGAirportDynamics::getAvailableParking(double *lat, double *lon,
@@ -325,17 +324,21 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
         takeoff.clear();
         lastUpdate = dayStart;
         prevTrafficType = trafficType;
-
+        /*
         FGEnvironment
             stationweather =
             ((FGEnvironmentMgr *) globals->get_subsystem("environment"))
             ->getEnvironment(getLatitude(), getLongitude(),
                              getElevation());
-
-        windSpeed = stationweather.get_wind_speed_kt();
-        windHeading = stationweather.get_wind_from_heading_deg();
+        */
+        windSpeed   = fgGetInt("/environment/metar/base-wind-speed-kt"); //stationweather.get_wind_speed_kt();
+        windHeading = fgGetInt("/environment/metar/base-wind-dir-deg");
+        //stationweather.get_wind_from_heading_deg();
         string scheduleName;
-        //cerr << "finding active Runway for" << _ap->getId() << endl;
+        //cerr << "finding active Runway for : " << _ap->getId() << endl;
+        //cerr << "Wind Heading              : " << windHeading << endl;
+        //cerr << "Wind Speed                : " << windSpeed << endl;
+
         //cerr << "Nr of seconds since day start << " << dayStart << endl;
 
         ScheduleTime *currSched;
@@ -347,7 +350,7 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
         scheduleName = currSched->getName(dayStart);
         maxTail = currSched->getTailWind();
         maxCross = currSched->getCrossWind();
-        //cerr << "SChedule anme = " << scheduleName << endl;
+        //cerr << "Current Schedule =        : " << scheduleName << endl;
         if (scheduleName.empty())
             return false;
         //cerr << "C"<< endl;
@@ -371,6 +374,13 @@ bool FGAirportDynamics::innerGetActiveRunway(const string & trafficType,
             currentlyActive = &ulActive;
         }
 
+        //cerr << "Durrently active selection for " << trafficType << ": ";
+        for (stringVecIterator it = currentlyActive->begin();
+             it != currentlyActive->end(); it++) {
+             //cerr << (*it) << " ";
+         }
+         //cerr << endl;
+
         currRunwayGroup->setActive(_ap,
                                    windSpeed,
                                    windHeading,
@@ -432,6 +442,12 @@ string FGAirportDynamics::chooseRwyByHeading(stringVec rwys,
     double rwyHeading, headingError;
     string runway;
     for (stringVecIterator i = rwys.begin(); i != rwys.end(); i++) {
+        if (!_ap->hasRunwayWithIdent(*i)) {
+          SG_LOG(SG_ATC, SG_WARN, "chooseRwyByHeading: runway " << *i <<
+            " not found at " << _ap->ident());
+          continue;
+        }
+        
         FGRunway *rwy = _ap->getRunwayByIdent((*i));
         rwyHeading = rwy->headingDeg();
         headingError = fabs(heading - rwyHeading);
@@ -520,6 +536,32 @@ int FGAirportDynamics::getGroundFrequency(unsigned leg)
     return groundFreq;
 }
 
+int FGAirportDynamics::getTowerFrequency(unsigned nr)
+{
+    int towerFreq = 0;
+    if (nr < 2) {
+        SG_LOG(SG_ATC, SG_ALERT,
+               "Leg value is smaller than two at " << SG_ORIGIN);
+    }
+    if (freqTower.size() == 0) {
+        return 0;
+    }
+    if ((freqTower.size() > nr - 1) && (nr > 1)) {
+        towerFreq = freqTower[nr - 1];
+    }
+    if ((freqTower.size() < nr - 1) && (nr > 1)) {
+        towerFreq =
+            (freqTower.size() <
+             (nr - 1)) ? freqTower[freqTower.size() -
+                                     1] : freqTower[nr - 2];
+    }
+    if ((freqTower.size() >= nr - 1) && (nr > 1)) {
+        towerFreq = freqTower[nr - 2];
+    }
+    return towerFreq;
+}
+
+
 FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway,
                                           double heading)
 {