X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fpositioninit.cxx;h=d4cdd179935df5134fccc0da95e0602de85c9afa;hb=71eeb62c1bd1bd3d58f73fd4079de59f38a08033;hp=3a9aaca7ec053c983e06f9d3bcfc78fc5e6a2d38;hpb=ffbb0a0e5d8915df208dc8042fd3338f04b01dfe;p=flightgear.git diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index 3a9aaca7e..d4cdd1799 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -24,6 +24,7 @@ // simgear #include +#include #include "globals.hxx" #include "fg_props.hxx" @@ -150,7 +151,8 @@ bool setPosFromAirportIDandHdg( const string& id, double tgt_hdg ) { } // Set current_options lon/lat given an airport id and parkig position name -static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) { +static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) +{ if ( id.empty() ) return false; @@ -167,11 +169,9 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par return false; } - int park_index = dcs->getNrOfParkings() - 1; - bool succes; + int gateID; double radius = fgGetDouble("/sim/dimensions/radius-m"); if ((parkpos == string("AVAILABLE")) && (radius > 0)) { - double lat, lon, heading; string fltType; string acOperator; SGPath acData; @@ -203,30 +203,27 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par } string acType; // Currently not used by findAvailable parking, so safe to leave empty. - succes = dcs->getAvailableParking(&lat, &lon, &heading, &park_index, radius, fltType, acType, acOperator); - if (succes) { + gateID = dcs->getAvailableParking(radius, fltType, acType, acOperator); + if (gateID >=0 ) { fgGetString("/sim/presets/parkpos"); - fgSetString("/sim/presets/parkpos", dcs->getParking(park_index)->getName()); + fgSetString("/sim/presets/parkpos", dcs->getParking(gateID)->getName()); } else { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to find a suitable parking at airport " << id ); return false; } } else { - //cerr << "We shouldn't get here when AVAILABLE" << endl; - while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--; - if (park_index < 0) { + gateID = dcs->findParkingByName(parkpos); + if (gateID < 0) { SG_LOG( SG_GENERAL, SG_ALERT, - "Failed to find parking position " << parkpos << - " at airport " << id ); + "Failed to find a parking at airport " << id << ":" << parkpos); return false; } } - FGParking* parking = dcs->getParking(park_index); + + FGParking* parking = dcs->getParking(gateID); parking->setAvailable(false); - fgApplyStartOffset( - SGGeod::fromDeg(parking->getLongitude(), parking->getLatitude()), - parking->getHeading()); + fgApplyStartOffset(parking->geod(), parking->getHeading()); return true; } @@ -307,10 +304,10 @@ 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 ) { - - const nav_list_type navlist - = globals->get_navlist()->findByIdentAndFreq( id.c_str(), freq, type ); +static bool fgSetPosFromNAV( const string& id, const double& freq, FGPositioned::Type type ) +{ + FGNavList::TypeFilter filter(type); + const nav_list_type navlist = FGNavList::findByIdentAndFreq( id.c_str(), freq, &filter ); if (navlist.size() == 0 ) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate NAV = " @@ -387,7 +384,7 @@ static bool fgSetPosFromCarrier( const string& carrier, const string& posid ) { static bool fgSetPosFromFix( const string& id ) { FGPositioned::TypeFilter fixFilter(FGPositioned::FIX); - FGPositioned* fix = FGPositioned::findNextWithPartialId(NULL, id, &fixFilter); + FGPositioned* fix = FGPositioned::findFirstWithIdent(id, &fixFilter); if (!fix) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to locate fix = " << id ); return false; @@ -400,7 +397,7 @@ static bool fgSetPosFromFix( const string& id ) // Set the initial position based on presets (or defaults) bool initPosition() { - // cout << "fgInitPosition()" << endl; + // cout << "initPosition()" << endl; double gs = fgGetDouble("/sim/presets/glideslope-deg") * SG_DEGREES_TO_RADIANS ; double od = fgGetDouble("/sim/presets/offset-distance-nm");