1
0
Fork 0

Csaba Halsz :

Makes it possible to start at a parking location defined in the AI/Airports/*/parking.xml files, using the parkpos command line option.
Note that the name to pass is the concatenation of the "name" and "number" fields in the xml.
This commit is contained in:
fredb 2008-02-28 21:39:25 +00:00
parent cb44d7c132
commit 482f1db990

View file

@ -824,6 +824,59 @@ static bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
return true;
}
// Set current_options lon/lat given an airport id and parkig position name
static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos ) {
if ( id.empty() )
return false;
// can't see an easy way around this const_cast at the moment
FGAirport* apt = const_cast<FGAirport*>(fgFindAirportID(id));
if (!apt) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find airport " << id );
return false;
}
FGAirportDynamics* dcs = apt->getDynamics();
if (!dcs) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find parking position " << parkpos <<
" at airport " << id );
return false;
}
int park_index = dcs->getNrOfParkings() - 1;
while (park_index >= 0 && dcs->getParkingName(park_index) != parkpos) park_index--;
if (park_index < 0) {
SG_LOG( SG_GENERAL, SG_ALERT,
"Failed to find parking position " << parkpos <<
" at airport " << id );
return false;
}
FGParking* parking = dcs->getParking(park_index);
double lat = parking->getLatitude();
double lon = parking->getLongitude();
double hdg = parking->getHeading();
// presets
fgSetDouble("/sim/presets/longitude-deg", lon );
fgSetDouble("/sim/presets/latitude-deg", lat );
fgSetDouble("/sim/presets/heading-deg", hdg );
// other code depends on the actual values being set ...
fgSetDouble("/position/longitude-deg", lon );
fgSetDouble("/position/latitude-deg", lat );
fgSetDouble("/orientation/heading-deg", hdg );
SG_LOG( SG_GENERAL, SG_INFO,
"Position for " << id << " is ("
<< lon << ", "
<< lat << ") new heading is "
<< hdg );
return true;
}
// Set current_options lon/lat given an airport id and runway number
static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy, bool rwy_req ) {
@ -1221,6 +1274,15 @@ bool fgInitPosition() {
if (hdg > 9990.0)
hdg = fgGetDouble("/environment/config/boundary/entry/wind-from-heading-deg", 270);
if ( !set_pos && !apt.empty() && !parkpos.empty() ) {
// An airport + parking position is requested
if ( fgSetPosFromAirportIDandParkpos( apt, parkpos ) ) {
// set tower position
fgSetString("/sim/tower/airport-id", apt.c_str());
set_pos = true;
}
}
if ( !set_pos && !apt.empty() && !rwy_no.empty() ) {
// An airport + runway is requested
if ( fgSetPosFromAirportIDandRwy( apt, rwy_no, rwy_req ) ) {