]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/approach.cxx
new FSF address
[flightgear.git] / src / ATC / approach.cxx
index cbb7ebddc5b1558f2737ada9121f57bf4efbddd4..a0c2c504d973fbbe848a67efc767153eda315663 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
 
 #include "approach.hxx"
 #include "transmission.hxx"
 #include "ATCDialog.hxx"
 
 #include <Airports/runways.hxx>
+#include <simgear/constants.h>
+#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);
@@ -48,7 +52,7 @@ FGApproach::FGApproach(){
   elev_node  = fgGetNode("/position/altitude-ft", true);
   hdg_node   = fgGetNode("/orientation/heading-deg", true);
   speed_node = fgGetNode("/velocities/airspeed-kt", true);
-  etime_node = fgGetNode("/sim/time/elapsed-ms", true);
+  etime_node = fgGetNode("/sim/time/elapsed-sec", true);
 
   first = true;
   active_runway = "";
@@ -74,7 +78,6 @@ FGApproach::~FGApproach(){
 }
 
 void FGApproach::Init() {
-  display = false;
 }
 
 
@@ -87,7 +90,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 +114,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;
@@ -125,15 +128,18 @@ void FGApproach::Update(double dt) {
                                // loop over all transmissions for station
                                for ( j=0; j<=num_trans-1; j++ ) {
                                        code = tmissions[j].get_code();
+                                       //cout << "code is " << code.c1 << "  " << code.c2 << "  " << code.c3 << '\n';
                                        // select proper transmissions
-                                       if ( ( code.c2 == -1 && planes[i].lmc.c3 == 0 ) || 
-                                               ( code.c1 == 0  && code.c2 == planes[i].lmc.c2 ) ) {
-                                               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(code.c3 != 2) {    // DCL - hack to prevent request crossing airspace being displayed since this isn't implemented yet.
+                                           if ( ( code.c2 == -1 && planes[i].lmc.c3 == 0 ) || 
+                                                   ( code.c1 == 0  && code.c2 == planes[i].lmc.c2 ) ) {
+                                                   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, APPROACH )) {
+                                                           current_atcdialog->add_entry( ident, transm, mentry, APPROACH, 0 );
+                                                   }
+                                           }
                                        }
                                }
                        }
@@ -172,8 +178,8 @@ void FGApproach::Update(double dt) {
                                else tpars.VDir = 2;
                                tpars.alt = planes[i].aalt;
                                message = current_transmissionlist->gen_text(station, code, tpars, true );
-                               cout << message << '\n';
-                               globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                               //cout << message << '\n';
+                               set_message(message);
                                planes[i].lmc = code;
                                planes[i].tlm = etime_node->getDoubleValue();
                                planes[i].on_crs = true;
@@ -230,9 +236,8 @@ 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';
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
-                                       
+                                       //cout << message << endl;
+                                       set_message(message);
                                }
                                else {
                                        code.c1 = 1;
@@ -241,8 +246,8 @@ 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';
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                                       //cout << message << endl;
+                                       set_message(message);
                                }
                                planes[i].lmc = code;
                                planes[i].tlm = etime_node->getDoubleValue();
@@ -289,7 +294,7 @@ void FGApproach::Update(double dt) {
                                        message = current_transmissionlist->gen_text(station, code, tpars, true);
                                        //cout << "Approach transmitting 3 ...\n";
                                        //cout << message << '\n';
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                                       set_message(message);
                                        planes[i].lmc = code;
                                        planes[i].tlm = etime_node->getDoubleValue();
                                }
@@ -319,7 +324,7 @@ void FGApproach::Update(double dt) {
                                        message = current_transmissionlist->gen_text(station, code, tpars, true);
                                        //cout << "Approach transmitting 4 ...\n";
                                        //cout << message << '\n';
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                                       set_message(message);
                                        planes[i].lmc = code;
                                        planes[i].tlm = etime_node->getDoubleValue();
                                        
@@ -346,7 +351,7 @@ void FGApproach::Update(double dt) {
                                message = current_transmissionlist->gen_text(station, code, tpars, true);
                                //cout << "Approach transmitting 5 ...\n";
                                //cout << message << '\n';
-                               globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                               set_message(message);
                                planes[i].lmc = code;
                                planes[i].tlm = etime_node->getDoubleValue();
                                
@@ -550,45 +555,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 
@@ -632,7 +611,7 @@ void FGApproach::update_plane_dat() {
 // =======================================================================
 // Add plane to Approach list
 // =======================================================================
-void FGApproach::AddPlane(string pid) {
+void FGApproach::AddPlane(const string& pid) {
 
   int i;
   for ( i=0; i<num_planes; i++) {
@@ -675,8 +654,8 @@ double FGApproach::calc_psl_dist(const double &h1, const double &d1,
   x3 *= sqrt(val2);
   y3 *= sqrt(val2);
   double da = fabs(atan2(y3,x3) - atan2(y1-y2,x1-x2));
-  if ( da > SGD_PI ) da -= 2*SGD_PI;
-  if ( fabs(da) > SGD_PI/2.) {
+  if ( da > SGD_PI ) da -= SGD_2PI;
+  if ( fabs(da) > SGD_PI_2) {
     //if ( x3*(x1-x2) < 0.0 && y3*(y1-y2) < 0.0) {
     x3 *= -1.0;
     y3 *= -1.0;
@@ -686,7 +665,7 @@ double FGApproach::calc_psl_dist(const double &h1, const double &d1,
   double dis2   = y1-y2-y3;
   dis = sqrt(dis);
   da = atan2(dis2,dis1);
-  if ( da < 0.0 ) da  += 2*SGD_PI;
+  if ( da < 0.0 ) da  += SGD_2PI;
   if ( da < a3 )  dis *= -1.0;
   //cout << dis1 << " " << dis2 << " " << da*SGD_RADIANS_TO_DEGREES << " " << h3
   //     << " " << sqrt(dis1*dis1 + dis2*dis2) << " " << dis << endl;
@@ -772,3 +751,11 @@ int FGApproach::RemovePlane() {
 
   return num_planes;
 }
+
+
+void FGApproach::set_message(const string &msg)
+{
+  fgSetString("/sim/messages/approach", msg.c_str());
+  globals->get_ATC_display()->RegisterSingleMessage( msg, 0 );
+}
+