]> git.mxchange.org Git - flightgear.git/commitdiff
Fix crash starting at heliport.
authorJames Turner <zakalawe@mac.com>
Tue, 5 Mar 2013 13:19:10 +0000 (13:19 +0000)
committerJames Turner <zakalawe@mac.com>
Tue, 5 Mar 2013 13:19:10 +0000 (13:19 +0000)
Don't assume FGAirports have runways, they might only have helipads.

src/ATC/atc_mgr.cxx
src/Main/positioninit.cxx

index 980e9df802e30c654b992b4db1480799a23387c6..4326af82a5b009e262a08d423b41e9ba56ed58e5 100644 (file)
@@ -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;
      }
index eb35799679e013dc0a09cf7a90642fe982603245..0c148d6d6d88abaeee0c271d0a7f1f575008d8b7 100644 (file)
@@ -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;
 }