From 325510519040056f52bf7ea3d3a70de3429d778b Mon Sep 17 00:00:00 2001
From: legoboyvdlp R <legoboyvdlp@gmail.com>
Date: Tue, 21 Jul 2020 14:20:19 +0100
Subject: [PATCH] Ensure that cruise parameters are set when cloning flightplan

---
 src/Navaids/FlightPlan.cxx                        | 13 +++++++++++++
 test_suite/unit_tests/Navaids/test_flightplan.cxx |  7 ++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/Navaids/FlightPlan.cxx b/src/Navaids/FlightPlan.cxx
index cfbca542b..9573caf62 100644
--- a/src/Navaids/FlightPlan.cxx
+++ b/src/Navaids/FlightPlan.cxx
@@ -140,6 +140,19 @@ FlightPlan* FlightPlan::clone(const string& newIdent) const
   c->_arrivalChanged = false;
   c->_departureChanged = false;
 
+  // copy cruise data
+  if (_cruiseFlightLevel > 0) {
+      c->setCruiseFlightLevel(_cruiseFlightLevel);
+  } else if (_cruiseAltitudeFt > 0) {
+      c->setCruiseAltitudeFt(_cruiseAltitudeFt);
+  }
+
+  if (_cruiseAirspeedMach > 0) {
+      c->setCruiseSpeedMach(_cruiseAirspeedMach);
+  } else if (_cruiseAirspeedKnots > 0) {
+      c->setCruiseSpeedKnots(_cruiseAirspeedKnots);
+  }
+
   c->_didLoadFP = true; // set the loaded flag to give delegates a chance
 
   // copy legs
diff --git a/test_suite/unit_tests/Navaids/test_flightplan.cxx b/test_suite/unit_tests/Navaids/test_flightplan.cxx
index ae7f4b49c..fe173c66c 100644
--- a/test_suite/unit_tests/Navaids/test_flightplan.cxx
+++ b/test_suite/unit_tests/Navaids/test_flightplan.cxx
@@ -926,7 +926,10 @@ void FlightplanTests::testCloningBasic()
     FlightPlanRef fp1 = makeTestFP("EGCC", "23L", "EHAM", "24",
                                    "TNT CLN");
     fp1->setIdent("testplan");
-    
+
+    fp1->setCruiseAltitudeFt(24000);
+    fp1->setCruiseSpeedKnots(448);
+
     auto fp2 = fp1->clone("testplan2");
 
     CPPUNIT_ASSERT(fp2->ident() == "testplan2");
@@ -934,6 +937,8 @@ void FlightplanTests::testCloningBasic()
     CPPUNIT_ASSERT(fp2->departureRunway()->ident() == "23L");
     CPPUNIT_ASSERT(fp2->destinationAirport()->ident() == "EHAM");
     CPPUNIT_ASSERT(fp2->destinationRunway()->ident() == "24");
+    CPPUNIT_ASSERT_EQUAL(24000, fp2->cruiseAltitudeFt());
+    CPPUNIT_ASSERT_EQUAL(448, fp2->cruiseSpeedKnots());
 
     CPPUNIT_ASSERT_EQUAL(5, fp2->numLegs());