Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set initialoxidizer to ship:oxidizer.
- set initialliquidfuel to ship:liquidfuel.
- lock ralt to altitude - ship:geoposition:terrainheight.
- set servos to ship:modulesnamed("ModuleRoboticRotationServo").
- set vectors to ship:partsdubbedpattern("vector").
- set turbos to ship:partsdubbedpattern("turbofan").
- set nukes to ship:partsdubbedpattern("nuc").
- lock twr to ship:availablethrust/ship:mass/body:mu*body:position:sqrmagnitude.
- for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
- set props to false.
- set proprad to 5.8.
- set showreadout to true.
- set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
- set rotors to list().
- for rm in rotormods {
- local rotor to lexicon().
- if(rm:getfield("motor") <> "Unpowered")
- {
- set rotor["part"] to rm:part.
- set rotor["mod"] to rm.
- set rotor["blades"] to list().
- for bm in rm:part:ModulesNamed("ModuleControlSurface") {
- local bpart to bm:part.
- local blade to lexicon().
- set blade["mod"] to bm.
- set blade["offset"] to vdot(-bpart:Facing:starvector, bpart:position - bpart:parent:position).
- set blade["proprad"] to proprad.
- bm:setfield("deploy", true).
- rotor["blades"]:add(blade).
- }
- rotors:add(rotor).
- if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 0).
- }
- }
- function displayDV {
- set liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
- set nukeLiquid to max(0, ship:liquidfuel-liquidmatched).
- set oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
- set nukesfirstdv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (nukeLiquid * 0.005))), 5).
- set vectorsfirstdv to Round(315 * 9.81 * ln(ship:mass / (ship:mass - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
- set nukeslastdv to Round(800 * 9.81 * ln((ship:mass - (oxidizermatched * 0.005 + liquidmatched * 0.005)) / (ship:mass - (oxidizermatched * 0.005 + liquidmatched * 0.005) - (nukeLiquid * 0.005))), 5).
- set vectorlastdv to Round(315 * 9.81 * ln((ship:mass - (nukeLiquid * 0.005)) / (ship:mass - (liquidmatched * 0.005) - (oxidizermatched * 0.005) - (nukeLiquid * 0.005))), 5).
- for res in ship:resources {
- if res:name = "liquidfuel"
- set lqcap to res:capacity.
- if res:name = "oxidizer"
- set oxcap to res:capacity.
- }
- set oxmass to oxcap * 0.005.
- set lqmatchmass to oxcap * 9 / 11 * 0.005.
- set nukesmaxdv to Round(800 * 9.81 * ln((ship:drymass + (lqcap * 0.005) ) / ship:drymass), 5).
- set vectormaxdv to Round(315 * 9.81 * ln((ship:drymass + lqmatchmass + oxmass ) / ship:drymass), 5).
- set justnukesdv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (ship:liquidfuel * 0.005))), 5).
- info(" nukes only: " + justnukesdv).
- info("").
- info(" vectors first: " + vectorsfirstdv).
- info(" nukes last: " + nukeslastdv).
- info("").
- info(" nukes first: " + nukesfirstdv).
- info(" vectors last: " + vectorlastdv).
- info("").
- info("nukes then vectors: " + (nukesfirstdv + vectorlastdv)).
- }
- 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.
- print char(7).
- set logmessage to round(missionTime,1):ToString():padleft(6) + ": " + message.
- print logmessage.
- }
- 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 shutoff {
- parameter engines to ship:partsdubbedpattern("vector").
- SetEngines("Shutdown Engine", engines).
- }
- function startup {
- parameter engines to ship:partsdubbedpattern("vector").
- SetEngines("Activate Engine", engines).
- }
- function ImaJet {
- parameter resetengines is true.
- props off.
- ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
- if resetengines shutoff(ship:engines).
- startup(turbos).
- }
- function ImtheRedBaron {
- parameter resetengines is true.
- if resetengines shutoff(ship:engines).
- ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
- for rotor in rotors {
- if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 100).
- if rotor:part:parent:name:contains("bay") {
- set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
- if baymod:hasevent("open") baymod:doevent("open").
- }
- }
- set props to true.
- lock rpmtarget to min(459,max(0, throttle * 460)).
- set props to true.
- for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("activate fusion power") m:doevent("activate fusion power").
- on round(time:seconds * 20) {
- if props {
- set rpmcopy to rpmtarget.
- for rotor in rotors {
- rotor:mod:setfield("rpm limit", rpmcopy ).
- set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * rpmcopy/60).
- set deploycopy to max(3, 4.5 + arctan2(airspeed, calcAirspeed)).
- for blade in rotor:blades {
- blade:mod:setfield("deploy angle", deploycopy).
- }
- }
- } else {
- for rotor in rotors {
- if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 0).
- if rotor:part:parent:name:contains("bay") {
- set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
- if baymod:hasevent("close") baymod:doevent("close").
- }
- }
- for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("deactivate fusion power") m:doevent("deactivate fusion power").
- }
- return props.
- }
- }
- thrustlimit(ship:engines, 100).
- for a in ship:modulesnamed("modulefueljettison") a:doevent("jettison tank contents").
- set autoVectoring to true.
- set mountainclearcutoff to 1000.
- lock srfp to 90-vang(srfprograde:vector,up:vector).
- ship:partsdubbedpattern("cockpit")[0]:controlfrom().
- for zztop in ship:partsdubbedpattern("ShuttleElevon") zztop:getmodule("modulecontrolsurface"):setfield("deploy",false).
- set groundaltitude to altitude.
- set runwayheight to round(altitude + 15).
- lock x to 90.
- lock b to 0.
- lock p to 5.
- lock aoa to arcsin(srfprograde:topvector*facing:vector).
- setangle(10).
- gear on.
- wait 10.
- brakes off.
- lock steering to heading(x,p).
- shutoff(ship:engines).
- lock throttle to (8-airspeed)/6.
- when altitude > 200 then {
- gear off.
- }
- info("Switch to boosted plane flight").
- for vec in vectors set vec:gimbal:limit to 2.
- ImaJet(false).
- ImtheRedBaron(false).
- info("engage dynamic servo with push").
- when vang(heading(90,5):vector,ship:facing:vector) < 5 then {
- lock throttle to 1.
- lock rpmtarget to 460.
- }
- when airspeed > 35 then {startup(vectors). set p to 22.}
- when airspeed > 100 then {
- info("storing vectors").
- shutoff(vectors).
- ThrustLimit(vectors, 100).
- SetAngle(90).
- }
- when apoapsis > mountainclearcutoff then {
- info("Will clear mountain").
- lock p to max(12,srfp).
- }
- when altitude > 3000 then {
- info("prop climb complete").
- startup(turbos).
- lock throttle to 1.
- }
- when airspeed > 300 then {
- info("Props Off").
- set props to false.
- }
- when airspeed > 1200 then {
- info("fast enough climb again").
- }
- when altitude > 14000 then {
- info("engage nukes").
- startup(nukes).
- }
- when (airspeed > 1200 and altitude > 20e3) or (airspeed > 1000 and verticalspeed < 10) then {
- info("push to orbit").
- SetAngle(90).
- lock p to 17.
- startup(vectors).
- ThrustLimit(vectors, 100).
- }
- when apoapsis > 100e3 then {
- info("lock to prograde").
- lock steering to prograde.
- }
- when altitude > body:atm:height and apoapsis > 80e3 then {
- info("limit throttle for circularize").
- set warpmode to "rails".
- warpto(time:Seconds + eta:apoapsis - 60).
- lock throttle to choose 1 if eta:apoapsis > obt:period / 2 else 50-eta:apoapsis.
- }
- when periapsis > body:atm:height then {
- info("peri over atm").
- lock throttle to 0.
- lock steering to "kill".
- displayDV().
- set filename to "SuderraOrbitStandalone".
- set filename to filename + ".L" + round(initialliquidfuel):tostring().
- set filename to filename + ".O" + round(initialoxidizer):tostring().
- set filename to filename + ".Ndv" + round(justnukesdv):tostring().
- copypath("0:/SuderraOrbitStandalone.ks",filename + ".ks").
- }
- set sgfirst to 0.
- set sgp to 0.
- set sggo to true.
- set sgf to 8.
- set sgpr to 4.
- set sgDisplayItems to lex().
- function sgd {
- parameter l. parameter d.
- If l:length > sgpr set sgpr to l:length.
- set dstring to d:tostring().
- if d:typename = "Scalar" set dstring to round(d,2):tostring().
- print (l:padleft(sgpr) + ": " + dstring):padright(terminal:width) at (0, sgp).
- set sgp to sgp + 1.
- }.
- set sgDisplayItems["p"] to { return p. }.
- set sgDisplayItems["runwayheight"] to { return runwayheight. }.
- set sgDisplayItems["twr"] to { return twr. }.
- set sgDisplayItems["status"] to { return ship:status. }.
- set sgDisplayItems["apoapsis"] to { return apoapsis. }.
- set sgDisplayItems["periapsis"] to { return periapsis. }.
- On round(kuniverse:realtime * sgf) {
- set sgp to sgfirst.
- for key in sgDisplayItems:keys {
- sgd(key,sgDisplayItems[key]()).
- }
- Print "":padright(terminal:width) at (0,sgp).
- return sggo.
- }
Add Comment
Please, Sign In to add comment