Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --/////////////////////////////////////////////////
- --//--------- PROGRMAME COMPUTEUR CRAFT ---------//
- --//--------- ************************* ---------//
- --//----- AFFICHAGE DYNAMIQUE ET INTERACTIF -----//
- --//---- DE TUBINE ET REATEUR DE BIGREACTOR -----//
- --/////////////////////////////////////////////////
- --Confguration
- rednet.open("left")
- local ecran=peripheral.wrap("top")
- local idTurbine = "MasterEnergie"
- --//////////////////////////////////////////////////
- --//------------ Variables Globale ---------------//
- --//////////////////////////////////////////////////
- local nbm = 8 --Nombre de turbine afficher
- local timeOut = 5 --temps maximal entre deux trames envoyees par un ordi
- local k=0
- local data={}
- local data100={}
- --/////////////////////////////////////////////////
- --//------------------ Main ---------------------//
- --/////////////////////////////////////////////////
- -- Fonction de recuperation des informations envoyees en wifi
- function Ecoute()
- --Init de data[*]["time"] a 0
- for i=1,nbm do
- data[i]={}
- data[i]["time"] = 0
- end
- data[100]={}
- data100["time"] = 0
- while true do
- local event, id, ID, TablData = os.pullEvent("rednet_message")
- if ID>=1 and ID<=8 then
- data[ID]=textutils.unserialize(TablData)
- data[ID]["time"]=os.clock()
- elseif ID==100 then
- data100=textutils.unserialize(TablData)
- data100["time"]=os.clock()
- end
- end
- end
- -- Fonction du main d'affichage
- function Affichage()
- local i
- Init()
- while true do --main
- k=k+1
- AffichageTurbine()
- AffichageReactor()
- DetectionPCoff()
- os.sleep(0.8)
- end
- end
- -- Tout est dans le nom
- function Tactille()
- local Mdata={}
- while true do
- local e, bt, yp, xp = os.pullEvent("monitor_touch")
- --Pour les turbines
- local i=1
- for i=1,nbm do
- --Choix des positions
- local x=1 y=1
- if i==1 then x=1 y=3
- elseif i==2 then x=1 y=52
- elseif i==3 then x=11 y=3
- elseif i==4 then x=11 y=52
- elseif i==5 then x=21 y=3
- elseif i==6 then x=21 y=52
- elseif i==7 then x=31 y=3
- elseif i==8 then x=31 y=52
- end
- --Activee/Desactivee
- if yp>=y+6 and yp<=y+11 and xp>=x+2 and xp<=x+5 then
- Mdata["numberTurbine"] = i
- Mdata["sInductor"] = data[i]["gInductor"]
- if data[i]["gActive"] == true then
- Mdata["sActive"]=false
- else
- Mdata["sActive"]=true
- end
- end
- --Engagement/Desengagement
- if xp==x+1 and yp>=y+6 and yp<=y+12 then
- Mdata["numberTurbine"] = i
- Mdata["sActive"] = data[i]["gActive"]
- if data[i]["gInductor"] == true then
- Mdata["sInductor"]=false
- else
- Mdata["sInductor"]=true
- end
- end
- end
- --Pour le reacteur
- --Activee/Desactivee
- if yp>=31 and yp<=40 and xp>=10 and xp<=28 then
- Mdata["numberTurbine"] = 100
- if data100["gActive"] == true then
- Mdata["sActive"]=false
- else
- Mdata["sActive"]=true
- end
- end
- rednet.broadcast(idTurbine,textutils.serialize(Mdata))
- os.sleep(0.5)
- end
- end
- --/////////////////////////////////////////////////
- --//---- Les fonctions dediees a Affichage() ----//q
- --/////////////////////////////////////////////////
- -- Fonction d'initialisation
- function Init()
- local cpt=1
- windows = {} --pour les images (paint)
- windows[1] = window.create(ecran, 3 , 2 , 18, 8, true)--Tubines
- windows[2] = window.create(ecran, 52, 2 , 18, 8, true)
- windows[3] = window.create(ecran, 3 , 12, 18, 8, true)
- windows[4] = window.create(ecran, 52, 12, 18, 8, true)
- windows[5] = window.create(ecran, 3 , 22, 18, 8, true)
- windows[6] = window.create(ecran, 52, 22, 18, 8, true)
- windows[7] = window.create(ecran, 3 , 32, 18, 8, true)
- windows[8] = window.create(ecran, 52, 32, 18, 8, true)
- windows[100] = window.create(ecran, 25, 10, 21, 35, true)--Reacteur
- windows[101] = window.create(ecran, 23, 2, 26, 6, true)--Titre
- --Chargement
- ecran.setBackgroundColor(colors.blue)
- ecran.clear()
- line(10 ,20,50 ,4, colors.black)
- for cpt=1, 50 do
- line(10 ,20 ,cpt,4, colors.green)
- os.sleep(0.05)
- end
- os.sleep(0.5)
- ecran.setBackgroundColor(colors.black)
- ecran.clear()
- Titre = paintutils.loadImage("Titre")
- windows[101].setBackgroundColor(colors.black)
- windows[101].setTextColor(colors.black)
- windows[101].clear()
- term.redirect(windows[101])
- paintutils.drawImage(Titre, 1, 1)
- end
- -- Fonction d'affichage des donnees des turbines
- function AffichageTurbine()
- local turb --l'image charger
- local i=1
- if k == 5 then k = 1 end --pour les images
- for i=1,nbm do --data[1] a data[nbm]
- --choix de la position
- local x=1 y=1
- if i==1 then x=1 y=3
- elseif i==2 then x=1 y=52
- elseif i==3 then x=11 y=3
- elseif i==4 then x=11 y=52
- elseif i==5 then x=21 y=3
- elseif i==6 then x=21 y=52
- elseif i==7 then x=31 y=3
- elseif i==8 then x=31 y=52
- end
- --Debut de l'affichage
- ecran.setBackgroundColor(colors.black)
- ecran.setTextColor(colors.white)
- ecran.setCursorPos(y+4,x) --**--
- ecran.write("Turbine "..i)
- if data[i]["PCon"] == true then
- --L'activite
- if data[i]["gActive"] == true then
- turb = paintutils.loadImage("turb"..k)
- else
- turb = paintutils.loadImage("turb0")
- end
- windows[i].setBackgroundColor(colors.black)
- windows[i].setTextColor(colors.black)
- windows[i].clear()
- term.redirect(windows[i])
- paintutils.drawImage(turb, 7, 2)
- --L'engagement
- if data[i]["gInductor"]==true then
- ecran.setCursorPos(y+4,x+1)
- ecran.setBackgroundColor(colors.black)
- ecran.write(" ")
- line(y+5 ,x+1 ,7 ,1, colors.blue)
- ecran.setCursorPos(y+5,x+1)
- ecran.write("Engager")
- ecran.setBackgroundColor(colors.black)
- ecran.write(" ")
- else
- line(y+4 ,x+1 ,7 ,1, colors.red)
- ecran.setCursorPos(y+4,x+1)
- ecran.write("Desengager")
- ecran.setBackgroundColor(colors.black)
- end
- ecran.setTextColor(colors.white)
- ecran.setCursorPos(y+1,x+7)
- ecran.write("Rotor: ")
- if data[i]["gSpeed"]<800 then
- ecran.setTextColor(colors.red)
- elseif data[i]["gSpeed"]<1000 then
- ecran.setTextColor(colors.blue)
- elseif data[i]["gSpeed"]<1700 then
- ecran.setTextColor(colors.red)
- elseif data[i]["gSpeed"]<1900 then
- ecran.setTextColor(colors.blue)
- else
- ecran.setTextColor(colors.red)
- end
- ecran.setCursorPos(y+8,x+7)
- ecran.write(number_format(data[i]["gSpeed"]).." RPM ")
- ecran.setTextColor(colors.white)
- ecran.setCursorPos(y,x+8)
- ecran.write("Prod : "..number_format(data[i]["gProductLastTick"]).." RF/t ")
- else
- turb = paintutils.loadImage("PCoff")
- windows[i].setBackgroundColor(colors.black)
- windows[i].setTextColor(colors.black)
- windows[i].clear()
- term.redirect(windows[i])
- paintutils.drawImage(turb, 5, 1)
- end
- end
- end
- --Fonction d'affichage des donnees du reacteur
- function AffichageReactor()
- local reactor --L'image charger
- local y=25 x=9
- --Affichage de l'activite
- ecran.setBackgroundColor(colors.black)
- ecran.setTextColor(colors.white)
- ecran.setCursorPos(y+7,x)
- ecran.write("Reactor")
- if data100["PCon"] == true then
- if data100["gActive"]==true then
- reactor = paintutils.loadImage("reactor")
- else
- reactor = paintutils.loadImage("reactoroff")
- end
- windows[100].setBackgroundColor(colors.black)
- windows[100].setTextColor(colors.black)
- windows[100].clear()
- term.redirect(windows[100])
- paintutils.drawImage(reactor, 7, 1)
- ecran.setBackgroundColor(colors.black)
- --Affichage des donnees
- ecran.setTextColor(colors.white)
- ecran.setCursorPos(y,x+20) --le stock de yell en ingot
- ecran.write("Fuel: "..number_format(data100["gFuelAmount"]).." yell ")
- ecran.setCursorPos(y+1,x+21)
- ecran.write("Decher: "..number_format(data100["gWasteAmount"]).." cyanit ")
- ecran.setCursorPos(y+5,x+22) --le stock de yell en %
- ecran.write("Stock: "..math.ceil(data100["gFuelAmount"]/data100["gFuelAmountMax"]*100).."%")
- ecran.setCursorPos(y+1,x+23) --production en mb/t
- ecran.write("Prod: "..number_format(data100["gHotFluidProducedLastTick"]).." mb/t ")
- ecran.setCursorPos(y,x+24) --consomation de yell en mb
- ecran.write("Conso: "..number_format(data100["gFuelConsumedLastTick"]))
- ecran.setCursorPos(y+9,x+24)
- ecran.write("mb/t de yell")
- ecran.setCursorPos(y+4,x+25) --temperature en C
- ecran.write("Temp: "..number_format(data100["gCasingtemperature"]).." C ")
- ecran.setCursorPos(y+4,x+26) --radiations %
- ecran.write("Reacto: "..number_format(data100["gFuelReactivity"]).." % ")
- else
- reactor = paintutils.loadImage("PCroff")
- windows[100].setBackgroundColor(colors.black)
- windows[100].setTextColor(colors.black)
- windows[100].clear()
- term.redirect(windows[100])
- paintutils.drawImage(reactor, 7, 1)
- end
- end
- --Detection d'un PC eteint
- function DetectionPCoff()
- local heure = os.clock()
- for i=1,nbm do
- if((heure - data[i]["time"]) > timeOut) then
- data[i]["PCon"] = false
- end
- end
- if((heure - data100["time"]) > timeOut) then
- data100["PCon"] = false
- end
- end
- --/////////////////////////////////////////////////
- --//---------- Les fonctions divers -------------//
- --/////////////////////////////////////////////////
- -- Gestion de rectangle de couleur
- function line(x ,y ,long ,larg, color_font)
- ecran.setBackgroundColor(color_font)
- for yp=y, y+larg-1 do
- ecran.setCursorPos(x,yp)
- ecran.write(string.rep(" ", long))
- end
- end
- -- Bare de progression
- function prog(x ,y ,long ,larg, valmin, valmax ,color_bar ,color_font)
- line(x ,y ,long ,larg, color_font)
- local bar = math.floor((valmin/valmax)*long)
- line(x ,y ,bar ,larg, color_bar)
- end
- -- Fonction pour transformer 9876543 en 9 876 543
- function number_format(n)
- local test=mille(n)
- if test.Mille==0 then
- return math.floor(n)
- else
- test.Mille=mille(test.Mille)
- if test.Mille.Mille==0 then
- return test.Mille.Cent.." "..cent(test.Cent)
- else
- return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
- end
- end
- end
- -- Fonction pour etre sur d'avoir trois chiffres (99 devient 099, 9 devient 009)
- function cent(n)
- n=math.floor(n)
- if n>99 then
- return n
- elseif n>9 then
- return "0"..n
- else
- return "00"..n
- end
- end
- -- Creer un objet avec les centaines d'un cotee les milliers de l'autre
- function mille(n)
- if n<1000 then
- return {Mille=0,Cent=n}
- else
- return {Mille=math.floor(n/1000),Cent=n%1000}
- end
- end
- -- Execute 3 fontions en paralleles (Main)
- parallel.waitForAll(Ecoute,Affichage,Tactille)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement