Skip to content

Instantly share code, notes, and snippets.

@JonnyOThan
Created December 11, 2018 15:12
Show Gist options
  • Save JonnyOThan/0064fb4caa1667e95ad5a09a5bc512f0 to your computer and use it in GitHub Desktop.
Save JonnyOThan/0064fb4caa1667e95ad5a09a5bc512f0 to your computer and use it in GitHub Desktop.
KOS mission phase manager
parameter ascent_roll is 0.
wait until ship:loaded and ship:unpacked.
if (ship:status = "PRELAUNCH") {
runpath("archive:/deploy", path(scriptpath()):name).
}
run once "logging"(1).
local mission_phases is list(
{
print "Please select a target".
wait until hastarget and target:body = body.
},
{ run launch. },
{ run ascent(ascent_roll). },
{ run finish_orbit. },
{ run plan_match_inclination.
run execute_node. },
{ run plan_mun_intercept.
run execute_node. },
{ run plan_periapsis_adjustment(target:name, 15000).
run execute_node. },
{ run plan_circularize.
run execute_node. },
{ run deorbit. },
{ run landing2. },
{ run ascent. },
{ run finish_orbit. },
{ run plan_mun_escape.
run execute_node. },
{ run reenter. }
).
run mission(mission_phases).
parameter phases.
run once "util".
run once "logging".
local persistence_file is "1:/persistence.json".
local phase_index is 0.
local persistence is lex().
function populate_persistence {
set persistence["phase_index"] to phase_index.
if hastarget {
set persistence["target_name"] to target:name.
} else {
set persistence["target_name"] to "".
}
}
if (exists(persistence_file)) {
set persistence to readjson(persistence_file).
set phase_index to persistence["phase_index"].
set target to persistence["target_name"].
}
until phase_index = phases.length {
log_debug("=== beginning phase " + phase_index + " ===").
phases[phase_index]().
set phase_index to phase_index + 1.
populate_persistence().
writejson(persistence, persistence_file).
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment