kOS-scripts/util.ks

65 lines
1.5 KiB
Plaintext
Raw Normal View History

2018-07-19 14:42:03 +02:00
function warp_to {
parameter timestamp.
KUNIVERSE:TIMEWARP:WARPTO(timestamp). // TODO: improve.
// wait until TIME >= timestamp. // TODO
2018-07-19 14:42:03 +02:00
}
function warp_for {
parameter seconds.
return warp_to(TIME:SECONDS + seconds).
}
function isp_sum {
local sum is 0.
list ENGINES in engines_list.
for engine in engines_list {
if engine:STAGE = STAGE:NUMBER set sum to sum + engine:VACUUMISP.
}
return sum.
}
function round_towards_zero {
parameter n.
if n < 0 return CEILING(n).
return FLOOR(n).
}
function orbital_velocity {
// Calculate the required velocity to acheive orbit at the provided altitude.
// https://en.wikipedia.org/wiki/Orbital_speed#Mean_orbital_speed
// http://www.orbiterwiki.org/wiki/Front_Cover_Equations
parameter altitude.
return SQRT(BODY:MU / (BODY:RADIUS + altitude)). // BODY:MU = CONSTANT:G * BODY:MASS
}
function unlock_control {
// Ensure that the throttle will be 0 when execution stops
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
// Ensure that the player is not locked out of control.
set SHIP:CONTROL:NEUTRALIZE to true.
unlock STEERING.
unlock THROTTLE.
}
function disable_engine_gimbal {
// Disable engine gimbal when engine is off
on (THROTTLE = 0) {
list ENGINES in engines_list.
for engine in engines_list {
if engine:HASGIMBAL set engine:GIMBAL:LOCK to (not THROTTLE).
}
return true. // preserve trigger
}
}