]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/apt_loader.cxx
Another clean-up iteration: FGAirportList::search is gone, replaced by two
[flightgear.git] / src / Airports / apt_loader.cxx
index 1f92be4d5ed3b11be5058ccfdc8f4db5f758efe6..d0602ac69c5c5c379a54d8c857e309e7b40603cf 100644 (file)
@@ -36,6 +36,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/misc/strutils.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <string>
 
 
 #include "apt_loader.hxx"
 
+static FGPositioned::Type fptypeFromRobinType(int aType)
+{
+  switch (aType) {
+  case 1: return FGPositioned::AIRPORT;
+  case 16: return FGPositioned::SEAPORT;
+  case 17: return FGPositioned::HELIPORT;
+  default:
+    SG_LOG(SG_GENERAL, SG_ALERT, "unsupported type:" << aType);
+    throw sg_range_exception("Unsupported airport type", "fptypeFromRobinType");
+  }
+}
+
 FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name,
     int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading,
     double apt_elev, SGGeod& tower, bool got_tower, int type)
@@ -69,8 +82,10 @@ FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const strin
         tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
     }
 
+  
+
     return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
-            type == 1/*airport*/, type == 16/*seaport*/, type == 17/*heliport*/);
+        fptypeFromRobinType(type));
 }
 
 // Load the airport data base from the specified aptdb file.  The
@@ -211,16 +226,19 @@ bool fgAirportDBLoad( FGAirportList *airports,
             double stopway2 = atof( stop[1].c_str() );
 
             int surface_code = atoi( token[10].c_str() );
-
-            FGRunway* rwy = new FGRunway(NULL, rwy_no, lon, lat, heading, length,
-                width, displ_thresh1, stopway1, surface_code, false);
-            
-            FGRunway* reciprocal = new FGRunway(NULL, FGRunway::reverseIdent(rwy_no), 
-                          lon, lat, heading + 180.0, length, width, 
-                          displ_thresh2, stopway2, surface_code, true);
-                          
+            SGGeod pos(SGGeod::fromDegFt(lon, lat, 0.0));
+            FGRunway* rwy = new FGRunway(NULL, rwy_no, pos, heading, length,
+                          width, displ_thresh1, stopway1, surface_code, false);
             runways.push_back(rwy);
-            runways.push_back(reciprocal);
+            
+            if (rwy_no[0] != 'x') {
+              // runways need a reciprocal, taxiways do not
+              FGRunway* reciprocal = new FGRunway(NULL, FGRunway::reverseIdent(rwy_no), 
+              pos, heading + 180.0, length, width, 
+              displ_thresh2, stopway2, surface_code, true);
+            
+              runways.push_back(reciprocal);
+            }
         } else if ( line_id == 18 ) {
             // beacon entry (ignore)
         } else if ( line_id == 14 ) {
@@ -231,7 +249,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
             double lat = atof( token[1].c_str() );
             double lon = atof( token[2].c_str() );
             double elev = atof( token[3].c_str() );
-            last_tower = SGGeod::fromDegFt(lon, lat, elev);
+            last_tower = SGGeod::fromDegFt(lon, lat, elev + last_apt_elev);
             got_tower = true;
         } else if ( line_id == 19 ) {
             // windsock entry (ignore)
@@ -252,7 +270,7 @@ bool fgAirportDBLoad( FGAirportList *airports,
 
     // add the last airport being processed if any
     addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
-        last_rwy_heading, last_apt_elev, last_tower, got_tower, 0);
+        last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type);
 
 
     //
@@ -271,8 +289,10 @@ bool fgAirportDBLoad( FGAirportList *airports,
         if ( ident == "#" || ident == "//" ) {
             metar_in >> skipeol;
         } else {
-            const FGAirport* a = airports->search( ident );
-            if ( a ) airports->has_metar( ident );
+            FGAirport* apt = FGAirport::findByIdent(ident);
+            if (apt) {
+                apt->setMetar(true);
+            }
         }
     }