]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/approach.cxx
Catch sound exceptions at the earliest, report problem has an alert, and continue...
[flightgear.git] / src / ATC / approach.cxx
index a08f571b5112493bf45a033863d2478a512e5499..110bf61b86b845d577c272f12991283d1cf398fc 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include "approach.hxx"
 #include "transmission.hxx"
 #include "transmissionlist.hxx"
@@ -25,6 +29,7 @@
 #include "ATCDialog.hxx"
 
 #include <Airports/runways.hxx>
+#include <simgear/constants.h>
 #include <simgear/math/polar3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 
@@ -47,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 = "";
@@ -174,7 +179,7 @@ void FGApproach::Update(double dt) {
                                tpars.alt = planes[i].aalt;
                                message = current_transmissionlist->gen_text(station, code, tpars, true );
                                //cout << message << '\n';
-                               globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                               set_message(message);
                                planes[i].lmc = code;
                                planes[i].tlm = etime_node->getDoubleValue();
                                planes[i].on_crs = true;
@@ -232,8 +237,7 @@ void FGApproach::Update(double dt) {
                                        message = current_transmissionlist->gen_text(station, code, tpars, true );
                                        //cout << "Approach transmitting...\n";
                                        //cout << message << endl;
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
-                                       
+                                       set_message(message);
                                }
                                else {
                                        code.c1 = 1;
@@ -243,7 +247,7 @@ void FGApproach::Update(double dt) {
                                        message = current_transmissionlist->gen_text(station, code, tpars, true);
                                        //cout << "Approach transmitting 2 ...\n";
                                        //cout << message << endl;
-                                       globals->get_ATC_display()->RegisterSingleMessage( message, 0 );
+                                       set_message(message);
                                }
                                planes[i].lmc = code;
                                planes[i].tlm = etime_node->getDoubleValue();
@@ -290,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();
                                }
@@ -320,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();
                                        
@@ -347,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();
                                
@@ -607,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++) {
@@ -650,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;
@@ -661,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;
@@ -747,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 );
+}
+