Advertisement
eytixis

Big Reactor with 2 turbines

Aug 6th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.75 KB | None | 0 0
  1. reactor = peripheral.wrap("BigReactors-Reactor_0")
  2. turbine1 = peripheral.wrap("BigReactors-Turbine_0")
  3. turbine2 = peripheral.wrap("BigReactors-Turbine_1")
  4. monitor = peripheral.wrap("top")
  5.  
  6. mon = true
  7. watch = true
  8.  
  9. times = {}
  10. times.monitor = {}
  11. times.watch = {}
  12. times.monitor.monitor = 0.4
  13. times.monitor.sync = 2
  14. times.watch.sync = 2
  15. times.watch.watch = 0.4
  16.  
  17. buttons = {}
  18. buttons[1] = {}
  19. buttons[2] = {}
  20. buttons[3] = {}
  21. buttons[4] = {}
  22. buttons[5] = {}
  23. buttons[6] = {}
  24.  
  25. buttons[1].label = "1 only "
  26. buttons[2].label = "2 only "
  27. buttons[3].label = "all on "
  28. buttons[4].label = "all off"
  29. buttons[5].label = " auto  "
  30. buttons[6].label = "monitor"
  31.  
  32. buttons[1].sx = 20
  33. buttons[3].sx = 20
  34. buttons[5].sx = 20
  35. buttons[1].sy = 2
  36. buttons[2].sx = 30
  37. buttons[4].sx = 30
  38. buttons[6].sx = 30
  39. buttons[1].sy = 2
  40. buttons[2].sy = 2
  41. buttons[3].sy = 7
  42. buttons[4].sy = 7
  43. buttons[5].sy = 12
  44. buttons[6].sy = 12
  45.  
  46. for sdfg = 1,6 do
  47.   buttons[sdfg].x = 9
  48.   buttons[sdfg].y = 3
  49. end
  50.  
  51. function singleTurbine(turb)
  52.   reactor.setAllControlRodLevels(86)
  53.   if turb == turbine1 then
  54.     turb1Enable()
  55.     turb2Disable()
  56.   elseif turb == turbine2 then
  57.     turb1Disable()
  58.     turb2Enable()
  59.   end
  60. end
  61.  
  62. function actives()
  63.   if turbine1.getActive() and turbine2.getActive() then
  64.     return 2
  65.   elseif turbine1.getActive() and not turbine2.getActive() then
  66.     return 1
  67.   elseif turbine2.getActive() and not turbine1.getActive() then
  68.     return 1
  69.   elseif not (turbine1.getActive() and turbine2.getActive()) then
  70.     return 0
  71.   end
  72. end
  73.  
  74. function createButtons()
  75.   for bts = 1,#buttons do
  76.     makeButton(buttons[bts].label,buttons[bts].x,buttons[bts].y,buttons[bts].sx,buttons[bts].sy)
  77.   end
  78. end
  79.  
  80. function allTurbines()
  81.   reactor.setAllControlRodLevels(73)
  82.   turb1Enable()
  83.   turb2Enable()
  84. end
  85.  
  86. function allOff()
  87.   reactor.setActive(false)
  88.   turbine1.setActive(false)
  89.   turbine2.setActive(false)
  90. end
  91.  
  92. function turb1Enable()
  93.   turbine1.setActive(true)
  94.  
  95. end
  96.  
  97. function turb2Enable()
  98.   turbine2.setActive(true)
  99. end
  100.  
  101. function setupMon()
  102.   monitor.clear()
  103.   monitor.setCursorPos(1,1)
  104. end
  105.  
  106. function monClear()
  107.   monitor.clear()
  108.   monitor.setCursorPos(1,1)
  109. end
  110.  
  111. function monit()
  112.   while true do
  113.     while mon do
  114.       monitorer()
  115.       sleep(times.monitor.monitor)
  116.     end
  117.     sleep(times.monitor.sync)
  118.   end
  119. end
  120.  
  121. function makeButton(label,x,y,xs,ys)
  122.   xf = xs + x-1
  123.   yf = ys + y-1
  124.   monitor.setBackgroundColor(colors.red)
  125.   for i = xs,xf do
  126.     for k = ys,yf do
  127.       monitor.setCursorPos(i,k)
  128.       monitor.write(" ")
  129.     end
  130.   end
  131.   monitor.setCursorPos(xs+1, math.floor((yf+ys)/2))
  132.   monitor.setTextColor(colors.blue)
  133.   monitor.write(label)
  134.   monitor.setBackgroundColor(colors.black)
  135. end
  136.  
  137.  
  138. function pullTouch()
  139.   while true do
  140.     event, per, tx, ty = os.pullEvent("monitor_touch")
  141.     if event == "monitor_touch" then
  142.       for aa = 1,#buttons do
  143.         for ax = buttons[aa].sx,(buttons[aa].sx+buttons[aa].x) do
  144.           for ay = buttons[aa].sy, (buttons[aa].sy+buttons[aa].y) do
  145.             if tx == ax and ty == ay then
  146.               if buttons[aa].label ==     "1 only " then
  147.                 singleTurbine(turbine1)
  148.               elseif buttons[aa].label == "2 only " then
  149.                 singleTurbine(turbine2)
  150.               elseif buttons[aa].label == "all on " then
  151.                 allTurbines()
  152.               elseif buttons[aa].label == "all off" then
  153.                 allOff()
  154.               elseif buttons[aa].label == " auto  " then
  155.                 changeAuto()
  156.               elseif buttons[aa].label == "monitor" then
  157.                 changeMonitor()
  158.               end
  159.             end
  160.           end
  161.         end
  162.       end
  163.     end
  164.   end
  165. end
  166.  
  167.  
  168. function turbWatch()
  169.   while true do
  170.     while watch do
  171.       onChange()
  172.       if turbine1.getActive() then
  173.         if turbine1.getRotorSpeed() < 1600 then
  174.           turbine1.setInductorEngaged(false)
  175.         else
  176.           turbine1.setInductorEngaged(true)
  177.         end
  178.       else
  179.         turbine1.setInductorEngaged(false)
  180.       end
  181.       if turbine2.getActive() then
  182.         if turbine2.getRotorSpeed() < 1600 then
  183.           turbine2.setInductorEngaged(false)
  184.         else
  185.           turbine2.setInductorEngaged(true)
  186.         end
  187.       else
  188.         turbine2.setInductorEngaged(false)
  189.       end
  190.     sleep(times.watch.watch)
  191.     end
  192.   sleep(times.watch.sync)
  193.   end
  194. end
  195.  
  196. function termClear()
  197.     term.clear()
  198.     term.setCursorPos(1,1)
  199. end
  200.  
  201. function changeMonitor()
  202.     mon = not mon
  203.     termClear()
  204.     print("Monitor: "..tostring(mon))
  205.     print("Auto: "..tostring(watch))
  206. end
  207.  
  208. function changeAuto()
  209.     watch = not watch
  210.     termClear()
  211.     print("Monitor: "..tostring(mon))
  212.     print("Auto: "..tostring(watch))
  213. end
  214.  
  215. function onChange()
  216.   if actives() == 0 then
  217.     reactor.setActive(false)
  218.   elseif actives() == 1 then
  219.     reactor.setActive(true)
  220.     reactor.setAllControlRodLevels(86)
  221.   elseif actives() == 2 then
  222.     reactor.setActive(true)
  223.     reactor.setAllControlRodLevels(73)
  224.   end
  225. end
  226.  
  227. function turb1Disable()
  228.   turbine1.setActive(false)
  229. end
  230.  
  231. function turb2Disable()
  232.   turbine2.setActive(false)
  233. end
  234.  
  235. function monitorer()
  236.   monClear()
  237.  
  238.     -- reactor monitor --
  239.   monitor.setTextColor(colors.blue)
  240.   monitor.write("Reactor")
  241.   monitor.setCursorPos(1,2)
  242.   if reactor.getActive() then
  243.     monitor.setTextColor(colors.lime)
  244.     monitor.write("Active")
  245.   else
  246.     monitor.setTextColor(colors.red)
  247.     monitor.write("Not Active")
  248.   end
  249.   monitor.setTextColor(colors.lightBlue)
  250.   monitor.setCursorPos(1,3)
  251.   monitor.write("Rods: ".. tostring(reactor.getControlRodLevel(1)).."%")
  252.   monitor.setCursorPos(1,4)
  253.   fuel = math.floor(reactor.getFuelAmount() / reactor.getFuelAmountMax() * 100)
  254.   monitor.write("Fuel: ".. tostring(fuel).."%")
  255.   energy = turbine1.getEnergyProducedLastTick() + turbine2.getEnergyProducedLastTick()
  256.   monitor.setCursorPos(1,5)
  257.   monitor.write("Power: ")
  258.   if actives() == 0 then
  259.     monitor.setTextColor(colors.red)
  260.     monitor.write(tostring(math.floor(energy)).."rf/t")
  261.   elseif actives()  == 1 then
  262.     monitor.setTextColor(colors.blue)
  263.     monitor.write(tostring(math.floor(energy)).."rf/t")
  264.   elseif actives() == 2 then
  265.     monitor.setTextColor(colors.lime)
  266.     monitor.write(tostring(math.floor(energy)).."rf/t")
  267.   end  
  268.  
  269.     -- turbine 1 monitor --
  270.   monitor.setCursorPos(1,7)
  271.   monitor.setTextColor(colors.blue)
  272.   monitor.write("Turbine 1")
  273.   monitor.setCursorPos(1,8)
  274.   if turbine1.getActive() then
  275.     monitor.setTextColor(colors.lime)
  276.     monitor.write("Active")
  277.   else
  278.     monitor.setTextColor(colors.red)
  279.     monitor.write("Not Active")
  280.   end
  281.   monitor.setTextColor(colors.lightBlue)
  282.   monitor.setCursorPos(1,9)
  283.   monitor.write("Energy: ")
  284.   if turbine1.getActive() then
  285.     monitor.setTextColor(colors.lime)
  286.     monitor.write(tostring(math.floor(turbine1.getEnergyProducedLastTick())).."rf/t")
  287.   else
  288.     monitor.setTextColor(colors.red)
  289.     monitor.write(tostring(math.floor(turbine1.getEnergyProducedLastTick())).."rf/t")  
  290.   end
  291.   monitor.setCursorPos(1,10)
  292.   monitor.setTextColor(colors.lightBlue)
  293.   monitor.write("Speed: ")
  294.   if turbine1.getActive() then
  295.     monitor.setTextColor(colors.lime)
  296.   else
  297.     monitor.setTextColor(colors.red)
  298.   end
  299.   monitor.write(tostring(math.floor(turbine1.getRotorSpeed())).." RPM")
  300.   monitor.setCursorPos(1,11)
  301.   if turbine1.getInductorEngaged() then
  302.     monitor.setTextColor(colors.lime)
  303.     monitor.write("Coils Engaged")
  304.   else
  305.     monitor.setTextColor(colors.red)
  306.     monitor.write("Coils Disengaged")
  307.   end
  308.  
  309. -- turbine 2 monitor --
  310.   monitor.setCursorPos(1,13)
  311.   monitor.setTextColor(colors.blue)
  312.   monitor.write("Turbine 2")
  313.   monitor.setCursorPos(1,14)
  314.   if turbine2.getActive() then
  315.     monitor.setTextColor(colors.lime)
  316.     monitor.write("Active")
  317.   else
  318.     monitor.setTextColor(colors.red)
  319.     monitor.write("Not Active")
  320.   end
  321.   monitor.setTextColor(colors.lightBlue)
  322.   monitor.setCursorPos(1,15)
  323.   monitor.write("Energy: ")
  324.   if turbine2.getActive() then
  325.     monitor.setTextColor(colors.lime)
  326.     monitor.write(tostring(math.floor(turbine2.getEnergyProducedLastTick())).."rf/t")
  327.   else
  328.     monitor.setTextColor(colors.red)
  329.     monitor.write(tostring(math.floor(turbine2.getEnergyProducedLastTick())).."rf/t")  
  330.   end
  331.   monitor.setCursorPos(1,16)
  332.   monitor.setTextColor(colors.lightBlue)
  333.   monitor.write("Speed: ")
  334.   if turbine2.getActive() then
  335.     monitor.setTextColor(colors.lime)
  336.   else
  337.     monitor.setTextColor(colors.red)
  338.   end
  339.   monitor.write(tostring(math.floor(turbine2.getRotorSpeed())).." RPM")
  340.   monitor.setCursorPos(1,17)
  341.   if turbine2.getInductorEngaged() then
  342.     monitor.setTextColor(colors.lime)
  343.     monitor.write("Coils Engaged")
  344.   else
  345.     monitor.setTextColor(colors.red)
  346.     monitor.write("Coils Disengaged")
  347.   end
  348.   createButtons()
  349. end
  350.  
  351. parallel.waitForAll(monit,turbWatch,pullTouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement