X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fpositioninit.cxx;h=337ab7141fdc73e54e0592f4ecaa5c0696159ad8;hb=0c00cd3c6d34e4e167457897a274864cb7236da6;hp=59000c10b5651fbca2af4506c3bbf7ef7d93d20b;hpb=56d7d049bc0b7361d1799298c38e61084f5d5e3f;p=flightgear.git diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index 59000c10b..337ab7141 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -196,7 +196,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find airport " << id ); return false; } - FGAirportDynamics* dcs = apt->getDynamics(); + FGAirportDynamicsRef dcs = apt->getDynamics(); if (!dcs) { SG_LOG( SG_GENERAL, SG_ALERT, "Airport " << id << "does not appear to have parking information available"); @@ -213,24 +213,24 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par string acfile = fgGetString("/sim/aircraft") + string(".xml"); acData.append(acfile); SGPropertyNode root; - readProperties(acData.str(), &root); + readProperties(acData, &root); SGPropertyNode * node = root.getNode("sim"); fltType = node->getStringValue("aircraft-class", "NONE" ); acOperator = node->getStringValue("aircraft-operator", "NONE" ); } catch (const sg_exception &) { SG_LOG(SG_GENERAL, SG_INFO, - "Could not load aircraft aircrat type and operator information from: " << acData.str() << ". Using defaults"); + "Could not load aircraft aircrat type and operator information from: " << acData << ". Using defaults"); // cout << path.str() << endl; } if (fltType.empty() || fltType == "NONE") { SG_LOG(SG_GENERAL, SG_INFO, - "Aircraft type information not found in: " << acData.str() << ". Using default value"); + "Aircraft type information not found in: " << acData << ". Using default value"); fltType = fgGetString("/sim/aircraft-class" ); } if (acOperator.empty() || fltType == "NONE") { SG_LOG(SG_GENERAL, SG_INFO, - "Aircraft operator information not found in: " << acData.str() << ". Using default value"); + "Aircraft operator information not found in: " << acData << ". Using default value"); acOperator = fgGetString("/sim/aircraft-operator" ); } @@ -261,7 +261,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par // The parking will be released after this function returns. // As a temporary measure, I'll try to reserve the parking via the atc_manager, which should work, because it uses the same // mechanism as the AI traffic code. - dcs->setParkingAvailable(pka.parking()->guid(), false); + dcs->setParkingAvailable(pka.parking(), false); fgApplyStartOffset(pka.parking()->geod(), pka.parking()->getHeading()); return true; } @@ -353,37 +353,51 @@ static void fgSetDistOrAltFromGlideSlope() { // Set current_options lon/lat given an airport id and heading (degrees) -static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned::Type type ) +static bool fgSetPosFromNAV( const string& id, + const double& freq, + FGPositioned::Type type, + PositionedID guid) { - FGNavList::TypeFilter filter(type); - const nav_list_type navlist = FGNavList::findByIdentAndFreq( id.c_str(), freq, &filter ); - - if (navlist.empty()) { - SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " - << id << ":" << freq ); - return false; - } - - if( navlist.size() > 1 ) { - std::ostringstream buf; - buf << "Ambigous NAV-ID: '" << id << "'. Specify id and frequency. Available stations:" << endl; - for( nav_list_type::const_iterator it = navlist.begin(); it != navlist.end(); ++it ) { - // NDB stored in kHz, VOR stored in MHz * 100 :-P - double factor = (*it)->type() == FGPositioned::NDB ? 1.0 : 1/100.0; - string unit = (*it)->type() == FGPositioned::NDB ? "kHz" : "MHz"; - buf << (*it)->ident() << " " - << std::setprecision(5) << (double)((*it)->get_freq() * factor) << " " - << (*it)->get_lat() << "/" << (*it)->get_lon() - << endl; + FGNavRecord* nav = 0; + + + if (guid != 0) { + nav = FGPositioned::loadById(guid); + if (!nav) + return false; + } else { + FGNavList::TypeFilter filter(type); + const nav_list_type navlist = FGNavList::findByIdentAndFreq( id.c_str(), freq, &filter ); + + if (navlist.empty()) { + SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " + << id << ":" << freq ); + return false; + } + + if( navlist.size() > 1 ) { + std::ostringstream buf; + buf << "Ambigous NAV-ID: '" << id << "'. Specify id and frequency. Available stations:" << endl; + for( nav_list_type::const_iterator it = navlist.begin(); it != navlist.end(); ++it ) { + // NDB stored in kHz, VOR stored in MHz * 100 :-P + double factor = (*it)->type() == FGPositioned::NDB ? 1.0 : 1/100.0; + string unit = (*it)->type() == FGPositioned::NDB ? "kHz" : "MHz"; + buf << (*it)->ident() << " " + << std::setprecision(5) << (double)((*it)->get_freq() * factor) << " " + << (*it)->get_lat() << "/" << (*it)->get_lon() + << endl; + } + + SG_LOG( SG_GENERAL, SG_ALERT, buf.str() ); + return false; + } + + // nav list must be of length 1 + nav = navlist[0]; } - - SG_LOG( SG_GENERAL, SG_ALERT, buf.str() ); - return false; - } - - FGNavRecord *nav = navlist[0]; - fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg")); - return true; + + fgApplyStartOffset(nav->geod(), fgGetDouble("/sim/presets/heading-deg")); + return true; } // Set current_options lon/lat given an aircraft carrier id @@ -429,7 +443,7 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) { } } -// Set current_options lon/lat given an airport id and heading (degrees) +// Set current_options lon/lat given a fix ident and GUID static bool fgSetPosFromFix( const string& id, PositionedID guid ) { FGPositioned* fix = NULL; @@ -558,14 +572,14 @@ bool initPosition() if ( !set_pos && !vor.empty() ) { // a VOR is requested - if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR ) ) { + if ( fgSetPosFromNAV( vor, vor_freq, FGPositioned::VOR, navaidId ) ) { set_pos = true; } } if ( !set_pos && !ndb.empty() ) { // an NDB is requested - if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB ) ) { + if ( fgSetPosFromNAV( ndb, ndb_freq, FGPositioned::NDB, navaidId ) ) { set_pos = true; } } @@ -585,10 +599,20 @@ bool initPosition() } if ( !set_pos ) { - // No lon/lat specified, no airport specified, default to - // middle of KSFO field. - fgSetDouble("/sim/presets/longitude-deg", -122.374843); - fgSetDouble("/sim/presets/latitude-deg", 37.619002); + // No lon/lat specified, no airport specified, use the default airport + // TODO: don't hardcode this + const FGAirport* airport = fgFindAirportID("LEBL"); + if( airport ) { + const SGGeod & airportGeod = airport->geod(); + fgSetDouble("/sim/presets/longitude-deg", airportGeod.getLongitudeDeg()); + fgSetDouble("/sim/presets/latitude-deg", airportGeod.getLatitudeDeg()); + } else { + // So, the default airport is unknown? We are in serious trouble. + // Let's hope KSFO still exists somehow + fgSetDouble("/sim/presets/longitude-deg", -122.374843); + fgSetDouble("/sim/presets/latitude-deg", 37.619002); + SG_LOG(SG_GENERAL, SG_ALERT, "Sorry, the default airport seems to be unknown."); + } } fgSetDouble( "/position/longitude-deg",