Advertisement
Guest User

startup

a guest
Aug 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.27 KB | None | 0 0
  1. --Sly's reactor--
  2.  
  3. --peripherals
  4. local m = {44,42,43}
  5. local monitors = {}
  6. for i=1,3 do
  7.     monitors[i] = peripheral.wrap("monitor_"..m[i])
  8. end
  9. local rMon = monitors[2]
  10. local bMon = monitors[3]
  11. local t = {11,10}
  12. local turbines = {}
  13. for i=1,2 do
  14.     turbines[i] = peripheral.wrap("BigReactors-Turbine_"..t[i])
  15. end
  16.  
  17. local r = peripheral.wrap("BigReactors-Reactor_4")
  18.  
  19. local core = peripheral.wrap("draconic_rf_storage_2")
  20. local prevT = core.getEnergyStored()
  21. local prev = {prevT,prevT,prevT,prevT,prevT}
  22. --variables
  23. local cols = {colors.blue,colors.lightBlue,colors.green,colors.orange,colors.red}
  24. local c = {1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,2,2,2,2,2,2,2,2,2,3,3,3,4,4,5}
  25. local dir = {"Upper","Lower"}
  26. local cmode = {colors.green,colors.red}
  27. local rActive = false
  28. local startupState = 0
  29. local Lclock = 0
  30. local sInfo = {"Basic Mainframe: ","Reactor Interface: ","Turbine Interfaces: ","Global Reactor Control: ","Safety Systems: ","Attempting to link computer"}
  31. local bInfo = {}
  32. for i=1,5 do bInfo[i] = true end
  33. bInfo[1] = false
  34.  
  35. function drawButton(id,txt,pos)
  36.    
  37.     bMon.setBackgroundColor(colors.black)
  38.     bMon.setCursorPos(pos[1],pos[2])
  39.     bMon.write(txt)
  40.     if bInfo[id] then
  41.         colsT = {colors.green,colors.gray}
  42.     else
  43.         colsT = {colors.gray,colors.red}
  44.     end
  45.     bMon.setCursorPos(pos[1]+10,pos[2])
  46.     bMon.setBackgroundColor(colsT[1])
  47.     bMon.write("    ")
  48.     bMon.setCursorPos(pos[1]+11,pos[2])
  49.     bMon.write(" ON ")
  50.    
  51.     bMon.setCursorPos(pos[1]+16,pos[2])
  52.     bMon.setBackgroundColor(colsT[2])
  53.     bMon.write("     ")
  54.     bMon.setCursorPos(pos[1]+17,pos[2])
  55.     bMon.write(" OFF ")
  56.  bMon.setBackgroundColor(colors.black)
  57. end
  58. function toRead(l)
  59.   local pow = math.floor(math.log(l)/math.log(1000))
  60.   local temp = {"","K","M","B","T"}
  61.   return (math.ceil( ( ( l/ (1000^pow) )*100 )-0.5)/100)..temp[pow+1]
  62. end
  63.  
  64. function drawGauge(i,n,pos)
  65.     local tur = turbines[i]
  66.     --local mon = monitors[m]
  67.     --mon.setTextScale(0.5)
  68.     if tur.getActive() then
  69.       act = 1
  70.     else
  71.       act = 2
  72.     end
  73.     local RPM = tur.getRotorSpeed()
  74.     local energyLastTick = tur.getEnergyProducedLastTick()
  75.     local enT = ""
  76.     if energyLastTick<1000 then
  77.         enT = math.ceil(energyLastTick-0.5).."RF/t"
  78.     else
  79.         enT = (math.ceil((energyLastTick/10)-0.5)/100).."kRF/t"
  80.     end
  81.     local flowRate = tur.getFluidFlowRate()
  82.     if tur.getInductorEngaged() then
  83.         coils = "Engaged"
  84.     else
  85.         coils = "Disengaged"
  86.     end
  87.    
  88.     --[[local RPMp = math.ceil(((RPM/2000) * 30) - 0.5)
  89.     mon.setTextColor(colors.black)
  90.     for y = 0,31 do
  91.         if y/3 == math.ceil(y/3) then
  92.           txt = math.ceil((y/30)*2000).." "
  93.           posx = pos[1] - (#txt-1)
  94.         else
  95.           posx = pos[1]
  96.           txt = " "
  97.         end
  98.         mon.setCursorPos(posx,pos[2]+(32-y))
  99.         mon.setBackgroundColor(colors.white)
  100.         mon.setTextColor(colors.black)
  101.         mon.write(txt)
  102.     if y==0 or y == 31 then
  103.         mon.setBackgroundColor(colors.white)
  104.     elseif y<=RPMp then
  105.         mon.setBackgroundColor(cols[c[y] ])
  106.     else
  107.         mon.setBackgroundColor(colors.black)
  108.     end
  109.     mon.setTextColor(colors.white)
  110.     mon.write(string.rep(" ",8))
  111.     mon.setBackgroundColor(colors.white)
  112.     mon.write(" ")
  113.     mon.setBackgroundColor(colors.black)
  114.     end ]]--
  115.     local m3 = monitors[n]
  116.     info = {dir[i],math.ceil(RPM-0.5).."RPM",enT,flowRate.."Mb/t",coils}
  117.     for l = 1,#info do
  118.         m3.setBackgroundColor(cmode[act])
  119.         m3.setCursorPos(-9+(i*12),l+2)
  120.         m3.write(string.rep(" ",10))
  121.         m3.setCursorPos(-9+(i*12),l+2)
  122.         m3.write(info[l])
  123.         m3.setBackgroundColor(colors.black)
  124.     end
  125.    
  126. end
  127.  
  128. while true do
  129.     Lclock = Lclock + 1
  130.     if Lclock >= 8 then Lclock = 0 end
  131.     --Turbines
  132.     --monitors[1].setBackgroundColor(colors.black)
  133.     --monitors[1].clear()
  134.     local m2 = monitors[1]
  135.     m2.clear()
  136.     m2.setCursorPos(4,1)
  137.     m2.write("Turbine Information")
  138.     m2.setTextScale(1.5)
  139.     for i=1,2 do
  140.         drawGauge(i,1,{-13+(i*32),3})
  141.     end
  142.    
  143.    
  144.     --Reactor
  145.     local Active = r.getActive()
  146.     rMon.setTextColor(colors.white)
  147.     if Active and not rActive then
  148.         if startupState == 0 then
  149.           rMon.clear()
  150.         end
  151.         startupState = startupState + 1
  152.         if startupState <12 then
  153.             if startupState/2 ~= math.ceil(startupState/2) then
  154.                 local line = (startupState+1 )/ 2
  155.                 rMon.setTextColor(colors.white)
  156.                 rMon.setCursorPos(1,line)
  157.                 rMon.write(sInfo[line])
  158.             else
  159.                 rMon.setTextColor(colors.green)
  160.                 rMon.write("Active")
  161.             end
  162.         elseif startupState<15 then
  163.             rMon.write(".")
  164.         elseif startupState == 16 then
  165.             rMon.setCursorPos(1,8)
  166.             rMon.write("Successful!")
  167.         end
  168.         if startupState == 18 then
  169.             startupState = 0
  170.             rActive = true
  171.             for i=1,2 do bInfo[i+1] = true end
  172.         end
  173.     else
  174.         rMon.clear()
  175.     end
  176.    
  177.     if rActive and not Active then
  178.         rActive = false
  179.         for i=1,2 do bInfo[i+1] = false end
  180.     end
  181.    
  182.     if rActive then
  183.     rMon.clear()
  184.         rMon.setTextScale(1)
  185.         rMon.setTextColor(colors.white)
  186.         rMon.setCursorPos(15,1)
  187.         rMon.write("Reactor Information")
  188.         rMon.setCursorPos(6,3)
  189.         rMon.write("Reactor Status: ")
  190.         rMon.setTextColor(colors.green)
  191.               rMon.setCursorPos(32,3)
  192.         rMon.write("ONLINE")
  193.         local En = 0
  194.         local enD = ""
  195.         for i=1,2 do En = En+turbines[i].getEnergyProducedLastTick() end
  196.         enD = toRead(En).."rf/t"
  197.         local rInfo = {
  198.             "Fuel Amount: ",r.getFuelAmount().."mB ("..(math.ceil((r.getFuelAmount()/r.getFuelAmountMax()*100)-0.5)).."%)",
  199.             "Waste Amount: ",r.getWasteAmount().."mB ("..(math.ceil((r.getWasteAmount()/10)-0.5)).."%)",
  200.             "Water Amount: ",r.getCoolantAmount().."mB ("..(math.ceil((r.getCoolantAmount()/r.getCoolantAmountMax()*100)-0.5)).."%)",
  201.             "Steam Amount: ",r.getHotFluidAmount().."mB ("..(math.ceil((r.getHotFluidAmount()/r.getHotFluidAmountMax()*100)-0.5)).."%)",
  202.             "Core/Casing Temper: ",math.ceil(r.getCasingTemperature()-0.5).." / "..math.ceil(r.getFuelTemperature()-0.5),
  203.             "Fuel Used/tick: ",math.ceil(r.getFuelConsumedLastTick()-0.5).."mB/t",
  204.             "Steam Produced/tick: ",math.ceil(r.getHotFluidProducedLastTick()-0.5).."mB/t",
  205.             "Fuel Reactivity: ",math.ceil(r.getFuelReactivity()-0.5).."%",
  206.             "Total Energy/tick: ",enD
  207.         }
  208.         for i=1,#rInfo do
  209.             if i/2 ~= math.ceil(i/2) then
  210.                 line = (i+1)/2
  211.                 rMon.setCursorPos(6,line+3)
  212.                 rMon.setTextColor(colors.white)
  213.             else
  214.                 line = (i)/2
  215.                 rMon.setCursorPos(32,line+3)
  216.                 rMon.setTextColor(colors.green)
  217.             end
  218.             rMon.write(rInfo[i])
  219.         end
  220.         st = core.getEnergyStored()
  221.         ma = core.getMaxEnergyStored()
  222.         stored = toRead(st)
  223.         max = toRead(ma)
  224.         rMon.setBackgroundColor(colors.black)
  225.         rMon.setCursorPos(4,15)
  226.         rMon.write(stored.."rf / "..max.."rf ("..math.ceil(((st/ma)*100)-0.5).."%)")
  227.         pStored = math.ceil(((st/ma)*30)-0.5)
  228.         for i=1,3 do
  229.             rMon.setCursorPos(3,15+i)
  230.             if i==2 then
  231.                 rMon.write(" ")
  232.                 rMon.setBackgroundColor(colors.blue)
  233.                 rMon.write(string.rep(" ",pStored))
  234.                 rMon.setBackgroundColor(colors.black)
  235.                 rMon.write(string.rep(" ",30-pStored))
  236.                 rMon.setBackgroundColor(colors.gray)
  237.                 rMon.write(" ")
  238.             else
  239.                 rMon.setBackgroundColor(colors.gray)
  240.                 rMon.write(string.rep(" ",32))
  241.             end
  242.         end
  243.         rMon.setBackgroundColor(colors.black)
  244.         enLastTick = (st - prev[1])
  245.         for i=1,#prev-1 do
  246.             enLastTick = enLastTick + (prev[i]-prev[i+1])
  247.         end
  248.         enLastTick = enLastTick / #prev
  249.         if enLastTick>0 then
  250.             enToFill = ma-st
  251.             ticksToFill = enToFill/enLastTick
  252.             minsToFill = "ETA to fill: "..math.ceil((ticksToFill/(20*60))-0.5).." minutes"
  253.         else
  254.             minsToFill = "ETA to fill: Infinity"
  255.         end
  256.         rMon.setCursorPos(4,19)
  257.         rMon.write(minsToFill)
  258.         table.insert(prev, 1, core.getEnergyStored())
  259.         table.remove(prev, 6)
  260.     else
  261.         if not Active then
  262.             if Lclock < 4 then
  263.                 rMon.setTextColor(colors.red)
  264.                 rMon.setTextScale(4)
  265.                 rMon.setCursorPos(4,2)
  266.                 rMon.write("REACTOR")
  267.                 rMon.setCursorPos(4,3)
  268.                 rMon.write("OFFLINE")
  269.             end
  270.         end
  271.     end
  272.     bMon.clear()
  273.     bMon.setCursorPos(21,1)
  274.     bMon.write("Controls")
  275.     drawButton(1,"Reactor:",{13,2})
  276.     bMon.setCursorPos(21,3)
  277.     bMon.write("Turbines")
  278.     bMon.setCursorPos(10,4)
  279.     bMon.write("Upper                    Lower")
  280.     drawButton(2,"Active:",{3,5})
  281.     drawButton(3,"Active:",{28,5})
  282.     drawButton(4,"Coils:",{3,6})
  283.     drawButton(5,"Coils:",{28,6})
  284.     r.setActive(bInfo[1])
  285.     for i=1,2 do turbines[i].setActive(bInfo[i+1]) end
  286.     for i=1,2 do turbines[i].setInductorEngaged(bInfo[i+3]) end
  287.     os.startTimer(0.35)
  288.     while true do
  289.         local evt = {os.pullEvent()}
  290.         if evt[1] == "timer" then
  291.             break
  292.         elseif evt[1] == "monitor_touch" then
  293.             if evt[2] == "monitor_43" and redstone.getInput("right") == true then
  294.                 local x = evt[3]
  295.                 local y = evt[4]
  296.                 if y==2 then
  297.                     if x>=23 and x<=26 then
  298.                         bInfo[1] = true
  299.                     elseif x>=29 and x<=33 then
  300.                         bInfo[1] = false
  301.                     end
  302.                 elseif y==5 then
  303.                     if x>=13 and x<=16 then
  304.                         bInfo[2] = true
  305.                     elseif x>=19 and x<=23 then
  306.                         bInfo[2] = false
  307.                     elseif x>=38 and x<=41 then
  308.                         bInfo[3] = true
  309.                     elseif x>=44 and x<=48 then
  310.                         bInfo[3] = false
  311.                     end
  312.                 elseif y==6 then
  313.                     if x>=13 and x<=16 then
  314.                         bInfo[4] = true
  315.                     elseif x>=19 and x<=23 then
  316.                         bInfo[4] = false
  317.                     elseif x>=38 and x<=41 then
  318.                         bInfo[5] = true
  319.                     elseif x>=44 and x<=48 then
  320.                         bInfo[5] = false
  321.                     end
  322.                 end
  323.             end
  324.         end
  325.     end
  326. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement