From fce2a53fc7cf5fb8e392a5e0570ad81f24e3ab0c Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 5 Mar 2013 13:19:10 +0000 Subject: [PATCH] Fix crash starting at heliport. Don't assume FGAirports have runways, they might only have helipads. --- src/ATC/atc_mgr.cxx | 56 +++++++++++++++++++++------------------ src/Main/positioninit.cxx | 20 +++++++++++--- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 980e9df80..4326af82a 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -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; } diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index eb3579967..0c148d6d6 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -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; } -- 2.39.5