sumguytwitches

hathi suderra takeoff

Aug 30th, 2023 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. set groundlevel to altitude.
  2. ship:partsdubbedpattern("cockpit")[0]:controlfrom().
  3.  
  4. set vectors to ship:partsdubbedpattern("vector").
  5. set nukes to ship:partsdubbedpattern("nuc").
  6. set turbos to ship:partsdubbedpattern("turbofan").
  7. set servos to ship:modulesnamed("ModuleRoboticRotationServo").
  8. set proprad to 5.8.
  9. set x to 90.
  10. lock p to 1.
  11. //set targetapoapsis to 100e3.
  12. set autoVectoring to true.
  13. set mountainclearcutoff to 1000.
  14. set turboSpeed to 350.
  15. lock srfp to 90-vang(srfprograde:vector,up:vector).
  16.  
  17. for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
  18.  
  19. set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
  20. set rotors to list().
  21. for rm in rotormods {
  22. local rotor to lexicon().
  23. if(rm:getfield("motor") <> "Unpowered")
  24. {
  25. set rotor["part"] to rm:part.
  26. set rotor["mod"] to rm.
  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. bm:setfield("pitch", true).
  39. bm:setfield("roll", true).
  40. bm:setfield("yaw", true).
  41.  
  42. rotor["blades"]:add(blade).
  43. }
  44.  
  45. rotors:add(rotor).
  46. if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 0).
  47. }
  48. }
  49. function ImaRocket {
  50. props off.
  51. setangle(0).
  52. ship:dockingports[0]:controlfrom().
  53. startup(vectors).
  54. shutoff(nukes).
  55. shutoff(turbos).
  56. }
  57.  
  58.  
  59. function ImaRocketPlane {
  60. props off.
  61. ship:rootpart:controlfrom().
  62. startup(vectors).
  63. shutoff(turbos).
  64. shutoff(nukes).
  65. }
  66.  
  67. function ImtheRedBaron {
  68. parameter resetengines is true.
  69. if resetengines shutoff(ship:engines).
  70. ship:partsdubbedpattern("cockpit")[0]:controlfrom().
  71. for rotor in rotors {
  72. if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 100).
  73. if rotor:part:parent:name:contains("bay") {
  74. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  75. if baymod:hasevent("open") baymod:doevent("open").
  76. }
  77. }
  78. set props to true.
  79.  
  80. lock rpmtarget to min(459,max(0, throttle * 460)).
  81.  
  82. set props to true.
  83. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("activate fusion power") m:doevent("activate fusion power").
  84.  
  85. on round(time:seconds * 20) {
  86. if props {
  87. set rpmcopy to rpmtarget.
  88. for rotor in rotors {
  89.  
  90. rotor:mod:setfield("rpm limit", rpmcopy ).
  91. set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * rpmcopy/60).
  92. set deploycopy to max(3, 4.5 + arctan2(airspeed, calcAirspeed)).
  93. for blade in rotor:blades {
  94. blade:mod:setfield("deploy angle", deploycopy).
  95. }
  96. }
  97.  
  98. } else {
  99. for rotor in rotors {
  100. if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 0).
  101.  
  102. if rotor:part:parent:name:contains("bay") {
  103. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  104. if baymod:hasevent("close") baymod:doevent("close").
  105. }
  106. }
  107. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("deactivate fusion power") m:doevent("deactivate fusion power").
  108. }
  109. return props.
  110. }
  111.  
  112.  
  113. }
  114.  
  115. function SetEngines {
  116. parameter targetMode to "Activate Engine".
  117. parameter engines to ship:partsdubbedpattern("vector").
  118. for engine in engines {
  119. if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
  120. if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
  121. if m:hasaction(targetMode) m:doaction(targetMode, true).
  122. }
  123. }
  124.  
  125. function shutoff {
  126. parameter engines to ship:partsdubbedpattern("vector").
  127. SetEngines("Shutdown Engine", engines).
  128. }
  129.  
  130. function startup {
  131. parameter engines to ship:partsdubbedpattern("vector").
  132. SetEngines("Activate Engine", engines).
  133. }
  134.  
  135. function ThrustLimit {
  136. parameter targetEngines.
  137. parameter targetThrust.
  138. for eng in targetEngines set eng:thrustlimit to targetThrust.
  139. }
  140.  
  141. function SetAngle {
  142. parameter targetangle.
  143. for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
  144. }
  145.  
  146. function info {
  147. parameter message.
  148.  
  149. set logmessage to round(missionTime,1) + ": " + message.
  150. print logmessage.
  151. }
  152. lock currpitch to 90-vang(up:vector,ship:facing:vector).
  153. lock p to 15.
  154. set x to 90.
  155. lock st to heading(x,p).
  156. lock slide to -vdot(st:starvector, srfprograde:vector).
  157. lock b to max(-15, min(15, choose 0 if abs(slide) < 5 else slide )).
  158.  
  159. gear off. brakes off.
  160. set airalt to groundlevel + 10.
  161. setangle(0).
  162. startup(vectors).
  163. set steeringmanager:Rollcontrolanglerange to 180.
  164.  
  165. set autovectoring to true.
  166. gear on.
  167. rcs on.
  168. wait 5.
  169. // for en in ship:engines {
  170. // en:shutdown().
  171. // if en:name:contains("ssme") and vdot(en:position, ship:facing:vector) > 1 en:activate().
  172. // }
  173. startup(vectors).
  174. lock steering to st.
  175. lock throttle to periapsis < body:atm:height.
  176. thrustlimit(vectors, 100).
  177.  
  178. info(status).
  179. on status {
  180. info(status).
  181. //gear off.
  182. return altitude < 1000.
  183. }
  184.  
  185. when currpitch > 12 then {
  186. imtheredbaron(false).
  187. lock rpmtarget to 460.
  188. startup(turbos).
  189. //lock throttle to 1.
  190. }
  191.  
  192. when altitude > groundlevel + 10 then {
  193. info("Retracting Gear").
  194. lock p to 17.
  195. gear off.
  196. steeringmanager:resetpids().
  197. }
  198. when airspeed > 50 then {
  199. lock steering to heading(x,p,-b).
  200. }
  201. when verticalSpeed > 3 then {
  202. steeringManager:resetpids().
  203. }
  204.  
  205. when autoVectoring then {
  206. setangle(currpitch).
  207. set tl to max(0,min(100,(max(-verticalspeed + 2,1300-altitude))*100)).
  208. //thrustlimit(vectors,tl).
  209. for vc in vectors {
  210. set vc:thrustlimit to tl + 100*(choose 1 if vdot(ship:facing:vector, vc:position) > 0 else -1)*steeringmanager:pitchpid:output.
  211. }
  212. //lock ttl to (130-airspeed)/2*100.
  213. thrustlimit(turbos,(-verticalspeed + 5)*100).
  214. return autoVectoring.
  215. }
  216.  
  217.  
  218. when apoapsis > mountainclearcutoff then {
  219. info("Will clear mountain").
  220. lock p to max(16,srfp).
  221. }
  222.  
  223.  
  224. when altitude > 3000 then {
  225. info("prop climb complete").
  226. startup(turbos).
  227. lock throttle to 1.
  228. autoVectoring off.
  229. thrustlimit(ship:engines, 100).
  230. SetAngle(90).
  231. }
  232.  
  233.  
  234. when airspeed > 300 then {
  235. info("Props Off").
  236. set props to false.
  237. }
  238.  
  239. when airspeed > turboSpeed then {
  240. info("Resume Airbreathing Flight").
  241. shutoff(vectors).
  242.  
  243. autoVectoring off.
  244. }
  245.  
  246. when altitude > 14000 then {
  247. info("engage nukes").
  248. startup(nukes).
  249. lock p to 18.
  250. }
  251.  
  252.  
  253. when altitude > 20000 then {
  254. info("push to orbit").
  255. SetAngle(90).
  256. lock p to min(45,airspeed/35).
  257. startup(vectors).
  258. ThrustLimit(vectors, 100).
  259. }
  260.  
  261. when altitude > body:atm:height and apoapsis > 100e3 then {
  262. info("race to circularize").
  263. lock steering to heading(90,15).
  264. }
  265.  
Add Comment
Please, Sign In to add comment