Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local uk = "unknown"
- local p = peripheral
- local cname = "cofh_thermalexpansion_energycell_"
- local mname = "monitor_"
- local sm = " "
- local k = 0 --X
- local l = 0 --X
- local m = 0 --X
- local n = 0 --X
- local o = 0 --X
- local q = 0 --X
- local r = 0 --X
- local s = 0 --X
- local t = 0
- local UHSLCmode = false
- local num = 0
- local energy = 0
- local maxenergy = 0
- local monitors = {}
- local cells = {}
- local timeINNum = 0
- local midnum = 0
- local cme = 0
- local ce = 0
- local mx = 0
- local inStartNum
- local inSumNum
- local inIDNum
- local onUHSLCmsg = "activateUHSLC"
- local offUHSLCmsg = "deactivateUHSLC"
- local onUHSLCmsgBACKDOOR = "openUHSLCbackdoor_activateUHSLC"
- local offUHSLCmsgBACKDOOR = "openUHSLCbackdoor_deactivateUHSLC"
- function configMonitor()
- while s==0 do
- term.clear()
- term.setCursorPos(1,1)
- local mid = 0
- print("Bitte gebe die aktive(!) Rednet-ID des 3x2 (bxl) Monitors ein!")
- print("Bitte beachte, dass das Programm abstuerzt, wenn es keine Zahl erhaelt!")
- mid = read()
- if tonumber(mid)>=0 then
- mx = mid+midnum
- mon = p.wrap(mname..tonumber(mx))
- mon.clear()
- print("Monitor erfolgreich konfiguriert!")
- os.sleep(1)
- s=1
- else
- print("Behindert?")
- os.sleep(1)
- s=0
- end
- end
- end
- function configCells()
- while l==0 do
- term.clear()
- term.setCursorPos(1,1)
- local cin = ""
- local inStart = ""
- local inSum = ""
- local inID = ""
- print("Willst du den automatischen oder den manuellen Modus für die Konfiguration deiner")
- print("Energiezellen benutzen?")
- print("Fuer den automatischen Modus, gebe 'auto' ein")
- print("Fuer den manuellen Modus, gebe 'manu' ein")
- print("Bitte beachte beim automatischen Modus, dass die IDs nacheinander folgen muessen! (Wie z.B.: 1,2,3,4,5,...)")
- print("(Der autom. Modus ist einfacher, der manuelle Modus ist auch nicht schlecht!)")
- print("HINWEIS: Dieses Programm ist fuer die Energiezellen von Thermal Expansion 4 geschrieben worden!")
- print("(Fuer PROs: Das bedeutet, dass fuer dieses Programm die Standardbezeichnung")
- print("'cofh_thermalexpansion_energycell_' benutzt wird!)")
- print("Bei Problemen entweder den Code aendern oder warten, bis einer was macht!")
- cin = read()
- if cin=="auto" then
- l=1
- term.clear()
- term.setCursorPos(1,1)
- print("Du hast den automatischen Modus gewaehlt")
- os.sleep(1)
- print("Gebe nun die niedrigste ID deiner Energiezellen ein!")
- inStart = read()
- local writeIStNfile = fs.open("inStartNum","w")
- writeIStNfile.writeLine(inStart)
- writeIStNfile.close()
- inStartNum = tonumber(inStart)
- os.sleep(1)
- print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
- inSum = read()
- local writeISNfile = fs.open("inSumNum","w")
- writeISNfile.writeLine(inSum)
- writeISNfile.close()
- inSumNum = tonumber(inSum)
- os.sleep(1)
- print("Energiezellen werden nun konfiguriert...")
- for i=1,inSumNum do
- x=inStartNum+inSumNum
- cells[i] = p.wrap(cname..x)
- print("Energiezelle 'c"..(i).."' wurde erfolgreich konfiguriert!")
- end
- os.sleep(1)
- print("Energiezellen sind nun konfiguriert!")
- os.sleep(1)
- else
- if cin=="manu" then
- l=1
- term.clear()
- term.setCursorPos(1,1)
- print("Du hast den manuellen Modus gewaehlt")
- os.sleep(1)
- print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
- inSum = read()
- local writeISNfile = fs.open("inSumNum","w")
- writeISNfile.writeLine(inSum)
- writeISNfile.close()
- inSumNum = tonumber(inSum)
- print("Gebe nun die(/alle) ID(s) deiner Energiezelle(n) nacheinander ein!")
- for i=1,inSumNum do
- local inID = read()
- local writeIIDNfile = fs.open("inIDNum","w")
- writeIIDNfile.writeLine(inID)
- writeIIDNfile.close()
- inIDNum = tonumber(inID)
- cells[i] = p.wrap(cname..inIDNum)
- print("Energiezelle 'c"..i.."' wurde erfolgreich konfiguriert!")
- end
- os.sleep(1)
- print("Energiezellen sind nun konfiguriert!")
- os.sleep(1)
- else
- l=0
- term.clear()
- term.setCursorPos(1,1)
- print(cin.." gibt es nicht!")
- os.sleep(1)
- end
- end
- end
- os.sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- end
- function configComputer()
- while m==0 do
- term.clear()
- term.setCursorPos(1,1)
- local sideRN = ""
- print("Dein Computer wird jetzt fuer Rednet konfiguriert!")
- print("Gebe nun ein, an welcher Seite des PCs das (wireless) Modem für Rednet angeschlossen ist!")
- print("Verfuegbare Seiten: oben('top'), unten('bottom'), rechts('right'), links('left'), hinten('back')")
- print("Bitte beachte, dass das Programm abstuerzt, wenn an der angegebenen Seite kein Modem angeschlossen ist!")
- sideRN = read()
- if sideRN == "top" or sideRN == "bottom" or sideRN == "right" or sideRN == "left" or sideRN == "back" then
- rednet.open(sideRN)
- print("Eingabe akzeptabel!")
- m=1
- os.sleep(1)
- else
- print(sideRN.." -Eingabe nicht akzeptabel!")
- m=0
- os.sleep(1)
- end
- end
- while n==0 do
- term.clear()
- term.setCursorPos(1,1)
- --local timeIN = ""
- print("Gebe nun die Zeit in Sekunden ein, wie oft der Computer die Daten der Energiezelle(n) abfragen soll!")
- print("Alles kleiner gleich 0 ist nicht akzeptabel! Wenn du bspw. jede halbe Sekunde haben willst, dann gebe '0.5' ein!")
- local timeIN = read()
- local writeTINNfile = fs.open("timeINNum","w")
- writeTINNfile.writeLine(timeIN)
- writeTINNfile.close()
- timeINNum = tonumber(timeIN)
- if timeINNum<=0 then
- print("Bist du eigentlich behindert? Ich hab doch gesagt, dass '"..timeINNum.."' nicht akzeptiert wird -.-")
- n=0
- os.sleep(1)
- else
- print("Updateintervall wurde erfolgreich auf '"..timeINNum.."'s gesetzt")
- n=1
- os.sleep(1)
- end
- end
- end
- function configUHSLC()
- while r==0 do
- local inUHSLCid = ""
- term.clear()
- term.setCursorPos(1,1)
- print("Gebe nun die ID des UHSLC-Controllers ein!")
- print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhaelt!")
- inUHSLCid = read()
- local writeIUHSLCIDfile = fs.open("inUHSLCidNum","w")
- writeIUHSLCIDfile.writeLine(inUHSLCid)
- writeIUHSLCIDfile.close()
- inUHSLCidNum = tonumber(inUHSLCid)
- if inUHSLCidNum>=0 then
- print("ID fuer den UHSLC-Controller wurde erfolgreich eingerichtet!")
- r=1
- os.sleep(1)
- else
- print("Bitte eine Zahl eingeben, die groesser gleich 0 ist!")
- r=0
- os.sleep(1)
- end
- end
- while t==0 do
- local inUHSLCidMAIN = ""
- term.clear()
- term.setCursorPos(1,1)
- print("Gebe nun die ID des UHSLC-Hauptcomputers ein!")
- print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhält!")
- inUHSLCidMAIN = read()
- local writeIUHSLCIDMAINfile = fs.open("inUHSLCidMAINNum","w")
- writeIUHSLCIDMAINfile.writeLine(inUHSLCidMAIN)
- writeIUHSLCIDMAINfile.close()
- inUHSLCidMAINNum= tonumber(inUHSLCidMAIN)
- if inUHSLCidMAINNum>=0 then
- print("ID fuer den UHSLC-Hauptcomputer wurde erfolgreich eingerichtet!")
- t=1
- os.sleep(1)
- else
- print("Bitte eine Zahl eingeben, die groesser gleich 0 ist!")
- t=0
- os.sleep(1)
- end
- end
- end
- function setupMonitor()
- mon.setBackgroundColor(colors.lime)
- mon.setTextColor(colors.blue)
- for i=0,20 do
- mon.setCursorPos(1,i+1)
- mon.write(sm)
- end
- mon.setCursorPos(1,1)
- mon.write(" ENERGIE-MONITOR"..sm)
- end
- function readEnergy()
- ce = 0
- cme = 0
- local readISNfile = fs.open("inSumNum","r")
- local readIStNfile = fs.open("inStartNum","r")
- local fileDataISN={}
- local fileDataIStN={}
- local ISNLine = readISNfile.readLine()
- local IStNLine = readIStNfile.readLine()
- repeat
- table.insert(fileDataISN,ISNLine)
- ISNLine = readISNfile.readLine()
- until ISNLine == nil
- repeat
- table.insert(fileDataIStN,IStNLine)
- IStNLine = readIStNfile.readLine()
- until IStNLine == nil
- for i=1,(tonumber(fileDataISN[1])+0) do
- cells = {}
- cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
- energy = cells[i].getEnergyStored("unknown")
- maxenergy = cells[i].getMaxEnergyStored("unknown")
- ce = ce+energy
- cme = cme+maxenergy
- end
- readISNfile.close()
- readIStNfile.close()
- end
- function writeEnergy()
- local readTINNfile = fs.open("timeINNum","r")
- local fileDataTINN={}
- local TINNLine = readTINNfile.readLine()
- repeat
- table.insert(fileDataTINN,TINNLine)
- TINNLine = readTINNfile.readLine()
- until TINNLine == nil
- readTINNfile.close()
- mon.setCursorPos(1,2)
- mon.clearLine()
- mon.write("Energie: "..ce.."RF"..sm)
- mon.setCursorPos(1,3)
- local cen = ce
- if cen>ceo then
- mon.clearLine()
- mon.write("Energiegewinn seit letztem"..sm)
- mon.setCursorPos(1,4)
- mon.clearLine()
- mon.write("Check ("..fileDataTINN[1].."s): +"..cen-ceo.."RF"..sm)
- else
- if cen==ceo then
- mon.clearLine()
- mon.write("Gleicher Energiestand"..sm)
- mon.setCursorPos(1,4)
- mon.clearLine()
- mon.write(sm)
- else
- if c13n<c13o then
- mon.clearLine()
- mon.write("Energieverlust seit letztem"..sm)
- mon.setCursorPos(1,4)
- mon.clearLine()
- mon.write("Check ("..fileDataTINN[1].."s): -"..ceo-cen.."RF"..sm)
- end
- end
- end
- local ep = cen/cme*100
- mon.setCursorPos(1,6)
- mon.clearLine()
- mon.write(" (in '%'):"..sm)
- mon.setCursorPos(1,7)
- mon.clearLine()
- mon.write(ep.."%"..sm)
- end
- function calcEnergyA()
- if o==0 then
- ceo=0
- o=1
- end
- end
- function calcEnergyB()
- ceo = 0
- local readISNfile = fs.open("inSumNum","r")
- local readIStNfile = fs.open("inStartNum","r")
- local fileDataISN={}
- local fileDataIStN={}
- local ISNLine = readISNfile.readLine()
- local IStNLine = readIStNfile.readLine()
- repeat
- table.insert(fileDataISN,ISNLine)
- ISNLine = readISNfile.readLine()
- until ISNLine == nil
- repeat
- table.insert(fileDataIStN,IStNLine)
- IStNLine = readIStNfile.readLine()
- until IStNLine == nil
- for i=1,(tonumber(fileDataISN[1])+0) do
- local eo = 0
- cells = {}
- cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
- eo = cells[i].getEnergyStored("unknown")
- ceo = ceo+eo
- end
- readISNfile.close()
- readIStNfile.close()
- end
- function rednetListener()
- local readTINNfile = fs.open("timeINNum","r")
- local fileDataTINN={}
- local TINNLine = readTINNfile.readLine()
- repeat
- table.insert(fileDataTINN,TINNLine)
- TINNLine = readTINNfile.readLine()
- until TINNLine == nil
- local RNid,RNmsg,RNdist = rednet.receive(tonumber((fileDataTINN[1]+0)))
- readTINNfile.close()
- local readIUHSLCIDMAINfile = fs.open("inUHSLCidMAINNum","r")
- local readIUHSLCIDfile = fs.open("inUHSLCidNum","r")
- local fileDataIUHSLCIDMAIN={}
- local fileDataIUHSLCID={}
- local IUHSLCIDMAINLine = readIUHSLCIDMAINfile.readLine()
- local IUHSLCIDLine = readIUHSLCIDfile.readLine()
- repeat
- table.insert(fileDataIUHSLCIDMAIN,IUHSLCIDMAINLine)
- IUHSLCIDMAINLine = readIUHSLCIDMAINfile.readLine()
- until IUHSLCIDMAINLine == nil
- repeat
- table.insert(fileDataIUHSLCID,IUHSLCIDLine)
- IUHSLCIDLine = readIUHSLCIDfile.readLine()
- until IUHSLCIDLine == nil
- if RNid==tonumber(fileDataIUHSLCIDMAIN[1]) then
- if RNmsg==onUHSLCmsg then
- print("UHSLC-Hauptcomputer (#"..RNid..") hat den UHSLC-Modus aktiviert!")
- UHSLC = true
- else
- if RNmsg==offUHSLCmsg then
- print("UHSLC-Hauptcomputer (#"..RNid..") hat den UHSLC-Modus aktiviert!")
- UHSLC = false
- else
- print("UHSLC-Hauptcomputer (#"..RNid..") schrieb: "..RNmsg)
- UHSLC = false
- end
- end
- else
- if RNid==tonumber(fileDataIUHSLCID[1]) then
- if RNmsg==onUHSLCmsg then
- print("UHSLC-Controller (#"..RNid..") hat den UHSLC-Modus aktiviert!")
- UHSLC = true
- else
- if RNmsg==offUHSLCmsg then
- print("UHSLC-Controller (#"..RNid..") hat den UHSLC-Modus deaktiviert!")
- UHSLC = false
- else
- print("UHSLC-Controller (#"..RNid..") schrieb: "..RNmsg)
- UHSLC = false
- end
- end
- else
- if RNmsg==onUHSLCmsgBACKDOOR then
- print("Ein unbekanntes Gerät (#"..RNid..") hat den UHSLC-Modus erfolgreich per Backdoor aktiviert!")
- UHSLC = true
- else
- if RNmsg==offUHSLCmsgBACKDOOR then
- print("Ein unbekanntes Gerät (#"..RNid..") hat den UHSLC-Modus erfolgreich per Backdoor deaktiviert!")
- UHSLC = false
- else
- if RNmsg=="update" then
- UHSLC = false
- else
- --print("(#"..RNid..") schrieb: "..RNmsg)
- UHSLC = false
- end
- end
- end
- end
- end
- end
- function monitorUpdater()
- if UHSLC then
- --mon.clear()
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.blue)
- for i=1,30 do
- mon.setCursorPos(1,i+1)
- mon.write(sm)
- end
- mon.setCursorPos(1,1)
- mon.write(" ENERGIE-MONITOR"..sm)
- mon.setCursorPos(12,12)
- mon.write("UHSLC")
- mon.setCursorPos(1,1)
- else
- --mon.clear()
- mon.setBackgroundColor(colors.lime)
- mon.setTextColor(colors.blue)
- for i=1,30 do
- mon.setCursorPos(1,i+1)
- mon.write(sm)
- end
- mon.setCursorPos(1,1)
- mon.write(" ENERGIE-MONITOR"..sm)
- end
- end
- while true do
- if k==0 then
- configComputer()
- configMonitor()
- configUHSLC()
- configCells()
- k=1
- end
- if q==0 then
- setupMonitor()
- q=1
- end
- calcEnergyA()
- readEnergy()
- writeEnergy()
- calcEnergyB()
- rednetListener()
- monitorUpdater()
- --local readTINNfile = fs.open("timeINNum","r")
- --local fileDataTINN={}
- --local TINNLine = readTINNfile.readLine()
- --repeat
- --table.insert(fileDataTINN,TINNLine)
- --TINNLine = readTINNfile.readLine()
- --until TINNLine == nil
- --os.sleep(tonumber((fileDataTINN[1]+0)))
- --readTINNfile.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement