Advertisement
Guest User

RC.lua

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.24 KB | None | 0 0
  1. local event = require("event")
  2. local component = require("component")
  3. local reactor = component.energy_device
  4. local sides = require("sides")
  5. -- --> local invSide = sides.east
  6. local invSide = sides.east
  7. local redstone = component.proxy(component.get("b436fc9f-1ef7-4de1-8542-131987723bb8"))
  8. local menet4 = component.proxy(component.get("49ac5fca-f841-43b6-970c-c3cf0688b13a"))
  9. local menet2 = component.proxy(component.get("1e64797f-db1f-4986-a3d8-231ddeb665cd"))
  10. local menet1 = component.proxy(component.get("d29efd26-9546-47bc-8bb6-5d0c41807466"))
  11. local gpu = component.gpu
  12. local w, h = gpu.getResolution()
  13. local inv = component.inventory_controller
  14. local invs = inv.getInventorySize(invSide)
  15. local power = 0
  16. local changing = false
  17. local lzhs = {}
  18. local li=1
  19. local rshs = {}
  20. local si=1
  21. local rods4 = {}
  22. local ri4=1
  23. local rods2 = {}
  24. local ri2=1
  25. local rods1 = {}
  26. local ri1=1
  27. local vents = {}
  28. local vi=1
  29. local ahes = {}
  30. local ai=1
  31. local ohes = {}
  32. local oi=1
  33. local hes = {}
  34. local hi=1
  35. local tnrs={}
  36. local ti=1
  37. local nrs={}
  38. local ni=1
  39. local c1s = {}
  40. local c1i=1
  41. local c3s = {}
  42. local c3i=1
  43. local c6s = {}
  44. local c6i=1
  45. local warn=false
  46. local args={...}
  47. local eutarget=2000
  48. local preveu=nil
  49. if #args>0 then
  50.   eutarget=tonumber(args[1])
  51. end
  52.  
  53. local prevb=0x000000
  54. function setGpuB(b)
  55.   if b~=prevb then
  56.     gpu.setBackground(b)
  57.     prevb=b
  58.   end
  59. end
  60.  
  61. local prevf=0x000000
  62. function setGpuF(f)
  63.   if f~=prevf then
  64.     gpu.setForeground(f)
  65.     prevf=f
  66.   end
  67. end
  68.  
  69. function getElement(pos)
  70.   local l=" "
  71.   if inv.getStackInSlot(invSide,pos) then
  72.     l=inv.getStackInSlot(invSide,pos)
  73.   end
  74.   return l
  75. end
  76.  
  77. local redDmg={}
  78. local blackDmg={}
  79.  
  80. function drawDmg()
  81.   if redDmg and #redDmg>0 then
  82.     setGpuB(0xFF0000)
  83.     for k,t in pairs(redDmg) do
  84.       gpu.set(t[2],t[1],string.rep(" ",t[3]))
  85.     end
  86.   end
  87.   if blackDmg and #blackDmg>0 then
  88.     setGpuB(0x1E1E1E)
  89.     for k,t in pairs(blackDmg) do
  90.       gpu.set(t[2],t[1],string.rep(" ",t[3]))
  91.     end
  92.   end
  93. end
  94.  
  95. function fillDmg(i,j,el,dmg)
  96.   if el=="LZH" then
  97.     dmg=(100000-dmg)/10000
  98.   elseif el=="Rod" or el=="RSH" then
  99.     dmg=(20000-dmg)/2000
  100.   elseif el=="Vent" then
  101.     dmg=(1000-dmg)/100
  102.   elseif el=="AHE" then
  103.     dmg=(10000-dmg)/1000
  104.   elseif el=="OHE" then
  105.     dmg=(5000-dmg)/500
  106.   elseif el=="HE" then
  107.     dmg=(2500-dmg)/250
  108.   elseif el=="TNR" then
  109.     dmg=(120000-dmg)/12000
  110.   elseif el=="NR" then
  111.     dmg=(30000-dmg)/3000
  112.   elseif el=="C1" then
  113.     dmg=(10000-dmg)/1000
  114.   elseif el=="C3" then
  115.     dmg=(30000-dmg)/3000
  116.   elseif el=="C6" then
  117.     dmg=(60000-dmg)/6000
  118.   end
  119.   if dmg>0 then
  120.     table.insert(redDmg,{i+5,j+2,dmg})
  121.     if dmg<10 then
  122.       table.insert(blackDmg,{i+5,j+2+dmg,11-dmg})
  123.     end
  124.   else
  125.     table.insert(blackDmg,{i+5,j+2,10})
  126.   end
  127. --[[  setGpuB(0xFF0000)
  128.   gpu.set(j+2,i+5,string.rep(" ",dmg))
  129.   if dmg<10 then
  130.     setGpuB(0x1E1E1E)
  131.     gpu.set(j+2+dmg,i+5,string.rep(" ",10-dmg))
  132.   end]]
  133. end
  134.  
  135. function stopme()
  136.   coroutine.yield()
  137.   return 0
  138. end
  139.  
  140. function checkDmg()
  141.   redDmg={}
  142.   blackDmg={}
  143.   local dmg=0
  144.   local needy=0
  145.   local elem
  146.  
  147.   for i=1,li-1,1 do
  148.     elem=inv.getStackInSlot(invSide,lzhs[i][3])
  149.     if elem then
  150.       fillDmg(lzhs[i][1],lzhs[i][2],"LZH",elem.customDamage)
  151.     else
  152.       fillDmg(lzhs[i][1],lzhs[i][2],"LZH",100000)
  153.     end
  154.     needy=needy+1
  155.     if needy>18 then
  156.       needy=stopme()
  157.     end
  158.   end
  159.  
  160.   for i=1,si-1,1 do
  161.     elem=inv.getStackInSlot(invSide,rshs[i][3])
  162.     if elem then
  163.       fillDmg(rshs[i][1],rshs[i][2],"RSH",elem.customDamage)
  164.     else
  165.       fillDmg(rshs[i][1],rshs[i][2],"RSH",20000)
  166.     end
  167.     needy=needy+1
  168.     if needy>18 then
  169.       needy=stopme()
  170.     end
  171.   end
  172.  
  173.   for i=1,ri4-1,1 do
  174.     elem=inv.getStackInSlot(invSide,rods4[i][3])
  175.     if elem and not string.match(elem.label,"Depleted") then
  176.       fillDmg(rods4[i][1],rods4[i][2],"Rod",elem.customDamage)
  177.     else
  178.       fillDmg(rods4[i][1],rods4[i][2],"Rod",20000)
  179.     end
  180.     needy=needy+1
  181.     if needy>18 then
  182.       needy=stopme()
  183.     end
  184.   end
  185.   for i=1,ri2-1,1 do
  186.     elem=inv.getStackInSlot(invSide,rods2[i][3])
  187.     if elem and not string.match(elem.label,"Depleted") then
  188.       fillDmg(rods2[i][1],rods2[i][2],"Rod",elem.customDamage)
  189.     else
  190.       fillDmg(rods2[i][1],rods2[i][2],"Rod",20000)
  191.     end
  192.     needy=needy+1
  193.     if needy>18 then
  194.       needy=stopme()
  195.     end
  196.   end
  197.   for i=1,ri1-1,1 do
  198.     elem=inv.getStackInSlot(invSide,rods1[i][3])
  199.     if elem and not string.match(elem.label,"Depleted") then
  200.       fillDmg(rods1[i][1],rods1[i][2],"Rod",elem.customDamage)
  201.     else
  202.       fillDmg(rods1[i][1],rods1[i][2],"Rod",20000)
  203.     end
  204.     needy=needy+1
  205.     if needy>18 then
  206.       needy=stopme()
  207.     end
  208.   end
  209.  
  210.   for i=1,vi-1,1 do
  211.     elem=inv.getStackInSlot(invSide,vents[i][3])
  212.     if elem then
  213.       fillDmg(vents[i][1],vents[i][2],"Vent",elem.customDamage)
  214.     else
  215.       fillDmg(vents[i][1],vents[i][2],"Vent",1000)
  216.     end
  217.     needy=needy+1
  218.     if needy>18 then
  219.       needy=stopme()
  220.     end
  221.   end
  222.  
  223.   for i=1,ai-1,1 do
  224.     elem=inv.getStackInSlot(invSide,ahes[i][3])
  225.     if elem then
  226.       fillDmg(ahes[i][1],ahes[i][2],"AHE",elem.customDamage)
  227.     else
  228.       fillDmg(ahes[i][1],ahes[i][2],"AHE",10000)
  229.     end
  230.     needy=needy+1
  231.     if needy>18 then
  232.       needy=stopme()
  233.     end
  234.   end
  235.  
  236.   for i=1,oi-1,1 do
  237.     elem=inv.getStackInSlot(invSide,ohes[i][3])
  238.     if elem then
  239.       fillDmg(ohes[i][1],ohes[i][2],"OHE",elem.customDamage)
  240.     else
  241.       fillDmg(ohes[i][1],ohes[i][2],"OHE",5000)
  242.     end
  243.     needy=needy+1
  244.     if needy>18 then
  245.       needy=stopme()
  246.     end
  247.   end
  248.  
  249.   for i=1,hi-1,1 do
  250.     elem=inv.getStackInSlot(invSide,hes[i][3])
  251.     if elem then
  252.       fillDmg(hes[i][1],hes[i][2],"HE",elem.customDamage)
  253.     else
  254.       fillDmg(hes[i][1],hes[i][2],"HE",2500)
  255.     end
  256.     needy=needy+1
  257.     if needy>18 then
  258.       needy=stopme()
  259.     end
  260.   end
  261.  
  262.   for i=1,ti-1,1 do
  263.     elem=inv.getStackInSlot(invSide,tnrs[i][3])
  264.     if elem then
  265.       fillDmg(tnrs[i][1],tnrs[i][2],"TNR",elem.customDamage)
  266.     else
  267.       fillDmg(tnrs[i][1],tnrs[i][2],"TNR",120000)
  268.     end
  269.     needy=needy+1
  270.     if needy>18 then
  271.       needy=stopme()
  272.     end
  273.   end
  274.  
  275.   for i=1,ni-1,1 do
  276.     elem=inv.getStackInSlot(invSide,nrs[i][3])
  277.     if elem then
  278.       fillDmg(nrs[i][1],nrs[i][2],"NR",elem.customDamage)
  279.     else
  280.       fillDmg(nrs[i][1],nrs[i][2],"NR",30000)
  281.     end
  282.     needy=needy+1
  283.     if needy>18 then
  284.       needy=stopme()
  285.     end
  286.   end
  287.  
  288.   for i=1,c1i-1,1 do
  289.     elem=inv.getStackInSlot(invSide,c1s[i][3])
  290.     if elem then
  291.       fillDmg(c1s[i][1],c1s[i][2],"C1",elem.customDamage)
  292.     else
  293.       fillDmg(c1s[i][1],c1s[i][2],"C1",10000)
  294.     end
  295.     needy=needy+1
  296.     if needy>18 then
  297.       needy=stopme()
  298.     end
  299.   end
  300.  
  301.   for i=1,c3i-1,1 do
  302.     elem=inv.getStackInSlot(invSide,c3s[i][3])
  303.     if elem then
  304.       fillDmg(c3s[i][1],c3s[i][2],"C3",elem.customDamage)
  305.     else
  306.       fillDmg(c3s[i][1],c3s[i][2],"C3",30000)
  307.     end
  308.     needy=needy+1
  309.     if needy>18 then
  310.       needy=stopme()
  311.     end
  312.   end
  313.  
  314.   for i=1,c6i-1,1 do
  315.     elem=inv.getStackInSlot(invSide,c6s[i][3])
  316.     if elem then
  317.       fillDmg(c6s[i][1],c6s[i][2],"C6",elem.customDamage)
  318.     else
  319.       fillDmg(c6s[i][1],c6s[i][2],"C6",60000)
  320.     end
  321.     needy=needy+1
  322.     if needy>18 then
  323.       needy=stopme()
  324.     end
  325.   end
  326.  
  327.   drawDmg()
  328. end
  329.  
  330. function fillElement(i,j,el,pos)
  331.   local j1=9+j
  332.   local i1=2+i
  333.   pos=pos or 1
  334.   local l=" "
  335.   if el.label then
  336.     l=el.label
  337.   end
  338.   if el=="X" then
  339.     setGpuB(0x696969)
  340.     setGpuF(0x3C3C3C)
  341.     gpu.set(j1+1,i1,"\")
  342.     gpu.set(j1+11,i1,"/")
  343.     gpu.set(j1+3,i1+1,"\")
  344.     gpu.set(j1+9,i1+1,"/")
  345.     gpu.set(j1+5,i1+2,"\")
  346.     gpu.set(j1+7,i1+2,"/")
  347.     gpu.set(j1+7,i1+3,"\")
  348.     gpu.set(j1+5,i1+3,"/")
  349.     gpu.set(j1+9,i1+4,"\")
  350.     gpu.set(j1+3,i1+4,"/")
  351.     gpu.set(j1+11,i1+5,"\")
  352.     gpu.set(j1+1,i1+5,"/")
  353.   elseif el=="0" then
  354.     gpu.set(j1+1,i1,"══════")
  355.     gpu.set(j1+1,i1+5,"══════")
  356.     gpu.set(j1,i1+1,"║║║║",true)
  357.     gpu.set(j1+7,i1+1,"║║║║",true)
  358.   elseif el=="1" then
  359.     gpu.set(j1+7,i1+1,"║║║║",true)
  360.   elseif el=="2" then
  361.     gpu.set(j1+1,i1,"══════")
  362.     gpu.set(j1+1,i1+2,"══════")
  363.     gpu.set(j1+1,i1+5,"══════")
  364.     gpu.set(j1,i1+3,"║║",true)
  365.     gpu.set(j1+7,i1+1,"║")
  366.   elseif el=="3" then
  367.     gpu.set(j1+1,i1,"══════")
  368.     gpu.set(j1+1,i1+2,"══════")
  369.     gpu.set(j1+1,i1+5,"══════")
  370.     gpu.set(j1+7,i1+3,"║║",true)
  371.     gpu.set(j1+7,i1+1,"║")
  372.   elseif el=="4" then
  373.     gpu.set(j1+1,i1+2,"══════")
  374.     gpu.set(j1,i1+1,"║")
  375.     gpu.set(j1+7,i1+1,"║")
  376.     gpu.set(j1+7,i1+3,"║║",true)
  377.   elseif el=="5" then
  378.     gpu.set(j1+1,i1,"══════")
  379.     gpu.set(j1+1,i1+2,"══════")
  380.     gpu.set(j1+1,i1+5,"══════")
  381.     gpu.set(j1,i1+1,"║")
  382.     gpu.set(j1+7,i1+3,"║║",true)
  383.   elseif el=="6" then
  384.     gpu.set(j1+1,i1,"══════")
  385.     gpu.set(j1+1,i1+2,"══════")
  386.     gpu.set(j1+1,i1+5,"══════")
  387.     gpu.set(j1,i1+1,"║")
  388.     gpu.set(j1,i1+3,"║║",true)
  389.     gpu.set(j1+7,i1+3,"║║",true)
  390.   elseif el=="7" then
  391.     gpu.set(j1+1,i1,"══════")
  392.     gpu.set(j1+7,i1+1,"║║║║",true)
  393.   elseif el=="8" then
  394.     gpu.set(j1+1,i1,"══════")
  395.     gpu.set(j1+1,i1+2,"══════")
  396.     gpu.set(j1+1,i1+5,"══════")
  397.     gpu.set(j1,i1+1,"║")
  398.     gpu.set(j1+7,i1+1,"║")
  399.     gpu.set(j1,i1+3,"║║",true)
  400.     gpu.set(j1+7,i1+3,"║║",true)
  401.   elseif el=="9" then
  402.     gpu.set(j1+1,i1,"══════")
  403.     gpu.set(j1+1,i1+2,"══════")
  404.     gpu.set(j1+1,i1+5,"══════")
  405.     gpu.set(j1,i1+1,"║")
  406.     gpu.set(j1+7,i1+3,"║║",true)
  407.     gpu.set(j1+7,i1+1,"║")
  408.   elseif string.match(l,"LZH") then
  409.     setGpuB(0x0000C0)
  410.     gpu.fill(j1+1,i1+1,12,4," ")
  411.     lzhs[li]={i1,j1,pos}
  412.     li=li+1
  413.   elseif string.match(l,"RSH") then
  414.     setGpuB(0xC00000)
  415.     gpu.fill(j1+1,i1+1,12,4," ")
  416.     rshs[si]={i1,j1,pos}
  417.     si=si+1
  418.   elseif string.match(l,"Quad") then
  419.     if string.match(l,"MOX") then
  420.       setGpuB(0x66B680)
  421.     else
  422.       setGpuB(0x006D00)
  423.     end
  424.     gpu.fill(j1+1,i1+1,2,4," ")
  425.     gpu.fill(j1+4,i1+1,2,4," ")
  426.     gpu.fill(j1+8,i1+1,2,4," ")
  427.     gpu.fill(j1+11,i1+1,2,4," ")
  428.     rods4[ri4]={i1,j1,pos}
  429.     ri4=ri4+1
  430.   elseif string.match(l,"Dual") then
  431.     if string.match(l,"MOX") then
  432.       setGpuB(0x66B680)
  433.     else
  434.       setGpuB(0x006D00)
  435.     end
  436.     gpu.fill(j1+4,i1+1,2,4," ")
  437.     gpu.fill(j1+8,i1+1,2,4," ")
  438.     rods2[ri2]={i1,j1,pos}
  439.     ri2=ri2+1
  440.   elseif string.match(l,"Rod") then
  441.     if string.match(l,"MOX") then
  442.       setGpuB(0x66B680)
  443.     else
  444.       setGpuB(0x006D00)
  445.     end
  446.     gpu.fill(j1+6,i1+1,2,4," ")
  447.     rods1[ri1]={i1,j1,pos}
  448.     ri1=ri1+1
  449.   elseif string.match(l,"Advanced Heat Vent") then
  450.     setGpuB(0x33B6FF)
  451.     gpu.fill(j1+1,i1+1,12,4," ")
  452.     vents[vi]={i1,j1,pos}
  453.     vi=vi+1
  454.   elseif string.match(l,"Overclocked") then
  455.     setGpuB(0xFFFF40)
  456.     gpu.fill(j1+1,i1+1,12,4," ")
  457.     vents[vi]={i1,j1,pos}
  458.     vi=vi+1
  459.   elseif string.match(l,"Component Heat Vent") then
  460.     setGpuB(0xE1E1E1)
  461.     gpu.fill(j1+1,i1+1,12,4," ")
  462.   elseif string.match(l,"Reactor Heat Vent") then
  463.     setGpuB(0xFF6D00)
  464.     gpu.fill(j1+1,i1+1,12,4," ")
  465.     vents[vi]={i1,j1,pos}
  466.     vi=vi+1
  467.   elseif string.match(l,"Heat Vent") then
  468.     setGpuB(0xA5A5A5)
  469.     gpu.fill(j1+1,i1+1,12,4," ")
  470.     vents[vi]={i1,j1,pos}
  471.     vi=vi+1
  472.   elseif string.match(l,"Advanced Heat Exchanger") then
  473.     setGpuB(0xE1E1E1)
  474.     gpu.fill(j1+1,i1+1,12,4," ")
  475.     setGpuB(0x33B6FF)
  476.     gpu.fill(j1+3,i1+2,8,2," ")
  477.     ahes[ai]={i1,j1,pos}
  478.     ai=ai+1
  479.   elseif string.match(l,"Component Heat Exchanger") then
  480.     setGpuB(0xE1E1E1)
  481.     gpu.fill(j1+1,i1+1,12,4," ")
  482.     setGpuB(0xFFFF40)
  483.     gpu.fill(j1+3,i1+2,8,2," ")
  484.     ohes[oi]={i1,j1,pos}
  485.     oi=oi+1
  486.   elseif string.match(l,"Reactor Heat Exchanger") then
  487.     setGpuB(0xE1E1E1)
  488.     gpu.fill(j1+1,i1+1,12,4," ")
  489.     setGpuB(0xFF6D00)
  490.     gpu.fill(j1+3,i1+2,8,2," ")
  491.     ohes[oi]={i1,j1,pos}
  492.     oi=oi+1
  493.   elseif string.match(l,"Heat Exchanger") then
  494.     setGpuB(0xE1E1E1)
  495.     gpu.fill(j1+1,i1+1,12,4," ")
  496.     setGpuB(0xA5A5A5)
  497.     gpu.fill(j1+3,i1+2,8,2," ")
  498.     hes[hi]={i1,j1,pos}
  499.     hi=hi+1
  500.   elseif string.match(l,"Iridium") then
  501.     setGpuB(0xFFFFFF)
  502.     gpu.fill(j1+1,i1+1,12,4," ")
  503.   elseif string.match(l,"Thick") then
  504.     setGpuB(0xFFFFFF)
  505.     gpu.fill(j1+1,i1+1,12,4," ")
  506.     tnrs[ti]={i1,j1,pos}
  507.     ti=ti+1
  508.   elseif string.match(l,"Neutron") then
  509.     setGpuB(0xFFFFFF)
  510.     gpu.fill(j1+1,i1+1,12,4," ")
  511.     setGpuB(0xA5A5A5)
  512.     gpu.fill(j1+4,i1+2,6,2," ")
  513.     nrs[ni]={i1,j1,pos}
  514.     ni=ni+1
  515.   elseif string.match(l,"10k") then
  516.     setGpuB(0x0000C0)
  517.     gpu.fill(j1+6,i1+1,2,4," ")
  518.     c1s[c1i]={i1,j1,pos}
  519.     c1i=c1i+1
  520.   elseif string.match(l,"30k") then
  521.     setGpuB(0x0000C0)
  522.     gpu.fill(j1+3,i1+1,2,4," ")
  523.     gpu.fill(j1+6,i1+1,2,4," ")
  524.     gpu.fill(j1+9,i1+1,2,4," ")
  525.     c3s[c3i]={i1,j1,pos}
  526.     c3i=c3i+1
  527.   elseif string.match(l,"60k") then
  528.     setGpuB(0x0000C0)
  529.     gpu.set(j1+3,i1+1,"  ")
  530.     gpu.set(j1+6,i1+1,"  ")
  531.     gpu.set(j1+9,i1+1,"  ")
  532.     gpu.set(j1+3,i1+3,"  ")
  533.     gpu.set(j1+6,i1+3,"  ")
  534.     gpu.set(j1+9,i1+3,"  ")
  535.     c6s[c6i]={i1,j1,pos}
  536.     c6i=c6i+1
  537.   elseif string.match(l,"Containment") then
  538.     setGpuB(0x996D40)
  539.     gpu.fill(j1+1,i1+1,12,4," ")
  540.   elseif string.match(l,"Capacity") then
  541.     setGpuB(0xFF6D00)
  542.     gpu.fill(j1+1,i1+1,12,4," ")
  543.   elseif string.match(l,"Plating") then
  544.     setGpuB(0xB4B4B4)
  545.     gpu.fill(j1+1,i1+1,12,4," ")
  546.   end
  547. end
  548.  
  549. function drawReactor()
  550.   setGpuB(0x696969)
  551.   for i=2,37,7 do
  552.     for j=9,137,16 do
  553.       gpu.fill(j,i,14,6," ")
  554.     end
  555.   end
  556. end
  557.  
  558. function drawElement(i,j)
  559.   local i1=i/7
  560.   local j1=j/16+1
  561.   local pos=i1*9+j1
  562.   local s=(invs-4)/6
  563.   if s<9 then
  564.     for g=8,s,-1 do
  565.       local m=math.fmod(pos,g+1)
  566.       if m==0 then
  567.         fillElement(i,j,"X")
  568.         return
  569.       end
  570.       local d=(pos-m)/(g+1)
  571.       pos=pos-d
  572.     end
  573.   end
  574.   local el=getElement(pos)
  575.   fillElement(i,j,el,pos)
  576. end
  577.  
  578. function fillEU(eu)
  579.   if preveu==nil or eu~=preveu then
  580.     setGpuB(0x000000)
  581.     gpu.fill(88,44,72,6," ")
  582.     setGpuF(0x00B6FF)
  583.     local l = string.len(eu)
  584.     for i=l,1,-1 do
  585.       fillElement(42,140-(l-i)*10,string.sub(eu,i,i))
  586.     end
  587.     preveu=eu
  588.   end
  589. end
  590.  
  591. function fillPower(power)
  592.   if power>0 then
  593.     setGpuB(0x00FF00)
  594.   else
  595.     setGpuB(0xFF0000)
  596.   end
  597.   gpu.fill(2,45,14,5," ")
  598. end
  599.  
  600. function fillWarning(w)
  601.   setGpuB(w)
  602.   gpu.fill(18,45,14,5," ")
  603. end
  604.  
  605. local m4p=15
  606. local m2p=15
  607. local m1p=15
  608. menet4.setOutput(2,15)
  609. menet2.setOutput(2,15)
  610. menet1.setOutput(1,15)
  611. function rodsChanged()
  612.   for i=1,ri4-1,1 do
  613.     if not inv.getStackInSlot(invSide,rods4[i][3]) or (inv.getStackInSlot(invSide,rods4[i][3]) and string.match(inv.getStackInSlot(invSide,rods4[i][3]).label,"Depleted")) then
  614.       if m4p==15 then
  615.         m4p=0
  616.         m2p=15
  617.         m1p=15
  618.         menet4.setOutput(2,0)
  619.         menet2.setOutput(2,15)
  620.         menet1.setOutput(1,15)
  621.       end
  622.       return false
  623.     end
  624.   end
  625.   for i=1,ri2-1,1 do
  626.     if not inv.getStackInSlot(invSide,rods2[i][3]) or (inv.getStackInSlot(invSide,rods2[i][3]) and string.match(inv.getStackInSlot(invSide,rods2[i][3]).label,"Depleted")) then
  627.       if m2p==15 then
  628.         m4p=15
  629.         m2p=0
  630.         m1p=15
  631.         menet4.setOutput(2,15)
  632.         menet2.setOutput(2,0)
  633.         menet1.setOutput(1,15)
  634.       end
  635.       return false
  636.     end
  637.   end
  638.   for i=1,ri1-1,1 do
  639.     if not inv.getStackInSlot(invSide,rods1[i][3]) or (inv.getStackInSlot(invSide,rods1[i][3]) and string.match(inv.getStackInSlot(invSide,rods1[i][3]).label,"Depleted")) then
  640.       if m1p==15 then
  641.         m4p=15
  642.         m2p=15
  643.         m1p=0
  644.         menet4.setOutput(2,15)
  645.         menet2.setOutput(2,15)
  646.         menet1.setOutput(1,0)
  647.       end
  648.       return false
  649.     end
  650.   end
  651.   return true
  652. end
  653.  
  654. function continueWork()
  655.   if reactor.getHeat()>0 then
  656.     power=0
  657.     redstone.setOutput(1,power)
  658.     menet4.setOutput(2,15)
  659.     menet2.setOutput(2,15)
  660.     menet1.setOutput(1,15)
  661.     fillPower(power)
  662.     fillWarning(0xFFB600)
  663.     fillEU(0)
  664.     warn=true
  665.     return true
  666.   end
  667.   local eu = reactor.getReactorEUOutput()
  668.   if changing then
  669.     if not rodsChanged() then
  670.       return true --do nothing
  671.     else
  672.       changing=false
  673.       power=15
  674.       redstone.setOutput(1,power)
  675.       fillWarning(0x000000)
  676.     end
  677.   else
  678.     if eu<eutarget and power>0 then
  679.       changing=true
  680.       power=0
  681.       redstone.setOutput(1,power)
  682.       fillWarning(0x006D00)
  683.       fillEU(0)
  684.       return true
  685.     end
  686.   end
  687.   fillEU(eu)
  688.   --checkDmg()
  689.   return true
  690. end
  691.  
  692. function shutexit()
  693.   redstone.setOutput(1,0)
  694.   setGpuF(0xFFFFFF)
  695.   setGpuB(0x000000)
  696.   gpu.fill(1, 1, w, h, " ")
  697.   return false
  698. end
  699.  
  700. local myEventHandlers = setmetatable({}, { __index = function() return continueWork end })
  701.  
  702. function myEventHandlers.key_down(adress, char, code, playerName)
  703.   if code==57 then
  704.     if not changing then
  705.       if power==0 then
  706.         if warn then
  707.           warn=false
  708.           fillWarning(0x000000)
  709.         end
  710.         power=15
  711.       else
  712.         power=0
  713.       end
  714.       fillPower(power)
  715.       redstone.setOutput(1,power)
  716.     end
  717.   elseif code==46 then
  718.     return shutexit()
  719.   end
  720.   return true
  721. end
  722.  
  723. function myEventHandlers.interrupted(...)
  724.   return shutexit()
  725. end
  726.  
  727. function handleEvent(eventID, ...)
  728.   if (eventID) then
  729.     return myEventHandlers[eventID](...)
  730.   end
  731.   return continueWork()
  732. end
  733.  
  734. setGpuB(0xC3C3C3)
  735.  
  736. gpu.fill(1, 1, w, h-7, " ")
  737.  
  738. drawReactor()
  739. for i=0,35,7 do
  740.   for j=0,128,16 do
  741.     drawElement(i,j)
  742.   end
  743. end
  744.  
  745. if reactor.getReactorEUOutput()>0 then
  746.   power=15
  747. end
  748. fillPower(power)
  749.  
  750. td=coroutine.create(function()
  751.   while true do
  752.     checkDmg()
  753.     os.sleep(0)
  754.   end
  755. end)
  756.  
  757. while handleEvent(event.pull(1)) do
  758.   coroutine.resume(td)
  759. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement