Advertisement
krezi1212123

OC BigReactors steam

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