sumguytwitches

Daimon landed to orbit

Oct 16th, 2023
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set initialoxidizer to ship:oxidizer.
  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. setangle(10).
  215. gear on.
  216. wait 10.
  217. brakes off.
  218. lock steering to heading(x,p).
  219.  
  220. shutoff(ship:engines).
  221. lock throttle to (8-airspeed)/6.
  222. when altitude > 200 then {
  223. gear off.
  224. }
  225.  
  226. info("Switch to boosted plane flight").
  227. for vec in vectors set vec:gimbal:limit to 2.
  228. ImaJet(false).
  229. ImtheRedBaron(false).
  230.  
  231. info("engage dynamic servo with push").
  232. when vang(heading(90,5):vector,ship:facing:vector) < 5 then {
  233. lock throttle to 1.
  234. lock rpmtarget to 460.
  235. }
  236. when airspeed > 35 then {startup(vectors). set p to 22.}
  237.  
  238.  
  239. when airspeed > 100 then {
  240. info("storing vectors").
  241. shutoff(vectors).
  242. ThrustLimit(vectors, 100).
  243. SetAngle(90).
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. when apoapsis > mountainclearcutoff then {
  252. info("Will clear mountain").
  253. lock p to max(12,srfp).
  254. }
  255.  
  256.  
  257. when altitude > 3000 then {
  258. info("prop climb complete").
  259. startup(turbos).
  260. lock throttle to 1.
  261. }
  262.  
  263.  
  264. when airspeed > 300 then {
  265. info("Props Off").
  266. set props to false.
  267. }
  268.  
  269.  
  270. when airspeed > 1200 then {
  271. info("fast enough climb again").
  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. }
  291.  
  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. when periapsis > body:atm:height then {
  301. info("peri over atm").
  302. lock throttle to 0.
  303. lock steering to "kill".
  304. displayDV().
  305. set filename to "SuderraOrbitStandalone".
  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.  
  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. set sgDisplayItems to lex().
  328.  
  329. function sgd {
  330. parameter l. parameter d.
  331. If l:length > sgpr set sgpr to l:length.
  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.  
Add Comment
Please, Sign In to add comment