// ═══════════════════════════════════════════════════════════ // staging.ks // Utility functions related to staging and the effects of changing stages // // Usage: // basicStaging() // calcBurnTime(dvNeeded: scalar) // ═══════════════════════════════════════════════════════════ declare function basicStaging { when ship:maxThrust = 0 then { print "Staging". stage. preserve. }. } function calcBurnTime { parameter dvNeeded. local totalTime to 0. local dvRemaining to dvNeeded. local stageNum to ship:stagenum. until dvRemaining <= 0 or stageNum < 0 { local stageDv to ship:stagedeltav(stageNum):current. local stageTime to ship:stagedeltav(stageNum):duration. if stageDv <= 0 { set stageNum to stageNum - 1. } else if stageDv >= dvRemaining { set totalTime to totalTime + stageTime * (dvRemaining / stageDv). set dvRemaining to 0. } else { set totalTime to totalTime + stageTime. set dvRemaining to dvRemaining - stageDv. set stageNum to stageNum - 1. } } if dvRemaining > 0 { print "WARNING: Insufficient dV. Short by " + round(dvRemaining, 1) + " m/s.". } return totalTime. }