Advertisement
sshikamaru

Open computers - Big reactor - French

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