]> git.mxchange.org Git - flightgear.git/commitdiff
Assigned an ATC controller to the user's Aircraft and change the comm1 radio frequenc...
authorDurk Talsma <durk@localhost.(none)>
Sun, 10 Apr 2011 06:58:48 +0000 (08:58 +0200)
committerDurk Talsma <durk@localhost.(none)>
Sun, 10 Apr 2011 06:58:48 +0000 (08:58 +0200)
src/ATC/atc_mgr.cxx
src/ATC/atc_mgr.hxx
src/ATC/atcdialog.cxx
src/ATC/trafficcontrol.cxx
src/ATC/trafficcontrol.hxx
src/Airports/dynamics.cxx
src/Airports/dynamics.hxx
src/Airports/groundnetwork.cxx

index ba71c608735255e169b91bee156eeb82283f28f9..d1a182f186ef825c68c4e8e3b0bebaa7460b0aae 100644 (file)
@@ -27,6 +27,9 @@
 #include <iostream>
 
 #include <simgear/math/SGMath.hxx>
+#include <Airports/dynamics.hxx>
+#include <Airports/simple.hxx>
+
 #include "atc_mgr.hxx"
 
 
@@ -43,6 +46,37 @@ void FGATCManager::init() {
     currentATCDialog = new FGATCDialogNew;
     currentATCDialog->init();
 
+    // find a reasonable controller for our user's aircraft..
+    // Let's start by working out the following three scenarios: 
+    // Starting on ground at a parking position
+    // Starting on ground at the runway.
+    // Starting in the Air
+    bool onGround  = fgGetBool("/sim/presets/onground");
+    string runway  = fgGetString("/sim/atc/runway");
+    string airport = fgGetString("/sim/presets/airport-id");
+    string parking = fgGetString("/sim/presets/parkpos");
+
+    FGAirport *apt = FGAirport::findByIdent(airport); 
+    cerr << "found information: " << runway << " " << airport << ": parking = " << parking << endl;
+     if (onGround) {
+        if (parking.empty()) {
+            controller = apt->getDynamics()->getTowerController();
+            int stationFreq = apt->getDynamics()->getTowerFrequency(2);
+            cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
+            fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
+
+        } else {
+            controller = apt->getDynamics()->getGroundNetwork();
+            int stationFreq = apt->getDynamics()->getGroundFrequency(2);
+            cerr << "Setting radio frequency to : " << stationFreq << endl;
+            fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
+
+        }
+     } else {
+        controller = 0;
+     }
+    //controller = 
+
     //dialog.init();
 }
 
@@ -52,4 +86,5 @@ void FGATCManager::addController(FGATCController *controller) {
 
 void FGATCManager::update ( double time ) {
     //cerr << "ATC update code is running at time: " << time << endl;
+   currentATCDialog->update(time);
 }
index c34c82446f03eb235a4d50d9c7c997d15199b703..5aab9b64cc3cfba00c1e498c7ad5feee6186cfe3 100644 (file)
@@ -46,6 +46,7 @@ class FGATCManager : public SGSubsystem
 {
 private:
   AtcVec activeStations;
+  FGATCController *controller; // The ATC controller that is responsible for the user's aircraft. 
   //FGATCDialogNew dialog;  // note that this variable should really replace the ugly global "currentATCDialog();
 
 public:
index 9c33b04aa2cb7f13350b0d2fdd7d2deb3e97f2b5..3ab9e28d7f2fd77df5380ce759193fb97aa30e04 100644 (file)
@@ -132,3 +132,13 @@ void FGATCDialogNew::PopupDialog() {
     dialogVisible = !dialogVisible;
     return;
 }
+
+void FGATCDialogNew::update(double dt) {
+    static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
+    int n = trans_num->getIntValue();
+    if (n >= 0) {
+        trans_num->setIntValue(-1);
+           // PopupCallback(n);
+        cerr << "Selected transmission message" << n << endl;
+    }
+}
\ No newline at end of file
index 664929bfc764da04b97d296409f599e38637c19f..b4bfb7efd94723b01b885a4f4ae86f701eba3f91 100644 (file)
@@ -452,8 +452,7 @@ FGATCController::FGATCController()
     dt_count = 0;
     available = true;
     lastTransmission = 0;
-    FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
-    mgr->addController(this);
+    initialized = false;
 }
 
 FGATCController::~FGATCController()
@@ -672,6 +671,15 @@ string FGATCController::genTransponderCode(string fltRules)
     }
 }
 
