]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/approach.cxx
Make sure the ATIS reports surface winds at airports above sea-level
[flightgear.git] / src / ATC / approach.cxx
index ca346bfb815b7d7fde7dd4e33274ac8441c6c0fe..a08f571b5112493bf45a033863d2478a512e5499 100644 (file)
 #include "ATCDialog.hxx"
 
 #include <Airports/runways.hxx>
+#include <simgear/math/polar3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 
-#ifdef FG_WEATHERCM
-# include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-# include <Environment/environment_mgr.hxx>
-# include <Environment/environment.hxx>
-#endif
+#include <Environment/environment_mgr.hxx>
+#include <Environment/environment.hxx>
 
 
 #include <GUI/gui.h>
 
 //Constructor
 FGApproach::FGApproach(){
-  comm1_node = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
-  comm2_node = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
+  comm1_node = fgGetNode("/instrumentation/comm[0]/frequencies/selected-mhz", true);
+  comm2_node = fgGetNode("/instrumentation/comm[1]/frequencies/selected-mhz", true);
+  
+  _type = APPROACH;
 
   num_planes = 0;
   lon_node   = fgGetNode("/position/longitude-deg", true);
@@ -74,7 +73,6 @@ FGApproach::~FGApproach(){
 }
 
 void FGApproach::Init() {
-  display = false;
 }
 
 
@@ -87,7 +85,7 @@ void FGApproach::Update(double dt) {
        const int max_trans = 20;
        FGTransmission tmissions[max_trans];
        int    wpn;
-       int    station = 1;
+       atc_type station = APPROACH;
        TransCode code;
        TransPar TPar;
        int    i,j;
@@ -111,7 +109,7 @@ void FGApproach::Update(double dt) {
        
        for (i=0; i<num_planes; i++) {
                if ( planes[i].ident == "Player") { 
-                       station = 1;
+                       station = APPROACH;
                        tpars.station = name;
                        tpars.callsign = "Player";
                        tpars.airport = ident;
@@ -133,8 +131,8 @@ void FGApproach::Update(double dt) {
                                                    mentry = current_transmissionlist->gen_text(station, code, tpars, false);
                                                    transm = current_transmissionlist->gen_text(station, code, tpars, true);
                                                    // is the transmission already registered?
-                                                   if (!current_atcdialog->trans_reg( ident, transm )) {
-                                                           current_atcdialog->add_entry( ident, transm, mentry );
+                                                   if (!current_atcdialog->trans_reg( ident, transm, APPROACH )) {
+                                                           current_atcdialog->add_entry( ident, transm, mentry, APPROACH, 0 );
                                                    }
                                            }
                                        }
@@ -233,7 +231,7 @@ void FGApproach::Update(double dt) {
                                        tpars.alt = planes[i].aalt;
                                        message = current_transmissionlist->gen_text(station, code, tpars, true );
                                        //cout << "Approach transmitting...\n";
-                                       //cout << message << '\n';
+                                       //cout << message << endl;
                                        globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
                                        
                                }
@@ -244,7 +242,7 @@ void FGApproach::Update(double dt) {
                                        tpars.runway = active_runway;
                                        message = current_transmissionlist->gen_text(station, code, tpars, true);
                                        //cout << "Approach transmitting 2 ...\n";
-                                       //cout << message << '\n';
+                                       //cout << message << endl;
                                        globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
                                }
                                planes[i].lmc = code;
@@ -553,45 +551,19 @@ double FGApproach::round_alt( const bool hl, double alt ) {
 void FGApproach::get_active_runway() {
        //cout << "Entering FGApproach::get_active_runway()\n";
 
-#ifdef FG_WEATHERCM
-  sgVec3 position = { lat, lon, elev };
-  FGPhysicalProperty stationweather = WeatherDatabase->get(position);
-#else
   FGEnvironment stationweather =
       ((FGEnvironmentMgr *)globals->get_subsystem("environment"))
         ->getEnvironment(lat, lon, elev);
-#endif
 
-#ifdef FG_WEATHERCM
-  //Set the heading to into the wind
-  double wind_x = stationweather.Wind[0];
-  double wind_y = stationweather.Wind[1];
-  
-  double speed = sqrt( wind_x*wind_x + wind_y*wind_y ) * SG_METER_TO_NM / (60.0*60.0);
-  double hdg;
-  
-  //If no wind use 270degrees
-  if(speed == 0) {
-    hdg = 270;
-  } else {
-    // //normalize the wind to get the direction
-    //wind_x /= speed; wind_y /= speed;
-    
-    hdg = - atan2 ( wind_x, wind_y ) * SG_RADIANS_TO_DEGREES ;
-    if (hdg < 0.0)
-      hdg += 360.0;
-  }
-#else
   double hdg = stationweather.get_wind_from_heading_deg();
-#endif
   
   FGRunway runway;
   if ( globals->get_runways()->search( ident, int(hdg), &runway) ) {
-    active_runway = runway.rwy_no;
-    active_rw_hdg = runway.heading;
-    active_rw_lon = runway.lon;
-    active_rw_lat = runway.lat;
-    active_rw_len = runway.length;
+    active_runway = runway._rwy_no;
+    active_rw_hdg = runway._heading;
+    active_rw_lon = runway._lon;
+    active_rw_lat = runway._lat;
+    active_rw_len = runway._length;
     //cout << "Active runway is: " << active_runway << "  heading = " 
     // << active_rw_hdg 
     // << " lon = " << active_rw_lon