Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set groundlevel to altitude.
- ship:partsdubbedpattern("cockpit")[0]:controlfrom().
- set vectors to ship:partsdubbedpattern("vector").
- set nukes to ship:partsdubbedpattern("nuc").
- set turbos to ship:partsdubbedpattern("turbofan").
- set servos to ship:modulesnamed("ModuleRoboticRotationServo").
- set proprad to 5.8.
- set x to 90.
- lock p to 1.
- //set targetapoapsis to 100e3.
- set autoVectoring to true.
- set mountainclearcutoff to 1000.
- set turboSpeed to 350.
- lock srfp to 90-vang(srfprograde:vector,up:vector).
- for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
- 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 b to bm:part.
- local blade to lexicon().
- set blade["mod"] to bm.
- set blade["offset"] to vdot(-b:Facing:starvector, b:position - b:parent:position).
- set blade["proprad"] to proprad.
- bm:setfield("deploy", true).
- bm:setfield("pitch", true).
- bm:setfield("roll", true).
- bm:setfield("yaw", true).
- rotor["blades"]:add(blade).
- }
- rotors:add(rotor).
- if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 0).
- }
- }
- function ImaRocket {
- props off.
- setangle(0).
- ship:dockingports[0]:controlfrom().
- startup(vectors).
- shutoff(nukes).
- shutoff(turbos).
- }
- function ImaRocketPlane {
- props off.
- ship:rootpart:controlfrom().
- startup(vectors).
- shutoff(turbos).
- shutoff(nukes).
- }
- function ImtheRedBaron {
- parameter resetengines is true.
- if resetengines shutoff(ship:engines).
- ship:partsdubbedpattern("cockpit")[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.
- }
- }
- 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 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.
- }
- lock currpitch to 90-vang(up:vector,ship:facing:vector).
- lock p to 15.
- set x to 90.
- lock st to heading(x,p).
- lock slide to -vdot(st:starvector, srfprograde:vector).
- lock b to max(-15, min(15, choose 0 if abs(slide) < 5 else slide )).
- gear off. brakes off.
- set airalt to groundlevel + 10.
- setangle(0).
- startup(vectors).
- set steeringmanager:Rollcontrolanglerange to 180.
- set autovectoring to true.
- gear on.
- rcs on.
- wait 5.
- // for en in ship:engines {
- // en:shutdown().
- // if en:name:contains("ssme") and vdot(en:position, ship:facing:vector) > 1 en:activate().
- // }
- startup(vectors).
- lock steering to st.
- lock throttle to periapsis < body:atm:height.
- thrustlimit(vectors, 100).
- info(status).
- on status {
- info(status).
- //gear off.
- return altitude < 1000.
- }
- when currpitch > 12 then {
- imtheredbaron(false).
- lock rpmtarget to 460.
- startup(turbos).
- //lock throttle to 1.
- }
- when altitude > groundlevel + 10 then {
- info("Retracting Gear").
- lock p to 17.
- gear off.
- steeringmanager:resetpids().
- }
- when airspeed > 50 then {
- lock steering to heading(x,p,-b).
- }
- when verticalSpeed > 3 then {
- steeringManager:resetpids().
- }
- when autoVectoring then {
- setangle(currpitch).
- set tl to max(0,min(100,(max(-verticalspeed + 2,1300-altitude))*100)).
- //thrustlimit(vectors,tl).
- for vc in vectors {
- set vc:thrustlimit to tl + 100*(choose 1 if vdot(ship:facing:vector, vc:position) > 0 else -1)*steeringmanager:pitchpid:output.
- }
- //lock ttl to (130-airspeed)/2*100.
- thrustlimit(turbos,(-verticalspeed + 5)*100).
- return autoVectoring.
- }
- when apoapsis > mountainclearcutoff then {
- info("Will clear mountain").
- lock p to max(16,srfp).
- }
- when altitude > 3000 then {
- info("prop climb complete").
- startup(turbos).
- lock throttle to 1.
- autoVectoring off.
- thrustlimit(ship:engines, 100).
- SetAngle(90).
- }
- when airspeed > 300 then {
- info("Props Off").
- set props to false.
- }
- when airspeed > turboSpeed then {
- info("Resume Airbreathing Flight").
- shutoff(vectors).
- autoVectoring off.
- }
- when altitude > 14000 then {
- info("engage nukes").
- startup(nukes).
- lock p to 18.
- }
- when altitude > 20000 then {
- info("push to orbit").
- SetAngle(90).
- lock p to min(45,airspeed/35).
- startup(vectors).
- ThrustLimit(vectors, 100).
- }
- when altitude > body:atm:height and apoapsis > 100e3 then {
- info("race to circularize").
- lock steering to heading(90,15).
- }
Add Comment
Please, Sign In to add comment