View difference between Paste ID: xhJfVAAq and rXf7M65y
SHOW: | | - or go back to the newest paste.
1-
switch to 3.
1+
2
set initialliquidfuel to ship:liquidfuel.
3
lock ralt to altitude - ship:geoposition:terrainheight.
4
set servos to ship:modulesnamed("ModuleRoboticRotationServo"). 
5
set vectors to ship:partsdubbedpattern("vector").
6
set turbos to ship:partsdubbedpattern("turbofan").
7
set nukes to ship:partsdubbedpattern("nuc").
8
lock twr to ship:availablethrust/ship:mass/body:mu*body:position:sqrmagnitude.
9
for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
10
set props to false.
11
set proprad to 5.8.
12
set showreadout to true.
13
set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
14
set rotors to list().
15
for rm in rotormods {
16
    local rotor to lexicon().
17
    if(rm:getfield("motor") <> "Unpowered")
18
    {
19
        set rotor["part"] to rm:part.
20
        set rotor["mod"] to rm.
21
 
22
        set rotor["blades"] to list().
23
        for bm in rm:part:ModulesNamed("ModuleControlSurface") {
24
            local bpart to bm:part.
25
 
26
            local blade to lexicon().
27
            set blade["mod"] to bm.        
28
            set blade["offset"] to vdot(-bpart:Facing:starvector, bpart:position - bpart:parent:position).
29
            set blade["proprad"] to proprad.
30
 
31
            bm:setfield("deploy", true). 
32
 
33
            rotor["blades"]:add(blade).
34
        }
35
 
36
        rotors:add(rotor).
37
        if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 0).
38
    }
39
}
40
41
42
function displayDV {
43
    
44
    set liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
45
    set nukeLiquid to max(0, ship:liquidfuel-liquidmatched).
46
    set oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
47
48
    set nukesfirstdv   to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (nukeLiquid * 0.005))), 5).
49
    set vectorsfirstdv to Round(315 * 9.81 * ln(ship:mass / (ship:mass - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
50
51
    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).
52
    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).
53
54
55
    for res in ship:resources {
56
        if res:name = "liquidfuel" 
57
            set lqcap to res:capacity. 
58
        if res:name = "oxidizer"
59
            set oxcap to res:capacity.
60
    }
61
    set oxmass to oxcap  * 0.005.
62
    set lqmatchmass to oxcap * 9 / 11 * 0.005.
63
64
    set nukesmaxdv to Round(800 * 9.81 * ln((ship:drymass + (lqcap * 0.005) ) / ship:drymass), 5).
65
    set vectormaxdv to Round(315 * 9.81 * ln((ship:drymass + lqmatchmass + oxmass ) / ship:drymass), 5).
66
 
67
    set justnukesdv   to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (ship:liquidfuel * 0.005))), 5).
68
69
70
    info("        nukes only: " + justnukesdv).
71
    info("").
72
    info("     vectors first: " + vectorsfirstdv).
73
    info("        nukes last: " + nukeslastdv).
74
    info("").
75
    info("       nukes first: " + nukesfirstdv).
76
    info("      vectors last: " + vectorlastdv).
77
    info("").
78
    info("nukes then vectors: " + (nukesfirstdv + vectorlastdv)).
79
80
}
81
82
function ThrustLimit {
83
    parameter targetEngines.
84
    parameter targetThrust.
85
    for eng in targetEngines set eng:thrustlimit to targetThrust.
86
}
87
88
function SetAngle {
89
    parameter targetangle.
90
    for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
91
}
92
93
function info {
94
    parameter message.
95
    print char(7).
96
    set logmessage to round(missionTime,1):ToString():padleft(6) + ": " + message.
97
    print logmessage.
98
}
99
function SetEngines {
100
    parameter targetMode to "Activate Engine".
101
    parameter engines to ship:partsdubbedpattern("vector").
102
    for engine in engines {
103
        if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
104
        if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
105
        if m:hasaction(targetMode) m:doaction(targetMode, true).
106
    }
107
}
108
function shutoff {
109
	parameter engines to ship:partsdubbedpattern("vector").
110
	SetEngines("Shutdown Engine", engines).
111
}
112
113
function startup {
114
	parameter engines to ship:partsdubbedpattern("vector").
115
	SetEngines("Activate Engine", engines).
116
}
117
118
function ImaJet {
119
	parameter resetengines is true.
120
	props off.
121
    ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom(). 
122
    if resetengines shutoff(ship:engines).
123
    startup(turbos). 
124
}
125
126
function ImtheRedBaron {
127
	parameter resetengines is true.
128
    if resetengines shutoff(ship:engines).
129
    ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom(). 
130
	for rotor in rotors {
131
		if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 100).
132
		if rotor:part:parent:name:contains("bay") {
133
			set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric"). 
134
			if baymod:hasevent("open") baymod:doevent("open"). 	
135
		}
136
	}
137
	set props to true.
138
139
    lock rpmtarget to min(459,max(0, throttle * 460)).
140
    
141
    set props to true.
142
    for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("activate fusion power") m:doevent("activate fusion power").
143
    
144
    on round(time:seconds * 20) {
145
        if props {
146
            set rpmcopy to rpmtarget.
147
            for rotor in rotors {
148
    
149
                rotor:mod:setfield("rpm limit", rpmcopy ). 
150
                set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * rpmcopy/60).
151
                set deploycopy to max(3, 4.5 + arctan2(airspeed, calcAirspeed)).
152
                for blade in rotor:blades {
153
                    blade:mod:setfield("deploy angle", deploycopy).    
154
                }
155
            }
156
157
        } else {
158
            for rotor in rotors {
159
                if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 0).
160
161
                if rotor:part:parent:name:contains("bay") {
162
                    set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric"). 
163
                    if baymod:hasevent("close") baymod:doevent("close"). 	
164
                }
165
            }
166
            for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("deactivate fusion power") m:doevent("deactivate fusion power").
167
        }
168
        return props.
169
    }
170
171
172
}
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
thrustlimit(ship:engines, 100).
198
for a in ship:modulesnamed("modulefueljettison") a:doevent("jettison tank contents").
199
set autoVectoring to true.
200
set mountainclearcutoff to 1000.
201
202
lock srfp to 90-vang(srfprograde:vector,up:vector). 
203
204
ship:partsdubbedpattern("cockpit")[0]:controlfrom().
205
for zztop in ship:partsdubbedpattern("ShuttleElevon") zztop:getmodule("modulecontrolsurface"):setfield("deploy",false).
206
207
208
set groundaltitude to altitude.
209
set runwayheight to round(altitude + 15).
210
lock x to 90.
211
lock b to 0.
212
lock p to 5.
213
lock aoa to arcsin(srfprograde:topvector*facing:vector).
214-
lock p to 22.
214+
setangle(10). 
215
gear on.
216-
info("preparing for takeoff at runway height of " + runwayheight).
216+
wait 10.
217
brakes off.
218-
set angleup to false.
218+
lock steering to heading(x,p).
219
220-
lights on.
220+
221
lock throttle to (8-airspeed)/6.
222-
startup(vectors).
222+
when altitude > 200 then {
223-
setangle(0). 
223+
224
}
225-
wait 4.
225+
226-
gear off.
226+
info("Switch to boosted plane flight").
227-
wait 3.
227+
for vec in vectors set vec:gimbal:limit to 2.
228-
info("hold position").
228+
ImaJet(false).
229-
set steeringmanager:rollcontrolanglerange to 180.
229+
ImtheRedBaron(false).
230-
lock steering to heading(90,4).
230+
231-
rcs on.
231+
info("engage dynamic servo with push"). 
232-
lock angletarget to arcsin(up:vector*facing:vector).
232+
when vang(heading(90,5):vector,ship:facing:vector) < 5 then {
233-
lock throttle to (111e3-apoapsis)/1000.
233+
	lock throttle to 1.
234-
wait 0.
234+
235-
when altitude > groundaltitude + 6 then {
235+
236-
    info("rotate").
236+
when airspeed > 35 then {startup(vectors). set p to 22.}
237
238-
    brakes off.  
238+
239-
    lock steering to heading(x,p,-b).
239+
240-
    set angleup to true.
240+
241
    shutoff(vectors).
242
    ThrustLimit(vectors, 100).
243-
when angleup and abs(steeringManager:angleerror) < 4 then {
243+
244
}
245-
    info("Switch to boosted plane flight").
245+
246-
    for vec in vectors set vec:gimbal:limit to 2.
246+
247-
    ImaJet(false).
247+
248-
    ImtheRedBaron(false).
248+
249
250
251-
    info("Add vector push"). 
251+
252-
    lock angletarget to arcsin(up:vector*facing:vector)+30. 	
252+
253
    lock p to max(12,srfp).
254
}
255-
info("initialize vtols"). 
255+
256-
set anglecopy to angletarget.
256+
257
when altitude > 3000 then {
258-
info("engage dynamic servo"). 
258+
259-
when true then { 
259+
260
    lock throttle to 1. 
261-
    set anglecopy to angletarget.             
261+
262-
    SetAngle(anglecopy). 
262+
263
264-
    return autoVectoring. 
264+
265
    info("Props Off").
266
    set props to false. 
267
}
268
 
269
270
when airspeed > 1200 then {
271-
    autoVectoring off.
271+
272-
    wait 1.
272+
273
when altitude > 14000 then {
274
    info("engage nukes").
275
    startup(nukes).
276
}
277
 
278
 
279
when (airspeed > 1200 and altitude > 20e3) or (airspeed > 1000 and verticalspeed < 10) then {
280
    info("push to orbit").
281
    SetAngle(90).
282
    lock p to 17.
283
    startup(vectors).
284
    ThrustLimit(vectors, 100).
285
}
286
287
when apoapsis > 100e3 then {
288
    info("lock to prograde").
289
    lock steering to prograde.
290-
    lock throttle to 1.    
290+
291-
    autoVectoring off.
291+
292-
    thrustlimit(ship:engines, 100).
292+
when altitude > body:atm:height and apoapsis > 80e3 then {
293
    info("limit throttle for circularize").
294
    set warpmode to "rails".
295
    warpto(time:Seconds + eta:apoapsis - 60).
296
    lock throttle to choose 1 if eta:apoapsis > obt:period / 2 else 50-eta:apoapsis.
297
}
298
299
300-
    steeringmanager:resetpids().
300+
301
    info("peri over atm").
302
    lock throttle to 0. 
303
    lock steering to "kill".
304
    displayDV().
305
    set filename to "SuderraOrbitStandalone".
306-
    set p to p + 1.
306+
    set filename to filename + ".L" + round(initialliquidfuel):tostring(). 
307
    set filename to filename + ".O" + round(initialoxidizer):tostring(). 
308
    set filename to filename + ".Ndv" + round(justnukesdv):tostring(). 
309
310
    copypath("0:/SuderraOrbitStandalone.ks",filename + ".ks").
311
}
312
313
314
315
316
317-
    lock p to 18.
317+
318
319
320
321
322
set sgfirst to 0.
323
set sgp to 0.
324
set sggo to true.
325
set sgf to 8.
326
set sgpr to 4.
327-
when altitude > body:atm:height and apoapsis > 110e3 then {
327+
328
329
function sgd {
330-
	wait 0.
330+
331-
	print "hey circularize" + char(7).
331+
332
    set dstring to d:tostring().
333
    if d:typename = "Scalar" set dstring to round(d,2):tostring().
334
335
    print (l:padleft(sgpr) + ": " + dstring):padright(terminal:width) at (0, sgp).
336
    set sgp to sgp + 1.
337
}.
338
339
set sgDisplayItems["p"] to { return p. }.
340
set sgDisplayItems["runwayheight"] to { return runwayheight. }.
341
set sgDisplayItems["twr"] to { return twr. }.
342
set sgDisplayItems["status"] to { return ship:status. }.
343
set sgDisplayItems["apoapsis"] to { return apoapsis. }.
344
set sgDisplayItems["periapsis"] to { return periapsis. }.
345
346
On round(kuniverse:realtime * sgf) {
347
    set sgp to sgfirst.
348
349
    for key in sgDisplayItems:keys {
350
351
        sgd(key,sgDisplayItems[key]()).
352
    }
353
354
    Print "":padright(terminal:width) at (0,sgp).
355
    return sggo.
356
}
357