Advertisement
sumguytwitches

Hathi Firmware

Feb 9th, 2023 (edited)
1,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.27 KB | None | 0 0
  1. // !runscript 5kbYLJTV
  2.  
  3.  
  4.  
  5. ship:controlpart:controlfrom().
  6. lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
  7. lock nukeLiquid to max(0, ship:liquidfuel-liquidmatched).
  8. lock x to body:geopositionof(ship:facing:vector):heading.
  9. lock p to 0.
  10. lock b to 0.
  11. lock ralt to altitude - ship:geoposition:terrainheight.
  12. lock twr to ship:availablethrust/ship:mass/body:mu*body:position:sqrmagnitude.
  13.  
  14. function displayDV {
  15.  
  16. set oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
  17.  
  18. set nukesfirstdv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (nukeLiquid * 0.005))), 5).
  19. set vectorsfirstdv to Round(315 * 9.81 * ln(ship:mass / (ship:mass - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
  20.  
  21. 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).
  22. 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).
  23.  
  24.  
  25. for res in ship:resources {
  26. if res:name = "liquidfuel"
  27. set lqcap to res:capacity.
  28. if res:name = "oxidizer"
  29. set oxcap to res:capacity.
  30. }
  31. set oxmass to oxcap * 0.005.
  32. set lqmatchmass to oxcap * 9 / 11 * 0.005.
  33.  
  34. set nukesmaxdv to Round(800 * 9.81 * ln((ship:drymass + (lqcap * 0.005) ) / ship:drymass), 5).
  35. set vectormaxdv to Round(315 * 9.81 * ln((ship:drymass + lqmatchmass + oxmass ) / ship:drymass), 5).
  36.  
  37. set justnukesdv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (ship:liquidfuel * 0.005))), 5).
  38.  
  39.  
  40. info(" nukes only: " + justnukesdv).
  41. info("").
  42. info(" vectors first: " + vectorsfirstdv).
  43. info(" nukes last: " + nukeslastdv).
  44. info("").
  45. info(" nukes first: " + nukesfirstdv).
  46. info(" vectors last: " + vectorlastdv).
  47. info("").
  48. info("nukes then vectors: " + (nukesfirstdv + vectorlastdv)).
  49.  
  50. }
  51.  
  52.  
  53. set vectors to ship:partsdubbedpattern("vector").
  54. set nukes to ship:partsdubbedpattern("nuc").
  55. set turbos to ship:partsdubbedpattern("turbofan").
  56. set servos to ship:modulesnamed("ModuleRoboticRotationServo").
  57. set proprad to 5.8.
  58.  
  59. for rap in ship:partsdubbedpattern("rapier") turbos:add(rap).
  60.  
  61. set rotormods to ship:modulesnamed("ModuleRoboticServoRotor").
  62. set rotors to list().
  63. for rm in rotormods {
  64. local rotor to lexicon().
  65. if(rm:getfield("motor") <> "Unpowered")
  66. {
  67. set rotor["part"] to rm:part.
  68. set rotor["mod"] to rm.
  69.  
  70. set rotor["blades"] to list().
  71. for bm in rm:part:ModulesNamed("ModuleControlSurface") {
  72. local bpart to bm:part.
  73.  
  74. local blade to lexicon().
  75. set blade["mod"] to bm.
  76. set blade["offset"] to vdot(-bpart:Facing:starvector, bpart:position - bpart:parent:position).
  77. set blade["proprad"] to proprad.
  78.  
  79. bm:setfield("deploy", true).
  80.  
  81. rotor["blades"]:add(blade).
  82. }
  83.  
  84. rotors:add(rotor).
  85. if rm:hasfield("torque limit(%)") rm:setfield("torque limit(%)", 0).
  86. }
  87. }
  88. function ImaRocket {
  89. props off.
  90. setangle(0).
  91. ship:dockingports[0]:controlfrom().
  92. startup(vectors).
  93. shutoff(nukes).
  94. shutoff(turbos).
  95. }
  96.  
  97. function ImaJet {
  98. parameter resetengines is true.
  99. props off.
  100. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  101. if resetengines shutoff(ship:engines).
  102. startup(turbos).
  103. }
  104.  
  105. function ImaRocketPlane {
  106. props off.
  107. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  108. startup(vectors).
  109. shutoff(turbos).
  110. shutoff(nukes).
  111. }
  112.  
  113. function ImtheRedBaron {
  114.  
  115. set steeringmanager:rollcontrolanglerange to 180.
  116. parameter resetengines is true.
  117. if resetengines shutoff(ship:engines).
  118. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  119. for rotor in rotors {
  120. if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 100).
  121. if rotor:part:parent:name:contains("bay") {
  122. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  123. if baymod:hasevent("open") baymod:doevent("open").
  124. }
  125. }
  126. set props to true.
  127.  
  128. lock rpmtarget to min(459,max(0, throttle * 460)).
  129.  
  130. set props to true.
  131. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("activate fusion power") m:doevent("activate fusion power").
  132.  
  133. on round(time:seconds * 20) {
  134. if props {
  135. set rpmcopy to rpmtarget.
  136. for rotor in rotors {
  137.  
  138. rotor:mod:setfield("rpm limit", rpmcopy ).
  139. set calcAirspeed to (2 * constant:pi * (rotor:blades[0]:proprad + rotor:blades[0]:offset) * rpmcopy/60).
  140. set deploycopy to max(3, 4.5 + arctan2(airspeed, calcAirspeed)).
  141. for blade in rotor:blades {
  142. blade:mod:setfield("deploy angle", deploycopy).
  143. }
  144. }
  145.  
  146. } else {
  147. for rotor in rotors {
  148. if rotor:mod:hasfield("torque limit(%)") rotor:mod:setfield("torque limit(%)", 0).
  149.  
  150. if rotor:part:parent:name:contains("bay") {
  151. set baymod to rotor:part:parent:getmodule("ModuleAnimateGeneric").
  152. if baymod:hasevent("close") baymod:doevent("close").
  153. }
  154. }
  155. for m in ship:modulesnamed("WBIModuleGeneratorFX") if m:hasevent("deactivate fusion power") m:doevent("deactivate fusion power").
  156. }
  157. return props.
  158. }
  159.  
  160.  
  161. }
  162.  
  163.  
  164. function GoToSleep {
  165. lock steering to "kill".
  166. gear on.
  167. setangle(90).
  168. wait 1.
  169. unlock steering.
  170. fuelCells off.
  171. radiators off.
  172. isru off.
  173. gear off.
  174. lights off.
  175. sas off.
  176. rcs off.
  177. set ev to "stop".
  178. for m in ship:modulesnamed("ModuleResourceConverter")
  179. for nn in m:allactionnames
  180. if nn:contains(ev)
  181. m:doaction(nn,true).
  182. for m in ship:modulesnamed("WBIModuleGeneratorFX")
  183. if m:hasevent("deactivate fusion power")
  184. m:doevent("deactivate fusion power").
  185. bays off.
  186.  
  187. }
  188.  
  189. function LevelUp {
  190. ship:modulesnamed("ModuleExperienceManagement")[0]:doevent("level up crew").
  191. }
  192.  
  193. function SetEngines {
  194. parameter targetMode to "Activate Engine".
  195. parameter engines to ship:partsdubbedpattern("vector").
  196. for engine in engines {
  197. if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
  198. if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
  199. if m:hasaction(targetMode) m:doaction(targetMode, true).
  200. }
  201. }
  202.  
  203. function shutoff {
  204. parameter engines to ship:partsdubbedpattern("vector").
  205. SetEngines("Shutdown Engine", engines).
  206. }
  207.  
  208. function startup {
  209. parameter engines to ship:partsdubbedpattern("vector").
  210. SetEngines("Activate Engine", engines).
  211. }
  212.  
  213. function ThrustLimit {
  214. parameter targetEngines.
  215. parameter targetThrust.
  216. for eng in targetEngines set eng:thrustlimit to targetThrust.
  217. }
  218.  
  219. function SetAngle {
  220. parameter targetangle.
  221. for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
  222. }
  223.  
  224. function info {
  225. parameter message.
  226.  
  227. set logmessage to round(missionTime,1):ToString():padleft(6) + ": " + message.
  228. print logmessage.
  229. }
  230.  
  231.  
  232. function powertakeoffatmo {
  233. parameter h to 90.
  234. parameter runwayheight to round(altitude + 21).
  235. parameter initialPitch to 6.
  236. lock x to h.
  237. lock b to 0.
  238. lock p to initialPitch.
  239. lock aoa to arcsin(srfprograde:topvector*facing:vector).
  240. info("preparing for takeoff at runway height of " + runwayheight).
  241. ship:dockingports[0]:controlfrom().
  242. set angleup to false.
  243.  
  244. lights on.
  245. shutoff(ship:engines).
  246. startup(vectors).
  247. thrustlimit(vectors, 100).
  248. setangle(0).
  249. wait 3.
  250. gear off.
  251. wait 1.
  252. info("hold position").
  253.  
  254. lock steering to lookdirup(up:Vector*10-ship:Velocity:surface*0.03,ship:facing:topvector).
  255. for vec in vectors set vec:gimbal:limit to 6.
  256. rcs on.
  257. lock angletarget to 0.
  258. lock throttle to 1.
  259.  
  260. when altitude > runwayheight then rcs off.
  261. when altitude > runwayheight - 7 then {
  262. info("rotate").
  263. gear off.
  264. brakes off.
  265. lock steering to lookdirup(up:Vector*10-ship:Velocity:surface*0.03,heading(h+180,0):vector).
  266. }
  267.  
  268. when altitude > runwayheight - 1 and abs(steeringManager:angleerror) < 1 and abs(steeringManager:rollerror) < 1 and ship:angularvel:mag < 0.3 then {
  269. info("Prep flight steering").
  270. ship:partsdubbedpattern("cockpit")[0]:controlfrom().
  271. lock steering to heading(x,p,-b).
  272. set steeringmanager:rollcontrolanglerange to 180.
  273. lock angletarget to arcsin(up:vector*facing:vector).
  274.  
  275. set angleup to true.
  276. wait 0.5.
  277. }
  278. when angleup and abs(steeringManager:angleerror) < 1 then {
  279.  
  280. info("Switch to boosted plane flight").
  281. for vec in vectors set vec:gimbal:limit to 2.
  282. ImaJet(false).
  283. ImtheRedBaron(false).
  284. lock rpmtarget to 460.
  285.  
  286. info("engage dynamic servo").
  287. lock angletarget to max(0, min(90,arcsin(up:vector*facing:vector)+verticalspeed*90)).
  288.  
  289. }
  290. info("initialize vtols").
  291. // lock vlimit to max(50-(altitude - ship:geoposition:terrainheight),(-verticalspeed + (runwayheight-altitude))*100).
  292. // set vlimitcopy to vlimit.
  293. set anglecopy to angletarget.
  294. set autovector to true.
  295. when true then {
  296.  
  297. set anglecopy to angletarget.
  298.  
  299. SetAngle(anglecopy).
  300.  
  301.  
  302. print " servo angle: " + anglecopy at (0,1).
  303. print " p: " + p at (0,2).
  304. print " runwayheight: " + runwayheight at (0,3).
  305. print " twr:" + twr at (0,4).
  306.  
  307. return autovector.
  308. }
  309. when airspeed > 150 then {
  310. info("storing vectors").
  311. shutoff(vectors).
  312. ThrustLimit(vectors, 100).
  313. SetAngle(90).
  314. set autovector to false.
  315. lock p to initialPitch.
  316. }
  317. }
  318.  
  319. function takeoffatmo {
  320. parameter h to 90.
  321. parameter runwayheight to round(altitude + 21).
  322. parameter initialPitch to 10.
  323. lock x to h.
  324. lock b to 0.
  325. lock p to initialPitch.
  326. lock aoa to arcsin(srfprograde:topvector*facing:vector).
  327. info("preparing for takeoff at runway height of " + runwayheight).
  328. ship:dockingports[0]:controlfrom().
  329. set angleup to false.
  330.  
  331. lights on.
  332. shutoff(ship:engines).
  333. startup(vectors).
  334. setangle(0).
  335. wait 3.
  336. info("hold position").
  337. set steeringmanager:rollcontrolanglerange to 180.
  338. lock steering to lookdirup(up:Vector*10-ship:Velocity:surface*0.03,ship:facing:topvector).
  339. for vec in vectors set vec:gimbal:limit to 6.
  340. rcs on.
  341. lock angletarget to 0.
  342. when ralt > runwayheight then rcs off.
  343. lock throttle to 1.
  344. when ralt > 3 then {
  345. info("rotate").
  346. gear off.
  347. brakes off.
  348. lock steering to lookdirup(up:Vector*10-ship:Velocity:surface*0.03,heading(h+180,0):vector).
  349. }
  350.  
  351. when altitude > runwayheight-2 and abs(steeringManager:angleerror) < 1 and abs(steeringManager:rollerror) < 1 and ship:angularvel:mag < 0.1 then {
  352. info("Prep flight steering").
  353. ship:partsdubbedpattern("cockpit")[0]:controlfrom().
  354. lock steering to heading(x,p,-b).
  355. lock angletarget to arcsin(up:vector*facing:vector).
  356.  
  357. set angleup to true.
  358. wait 0.5.
  359. }
  360. when angleup and abs(steeringManager:angleerror) < 1 then {
  361.  
  362. info("Switch to boosted plane flight").
  363. for vec in vectors set vec:gimbal:limit to 2.
  364. ImaJet(false).
  365. ImtheRedBaron(false).
  366.  
  367. info("engage dynamic servo").
  368. lock angletarget to max(0, min(90,arcsin(up:vector*facing:vector) + 100 - ((-verticalspeed + (runwayheight-altitude)/1.5)*100))).
  369.  
  370. }
  371. info("initialize vtols").
  372. lock vlimit to max(50-(altitude - ship:geoposition:terrainheight),(-verticalspeed + (runwayheight-altitude))*100).
  373. set vlimitcopy to vlimit.
  374. set anglecopy to angletarget.
  375.  
  376. when true then {
  377. set vlimitcopy to vlimit.
  378. set anglecopy to angletarget.
  379. ThrustLimit(vectors, vlimitcopy).
  380. SetAngle(anglecopy).
  381.  
  382. print " v thrust: " + vlimitcopy at (0,0).
  383. print " servo angle: " + anglecopy at (0,1).
  384. print " p: " + p at (0,2).
  385. print " runwayheight: " + runwayheight at (0,3).
  386. print " twr:" + twr at (0,4).
  387.  
  388. return altitude < runwayheight + 20.
  389. }
  390. when altitude > runwayheight + 20 then {
  391. info("storing vectors").
  392. shutoff(vectors).
  393. ThrustLimit(vectors, 100).
  394. SetAngle(90).
  395. }
  396. }
  397.  
  398.  
  399. function powerlandatmo {
  400. set navmode to "surface".
  401. props off.
  402. lock steering to srfprograde.
  403. set x to body:geopositionof(srfprograde:vector):heading.
  404. set p to 0.
  405. ship:partsdubbedpattern("cockpit")[0]:controlfrom().
  406. shutoff(ship:engines).
  407. thrustlimit(vectors, 0).
  408. startup(vectors).
  409. lock throttle to 1.
  410. set landing to true.
  411.  
  412. on time:seconds {
  413.  
  414. set vthrottle to 100*(-verticalspeed-2)-sqrt(2*max(1,(max(0.1,vdot(up:vector,vectors[0]:facing:vector))* availablethrust*0.85)/mass-body:mu/(body:radius^2))*max(altitude-geoposition:terrainheight-50+verticalspeed*0.5,0.1)).
  415. thrustlimit(vectors, vthrottle).
  416. print (" Thrust Limit:" + round(vthrottle)):padright(terminal:width) at (0,0).
  417.  
  418. set vangle to max(-45,min(45,-groundspeed*vdot(ship:facing:vector, velocity:surface))).
  419. setangle(vangle).
  420. print (" Angle:" + round(vangle)):padright(terminal:width) at (0,1).
  421.  
  422. print ("Alt above Ground:" + round(altitude - ship:geoposition:terrainheight)):padright(terminal:width) at (0,2).
  423. return landing.
  424. }
  425.  
  426. when airspeed < 10 then {
  427. lock steering to heading(x,p).
  428. gear on.
  429. brakes on.
  430.  
  431. }
  432.  
  433. when ship:verticalspeed > 0 and altitude - ship:geoposition:terrainheight < 1000 and groundspeed < 10 then
  434. {
  435. lock throttle to 0.
  436.  
  437. set landing to false.
  438. }
  439. }
  440.  
  441. function landnukeonly {
  442. parameter targetgroundspeed is 200.
  443.  
  444.  
  445. list engines in es. for e in es e:shutdown().
  446. SetEngines("Activate Engine", nukes).
  447.  
  448. info("reducing groundspeed to under " + targetgroundspeed).
  449. lock steering to -velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5.
  450. lock throttle to choose groundspeed - targetgroundspeed if abs(steeringmanager:angleerror) < 5 else 0.
  451.  
  452.  
  453. wait until groundspeed < targetgroundspeed + 1.
  454.  
  455. brakes on.
  456. gear on.
  457. lights on.
  458.  
  459. wait until abs(steeringmanager:angleerror) < 5.
  460. set complete to false.
  461. info("begin final landing sequence").
  462.  
  463. lock throttle to (-verticalspeed-1)-sqrt(2*max(1,(max(0.1,vdot(up:vector,ship:facing:vector))* availablethrust*0.7)/mass-body:mu/(body:radius^2))*max(altitude-geoposition:terrainheight-50+verticalspeed*0.5,0.1)).
  464. when verticalspeed > -2 and ralt < 45 and verticalspeed < 0 then {
  465. lock throttle to 0.
  466. lock steering to heading(90,0).
  467. set complete to true.
  468. }
  469.  
  470. lock steering to lookdirup(-velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5,heading(270,0):vector).
  471.  
  472.  
  473. when ship:status = "Landed" then info("welcome to " + body:name).
  474. }
  475.  
  476.  
  477. function landnoatmo {
  478. parameter targetgroundspeed is groundspeed / 2.
  479. info("reducing groundspeed to under " + targetgroundspeed).
  480. lock steering to -velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5.
  481. lock throttle to choose groundspeed - targetgroundspeed if abs(steeringmanager:angleerror) < 5 else 0.
  482. when ship:liquidfuel < (ship:oxidizer * 9 / 11) + 0.4 then
  483. {
  484. info("switching to rockets").
  485. list engines in es. for e in es e:shutdown().
  486. SetEngines("Activate Engine", vectors).
  487. }
  488.  
  489. wait until groundspeed < targetgroundspeed + 1.
  490. info("preparing final form").
  491. lock throttle to 0.
  492. list engines in es. for e in es e:shutdown().
  493. SetEngines("Activate Engine", vectors).
  494. SetAngle(0).
  495. rcs on.
  496.  
  497. ship:dockingports[0]:controlfrom().
  498. brakes on.
  499. gear on.
  500. lights on.
  501.  
  502. wait until abs(steeringmanager:angleerror) < 5.
  503. set complete to false.
  504. info("begin final landing sequence").
  505.  
  506. lock throttle to (-verticalspeed-1)-sqrt(2*max(1,(max(0.1,vdot(up:vector,ship:facing:vector))* availablethrust*0.75)/mass-body:mu/(body:radius^2))*max(altitude-geoposition:terrainheight-60+verticalspeed*0.5,0.1)).
  507. when verticalspeed>0 and ralt < 1000 then {
  508. lock throttle to 0.
  509. lock steering to heading(90,90).
  510. set complete to true.
  511. }
  512.  
  513. lock steering to lookdirup(-velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5,heading(270,0):vector).
  514.  
  515.  
  516. wait until complete.
  517. info("welcome to " + body:name).
  518. }
  519.  
  520.  
  521. function takeoffnoatmo {
  522. parameter targetalt is 15e3.
  523. parameter targetpitch is 20.
  524.  
  525. set steeringmanager:rollcontrolanglerange to 180.
  526. SetAngle (0).
  527. lights on.
  528. list engines in es. for e in es e:shutdown().
  529. SetEngines("Activate Engine", vectors).
  530. ship:dockingports[0]:controlfrom().
  531. rcs on.
  532. lock steering to heading(90,90).
  533. lock throttle to -verticalspeed + 5.
  534.  
  535. when ralt > 100 and abs(steeringmanager:angleerror) < 5 then {
  536. lock throttle to 0.
  537. gear off.
  538. lights off.
  539. SetAngle(90).
  540. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  541. lock steering to heading(90,targetpitch).
  542. wait 0.
  543. when abs(steeringmanager:angleerror) < 5 then lock throttle to targetalt - apoapsis.
  544. if nukeLiquid > 1 {
  545. SetEngines("Activate Engine", nukes).
  546. when nukeLiquid < 1 then SetEngines("Shutdown Engine", nukes).
  547. }
  548.  
  549. }
  550. when apoapsis > targetalt -500 then {
  551. print "takeoff complete".
  552. lock throttle to 0.
  553. }
  554.  
  555. }
  556.  
  557. function takeoffnoatmo2 {
  558. parameter targetalt is 20e3.
  559. parameter climbangle is 20.
  560.  
  561. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  562. set steeringmanager:rollcontrolanglerange to 180.
  563. set autoangle to true. when autoangle then { setangle(90-vang(up:vector, ship:facing:vector)). return autoangle. }
  564. lights on.
  565. list engines in es. for e in es e:shutdown().
  566. SetEngines("Activate Engine", vectors).
  567. ThrustLimit(vectors, 100).
  568. rcs on.
  569. lock steering to heading(90,0).
  570. lock throttle to -verticalspeed + 5.
  571. brakes off.
  572. when ralt > 26 and abs(steeringmanager:angleerror) < 5 then {
  573. gear off.
  574. lights off.
  575. lock steering to heading(90,climbangle).
  576. wait 0.
  577. wait 0.
  578. when 90-vang(up:vector, ship:facing:vector) > climbangle then {
  579. lock throttle to targetalt - apoapsis.
  580. set autoangle to false. wait 0.
  581. SetAngle(90).
  582. }
  583.  
  584. if nukeLiquid > 0 {
  585. SetEngines("Activate Engine", nukes).
  586. when nukeLiquid < 1 then SetEngines("Shutdown Engine", nukes).
  587. }
  588.  
  589. }
  590. when apoapsis > targetalt -500 then {
  591. print "takeoff complete".
  592. lock throttle to 0.
  593. }
  594.  
  595. }
  596.  
  597. function powertakeoff {
  598. set steeringmanager:rollcontrolanglerange to 180.
  599. set x to 90.
  600. parameter targetalt is body:atm:height + 10e3.
  601. set climbangle to 85.
  602. lock p to max(0, 90*(1-(apoapsis/targetalt)^0.5)).
  603. ship:partsdubbedpattern("HathiCockpit")[0]:controlfrom().
  604. set steeringmanager:rollcontrolanglerange to 180.
  605. set autoangle to true.
  606. when autoangle then { setangle(90-vang(up:vector, ship:facing:vector)). return autoangle. }
  607.  
  608. lights on.
  609. for en in ship:engines en:shutdown().
  610. SetEngines("Activate Engine", vectors).
  611. ThrustLimit(ship:engines, 100).
  612. rcs on.
  613. lock steering to heading(x,0).
  614. lock throttle to (targetalt-apoapsis+5e3)/10.
  615. brakes off.
  616. when ralt > 26 and abs(steeringmanager:angleerror) < 5 then {
  617. gear off.
  618. lights off.
  619. lock steering to heading(x,p).
  620. wait 0.
  621. wait 0.
  622. when 90-vang(up:vector, ship:facing:vector) > p-10 then {
  623. lock steering to heading(90,p).
  624. lock throttle to (targetalt-apoapsis+5e3)/1000.
  625. set autoangle to false. wait 0.
  626. SetAngle(90).
  627. if altitude < body:atm:height and airspeed < 300 {
  628. ImtheRedBaron(false).
  629. when airspeed > 300 then props off.
  630. }
  631. }
  632.  
  633. if nukeLiquid > 1 {
  634. SetEngines("Activate Engine", nukes).
  635. when nukeLiquid < 1 then SetEngines("Shutdown Engine", nukes).
  636. }
  637. if body:atm:oxygen {startup(turbos).}
  638.  
  639. }
  640. when apoapsis > targetalt -500 then {
  641. print "takeoff complete".
  642. lock throttle to 0.
  643. lock steering to srfprograde.
  644. }
  645.  
  646. }
  647.  
  648.  
  649. function fuelfordvtarget {
  650. parameter targetRocketDv.
  651. parameter rocketisp to 315.
  652.  
  653. set orewiggle to 0.1.
  654. fuelcells on.
  655.  
  656. if ship:status = "landed" { deploydrills on. wait 3. drills on. }
  657. set res to gui(200, 100).
  658. Set res:x to -40.
  659. set res:y to 5.
  660. res:show.
  661. set reslist to list().
  662. for rs in ship:resources {
  663. set l to res:addlabel().
  664. Set l:style:fontsize to 20.
  665. reslist:add(l).
  666. }
  667. on time:seconds {
  668. set i to 0.
  669. for rs in ship:resources {
  670. set reslist[i]:text to rs:name + " " + round(rs:amount,1) + " / " + rs:capacity.
  671. set reslist[i]:style:textcolor to rgb(1 - rs:amount/rs:capacity, rs:amount/rs:capacity, 0.3).
  672. set i to i + 1.
  673. }
  674. return res:visible.
  675. }
  676.  
  677.  
  678. radiators on.
  679.  
  680. lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
  681. lock oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
  682. lock vectordv to Round(rocketisp * 9.81 * ln(ship:mass / (ship:mass - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
  683. print vectordv.
  684. set isrs to ship:modulesnamed("ModuleResourceConverter").
  685. set warp to 1. wait 1. set warp to 6.
  686. if(vectordv < targetRocketDv and ship:oxidizer * 9 / 11 <= ship:liquidfuel)
  687. {
  688. print "refilling ox to match liquid".
  689. for isr in isrs { if isr:hasaction("start isru [ox]") isr:doaction("start isru [ox]",true).}
  690.  
  691. set warp to 1. wait 1. set warp to 5.
  692. wait until ship:oxidizer * 9 / 11 >= ship:liquidfuel or vectordv >= targetRocketDv or ship:ore < orewiggle.
  693. }
  694. isru off.
  695. if(vectordv < targetRocketDv)
  696. {
  697. print "refilling lf + o to match dv target".
  698. for isr in isrs { if isr:hasaction("start isru [lf+ox]") isr:doaction("start isru [lf+ox]",true).}
  699.  
  700. wait until vectordv >= targetRocketDv or (ship:ore < orewiggle and ship:status <> "Landed").
  701. }
  702. isru off.
  703. for isr in isrs { if isr:hasaction("start isru [lqdfuel]") isr:doaction("start isru [lqdfuel]",true).}
  704. print "converting remaining ore to liquidfuel".
  705. wait until choose ship:ore > 550 if ship:status = "landed" else ship:ore < orewiggle and ship:liquidfuel > 38e3.
  706. isru off.
  707. set warp to 0.
  708. if ship:status = "landed" { deploydrills off. }
  709. radiators off.
  710. fuelcells off.
  711. print "Fuel Converted".
  712. res:hide.
  713. }
  714. function fuelmaxvectors{
  715.  
  716. set orewiggle to 0.1.
  717. fuelcells on.
  718.  
  719. if ship:status = "landed" { deploydrills on. wait 3. drills on. }
  720.  
  721. set res to gui(200, 100).
  722. Set res:x to -40.
  723. set res:y to 5.
  724. res:show.
  725. set reslist to list().
  726. for rs in ship:resources {
  727. set l to res:addlabel().
  728. Set l:style:fontsize to 20.
  729. reslist:add(l).
  730. if rs:name:contains("oxidizer") set oxmax to rs:capacity.
  731. }
  732.  
  733. on time:seconds {
  734. set i to 0.
  735. for rs in ship:resources {
  736. set reslist[i]:text to rs:name + " " + round(rs:amount,1) + " / " + rs:capacity.
  737. set reslist[i]:style:textcolor to rgb(1 - rs:amount/rs:capacity, rs:amount/rs:capacity, 0.3).
  738. set i to i + 1.
  739. }
  740. return res:visible.
  741. }
  742.  
  743.  
  744. radiators on.
  745.  
  746. lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
  747. lock oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
  748.  
  749. set isrs to ship:modulesnamed("ModuleResourceConverter").
  750. set warp to 1. wait 1. set warp to 6.
  751. if(ship:oxidizer * 9 / 11 <= ship:liquidfuel)
  752. {
  753. print "refilling ox to match liquid".
  754. for isr in isrs { if isr:hasaction("start isru [ox]") isr:doaction("start isru [ox]",true).}
  755.  
  756. set warp to 1. wait 1. set warp to 6.
  757. wait until ship:oxidizer * 9 / 11 >= ship:liquidfuel or ship:oxidizer >= oxmax.
  758. }
  759. isru off.
  760. print "refilling lf + o to match dv target".
  761. for isr in isrs { if isr:hasaction("start isru [lf+ox]") isr:doaction("start isru [lf+ox]",true).}
  762.  
  763. wait until ship:oxidizer >= oxmax.
  764.  
  765. isru off.
  766. set warp to 0.
  767. if ship:status = "landed" { deploydrills off. }
  768. radiators off.
  769. fuelcells off.
  770. print "Fuel Converted".
  771. res:hide.
  772. }
  773. clearscreen. wait 0.
  774. print "Welcome to " + ship:name.
  775. for i in range(terminal:height-3) Print "":padright(terminal:width).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement