From 6be96ebf8a3a8cad0b01b73c0ea9609d4f2e11f1 Mon Sep 17 00:00:00 2001 From: annabunches Date: Sun, 29 Aug 2021 01:07:14 -0400 Subject: [PATCH] Add launchpad code for controlling pre-launch sequence with ModularLaunchpads. (this is 100% aesthetic but it's really pretty) --- boot/launchpad.ks | 10 ++++++++ lib/launch_rocket.ks | 2 ++ lib/systems.ks | 10 ++++++++ prog/launchpad.ks | 58 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 boot/launchpad.ks create mode 100644 prog/launchpad.ks diff --git a/boot/launchpad.ks b/boot/launchpad.ks new file mode 100644 index 0000000..c252859 --- /dev/null +++ b/boot/launchpad.ks @@ -0,0 +1,10 @@ +RunOncePath("0:/lib/boot"). + +parameter debug is false. + +Bootstrap( + "/boot/launchpad", + "/prog/launchpad", + List(), + debug +). diff --git a/lib/launch_rocket.ks b/lib/launch_rocket.ks index 1ee7159..c18ae2d 100644 --- a/lib/launch_rocket.ks +++ b/lib/launch_rocket.ks @@ -35,6 +35,8 @@ function Launch { parameter pitchTime is 30. parameter autoStage is true. + NoFuelResources(true). + // Configure subsystems. RCS off. SAS off. diff --git a/lib/systems.ks b/lib/systems.ks index 31561d1..d8de579 100644 --- a/lib/systems.ks +++ b/lib/systems.ks @@ -23,3 +23,13 @@ function SolarPanels { PANELS off. } } + +function NoFuelResources { + parameter enable is true. + + for part in SHIP:PartsTagged("nofuel") { + for resource in part:RESOURCES { + set resource:ENABLED to enable. + } + } +} diff --git a/prog/launchpad.ks b/prog/launchpad.ks new file mode 100644 index 0000000..d48240b --- /dev/null +++ b/prog/launchpad.ks @@ -0,0 +1,58 @@ +// 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. +// +// The launchpad object should have the "launchpad" tag. +// Fuel tanks with the "nofuel" tag will have *all* resources temporarily disabled during this +// sequence. The main ship computer must re-enable them after staging. NoFuelResources in lib/systems is ideal +// for this. + +RunOncePath("/lib/systems"). + +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 { + print "Beginning pre-launch sequence.". + NoFuelResources(false). + + // turn on generator and fuel flow + enableLaunchpadFlow(). + + lock THROTTLE to 0. + stage. + local startTime is TIME:SECONDS. + lock THROTTLE to (TIME:SECONDS-startTime)/15. + wait 15. + set SHIP:CONTROL:PILOTMAINTHROTTLE to 1.0. + unlock THROTTLE. + + print "Pre-launch sequence complete.". + iface:Hide(). + shutdown. +} + +global iface is gui(250, 300). +set iface:X to 200. +set iface:Y to 500. +local top is iface:AddVLayout(). + +local btn is top:AddButton("Pre-Launch"). +set btn:onClick to preLaunch@. +iface:Show(). +wait until false.