Fix crash starting at heliport.
Don't assume FGAirports have runways, they might only have helipads.
This commit is contained in:
parent
50c70035b3
commit
fce2a53fc7
2 changed files with 46 additions and 30 deletions
|
@ -103,28 +103,11 @@ void FGATCManager::init() {
|
|||
FGAirport *apt = FGAirport::findByIdent(airport);
|
||||
if (apt && onGround) {// && !runway.empty()) {
|
||||
FGAirportDynamics* dcs = apt->getDynamics();
|
||||
fp = new FGAIFlightPlan;
|
||||
ParkingAssignment pk(dcs->getParkingByName(parking));
|
||||
|
||||
// No valid parking location, so either at the runway or at a random location.
|
||||
if (!pk.isValid()) {
|
||||
if (!runway.empty()) {
|
||||
controller = apt->getDynamics()->getTowerController();
|
||||
int stationFreq = apt->getDynamics()->getTowerFrequency(2);
|
||||
if (stationFreq > 0)
|
||||
{
|
||||
//cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
|
||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||
}
|
||||
leg = 3;
|
||||
string fltType = "ga";
|
||||
fp->setRunway(runway);
|
||||
fp->createTakeOff(&ai_ac, false, apt, 0, fltType);
|
||||
ai_ac.setTakeOffStatus(2);
|
||||
} else {
|
||||
// We're on the ground somewhere. Handle this case later.
|
||||
}
|
||||
} else {
|
||||
if (pk.isValid()) {
|
||||
fp = new FGAIFlightPlan;
|
||||
controller = apt->getDynamics()->getStartupController();
|
||||
int stationFreq = apt->getDynamics()->getGroundFrequency(1);
|
||||
if (stationFreq > 0)
|
||||
|
@ -141,18 +124,39 @@ void FGATCManager::init() {
|
|||
string airline; // Currently used for gate selection, but a fallback mechanism will apply when not specified.
|
||||
fp->setGate(pk);
|
||||
if (!(fp->createPushBack(&ai_ac,
|
||||
false,
|
||||
apt,
|
||||
aircraftRadius,
|
||||
fltType,
|
||||
aircraftType,
|
||||
airline))) {
|
||||
false,
|
||||
apt,
|
||||
aircraftRadius,
|
||||
fltType,
|
||||
aircraftType,
|
||||
airline))) {
|
||||
controller = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (!runway.empty()) {
|
||||
controller = apt->getDynamics()->getTowerController();
|
||||
int stationFreq = apt->getDynamics()->getTowerFrequency(2);
|
||||
if (stationFreq > 0)
|
||||
{
|
||||
//cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
|
||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||
}
|
||||
fp = new FGAIFlightPlan;
|
||||
leg = 3;
|
||||
string fltType = "ga";
|
||||
fp->setRunway(runway);
|
||||
fp->createTakeOff(&ai_ac, false, apt, 0, fltType);
|
||||
ai_ac.setTakeOffStatus(2);
|
||||
} else {
|
||||
// We're on the ground somewhere. Handle this case later.
|
||||
}
|
||||
|
||||
if (fp) {
|
||||
fp->getLastWaypoint()->setName( fp->getLastWaypoint()->getName() + string("legend"));
|
||||
}
|
||||
fp->getLastWaypoint()->setName( fp->getLastWaypoint()->getName() + string("legend"));
|
||||
} else {
|
||||
controller = 0;
|
||||
}
|
||||
|
|
|
@ -151,11 +151,23 @@ static bool setPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
|
|||
|
||||
const FGAirport* apt = fgFindAirportID(id);
|
||||
if (!apt) return false;
|
||||
FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
|
||||
fgSetString("/sim/atc/runway", r->ident().c_str());
|
||||
|
||||
SGGeod startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
|
||||
fgApplyStartOffset(startPos, r->headingDeg(), tgt_hdg);
|
||||
SGGeod startPos;
|
||||
double heading = tgt_hdg;
|
||||
if (apt->type() == FGPositioned::HELIPORT) {
|
||||
if (apt->numHelipads() > 0) {
|
||||
startPos = apt->getHelipadByIndex(0)->geod();
|
||||
} else {
|
||||
startPos = apt->geod();
|
||||
}
|
||||
} else {
|
||||
FGRunway* r = apt->findBestRunwayForHeading(tgt_hdg);
|
||||
fgSetString("/sim/atc/runway", r->ident().c_str());
|
||||
startPos = r->pointOnCenterline(fgGetDouble("/sim/airport/runways/start-offset-m", 5.0));
|
||||
heading = r->headingDeg();
|
||||
}
|
||||
|
||||
fgApplyStartOffset(startPos, heading, tgt_hdg);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue