Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
- lock NukeLiquid to max(0, ship:liquidfuel-liquidmatched).
- lock nukedv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (NukeLiquid * 0.005))), 5).
- lock oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
- lock vectordv to Round(315 * 9.81 * ln((ship:mass - (NukeLiquid * 0.005)) / ((ship:mass - (NukeLiquid * 0.005)) - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
- bays off. brakes off. rcs on.
- function SetEngines {
- parameter targetMode to "Activate Engine".
- parameter engines to ship:partsdubbedpattern("vector").
- for engine in engines {
- if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
- if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
- if m:hasaction(targetMode) m:doaction(targetMode, true).
- }
- }
- function ThrustLimit {
- parameter targetEngines.
- parameter targetThrust.
- for eng in targetEngines set eng:thrustlimit to targetThrust.
- }
- function SetAngle {
- parameter targetangle.
- for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
- }
- function info {
- parameter message.
- set logmessage to round(missionTime,1) + ": " + message.
- print logmessage.
- }
- copypath("0:","1:").
- for i in range(terminal:height-3) Print "":padright(terminal:width).
- set steeringmanager:rollcontrolanglerange to 180.
- set takeoffspeed to 100.
- set targetOrbitAltitude to 101e3.
- set vectors to ship:partsdubbedpattern("vector").
- set nukes to ship:partsdubbedpattern("nuc").
- set servos to ship:modulesnamed("ModuleRoboticRotationServo").
- lock p to choose 0 if airspeed < takeoffspeed else min(25,max(0,groundspeed/7.5)).
- lock steering to heading(90,p).
- SetEngines("Activate Engine", vectors).
- lock throttle to targetOrbitAltitude-apoapsis.
- lock angletarget to 0.
- when altitude > 72 then {
- gear off.
- info("engage dynamic servo").
- lock angletarget to max(0, min(90,100 - ((-verticalspeed + (80-altitude)/1.5)*100))).
- //set p to 10.
- }
- info("initialize vtols").
- lock vlimit to (-verticalspeed + (80-altitude))*100.
- set vlimitcopy to vlimit.
- set anglecopy to angletarget.
- when abs(vang(ship:facing:vector, heading(90,0):vector)) < 5 then {
- SetEngines("Activate Engine", ship:partsdubbedpattern("turbofan")).
- }
- until vlimit < 0 {
- set vlimitcopy to vlimit.
- set anglecopy to angletarget.
- ThrustLimit(vectors, vlimitcopy).
- SetAngle(anglecopy).
- print " v thrust: " + vlimitcopy at (0,0).
- print "servo angle: " + anglecopy at (0,1).
- print " p: " + p at (0,2).
- wait 0.
- }
- info("store vtols").
- SetEngines("Shutdown Engine", vectors).
- SetAngle(90).
- print " v thrust: " + vlimitcopy at (0,0).
- print "servo angle: " + anglecopy at (0,1).
- info("gain speed").
- lock aoa to vang(srfprograde:vector, ship:facing:vector).
- lock p to max(aoa+0.5,min(45, aoa+(airspeed-400)/5 )).
- when altitude > 8000 then {
- info("go faster").
- lock p to vang(srfprograde:vector,heading(90,0):vector).
- }
- when altitude > 8000 and p < 10 then set p to 10.
- when altitude > 14000 then {
- info("engage nukes").
- SetEngines("Activate Engine", nukes).
- set p to 15.
- }
- when altitude > 20000 then {
- info("push to orbit").
- lock p to airspeed/50.
- SetEngines("Activate Engine", vectors).
- ThrustLimit(vectors, 100).
- }
- when altitude > 20000 and p > 30 then lock p to 30.
- when ship:oxidizer < 500 then {
- info("preserve landing fuel").
- SetEngines("Shutdown Engine", vectors).
- }
- when apoapsis >= targetOrbitAltitude-5e3 then {
- info("lock surface prograde").
- lock p to vang(srfprograde:vector,heading(90,0):vector).
- }
- when altitude > 50e3 then {
- lock p to vang(prograde:vector,heading(90,0):vector).
- }
- when apoapsis >= targetOrbitAltitude then {
- info("warping to space").
- SetEngines("Shutdown Engine", ship:partsdubbedpattern("turbofan")).
- lock throttle to 0.
- set warpmode to "physics".
- set warp to 3.
- }
- when (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
- steeringManager:resettodefault().
- set warp to 0.
- wait until kuniverse:timewarp:issettled.
- set warpmode to "rails".
- info("adjusting apoapsis").
- lock throttle to choose (targetOrbitAltitude - apoapsis)/10 if apoapsis - periapsis > 10 else 0.
- }
- when apoapsis >= targetOrbitAltitude and (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
- lock throttle to 0.
- list engines in es. for e in es e:shutdown().
- SetEngines("Activate Engine", nukes).
- if(apoapsis - periapsis > 10) {
- info("need to circularize").
- set warpmode to "rails".
- set warp to 1.
- wait 1.
- warpto(time:Seconds + eta:apoapsis - 50).
- wait until eta:apoapsis < 50.
- info("circularizing").
- set circularizing to true.
- lock desiredVel to vxcl(up:vector,velocity:orbit):normalized * sqrt(body:MU/(body:Radius + altitude)).
- lock dV to desiredVel - velocity:orbit.
- lock steering to lookdirup(dV, ship:facing:topvector).
- when circularizing then {
- if vang(facing:vector,dV) > 10 {
- lock throttle to 0.
- } else {
- lock throttle to dv:mag / 2.
- }
- if dv:mag > 0.3 {
- return true.
- } else {
- info("circularize complete").
- lock throttle to 0.
- set circularizing to false.
- }
- }
- return circularizing.
- }
- }
- function landnoatmo {
- info("reducing groundspeed").
- lock steering to -velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5.
- lock throttle to choose groundspeed - 200 if abs(steeringmanager:angleerror) < 5 else 0.
- when ship:liquidfuel < (ship:oxidizer * 9 / 11) + 0.4 then
- {
- info("switching to rockets").
- list engines in es. for e in es e:shutdown().
- SetEngines("Activate Engine", vectors).
- }
- wait until groundspeed < 201.
- info("preparing final form").
- lock throttle to 0.
- list engines in es. for e in es e:shutdown().
- SetEngines("Activate Engine", vectors).
- SetAngle(0).
- rcs on.
- toggle ag10.
- brakes on.
- gear on.
- lights on.
- wait until abs(steeringmanager:angleerror) < 5.
- set complete to false.
- info("begin final landing sequence").
- lock throttle to (-verticalspeed-1)-sqrt(2*max(1,(max(0.1,vdot(up:vector,facing:vector))* availablethrust*0.9)/mass-body:mu/(body:radius^2))*max(altitude-geoposition:terrainheight-50+verticalspeed*0.5,0.1)).
- when verticalspeed>0 and alt:radar < 1000 then {
- lock throttle to 0.
- lock steering to heading(90,90).
- set complete to true.
- }
- lock steering to lookdirup(-velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5,heading(270,0):vector).
- wait until complete.
- info("welcome to mun").
- }
Add Comment
Please, Sign In to add comment