Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. print "hello script".
  2.  
  3. global all_engines to LIST().
  4. list ENGINES in all_engines.
  5.  
  6. set staging to false.
  7. set running to false.
  8.  
  9. function notify {
  10. parameter reached.
  11. parameter condition.
  12.  
  13. if (condition) {
  14. print "Reached " + reached.
  15. }
  16.  
  17. return condition.
  18. }
  19.  
  20. function out_of_atmosphere {
  21. return notify("out of atmosphere", ship:altitude > 55000).
  22. }
  23.  
  24. function periapsis_goal {
  25. return notify("periapsis target", ship:periapsis > target_periapsis).
  26. }
  27.  
  28. function apoapsis_goal {
  29. return notify("apoapsis target", ship:apoapsis > target_apoapsis).
  30. }
  31.  
  32. function check_engines_flameout {
  33. for eng in all_engines {
  34. if eng:stage >= stage:number and not eng:flameout {
  35. return false.
  36. }
  37. }
  38.  
  39. return true.
  40. }
  41.  
  42. function ideal_throttle {
  43. if apoapsis_goal() and not periapsis_goal() and eta:apoapsis < 20 {
  44. return 0.75.
  45. } else if apoapsis_goal() and not periapsis_goal() and eta:apoapsis >= 20 {
  46. return 0.
  47. } else if not out_of_atmosphere() {
  48. return 1.
  49. } else if not apoapsis_goal() {
  50. return 0.75.
  51. } else {
  52. return 0.
  53. }
  54. }
  55.  
  56. function ideal_steering {
  57. if staging {
  58. return facing.
  59. } else if apoapsis_goal() {
  60. return heading(90, 0, -90).
  61. } else if ship:altitude < 55000 or not apoapsis_goal() {
  62. set ship_velocity_factor to ship:velocity:surface:mag / 200.
  63. set angle to max(0, 90 - ship_velocity_factor * 10).
  64. return heading(90, angle, -90).
  65. } else {
  66. return heading(90, 0, -90).
  67. }
  68. }
  69.  
  70. function launch_ship {
  71. print "Running".
  72.  
  73. set running to true.
  74.  
  75. until periapsis_goal() and apoapsis_goal() {
  76. if check_engines_flameout() {
  77. print "Staging !".
  78. set staging to true.
  79.  
  80. wait 0.5.
  81. STAGE.
  82.  
  83. set staging to false.
  84. }
  85.  
  86. set throttle to ideal_throttle().
  87. set steering to ideal_steering().
  88.  
  89. wait 0.2.
  90. }
  91.  
  92. set running to false.
  93. }
  94.  
  95. set target_apoapsis to 75000.
  96. set apoapsis_offset to 5000.
  97.  
  98. set real_target_apoapsis to target_apoapsis - apoapsis_offset.
  99. set target_periapsis to target_apoapsis - (target_apoapsis * 0.05).
  100.  
  101. // main
  102. print "main".
  103. rcs on.
  104. stage.
  105.  
  106. print "go !".
  107. when ship:apoapsis < target_apoapsis and not running then {
  108. launch_ship().
  109. preserve.
  110. }
  111.  
  112.  
  113.  
  114. wait until apoapsis_goal() and periapsis_goal().
  115. set throttle to 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement