serafim7

bigreactors turbine [OpenComputers]

Nov 8th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.24 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. local gpu = component.gpu
  16. gpu.setResolution(100,50)
  17. br = component.getPrimary("br_turbine")
  18. tur = component.br_turbine
  19. local maxgetsteam = 2000
  20. local mingetsteam = 0
  21. local steam = 2000
  22. local rate = tur.getFluidFlowRateMax()
  23. local speed = 0
  24. local block = 1
  25. local block2 = 1
  26. local eng23 = 0
  27.  
  28.  
  29. local function sig(a)
  30.  return math.floor(a)
  31. end
  32.  
  33. local function englimit()
  34.   if br.getEnergyStored() >= eng23 then
  35.     br.setInductorEngaged(false)  
  36.   elseif br.getEnergyStored() < eng23 then
  37.     br.setInductorEngaged(true)
  38. end
  39. end
  40.  
  41. local function speedlimit()
  42.    if br.getRotorSpeed() < speed then
  43.     tur.setFluidFlowRateMax(maxgetsteam)
  44.    elseif br.getRotorSpeed() > speed then
  45.     tur.setFluidFlowRateMax(mingetsteam)
  46.  end
  47.  end
  48.  
  49. local function loadbar(x,y,width,cur,text,bg,fg)
  50.   local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  51.   local oldbg = gpu.setBackground(bg)
  52.   local oldfg = gpu.setForeground(fg)
  53.   gpu.set(x,y,unicode.sub(raw,1,cur))
  54.   gpu.setBackground(oldbg)
  55.   gpu.setForeground(oldfg)
  56.   gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
  57. end
  58.  
  59. local function setColor(bg,fg)
  60.   gpu.setBackground(bg)
  61.   gpu.setForeground(fg)
  62. end
  63.  
  64. local function bargraph(x,y,length,am,cap,na,col,colpol)
  65.   local amount = am
  66.   local capacity = cap
  67.   local pct = amount / capacity
  68.   local cur = math.floor(pct * length)
  69.   local color = col
  70.   local color2 = colpol
  71.   local name = na
  72.   local textfrac = string.format("%s / %s", amount, capacity)
  73.   local textpct = string.format("%.02f%%", pct*100)
  74.   local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 6) .. "   " .. textpct .. " "
  75.   local text1 = "              Уровень заполнения : ("..name..")"
  76.   loadbar(x,y,length,cur,text1,color,color2)
  77.   loadbar(x,y+1,length,cur,text,color,color2)
  78. end
  79.  
  80. local function drawbars()
  81.   amFuel = br.getInputAmount()
  82.   capFuel = 4000
  83.   naFuel = "ПАР"
  84.   colFuel = 0xFFFF00
  85.   colpolFuel = 0x0000FF
  86.   bargraph(2,13,98,amFuel,capFuel,naFuel,colFuel,colpolFuel)
  87.   amWaste = br.getOutputAmount()
  88.   capWaste = 4000
  89.   naWaste = "ВОДА"
  90.   colWaste = 0x00FFFF
  91.   colpolWaste = 0xFF00FF
  92.   bargraph(2,16,98,amWaste,capWaste,naWaste,colWaste,colpolWaste)
  93.   amSteam = br.getRotorSpeed()
  94.   capSteam = 3000
  95.   naSteam = "СКОРОСТЬ РОТОРА"
  96.   colSteam = 0x8F8F8F
  97.   colpolSteam = 0xFFFF00
  98.   bargraph(2,19,98,amSteam,capSteam,naSteam,colSteam,colpolSteam)
  99.   amWater = br.getEnergyStored()
  100.   capWater = 1000000
  101.   naWater = "НАКОПЛЕННАЯ ЭНЕРГИЯ"
  102.   colWater = 0x71b6cb
  103.   colpolWater = 0x0000FF
  104.   bargraph(2,22,98,amWater,capWater,naWater,colWater,colpolWater)
  105.   en = tur.getEnergyProducedLastTick()
  106.   en2 = en * 20
  107.   en3 = en2 * 60
  108.   en4 = en3 * 60
  109.   gpu.set(3,43,string.format("%10f",sig(en)))
  110.   gpu.set(25,43,string.format("%10f",sig(en2)))
  111.   gpu.set(49,43,string.format("%10f",sig(en3)))
  112.   gpu.set(74,43,string.format("%10f",sig(en4)))
  113.   amstel = tur.getFluidFlowRate()
  114.   gpu.set(19,33, string.format("%10d", speed))
  115.   gpu.set(64,32, string.format("%10d", eng23))
  116.    if block == 2 then
  117.     speedlimit()
  118.     gpu.set(13,6, "         ")
  119.    elseif block == 2 then
  120.     tur.setFluidFlowRateMax(steam)
  121.     gpu.set(13,6, string.format("%10d",steam))
  122.    end
  123.    if block2 == 2 then
  124.     englimit()
  125.    end
  126. end
  127.  
  128. local function work(h,m)
  129.   gpu.set(h,m,"            ")
  130. gpu.set(h,m+1,"  ВКЛЮЧИТЬ  ")
  131. gpu.set(h,m+2,"            ")
  132. end
  133.  
  134. local function nwork(h,m)
  135.   gpu.set(h,m,"            ")
  136. gpu.set(h,m+1," ВЫКЛЮЧИТЬ  ")
  137. gpu.set(h,m+2,"            ")
  138. end
  139.  
  140. local function POWER()
  141.      local ON = br.getActive()
  142.         if ON == true then
  143.           setColor(0x00FF00,0x000000)
  144.           work(87,2)
  145.           setColor(0x000000,0xFF0000)
  146.           nwork(87,6)
  147.           setColor(0x000000,0xFFFFFF)
  148.         elseif ON == false then
  149.           setColor(0x000000,0x00FF00)
  150.           work(87,2)
  151.           setColor(0xFF0000,0xFFFFFF)
  152.           nwork(87,6)
  153.           setColor(0x000000,0xFFFFFF)
  154.       end
  155.  
  156. end
  157.  
  158. local function INGUCKTOR()
  159.      local ONLINE = br.getInductorEngaged()
  160.         if ONLINE == true then
  161.           setColor(0x00FF00,0x000000)
  162.           work(55,2)
  163.           setColor(0x000000,0xFF0000)
  164.           nwork(55,6)
  165.           setColor(0x000000,0xFFFFFF)
  166.         elseif ONLINE == false then
  167.           setColor(0x000000,0x00FF00)
  168.           work(55,2)
  169.           setColor(0xFF0000,0xFFFFFF)
  170.           nwork(55,6)
  171.           setColor(0x000000,0xFFFFFF)
  172.       end
  173.  
  174. end
  175.  
  176. local function SPEEDINDICATOR()
  177.         if block == 2 then
  178.           setColor(0x00FF00,0x000000)
  179.           work(33,28)
  180.           setColor(0x000000,0xFF0000)
  181.           nwork(3,28)
  182.           setColor(0x000000,0xFFFFFF)
  183.         elseif block == 1 then
  184.           setColor(0x000000,0x00FF00)
  185.           work(33,28)
  186.           setColor(0xFF0000,0xFFFFFF)
  187.           nwork(3,28)
  188.           setColor(0x000000,0xFFFFFF)
  189.       end
  190. end
  191.  
  192. local function ENGINDICATOR()
  193.         if block2 == 2 then
  194.           setColor(0x00FF00,0x000000)
  195.           work(78,28)
  196.           setColor(0x000000,0xFF0000)
  197.           nwork(48,28)
  198.           setColor(0x000000,0xFFFFFF)
  199.         elseif block2 == 1 then
  200.           setColor(0x000000,0x00FF00)
  201.           work(78,28)
  202.           setColor(0xFF0000,0xFFFFFF)
  203.           nwork(48,28)
  204.           setColor(0x000000,0xFFFFFF)
  205.       end
  206. end
  207.  
  208. term.clear()
  209.  gpu.set(1,1,"╔══════════════════════════════════╦════════════════╦══════════════╦════════════════╦══════════════╗")
  210.  gpu.set(1,2,"║                                  ║                ║ ████████████ ║                ║ ████████████ ║")
  211.  gpu.set(1,3,"║                                  ║                ║ █ ВКЛЮЧИТЬ █ ║                ║ █ ВКЛЮЧИТЬ █ ║")
  212.  gpu.set(1,4,"║                                  ║ УПРАВЛЕНИЕ     ║ ████████████ ║ УПРАВЛЕНИЕ     ║ ████████████ ║")
  213.  gpu.set(1,5,"║                                  ║             -->╠══════════════╣             -->╠══════════════╣")
  214.  gpu.set(1,6,"║                                  ║ КАТУШКАМИ      ║ ████████████ ║  ТУРБИНОЙ      ║ ████████████ ║")
  215.  gpu.set(1,7,"║                                  ║                ║ █ВЫКЛЮЧИТЬ █ ║                ║ █ВЫКЛЮЧИТЬ █ ║")
  216.  gpu.set(1,8,"║                                  ║                ║ ████████████ ║                ║ ████████████ ║")
  217.  gpu.set(1,9,"╠══════════════════════════════════╩════════════════╩══════════════╩════════════════╩══════════════╣")
  218. gpu.set(1,10,"║                                                                                                  ║")
  219. gpu.set(1,11,"║                                                                                                  ║")
  220. gpu.set(1,12,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  221. gpu.set(1,13,"║                                                                                                  ║")
  222. gpu.set(1,14,"║                                                                                                  ║")
  223. gpu.set(1,15,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  224. gpu.set(1,16,"║                                                                                                  ║")
  225. gpu.set(1,17,"║                                                                                                  ║")
  226. gpu.set(1,18,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  227. gpu.set(1,19,"║                                                                                                  ║")
  228. gpu.set(1,20,"║                                                                                                  ║")
  229. gpu.set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
  230. gpu.set(1,22,"║                                                                                                  ║")
  231. gpu.set(1,23,"║                                                                                                  ║")
  232. gpu.set(1,24,"╠════════════════════════════════════════════╦════════════════════════════════════════════╦════════╣")
  233. gpu.set(1,25,"║ АВТОМАТИЧЕСКОЕ УПРАВЛЕНИЕ СКОРОСТЬЮ ТУРБИНЫ║ АВТОМАТИЧЕСКОЕ УПРАВЛЕНИЕ ЭНЕРГИЕЙ В       ║        ║")
  234. gpu.set(1,26,"║ (УПРАВЛЕНИЕ ПОДАЧЕЙ ПАРА ОТКЛЮЧИТСЯ)       ║ БАТАРЕИ                                    ║        ║")
  235. gpu.set(1,27,"╠══════════════╦══════════════╦══════════════╣══════════════╦══════════════╦══════════════╣        ║")  
  236. gpu.set(1,28,"║ ████████████ ║              ║ ████████████ ║ ████████████ ║              ║ ████████████ ║        ║")
  237. gpu.set(1,29,"║ █ ВКЛЮЧИТЬ █ ║              ║ █ВЫКЛЮЧИТЬ █ ║ █ ВКЛЮЧИТЬ █ ║              ║ █ВЫКЛЮЧИТЬ █ ║        ║")
  238. gpu.set(1,30,"║ ████████████ ║              ║ ████████████ ║ ████████████ ║              ║ ████████████ ║        ║")
  239. gpu.set(1,31,"╠══════════════╝              ╚══════════════╠══════════════╝              ╚══════════════╣        ║")
  240. gpu.set(1,32,"║    +1000     |              |     -1000    ║    +100000   |              |     -100000  ║        ║")
  241. gpu.set(1,33,"║    +100      |              |     -100     ║    +10000    |              |     -10000   ║        ║")
  242. gpu.set(1,34,"║    +10       |              |     -10      ║    +1000     |              |     -1000    ║        ║")
  243. gpu.set(1,35,"║    +1        |              |     -1       ║    +100      |              |     -100     ║        ║")
  244. gpu.set(1,36,"╠════════════════════════════════════════════╩════════════════════════════════════════════╩════════╣")
  245. gpu.set(1,37,"║ КОЛИЧЕСТВА ВЫРАБАТЫВАЕМОЙ ЭНЕРГИИ ЗА ПРОМЕЖУТОК ВЕМЕНИ                                           ║")
  246. gpu.set(1,38,"╠═════════════════════╦═══════════════════════╦════════════════════════╦═══════════════════════════╣")
  247. gpu.set(1,39,"║ REDSTONEFLUX/TICK   ║ REDSTONEFLUX/SECOND   ║ REDSTONEFLUX/MINUTS    ║ REDSTONEFLUX/HOURSE       ║")
  248. gpu.set(1,40,"║                     ║                       ║                        ║                           ║")
  249. gpu.set(1,41,"║ RF/T                ║ RF/SEC                ║ RF/M                   ║ RF/H                      ║")
  250. gpu.set(1,42,"║                     ║                       ║                        ║                           ║")
  251. gpu.set(1,43,"║                     ║                       ║                        ║                           ║")
  252. gpu.set(1,44,"╠═════════════════════╩═══════════════════════╩════════════════════════╩═══════════════════════════╣")
  253. gpu.set(1,45,"║                                                                                                  ║")
  254. gpu.set(1,46,"║                                                                                                  ║")
  255. gpu.set(1,47,"║                                                                                                  ║")
  256. gpu.set(1,48,"║                                                                                                  ║")
  257. gpu.set(1,49,"║                                                                                                  ║")
  258. gpu.set(1,50,"╚══════════════════════════════════════════════════════════════════════════════════════════════════╝")
  259.  
  260. POWER()
  261. INGUCKTOR()
  262. SPEEDINDICATOR()
  263. ENGINDICATOR()
  264.  
  265. local function onTouch(event,adress,x,y,clic,pseudo)
  266. if x==1 and y==1 then
  267.       computer.pushSignal("quit")
  268.       term.setCursor(1,1)
  269.       return false
  270.      elseif x > 85 and x < 100 and y > 1 and y < 5 then
  271.       br.setActive(true)
  272.       POWER()
  273.      elseif x > 85 and x < 100 and y > 5 and y < 9 then
  274.       br.setActive(false)
  275.       POWER()
  276.      elseif x > 54 and x < 67 and y > 1 and y < 5 then
  277.       br.setInductorEngaged(true)
  278.       INGUCKTOR()
  279.      elseif x > 54 and x < 67 and y > 5 and y < 9 then
  280.       br.setInductorEngaged(false)
  281.       INGUCKTOR()
  282.      elseif x > 2 and x < 15 and y > 28 and y < 30 then
  283.        block = 1
  284.        SPEEDINDICATOR()
  285.      elseif x > 32 and x < 45 and y > 28 and y < 30 then
  286.        block = 2
  287.        SPEEDINDICATOR()
  288.       elseif x > 47 and x < 60 and y > 28 and y < 30 then
  289.        block2 = 1
  290.        ENGINDICATOR()
  291.         br.setInductorEngaged(false)
  292.       INGUCKTOR()
  293.      elseif x > 77 and x < 90 and y > 28 and y < 30 then
  294.        block2 = 2
  295.        ENGINDICATOR()
  296.         br.setInductorEngaged(false)
  297.       INGUCKTOR()
  298.       elseif x > 50 and x < 57 and y == 32 then                       -- скорость +1000
  299.       if eng23 >= 900000 then
  300.        eng23 = 1000000
  301.       else
  302.        eng23 = eng23 + 100000
  303.       end
  304.       gpu.set(64,32, string.format("%10d", eng23))
  305.      elseif x > 50 and x < 57 and y == 33 then                       -- скорость +100
  306.       if eng23 >= 990000 then
  307.        eng23 = 1000000
  308.       else
  309.        eng23 = eng + 10000
  310.       end
  311.       gpu.set(64,32, string.format("%10d", eng23))
  312.      elseif x > 50 and x < 57 and y == 34 then                       -- скорость +10
  313.       if eng23 >= 999000 then
  314.        eng23 = 1000000
  315.       else
  316.        eng23 = eng23 + 1000
  317.       end
  318.       gpu.set(64,32, string.format("%10d", eng23))
  319.      elseif x > 50 and x < 57 and y == 35 then                       -- скорость +1
  320.       if eng23 >= 999900 then
  321.        eng23 = 1000000
  322.       else
  323.        eng23 = eng23 + 100
  324.       end
  325.       gpu.set(64,32, string.format("%10d", eng23))
  326.      elseif x > 80 and x < 87 and y == 32 then                       -- скорость -1000
  327.       if eng23 <= 100000 then
  328.          eng23 = 0
  329.       else
  330.          eng23 = eng23 - 100000  
  331.       end
  332.       gpu.set(64,32, string.format("%10d", eng23))
  333.      elseif x > 80 and x < 87 and y == 33 then                       -- скорость -100
  334.       if eng23 <= 10000 then
  335.          eng23 = 0
  336.       else
  337.          eng23 = eng23 - 10000   
  338.       end
  339.       gpu.set(64,32, string.format("%10d", eng23))
  340.      elseif x > 80 and x < 87 and y == 34 then                       -- скорость -10
  341.       if eng23 <= 1000 then
  342.          eng23 = 0
  343.       else
  344.          eng23 = eng23 - 1000  
  345.       end
  346.       gpu.set(64,32, string.format("%10d", eng23))
  347.      elseif x > 80 and x < 87 and y == 35 then                       -- скорость -1
  348.       if eng23 <= 100 then
  349.          eng23 = 0
  350.       else
  351.          eng23 = eng23 - 100  
  352.       end
  353.       gpu.set(64,32, string.format("%10d", eng23))
  354.      elseif x > 2 and x < 15 and y == 32 then                       -- скорость +1000
  355.       if speed >= 2000 then
  356.        speed = 3000
  357.       else
  358.        speed = speed + 1000
  359.       end
  360.       gpu.set(19,33, string.format("%10d", speed))
  361.      elseif x > 2 and x < 15 and y == 33 then                       -- скорость +100
  362.       if speed >= 2900 then
  363.        speed = 3000
  364.       else
  365.        speed = speed + 100
  366.       end
  367.       gpu.set(19,33, string.format("%10d", speed))
  368.      elseif x > 2 and x < 15 and y == 34 then                       -- скорость +10
  369.       if speed >= 2990 then
  370.        speed = 3000
  371.       else
  372.        speed = speed + 10
  373.       end
  374.       gpu.set(19,33, string.format("%10d", speed))
  375.      elseif x > 2 and x < 15 and y == 35 then                       -- скорость +1
  376.       if speed >= 2999 then
  377.        speed = 3000
  378.       else
  379.        speed = speed + 1
  380.       end
  381.       gpu.set(19,33, string.format("%10d", speed))
  382.      elseif x > 31 and x < 44 and y == 32 then                       -- скорость -1000
  383.       if speed <= 1000 then
  384.          speed = 0
  385.       else
  386.          speed = speed - 1000    
  387.       end
  388.       gpu.set(19,33, string.format("%10d", speed))
  389.      elseif x > 31 and x < 44 and y == 33 then                       -- скорость -100
  390.       if speed <= 100 then
  391.          speed = 0
  392.       else
  393.          speed = speed - 100     
  394.       end
  395.       gpu.set(19,33, string.format("%10d", speed))
  396.      elseif x > 31 and x < 44 and y == 34 then                       -- скорость -10
  397.       if speed <= 10 then
  398.          speed = 0
  399.       else
  400.          speed = speed - 10  
  401.       end
  402.       gpu.set(19,33, string.format("%10d", speed))
  403.      elseif x > 31 and x < 44 and y == 35 then                       -- скорость -1
  404.       if speed <= 1 then
  405.          speed = 0
  406.       else
  407.          speed = speed - 1   
  408.       end
  409.       gpu.set(19,33, string.format("%10d", speed))
  410. end
  411. end
  412.  
  413. local function onTimer(_,timer)
  414.   drawbars()
  415.   return true
  416. end
  417.  
  418. event.listen("touch",onTouch)
  419. local timer = event.timer(0,onTimer,math.huge)
  420. event.pull("quit")
  421. event.cancel(timer)
  422. event.ignore("touch",onTouch)
  423. component.gpu.setResolution(100,50)
  424. term.clear()
Add Comment
Please, Sign In to add comment