Last active
April 25, 2025 16:22
-
-
Save numberlesstim/da515adddd047f8e3af00bd05236279d to your computer and use it in GitHub Desktop.
kOS script for KSP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//FTLutils.ks | |
//pastebin: iDk9QRCc | |
//gist: da515adddd047f8e3af00bd05236279d | |
set engstate to lex(). | |
set warpengines to list(). | |
set controlstate to ship:controlpart. | |
set warpguilex to lex(). | |
set warpguistep to 0. | |
warputil on. | |
autoignition on. | |
autoTarget on. | |
warpdrive off. | |
flinging off. | |
exiting off. | |
if not (defined tar) set tar to choose target if (hastarget and target:istype("Orbitable")) else body. | |
if not (defined gBrakeRad) set gBrakeRad to 5. | |
if not (defined rSafety) set rSafety to 2.1. | |
if not (defined minFlingAngle) set minFlingAngle to 175. | |
if not (defined talt) set talt to -1. | |
if not (defined cgrey) set cgrey to "images/white50". | |
if not (defined cwhite) set cwhite to "images/white100". | |
if not (defined cred) set cred to "images/bgSolidRed". | |
if not (defined cgreen) set cgreen to "images/bgSolidGreen". | |
if not (defined cyellow) set cyellow to "images/bgSolidYellow". | |
if not (defined cblue) set cblue to "images/bgSolidBlue". | |
if not (defined brightlist) set brightlist to list(cwhite, cyellow, cgreen). | |
if not (defined colCharLex) set colCharLex to lex(cgrey, "", cwhite, "W", cred, "R", cgreen, "G", cyellow, "Y", cblue, "B"). | |
if not (defined l_width) set l_width to 110. | |
if not (defined v_width) set v_width to 110. | |
if not (defined c_width) set c_width to 15. | |
if not (defined spacing) set spacing to 15. | |
if not (defined fontsize) set fontsize to 20. | |
//if not (defined font) set font to "DejaVu Sans Mono Bold". | |
if not (defined font) set font to "Consolas Bold". | |
if not (defined helphidedelay) set helphidedelay to 300. | |
set helphidetime to 0. | |
set tspd to 10. | |
set exx to 0. | |
set exy to 0. | |
set ext to 0. | |
set exg to 1500. | |
lock minvel to choose sqrt(tar:mu/(tar:soiradius)) if tar:istype("Body") else tar:obt:velocity:orbit:mag. | |
lock maxvel to choose sqrt(tar:mu/(tar:radius*2)) if tar:istype("body") else minvel. | |
lock gBrakeAlt to body:radius * gBrakeRad. | |
lock relvel to tar:velocity:orbit - ship:velocity:orbit. | |
lock gBrakePos to body:position - relvel:normalized * gBrakeAlt. | |
lock circBd to choose tar if tar:istype("Body") else body. | |
lock circVel to choose -relvel if tar:istype("Body") else velocity:orbit.//attempting to use -relvel to fix resulting orbit being retrograde | |
lock circPos to circBd:position + vcrs(-circBd:angularvel, circVel):normalized * (circBd:mu/(circVel:mag^2)). | |
lock tarPos to tar:position - tar:position:normalized * min(max(tar:radius * rSafety, tar:soiradius/2), tar:soiradius). | |
lock manualPos to v(0,0,0). | |
lock manualRDist to vxcl(manualPos, body:position):mag/body:radius. | |
lock gBrakeRDist to vxcl(gBrakePos, body:position):mag/body:radius. | |
lock tarRDist to vxcl(tar:position, body:position):mag/body:radius. | |
lock circRDist to vxcl(circPos, body:position):mag/body:radius. | |
lock shipRAlt to body:position:mag/body:radius. | |
lock steer to facing. | |
set steerMessage to "Please lock [steer] to either gBrakePos, circPos, tarPos or manualPos, depending on what you're doing. Then base your steering lock on steer.". | |
for en in ship:engines { | |
if en:hasmodule("wbiWarpEngine") { | |
warpengines:add(en). | |
set engstate[en] to false. | |
} | |
else { | |
set engstate[en] to en:ignition. | |
en:shutdown. | |
} | |
} | |
for m in ship:modulesnamed("wbiWarpEngine") if m:hasfield("Supercharger") m:setfield("Supercharger", 200). | |
wait 0. | |
function commandCheck { | |
if (defined cf) and (defined cr) { | |
if cf:hassuffix("controlfrom") and cr:hassuffix("controlfrom") and vang(cf:facing:vector, cr:facing:vector) > minFlingAngle return true. | |
} | |
return false. | |
} | |
function flip { | |
parameter doCheck is true. | |
if doCheck and not commandCheck() { | |
print "Flip setup incomplete or incompatible.". | |
print "Please define cf and cr". | |
print "Both need to have a :controlfrom suffix and need to be pointing opposite to each other.". | |
} | |
else { | |
if ship:controlpart = cf cr:controlfrom. | |
else cf:controlfrom. | |
} | |
} | |
function orbitalSpeed { | |
parameter a is altitude. | |
parameter bd is body. | |
if a <= -bd:radius return -1. | |
return sqrt(bd:mu/(bd:radius + a)). | |
} | |
lock tarvel to orbitalSpeed(talt, tar). | |
function fling { | |
parameter initialThrottle is 1. | |
parameter cutoff is 5e-3. | |
if steer = "kill" OR (steer <> gBrakePos AND steer <> circPos AND steer <> manualPos AND steer <> tarPos) OR vang(steeringmanager:target:vector, choose steer:vector if steer:hassuffix("vector") else steer) > 1 { | |
print steerMessage. | |
return false. | |
} | |
if not commandCheck() { | |
print "Fling setup incomplete or incompatible.". | |
print "Please define cf and cr". | |
print "Both need to have a :controlfrom suffix and need to be pointing opposite to each other.". | |
} | |
else { | |
if flinging { | |
print "Already flinging". | |
} | |
else { | |
flinging on. | |
set ship:control:pilotmainthrottle to initialThrottle. | |
when vdot(facing:vector, steer) < 0 or not flinging then { | |
if flinging { | |
flip(false). | |
if ship:control:pilotmainthrottle <= cutoff { | |
set ship:control:pilotmainthrottle to 0. | |
flinging off. | |
} | |
else set ship:control:pilotmainthrottle to max(ship:control:pilotmainthrottle/2, cutoff). | |
return true. | |
} | |
set ship:control:pilotmainthrottle to 0. | |
return false. | |
} | |
} | |
} | |
} | |
function pathClear { | |
parameter path, bdl. | |
if not bdl:isType("list") set bdl to list(bdl). | |
local cleared is lex(). | |
local clipped is lex(). | |
local hit is lex(). | |
for bd in bdl { | |
local closest is vxcl(path, bd:position):mag. | |
if bd <> sun AND closest > bd:soiradius set cleared[bd:name] to closest. | |
else if closest > bd:radius * rSafety { | |
local endVec is path - bd:position. | |
//does path end before reaching bd soi? | |
if bd = sun OR vdot(endVec, bd:position) > 0 OR endVec:mag < bd:soiradius set clipped[bd:name] to closest. | |
else set cleared[bd:name] to endVec:mag. | |
} | |
else { | |
local endDist is (path - bd:position):mag. | |
//does path end before hitting bd? | |
if vdot(path - bd:position, bd:position) > 0 OR endDist < bd:radius * rSafety set hit[bd:name] to closest. | |
//does path end before reaching bd soi? | |
else if bd = sun OR endDist < bd:soiradius set clipped[bd:name] to endDist. | |
else set cleared[bd:name] to endDist. | |
} | |
} | |
if cleared:keys:length > 0 print "Path is clearing " + cleared:keys:join(", ") + ".". | |
if clipped:keys:length > 0 print "Path is clipping the soi of " + clipped:keys:join(", ") + ".". | |
if hit:keys:length > 0 print "Path is hitting " + hit:keys:join(", ") + ".". | |
return lex("cleared", cleared, "clipped", clipped, "hit", hit). | |
} | |
function autowarp { | |
parameter whereto is maxvel * 1.1. | |
parameter warplevel is 4. | |
if relvel:mag < whereto OR vang(relvel, body:position) > 50 OR (altitude > tar:altitude AND tar:body = body) OR (altitude/body:radius < rSafety AND verticalspeed < 0) { | |
print "AutoWarp conditions already met". | |
return false. | |
} | |
//this is just a precaution and may not be needed at all | |
if autoignition { | |
warpdrive off. | |
wait .15. | |
} | |
set warp to 1. | |
wait until kuniverse:timewarp:issettled. | |
set warp to warplevel. | |
when relvel:mag < whereto OR vang(relvel, body:position) > 50 OR (altitude > tar:altitude AND tar:body = body) OR (altitude/body:radius < rSafety AND verticalspeed < 0) OR warp = 0 then { | |
if warp > 0 set warp to 0. | |
} | |
} | |
function increase { | |
parameter steps is 1. | |
if warp > 0 set warp to warp + steps. | |
} | |
function decrease { | |
parameter steps is 1. | |
if warp > 0 set warp to max(0, warp - steps). | |
} | |
function quickstart { | |
parameter useRCS is true. | |
set rcs to useRCS. | |
if tar = body or tar:body = body { | |
lock steer to gBrakePos. | |
} | |
else if tar <> sun { | |
lock steer to tar:body:position. | |
} | |
else lock steer to facing:vector. | |
lock steering to choose lookdirup(steer, facing:topvector) if steer:istype("vector") else steer. | |
} | |
function engage { | |
parameter thr is 1. | |
set ship:control:pilotmainthrottle to thr. | |
} | |
function disengage { | |
set ship:control:pilotmainthrottle to 0. | |
if flinging flinging off. | |
} | |
function hold { | |
disengage(). | |
} | |
function stop { | |
disengage(). | |
} | |
function pathVecIsSafe { | |
parameter pathVec. | |
parameter bd is body. | |
//pathVec points away from bd. | |
if vang(bd:position, pathVec) > 90 return true. | |
//pathVec does not come closer than rSafety to bd at the closest point | |
if vxcl(pathVec, bd:position):mag/bd:radius > rSafety return true. | |
//pathVec does not reach closer to bd than rSafety | |
if pathVec:mag < bd:position:mag AND (bd:position - pathVec):mag/bd:radius > rSafety return true. | |
return false. | |
} | |
function help { | |
parameter what is "". | |
local found is false. | |
local lines is list(). | |
if what:contains("flip") { | |
lines:add(""). | |
lines:add("Flip: Swaps the controlpart between [cf] and [cr]. Only works if set up correctly"). | |
lines:add("Both need to have a :controlfrom suffix and need to be pointing opposite to each other"). | |
found on. | |
} | |
if what:contains("fling") { | |
lines:add(""). | |
lines:add("Fling(<initThr>, <cutoff>): Use FTL travel to reach as close as possible to whatever valid position [steer] is currently locked to"). | |
lines:add("Requires valid setup of the [cf] and [cr] controlparts: (see help("+char(34)+"flip"+char(34)+"))"). | |
lines:add("Make sure the chosen position is displayed in green to not get stuck below FTL operation altitude near the current body"). | |
lines:add("Starts with a throttle of <initThr>, then halfes it incrementally whenever passing the chosen position until reaching <cutoff> throttle"). | |
found on. | |
} | |
if what:contains("autowarp") { | |
lines:add(""). | |
lines:add("Autowarp(<whereto=maxvel*1.1>, <warplevel=4>): initiates a timewarp until one of the following conditions is met:"). | |
lines:add(" - relvel < whereto"). | |
lines:add(" - RV-Ang > 50"). | |
lines:add(" - altitude > tar:altitude (only if orbiting the same parent body)"). | |
lines:add(" - anything else stops the timewarp"). | |
lines:add("You can manipulate the warp with fnc increase(<warpsteps>) and decrease(<warpsteps>) or manually at any time, both functions containing a safety-check"). | |
found on. | |
} | |
if what:contains("engage") { | |
lines:add(""). | |
lines:add("Engage(<pilotthrottle=1>) | Disengage: Activate/Deactivate the FTL Engines manually. This sets ship:control:pilotmainthrottle to <pilotthrottle>"). | |
found on. | |
} | |
if what:contains("autoignition") { | |
lines:add(""). | |
lines:add("[Autoignition]: Automatically disables the warpdrives during warp to not waste graviolium. !Not applied for warps initiated by programs running on the same core!"). | |
found on. | |
} | |
if what:contains("autotarget") or what = "tar" { | |
lines:add(""). | |
lines:add("[Autotarget]: Automatically set tar to target, whenever it changes"). | |
found on. | |
} | |
if what:contains("warpdrive"){ | |
lines:add(""). | |
lines:add("[Warpdrive]: Enables/Disables the FTL engines. Can be overruled by [Autoignition]"). | |
found on. | |
} | |
if what:contains("warputil"){ | |
lines:add(""). | |
lines:add("[Warputil]: Set [Warputil] to 'false' to exit and reset the ships controlpart* and engine-state to whatever it was when running this program"). | |
found on. | |
} | |
if what:contains("controlpart") { | |
lines:add(""). | |
lines:add("Only parts that have the :controlfrom suffix or an event/action "+char(34)+"control from here"+char(34)+" in any of its PartModules can be reset to on exit"). | |
found on. | |
} | |
if what:contains("flinging") { | |
lines:add(""). | |
lines:add("[flinging]: This flag is used by fnc fling. Disengage can cancle a fling at any time"). | |
found on. | |
} | |
if what:contains("vel") { | |
lines:add(""). | |
lines:add("relvel: Relative velocity between ship and tar. May be wrong if [tar] and ship orbit different parent bodies"). | |
lines:add("minvel: Slowest possible speed to achieve a stable orbit around [tar] (right at the soi border)"). | |
lines:add("tarvel: Speed required for a circular orbit around [tar] at user defined [talt]"). | |
lines:add("maxvel: Fastest possible speed to achieve a circular orbit around [tar] (at a distance of [tar]:radius; faster speeds can still reach an elliptical orbit without escaping)"). | |
found on. | |
} | |
if what:contains("gBrake") { | |
lines:add(""). | |
lines:add("[gBrakeRad]: Distance from the body gBrakePos should be, measured in multitudes of body:radius (white if below, yellow if above [tar])"). | |
lines:add("[gBrakePos]: Position where gravity braking is most efficient (hopefully)"). | |
found on. | |
} | |
if what:contains("safety") or what:contains("tarRDist") { | |
lines:add(""). | |
lines:add("[rSafety]: Multitudes of body:radius used to mark [steer] positions as safe(green) or unsafe(red), measured from the closest point of the path"). | |
lines:add("FTL engines will not work if closer than 2*body:radius to body:position"). | |
found on. | |
} | |
if what:contains("circPos") { | |
lines:add(""). | |
lines:add("circPos: Position to achive a circular orbit around [tar] given the current relvel"). | |
lines:add(" Red: The path to circPos is currently passing too close to the current body"). | |
lines:add("Yellow: The path to circPos clears the current body, but may hit [tar]"). | |
lines:add(" Green: The path to circPos clears both the current body and [tar]"). | |
lines:add(""). | |
found on. | |
} | |
if what:contains("help") or what = "what" { | |
lines:add(""). | |
lines:add("Help(<what>): Attempts to print helpful words depending on <what> string you feed in"). | |
found on. | |
} | |
if what:contains("quick") or what:contains("start") { | |
lines:add(""). | |
lines:add("QuickStart(<useRCS=true>): Locks steer to gBrakePos or [tar]:body:position, steering to lookdirup(steer, facing:topvector) and sets rcs to <useRCS>"). | |
found on. | |
} | |
if what:contains("color") or what:contains("red") or what:contains("yellow") or what:contains("green") { | |
lines:add(""). | |
lines:add("Color codes:"). | |
lines:add(" Green: Safe to use"). | |
lines:add("Yellow: Use with caution, something may go wrong"). | |
lines:add(" Red: Not safe to use"). | |
found on. | |
} | |
if not found { | |
lines:add(""). | |
lines:add("Available functions of interest: help, engage, disengage, autowarp, fling, flip"). | |
lines:add("Settable variables of interest: autotarget, autoignition, warpdrive, warputil, flinging"). | |
lines:add("Usage: lock steer to one of the available positions, then base your steering-lock on steer"). | |
lines:add("Call help(<what>) for more info"). | |
} | |
local helpstring is "". | |
lines:remove(0). | |
for line in lines{ | |
set helpstring to helpstring + line + char(10). | |
} | |
set helphidetime to kuniverse:realtime + helphidedelay. | |
set warpguilex:help:style:align to "left". | |
set warpguilex:help:text to helpstring:remove(helpstring:length - 1, 1). | |
} | |
function hideHelp { | |
set helphidetime to 0. | |
} | |
lock _target to choose target if hastarget else "none". | |
on _target { | |
if warputil { | |
if autoTarget { | |
if hastarget and target:isType("Orbitable") set tar to target. | |
else { | |
print "AutoTarget failed.". | |
autotarget off. | |
warpguilex:b_autoTarget:pressed on. | |
} | |
} | |
return true. | |
} | |
} | |
on warpdrive { | |
local evGen is choose "Activate Main Power" if warpdrive else "Deactivate Main Power". | |
local evAux is choose "Activate Auxilary Power" if warpdrive else "Deactivate Auxilary Power". | |
local evEng is choose "Activate Engine" if warpdrive else "Deactivate Engine". | |
for m in ship:modulesnamed("wbiModuleGeneratorFX") { | |
if m:hasevent(evGen) m:doevent(evGen). | |
if m:hasevent(evAux) m:doevent(evAux). | |
} | |
for m in ship:modulesnamed("wbiWarpEngine") { | |
if m:hasevent(evEng) m:doevent(evEng). | |
} | |
set warpguilex:b_warpdrive:pressed to not warpdrive. | |
return warputil. | |
} | |
on warp { | |
if warputil { | |
if autoignition { | |
set warpdrive to warp = 0. | |
} | |
return true. | |
} | |
return false. | |
} | |
//gui construction | |
{ | |
wait 0. | |
set warpgui to gui(100, 100). | |
set warpgui:y to 1100. | |
set warpguilex:frame to warpgui:addVLayout(). | |
set warpguilex:base to warpguilex:frame:addHLayout(). | |
set warpguilex:main to warpguilex:base:addVLayout(). | |
//RBox: | |
set warpguilex:rbox to warpguilex:main:addHLayout(). | |
set warpguilex:leftRbox to warpguilex:rbox:addVLayout(). | |
set warpguilex:rightRbox to warpguilex:rbox:addVLayout(). | |
for l in list("Body", "Tar", "TarRAlt") { | |
set warpguilex[l + "box"] to warpguilex:leftRbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addLabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
for l in list("rSafety", "gBrakeRad", "ShipRAlt") { | |
set warpguilex[l + "box"] to warpguilex:rightRbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addlabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
//VelBox: | |
set warpguilex:spacingVelbox to warpguilex:main:addSpacing(spacing). | |
set warpguilex:velbox to warpguilex:main:addHLayout(). | |
set warpguilex:leftvelbox to warpguilex:velbox:addVLayout(). | |
set warpguilex:rightvelbox to warpguilex:velbox:addVLayout(). | |
for l in list("Maxvel", "Tarvel", "Minvel") { | |
set warpguilex[l + "box"] to warpguilex:leftvelbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addlabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
for l in list("Relvel", "Talt", "RVAngle") { | |
set warpguilex[l + "box"] to warpguilex:rightvelbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addlabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
//SteerBox: | |
set warpguilex:spacingSteerBox to warpguilex:main:addSpacing(spacing). | |
set warpguilex:titleSteerBox to warpguilex:main:addLabel("Available [Steer] locks"). | |
set warpguilex:steerbox to warpguilex:main:addHLayout(). | |
set warpguilex:leftSteerBox to warpguilex:steerbox:addVLayout(). | |
set warpguilex:rightSteerBox to warpguilex:steerbox:addVLayout(). | |
for l in list("circPos", "tarPos") { | |
set warpguilex[l + "box"] to warpguilex:leftSteerbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addlabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
for l in list("gBrakePos", "manualPos") { | |
set warpguilex[l + "box"] to warpguilex:rightSteerbox:addHLayout(). | |
set warpguilex["l_" + l] to warpguilex[l + "box"]:addlabel("l_" + l). | |
set warpguilex["c_" + l] to warpguilex[l + "box"]:addlabel(""). | |
set warpguilex["v_" + l] to warpguilex[l + "box"]:addlabel("v_" + l). | |
} | |
//vars and functions: | |
set warpguilex:spacingVarBox to warpguilex:main:addSpacing(spacing). | |
set warpguilex:titleVarBox to warpguilex:main:addLabel("settable [vars] and callable <functions>"). | |
set warpguilex:varBox to warpguilex:main:addVLayout(). | |
set warpguilex:topVarBox to warpguilex:varBox:addHLayout(). | |
set warpguilex:VarBox1 to warpguilex:topVarBox:addVLayout(). | |
set warpguilex:VarBox2 to warpguilex:topVarBox:addVLayout(). | |
set warpguilex:VarBox3 to warpguilex:topVarBox:addVLayout(). | |
for l in list("Warpdrive", "Engage", "Engaged") { | |
set warpguilex["b_" + l] to warpguilex:VarBox1:addButton(l). | |
} | |
for l in list("AutoIgnition", "Fling", "Flinging") { | |
set warpguilex["b_" + l] to warpguilex:VarBox2:addButton(l). | |
} | |
for l in list("AutoTarget", "Autowarp", "Flip") { | |
set warpguilex["b_" + l] to warpguilex:VarBox3:addButton(l). | |
} | |
set warpguilex:disengageBox to warpguilex:varBox:addHLayout(). | |
set warpguilex:b_Disengage to warpguilex:disengageBox:addButton("<DISENGAGE> | <HOLD> | <STOP>"). | |
//Help: | |
//set warpguilex:spacingHelp to warpguilex:frame:addSpacing(spacing). | |
set warpguilex:helpbox to warpguilex:frame:addVLayout(). | |
set warpguilex:help to warpguilex:helpbox:addLabel("call help(<what>) for more info"). | |
//Exit: | |
set warpguilex:spacingExit to warpguilex:main:addSpacing(spacing). | |
set warpguilex:titleExit to warpguilex:main:addButton("[Warputil] off to exit"). | |
set warpguilex:titleExit:style:bg to "". | |
set warpguilex:titleExit:style:on:textcolor to grey. | |
//Styling: | |
for key in warpguilex:keys { | |
local stl is warpguilex[key]. | |
if stl:typename <> "Spacing" { | |
set stl to stl:style. | |
set stl:fontsize to fontsize. | |
set stl:font to font. | |
set stl:wordwrap to false. | |
if key:startswith("v_") { | |
set stl:align to "left". | |
set stl:width to v_width. | |
} | |
else if key:startswith("l_") { | |
set stl:align to "right". | |
set stl:width to l_width. | |
set warpguilex[key]:text to key:replace("l_", ""). | |
} | |
else if key:startswith("b_") { | |
set stl:align to "center". | |
set warpguilex[key]:pressed to true. | |
set stl:bg to "". | |
set stl:on:textcolor to grey. | |
set stl:textcolor to green. | |
} | |
else if key:startswith("c_") { | |
set stl:align to "center". | |
set stl:bg to cgrey. | |
set stl:textcolor to white. | |
set stl:width to c_width. | |
} | |
else if key:contains("left") or key:contains("right") { | |
set stl:width to (v_width + l_width + c_width + spacing). | |
} | |
else if key:contains("title") { | |
set stl:textcolor to rgba(0.8, 0.8, 0.8, 1). | |
set stl:align to "center". | |
} | |
} | |
} | |
set warpguilex:help:style:wordwrap to true. | |
set warpguilex:help:style:align to "center". | |
//set warpguilex:help:style:textcolor to grey. | |
//set warpguilex:help:style:height to 200. | |
set warpguilex:help:style:vstretch to false. | |
for l in list("Minvel", "Maxvel", "TarRAlt") { | |
for w in warpguilex[l + "Box"]:widgets set w:style:textcolor to white. | |
} | |
//add [] to changeable vars | |
for l in list("Talt", "Tar", "rSafety", "gBrakeRad", "manualPos") { | |
local label is warpguilex["l_" + l]. | |
set label:text to "[" + label:text + "]". | |
} | |
for l in list("Warpdrive", "AutoIgnition", "AutoTarget") { | |
local button is warpguilex["b_" + l]. | |
set button:text to "[" + button:text + "]". | |
} | |
for l in list("Engage", "Fling", "Autowarp", "Flip") { | |
local button is warpguilex["b_" + l]. | |
set button:text to "<" + button:text + ">". | |
} | |
warpgui:show(). | |
wait .1. | |
set warpgui:x to -40. | |
set warpgui:y to 0. | |
} | |
//gui trigger | |
on round(time:seconds * tspd) { | |
if warputil { | |
if warpguistep = 0 { | |
local col is cwhite. | |
set col to choose cgreen if (relvel:mag >= minvel and relvel:mag <= maxvel) else choose cred if relvel:mag > maxvel else cblue. | |
//for w in warpguilex["relvelbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_relvel:style:bg to col. | |
set warpguilex:c_relvel:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_relvel:text to colCharLex[col]. | |
set col to choose cgreen if (tarvel >= minvel and tarvel <= maxvel) else cred. | |
//for w in warpguilex["Tarvelbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_tarvel:style:bg to col. | |
set warpguilex:c_tarvel:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_tarvel:text to colCharLex[col]. | |
set col to choose cgreen if vang(relvel, body:position) < 50 else choose cred if vang(relvel, body:position) >= 90 else cyellow. | |
//for w in warpguilex["RVAnglebox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_rvangle:style:bg to col. | |
set warpguilex:c_rvangle:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_rvangle:text to colCharLex[col]. | |
set col to choose cgreen if (talt > tar:radius and talt < tar:soiradius - tar:radius) else cred. | |
//for w in warpguilex["Taltbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_talt:style:bg to col. | |
set warpguilex:c_talt:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_talt:text to colCharLex[col]. | |
set col to choose cgreen if tar:body = body OR tar = body else cred. | |
//for w in warpguilex["Tarbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_tar:style:bg to col. | |
set warpguilex:c_tar:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_tar:text to colCharLex[col]. | |
set warpguilex:c_body:style:bg to col. | |
set warpguilex:c_body:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_body:text to colCharLex[col]. | |
set col to choose cwhite if gBrakeRad < tar:altitude/body:radius else cyellow. | |
//for w in warpguilex["gBrakeRadbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_gBrakeRad:style:bg to col. | |
set warpguilex:c_gBrakeRad:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_gBrakeRad:text to colCharLex[col]. | |
set col to choose cgreen if (rSafety > 2 and (body <> sun and rSafety < body:soiradius/body:radius)) else choose cyellow if body = sun else cred. | |
//for w in warpguilex["rSafetybox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_rSafety:style:bg to col. | |
set warpguilex:c_rSafety:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_rSafety:text to colCharLex[col]. | |
set col to choose cgreen if pathVecIsSafe(tar:position, body) else cred. | |
//for w in warpguilex["tarPositionbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_tarPos:style:bg to col. | |
set warpguilex:c_tarPos:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_tarPos:text to colCharLex[col]. | |
set col to choose cgreen if pathVecIsSafe(gBrakePos, body) else cred. | |
//for w in warpguilex["gBrakePosbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_gBrakePos:style:bg to col. | |
set warpguilex:c_gBrakePos:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_gBrakePos:text to colCharLex[col]. | |
set col to choose cgreen if pathVecIsSafe(manualPos, body) else cred. | |
//for w in warpguilex["manualPosbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_manualPos:style:bg to col. | |
set warpguilex:c_manualPos:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_manualPos:text to colCharLex[col]. | |
set col to cred. | |
if tar:istype("Body") { | |
local safeBody is pathVecIsSafe(circPos, body). | |
local safeTar is pathVecIsSafe(circPos, tar). | |
if safeBody set col to choose cgreen if safeTar else cyellow. | |
} | |
//for w in warpguilex["circPosbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_circPos:style:bg to col. | |
set warpguilex:c_circPos:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_circPos:text to colCharLex[col]. | |
set col to cred. | |
if shipRAlt > rSafety set col to choose cgreen if shipRAlt > rsafety * 2 else cyellow. | |
//for w in warpguilex["shipRAltbox"]:widgets set w:style:textcolor to col. | |
set warpguilex:c_shipRAlt:style:bg to col. | |
set warpguilex:c_shipRAlt:style:textcolor to choose black if brightlist:contains(col) else white. | |
set warpguilex:c_shipRAlt:text to colCharLex[col]. | |
set warpguistep to 1. | |
} | |
else if warpguistep = 1 { | |
set warpguilex:v_relvel:text to round(relvel:mag):toString(). | |
set warpguilex:v_minvel:text to ceiling(minvel):toString(). | |
set warpguilex:v_tarvel:text to round(tarvel):toString(). | |
set warpguilex:v_maxvel:text to floor(maxvel):toString(). | |
set warpguilex:v_rvangle:text to round(vang(body:position, relvel)):toString(). | |
set warpguilex:v_talt:text to talt:toString(). | |
set warpguilex:v_tar:text to tar:name. | |
set warpguilex:v_tarralt:text to round(tar:altitude/tar:body:radius, 1):toString(). | |
set warpguilex:v_shipralt:text to round(shipRAlt, 1):toString(). | |
set warpguilex:v_gbrakerad:text to gBrakeRad:toString(). | |
set warpguilex:v_rsafety:text to rSafety:toString(). | |
set warpguilex:v_tarpos:text to round(tarRDist, 1):toString(). | |
set warpguilex:v_gbrakepos:text to round(gBrakeRDist, 1):toString(). | |
set warpguilex:v_circpos:text to round(circRDist, 1):toString(). | |
set warpguilex:v_manualpos:text to round(manualRDist, 1):toString(). | |
set warpguilex:v_body:text to body:name. | |
set warpguilex:b_autoIgnition:pressed to not autoIgnition. | |
set warpguilex:b_autoTarget:pressed to not autoTarget. | |
set warpguilex:b_engage:pressed to warp > 0 or altitude < body:radius or (not warpdrive) or ship:graviolium < 0.1. | |
set warpguilex:b_autoWarp:pressed to warp > 0 or vang(body:position, relvel) > 50. | |
set warpguilex:b_engaged:pressed to not (warpdrive and ship:control:pilotmainthrottle > 0 and ship:graviolium > 0.1 and altitude > body:radius and warp = 0). | |
set warpguilex:b_flinging:pressed to not flinging. | |
set warpguilex:b_disengage:pressed to (ship:control:pilotmainthrottle = 0). | |
local commCheck is commandCheck(). | |
set warpguilex:b_fling:pressed to not commCheck. | |
set warpguilex:b_flip:pressed to not commCheck. | |
set warpguistep to 2. | |
} | |
else if warpguistep = 2 { | |
if helphidetime < kuniverse:realtime { | |
local l is warpguilex:help. | |
set l:text to "call help(<what>) for more info". | |
set l:style:align to "center". | |
} | |
else set warpguilex:help:style:height to 0. | |
set warpguistep to 0. | |
} | |
return true. | |
} | |
if exiting { | |
local deltatime is time:seconds - ext. | |
if deltatime = 0 return true. | |
set ext to time:seconds. | |
set exy to exy + deltatime * exg. | |
set warpgui:x to warpgui:x + exx * deltatime. | |
set warpgui:y to warpgui:y + exy * deltatime. | |
if warpgui:y < 1100 return true. | |
warpgui:hide(). | |
warpgui:dispose(). | |
return false. | |
} | |
exiting on. | |
set exx to (random() - 0.5) * 1000. | |
set ext to time:seconds. | |
set tspd to 50. | |
return true. | |
} | |
//killswitch | |
when not warputil then { | |
set ship:control:pilotmainthrottle to 0. | |
warpdrive off. | |
for en in ship:engines { | |
if engstate[en] en:activate. | |
else en:shutdown. | |
} | |
if controlstate:hassuffix("controlfrom") { | |
controlstate:controlfrom. | |
} | |
else { | |
for m in controlstate:modules { | |
local mod is controlstate:getmodule(m). | |
if mod:hasevent("control from here") { | |
mod:doevent("control from here"). | |
break. | |
} | |
if mod:hasaction("control from here") { | |
mod:doaction("control from here", true). | |
break. | |
} | |
} | |
print "Failed to reset to original controlpart.". | |
print "<color=white>Check controlpart!</color>". | |
} | |
warpguilex:titleExit:pressed on. | |
} | |
set warpdrive to warp = 0. | |
clearscreen. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment