X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FScripting%2FNasalPositioned.cxx;h=66bfb5826a370b55bf7af5642dbdf78096d6baf3;hb=12076bce0e9fb66286f14931e8f4eb12fc0b9b82;hp=3ec918cbdd92b9e9d3480c6766f4b3ab8e1fdae0;hpb=a3a40af860505a481e6bb468239766f8ce405998;p=flightgear.git diff --git a/src/Scripting/NasalPositioned.cxx b/src/Scripting/NasalPositioned.cxx index 3ec918cbd..66bfb5826 100644 --- a/src/Scripting/NasalPositioned.cxx +++ b/src/Scripting/NasalPositioned.cxx @@ -53,6 +53,7 @@ #include #include #include +#include using namespace flightgear; @@ -313,7 +314,7 @@ naRef ghostForWaypt(naContext c, const Waypt* wpt) if (!wpt) { return naNil(); } - + Waypt::get(wpt); // take a ref return naNewGhost2(c, &WayptGhostType, (void*) wpt); } @@ -801,7 +802,7 @@ static bool hashIsCoord(naRef h) return false; } - return naEqual(naVec_get(parents, 0), geoCoordClass); + return naEqual(naVec_get(parents, 0), geoCoordClass) != 0; } bool geodFromHash(naRef ref, SGGeod& result) @@ -1339,18 +1340,21 @@ static naRef f_airport_parking(naContext c, naRef me, int argc, naRef* args) } FGAirportDynamics* dynamics = apt->getDynamics(); - for (int i=0; igetNrOfParkings(); ++i) { - FGParking* park = dynamics->getParking(i); - // filter out based on availability and type - if (onlyAvailable && !park->isAvailable()) { + PositionedIDVec parkings = flightgear::NavDataCache::instance()->airportItemsOfType(apt->guid(), + FGPositioned::PARKING); + + BOOST_FOREACH(PositionedID parking, parkings) { + // filter out based on availability and type + if (onlyAvailable && !dynamics->isParkingAvailable(parking)) { continue; } + FGParking* park = dynamics->getParking(parking); if (!type.empty() && (park->getType() != type)) { continue; } - const SGGeod& parkLoc = park->getGeod(); + const SGGeod& parkLoc = park->geod(); naRef ph = naNewHash(c); hashset(c, ph, "name", stringToNasal(c, park->getName())); hashset(c, ph, "lat", naNum(parkLoc.getLatitudeDeg())); @@ -2121,6 +2125,31 @@ static naRef f_flightplan_clone(naContext c, naRef me, int argc, naRef* args) return ghostForFlightPlan(c, fp->clone()); } +static naRef f_flightplan_pathGeod(naContext c, naRef me, int argc, naRef* args) +{ + FlightPlan* fp = flightplanGhost(me); + if (!fp) { + naRuntimeError(c, "flightplan.clone called on non-flightplan object"); + } + + if ((argc < 1) || !naIsNum(args[0])) { + naRuntimeError(c, "bad argument to flightplan.pathGeod"); + } + + if ((argc > 1) && !naIsNum(args[1])) { + naRuntimeError(c, "bad argument to flightplan.pathGeod"); + } + + int index = (int) args[0].num; + double offset = (argc > 1) ? args[1].num : 0.0; + naRef result = naNewHash(c); + SGGeod g = fp->pointAlongRoute(index, offset); + hashset(c, result, "lat", naNum(g.getLatitudeDeg())); + hashset(c, result, "lon", naNum(g.getLongitudeDeg())); + return result; +} + + static naRef f_leg_setSpeed(naContext c, naRef me, int argc, naRef* args) { FlightPlan::Leg* leg = fpLegGhost(me); @@ -2361,7 +2390,8 @@ naRef initNasalPositioned(naRef globals, naContext c, naRef gcSave) hashset(c, flightplanPrototype, "cleanPlan", naNewFunc(c, naNewCCode(c, f_flightplan_clearPlan))); hashset(c, flightplanPrototype, "clearWPType", naNewFunc(c, naNewCCode(c, f_flightplan_clearWPType))); hashset(c, flightplanPrototype, "clone", naNewFunc(c, naNewCCode(c, f_flightplan_clone))); - + hashset(c, flightplanPrototype, "pathGeod", naNewFunc(c, naNewCCode(c, f_flightplan_pathGeod))); + waypointPrototype = naNewHash(c); hashset(c, gcSave, "wayptProto", waypointPrototype);