View difference between Paste ID: A0u1dhNC and V3bpYEja
SHOW: | | - or go back to the newest paste.
1-
lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
1+
2-
lock NukeLiquid to max(0, ship:liquidfuel-liquidmatched).
2+
3-
lock nukedv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (NukeLiquid * 0.005))), 5).
3+
    print char(7).
4
    set logmessage to round(missionTime,1):tostring():padleft(5) + ": " + message.
5-
lock oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
5+
6-
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).
6+
7
8-
bays off. brakes off. rcs on.
8+
9-
function SetEngines {
9+
10-
    parameter targetMode to "Activate Engine".
10+
11-
    parameter engines to ship:partsdubbedpattern("vector").
11+
//Variables
12-
    for engine in engines {
12+
set x to 90.
13-
        if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
13+
lock p to choose 0 if airspeed < takeoffspeed else min(60,max(0,groundspeed/5)).
14-
        if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
14+
set takeoffspeed to 125.
15-
        if m:hasaction(targetMode) m:doaction(targetMode, true).
15+
set targetOrbitAltitude to body:atm:height + 1e4.
16
lock angletarget to 0.
17
set shipbounds to ship:bounds.
18
set runwayaltradar to 4.
19-
function ThrustLimit {
19+
lock vlimit to max(0,(-verticalspeed + (runwayaltradar-shipbounds:bottomaltradar))*100).
20-
    parameter targetEngines.
20+
21-
    parameter targetThrust.
21+
22-
    for eng in targetEngines set eng:thrustlimit to targetThrust.
22+
23
set maxCircEta to 50.
24
set chaseSpeed to 350.
25-
function SetAngle {
25+
set turboSpeed to 300.
26-
    parameter targetangle.
26+
set autoVectoring to true.
27-
    for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
27+
set minheight to 0.
28
circularizing off.
29
30
//Triggers
31
when shipbounds:bottomaltradar > 0.5 and abs(steeringmanager:angleerror) < 5 then {    
32
    info("engage dynamic servo").
33-
    set logmessage to round(missionTime,1) + ": " + message.
33+
34
    lock angletarget to max(0, min(90,100 - ((-verticalspeed + (runwayaltradar-shipbounds:bottomaltradar)/1.5)*100))).
35
}
36
when shipbounds:bottomaltradar > 1 and ship:verticalspeed < 1 then {
37
    info("Capture starting height").
38-
copypath("0:","1:").
38+
    set minheight to shipbounds:bottomaltradar.
39
}
40
41
when true then {    
42
    if(shipbounds:bottomaltradar < minheight) set minheight to shipbounds:bottomaltradar.
43-
set takeoffspeed to 100.
43+
44-
set targetOrbitAltitude to 101e3.
44+
45
    ThrustLimit(vectors, vlimitcopy).
46-
set vectors to ship:partsdubbedpattern("vector").
46+
47-
set nukes to ship:partsdubbedpattern("nuc").
47+
    return autoVectoring.
48-
set servos to ship:modulesnamed("ModuleRoboticRotationServo"). 
48+
49-
lock p to choose 0 if airspeed < takeoffspeed else min(25,max(0,groundspeed/7.5)).
49+
50-
lock steering to heading(90,p).
50+
when airspeed > takeoffspeed then {
51-
wait 0.5.
51+
    info("Vector Power Climb").
52-
SetEngines("Activate Engine", vectors).
52+
    lock vlimit to 100.
53
    lock p to 60.
54
}
55-
when altitude > 72 and abs(steeringmanager:angleerror) < 5 then {
55+
56
when apoapsis > 1000 then { 
57
    info("will clear mountain, locking to surface prograde").    
58-
    lock angletarget to max(0, min(90,100 - ((-verticalspeed + (80-altitude)/1.5)*100))).
58+
    lock p to max(10,vang(srfprograde:vector,heading(90,0):vector)).
59-
    //set p to 10.
59+
60
61
when airspeed > turboSpeed then {
62-
info("initialize vtols").
62+
    info("Resume Airbreathing Flight").
63-
lock vlimit to (-verticalspeed + (80-altitude))*100.
63+
    shutoff(vectors).
64
    set vlimit to 100.
65
    set angletarget to 90.
66
    
67-
when abs(vang(ship:facing:vector, heading(90,0):vector)) < 5 then {
67+
    autoVectoring off.
68-
     SetEngines("Activate Engine", ship:partsdubbedpattern("turbofan")).
68+
69
70
71-
until vlimit < 0 {
71+
72
    info("engage nukes").
73
    startup(nukes).
74
    lock p to 15.
75
}
76-
    print "   v thrust: " + vlimitcopy at (0,0).
76+
77-
    print "servo angle: " + anglecopy at (0,1).
77+
78-
    print "          p: " + p at (0,2).
78+
79-
    wait 0.
79+
    lock p to min(35,airspeed/50).
80
    startup(vectors).
81
    ThrustLimit(vectors, 100).
82-
info("store vtols").
82+
83-
SetEngines("Shutdown Engine", vectors).
83+
84
when apoapsis >= targetOrbitAltitude-5e3 then {
85-
SetAngle(90).
85+
    info("locking to surface prograde").
86-
print "   v thrust: " + vlimitcopy at (0,0).
86+
87-
print "servo angle: " + anglecopy at (0,1).
87+
88-
info("gain speed").
88+
89
when ship:oxidizer < 3750 then {
90-
lock p to max(aoa+0.5,min(45, aoa+(airspeed-400)/5 )).
90+
91
    shutoff(vectors).
92-
when altitude > 8000 then {
92+
93-
    info("go faster").
93+
94
when apoapsis >= targetOrbitAltitude then {
95
    info("warping to space").
96-
when altitude > 8000 and p < 10 then set p to 10.
96+
97
    shutoff(turbos).
98
 
99
    lock throttle to 0.
100-
    SetEngines("Activate Engine", nukes).
100+
101-
    set p to 15.
101+
102
}
103
104
when (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
105
 
106-
    lock p to airspeed/50.
106+
107-
    SetEngines("Activate Engine", vectors).
107+
108
    wait until kuniverse:timewarp:issettled.
109
    set warpmode to "rails".
110-
when altitude > 20000 and p > 30 then lock p to 30.
110+
111
    lock throttle to 1.
112
}
113
114
115-
    SetEngines("Shutdown Engine", vectors).
115+
116
    info("prep for circularization").
117
    set warp to 0. 
118
    lock throttle to 0.    
119-
    info("lock surface prograde").
119+
    shutoff(turbos).
120
    shutoff(vectors).
121
    startup(nukes).
122
123-
when altitude > 50e3 then {
123+
    lock throttle to periapsis < body:atm:height.
124-
    lock p to vang(prograde:vector,heading(90,0):vector).
124+
    lock p to max(0,min(60,-verticalspeed)).    
125
 
126
}
127
128
when eta:apoapsis < maxCircEta and altitude > body:atm:height and apoapsis > targetOrbitAltitude then {
129
    
130-
    SetEngines("Shutdown Engine", ship:partsdubbedpattern("turbofan")).
130+
    info("Final circularization").
131
    rcs on.
132
    set circularizing to true.
133
    lock desiredVel to vxcl(up:vector,velocity:orbit):normalized * sqrt(body:MU/(body:Radius + altitude)). 
134
    lock dV to desiredVel - velocity:orbit. 
135
    lock steering to lookdirup(dV, ship:facing:topvector). 
136
}
137
138
when circularizing then { 
139
    if vang(facing:vector,dV) > 10 {
140
        lock throttle to 0. 
141
    } else { 
142
        lock throttle to dv:mag / 2. 
143
    }
144-
    lock throttle to choose (targetOrbitAltitude - apoapsis)/10 if apoapsis - periapsis > 10 else 0.
144+
    if dv:mag > 0.3 { 
145
        return true.
146
    } else {
147
        info("circularize complete"). 
148-
        
148+
        lock throttle to 0. 
149
        set circularizing to false.
150-
    list engines in es. for e in es e:shutdown().
150+
        rcs off.
151-
    SetEngines("Activate Engine", nukes).
151+
152-
    if(apoapsis - periapsis > 10) {    
152+
        info("Final Stats: ").
153-
        info("need to circularize"). 
153+
        info("apoapsis " + apoapsis).
154-
        set warpmode to "rails".   
154+
        info("periapsis " + periapsis).
155-
        set warp to 1. 
155+
        info("liquidfuel " + ship:liquidfuel).
156-
        wait 1.
156+
        info("oxidizer" + ship:oxidizer).
157-
        warpto(time:Seconds + eta:apoapsis - 50).
157+
158-
        wait until eta:apoapsis < 50.
158+
    return circularizing.
159-
        info("circularizing").
159+
} 
160-
        set circularizing to true.
160+
161-
        lock desiredVel to vxcl(up:vector,velocity:orbit):normalized * sqrt(body:MU/(body:Radius + altitude)). 
161+
//Settings
162-
        lock dV to desiredVel - velocity:orbit. 
162+
163-
        lock steering to lookdirup(dV, ship:facing:topvector). 
163+
164-
        when circularizing then { 
164+
//Flight
165-
            if vang(facing:vector,dV) > 10 {
165+
bays off. 
166-
                lock throttle to 0. 
166+
brakes off.
167-
            } else { 
167+
startup(vectors).
168-
                lock throttle to dv:mag / 2. 
168+
startup(turbos).
169-
            }
169+
170-
            if dv:mag > 0.3 { 
170+
lock steering to heading(x,p).
171-
                return true.
171+
172-
            } else {
172+
173-
                info("circularize complete"). 
173+
174-
                lock throttle to 0. 
174+
175-
                set circularizing to false.
175+
info("non-blocking").