+void FGATCController::init() 
+{
+   if (!initialized) {
+       FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
+       mgr->addController(this);
+       initialized = true;
+    }
+}
+
 /***************************************************************************
  * class FGTowerController
  *
@@ -690,6 +698,7 @@ void FGTowerController::announcePosition(int id,
                                          double radius, int leg,
                                          FGAIAircraft * ref)
 {
+    init();
     TrafficVectorIterator i = activeTraffic.begin();
     // Search whether the current id alread has an entry
     // This might be faster using a map instead of a vector, but let's start by taking a safe route
@@ -882,6 +891,7 @@ void FGStartupController::announcePosition(int id,
                                            double radius, int leg,
                                            FGAIAircraft * ref)
 {
+    init();
     TrafficVectorIterator i = activeTraffic.begin();
     // Search whether the current id alread has an entry
     // This might be faster using a map instead of a vector, but let's start by taking a safe route
@@ -1141,6 +1151,7 @@ void FGApproachController::announcePosition(int id,
                                             double alt, double radius,
                                             int leg, FGAIAircraft * ref)
 {
+    init();
     TrafficVectorIterator i = activeTraffic.begin();
     // Search whether the current id alread has an entry
     // This might be faster using a map instead of a vector, but let's start by taking a safe route
index 2550f7cb6adbee7d53820a2a0a6ed76a03197241..20ec9962ebbb89e825b9ac4cff0007e0a32841ae 100644 (file)
@@ -225,6 +225,8 @@ typedef vector<ActiveRunway>::iterator ActiveRunwayVecIterator;
  *************************************************************************************/
 class FGATCController
 {
+private:
+     bool initialized;
 protected:
   bool available;
   time_t lastTransmission;
@@ -260,6 +262,8 @@ public:
       ATC_GROUND_TO_AIR } AtcMsgDir;
   FGATCController();
   virtual ~FGATCController();
+  void init();
+
   virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
                                 double lat, double lon,
                                 double hdg, double spd, double alt, double radius, int leg,
index 11cb454b97c5f8bdf851e6aa3ac81308d78b78d7..d608043b478bee48b05c9e6c6dc56b8f2e33f056 100644 (file)
@@ -535,6 +535,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)
 {
index 60921821863438f422f2ad51e4c32d441d9dede3..ecadb9d62205b91fcfc8f538fe1c37a3a5703d85 100644 (file)
@@ -119,8 +119,8 @@ public:
   FGApproachController   *getApproachController()   { return &approachController; };
 
   const string& getAtisInformation() { return atisInformation; };
-  int getGroundFrequency(unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
-
+  int getGroundFrequency (unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
+  int getTowerFrequency  (unsigned nr);
   void setRwyUse(const FGRunwayPreference& ref);
 };
 
index 3ba65015859e7a13d1d02197797223b9162c4c90..0470e4af92ef9a28663887cd57e42fc90d404924 100644 (file)
@@ -460,6 +460,7 @@ void FGGroundNetwork::announcePosition(int id,
                                        double radius, int leg,
                                        FGAIAircraft * aircraft)
 {
+    init();
     TrafficVectorIterator i = activeTraffic.begin();
     // Search search if the current id alread has an entry
     // This might be faster using a map instead of a vector, but let's start by taking a safe route