Initial import

This commit is contained in:
2025-10-29 15:39:36 -07:00
commit af3c3ecdd3
38 changed files with 2308 additions and 0 deletions

208
lib/stage/able.ks Normal file
View File

@@ -0,0 +1,208 @@
@lazyglobal off.
global able is lex(
"launch", launch@,
"burn", burn@,
"orbit", do_orbit@,
"circularize", circularize@,
"yeet", yeet@,
"power_down", power_down@,
"power_up", power_up@
).
local function engine {
local early is ship:partsdubbed("ROE-AJ10Early").
local mid is ship:partsdubbed("ROE-AJ10Mid").
for eng in early {
return eng.
}
for eng in mid {
return eng.
}
}
local function ignite {
rcs on.
lock throttle to 1.0.
wait 3.
stage.
}
local function is_ablestar {
return not ship:partsdubbed("ROE-AJ10Mid"):empty.
}
local function yeet {
parameter hdg, tgt_alt.
power_down().
set warpmode to "physics".
set warp to 3.
if is_ablestar() {
wait until eta:apoapsis < 180.
} else {
wait until eta:apoapsis < 100.
}
set warp to 0.
wait until kuniverse:timewarp:issettled.
power_up().
rcs on.
local target is heading(hdg, ship:obt:trueanomaly - 180, -hdg).
lock steering to target.
if is_ablestar() {
wait until eta:apoapsis < 150.
} else {
wait until eta:apoapsis < 80.
}
lock throttle to 1.0.
wait 3.
stage.
wait until ship:obt:apoapsis > tgt_alt.
rcs off.
lock throttle to 0.0.
unlock steering.
wait 0.
}
local function do_orbit {
parameter hdg, burnout is false.
// power_down().
set warpmode to "physics".
set warp to 3.
wait until eta:apoapsis < 100.
set warp to 0.
wait until kuniverse:timewarp:issettled.
// power_up().
rcs on.
local target is heading(hdg, ship:obt:trueanomaly - 180, -hdg).
lock steering to target.
wait until eta:apoapsis < 80.
lock throttle to 1.0.
wait 3.
stage.
if burnout {
wait until engine():flameout.
} else {
wait until ship:velocity:orbit:mag > circular_vel().
}
// Fine-tune orbital speed w/ RCS fore/aft?
rcs off.
lock throttle to 0.0.
unlock steering.
wait 0.
}
local function circularize {
parameter target_ecc, max_vel_delta is 0.1.
power_down().
set warpmode to "physics".
set warp to 3.
wait until eta:apoapsis < 100.
set warp to 0.
wait until kuniverse:timewarp:issettled.
power_up().
rcs on.
lock steering to ship:prograde.
wait until eta:apoapsis < 80.
local second_burn is engine:ignition.
engine():shutdown().
lock throttle to 1.0.
wait 3.
engine():activate().
wait until ship:velocity:orbit:mag > circular_vel().
lock throttle to 0.0.
lock steering to lookdirup(ship:prograde:forevector, ship:up:forevector).
until false {
local threshold is 0.1.
local p is threshold / max_vel_delta.
local dv is circular_vel() - ship:velocity:orbit:mag.
local vert_vel is ship:verticalspeed * ship:up:forevector.
local vert_vel_d is 0.0 - vert_vel:mag.
local horz_vel_d is circular_vel() - (ship:velocity:orbit - vert_vel):mag.
local horz_factor is horz_vel_d * p.
local vert_factor is vert_vel_d * p.
if ship:obt:eccentricity < target_ecc or (abs(horz_factor) < threshold and abs(vert_factor) < threshold) {
set ship:control:fore to 0.
set ship:control:top to 0.
break.
}
set ship:control:fore to horz_factor.
set ship:control:top to vert_factor.
wait 0.
}
unlock steering.
rcs off.
wait 0.
}
local function burn {
lock steering to heading(hdg, 0, -hdg).
parameter hdg.
ignite().
wait 1.
rcs off.
set warpmode to "physics".
set warp to 3.
wait until ship:thrust = 0.
unlock steering.
unlock throttle.
set warp to 0.
wait until kuniverse:timewarp:issettled.
}
local function launch {
parameter hdg, target_alt.
local pitch_pid is pidloop(0.001, 0, 0, -90, 90, 1).
set pitch_pid:setpoint to target_alt.
local wanted_hdg is ship:facing.
lock steering to wanted_hdg.
ignite().
wait 1.
set warpmode to "physics".
set warp to 3.
until ship:thrust = 0 or ship:obt:periapsis > target_alt or eta:periapsis < eta:apoapsis {
local wanted_pitch is pitch_pid:update(time:seconds, ship:obt:apoapsis).
local neutral_pitch is ship:obt:trueanomaly / 2 - 90.
set wanted_hdg to heading(hdg, wanted_pitch, -hdg).
wait 0.
}
if ship:thrust <> 0 {
lock steering to ship:prograde.
wait until ship:thrust = 0.
}
unlock steering.
unlock throttle.
rcs off.
set warp to 0.
wait until kuniverse:timewarp:issettled.
}
local function power_down {
local avionics is ship:partsdubbed("able-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("shutdown avionics", true).
}
local function power_up {
local avionics is ship:partsdubbed("able-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("activate avionics", true).
}

85
lib/stage/agena.ks Normal file
View File

@@ -0,0 +1,85 @@
@lazyglobal off.
runoncepath("0:/lib/common.ks").
global agena is lex(
"orbit", do_orbit@,
"power_down", power_down@,
"power_up", power_up@,
"low_power", low_power@,
"separate", separate@,
"transfer_burn", transfer_burn@
).
local function do_orbit {
parameter hdg.
print "Agena startup".
print "Warping to burn".
set warpmode to "physics".
set warp to 3.
wait until eta:apoapsis < 140.
set warp to 0.
wait until kuniverse:timewarp:issettled.
print "RCS On. Locking heading".
rcs on.
local target is heading(hdg, ship:obt:trueanomaly - 180, -hdg).
lock steering to target.
wait until eta:apoapsis < 120.
print "Throttle up".
lock throttle to 1.0.
wait 3.
stage.
print "GO GO GO".
wait until ship:velocity:orbit:mag > circular_vel() and ship:obt:periapsis > 140000.
rcs off.
lock throttle to 0.0.
unlock steering.
wait 0.
print "Agena done".
}
local function power_down {
local avionics is ship:partsdubbed("agena-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("shutdown avionics", true).
}
local function power_up {
local avionics is ship:partsdubbed("agena-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("activate avionics", true).
}
local function low_power {
local avionics is ship:partsdubbed("agena-avionics")[0].
local power is avionics:resources[0].
return power:amount / power:capacity < 0.1.
}
local function separate {
rcs on.
lock steering to prograde.
lock throttle to 1.0.
wait 5.
lock throttle to 0.0.
unlock steering.
rcs off.
}
local function transfer_burn {
parameter target_vel.
// Shutdown engine for ullage
local engine is ship:partsdubbed("ROE-Agena")[0].
engine:shutdown().
lock throttle to 1.0.
wait 3.
// Engine on
engine:activate().
wait until ship:velocity:orbit:mag >= target_vel.
lock throttle to 0.0.
wait 0.
}

102
lib/stage/atlas.ks Normal file
View File

@@ -0,0 +1,102 @@
@lazyglobal off.
runoncepath("0:/lib/common.ks").
global atlas is lex(
"launch", launch@
).
local function launch {
parameter hdg, target_ap, target_pitch is 6.
lock throttle to 1.0.
local engine is ship:partsdubbed("ROE-LR89.2")[0].
stage.
wait until stage:ready.
wait until engine:thrust > (engine:maxthrust * 0.9).
stage.
local booster_drop is time:seconds + 160.
local target_vel is 150.
lock steering to heading(hdg, 90 - min(target_pitch, target_pitch * (ship:velocity:surface:mag / target_vel)), -hdg).
wait until ship:velocity:surface:mag > target_vel.
print "Heading stable, switching to gravity turn".
set warpmode to "physics".
set warp to 3.
lock steering to lookdirup(ship:srfprograde:forevector, ship:up:forevector).
wait until time:seconds > booster_drop.
set warp to 0.
wait until kuniverse:timewarp:issettled.
stage.
wait 2.
set warp to 3.
wait until ship:altitude > 100000.
print "Dropping Fairings".
if not ship:partsdubbed("SSTUHollowRing"):empty {
set warp to 0.
wait until kuniverse:timewarp:issettled.
print "Dropping Fairings".
stage.
wait 2.
set warp to 3.
}
print "Switching to target PE mode".
lock steering to insert_orbit_pe(hdg, target_ap).
wait until ship:thrust = 0.
unlock steering.
lock throttle to 0.0.
set warp to 0.
wait until kuniverse:timewarp:issettled.
}
local function drawvec {
parameter vec, color, desc.
local origin is ship:position.
return vecdraw(origin, origin + vec:normalized, color, desc, 5.0, TRUE, 0.2, TRUE, FALSE).
}
local function insert_orbit_pe {
parameter azimuth, target_ap.
//clearvecdraws().
local ap_hdg is ap_prograde().
local origin is ship:position.
//drawvec(ship:facing:forevector, RGB(0, 1, 0), "Ship Facing").
//drawvec(ap_hdg:forevector, RGB(1, 1, 0), "AP Prograde").
local ap_delta is ship:orbit:apoapsis - target_ap.
local cur_burn_angle is mod(vang(vxcl(ship:facing:forevector, ap_hdg:starvector), ap_hdg:forevector) + 360, 360).
local ap_burn_ang is symmetric_clamp(ap_delta/3000, 90).
local target_burn_hdg is angleaxis(ap_burn_ang, ap_hdg:starvector) * ap_hdg.
//drawvec(target_burn_hdg:forevector, RGB(1, 0, 0), "Non-azimuth-corrected burn vector").
// Vector pointing exactly towards our azimuth, flat with our orbital position
local azimuth_vector is heading(azimuth, 0, 0):forevector.
//drawvec(azimuth_vector, RGB(0, 1, 1), "Azimuth").
// Vector pointing exactly towards AP, flat with our orbital position
local steering_vector is vxcl(ship:up:forevector, target_burn_hdg:forevector).
//drawvec(steering_vector, RGB(1, 0, 1), "AP Steering Vector").
// Angle to rotate to bring our AP vector to our azimuth
local azimuth_ang is vang(steering_vector, azimuth_vector).
local azimuth_adjustment is angleaxis(-azimuth_ang, ship:up:forevector).
local azimuth_burn_hdg is azimuth_adjustment * target_burn_hdg.
//drawvec(azimuth_burn_hdg:forevector, RGB(0, 1, 0), "Azimuth-corrected burn vector").
local steering_ang is symmetric_clamp(vang(ship:facing:forevector, azimuth_burn_hdg:forevector), 10).
local steering_hdg is angleaxis(steering_ang, vcrs(ship:facing:forevector, azimuth_burn_hdg:forevector)) * ship:facing.
return steering_hdg.
}
local function symmetric_clamp {
parameter val, limit.
return min(max(val, -limit), limit).
}

172
lib/stage/centaur.ks Normal file
View File

@@ -0,0 +1,172 @@
@lazyglobal off.
runoncepath("0:/lib/common.ks").
global centaur is lex(
"orbit", do_orbit@,
"power_down", power_down@,
"power_up", power_up@,
"low_power", low_power@,
"separate", separate@,
"transfer_burn", transfer_burn@,
"burn_time", centaur_burn_time@,
"capture_burn", capture_burn@
).
local function do_orbit {
parameter hdg, target_ecc is 0.002, max_vel_delta is 0.1.
print "Centaur startup".
local dv is circularization_dv().
local circularization_time is centaur_burn_time(dv).
local half_circularization_time is centaur_burn_time(dv / 2).
print "Circularization is " + dv + "m/s over " + circularization_time + "s".
print "Will burn " + half_circularization_time + "s before AP".
local ignition_time is half_circularization_time.
local ullage_time is ignition_time + 3.
local steering_time is ullage_time + 20.
print "Warping to burn".
set warpmode to "physics".
set warp to 3.
wait until eta:apoapsis < steering_time.
set warp to 0.
wait 1.
wait until kuniverse:timewarp:issettled.
print "RCS On. Locking heading".
rcs on.
local target is heading(hdg, ship:obt:trueanomaly - 180, -hdg).
lock steering to target.
wait until eta:apoapsis < ullage_time.
print "Throttle up".
lock throttle to 1.0.
wait until eta:apoapsis < ignition_time.
stage.
print "GO GO GO".
wait until ship:velocity:orbit:mag > circular_vel() and ship:obt:periapsis > 140000.
lock throttle to 0.0.
lock steering to lookdirup(ship:prograde:forevector, ship:up:forevector).
until false {
local threshold is 0.1.
local p is threshold / max_vel_delta.
local dv is circular_vel() - ship:velocity:orbit:mag.
local vert_vel is ship:verticalspeed * ship:up:forevector.
local vert_vel_d is 0.0 - vert_vel:mag.
local horz_vel_d is circular_vel() - (ship:velocity:orbit - vert_vel):mag.
local horz_factor is horz_vel_d * p.
local vert_factor is vert_vel_d * p.
if ship:obt:eccentricity < target_ecc or (abs(horz_factor) < threshold and abs(vert_factor) < threshold) {
set ship:control:fore to 0.
set ship:control:top to 0.
break.
}
set ship:control:fore to horz_factor.
set ship:control:top to vert_factor.
wait 0.
}
rcs off.
unlock steering.
wait 0.
print "Centaur done".
}
local function power_down {
local avionics is ship:partsdubbed("centaur-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("shutdown avionics", true).
}
local function power_up {
local avionics is ship:partsdubbed("centaur-avionics")[0].
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("activate avionics", true).
}
local function low_power {
local avionics is ship:partsdubbed("centaur-avionics")[0].
local power is avionics:resources[0].
return power:amount / power:capacity < 0.1.
}
local function separate {
rcs on.
lock steering to prograde.
lock throttle to 1.0.
wait 5.
lock throttle to 0.0.
unlock steering.
rcs off.
}
local function transfer_burn {
parameter target_ap.
// Shutdown engine for ullage
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
engine:shutdown().
lock throttle to 1.0.
wait 3.
// Engine on
engine:activate().
wait until ship:obt:apoapsis > target_ap.
lock throttle to 0.0.
wait 0.
}
local function centaur_burn_time {
parameter dv.
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
return burn_time(dv, engine).
}
local function capture_burn {
parameter threshold is 250_000.
local engine is ship:partsdubbed("ROE-RL10Fixed")[0].
engine:shutdown().
local initial_pe is ship:obt:periapsis.
wait 1.
warpto(eta:periapsis + time:seconds - 30).
wait 1.
wait until kuniverse:timewarp:warp = 0.
wait until kuniverse:timewarp:issettled.
power_up().
rcs on.
lock steering to ship:retrograde.
wait 1.
wait until steering_locked().
lock throttle to 1.
wait 3.
engine:activate().
if initial_pe > threshold {
wait until ship:obt:periapsis < (threshold/2).
lock throttle to 0.
engine:shutdown().
power_down().
unlock steering.
wait 1.
warpto(eta:periapsis + time:seconds - 30).
wait 1.
wait until kuniverse:timewarp:warp = 0.
wait until kuniverse:timewarp:issettled.
wait 1.
power_up().
lock steering to ship:retrograde.
wait 1.
wait until steering_locked().
lock throttle to 1.
wait 3.
engine:activate().
wait until ship:obt:apoapsis < (threshold*2).
} else {
wait until ship:obt:eccentricity < 1 and ship:obt:apoapsis < threshold*2.
}
engine:shutdown().
lock throttle to 0.
power_down().
wait 1.
}

72
lib/stage/probe.ks Normal file
View File

@@ -0,0 +1,72 @@
@lazyglobal off.
runoncepath("0:/lib/common.ks").
global probe is lex(
"power_down", power_down@,
"power_up", power_up@,
"capture_burn", capture_burn@
).
local function capture_burn {
parameter threshold is 250_000.
local engine is ship:partsdubbed("ROE-generic-quarter")[0].
engine:shutdown().
local initial_pe is ship:obt:periapsis.
wait 1.
warpto(eta:periapsis + time:seconds - 30).
wait 1.
wait until kuniverse:timewarp:warp = 0.
wait until kuniverse:timewarp:issettled.
power_up().
rcs on.
lock steering to ship:retrograde.
wait 1.
wait until steering_locked().
lock throttle to 1.
engine:activate().
if initial_pe > threshold {
wait until ship:obt:periapsis < (threshold/2).
lock throttle to 0.
engine:shutdown().
lock steering to sun:direction.
wait 1.
wait until steering_locked().
power_down().
unlock steering.
wait 1.
set warpmode to "rails".
warpto(eta:periapsis + time:seconds - 30).
wait 1.
wait until kuniverse:timewarp:warp = 0.
wait until kuniverse:timewarp:issettled.
wait 1.
power_up().
lock steering to ship:retrograde.
wait 1.
wait until steering_locked().
lock throttle to 1.
engine:activate().
wait until ship:obt:apoapsis < (threshold*2).
} else {
wait until ship:obt:eccentricity < 1 and ship:obt:apoapsis < threshold*2.
}
engine:shutdown().
lock throttle to 0.
power_down().
wait 1.
}
local function power_down {
local avionics is ship:rootpart.
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("shutdown avionics", true).
}
local function power_up {
local avionics is ship:rootpart.
local avi_mod is avionics:getmodule("ModuleProceduralAvionics").
avi_mod:doaction("activate avionics", true).
}

63
lib/stage/thor.ks Normal file
View File

@@ -0,0 +1,63 @@
@lazyglobal off.
global thor is lex(
"launch", launch@
).
local function launch {
parameter hdg, target_alt, target_pitch is 6, target_vel is 150.
lock throttle to 1.0.
local engine is ship:partsdubbed("ROE-LR79")[0].
local boosters is ship:partsdubbed("ROE-Castor1").
stage.
wait until stage:ready.
wait until engine:thrust > (engine:maxthrust * 0.9).
stage.
if boosters:length > 0 {
when boosters[0]:thrust < 1 then {
print "Dropping boosters".
stage.
}
}
lock steering to heading(hdg, 90 - min(target_pitch, target_pitch * (ship:velocity:surface:mag / target_vel)), -hdg).
wait until ship:velocity:surface:mag > target_vel.
// wait until steering_locked().
print "Heading stable, switching to gravity turn".
set warp to 3.
lock steering to lookdirup(ship:srfprograde:forevector, ship:up:forevector).
wait until ship:altitude > 100000.
if not ship:partsdubbed("SSTUHollowRing"):empty {
set warp to 0.
wait until kuniverse:timewarp:issettled.
print "Dropping Fairings".
stage.
wait 2.
set warp to 3.
}
// print "Switching to target AP mode".
// local pitch_pid is pidloop(0.0003, 0, 0, -90, 90, 1).
// set pitch_pid:setpoint to target_alt.
// local wanted_hdg is ship:srfprograde.
// lock steering to wanted_hdg.
//
// until ship:thrust = 0 {
// local wanted_pitch is pitch_pid:update(time:seconds, ship:obt:apoapsis).
// local neutral_pitch is ship:obt:trueanomaly / 2 - 90.
// set wanted_hdg to heading(hdg, wanted_pitch, -hdg).
// }
wait until ship:thrust = 0.
unlock steering.
lock throttle to 0.0.
set warp to 0.
wait until kuniverse:timewarp:issettled.
}

37
lib/stage/v2.ks Normal file
View File

@@ -0,0 +1,37 @@
@lazyglobal off.
runoncepath("0:/lib/common.ks").
global v2 is lex(
"launch", launch@
).
local function launch {
parameter hdg, target_pitch is 10.
lock throttle to 1.0.
local engine is 0.
// local a4 is ship:partsdubbed("ROE-A4").
local xlr41 is ship:partsdubbed("ROE-XLR41").
local naa75 is ship:partsdubbed("ROE-A7").
local engine is choose naa75[0] if xlr41:empty else xlr41[0].
stage.
wait until stage:ready.
wait until engine:thrust > (engine:maxthrust * 0.9).
stage.
print "Beginning initial pitchover".
local target_vel is 150.
lock steering to heading(hdg, 90 - min(target_pitch, target_pitch * (ship:velocity:surface:mag / target_vel)), -hdg).
wait until ship:velocity:surface:mag > target_vel.
//wait until steering_locked().
print "Heading stable, switching to gravity turn".
lock steering to lookdirup(ship:srfprograde:forevector, ship:up:forevector).
wait until ship:thrust = 0.
unlock throttle.
unlock steering.
}