Advertisement
sumguytwitches

Hathi IV to orbit

Aug 21st, 2023 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. function info {
  2. parameter message.
  3. print char(7).
  4. set logmessage to round(missionTime,1):tostring():padleft(6) + ": " + message.
  5. print logmessage.
  6. }
  7.  
  8. for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
  9. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("activate fusion power") m:doevent("activate fusion power").
  10. set steeringmanager:rollcontrolanglerange to 180.
  11. set proprad to 5.8.
  12. set complete to false.
  13. set chaseSpeed to 350.
  14. set turboSpeed to 300.
  15. set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
  16. set rotors to list().
  17. for rm in rotormods {
  18. local rotor to lexicon().
  19. if(rm:getfield("motor") <> "Unpowered")
  20. {
  21. set rotor["part"] to rm:part.
  22. set rotor["mod"] to rm.
  23. if rotor:part:parent:name:contains("bay") {
  24. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  25. if baymod:hasevent("open") baymod:doevent("open").
  26. }
  27.  
  28. set rotor["blades"] to list().
  29. for bm in rm:part:ModulesNamed("ModuleControlSurface") {
  30. local b to bm:part.
  31.  
  32. local blade to lexicon().
  33. set blade["mod"] to bm.
  34. set blade["offset"] to vdot(-b:Facing:starvector, b:position - b:parent:position).
  35. set blade["proprad"] to proprad.
  36.  
  37. bm:setfield("deploy", true).
  38.  
  39. rotor["blades"]:add(blade).
  40. }
  41.  
  42. rotors:add(rotor).
  43. if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 100).
  44. }
  45. }
  46. lock rpmtarget to min(459,max(0, throttle * 460)).
  47.  
  48. set props to true.
  49.  
  50. on round(time:seconds * 20) {
  51. if props {
  52. set rpmcopy to rpmtarget.
  53. for rotor in rotors {
  54.  
  55. rotor:mod:setfield("rpm limit", rpmcopy ).
  56. set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * rpmcopy/60).
  57. set deploycopy to max(3, 4.5 + arctan2(airspeed, calcAirspeed)).
  58. for blade in rotor:blades {
  59. blade:mod:setfield("deploy angle", deploycopy).
  60. }
  61. }
  62. }
  63.  
  64. return props.
  65. }
  66. set x to choose 90 if vang(heading(90,0):vector,ship:facing:vector) < 45 else 0.
  67. lock p to 0.
  68. lock steering to heading(x,p).
  69. brakes on.
  70. bays on.
  71. wait 4.
  72. brakes off.
  73. lock throttle to 1.
  74. SetAngle(15).
  75. startup(vectors).
  76. startup(turbos).
  77. when airspeed > 90 then {
  78. info("takeoff").
  79. set p to 10.
  80. }
  81. when airspeed > 110 then {
  82. info("climb").
  83. set p to 20.
  84. setangle(25).
  85. }
  86. when airspeed > 150 and apoapsis < 2000 then {
  87. info("vector full push").
  88. setangle(90).
  89. set p to 40.
  90. gear off.
  91. }
  92.  
  93.  
  94.  
  95. when apoapsis > 2000 then {
  96. info("will clear mountain, locking to surface prograde").
  97. lock p to max(10,vang(srfprograde:vector,heading(x,0):vector)).
  98. }
  99.  
  100. when airspeed > 300 then {
  101. info("put away props").
  102. set props to false.
  103.  
  104. for rotor in rotors {
  105. rotor:mod:setfield("torque limit(%)", 0).
  106. rotor:mod:setfield("rpm limit", 0 ).
  107.  
  108. for blade in rotor:blades {
  109. blade:mod:setfield("deploy angle", 90).
  110. }
  111. }
  112.  
  113. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("deactivate fusion power") m:doevent("deactivate fusion power").
  114. wait 0.
  115. bays off.
  116. }
  117.  
  118. when airspeed > turboSpeed then {
  119. info("Resume Airbreathing Flight").
  120. shutoff(vectors).
  121. set vlimit to 100.
  122. set angletarget to 90.
  123.  
  124. autoVectoring off.
  125. }
  126.  
  127. when altitude > 14000 then {
  128. info("engage nukes").
  129. startup(nukes).
  130. lock p to 15.
  131. }
  132.  
  133.  
  134. when altitude > 20000 then {
  135. info("push to orbit").
  136. lock p to min(35,airspeed/50).
  137. startup(vectors).
  138. ThrustLimit(vectors, 100).
  139. }
  140.  
  141. when apoapsis > body:Atm:height + 10e3 then {
  142. info("apoapsis achieved").
  143. lock throttle to 0.
  144. lock steering to srfprograde.
  145. shutoff(turbos).
  146. }
  147. when altitude > body:atm:height then {
  148. info("in space").
  149. lock steering to prograde.
  150. lock throttle to 30-eta:apoapsis.
  151. }
  152. when periapsis > body:atm:height then {
  153. lock desiredVel to vxcl(up:vector,velocity:orbit):normalized * sqrt(body:MU/(body:Radius + altitude)).
  154. lock dV to desiredVel - velocity:orbit.
  155. lock steering to lookdirup(dV, ship:facing:topvector).
  156. when true then {
  157. if vang(facing:vector,dV) > 10 lock throttle to 0. else lock throttle to dv:mag / 2.
  158. if dv:mag > 0.3 return true. else {
  159. set complete to true.
  160. lock throttle to 0.
  161.  
  162. info("welcome to orbit").
  163. info(" On nukes: " + nukedv).
  164. info(" On vectors: " + vectordv).
  165.  
  166. info(" On nukes last: " + nukelastdv).
  167. info("On vectors last: " + vectorlastdv).
  168. }
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement