]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/runways.cxx
Change tower location to an SGGeod. Include taxiways too.
[flightgear.git] / src / Airports / runways.cxx
index ae32b9fa265b8daf2adc851e447822658802fff3..4018cc5bcc5d735b10c0d60a0b4015ee11f2730c 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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.
 //
 // $Id$
 
@@ -43,14 +43,14 @@ SG_USING_STD(multimap);
 
 
 // add an entry to the list
-void FGRunwayList::add( const string id, const string rwy_no,
+void FGRunwayList::add( const string& id, const string& rwy_no,
                         const double longitude, const double latitude,
                         const double heading, const double length,
                         const double width,
                         const double displ_thresh1, const double displ_thresh2,
                         const double stopway1, const double stopway2,
-                        const string lighting_flags, const int surface_code,
-                        const string shoulder_code, const int marking_code,
+                        const string& lighting_flags, const int surface_code,
+                        const string& shoulder_code, const int marking_code,
                         const double smoothness, const bool dist_remaining )
 {
     FGRunway rwy;
@@ -80,22 +80,26 @@ void FGRunwayList::add( const string id, const string rwy_no,
     rwy._smoothness = smoothness;
     rwy._dist_remaining = dist_remaining;
 
-    if ( rwy_no == "xxx" ) {
+    if ( rwy_no[0] == 'x' ) {
         rwy._type = "taxiway";
-        // don't insert taxiways into the DB for now
     } else {
         rwy._type = "runway";
-        runways.insert(pair<const string, FGRunway>(rwy._id, rwy));
     }
+    runways.insert(pair<const string, FGRunway>(rwy._id, rwy));
 }
 
 
 // Return reverse rwy number
 // eg 01 -> 19
 // 03L -> 21R
-static string GetReverseRunwayNo(string rwyno) {       
+static string GetReverseRunwayNo(string& rwyno) {      
     // cout << "Original rwyno = " << rwyNo << '\n';
     
+    // Helipads don't have a seperate number per end
+    if(rwyno.size() && (rwyno[0] == 'H' || rwyno[0] == 'h' || rwyno[0] == 'x')) {
+       return rwyno;
+    }
+    
     // standardize input number
     string tmp = rwyno.substr(1, 1);
     if (( tmp == "L" || tmp == "R" || tmp == "C" ) || (rwyno.size() == 1)) {
@@ -216,8 +220,8 @@ string FGRunwayList::search( const string& aptid, const int tgt_hdg ) {
     FGRunway r;
     FGRunway tmp_r;    
     string rn;
-    double found_dir = 0.0;  
+    double found_dir = 0.0;
+
     if ( !search( aptid, &tmp_r ) ) {
        SG_LOG( SG_GENERAL, SG_ALERT,
                 "Failed to find " << aptid << " in database." );
@@ -228,47 +232,44 @@ string FGRunwayList::search( const string& aptid, const int tgt_hdg ) {
     double min_diff = 360.0;
     
     while ( tmp_r._id == aptid ) {
-       r = tmp_r;
-       
        // forward direction
-       diff = tgt_hdg - r._heading;
+       diff = tgt_hdg - tmp_r._heading;
        while ( diff < -180.0 ) { diff += 360.0; }
        while ( diff >  180.0 ) { diff -= 360.0; }
        diff = fabs(diff);
         // SG_LOG( SG_GENERAL, SG_INFO,
-        //        "Runway " << r.rwy_no << " heading = " << r.heading <<
-        //        " diff = " << diff );
+        //        "Runway " << tmp_r._rwy_no << " heading = "
+       //         << tmp_r._heading << " diff = " << diff );
        if ( diff < min_diff ) {
            min_diff = diff;
-           rn = r._rwy_no;
+           r = tmp_r;
            found_dir = 0;
        }
        
        // reverse direction
-       diff = tgt_hdg - r._heading - 180.0;
+       diff = tgt_hdg - tmp_r._heading - 180.0;
        while ( diff < -180.0 ) { diff += 360.0; }
        while ( diff >  180.0 ) { diff -= 360.0; }
        diff = fabs(diff);
         // SG_LOG( SG_GENERAL, SG_INFO,
-        //        "Runway -" << r._rwy_no << " heading = " <<
-        //        r._heading + 180.0 <<
+        //        "Runway -" << tmp_r._rwy_no << " heading = " <<
+        //        tmp_r._heading + 180.0 <<
         //        " diff = " << diff );
        if ( diff < min_diff ) {
            min_diff = diff;
-           rn = r._rwy_no;
+           r = tmp_r;
            found_dir = 180.0;
        }
        
-       next( &tmp_r );
+        if (!next( &tmp_r ))
+            break;
     }
     
     // SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << r._rwy_no
     //        << " + " << found_dir );
     rn = r._rwy_no;
-    // cout << "In search, rn = " << rn << endl;
     if ( found_dir == 180 ) {
        rn = GetReverseRunwayNo(rn);
-       //cout << "New rn = " << rn << '\n';
     }  
     
     return rn;