+ FGRunway* rwy = runwayGhost(value);
+ if (rwy){
+ fp->setDestination(rwy);
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting destination");
+ } else if (!strcmp(fieldName, "departure_runway")) {
+ FGRunway* rwy = runwayGhost(value);
+ if (rwy){
+ fp->setDeparture(rwy);
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting departure");
+ } else if (!strcmp(fieldName, "destination_runway")) {
+ FGRunway* rwy = runwayGhost(value);
+ if (rwy){
+ fp->setDestination(rwy);
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting departure");
+ } else if (!strcmp(fieldName, "sid")) {
+ Procedure* proc = procedureGhost(value);
+ if (proc && (proc->type() == PROCEDURE_SID)) {
+ fp->setSID((flightgear::SID*) proc);
+ return;
+ }
+ // allow a SID transition to be set, implicitly include the SID itself
+ if (proc && (proc->type() == PROCEDURE_TRANSITION)) {
+ fp->setSID((Transition*) proc);
+ return;
+ }
+
+ if (naIsString(value)) {
+ FGAirport* apt = fp->departureAirport();
+ fp->setSID(apt->findSIDWithIdent(naStr_data(value)));
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting SID");
+ } else if (!strcmp(fieldName, "star")) {
+ Procedure* proc = procedureGhost(value);
+ if (proc && (proc->type() == PROCEDURE_STAR)) {
+ fp->setSTAR((STAR*) proc);
+ return;
+ }
+
+ if (proc && (proc->type() == PROCEDURE_TRANSITION)) {
+ fp->setSTAR((Transition*) proc);
+ return;
+ }
+
+ if (naIsString(value)) {
+ FGAirport* apt = fp->destinationAirport();
+ fp->setSTAR(apt->findSTARWithIdent(naStr_data(value)));
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting STAR");
+ } else if (!strcmp(fieldName, "approach")) {
+ Procedure* proc = procedureGhost(value);
+ if (proc && Approach::isApproach(proc->type())) {
+ fp->setApproach((Approach*) proc);
+ return;
+ }
+
+ if (naIsString(value)) {
+ FGAirport* apt = fp->destinationAirport();
+ fp->setApproach(apt->findApproachWithIdent(naStr_data(value)));
+ return;
+ }
+
+ naRuntimeError(c, "bad argument type setting approach");
+ }
+}
+
+
+static naRef procedureTpType(naContext c, ProcedureType ty)
+{
+ switch (ty) {
+ case PROCEDURE_SID: return stringToNasal(c, "sid");
+ case PROCEDURE_STAR: return stringToNasal(c, "star");
+ case PROCEDURE_APPROACH_VOR:
+ case PROCEDURE_APPROACH_ILS:
+ case PROCEDURE_APPROACH_RNAV:
+ case PROCEDURE_APPROACH_NDB:
+ return stringToNasal(c, "IAP");
+ default:
+ return naNil();
+ }
+}
+
+static naRef procedureRadioType(naContext c, ProcedureType ty)
+{
+ switch (ty) {
+ case PROCEDURE_APPROACH_VOR: return stringToNasal(c, "VOR");
+ case PROCEDURE_APPROACH_ILS: return stringToNasal(c, "ILS");
+ case PROCEDURE_APPROACH_RNAV: return stringToNasal(c, "RNAV");
+ case PROCEDURE_APPROACH_NDB: return stringToNasal(c, "NDB");
+ default:
+ return naNil();
+ }
+}
+
+static const char* procedureGhostGetMember(naContext c, void* g, naRef field, naRef* out)
+{
+ const char* fieldName = naStr_data(field);
+ Procedure* proc = (Procedure*) g;
+
+ if (!strcmp(fieldName, "parents")) {
+ *out = naNewVector(c);
+ naVec_append(*out, procedurePrototype);
+ } else if (!strcmp(fieldName, "id")) *out = stringToNasal(c, proc->ident());
+ else if (!strcmp(fieldName, "airport")) *out = ghostForAirport(c, proc->airport());
+ else if (!strcmp(fieldName, "tp_type")) *out = procedureTpType(c, proc->type());
+ else if (!strcmp(fieldName, "radio")) *out = procedureRadioType(c, proc->type());
+ else if (!strcmp(fieldName, "runways")) {
+ *out = naNewVector(c);
+ BOOST_FOREACH(FGRunwayRef rwy, proc->runways()) {
+ naVec_append(*out, stringToNasal(c, rwy->ident()));
+ }
+ } else if (!strcmp(fieldName, "transitions")) {
+ if ((proc->type() != PROCEDURE_SID) && (proc->type() != PROCEDURE_STAR)) {
+ *out = naNil();
+ return "";
+ }
+
+ ArrivalDeparture* ad = static_cast<ArrivalDeparture*>(proc);
+ *out = naNewVector(c);
+ BOOST_FOREACH(std::string id, ad->transitionIdents()) {
+ naVec_append(*out, stringToNasal(c, id));
+ }
+ } else {
+ return 0;
+ }
+
+ return "";
+}
+
+static const char* runwayGhostGetMember(naContext c, void* g, naRef field, naRef* out)
+{
+ const char* fieldName = naStr_data(field);
+ 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, "reciprocal")) {
+ *out = ghostForRunway(c, rwy->reciprocalRunway());
+ } 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 "";
+}
+
+static const char* navaidGhostGetMember(naContext c, void* g, naRef field, naRef* out)
+{
+ const char* fieldName = naStr_data(field);
+ FGNavRecord* nav = (FGNavRecord*) g;
+
+ if (!strcmp(fieldName, "id")) *out = stringToNasal(c, nav->ident());
+ else if (!strcmp(fieldName, "name")) *out = stringToNasal(c, nav->name());
+ else if (!strcmp(fieldName, "lat")) *out = naNum(nav->get_lat());
+ else if (!strcmp(fieldName, "lon")) *out = naNum(nav->get_lon());
+ else if (!strcmp(fieldName, "elevation")) {
+ *out = naNum(nav->get_elev_ft() * SG_FEET_TO_METER);
+ } else if (!strcmp(fieldName, "type")) {
+ *out = stringToNasal(c, nav->nameForType(nav->type()));
+ } else if (!strcmp(fieldName, "frequency")) {
+ *out = naNum(nav->get_freq());
+ } else if (!strcmp(fieldName, "range_nm")) {
+ *out = naNum(nav->get_range());
+ } else if (!strcmp(fieldName, "course")) {
+ if ((nav->type() == FGPositioned::ILS) || (nav->type() == FGPositioned::LOC)) {
+ double radial = nav->get_multiuse();
+ SG_NORMALIZE_RANGE(radial, 0.0, 360.0);
+ *out = naNum(radial);
+ } else {
+ *out = naNil();
+ }
+ } else {
+ return 0;
+ }
+
+ return "";
+}
+
+static const char* fixGhostGetMember(naContext c, void* g, naRef field, naRef* out)
+{
+ const char* fieldName = naStr_data(field);
+ FGFix* fix = (FGFix*) g;
+
+ if (!strcmp(fieldName, "id")) *out = stringToNasal(c, fix->ident());
+ else if (!strcmp(fieldName, "lat")) *out = naNum(fix->get_lat());
+ else if (!strcmp(fieldName, "lon")) *out = naNum(fix->get_lon());
+ else {
+ return 0;
+ }
+
+ return "";