From: mfranz Date: Sun, 14 Oct 2007 07:51:11 +0000 (+0000) Subject: airportinfo(): add possibility to search for next airport of a particular X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=40f8213b0f907e08650020b1342f268f56e43c9e;p=flightgear.git airportinfo(): add possibility to search for next airport of a particular type: "airport" (default), "seaport", "heliport" --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index ac5c98d1d..32fec50ac 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -389,9 +389,8 @@ static naRef f_parsexml(naContext c, naRef me, int argc, naRef* args) try { readXML(input, visitor); } catch (const sg_exception& e) { - string msg = string("parsexml(): file '") + file + "' " - + e.getFormattedMessage(); - naRuntimeError(c, msg.c_str()); + naRuntimeError(c, "parsexml(): file '%s' %s", + file, e.getFormattedMessage().c_str()); return naNil(); } return args[0]; @@ -489,26 +488,46 @@ static naRef f_geodinfo(naContext c, naRef me, int argc, naRef* args) class airport_filter : public FGAirportSearchFilter { virtual bool pass(FGAirport *a) { return a->isAirport(); } } airport; - -// Returns airport data for given airport id ("KSFO"), or for the airport -// nearest to a given lat/lon pair, or without arguments, to the current -// aircraft position. Returns nil on error. Only one side of each runway is -// returned. +class seaport_filter : public FGAirportSearchFilter { + virtual bool pass(FGAirport *a) { return a->isSeaport(); } +} seaport; +class heliport_filter : public FGAirportSearchFilter { + virtual bool pass(FGAirport *a) { return a->isHeliport(); } +} heliport; + +// Returns data hash for particular or nearest airport of a , or nil +// on error. Only one side of each runway is contained. +// +// airportinfo(); e.g. "KSFO" +// airportinfo(); type := ("airport"|"seaport"|"heliport") +// airportinfo() same as airportinfo("airport") +// airportinfo(, [, ]); static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args) { - static SGConstPropertyNode_ptr lat = fgGetNode("/position/latitude-deg", true); - static SGConstPropertyNode_ptr lon = fgGetNode("/position/longitude-deg", true); + static SGConstPropertyNode_ptr latn = fgGetNode("/position/latitude-deg", true); + static SGConstPropertyNode_ptr lonn = fgGetNode("/position/longitude-deg", true); + double lat, lon; - // airport FGAirportList *aptlst = globals->get_airports(); FGAirport *apt; - if(argc == 0) - apt = aptlst->search(lon->getDoubleValue(), lat->getDoubleValue(), airport); - else if(argc == 1 && naIsString(args[0])) - apt = aptlst->search(naStr_data(args[0])); - else if(argc == 2 && naIsNum(args[0]) && naIsNum(args[1])) - apt = aptlst->search(args[1].num, args[0].num, airport); - else { + if(argc >= 2 && naIsNum(args[0]) && naIsNum(args[1])) { + lat = args[0].num; + lon = args[1].num; + args += 2; + argc -= 2; + } else { + lat = latn->getDoubleValue(); + lon = lonn->getDoubleValue(); + } + if(argc == 0) { + apt = aptlst->search(lon, lat, airport); + } else if(argc == 1 && naIsString(args[0])) { + const char *s = naStr_data(args[0]); + if(!strcmp(s, "airport")) apt = aptlst->search(lon, lat, airport); + else if(!strcmp(s, "seaport")) apt = aptlst->search(lon, lat, seaport); + else if(!strcmp(s, "heliport")) apt = aptlst->search(lon, lat, heliport); + else apt = aptlst->search(s); + } else { naRuntimeError(c, "airportinfo() with invalid function arguments"); return naNil(); }