Advertisement
readix

reactorController

Apr 10th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local reactor1 = peripheral.wrap("BigReactors-Reactor_2")
  2. local mon = peripheral.wrap("top")
  3. local x =peripheral.wrap("right")
  4. local alarm = true
  5. local storageMax = 85
  6. local controlleRod = 60
  7.  
  8.  
  9. local xpos, ypos, monmessage = 1, 15, ""
  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(reactor1.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(reactor1.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.   term.setCursorPos(1,6)
  78.     if alarm then
  79.         write("                                                                     ")
  80.         term.setCursorPos(1,6)
  81.         write("Alarm ")
  82.         term.setTextColor(colors.lime)
  83.         write("on")
  84.         term.setTextColor(colors.white)
  85.   else
  86.         write("                                                                     ")
  87.         term.setCursorPos(1,6)
  88.         write("alarm ")
  89.         term.setTextColor(colors.lime)
  90.         write("off")
  91.         term.setTextColor(colors.white)
  92.   end
  93.     term.setCursorPos(1,8)
  94.     write("Storage Max RF : ")
  95.     term.setTextColor(colors.lime)
  96.     write(storageMax)
  97.     term.setTextColor(colors.white)
  98.     write(", Rod Level : ")
  99.     term.setTextColor(colors.lime)
  100.     write(reactor1.getControlRodLevel(0))
  101.     term.setTextColor(colors.white)
  102.  
  103.  
  104.  
  105. --end affiche
  106. end
  107.  
  108. function event1()
  109.     while true do
  110.         event, number, bool = os.pullEvent("key")
  111.         if number == 33 then --off
  112.             reactor1.setActive(false)
  113.             alarm=false
  114.              --term.setCursorPos(1,4)
  115.             --term.setCursorPos(1,5)
  116.             --write("off")
  117.             --write("stoped")
  118.    
  119.         elseif number == 49 then
  120.             reactor1.setActive(true) --on
  121.             alarm=true
  122.             --term.setCursorPos(1,4)
  123.             --write("on")
  124.    
  125.         elseif number==31 then --stop
  126.             alarm=false
  127.          --term.setCursorPos(1,5)
  128.         -- write("stoped")
  129.         end
  130.     end
  131. end
  132.  
  133. function playAffiche()
  134.     while true do
  135.         affiche()
  136.         sleep(0)
  137.     end
  138. end
  139.  
  140. function read()
  141.     while true do
  142.        
  143.         local event, p1 = os.pullEvent()
  144.         if (event == "char") and (xpos < 50) then
  145.             monmessage = monmessage..p1
  146.             term.setCursorPos(xpos,ypos)
  147.             term.write(p1)
  148.             xpos = xpos+1
  149.         elseif event == "key" then
  150.              if (p1 == 14) and (xpos > 1) then
  151.                  monmessage = string.sub( monmessage, 1, string.len( monmessage ) - 1 )
  152.                  xpos = xpos-1
  153.                 term.setCursorPos(xpos,ypos)
  154.                  term.write(" ")
  155.                  term.setCursorPos(xpos,ypos)
  156.              elseif p1 == 28 then
  157.                 --monmessage = tostring( monmessage )
  158.                 --break
  159.                                
  160.                 envoiMsg()
  161.                 xpos, ypos = 1, 15
  162.                 term.setCursorPos(xpos,ypos)
  163.                 term.write("                                                ")
  164.                 term.setCursorPos(xpos,ypos)
  165.                 end
  166.         end
  167.        
  168.     end
  169. end
  170.  
  171.  
  172. function envoiMsg()
  173.     if monmessage == "rod" then
  174.         stat = "rod"
  175.         monmessage=""
  176.     elseif monmessage == "storage" then
  177.         stat = "storage"
  178.         monmessage=""
  179.     elseif monmessage =="++" then
  180.            
  181.             if stat=="rod" then
  182.                 controlleRod=controlleRod+10
  183.                 reactor1.setAllControlRodLevels(controlleRod)
  184.             elseif stat=="storage" then
  185.                 storageMax=storageMax+10
  186.             end
  187.             stat = "nothing"
  188.             monmessage=""
  189.     elseif monmessage =="--" then
  190.            
  191.             if stat=="rod" then
  192.                 controlleRod=controlleRod-10
  193.                 reactor1.setAllControlRodLevels(controlleRod)
  194.             elseif stat=="storage" then
  195.                 storageMax=storageMax-10
  196.             end
  197.             stat = "nothing"
  198.             monmessage=""
  199.     elseif monmessage == "off" then
  200.         reactor1.setActive(false)
  201.          alarm=false
  202.         active = "off"
  203.     elseif monmessage == "on" then
  204.         reactor1.setActive(true) --on
  205.         active = "on"
  206.         alarm=true     
  207.     elseif monmessage == "stop" then
  208.         alarm=false
  209.     else
  210.             stat = "nothing"
  211.             monmessage=""
  212.     end
  213.         monmessage=""
  214.    
  215.        
  216.    
  217. end
  218.  
  219.  
  220.  
  221. function readController()
  222.      while true do
  223.        
  224.         if stat ==  "nothing" then
  225.             term.setCursorPos(1,10)
  226.             term.setTextColor(colors.red)
  227.             write("Write rod to modify the production or storage to modify max storage of RF")
  228.             term.setTextColor(colors.white)
  229.         elseif stat == "rod" then
  230.             term.setCursorPos(1,10)
  231.             write("                                                                     ")
  232.            
  233.             term.setCursorPos(1,10)
  234.             term.setTextColor(colors.red)
  235.             write("Write ++ or -- (+10 or -10), it is : "..reactor1.getControlRodLevel(0))
  236.             term.setTextColor(colors.white)
  237.             term.setCursorPos(1,11)
  238.             write("                                                                     ")
  239.         elseif stat == "storage" then
  240.             term.setCursorPos(1,10)
  241.             write("                                                                     ")
  242.             term.setCursorPos(1,10)
  243.             term.setTextColor(colors.red)
  244.             write("Write ++ or -- (+10 or -10), it is: "..storageMax)
  245.             term.setTextColor(colors.white)
  246.             term.setCursorPos(1,11)
  247.             write("                                                                    ")
  248.         end
  249.         sleep(1)
  250.     end
  251. end
  252.  
  253.  
  254. function controller()
  255.     while true do
  256.         if reactor1.getActive() and reactor1.getEnergyStored()/100000 >=storageMax then
  257.             reactor1.setActive(false)
  258.             redstone.setOutput("left",true)
  259.         elseif not (reactor1.getActive()) and active == "on" and reactor1.getEnergyStored()/100000 <= storageMax-20 then
  260.             reactor1.setActive(true)
  261.             redstone.setOutput("left",false)
  262.         end
  263.         sleep(1)
  264.     end
  265. end
  266.  
  267.  
  268. function play()
  269.     while true do
  270.         while reactor1.getFuelAmount() <3000 and alarm==true and reactor1.getActive() do
  271.            
  272.             redstone.setOutput("left",true)
  273.             x.setPitch(23)
  274.             x.triggerNote()
  275.             sleep(1)
  276.             x.setPitch(24)
  277.             x.triggerNote()
  278.             redstone.setOutput("left",false)
  279.             sleep(1)
  280.         end
  281.         redstone.setOutput("left",false)
  282.    
  283.  
  284.      sleep(1)
  285.     end
  286. end
  287. reactor1.setActive(true)
  288. term.clear()
  289. parallel.waitForAny(play,playAffiche,readController,controller,read)
  290.  
  291.  
  292. function afficheCommand()
  293.     while true do
  294.   local reactor = peripheral.wrap("BigReactors-Reactor_4")
  295.  
  296.   print("getConnected: ", reactor.getConnected())
  297.   print("getActive: ", reactor.getActive())
  298.   print("getNumberOfControlRods: ", reactor.getNumberOfControlRods())
  299.   print("getEnergyStored: ", reactor.getEnergyStored())
  300.   print("getFuelTemperature: ", reactor.getFuelTemperature())
  301.   print("getCasingTemperature: ", reactor.getCasingTemperature())
  302.   print("getFuelAmount: ", reactor.getFuelAmount())
  303.   print("getWasteAmount: ", reactor.getWasteAmount())
  304.   print("getFuelAmountMax: ", reactor.getFuelAmountMax())
  305.   print("getControlRodName: ", reactor.getControlRodName(0))
  306.   print("getControlRodLevel: ", reactor.getControlRodLevel(0))
  307.   print("getEnergyProducedLastTick: ", reactor.getEnergyProducedLastTick())
  308.   print("getCoolantAmount: ", reactor.getCoolantAmount())
  309.   print("getCoolantType: ", reactor.getCoolantType())
  310.   print("getHotFluidAmount: ", reactor.getHotFluidAmount())
  311.   print("getHotFluidType: ", reactor.getHotFluidType())
  312.   print("getFuelReactivity: ", reactor.getFuelReactivity())
  313.   print("getFuelConsumedLastTick: ", reactor.getFuelConsumedLastTick())
  314.   print("isActivelyCooled: ", reactor.isActivelyCooled())
  315.  
  316.  -- reactor.setActive(boolean)
  317.  -- reactor.setAllControlRodLevels(level 0-100)
  318.  -- reactor.setControlRodLevel(index, level 0-100)
  319.  -- doEjectWaste()
  320.  
  321.   sleep(5)
  322. end
  323. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement