Advertisement
N9vaivie

Staging Script (rough)

Oct 23rd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. //setup
  2. Clearscreen. Set eLT to 0. //for some reason kOS doesn't think eLT is defined?
  3. Set count to 10. Set relog to 0.
  4. Set cpuDisplay to PROCESSOR("cpuDisplay").
  5.  
  6. Set allEngines to ship:partsdubbed("eng1").
  7.  
  8. Wait until not core:messages:empty.
  9.  
  10. //edit n9LaunchParameters.ks to select parameters:
  11. When not core:messages:empty then {
  12. Set received to core:messages:pop.
  13.  
  14. If received:content = "ManualStaging" {
  15. cpuDisplay:connection:sendmessage("Rocket Profile Selected: Manual Staging.").
  16. cpuDisplay:connection:sendmessage("Staging: Shutting Down...").
  17. Shutdown.
  18. }
  19.  
  20. If received:content = "shutdown"{
  21. cpuDisplay:connection:sendmessage("Staging: Shutting Down...").
  22. Shutdown.
  23. }
  24.  
  25. If received:content = "L4" {
  26. cpuDisplay:connection:sendmessage("Rocket Profile Selected: L4.").
  27. Set eLT to 3098.
  28. Set sR to 2.
  29. Lock fT to round(ship:Kerosene).
  30. Set fTT to 25000.
  31. Set bS to 1.
  32. When sR = 1 then {
  33. Lock fT to round(ship:HTP).
  34. Set fTT to 137.
  35. }
  36. }
  37.  
  38. Preserve.
  39. }.
  40.  
  41. function liftOff {
  42. parameter expectedLaunchThrust.
  43.  
  44. cpuDisplay:connection:sendmessage("Hit '0' to initiate countdown!").
  45.  
  46. On Ag10 {
  47. Until count = 0 {
  48. cpuDisplay:connection:sendmessage("T minus " + count + " seconds...").
  49.  
  50. If count = 3 {
  51. Stage.
  52. }
  53.  
  54. Wait 1.
  55. Set count to (count - 1).
  56. }
  57. }
  58.  
  59. Wait until count = 0.
  60. Wait until ship:maxThrust > (expectedLaunchThrust * 0.9).
  61. Stage.
  62. cpuDisplay:connection:sendmessage("Lift Off!").
  63. }.
  64.  
  65. function stageProgram {
  66. parameter stagesRemaining.
  67. parameter fuelType.
  68. parameter fuelTypeThreshold.
  69. parameter boosterStage.
  70.  
  71. Set expectedThrust to ship:maxThrust.
  72. Wait until ship:maxThrust < (expectedThrust * 0.9).
  73.  
  74. Wait 1.
  75.  
  76. If fuelType < fuelTypeThreshold {
  77. Wait 3. Stage.
  78. cpuDisplay:connection:sendmessage("Stage Separation!").
  79.  
  80. If boosterStage = 0 {
  81. cpuDisplay:connection:sendmessage("Ullaging...").
  82. Wait 1. Stage.
  83. cpuDisplay:connection:sendmessage("Lighting Next Stage").
  84. Wait 4.
  85.  
  86. If ship:maxThrust > (expectedThrust * 0.7) {
  87. cpuDisplay:connection:sendmessage("Good Light!").
  88. set sR to (stagesRemaining - 1).
  89. }
  90.  
  91. If ship:maxThrust < (expectedThrust * 0.7) {
  92. cpuDisplay:connection:sendmessage("Engine Failure...").
  93. }
  94. }
  95.  
  96. If boosterStage = 1 {
  97. Set bS to 0.
  98. }
  99. }
  100.  
  101. If fuelType > fuelTypeThreshold {
  102. cpuDisplay:connection:sendmessage("Unexpected Thrust Loss!").
  103. cpuDisplay:connection:sendmessage(fuelType + " is more than " + fuelTypeThreshold).
  104.  
  105. Wait 1. Set previousThrust to ship:maxThrust. Wait 1.
  106.  
  107. If ship:maxThrust = 0 {
  108. cpuDisplay:connection:sendmessage("Switching to Manual Staging.").
  109. Shutdown.
  110. }
  111.  
  112. If ship:maxThrust < (previousThrust * 0.9) {
  113. cpuDisplay:connection:sendmessage("Switching to Manual Staging.").
  114. Shutdown.
  115. }
  116.  
  117. If ship:maxThrust > (previousThrust * 0.9) {
  118. cpuDisplay:connection:sendmessage("Stable. Manual Separation Required.").
  119. Set relog to 1.
  120. If boosterStage = 1 {
  121. Set bS to 0.
  122. }
  123. set sR to (stagesRemaining - 1).
  124. }
  125. }
  126.  
  127. Wait until sR = (stagesRemaining - 1).
  128. }
  129.  
  130. liftOff(eLT).
  131.  
  132. Until sR = 0 {
  133. stageProgram(sR,fT,fTT,bS).
  134. If relog = 1 {
  135. Set sR to (sR + 1).
  136. Set relog to 0.
  137. }
  138. Wait 0.1.
  139. }.
  140.  
  141. cpuDisplay:connection:sendmessage("Staging: Shutting Down...").
  142. Shutdown.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement