kOS/prog/launchpad.ks

93 lines
2.7 KiB
Plaintext

// Control code for pre-launch sequence using ModularLaunchPads.
// This enable's the launchpad's fuel feed,
// stages, spools up the engines, and then "releases control"
// to the main ship computer.
//
// *** TAGGING REQUIREMENTS ***
// The launchpad object should have the "launchpad" tag.
// The ship's main CPU (the one with launch functionality" should be tagged "shipcpu".
// Fuel tanks with the "nofuel" tag will have *all* resources temporarily disabled during the pre-launch
// sequence. The main ship computer must re-enable them after staging. NoFuelResources() in lib/systems is ideal
// for this.
// Similarly, any crossfeed-capable decouplers tagged "prelaunch" will have crossfeed ENABLED during pre-launch.
// MainCPU should, again, disable these once it stages. PreLaunchCrossfeed() in lib/systems is your friend.
RunOncePath("/lib/systems").
RunOncePath("/lib/ui").
RunOncePath("/lib/sound").
ClearGuis().
function enableLaunchpadFlow {
local lp is SHIP:PartsTagged("launchpad")[0].
// ModularLaunchpads have more than one module with the "ModuleGenerator" name, so we have to
// iterate over them all.
local i is 0.
until i >= lp:ALLMODULES:LENGTH {
local m is lp:GetModuleByIndex(i).
if m:NAME = "ModuleGenerator" {
if m:HasEvent("activate generator") { m:DoEvent("activate generator"). }
if m:HasEvent("start fueling") { m:DoEvent("start fueling"). }
}
set i to i+1.
}
}
function preLaunch {
parameter options.
print "Beginning pre-launch sequence.".
NoFuelResources(false).
PreLaunchCrossfeed(true).
// turn on generator and fuel flow
enableLaunchpadFlow().
InfoTone().
wait 2.
local duration is options["Spool-up Time"]:TEXT:ToNumber().
lock THROTTLE to 0.
stage.
local startTime is TIME:SECONDS.
lock THROTTLE to (TIME:SECONDS-startTime)/duration.
wait duration.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 1.0.
unlock THROTTLE.
print "Pre-launch sequence complete. Initiating launch.".
local msg is Lex(
"command", "launch",
"angle", options["Kick Angle"]:TEXT:ToNumber(),
"time", options["Kick Time"]:TEXT:ToNumber(),
"start", options["Kick Start"]:TEXT:ToNumber()
).
Processor("shipcpu"):CONNECTION:SendMessage(msg).
iface:Hide().
shutdown.
}
global iface is gui(250, 200).
set iface:X to 200.
set iface:Y to 500.
local top is iface:AddVLayout().
local row is iface:AddHLayout().
local stk is iface:AddStack().
MakeMenu(
stk,
MakeButton(row, "Launch Sequence"),
List(
List("Spool-up Time", "SCALAR", "15"),
List("Kick Angle", "SCALAR", "30"),
List("Kick Time", "SCALAR", "45"),
List("Kick Start", "SCALAR", "100")
),
"Execute",
preLaunch@
).
iface:Show().
wait until false.