Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Liste des require
- 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 colors = require("colors")
- local sides = require("sides")
- local serialization = require("serialization")
- print("Requires... ok")
- os.sleep(0,5)
- --Définitions des variables
- local table_fermenter = {name_oc="fermenter",name="Fermenteur",titre="DE FERMENTEUR",item=" Cannes à sucre",item_color=0xb4f6a3,product=" Ethanol ",product_color=0xcccaa5}
- local table_squeezer = {name_oc="squeezer",name="Fermenteur",titre="D'EXTRACTEUR ",item="Graines de melon",item_color=0xdf9891,product="Huile de plante",product_color=0x6a6837}
- local table_generale = {table_fermenter,table_squeezer}
- local i = 0
- local j = 0
- local h = 0
- local volume
- local volume_max
- local t_volume = {0,0,0}
- local t_volume_max = {0,0,0}
- local t_item = {0,0,0}
- local t_item_max = {0,0,0}
- local old_volume = {1000000000000,1000000000000,1000000000000}
- local old_tank = 1000000000000000
- local arg = {...}
- local nb_groupe = tonumber(arg[1])
- local nom_machine = tostring(arg[2])
- local Idcodes
- local top = sides.top
- local table_value = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false}
- local amount_tampon = 0
- local table_reception = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- local table_emmission = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- if nom_machine == "f" then
- ntable = 1
- elseif nom_machine == "s" then
- ntable = 2
- end
- local noir = 0x000000
- local blanc = 0xFFFFFF
- local rouge = 0xFF0000
- local vert = 0x00FF00
- local bleu = 0x0000FF
- local orange = 0xFFFA000
- local color_produit = table_generale[ntable].product_color
- local color_tampon = table_generale[ntable].item_color
- local etat_mode_auto = 1
- local old_etat_mode_auto = 4
- local tableau_etat_sortie = {false,false,false} -- 1 = vanne tampon / 2 = vanne alim cuve / 3 = vanne tirage cuve
- local tableau_old_etat_sortie = {true,true,true} -- 1 = vanne tampon / 2 = vanne alim cuve / 3 = vanne tirage cuve
- print("Initialisation variables... ok")
- os.sleep(0,5)
- --Récupération du matériel
- local screen = component.getPrimary("screen")
- local gpu = component.gpu
- gpu.setResolution(75,60)
- local modem = component.modem
- local rs = component.redstone
- local port_modem = 10001
- local tank = component.thermalexpansion_tank
- local chest = component.diamond
- print("Récupération materiel... ok")
- os.sleep(0,5)
- --Ouverture des ports du modem
- modem.open(10001)
- print("Ouverture des ports... ok")
- os.sleep(0,5)
- --Fonctions
- local function setColor(bg,fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- local function unitmb(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 loadbar(x,y,width,cur,text,bg)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(blanc - bg)
- gpu.set(x,y,unicode.sub(raw,1,cur))
- gpu.setBackground(oldbg)
- gpu.setForeground(oldfg)
- gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
- end
- local function affbar(x,y,length)
- local capacity = tank.getTankInfo()[1].capacity
- local amount
- local text1
- if tank.getTankInfo()[1].contents == nil then
- amount = 0
- text1 = " Cuve de stockage groupe n°"..nb_groupe.." : ".. "Vide"
- else
- amount = tank.getTankInfo()[1].contents.amount
- text1 = " Cuve de stockage groupe n°"..nb_groupe.." : " .. tank.getTankInfo()[1].contents.rawName
- end
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local textfrac = string.format("%s / %s", unitmb(amount), unitmb(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local text2
- if old_tank > amount then
- text2 = " ◄ "
- elseif old_tank < amount then
- text2 = " ► "
- end
- if old_tank == amount then
- else
- local texte = "║"
- local text4 = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text1,color_produit)
- loadbar(x,y+1,length,cur,text2,color_produit)
- loadbar(x,y+2,length,cur,text4,color_produit)
- end
- old_tank = amount
- end
- local function barre_verticale(x,y,hauteur,largeur,volume,volume_max,item,item_max,n,type_machine)
- local entete = table_generale[table_reception[2]].name.." n°"..n
- local k = 0
- local text
- if old_volume[n] < volume then
- text = " ► "
- elseif old_volume[n] > volume then
- text = " ◄ "
- elseif old_volume[n] == volume then
- text = " = "
- end
- local cur = math.floor((volume / volume_max) * hauteur)
- local dir = string.rep(" ",largeur)
- for k = 1, hauteur do
- local vy = y + hauteur - k
- if k <= cur then
- setColor(table_generale[table_reception[2]].product_color,1-table_generale[table_reception[2]].product_color)
- elseif k > cur then
- setColor(noir,blanc)
- end
- gpu.set(x,vy,dir)
- if k == 1 then
- gpu.set(x,vy,dir)
- elseif k == hauteur - 22 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" % 6.02f%%",item*100/(64*9)))
- elseif k == hauteur - 21 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" Quantité % 3d",item))
- elseif k == hauteur - 20 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,table_generale[type_machine].item)
- elseif k == hauteur - 10 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" Cur %06.02f%% ",(volume/volume_max)*100))
- elseif k == hauteur - 8 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Max "..unitmb(volume_max))
- elseif k == hauteur - 6 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Etat :"..text)
- elseif k == hauteur - 5 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Cur "..unitmb(volume))
- elseif k == hauteur - 1 then
- gpu.set(x,vy,entete)
- end
- setColor(noir,blanc)
- end
- t_volume[n] = volume
- t_volume_max[n] = volume_max
- t_item[n] = item
- t_item_max[n] = item_max
- end
- local function on_off_rec(x,y,bit)
- local color
- if bit == true then
- text = " ON "
- color = vert
- elseif bit == false then
- text = " OFF "
- color = rouge
- end
- setColor(color,noir)
- gpu.set(x,y,text)
- setColor(noir,blanc)
- end
- local function process(x,y,hauteur,largeur,n)
- barre_verticale(x,y,hauteur,largeur,table_reception[4],table_reception[5],table_reception[6],table_reception[7],n,table_reception[2])
- old_volume[n] = t_volume[n]
- on_off_rec(x+10,41,table_reception[10][n])
- on_off_rec(x+10,42,table_reception[9][n])
- on_off_rec(x+10,43,table_reception[8][n])
- end
- local function tampon(x,y,largeur)
- amount_tampon = 0
- local inv = 0
- local capacity = 108*64
- for i = 1, 108 do
- if chest.getStackInSlot(i) == nil then
- inv = 0
- else
- inv = chest.getStackInSlot(i).qty
- end
- amount_tampon = amount_tampon + inv
- end
- local pct = amount_tampon / capacity
- local cur = math.floor(pct * largeur)
- local text1 = " "..string.format("%s / %s", amount_tampon, capacity)
- local text2 = " "..string.format("% 6.02f%%", pct*100)
- loadbar(x,y,largeur,cur,text1,color_tampon)
- loadbar(x,y+1,largeur,cur,text2,color_tampon)
- end
- local function vanne(x,y,bit,n)
- if bit == true then
- setColor(noir,vert)
- gpu.set(x,y+0," ║ ")
- gpu.set(x,y+1," ║ ")
- gpu.set(x,y+2," ║ ")
- rs.setBundledOutput(top,n-1,0)
- elseif bit == false then
- setColor(noir,rouge)
- gpu.set(x,y+0," ")
- gpu.set(x,y+1,"═════")
- gpu.set(x,y+2," ")
- rs.setBundledOutput(top,n-1,255)
- end
- setColor(noir,blanc)
- end
- local function fonction_auto(x,y,amount,capacity,bit)
- local pct = amount/capacity
- if etat_mode_auto == 1 then
- tableau_etat_sortie[n] = false
- elseif etat_mode_auto == 2 then
- if pct*100 > niveau_maxi then
- tableau_etat_sortie[n] = true
- elseif pct*100 < niveau_mini then
- tableau_etat_sortie[n] = false
- end
- elseif etat_mode_auto == 3 then
- tableau_etat_sortie[n] = true
- end
- if tableau_old_etat_sortie[n] == tableau_etat_sortie[n] then
- else
- vanne(x,y,bit,3)
- end
- if old_etat_mode_auto == etat_mode_auto then
- else
- if etat == 1 then
- setColor(noir, rouge)
- gpu.set(x+5,y+1,"Fermée ")
- elseif etat == 2 then
- setColor(noir, orange)
- gpu.set(x+5,y+1," Automatique")
- elseif etat == 3 then
- setColor(noir, vert)
- gpu.set(x+5,y+1,"Ouverte ")
- end
- end
- if init == 1 then
- tableau_old_etat_sortie[n] = tableau_etat_sortie[n]
- tableau_old_mode_auto[n] = tableau_mode_auto[n]
- end
- end
- local function on_off(x,y,n)
- if tableau_etat_sortie[n] == false then
- setColor(rouge, noir)
- gpu.set(x+4,y," OFF ")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- rs.setBundledOutput(top,n-1,255)
- elseif tableau_etat_sortie[n] == true then
- setColor(noir, rouge)
- gpu.set(x+4,y," OFF ")
- setColor(vert, noir)
- gpu.set(x,y," ON ")
- rs.setBundledOutput(top,n-1,0)
- end
- setColor(noir, blanc)
- end
- local function on_auto_off(x,y,n)
- if tableau_mode_auto[n] == 1 then
- setColor(rouge, noir)
- gpu.set(x+12,y," OFF ")
- setColor(noir, orange)
- gpu.set(x+5,y," AUTO ")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- elseif tableau_mode_auto[n] == 2 then
- setColor(noir, rouge)
- gpu.set(x+12,y," OFF ")
- setColor(orange, noir)
- gpu.set(x+5,y," AUTO ")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- elseif tableau_mode_auto[n] == 3 then
- setColor(noir, rouge)
- gpu.set(x+12,y," OFF ")
- setColor(noir, orange)
- gpu.set(x+5,y," AUTO ")
- setColor(vert, noir)
- gpu.set(x,y," ON ")
- end
- setColor(noir, blanc)
- end
- local function send(port)
- table_emmission[1] = nb_groupe --n° groupe
- table_emmission[2] = table_reception[2] --type machine
- table_emmission[3] = t_volume[1] --volume machine 1
- table_emmission[4] = t_volume_max[1] --volume_max machine 1
- table_emmission[5] = t_item[1] --item machine 1
- table_emmission[6] = t_item_max[1] --item_max machine 1
- table_emmission[7] = t_volume[2] --volume machine 2
- table_emmission[8] = t_volume_max[2] --volume_max machine 2
- table_emmission[9] = t_item[2] --item machine 2
- table_emmission[10] = t_item_max[2] --item_max machine 2
- table_emmission[11] = t_volume[3] --volume machine 3
- table_emmission[12] = t_volume_max[3] --volume_max machine 3
- table_emmission[13] = t_item[3] --item machine 3
- table_emmission[14] = t_item_max[3] --item_max machine 3
- table_emmission[15] = amount_tampon --tampon
- table_emmission[16] = 108*64 --tampon max
- local table_s = serialization.serialize(table_emmission)
- local IDcodes = "machinex3"
- modem.broadcast(port,IDcodes,table_s)
- local texte_vide = ""
- j = j + 1
- if j > 9 then
- j = 0
- texte_vide = " "
- end
- local text = " Envoi n°"..string.format("%s", j+1).." Confirmé"..texte_vide
- gpu.set(4+j,46,text)
- end
- print("Fonctions... ok")
- os.sleep(0,5)
- print("Initialisation programme...")
- os.sleep(1)
- --Trame de fond
- gpu.set(1,1,[[╔═════════════════════════════════════════════════════════════════════════╗]])
- gpu.set(1,2,[[║ ║]])
- gpu.set(1,3,[[╠═════════════════════════════════════════════════════════════════════════╣]])
- gpu.set(1,4,[[║ _________________________________________ ║]])
- gpu.set(1,5,[[║ / \ ║]])
- gpu.set(1,6,[[║ / COLONNE N° \ ║]])
- gpu.set(1,7,[[║ /_____________________________________________\ ║]])
- gpu.set(1,8,[[║ │ │ │ │ ║]])
- gpu.set(1,9,[[║ │ │ │ │ ┌───────────────────┐ ║]])
- gpu.set(1,10,[[║ │ │ │ │ │ Vanne Tampon │ ║]])
- gpu.set(1,11,[[║ │ │ │ │ │ ■ON■ ■OFF■ │ ║]])
- gpu.set(1,12,[[║ │ │ │ │ ├───────────────────┤ ║]])
- gpu.set(1,13,[[║ │ │ │ │ │ Vanne tirage cuve │ ║]])
- gpu.set(1,14,[[║ │ │ │ │ │ ■ON■ ■AUTO■ ■OFF■ │ ║]])
- gpu.set(1,15,[[║ │ │ │ │ ├───────────────────┤ ║]])
- gpu.set(1,16,[[║ │ │ │ │ │ Vanne gavage cuve │ ║]])
- gpu.set(1,17,[[║ │ │ │ │ │ ■ON■ ■OFF■ │ ║]])
- gpu.set(1,18,[[║ │ │ │ │ ├───────────────────┤ ║]])
- gpu.set(1,19,[[║ │ │ │ │ │ Etat des vannes │ ║]])
- gpu.set(1,20,[[║ │ │ │ │ │Vanne tampon ■OFF■ │ ║]])
- gpu.set(1,21,[[║ │ │ │ │ │Vanne tirage ■OFF■ │ ║]])
- gpu.set(1,22,[[║ │ │ │ │ │Vanne gavage ■OFF■ │ ║]])
- gpu.set(1,23,[[║ │ │ │ │ └───────────────────┘ ║]])
- gpu.set(1,24,[[║ │ │ │ │ ║]])
- gpu.set(1,25,[[║ │ │ │ │ ║]])
- gpu.set(1,26,[[║ │ │ │ │ ║]])
- gpu.set(1,27,[[║ │ │ │ │ ╔══< Alimentation ║]])
- gpu.set(1,28,[[║ │ │ │ │ ║ Item ║]])
- gpu.set(1,29,[[║ │ │ │ │ ║]])
- gpu.set(1,30,[[║ │ │ │ │ ═════ ║]])
- gpu.set(1,31,[[║ │ │ │ │ ║]])
- gpu.set(1,32,[[║ │ │ │ │ ┌───╨───────────────┐ ║]])
- gpu.set(1,33,[[║ │ │ │ │ │ Stock Tampon │ ║]])
- gpu.set(1,34,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,35,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,36,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,37,[[║ │ │ │ │ └─────────╥─────────┘ ║]])
- gpu.set(1,38,[[║ │ │ │ │ ║ ║]])
- gpu.set(1,39,[[║ ├───────────────┼───────────────┼───────────────┤ ║ ║]])
- gpu.set(1,40,[[║ │ Fonctionnement│ Fonctionnement│ Fonctionnement│ ║ ║]])
- gpu.set(1,41,[[║ │ Energie :■OFF■│ Energie :■OFF■│ Energie :■OFF■│ ║ ║]])
- gpu.set(1,42,[[║ │ Produit :■OFF■│ Produit :■OFF■│ Produit :■OFF■╞<══════════╝ ║]])
- gpu.set(1,43,[[║ │ Item :■OFF■│ Item :■OFF■│ Item :■OFF■│ ║]])
- gpu.set(1,44,[[║ ├───────────────┴───────────────┴───────────────┤ ║]])
- gpu.set(1,45,[[║ │ │ ║]])
- gpu.set(1,46,[[║ │ │ ║]])
- gpu.set(1,47,[[║ │ │ ║]])
- gpu.set(1,48,[[║ └────────────────────────╥──────────────────────┘ ╔═> Cuve principale ║]])
- gpu.set(1,49,[[║ ║ ║ ║]])
- gpu.set(1,50,[[║ ║]])
- gpu.set(1,51,[[║ ═════ ═════ ║]])
- gpu.set(1,52,[[║ ║]])
- gpu.set(1,53,[[║ ║ ║ ║]])
- gpu.set(1,54,[[║ /¯¯║¯¯\ /¯¯║¯¯\ ║]])
- gpu.set(1,55,[[║ /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ║ ¯¯¯¯¯¯¯¯¯¯¯¯¯\ ║]])
- gpu.set(1,56,[[║ │ Cuve Produit ║ │ ║]])
- gpu.set(1,57,[[║ │ ║ │ ║]])
- gpu.set(1,58,[[║ │ ║ │ ║]])
- gpu.set(1,59,[[║ \___________________________________________________________________/ ║]])
- gpu.set(1,60,[[╚═════════════════════════════════════════════════════════════════════════╝]])
- local function affbouton(x,y)
- vanne(26,50,false,1)
- vanne(53,50,false,2)
- vanne(55,29,false,3)
- end
- affbouton(2,2)
- gpu.set(41,6,tostring(nb_groupe))
- gpu.set(25,6,table_generale[ntable].titre)
- local function onTouch(_,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
- gpu.set(4,2,tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
- if x~=1 and y~=1 then
- elseif x==1 and y==1 then
- computer.pushSignal("quit")
- gpu.fill(1,1,160,50," ")
- term.setCursor(1,1)
- return false
- end
- end
- local function onModem(_,_,from,port,_,IDcode,message)
- table_reception = serialization.unserialize(message)
- if IDcode == "machine" then
- if table_reception[2] == ntable then
- if table_reception[1] == nb_groupe then
- local texte_vide = ""
- h = h + 1
- if h > 9 then
- h = 0
- texte_vide = " "
- end
- local text = " Réception n°"..string.format("%s", h+1).." Confirmé"..texte_vide
- gpu.set(4+h,45,text)
- process(4+16*(table_reception[3]-1),9,30,15,table_reception[3])
- send(port_modem)
- end
- end
- end
- end
- local function onTimer(_,timer)
- affbar(4,56,69)
- tampon(54,34,19)
- fonction_auto(53,50,amount,capacity,tableau_etat_sortie[3])
- return true
- end
- event.listen("touch",onTouch)
- event.listen("modem_message",onModem)
- local timer = event.timer(.1,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- event.ignore("modem_message",onModem)
- modem.close()
- gpu.fill(1,1,160,50," ")
- gpu.setResolution(160,40)
- --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