Advertisement
sumguytwitches

SG Hathi II to Orbit

Jul 27th, 2023 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function info {
  2. parameter message.
  3. print char(7).
  4. set logmessage to round(missionTime,1):tostring():padleft(5) + ": " + message.
  5. print logmessage.
  6. }
  7.  
  8.  
  9. for i in range(terminal:height-3) Print "":padright(terminal:width).
  10.  
  11. //Variables
  12. set x to 90.
  13. lock p to choose 0 if airspeed < takeoffspeed else min(60,max(0,groundspeed/5)).
  14. set takeoffspeed to 125.
  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. lock vlimit to max(0,(-verticalspeed + (runwayaltradar-shipbounds:bottomaltradar))*100).
  20. set vlimitcopy to vlimit.
  21. set anglecopy to angletarget.
  22. lock aoa to vang(srfprograde:vector, ship:facing:vector).
  23. set maxCircEta to 50.
  24. set chaseSpeed to 350.
  25. set turboSpeed to 300.
  26. set autoVectoring to true.
  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. gear off.
  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. set minheight to shipbounds:bottomaltradar.
  39. }
  40.  
  41. when true then {
  42. if(shipbounds:bottomaltradar < minheight) set minheight to shipbounds:bottomaltradar.
  43. set vlimitcopy to vlimit.
  44. set anglecopy to angletarget.
  45. ThrustLimit(vectors, vlimitcopy).
  46. SetAngle(anglecopy).
  47. return autoVectoring.
  48. }
  49.  
  50. when airspeed > takeoffspeed then {
  51. info("Vector Power Climb").
  52. lock vlimit to 100.
  53. lock p to 60.
  54. }
  55.  
  56. when apoapsis > 1000 then {
  57. info("will clear mountain, locking to surface prograde").
  58. lock p to max(10,vang(srfprograde:vector,heading(90,0):vector)).
  59. }
  60.  
  61. when airspeed > turboSpeed then {
  62. info("Resume Airbreathing Flight").
  63. shutoff(vectors).
  64. set vlimit to 100.
  65. set angletarget to 90.
  66.  
  67. autoVectoring off.
  68. }
  69.  
  70.  
  71. when altitude > 14000 then {
  72. info("engage nukes").
  73. startup(nukes).
  74. lock p to 15.
  75. }
  76.  
  77. when altitude > 20000 then {
  78. info("push to orbit").
  79. lock p to min(35,airspeed/50).
  80. startup(vectors).
  81. ThrustLimit(vectors, 100).
  82. }
  83.  
  84. when apoapsis >= targetOrbitAltitude-5e3 then {
  85. info("locking to surface prograde").
  86. lock p to vang(srfprograde:vector,heading(90,0):vector).
  87. }
  88.  
  89. when ship:oxidizer < 3750 then {
  90. info("preserve landing fuel").
  91. shutoff(vectors).
  92. }
  93.  
  94. when apoapsis >= targetOrbitAltitude then {
  95. info("warping to space").
  96.  
  97. shutoff(turbos).
  98.  
  99. lock throttle to 0.
  100. set warpmode to "physics".
  101. set warp to 3.
  102. }
  103.  
  104. when (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
  105.  
  106. steeringManager:resettodefault().
  107. set warp to 0.
  108. wait until kuniverse:timewarp:issettled.
  109. set warpmode to "rails".
  110. info("adjusting apoapsis").
  111. lock throttle to 1.
  112. }
  113.  
  114.  
  115. when apoapsis >= targetOrbitAltitude and (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
  116. info("prep for circularization").
  117. set warp to 0.
  118. lock throttle to 0.
  119. shutoff(turbos).
  120. shutoff(vectors).
  121. startup(nukes).
  122.  
  123. lock throttle to periapsis < body:atm:height.
  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. 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. if dv:mag > 0.3 {
  145. return true.
  146. } else {
  147. info("circularize complete").
  148. lock throttle to 0.
  149. set circularizing to false.
  150. rcs off.
  151.  
  152. info("Final Stats: ").
  153. info("apoapsis " + apoapsis).
  154. info("periapsis " + periapsis).
  155. info("liquidfuel " + ship:liquidfuel).
  156. info("oxidizer" + ship:oxidizer).
  157. }
  158. return circularizing.
  159. }
  160.  
  161. //Settings
  162. set steeringmanager:rollcontrolanglerange to 180.
  163.  
  164. //Flight
  165. bays off.
  166. brakes off.
  167. startup(vectors).
  168. startup(turbos).
  169.  
  170. lock steering to heading(x,p).
  171. lock throttle to targetOrbitAltitude-apoapsis.
  172.  
  173.  
  174.  
  175. info("non-blocking").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement