serafim7

bigreactors steam [OpenComputers]

Nov 8th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.09 KB | None | 0 0
  1. --http://computercraft.ru/topic/1894-opencomputers-bigreactors-turbine-reactorsteam/#entry34797
  2. --https://www.youtube.com/watch?v=nJkMO8Z_qdw
  3. --https://computercraft.ru/uploads/monthly_01_2017/post-18501-0-92836200-1485301753.png
  4. --https://computercraft.ru/uploads/monthly_01_2017/post-18501-0-36157800-1485301826.png
  5.  
  6. local term = require("term")
  7. local component = require("component")
  8. local computer = require("computer")
  9. local math = require("math")
  10. local event = require("event")
  11. local string = require("string")
  12. local unicode = require("unicode")
  13. local os = require("os")
  14. local fs = require('filesystem')
  15.  
  16. local gpu = component.gpu
  17. gpu.setResolution(100,50)
  18. br = component.getPrimary("br_reactor")
  19.  
  20. local boucle2 = 0
  21. local a = 80
  22. local b = 1
  23. local lvl
  24. local val = 0
  25. local rod = 1
  26. local nbrrod = br.getNumberOfControlRods()
  27.  
  28. local function setColor(bg,fg)
  29.   gpu.setBackground(bg)
  30.   gpu.setForeground(fg)
  31. end
  32.  
  33. local function loadbar(x,y,width,cur,text,bg,fg)
  34.   local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  35.   local oldbg = gpu.setBackground(bg)
  36.   local oldfg = gpu.setForeground(fg)
  37.   gpu.set(x,y,unicode.sub(raw,1,cur))
  38.   gpu.setBackground(oldbg)
  39.   gpu.setForeground(oldfg)
  40.   gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
  41. end
  42.  
  43. local function hexa(dec)
  44. local B,K,OUT,I,D = 16,"0123456789ABCDEF","",0
  45.   if dec <= 0 then
  46.     OUT = "00"
  47.   elseif dec > 0 and dec < 16 then
  48.     D = dec + 1
  49.     OUT = "0"..string.sub(K,D,D)
  50.   elseif dec > 16 and dec < 256 then
  51.     V1 = math.modf(dec/B)+1
  52.     V2 = dec-V1*16
  53.     OUT = string.sub(K,V1,V1)..string.sub(K,V2,V2)
  54.   elseif dec >= 255 then
  55.     OUT = "FF"
  56.   end
  57.   return OUT
  58. end
  59.  
  60. local function round(num, dec)
  61.   local mult = 10 ^ (dec or 0)
  62.   return math.floor(num * mult + 0.5) / mult
  63. end
  64.  
  65. local function affrod(x,y,l)
  66.   local rodv = rod + l -1
  67.   if rodv < 0 or rodv > nbrrod -1then
  68.     gpu.set(x,y,"                                         ")
  69.   else
  70.     local lvl = br.getControlRodLevel(rodv)
  71.     gpu.set(x,y,"СТЕРЖЕНЬ:"..string.format("% 2s",rodv + 1).."  / ГЛУБИНА ПОГРУЖЕНИЯ : "..string.format("% 3s",lvl).."%")
  72.   end
  73. end
  74.  
  75. local function control(x,y)
  76.   local lvl = br.getControlRodLevel(rod-1)
  77.   local rouge = math.floor((100-lvl)*255/50)
  78.   local vert = math.floor(lvl*255/50)
  79.   local color = hexa(rouge)..hexa(vert).."00"
  80.   local color2 = tonumber(string.format("%6s",color),16)
  81.   setColor(color2,0x0000FF)
  82.   gpu.set(22,48,string.format("% 3s",rod))
  83.   setColor(0x0, 0xFFFFFF)
  84.   affrod(x,y-6,-3)
  85.   affrod(x,y-4,-2)
  86.   affrod(x,y-2,-1)
  87.   setColor(0x00FF00,0x0000FF)
  88.   affrod(x,y,0)
  89.   setColor(0x000000,0xFFFFFF)
  90.   affrod(x,y+2,1)
  91.   affrod(x,y+4,2)
  92.   affrod(x,y+6,3)
  93. end
  94.  
  95. local function manualrod(x,y,rod)
  96.   local lvl
  97.     gpu.set(a,b,"╦═══════════════════╗")
  98.   gpu.set(a,b+1,"║ ГЛУБИНА СТЕРЖНЕЯ  ║")
  99.   gpu.set(a,b+2,"╠═══════════════════╣")
  100.   gpu.set(a,b+3,"║ НОМЕР      █100█  ║")
  101.   gpu.set(a,b+4,"║                   ║")
  102.   gpu.set(a,b+5,"║    █-10█   █+10█  ║")
  103.   gpu.set(a,b+6,"║                   ║")
  104.   gpu.set(a,b+7,"║    █-1 █   █+1 █  ║")
  105.   gpu.set(a,b+8,"║                   ║")
  106.   gpu.set(a,b+9,"║   ██████  ███████ ║")
  107.  gpu.set(a,b+10,"║   ОТМЕНА  ПРИНЯТЬ ║")
  108.  gpu.set(a,b+11,"║   ██████  ███████ ║")
  109.  gpu.set(a,b+12,"╚═══════════════════╣")
  110.   lvl = br.getControlRodLevel(rod-1)
  111.   gpu.set(a+12,b+3,string.format("% 3s",lvl))
  112.   gpu.set(a+8,b+3,string.format("% 2s",rod))
  113.   boucle2 = 1
  114. end
  115.  
  116. local function manualallrod()
  117.     gpu.set(a,b,"╦═══════════════════╗")
  118.   gpu.set(a,b+1,"║ ГЛУБИНА СТЕРЖНЕЙ  ║")
  119.   gpu.set(a,b+2,"╠═══════════════════╣")
  120.   gpu.set(a,b+3,"║ВСЕ СТЕРЖНИ █100█  ║")
  121.   gpu.set(a,b+4,"║                   ║")
  122.   gpu.set(a,b+5,"║    █-10█   █+10█  ║")
  123.   gpu.set(a,b+6,"║                   ║")
  124.   gpu.set(a,b+7,"║    █-1 █   █+1 █  ║")
  125.   gpu.set(a,b+8,"║                   ║")
  126.   gpu.set(a,b+9,"║   ██████ ███████  ║")
  127.  gpu.set(a,b+10,"║   ОТМЕНА ПРИНЯТЬ  ║")
  128.  gpu.set(a,b+11,"║   ██████ ███████  ║")
  129.  gpu.set(a,b+12,"╚═══════════════════╣")
  130.   gpu.set(a+12,b+3,string.format("% 3s",val))
  131.   boucle2 = 2
  132. end
  133.  
  134. local function manualoff()
  135.   boucle2 = 0
  136.     gpu.set(a,b,"════════════════════╗")
  137.   gpu.set(a,b+1,"                    ║")
  138.   gpu.set(a,b+2,"                    ║")
  139.   gpu.set(a,b+3,"                    ║")
  140.   gpu.set(a,b+4,"                    ║")
  141.   gpu.set(a,b+5,"                    ║")
  142.   gpu.set(a,b+6,"                    ║")
  143.   gpu.set(a,b+7,"                    ║")
  144.   gpu.set(a,b+8,"                    ║")
  145.   gpu.set(a,b+9,"                    ║")
  146.  gpu.set(a,b+10,"                    ║")
  147.  gpu.set(a,b+11,"                    ║")
  148.  gpu.set(a,b+12,"                    ║")
  149. end
  150.  
  151. local function bargraph(x,y,length,am,cap,na,col,colpol)
  152.   local amount = am
  153.   local capacity = cap
  154.   local pct = amount / capacity
  155.   local cur = math.floor(pct * length)
  156.   local color = col
  157.   local color2 = colpol
  158.   local name = na
  159.   local textfrac = string.format("%s / %s", amount, capacity)
  160.   local textpct = string.format("%.02f%%", pct*100)
  161.   local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 6) .. "   " .. textpct .. " "
  162.   local text1 = "              Уровень заполнения : ("..name..")"
  163.   loadbar(x,y,length,cur,text1,color,color2)
  164.   loadbar(x,y+1,length,cur,text,color,color2)
  165. end
  166.  
  167. function drawbars()
  168.   amFuel = br.getFuelAmount()
  169.   capFuel = br.getFuelAmountMax()
  170.   naFuel = "ТОПЛИВО - Yellorium"
  171.   colFuel = 0xFFFF00
  172.   colpolFuel = 0x0000FF
  173.   bargraph(2,22,98,amFuel,capFuel,naFuel,colFuel,colpolFuel)
  174.   amWaste = br.getWasteAmount()
  175.   capWaste = 64000
  176.   naWaste = "ОТХОДЫ - Cyanite"
  177.   colWaste = 0x00FFFF
  178.   colpolWaste = 0xFF00FF
  179.   bargraph(2,25,98,amWaste,capWaste,naWaste,colWaste,colpolWaste)
  180.   amSteam = br.getHotFluidAmount()
  181.   capSteam = br.getHotFluidAmountMax()
  182.   naSteam = "ПАР"
  183.   colSteam = 0x8F8F8F
  184.   colpolSteam = 0xFFFF00
  185.   bargraph(2,28,98,amSteam,capSteam,naSteam,colSteam,colpolSteam)
  186.   amWater = br.getCoolantAmount()
  187.   capWater = br.getCoolantAmountMax()
  188.   naWater = "ВОДА"
  189.   colWater = 0x71b6cb
  190.   colpolWater = 0x0000FF
  191.   bargraph(2,31,98,amWater,capWater,naWater,colWater,colpolWater)
  192.   consot = br.getFuelConsumedLastTick()
  193.   consos = consot * 20
  194.   consoh = consos * 3.6
  195.   consoj = consoh * 24  
  196.   gpu.set(2,35,string.format("% 1.03f",consot).."mb/t =>"..string.format("% 1.02f",consos).."mb/s =>"..string.format("% 3.02f",consoh).."b/h =>"..string.format("% 5.02f",consoj).."b/d")
  197.   Tcore = br.getCasingTemperature()
  198.   Tfuel = br.getFuelTemperature()
  199.   Reactivity = br.getFuelReactivity()
  200.   Prod = br.getHotFluidProducedLastTick()
  201.   gpu.set(35,38,string.format("% 4.2f",Tcore))
  202.   gpu.set(35,40,string.format("% 4.2f",Tfuel))
  203.   gpu.set(35,42,string.format("% 4.2f",Reactivity))
  204.   gpu.set(35,44,string.format("% 4.2f",Prod))
  205. end
  206.  
  207. local function waste()
  208. local waste = br.getWasteAmount()
  209.   if waste > 48000 then
  210.     br.doEjectWaste()
  211.   end
  212. end
  213.  
  214. local function marche(x,y)
  215.   gpu.set(x,y,"              ")
  216. gpu.set(x,y+1,"   ВКЛЮЧИТЬ   ")
  217. gpu.set(x,y+2,"              ")
  218. end
  219.  
  220. local function arret(x,y)
  221.   gpu.set(x,y,"              ")
  222. gpu.set(x,y+1,"   ВЫКЛЮЧИТЬ  ")
  223. gpu.set(x,y+2,"              ")
  224. end
  225.  
  226. local function start()
  227. local ON = br.getActive()
  228.   if ON == true then
  229.     setColor(0x00FF00,0x0)
  230.     marche(60,11)
  231.     setColor(0x0,0xFF0000)
  232.     arret(60,15)
  233.     setColor(0x0,0xFFFFFF)
  234.   elseif ON == false then
  235.     setColor(0x0,0x00FF00)
  236.     marche(60,11)
  237.     setColor(0xFF0000,0xFFFFFF)
  238.     arret(60,15)
  239.     setColor(0x0,0xFFFFFF)
  240.   end
  241. end
  242.  
  243. function allrods(val)
  244.   for i=0, nbrrod-1 do
  245.     level = br.getControlRodLevel(i)
  246.     newlevel = val + level
  247.     if newlevel > 100 then
  248.       newlevel = 100
  249.     elseif newlevel < 0 then
  250.       newlevel = 0
  251.     else
  252.       newlevel = level + val
  253.     end
  254.     br.setControlRodLevel(i,newlevel)
  255.   end
  256. end
  257.  
  258. term.clear()
  259.  gpu.set(1,1,"╔══════════════════════════════════════════════════════════════════════════════════════════════════╗")
  260.  gpu.set(1,2,"║                                                                                                  ║")
  261.  gpu.set(1,3,"║   ███████████████████████████████████████████████       ███████████████████                      ║")
  262.  gpu.set(1,4,"║   ██                                           ██       █ Ручной контроль █                      ║")
  263.  gpu.set(1,5,"║   ██                                           ██       █       всех      █                      ║")
  264.  gpu.set(1,6,"║   ██                                           ██       █     стержней    █                      ║")
  265.  gpu.set(1,7,"║   ██                                           ██       █                 █                      ║")
  266.  gpu.set(1,8,"║   ██                                           ██       ███████████████████                      ║")
  267.  gpu.set(1,9,"║   ██                                           ██                                                ║")
  268. gpu.set(1,10,"║   ██                                           ██                                                ║")
  269. gpu.set(1,11,"║   ██                                           ██        █████████████                           ║")
  270. gpu.set(1,12,"║   ██                                           ██        █ВКЛЮЧИТЬ  ██                           ║")
  271. gpu.set(1,13,"║   ██                                           ██        █████████████                           ║")
  272. gpu.set(1,14,"║   ██                                           ██                                                ║")
  273. gpu.set(1,15,"║   ██                                           ██        █████████████                           ║")
  274. gpu.set(1,16,"║   ██                                           ██        █ВЫКЛЮЧИТЬ ██                           ║")
  275. gpu.set(1,17,"║   ███████████████████████████████████████████████        █████████████                           ║")
  276. gpu.set(1,18,"║                                                                                                  ║")
  277. gpu.set(1,19,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  278. gpu.set(1,20,"║                                                                                                  ║")
  279. gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  280. gpu.set(1,22,"║                                                                                                  ║")
  281. gpu.set(1,23,"║                                                                                                  ║")
  282. gpu.set(1,24,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  283. gpu.set(1,25,"║                                                                                                  ║")
  284. gpu.set(1,26,"║                                                                                                  ║")
  285. gpu.set(1,27,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  286. gpu.set(1,28,"║                                                                                                  ║")
  287. gpu.set(1,29,"║                                                                                                  ║")
  288. gpu.set(1,30,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  289. gpu.set(1,31,"║                                                                                                  ║")
  290. gpu.set(1,32,"║                                                                                                  ║")
  291. gpu.set(1,33,"╠════════════════════════════════════════════════╦═════════════════════════════════════════════════╣")
  292. gpu.set(1,34,"║ РАСХОД ТОПЛИВА                                 ║  MiliBukket/second => mb/s   Bukket/Hour => b/h ║")
  293. gpu.set(1,35,"║                                                ║  MiliBukket/tick   => mb/t   Bukket/Day  => b/d ║")
  294. gpu.set(1,36,"╠════════════════════════════════════════════════╩══════════════════════╦══════════════════════════╣")
  295. gpu.set(1,37,"║                                                                       ║                          ║")
  296. gpu.set(1,38,"║    ТЕМПЕРАТУРА РЕАКТОРА       :           °C                          ║                          ║")
  297. gpu.set(1,39,"║                                                                       ║    ██████████████████    ║")
  298. gpu.set(1,40,"║    ТЕМПЕРАТУРА ТОПЛИВА        :           °C                          ║    ██   ИЗВЛЕЧЬ    ██    ║")
  299. gpu.set(1,41,"║                                                                       ║    ██   CYANITE    ██    ║")
  300. gpu.set(1,42,"║    РАДИОАКТИВНОСТЬ ТОПЛИВА    :           %                           ║    ██████████████████    ║")
  301. gpu.set(1,43,"║                                                                       ║                          ║")
  302. gpu.set(1,44,"║    ПЕРЕРАБОТКА ПАРА           :           mb/t                        ║    ██████████████████    ║")
  303. gpu.set(1,45,"╠═══════════════════════════════════════════════════════════════════════╣    ██   ИЗВЛЕЧЬ    ██    ║")
  304. gpu.set(1,46,"║   ВЫБОР СТЕРЖНЯ                                                       ║    ██  YELLORIUM   ██    ║")
  305. gpu.set(1,47,"║                                               ██████████████████      ║    ██████████████████    ║")
  306. gpu.set(1,48,"║   █ -10 █  █ -1 █  rod  █ +1 █  █ +10 █       ██ ИЗМЕНИТЬ ROD ██      ║                          ║")
  307. gpu.set(1,49,"║                                               ██████████████████      ║                          ║")
  308. gpu.set(1,50,"╚═══════════════════════════════════════════════════════════════════════╩══════════════════════════╝")
  309.  
  310. start()
  311.  
  312. local function onTouch(event,adress,x,y,clic,pseudo)
  313.   local tclic
  314.   if clic == 0  then
  315.     tclic = "НАЖИТО ЛКМ"
  316.   elseif clic == 1 then
  317.     tclic = "НАЖИТО ПКМ"
  318.   else
  319.     tclic = "НАЖИТО НЕИЗВЕСТНО"
  320.   end
  321.   gpu.set(6,20,"                "..tclic.." . ИГРОКОМ: "..pseudo.." ( X : "..string.format("% 3s",x).." Y: "..string.format("% 3s",y)..")")
  322.  
  323.   if x==1 and y==1 then
  324.       computer.pushSignal("quit")
  325.       term.setCursor(1,1)
  326.       return false
  327.      
  328.   elseif boucle2 == 0 then
  329.     if x > 48 and x < 67 and y > 46 and y < 50 then
  330.       manualrod(x,y,rod)
  331.       lvl = br.getControlRodLevel(rod-1)
  332.     elseif x > 58 and x < 78 and y > 2 and y < 9 then
  333.       manualallrod()
  334.     elseif x > 77 and x < 96 and y > 38 and y < 43 then
  335.       br.doEjectWaste()
  336.     elseif x > 77 and x < 96 and y > 43 and y < 48 then
  337.       br.doEjectFuel()
  338.     elseif x > 4 and x < 12 and y == 48 then
  339.       if rod < 9 then
  340.         rod = 0
  341.       else
  342.         rod = rod - 10
  343.       end
  344.     elseif x > 13 and x < 20 and y == 48 then
  345.       if rod < 1 then
  346.         rod = 0
  347.       else
  348.         rod = rod - 1
  349.       end    
  350.     elseif x > 27 and x < 34 and y == 48 then
  351.       if rod > nbrrod - 1 then
  352.         rod = nbrrod
  353.       else
  354.         rod = rod + 1
  355.       end    
  356.     elseif x > 35 and x < 42 and y == 48 then
  357.       if rod > nbrrod - 10 then
  358.         rod = nbrrod
  359.       else
  360.         rod = rod + 10
  361.       end  
  362.  
  363.     elseif x > 58 and x < 73 and y > 10 and y < 14 then
  364.       br.setActive(true)
  365.       start()
  366.     elseif x > 58 and x < 73 and y > 14 and y < 18 then
  367.       br.setActive(false)
  368.       start()
  369.     end
  370.  
  371.   elseif boucle2 == 1 then
  372.     if x > a+5 and x < a+18 and y > b+4 and y < b+8 then
  373.       if x > a+11 and x < a+14 and y == b+5 then
  374.         if lvl < 91 then
  375.           lvl = lvl + 10
  376.         else
  377.           lvl = 100
  378.         end
  379.       elseif x > a+14 and x < a+18 and y == b+7 then
  380.         if lvl < 100 then
  381.           lvl = lvl + 1
  382.         else
  383.           lvl = 100
  384.         end
  385.       elseif x > a+5 and x < a+9 and y == b+5 then
  386.         if lvl > 10 then
  387.           lvl = lvl - 10
  388.         else
  389.           lvl = 0
  390.         end
  391.       elseif x > a+5 and x < a+9 and y == b+7 then
  392.         if lvl > 1 then
  393.           lvl = lvl - 1
  394.         else
  395.           lvl = 0
  396.         end
  397.       end
  398.       gpu.set(a+14,b+3,string.format("%3s",lvl))
  399.     elseif x > a+3 and x < a+11 and y > b+8 and y < b+12 then
  400.       manualoff()
  401.     elseif x > a+11 and x < a+19 and y > b+8 and y < b+12 then
  402.       br.setControlRodLevel(rod-1,lvl)
  403.       manualoff()
  404.     end
  405.   elseif boucle2 == 2 then
  406.     if x > a+5 and x < a+17 and y > b+4 and y < b+8 then
  407.       if x > a+13 and x < a+18 and y == b+5 then
  408.         if val < 91 then
  409.           val = val + 10
  410.         else
  411.           val = 100
  412.         end
  413.       elseif x > a+13 and x < a+18 and y == b+7 then
  414.         if val < 100 then
  415.           val = val + 1
  416.         else
  417.           val = 100
  418.         end
  419.       elseif x > a+5 and x < a+9 and y == b+5 then
  420.         if val > -91 then
  421.           val = val - 10
  422.         else
  423.           val = -100
  424.         end
  425.       elseif x > a+5 and x < a+9 and y == b+7 then
  426.         if val > -100 then
  427.           val = val - 1
  428.         else
  429.           val = -100
  430.         end
  431.       end
  432.       gpu.set(a+14,b+3,string.format("%3s",val))
  433.     elseif x > a+3 and x < a+11 and y > b+8 and y < b+12 then
  434.       manualoff()
  435.       val = 0
  436.     elseif x > a+11 and x < a+19 and y > b+8 and y < b+12 then
  437.       allrods(val)
  438.       manualoff()
  439.       val = 0
  440.     end
  441.   end
  442. end
  443.  
  444. local function onTimer(_,timer)
  445.   waste()
  446.   control(8,10)
  447.   drawbars()
  448.   return true
  449. end
  450.  
  451. event.listen("touch",onTouch)
  452. local timer = event.timer(0,onTimer,math.huge)
  453. event.pull("quit")
  454. event.cancel(timer)
  455. event.ignore("touch",onTouch)
  456. component.gpu.setResolution(160,50)
  457. term.clear()
Add Comment
Please, Sign In to add comment