Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local computer = require("computer")
- local component = require("component")
- local term = require("term")
- local math = require("math")
- local event = require("event")
- local string = require("string")
- local unicode = require("unicode")
- local color = require("colors")
- local side = require("sides")
- local serialization = require("serialization")
- --Récupération des écrans et GPU
- local screen1 = component.get("4e22","screen")
- local screen2 = component.get("0d79","screen")
- local pgpus = {}
- pgpus[1] = component.proxy(component.get("de87","gpu"))
- pgpus[2] = component.proxy(component.get("9e8a","gpu"))
- pgpus[2].bind(screen2)
- pgpus[1].bind(screen1)
- pgpus[1].setResolution(100,50)
- pgpus[2].setResolution(100,50)
- --Récupération des composants
- local modem = component.modem
- local rs = component.redstone
- local fusion = component.reactor_logic_adapter
- local laser1 = component.proxy(component.get("31d4","laser_amplifier"))
- local laser2 = component.proxy(component.get("4628","laser_amplifier"))
- local cmd = side.top
- local DTd = side.east
- local DTg = side.west
- --définition des variables
- local lancement = 600000000
- local ratio_fusion = 0
- local alim_fusion_dtfuel_value = 0
- local charge_laser = false
- local charge_laser1 = false
- local charge_laser2 = false
- local alim_fusion = false
- local alim_fusion_tritium = false
- local alim_fusion_deuterium = false
- local alim_cuve_gauche_dtfuel = false
- local alim_cuve_droite_dtfuel = false
- local activation_laser_amplifier = false
- local laser_pret = false
- local alim_dtfuel_tritium = false
- local alim_dtfuel_deuterium = false
- local table_bit = {
- false, -- 1 charge_laser
- false, -- 2 charge_laser1
- false, -- 3 charge_laser2
- false, -- 4 alim_fusion
- false, -- 5 alim_fusion_tritium
- false, -- 6 alim_fusion_deuterium
- false, -- 7 alim_cuve_gauche_dtfuel
- false, -- 8 alim_cuve_droite_dtfuel
- false, -- 9 activation_laser_amplifier
- false, -- 10 laser_pret
- false, -- 11 alim_dtfuel_tritium
- false -- 12 alim_dtfuel_deuterium
- }
- local table_bit2 = {}
- local function bit_in_variables()
- charge_laser = table_bit[1]
- charge_laser1 = table_bit[2] and charge_laser
- charge_laser2 = table_bit[3] and charge_laser
- alim_fusion = table_bit[4]
- alim_fusion_tritium = table_bit[5]
- alim_fusion_deuterium = table_bit[6]
- alim_cuve_gauche_dtfuel = table_bit[7]
- alim_cuve_droite_dtfuel = table_bit[8]
- activation_laser_amplifier = table_bit[9]
- laser_pret = table_bit[10]
- alim_dtfuel_tritium = table_bit[11]
- alim_dtfuel_deuterium = table_bit[12]
- end
- local table_rotary = {}
- local i = 0
- for i = 0, 23 do
- local text = "Rotary n°"..tostring(i)
- local v1 = false
- table_rotary[i] = {label=text,bit=v1}
- end
- local test1 = false
- local test2 = false
- local noir = 0x000000
- local blanc = 0xFFFFFF
- local rouge = 0xFF0000
- local vert = 0x00FF00
- local bleu = 0x0000FF
- local cyan = 0x00FFFF
- local jaune = 0xFFFF00
- local magenta = 0xFF00FF
- local violet = 0xBE00FF
- local orange = 0xFF9143
- --initialisation de la redstone
- for i = 0, 15 do
- rs.setBundledOutput(cmd,i,255)
- rs.setBundledOutput(DTg,i,255)
- rs.setBundledOutput(DTd,i,255)
- end
- --Récupération des tanks
- local tank_tritium = component.proxy(component.get("ce22","tank_controller"))
- local tank_deuterium = component.proxy(component.get("3e03","tank_controller"))
- local tank_dtg = component.proxy(component.get("7957","tank_controller"))
- local tank_dtd = component.proxy(component.get("4803","tank_controller"))
- local tank = {{tank_tritium,color=0x0000ff},{tank_deuterium,color=0xff0000},{tank_dtg,color=0xff00ff},{tank_dtd,color=0xff00ff}}
- --Ouverture des ports
- modem.open(10001)
- --Fonctions
- local function setColor(bg,fg,gpu)
- pgpus[gpu].setBackground(bg)
- pgpus[gpu].setForeground(fg)
- end
- local function unit(qty)
- if qty >= 1000000000 then
- return string.format("%.02f MB",qty/10000000)
- elseif qty >=1000000 then
- return string.format("%.02f KB",qty/1000000)
- elseif qty >=1000 then
- return string.format("%.02f B ",qty/1000)
- else
- return string.format("%d mB",qty)
- end
- end
- local function unitrf(qty)
- if qty >= 1000000000000000 or qty <= -1000000000000000 then
- return string.format("%.03f PRF",qty/1000000000000000)
- elseif qty >= 1000000000000 or qty <= -1000000000000 then
- return string.format("%.03f TRF",qty/1000000000000)
- elseif qty >=1000000000 or qty <= -1000000000 then
- return string.format("%.03f GRF",qty/1000000000)
- elseif qty >=1000000 or qty <= -1000000 then
- return string.format("%.03f MRF",qty/1000000)
- elseif qty >=1000 or qty <= -1000 then
- return string.format("%.03f kRF",qty/1000)
- else
- return string.format("%.03f RF ",qty)
- end
- end
- function loadbar(x,y,width,cur,text,bg,fg,gpu)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = pgpus[gpu].setBackground(bg)
- local oldfg = pgpus[gpu].setForeground(fg)
- pgpus[gpu].set(x,y,unicode.sub(raw,1,cur))
- pgpus[gpu].setBackground(oldbg)
- pgpus[gpu].setForeground(oldfg)
- pgpus[gpu].set(x+cur,y,unicode.sub(raw,cur+1,width))
- end
- local function afftank(x,y,length,ntank,gpu)
- local amount = tank[ntank][1].getFluidInTank(0)[1].amount
- local capacity = tank[ntank][1].getFluidInTank(0)[1].capacity
- local label = tank[ntank][1].getFluidInTank(0)[1].label
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local bg = tank[ntank].color
- local fg = blanc - bg
- local textfrac = string.format("%s / %s", unitrf(amount), unitrf(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local text1 = " "..label
- local text2 = ""
- local text3 = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text1,bg,fg,gpu)
- loadbar(x,y+1,length,cur,text2,bg,fg,gpu)
- loadbar(x,y+2,length,cur,text3,bg,fg,gpu)
- end
- local function affenergie(x,y,length,tableau,gpu)
- local amount = tableau[1] * 0.4
- local capacity = tableau[2] * 0.4
- local pct = amount / capacity
- local color = cyan
- local color2 = rouge
- local cur = math.floor(pct * length)
- local textfrac = string.format("%s / %s", unitrf(amount), unitrf(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local text1 = " ENERGIE DANS LA BATTERIE MEKANISM "
- local text2 = ""
- local text3 = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text1,color,color2,gpu)
- loadbar(x,y+1,length,cur,text2,color,color2,gpu)
- loadbar(x,y+2,length,cur,text3,color,color2,gpu)
- end
- local function afflaser(x,y,length,amount,capacity,gpu)
- local pct = amount / capacity
- local color = 0x0000FF
- local color2 = 0xFFFF00
- local cur = math.floor(pct * length)
- local cur2 = math.floor(lancement / capacity * length)-1
- local textfrac = string.format("%s / %s", unitrf(amount), unitrf(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local texte_laser1
- local texte_laser2
- if amount == capacity then
- texte_laser1 = "Chargé totalement"
- elseif charge_laser == false then
- texte_laser1 = "En attente de charge"
- elseif charge_laser == true then
- if charge_laser1 == false and charge_laser2 == false then
- texte_laser1 = "En attente de charge"
- else
- texte_laser1 = "En charge"
- end
- end
- if amount < lancement then
- texte_laser2 = " - Lancement impossible"
- elseif amount >= lancement then
- texte_laser2 = " - Lancement possible"
- end
- texte_palier = "│ Palier de lancement minimum : "..unitrf(lancement)
- local text1 = " Charge du Laser Amplifier - "..texte_laser1..texte_laser2
- local text2 = textfrac .. string.rep(" ", cur2 - string.len(textfrac)) .. texte_palier .. string.rep(" ", length - cur2 - string.len(texte_palier) - string.len(textpct) - 0) .. textpct
- loadbar(x,y,length,cur,text1,color,color2,gpu)
- loadbar(x,y+1,length,cur,text2,color,color2,gpu)
- end
- local function lvl_deut(x,y,length,ntank,gpu)
- local amount = tank[ntank][1].getFluidInTank(0)[1].amount
- local capacity = tank[ntank][1].getFluidInTank(0)[1].capacity
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local bg = tank[ntank].color
- local fg = blanc - bg
- local text = ntank.." : "..unit(amount)
- loadbar(x,y,length,cur,text,bg,fg,gpu)
- end
- local function barre_verticale(x,y,hauteur,largeur,entete,ntank,color1,color2,gpu)
- local k = 0
- local amount = tank[ntank][1].getFluidInTank(0)[1].amount
- local capacity = tank[ntank][1].getFluidInTank(0)[1].capacity
- local cur = math.floor((amount / capacity) * hauteur)
- local dir = string.rep(" ",largeur)
- for k = 1, hauteur do
- local vy = y + hauteur - k
- if k <= cur then
- setColor(color1,color2,gpu)
- elseif k > cur then
- setColor(noir,blanc,gpu)
- end
- pgpus[gpu].set(x,vy,dir)
- if k == 1 then
- pgpus[gpu].set(x,vy,dir)
- pgpus[gpu].set(x,vy," Max "..unit(capacity))
- elseif k == 3 then
- pgpus[gpu].set(x,vy,dir)
- pgpus[gpu].set(x,vy," Cur "..unit(amount))
- elseif k == 4 then
- pgpus[gpu].set(x,vy,dir)
- pgpus[gpu].set(x,vy,string.format(" Cur %06.02f%% ",(amount/capacity)*100))
- elseif k == hauteur then
- pgpus[gpu].set(x,vy,entete)
- end
- setColor(noir,blanc,gpu)
- end
- end
- local function bouton(x,y,etat,text,color,color2,gpu)
- if etat == true then
- setColor(color,color2,gpu)
- pgpus[gpu].set(x,y," "..text.." ")
- setColor(noir,blanc,gpu)
- elseif etat == false then
- setColor(color2,color,gpu)
- pgpus[gpu].set(x,y," "..text.." ")
- setColor(noir,blanc,gpu)
- end
- end
- local function bouton_rotary(x,y,netat,gpu)
- local text
- if table_rotary[netat].bit == true then
- text = "ON "
- bouton(x,y,table_rotary[netat].bit,text,vert,noir,gpu)
- elseif table_rotary[netat].bit == false then
- text = "OFF"
- bouton(x,y,table_rotary[netat].bit,text,rouge,noir,gpu)
- end
- end
- local function boutonx2(x,y,x2,y2,nbit,text1,text2,color1,color2,color3,color4,espace,gpu)
- if x2 > x-1 and x2 < x+string.len(text1)+2 and y2 == y then
- table_bit[nbit] = true
- elseif x2 > x+string.len(text1)+2 and x2 < x+string.len(text1)+string.len(text2)+5 and y2 == y then
- table_bit[nbit] = false
- end
- pgpus[2].set(4+10*(nbit-1),9,tostring(nbit).." : "..tostring(table_bit[nbit]).." ")
- bouton(x,y,table_bit[nbit],text1,color1,color2,gpu)
- bouton(x+string.len(text1)+2+espace,y,not(table_bit[nbit]),text2,color3,color4,gpu)
- end
- local function afflasers(x,y,length,gpu)
- local amount1 = laser1.getEnergy() * 0.4
- local capacity1 = laser1.getMaxEnergy() * 0.4
- local amount2 = laser2.getEnergy() * 0.4
- local capacity2 = laser2.getMaxEnergy() * 0.4
- afflaser(x,y,length,amount1,capacity1,gpu)
- afflaser(x,y+3,length,amount2,capacity2,gpu)
- end
- local function conversion_binaire_nombre(etat)
- if etat == false then
- return 255
- elseif etat == true then
- return 0
- end
- end
- local function conversion_nombre_binaire(etat)
- if etat == 0 then
- return true
- elseif etat > 0 then
- return false
- end
- end
- local function affrotaryx24(x,y,gpu)
- local etat
- local i
- for i = 0, 23 do
- if i <= 5 then
- bouton_rotary(x-8*(i),15,i,gpu)
- elseif i > 5 and i <= 11 then
- bouton_rotary(x-8*(i-6),39,i,gpu)
- elseif i > 11 and i <= 17 then
- bouton_rotary(x+9+8*(i-12),15,i,gpu)
- elseif i > 17 and i <= 23 then
- bouton_rotary(x+9+8*(i-18),39,i,gpu)
- end
- end
- end
- local function aff_pourcent(gpu)
- setColor(bleu,blanc,gpu)
- local alim_pct = alim_fusion_dtfuel_value / 24
- pgpus[gpu].set(26,22,string.format("%06.02f%%", alim_pct*100))
- setColor(noir,blanc,gpu)
- if alim_fusion == false then
- setColor(orange,noir,gpu)
- pgpus[gpu].set(48,31,string.format("%06.02f%%", ratio_fusion))
- setColor(noir,blanc,gpu)
- elseif alim_fusion == true then
- pgpus[gpu].set(48,31,"-------")
- end
- end
- local function cmd_rotary()
- local i
- for i = 0, 24 do
- if i < alim_fusion_dtfuel_value then
- if i < 12 then
- rs.setBundledOutput(DTg,i,0)
- elseif i >= 12 then
- rs.setBundledOutput(DTd,i-12,0)
- end
- elseif i >= alim_fusion_dtfuel_value then
- if i < 12 then
- rs.setBundledOutput(DTg,i,255)
- elseif i >= 12 then
- rs.setBundledOutput(DTd,i-12,255)
- end
- end
- end
- end
- local function tables_differentes()
- if table_bit ~= table_bit2 then
- rs.setBundledOutput(cmd,0,conversion_binaire_nombre(charge_laser1)) -- laser gauche
- rs.setBundledOutput(cmd,1,conversion_binaire_nombre(charge_laser2)) -- laser droite
- rs.setBundledOutput(cmd,2,conversion_binaire_nombre(alim_fusion_deuterium)) -- alim fusion en deutérium
- rs.setBundledOutput(cmd,3,conversion_binaire_nombre(alim_fusion_tritium)) -- alim fusion en tritium
- rs.setBundledOutput(cmd,4,conversion_binaire_nombre(alim_fusion)) -- alim fusion dt-fuel ou deut-trit
- rs.setBundledOutput(cmd,5,conversion_binaire_nombre(not(alim_fusion))) -- alim fusion dt-fuel ou deut-trit
- rs.setBundledOutput(cmd,6,conversion_binaire_nombre(alim_cuve_gauche_dtfuel)) -- alim cuve gauche dt-fuel
- rs.setBundledOutput(cmd,7,conversion_binaire_nombre(alim_cuve_droite_dtfuel)) -- alim cuve droite dt-fuel
- rs.setBundledOutput(cmd,8,conversion_binaire_nombre(activation_laser_amplifier)) -- activation laser amplifier - lancement fusion
- rs.setBundledOutput(cmd,9,conversion_binaire_nombre(laser_pret)) -- laser_pret
- --rs.setBundledOutput(cmd,10,conversion_binaire_nombre()) --
- rs.setBundledOutput(cmd,11,conversion_binaire_nombre(alim_dtfuel_tritium)) -- alim machinerie dt-fuel en tritium
- --rs.setBundledOutput(cmd,12,conversion_binaire_nombre()) --
- --rs.setBundledOutput(cmd,13,conversion_binaire_nombre()) --
- rs.setBundledOutput(cmd,14,conversion_binaire_nombre(alim_dtfuel_deuterium)) -- alim machinerie dt-fuel en deutérium
- --rs.setBundledOutput(cmd,15,conversion_binaire_nombre()) --
- end
- aff_pourcent(2)
- bit_in_variables()
- table_bit2 = table_bit
- end
- --Matrices
- pgpus[1].set(1,1,"╔Ecran n°1═════════════════════════════════════════════════════════════════════════════════════════╗")
- pgpus[1].set(1,2,"║ ║")
- pgpus[1].set(1,3,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- pgpus[1].set(1,4,"║ ETAT DES RESERVOIRS DE FLUIDES POUR LE REACTEUR A FUSION ║")
- pgpus[1].set(1,5,"╟──────────────────────────────────────────────────────────────────────────────────────────────────╢")
- pgpus[1].set(1,6,"║ ║")
- pgpus[1].set(1,7,"║ ║")
- pgpus[1].set(1,8,"║ ║")
- pgpus[1].set(1,9,"╟──────────────────────────────────────────────────────────────────────────────────────────────────╢")
- pgpus[1].set(1,10,"║ ║")
- pgpus[1].set(1,11,"║ ║")
- pgpus[1].set(1,12,"║ ║")
- pgpus[1].set(1,13,"╟──────────────────────────────────────────────────────────────────────────────────────────────────╢")
- pgpus[1].set(1,14,"║ ║")
- pgpus[1].set(1,15,"║ ║")
- pgpus[1].set(1,16,"║ ║")
- pgpus[1].set(1,17,"╟──────────────────────────────────────────────────────────────────────────────────────────────────╢")
- pgpus[1].set(1,18,"║ ║")
- pgpus[1].set(1,19,"║ ║")
- pgpus[1].set(1,20,"║ ║")
- pgpus[1].set(1,21,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- pgpus[1].set(1,22,"║ ║")
- pgpus[1].set(1,23,"║ ║")
- pgpus[1].set(1,24,"║ ║")
- pgpus[1].set(1,25,"║ ║")
- pgpus[1].set(1,26,"║ ║")
- pgpus[1].set(1,27,"║ ║")
- pgpus[1].set(1,28,"║ ║")
- pgpus[1].set(1,29,"║ ║")
- pgpus[1].set(1,30,"║ ║")
- pgpus[1].set(1,31,"║ ║")
- pgpus[1].set(1,32,"║ ║")
- pgpus[1].set(1,33,"║ ║")
- pgpus[1].set(1,34,"║ ║")
- pgpus[1].set(1,35,"║ ║")
- pgpus[1].set(1,36,"║ ║")
- pgpus[1].set(1,37,"║ ║")
- pgpus[1].set(1,38,"║ ║")
- pgpus[1].set(1,39,"║ ║")
- pgpus[1].set(1,40,"║ ║")
- pgpus[1].set(1,41,"║ ║")
- pgpus[1].set(1,42,"║ ║")
- pgpus[1].set(1,43,"║ ║")
- pgpus[1].set(1,44,"║ ║")
- pgpus[1].set(1,45,"║ ║")
- pgpus[1].set(1,46,"╠══════════════════════════════════════════════════════════════════════════════════════════════════╣")
- pgpus[1].set(1,47,"║ ║")
- pgpus[1].set(1,48,"║ ║")
- pgpus[1].set(1,49,"║ ║")
- pgpus[1].set(1,50,"╚══════════════════════════════════════════════════════════════════════════════════════════════════╝""ON","OFF",vert,noir,rouge,noir,1,2)
- boutonx2(24,32,x,y,2,"ON","OFF",vert,noir,rouge,noir,2,2)
- boutonx2(67,32,x,y,3,"ON","OFF",vert,noir,rouge,noir,2,2)
- boutonx2(20,43,x,y,4,"D-T Fuel","Deutérium-Tritium",violet,noir,jaune,noir,1,2)
- end
- affboutons(2,1)
- affrotaryx24(44,15,2)
- aff_pourcent(2)
- local function onModem(_,_,from,port,_,IDcodes,message)
- if IDcodes == "batterie générale" then
- value_receive = serialization.unserialize(message)
- affenergie(2,47,98,value_receive,1)
- end
- end
- local function onRedstone(event,address,side,value)
- if side == 4 or side == 5 then
- affrotaryx24(44,15,2)
- end
- end
- local function onTouch(event,address,x,y,clic,pseudo)
- local tclic
- if clic == 0 then
- tclic = "Clic gauche"
- elseif clic == 1 then
- tclic = "Clic droit"
- else
- tclic = "Clic inconnu"
- end
- local ecran = ""
- if address == screen1 then
- ecran = "1"
- elseif address == screen2 then
- ecran = "2"
- else
- ecran = "?"
- end
- pgpus[1].set(2,2," ")
- pgpus[1].set(5,2," "..tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y).." sur l'écran n°"..ecran)
- pgpus[2].set(2,2," ")
- pgpus[2].set(5,2," "..tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y).." sur l'écran n°"..ecran)
- if address == screen1 then
- if x~=1 and y~=1 then
- if x>13 and x<31 and y>4 and y<13 then
- elseif x>44 and x<62 and y>22 and y<31 then
- end
- elseif x==1 and y==1 then
- computer.pushSignal("quit")
- term.setCursor(1,1)
- return false
- end
- elseif address==screen2 then
- if x~=1 and y~=1 then
- affboutons(x,y)
- if y==22 then
- if x>22 and x<26 then
- alim_fusion_dtfuel_value = alim_fusion_dtfuel_value + 1
- if alim_fusion_dtfuel_value > 24 then
- alim_fusion_dtfuel_value = 24
- end
- aff_pourcent(2)
- elseif x>32 and x<36 then
- alim_fusion_dtfuel_value = alim_fusion_dtfuel_value - 1
- if alim_fusion_dtfuel_value < 0 then
- alim_fusion_dtfuel_value = 0
- end
- aff_pourcent(2)
- end
- cmd_rotary()
- elseif y==31 then
- if x>45 and x<47 then
- ratio_fusion = ratio_fusion + 1
- if ratio_fusion > 100 then
- ratio_fusion = 100
- end
- aff_pourcent(2)
- elseif x>55 and x<57 then
- ratio_fusion = ratio_fusion - 1
- if ratio_fusion < 0 then
- ratio_fusion = 0
- end
- aff_pourcent(2)
- end
- end
- elseif x==1 and y==1 then
- computer.pushSignal("quit")
- term.setCursor(1,1)
- return false
- end
- end
- end
- local function onTimer(_,timer)
- lvl_deut(65,21,15,3,2)
- lvl_deut(65,22,15,4,2)
- afftank(2,6,98,1,1)
- afftank(2,10,98,2,1)
- afftank(2,14,98,3,1)
- afftank(2,18,98,4,1)
- barre_verticale(4,22,11,15," TRITIUM ",3,bleu,jaune,2)
- barre_verticale(83,22,11,15," DEUTERIUM ",3,rouge,vert,2)
- afflasers(2,45,98,2)
- tables_differentes()
- return true
- end
- event.listen("touch",onTouch)
- event.listen("modem_message",onModem)
- local timer = event.timer(.1,onTimer,math.huge)
- event.listen("redstone_changed", onRedstone)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- event.ignore("modem_message",onModem)
- event.ignore("redstone_changed", onRedstone)
- modem.close(10001)
- setColor(noir,blanc,1)
- setColor(noir,blanc,2)
- pgpus[1].setResolution(160,50)
- pgpus[2].setResolution(160,50)
- pgpus[2].fill(1,1,160,50," ")
- pgpus[1].fill(1,1,160,50," ")
- --Créé par sshikamaru. Vous avez le droit de l'utiliser mais pas de le distribuer.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement