Advertisement
sshikamaru

Open computers - Big reactor - 85 rods - English

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