Advertisement
sshikamaru

reacteur 2

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