Created
November 30, 2016 03:43
-
-
Save t0chas/4ca4b840ab5a3239e21adc161c61e810 to your computer and use it in GitHub Desktop.
KSP kOS mod - Landing script
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
RUN ONCE surfaceLib. | |
DECLARE LOCAL runmode to 0. | |
DECLARE LOCAL impactTimeDelta to 0. | |
DECLARE LOCAL impactTimeStamp to 0. | |
DECLARE LOCAL pos to 0. | |
DECLARE LOCAL impactGeoPos to 0. | |
DECLARE LOCAL impactVel to 0. | |
DECLARE LOCAL deltaV to 0. | |
DECLARE LOCAL max_acc to 0. | |
DECLARE LOCAL burnTime to 0. | |
DECLARE LOCAL burnStart to 0. | |
DECLARE LOCAL tset to 0. | |
DECLARE LOCAL tfactor to 1. | |
clearscreen. | |
LOCK max_acc to SHIP:AVAILABLETHRUST / SHIP:MASS. | |
UNTIL runmode = -1{ | |
PRINT " land_v2 " AT (0, 0). | |
PRINT "-----------------------" AT (0, 1). | |
PRINT "runmode: " + runmode + " " AT (0, 2). | |
PRINT "-----------------------" AT (0, 3). | |
if runmode > 0 { | |
PRINT "expc terrain: " + round(impactGeoPos:TERRAINHEIGHT, 2) + " " AT (0, 4). | |
PRINT "terrain: " + round(SHIP:GEOPOSITION:TERRAINHEIGHT, 2) + " " AT (0, 5). | |
PRINT "radar: " + round(ALT:RADAR, 2) + " " AT (0, 6). | |
PRINT "-----------------------" AT (0, 7). | |
PRINT "deltaV: " + round(deltaV, 2) + " " AT (0, 8). | |
PRINT "burnTime: " + round(burnTime, 2) + " " AT (0, 9). | |
PRINT "impactTime: " + round(impactTimeStamp - TIME:SECONDS, 2) + " " AT (0,10). | |
PRINT "burnStart: " + round(burnStart - TIME:SECONDS, 2) + " " AT (0,11). | |
PRINT "throttle: " + round(tset, 2) + " " AT (0,12). | |
PRINT "-----------------------" AT (0,13). | |
PRINT "SURFACE: " + round(SHIP:VELOCITY:SURFACE:MAG, 2) + " " AT (0,14). | |
PRINT "VERTICALSPEED: " + round(SHIP:VERTICALSPEED, 2) + " " AT (0,15). | |
PRINT "-----------------------" AT (0,16). | |
} | |
if runmode = 0 {//init | |
if SHIP:STATUS <> "SUB_ORBITAL"{ | |
SET runmode to -1. | |
print "Ship not in suborbital trajectory.". | |
}else{ | |
SET runmode to 1. | |
SET impactTimeDelta to impactTime(). | |
SET impactTimeStamp to TIME:SECONDS + impactTimeDelta. | |
SET pos to POSITIONAT(SHIP, impactTimeStamp). | |
SET impactGeoPos to SHIP:BODY:GEOPOSITIONOF(pos). | |
SET impactVel to VELOCITYAT(SHIP, impactTimeStamp). | |
SET deltaV to impactVel:SURFACE:MAG. | |
SET burnTime to deltaV / max_acc. | |
SET burnTime to burnTime * 0.54. | |
SET burnStart to impactTimeStamp - burnTime. | |
GEAR off. | |
SAS off. | |
} | |
}else if runmode = 1 { | |
LOCK steering to SHIP:SRFRETROGRADE. | |
wait 1. | |
if burnStart - TIME:SECONDS < 60 | |
SET runmode to 3. | |
else | |
SET runmode to 2. | |
}else if runmode = 2 { //warp | |
if WARP = 0 | |
WARPTO(burnStart - 60). | |
if TIME:SECONDS >= burnStart -60 { | |
SET runmode to 3. | |
wait 1. | |
} | |
} else if runmode = 3 { // wait for burn | |
SET tset to 0. | |
LOCK steering to SHIP:SRFRETROGRADE. | |
wait 1. | |
LOCK throttle to tset. | |
wait 1. | |
if TIME:SECONDS >= burnStart{ | |
SET runmode to 4. | |
} | |
}else if runmode = 4 { // burn | |
if SHIP:VELOCITY:SURFACE:MAG > 30 | |
SET tfactor to 1.0. | |
else if SHIP:VELOCITY:SURFACE:MAG <= 30 AND ALT:RADAR > 100 | |
SET tfactor to 0.1. | |
else if SHIP:VELOCITY:SURFACE:MAG <= 30 AND ALT:RADAR > 30 | |
SET tfactor to 0.5. | |
if SHIP:VELOCITY:SURFACE:MAG <= 10 AND ALT:RADAR < 30 | |
SET tfactor to 0.9. | |
if SHIP:VERTICALSPEED < 0 | |
SET tset to min((SHIP:VELOCITY:SURFACE:MAG/max_acc) * tfactor, 1). | |
else | |
SET tset to 0. | |
if ALT:RADAR <= 30{ | |
//SET srfSlope to geo_normalvector(ship:GEOPOSITION, 2). | |
//LOCK steering to srfSlope. | |
GEAR ON. | |
}else{ | |
//LOCK steering to SHIP:SRFRETROGRADE. | |
} | |
if SHIP:STATUS = "LANDED" | |
SET runmode to 5. | |
}else if runmode = 5 { | |
SET runmode to -1. | |
SET tset to 0. | |
SAS ON. | |
} | |
} | |
unlock steering. | |
unlock throttle. | |
wait 1. | |
//set throttle to 0 just in case. | |
SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0. |
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
function impactTime{ | |
DECLARE LOCAL pos to 0. | |
DECLARE LOCAL geoPos to 0. | |
DECLARE LOCAL altAtpos to 0. | |
FROM {local i is round(ETA:PERIAPSIS).} UNTIL i = 0 STEP {set i to i-1.} DO { | |
SET pos to POSITIONAT(SHIP, TIME:SECONDS + i). | |
SET geoPos to SHIP:BODY:GEOPOSITIONOF(pos). | |
SET altAtpos to SHIP:BODY:ALTITUDEOF(pos). | |
//print "seconds to PE: " + i + "; geoPos:TERRAINHEIGHT: " + geoPos:TERRAINHEIGHT + "; ALTITUDEOF: " + altAtpos. | |
if geoPos:TERRAINHEIGHT <= altAtpos { | |
return i. | |
} | |
} | |
//print "impact at:" + impactTime + "; geoPos:TERRAINHEIGHT: " + geoPos:TERRAINHEIGHT + "; ALTITUDEOF: " + altAtpos. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment