airportinfo(): add possibility to search for next airport of a particular
type: "airport" (default), "seaport", "heliport"
This commit is contained in:
parent
73bec9e1f8
commit
40f8213b0f
1 changed files with 36 additions and 17 deletions
|
@ -389,9 +389,8 @@ static naRef f_parsexml(naContext c, naRef me, int argc, naRef* args)
|
||||||
try {
|
try {
|
||||||
readXML(input, visitor);
|
readXML(input, visitor);
|
||||||
} catch (const sg_exception& e) {
|
} catch (const sg_exception& e) {
|
||||||
string msg = string("parsexml(): file '") + file + "' "
|
naRuntimeError(c, "parsexml(): file '%s' %s",
|
||||||
+ e.getFormattedMessage();
|
file, e.getFormattedMessage().c_str());
|
||||||
naRuntimeError(c, msg.c_str());
|
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
return args[0];
|
return args[0];
|
||||||
|
@ -489,26 +488,46 @@ static naRef f_geodinfo(naContext c, naRef me, int argc, naRef* args)
|
||||||
class airport_filter : public FGAirportSearchFilter {
|
class airport_filter : public FGAirportSearchFilter {
|
||||||
virtual bool pass(FGAirport *a) { return a->isAirport(); }
|
virtual bool pass(FGAirport *a) { return a->isAirport(); }
|
||||||
} airport;
|
} airport;
|
||||||
|
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 airport data for given airport id ("KSFO"), or for the airport
|
// Returns data hash for particular or nearest airport of a <type>, or nil
|
||||||
// nearest to a given lat/lon pair, or without arguments, to the current
|
// on error. Only one side of each runway is contained.
|
||||||
// aircraft position. Returns nil on error. Only one side of each runway is
|
//
|
||||||
// returned.
|
// airportinfo(<id>); e.g. "KSFO"
|
||||||
|
// airportinfo(<type>); type := ("airport"|"seaport"|"heliport")
|
||||||
|
// airportinfo() same as airportinfo("airport")
|
||||||
|
// airportinfo(<lat>, <lon> [, <type>]);
|
||||||
static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
|
static naRef f_airportinfo(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
static SGConstPropertyNode_ptr lat = fgGetNode("/position/latitude-deg", true);
|
static SGConstPropertyNode_ptr latn = fgGetNode("/position/latitude-deg", true);
|
||||||
static SGConstPropertyNode_ptr lon = fgGetNode("/position/longitude-deg", true);
|
static SGConstPropertyNode_ptr lonn = fgGetNode("/position/longitude-deg", true);
|
||||||
|
double lat, lon;
|
||||||
|
|
||||||
// airport
|
|
||||||
FGAirportList *aptlst = globals->get_airports();
|
FGAirportList *aptlst = globals->get_airports();
|
||||||
FGAirport *apt;
|
FGAirport *apt;
|
||||||
if(argc == 0)
|
if(argc >= 2 && naIsNum(args[0]) && naIsNum(args[1])) {
|
||||||
apt = aptlst->search(lon->getDoubleValue(), lat->getDoubleValue(), airport);
|
lat = args[0].num;
|
||||||
else if(argc == 1 && naIsString(args[0]))
|
lon = args[1].num;
|
||||||
apt = aptlst->search(naStr_data(args[0]));
|
args += 2;
|
||||||
else if(argc == 2 && naIsNum(args[0]) && naIsNum(args[1]))
|
argc -= 2;
|
||||||
apt = aptlst->search(args[1].num, args[0].num, airport);
|
} else {
|
||||||
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");
|
naRuntimeError(c, "airportinfo() with invalid function arguments");
|
||||||
return naNil();
|
return naNil();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue