#include <Navaids/routePath.hxx>
#include <Navaids/procedure.hxx>
#include <Navaids/airways.hxx>
+#include <Navaids/NavDataCache.hxx>
using namespace flightgear;
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out);
naGhostType RunwayGhostType = { positionedGhostDestroy, "runway", runwayGhostGetMember, 0 };
+naGhostType TaxiwayGhostType = { positionedGhostDestroy, "taxiway", runwayGhostGetMember, 0 };
static const char* fixGhostGetMember(naContext c, void* g, naRef field, naRef* out);
naGhostType FixGhostType = { positionedGhostDestroy, "fix", fixGhostGetMember, 0 };
return 0;
}
+static FGTaxiway* taxiwayGhost(naRef r)
+{
+ if (naGhost_type(r) == &TaxiwayGhostType)
+ return (FGTaxiway*) naGhost_ptr(r);
+ return 0;
+}
+
static FGFix* fixGhost(naRef r)
{
if (naGhost_type(r) == &FixGhostType)
return naNewGhost2(c, &RunwayGhostType, (void*) r);
}
+naRef ghostForTaxiway(naContext c, const FGTaxiway* r)
+{
+ if (!r) {
+ return naNil();
+ }
+
+ FGPositioned::get(r); // take a ref
+ return naNewGhost2(c, &TaxiwayGhostType, (void*) r);
+}
+
naRef ghostForFix(naContext c, const FGFix* r)
{
if (!r) {
if (!wpt) {
return naNil();
}
-
+
Waypt::get(wpt); // take a ref
return naNewGhost2(c, &WayptGhostType, (void*) wpt);
}
naHash_set(*out, rwyid, rwydata);
}
+ } else if (!strcmp(fieldName, "taxiways")) {
+ *out = naNewVector(c);
+ for(unsigned int r=0; r<apt->numTaxiways(); ++r) {
+ FGTaxiway* taxi(apt->getTaxiwayByIndex(r));
+ naRef taxidata = ghostForTaxiway(c, taxi);
+ naVec_append(*out, taxidata);
+ }
+
} else {
return 0;
}
static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
{
const char* fieldName = naStr_data(field);
- FGRunway* rwy = (FGRunway*) g;
-
- if (!strcmp(fieldName, "id")) *out = stringToNasal(c, rwy->ident());
- else if (!strcmp(fieldName, "lat")) *out = naNum(rwy->latitude());
- else if (!strcmp(fieldName, "lon")) *out = naNum(rwy->longitude());
- else if (!strcmp(fieldName, "heading")) *out = naNum(rwy->headingDeg());
- else if (!strcmp(fieldName, "length")) *out = naNum(rwy->lengthM());
- else if (!strcmp(fieldName, "width")) *out = naNum(rwy->widthM());
- else if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM());
- else if (!strcmp(fieldName, "stopway")) *out = naNum(rwy->stopwayM());
- else if (!strcmp(fieldName, "ils_frequency_mhz")) {
- *out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil();
- } else if (!strcmp(fieldName, "ils")) {
- *out = ghostForNavaid(c, rwy->ILS());
+ FGRunwayBase* base = (FGRunwayBase*) g;
+
+ if (!strcmp(fieldName, "id")) *out = stringToNasal(c, base->ident());
+ else if (!strcmp(fieldName, "lat")) *out = naNum(base->latitude());
+ else if (!strcmp(fieldName, "lon")) *out = naNum(base->longitude());
+ else if (!strcmp(fieldName, "heading")) *out = naNum(base->headingDeg());
+ else if (!strcmp(fieldName, "length")) *out = naNum(base->lengthM());
+ else if (!strcmp(fieldName, "width")) *out = naNum(base->widthM());
+ else if (!strcmp(fieldName, "surface")) *out = naNum(base->surface());
+ else if (base->type() == FGRunwayBase::RUNWAY) {
+ FGRunway* rwy = (FGRunway*) g;
+ if (!strcmp(fieldName, "threshold")) *out = naNum(rwy->displacedThresholdM());
+ else if (!strcmp(fieldName, "stopway")) *out = naNum(rwy->stopwayM());
+ else if (!strcmp(fieldName, "ils_frequency_mhz")) {
+ *out = rwy->ILS() ? naNum(rwy->ILS()->get_freq() / 100.0) : naNil();
+ } else if (!strcmp(fieldName, "ils")) {
+ *out = ghostForNavaid(c, rwy->ILS());
+ } else {
+ return 0;
+ }
} else {
- return 0;
+ return 0;
}
return "";
return false;
}
- return naEqual(naVec_get(parents, 0), geoCoordClass);
+ return naEqual(naVec_get(parents, 0), geoCoordClass) != 0;
}
bool geodFromHash(naRef ref, SGGeod& result)
return 1;
}
+ if (gt == &TaxiwayGhostType) {
+ result = taxiwayGhost(args[offset])->geod();
+ return 1;
+ }
+
if (gt == &FixGhostType) {
result = fixGhost(args[offset])->geod();
return 1;
return ghostForRunway(c, apt->getRunwayByIdent(ident));
}
+static naRef f_airport_taxiway(naContext c, naRef me, int argc, naRef* args)
+{
+ FGAirport* apt = airportGhost(me);
+ if (!apt) {
+ naRuntimeError(c, "airport.taxiway called on non-airport object");
+ }
+
+ if ((argc < 1) || !naIsString(args[0])) {
+ naRuntimeError(c, "airport.taxiway expects a taxiway ident argument");
+ }
+
+ naRef taxiways = naNewVector(c);
+
+ for (unsigned int i = 0; i < apt->numTaxiways(); i++) {
+ naVec_append(taxiways, ghostForTaxiway(c, apt->getTaxiwayByIndex(i)));
+ }
+
+ return taxiways;
+}
+
static naRef f_airport_sids(naContext c, naRef me, int argc, naRef* args)
{
FGAirport* apt = airportGhost(me);
}
FGAirportDynamics* dynamics = apt->getDynamics();
- for (int i=0; i<dynamics->getNrOfParkings(); ++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()));
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);
hashset(c, gcSave, "airportProto", airportPrototype);
hashset(c, airportPrototype, "runway", naNewFunc(c, naNewCCode(c, f_airport_runway)));
+ hashset(c, airportPrototype, "taxiway", naNewFunc(c, naNewCCode(c, f_airport_taxiway)));
hashset(c, airportPrototype, "tower", naNewFunc(c, naNewCCode(c, f_airport_tower)));
hashset(c, airportPrototype, "comms", naNewFunc(c, naNewCCode(c, f_airport_comms)));
hashset(c, airportPrototype, "sids", naNewFunc(c, naNewCCode(c, f_airport_sids)));
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);