readix

turbineController

Apr 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local reactor1 = peripheral.wrap("BigReactors-Reactor_4")
  2. local mon = peripheral.wrap("top")
  3. local x =peripheral.wrap("right")
  4. local alarm = true
  5. local storageMax = 85
  6. local controlleRod = reactor1.getControlRodLevel(0)
  7. local turbine = peripheral.wrap("BigReactors-Turbine_12")
  8.  
  9. local xpos, ypos, monmessage = 1, 16, ""
  10. local stat="nothing" --storage or rod
  11.  
  12. local active = "on"
  13.  
  14. function affiche()
  15.      
  16.   mon.clear()
  17.   -- Begin Reactor 1
  18.   --mon.setCursorPos(1,1)
  19.   --mon.setTextColor(colors.white)
  20.   --mon.write("Reactor #: ")
  21.   --mon.setTextColor(colors.lime)
  22.   --mon.write("1")
  23.  
  24.   mon.setCursorPos(1,1)
  25.   mon.setTextColor(colors.white)
  26.   mon.write("Active: ")
  27.   mon.setTextColor(colors.lime)
  28.   mon.write(reactor1.getActive())
  29.    
  30.   mon.setCursorPos(1,2)
  31.   mon.setTextColor(colors.white)
  32.   mon.write("RF/T: ")  
  33.   mon.setTextColor(colors.lime)
  34.   mon.write(math.floor(turbine.getEnergyProducedLastTick()))
  35.  
  36.   mon.setCursorPos(1,3)
  37.   mon.setTextColor(colors.white)
  38.   mon.write("RF Stored: ")
  39.   mon.setTextColor(colors.lime)
  40.   mon.write(math.floor(turbine.getEnergyStored()))
  41.  
  42.   mon.setCursorPos(1,4)
  43.   mon.setTextColor(colors.white)
  44.   mon.write("Casing Heat: ")
  45.   mon.setTextColor(colors.lime)
  46.   mon.write(math.floor(reactor1.getCasingTemperature()))
  47.  
  48.   mon.setCursorPos(1,5)
  49.   mon.setTextColor(colors.white)
  50.   mon.write("Fuel Heat: ")
  51.   mon.setTextColor(colors.lime)
  52.   mon.write(math.floor(reactor1.getFuelTemperature()))
  53.   -- End Reactor 1
  54.   --term.clear()
  55.   term.setCursorPos(1,1)
  56.   write("Write off to turn off ")
  57.   term.setCursorPos(1,2)
  58.   write("Write on to turn on ")
  59.   term.setCursorPos(1,3)
  60.   write("Write stop to stop the alert ")
  61.   term.setCursorPos(1,5)
  62.   if reactor1.getActive() then
  63.         write("                                                                     ")
  64.         term.setCursorPos(1,5)
  65.         write("Reactor : ")
  66.         term.setTextColor(colors.lime)
  67.         write("on")
  68.         term.setTextColor(colors.white)
  69.   else
  70.         write("                                                                     ")
  71.         term.setCursorPos(1,5)
  72.         write("Reactor : ")
  73.         term.setTextColor(colors.lime)
  74.         write("off")
  75.         term.setTextColor(colors.white)
  76.   end
  77.    if turbine.getActive() then
  78.         write("                                                                     ")
  79.         term.setCursorPos(1,6)
  80.         write("Turbine : ")
  81.         term.setTextColor(colors.lime)
  82.         write("on ")
  83.         term.setTextColor(colors.white)
  84.   else
  85.         write("                                                                     ")
  86.         term.setCursorPos(1,6)
  87.         write("Turbine : ")
  88.         term.setTextColor(colors.lime)
  89.         write("off")
  90.         term.setTextColor(colors.white)
  91.   end
  92.   term.setCursorPos(1,7)
  93.     if alarm then
  94.         write("                                                                     ")
  95.         term.setCursorPos(1,7)
  96.         write("Alarm ")
  97.         term.setTextColor(colors.lime)
  98.         write("on")
  99.         term.setTextColor(colors.white)
  100.   else
  101.         write("                                                                     ")
  102.         term.setCursorPos(1,7)
  103.         write("alarm ")
  104.         term.setTextColor(colors.lime)
  105.         write("off")
  106.         term.setTextColor(colors.white)
  107.   end
  108.     term.setCursorPos(1,9)
  109.     write("Storage Max RF : ")
  110.     term.setTextColor(colors.lime)
  111.     write(storageMax)
  112.     term.setTextColor(colors.white)
  113.     write(", Rod Level : ")
  114.     term.setTextColor(colors.lime)
  115.     write(reactor1.getControlRodLevel(0))
  116.     term.setTextColor(colors.white)
  117.  
  118.  
  119.  
  120. --end affiche
  121. end
  122.  
  123. function event1()
  124.     while true do
  125.         event, number, bool = os.pullEvent("key")
  126.         if number == 33 then --off
  127.             reactor1.setActive(false)
  128.             alarm=false
  129.              --term.setCursorPos(1,4)
  130.             --term.setCursorPos(1,5)
  131.             --write("off")
  132.             --write("stoped")
  133.    
  134.         elseif number == 49 then
  135.             reactor1.setActive(true) --on
  136.             alarm=true
  137.             --term.setCursorPos(1,4)
  138.             --write("on")
  139.    
  140.         elseif number==31 then --stop
  141.             alarm=false
  142.          --term.setCursorPos(1,5)
  143.         -- write("stoped")
  144.         end
  145.     end
  146. end
  147.  
  148. function playAffiche()
  149.     while true do
  150.         affiche()
  151.         sleep(0)
  152.     end
  153. end
  154.  
  155. function read()
  156.     while true do
  157.        
  158.         local event, p1 = os.pullEvent()
  159.         if (event == "char") and (xpos < 50) then
  160.             monmessage = monmessage..p1
  161.             term.setCursorPos(xpos,ypos)
  162.             term.write(p1)
  163.             xpos = xpos+1
  164.         elseif event == "key" then
  165.              if (p1 == 14) and (xpos > 1) then
  166.                  monmessage = string.sub( monmessage, 1, string.len( monmessage ) - 1 )
  167.                  xpos = xpos-1
  168.                 term.setCursorPos(xpos,ypos)
  169.                  term.write(" ")
  170.                  term.setCursorPos(xpos,ypos)
  171.              elseif p1 == 28 then
  172.                 --monmessage = tostring( monmessage )
  173.                 --break
  174.                                
  175.                 envoiMsg()
  176.                 monmessage="" --peutetre faux je rajoute apres coup
  177.                 xpos, ypos = 1, 16
  178.                 term.setCursorPos(xpos,ypos)
  179.                 term.write("                                                ")
  180.                 term.setCursorPos(xpos,ypos)
  181.                 end
  182.         end
  183.        
  184.     end
  185. end
  186.  
  187.  
  188. function envoiMsg()
  189.     if monmessage == "rod" then
  190.         stat = "rod"
  191.         monmessage=""
  192.     elseif monmessage == "storage" then
  193.         stat = "storage"
  194.         monmessage=""
  195.     elseif monmessage == "turbine" then
  196.         stat = "coil"
  197.         monmessage=""
  198.     elseif monmessage =="++" then
  199.            
  200.             if stat=="rod" then
  201.                 controlleRod=controlleRod+10
  202.                 reactor1.setAllControlRodLevels(controlleRod)
  203.             elseif stat=="storage" then
  204.                 storageMax=storageMax+10
  205.             end
  206.             stat = "nothing"
  207.             monmessage=""
  208.     elseif monmessage =="--" then
  209.            
  210.             if stat=="rod" then
  211.                 controlleRod=controlleRod-10
  212.                 reactor1.setAllControlRodLevels(controlleRod)
  213.             elseif stat=="storage" then
  214.                 storageMax=storageMax-10
  215.             end
  216.             stat = "nothing"
  217.             monmessage=""
  218.     elseif monmessage == "off" then
  219.         if stat == "coil" then
  220.             turbine.setConnected(false)
  221.         elseif stat=="nothing" then
  222.             reactor1.setActive(false)
  223.              alarm=false
  224.             active = "off"
  225.         end
  226.     elseif monmessage == "on" then
  227.         if stat == "coil" then
  228.             turbine.setConnected(true)
  229.         elseif stat=="nothing" then
  230.             reactor1.setActive(true) --on
  231.             active = "on"
  232.             alarm=true     
  233.         end
  234.     elseif monmessage == "stop" then
  235.         alarm=false
  236.     else
  237.             stat = "nothing"
  238.             monmessage=""
  239.     end
  240.         monmessage=""
  241.    
  242.        
  243.    
  244. end
  245.  
  246.  
  247.  
  248. function readController()
  249.      while true do
  250.        
  251.         if stat ==  "nothing" then
  252.             term.setCursorPos(1,11)
  253.             term.setTextColor(colors.red)
  254.             write("Write rod to modify the production or storage to modify max storage of RF or turbine to turn on/off")
  255.             term.setTextColor(colors.white)
  256.         elseif stat == "rod" then
  257.             term.setCursorPos(1,11)
  258.             write("                                                                     ")
  259.            
  260.             term.setCursorPos(1,11)
  261.             term.setTextColor(colors.red)
  262.             write("Write ++ or -- (+10 or -10), it is : "..reactor1.getControlRodLevel(0))
  263.             term.setTextColor(colors.white)
  264.             term.setCursorPos(1,12)
  265.             write("                                                                     ")
  266.             term.setCursorPos(1,13)
  267.             write("                                                                     ")
  268.         elseif stat == "storage" then
  269.             term.setCursorPos(1,11)
  270.             write("                                                                     ")
  271.             term.setCursorPos(1,11)
  272.             term.setTextColor(colors.red)
  273.             write("Write ++ or -- (+10 or -10), it is: "..storageMax)
  274.             term.setTextColor(colors.white)
  275.             term.setCursorPos(1,12)
  276.             write("                                                                    ")
  277.             term.setCursorPos(1,13)
  278.             write("                                                                     ")
  279.         elseif stat == "coil" then
  280.             term.setCursorPos(1,11)
  281.             write("                                                                     ")
  282.             term.setCursorPos(1,11)
  283.             term.setTextColor(colors.red)
  284.             write("Write on or off to turn on or off the turbine ")
  285.             term.setTextColor(colors.white)
  286.             term.setCursorPos(1,12)
  287.             write("                                                                    ")
  288.             term.setCursorPos(1,13)
  289.             write("                                                                     ")
  290.         end
  291.         sleep(1)
  292.     end
  293. end
  294.  
  295.  
  296. function controller()
  297.     while true do
  298.         if reactor1.getActive() and reactor1.getEnergyStored()/100000 >=storageMax then
  299.             reactor1.setActive(false)
  300.    redstone.setOutput("left",true)
  301.         elseif not (reactor1.getActive()) and active == "on" and reactor1.getEnergyStored()/100000 <= storageMax-20 then
  302.             reactor1.setActive(true)
  303.             redstone.setOutput("left",false)
  304.         end
  305.         sleep(1)
  306.     end
  307. end
  308.  
  309.  
  310. function play()
  311.     while true do
  312.         while reactor1.getFuelAmount() <3000 and alarm==true and reactor1.getActive() do
  313.            
  314.             redstone.setOutput("left",true)
  315.             x.setPitch(23)
  316.             x.triggerNote()
  317.             sleep(1)
  318.             x.setPitch(24)
  319.             x.triggerNote()
  320.             redstone.setOutput("left",false)
  321.             sleep(1)
  322.         end
  323.         redstone.setOutput("left",false)
  324.    
  325.  
  326.      sleep(1)
  327.     end
  328. end
  329. reactor1.setActive(true)
  330. term.clear()
  331. parallel.waitForAny(play,playAffiche,readController,controller,read)
  332.  
  333.  
  334. function afficheCommand()
  335.     while true do
  336.   local reactor = peripheral.wrap("BigReactors-Reactor_4")
  337.  
  338.   print("getConnected: ", reactor.getConnected())
  339.   print("getActive: ", reactor.getActive())
  340.   print("getNumberOfControlRods: ", reactor.getNumberOfControlRods())
  341.   print("getEnergyStored: ", reactor.getEnergyStored())
  342.   print("getFuelTemperature: ", reactor.getFuelTemperature())
  343.   print("getCasingTemperature: ", reactor.getCasingTemperature())
  344.   print("getFuelAmount: ", reactor.getFuelAmount())
  345.   print("getWasteAmount: ", reactor.getWasteAmount())
  346.   print("getFuelAmountMax: ", reactor.getFuelAmountMax())
  347.   print("getControlRodName: ", reactor.getControlRodName(0))
  348.   print("getControlRodLevel: ", reactor.getControlRodLevel(0))
  349.   print("getEnergyProducedLastTick: ", reactor.getEnergyProducedLastTick())
  350.   print("getCoolantAmount: ", reactor.getCoolantAmount())
  351.   print("getCoolantType: ", reactor.getCoolantType())
  352.   print("getHotFluidAmount: ", reactor.getHotFluidAmount())
  353.   print("getHotFluidType: ", reactor.getHotFluidType())
  354.   print("getFuelReactivity: ", reactor.getFuelReactivity())
  355.   print("getFuelConsumedLastTick: ", reactor.getFuelConsumedLastTick())
  356.   print("isActivelyCooled: ", reactor.isActivelyCooled())
  357.  
  358.  -- reactor.setActive(boolean)
  359.  -- reactor.setAllControlRodLevels(level 0-100)
  360.  -- reactor.setControlRodLevel(index, level 0-100)
  361.  -- doEjectWaste()
  362.  
  363.   sleep(5)
  364. end
  365. end
Add Comment
Please, Sign In to add comment