]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/ilslist.cxx
Added static port system and a new altimeter model connected to it.
[flightgear.git] / src / Navaids / ilslist.cxx
index cf8c9e55fb22b6f56b92e5f968b34361bac76991..151c87b89aa0c898fe9f86230990ad5492180aeb 100644 (file)
@@ -48,7 +48,6 @@ FGILSList::~FGILSList( void ) {
 
 // load the navaids and build the map
 bool FGILSList::init( SGPath path ) {
-    FGILS ils;
 
     ilslist.erase( ilslist.begin(), ilslist.end() );
 
@@ -63,43 +62,38 @@ bool FGILSList::init( SGPath path ) {
     in >> skipeol;
     in >> skipcomment;
 
-#ifdef __MWERKS__
+    // double min = 1000000.0;
+    // double max = 0.0;
 
+#ifdef __MWERKS__
     char c = 0;
-    while ( in.get(c) && c != '\0' && ils.get_ilstype() != '[' ) {
+    while ( in.get(c) && c != '\0' ) {
         in.putback(c);
-        in >> ils;
-       if ( ils.get_ilstype() != '[' ) {
-           ilslist[ils.get_locfreq()].push_back(ils);
-       }
-        in >> skipcomment;
-    }
-
 #else
+    while ( ! in.eof() ) {
+#endif
 
-    double min = 1000000.0;
-    double max = 0.0;
-
-    while ( ! in.eof() && ils.get_ilstype() != '[' ) {
+        FGILS ils;
         in >> ils;
-       /* cout << "id = " << n.get_ident() << endl;
-       cout << " type = " << n.get_type() << endl;
-       cout << " lon = " << n.get_lon() << endl;
-       cout << " lat = " << n.get_lat() << endl;
-       cout << " elev = " << n.get_elev() << endl;
-       cout << " freq = " << n.get_freq() << endl;
-       cout << " range = " << n.get_range() << endl; */
-       if ( ils.get_ilstype() != '[' ) {
-           ilslist[ils.get_locfreq()].push_back(ils);
-       }
+        if ( ils.get_ilstype() == '[' ) {
+            break;
+        }
+
+        /* cout << "typename = " << ils.get_ilstypename() << endl;
+        cout << " aptcode = " << ils.get_aptcode() << endl;
+        cout << " twyno = " << ils.get_rwyno() << endl;
+        cout << " locfreq = " << ils.get_locfreq() << endl;
+        cout << " locident = " << ils.get_locident() << endl << endl; */
+
+        ilslist[ils.get_locfreq()].push_back(ils);
         in >> skipcomment;
 
-       if ( ils.get_locfreq() < min ) {
+       /* if ( ils.get_locfreq() < min ) {
            min = ils.get_locfreq();
        }
        if ( ils.get_locfreq() > max ) {
            max = ils.get_locfreq();
-       }
+       } */
 
        // update the marker beacon list
        if ( fabs(ils.get_omlon()) > SG_EPSILON ||
@@ -122,8 +116,6 @@ bool FGILSList::init( SGPath path ) {
     // cout << "min freq = " << min << endl;
     // cout << "max freq = " << max << endl;
 
-#endif
-
     return true;
 }
 
@@ -138,6 +130,9 @@ bool FGILSList::query( double lon, double lat, double elev, double freq,
     ils_list_iterator current = stations.begin();
     ils_list_iterator last = stations.end();
 
+    double best_angle = 362.0;
+    bool found_one = false;
+
     // double az1, az2, s;
     Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
     Point3D station;
@@ -162,10 +157,31 @@ bool FGILSList::query( double lon, double lat, double elev, double freq,
        // reduced signal strength
        if ( d < (2* FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
                  * 2 * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER) ) {
-           *ils = *current;
-           return true;
+
+            found_one = true;
+
+            // Get our bearing from this station.
+            double reciprocal_bearing, dummy;
+            double a_lat_deg = lat * SGD_RADIANS_TO_DEGREES;
+            double a_lon_deg = lon * SGD_RADIANS_TO_DEGREES;
+            // Locator beam direction
+            double s_ils_deg = current->get_locheading() - 180.0;
+            if ( s_ils_deg < 0.0 ) { s_ils_deg += 360.0; }
+            double angle_to_beam_deg;
+
+            // printf("**ALI geting geo_inverse_wgs_84 with elev = %.2f, a.lat = %.2f, a.lon = %.2f,
+            // s.lat = %.2f, s.lon = %.2f\n", elev,a_lat_deg,a_lon_deg,current->get_loclat(),current->get_loclon());
+
+            geo_inverse_wgs_84( elev, current->get_loclat(),
+                                current->get_loclon(), a_lat_deg, a_lon_deg,
+                                &reciprocal_bearing, &dummy, &dummy );
+            angle_to_beam_deg = fabs(reciprocal_bearing - s_ils_deg);
+            if ( angle_to_beam_deg <= best_angle ) {
+                *ils = *current;
+                best_angle = angle_to_beam_deg;
+            }
        }
     }
 
-    return false;
+    return found_one;
 }