From: daveluff Date: Wed, 5 Mar 2003 21:34:58 +0000 (+0000) Subject: Added some airport search functions that are straight copies of a couple of statics... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8bbaba31931de4abb36f15250bcbb6843cdda08a;p=flightgear.git Added some airport search functions that are straight copies of a couple of statics in fg_init, and will probably be removed again at some point, and added a function to convert a runway designator string to a spoken style phrase --- diff --git a/src/ATC/ATCutils.cxx b/src/ATC/ATCutils.cxx index 0c98fa73b..eb89d579a 100644 --- a/src/ATC/ATCutils.cxx +++ b/src/ATC/ATCutils.cxx @@ -21,9 +21,14 @@ #include #include #include +#include +#include #include //#include +#include +#include
+ #include "ATCutils.hxx" // Convert any number to spoken digits @@ -74,6 +79,19 @@ string ConvertRwyNumToSpokenString(int n) { return(str); } +// Assumes we get a two-digit string optionally appended with R or L +// eg 01 07L 29R 36 +// Anything else is not guaranteed to be handled correctly! +string ConvertRwyNumToSpokenString(string s) { + if(s.size() < 3) { + return(ConvertRwyNumToSpokenString(atoi(s.c_str()))); + } else { + string r = ConvertRwyNumToSpokenString(atoi(s.substr(0,2).c_str())); + return(r += (s.substr(2,1) == "L" ? " left" : " right")); // Warning - not much error checking there! + } +} + + // Return the phonetic letter of a letter represented as an integer 1->26 string GetPhoneticIdent(int i) { // TODO - Check i is between 1 and 26 and wrap if necessary @@ -218,3 +236,47 @@ void dclBoundHeading(double &hdg) { hdg -= 360.0; } } + +// Airport stuff. The next two functions are straight copies of their fg.... equivalents +// in fg_init.cxx, and are just here temporarily until some rationalisation occurs. +// find basic airport location info from airport database +bool dclFindAirportID( const string& id, FGAirport *a ) { + if ( id.length() ) { + SGPath path( globals->get_fg_root() ); + path.append( "Airports" ); + path.append( "simple.mk4" ); + FGAirports airports( path.c_str() ); + + SG_LOG( SG_GENERAL, SG_INFO, "Searching for airport code = " << id ); + + if ( ! airports.search( id, a ) ) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Failed to find " << id << " in " << path.str() ); + return false; + } + } else { + return false; + } + + SG_LOG( SG_GENERAL, SG_INFO, + "Position for " << id << " is (" + << a->longitude << ", " + << a->latitude << ")" ); + + return true; +} + +// get airport elevation +double dclGetAirportElev( const string& id ) { + FGAirport a; + // double lon, lat; + + SG_LOG( SG_GENERAL, SG_INFO, + "Finding elevation for airport: " << id ); + + if ( dclFindAirportID( id, &a ) ) { + return a.elevation; + } else { + return -9999.0; + } +} diff --git a/src/ATC/ATCutils.hxx b/src/ATC/ATCutils.hxx index 7655ec85c..de50b6e29 100644 --- a/src/ATC/ATCutils.hxx +++ b/src/ATC/ATCutils.hxx @@ -18,6 +18,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#include + #include #include #include @@ -40,6 +42,13 @@ string ConvertNumToSpokenDigits(string n); // Convert a 2 digit rwy number to a spoken-style string string ConvertRwyNumToSpokenString(int n); +// Convert rwy number string to a spoken-style string +// eg "05L" to "zero five left" +// Assumes we get a two-digit string optionally appended with R or L +// eg 01 07L 29R 36 +// Anything else is not guaranteed to be handled correctly! +string ConvertRwyNumToSpokenString(string s); + // Return the phonetic letter of a letter represented as an integer 1->26 string GetPhoneticIdent(int i); @@ -66,3 +75,19 @@ double GetHeadingFromTo(Point3D A, Point3D B); // Given a heading (in degrees), bound it from 0 -> 360 void dclBoundHeading(double &hdg); + + +/******************************* +* +* Airport-related functions +* +********************************/ + +// The next two functions are straight copies of their fg.... equivalents +// in fg_init.cxx, and are just here temporarily until some rationalisation occurs. + +// find basic airport location info from airport database +bool dclFindAirportID( const string& id, FGAirport *a ); + +// get airport elevation +double dclGetAirportElev( const string& id );