Advertisement
Guest User

draw.lua

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