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