Advertisement
TheProgrammer

jabcuw4fh89

Aug 23rd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.09 KB | None | 0 0
  1. local uk = "unknown"
  2. local p = peripheral
  3. local cname = "cofh_thermalexpansion_energycell_"
  4. local mname = "monitor_"
  5. local sm = "                                                                     "
  6. local k = 0 --X
  7. local l = 0 --X
  8. local m = 0 --X
  9. local n = 0 --X
  10. local o = 0 --X
  11. local q = 0 --X
  12. local r = 0 --X
  13. local s = 0 --X
  14. local t = 0
  15. local UHSLC = false
  16. local changedUHSLC = true
  17. local num = 0
  18. local energy = 0
  19. local maxenergy = 0
  20. local monitors = {}
  21. local cells = {}
  22. local timeINNum = 0
  23. local midnum = 0
  24. local cme = 0
  25. local ce = 0
  26. local mx = 0
  27. local inStartNum
  28. local inSumNum
  29. local inIDNum
  30. local onUHSLCmsg = "activateUHSLC"
  31. local offUHSLCmsg = "deactivateUHSLC"
  32. local onUHSLCmsgBACKDOOR = "openUHSLCbackdoor_activateUHSLC"
  33. local offUHSLCmsgBACKDOOR = "openUHSLCbackdoor_deactivateUHSLC"
  34.  
  35. function configMonitor()
  36.  while s==0 do
  37.   term.clear()
  38.   term.setCursorPos(1,1)
  39.   local mid = 0
  40.   print("Bitte gebe die aktive(!) Rednet-ID des 3x2 (bxl) Monitors ein!")
  41.   print("Bitte beachte, dass das Programm abstuerzt, wenn es keine Zahl erhaelt!")
  42.   mid = read()
  43.   if tonumber(mid)>=0 then
  44.    mx = mid+midnum
  45.    mon = p.wrap(mname..tonumber(mx))
  46.    mon.clear()
  47.    print("Monitor erfolgreich konfiguriert!")
  48.    os.sleep(1)
  49.    s=1
  50.   else
  51.    print("Behindert?")
  52.    os.sleep(1)
  53.    s=0
  54.   end
  55.  end
  56. end
  57.  
  58. function configCells()
  59.  while l==0 do
  60.   term.clear()
  61.   term.setCursorPos(1,1)
  62.   local cin = ""
  63.   local inStart = ""
  64.   local inSum = ""
  65.   local inID = ""
  66.   print("Willst du den automatischen oder den manuellen Modus für die Konfiguration deiner")
  67.   print("Energiezellen benutzen?")
  68.   print("Fuer den automatischen Modus, gebe 'auto' ein")
  69.   print("Fuer den manuellen Modus, gebe 'manu' ein")
  70.   print("Bitte beachte beim automatischen Modus, dass die IDs nacheinander folgen muessen! (Wie z.B.: 1,2,3,4,5,...)")
  71.   print("(Der autom. Modus ist einfacher, der manuelle Modus ist auch nicht schlecht!)")
  72.   print("HINWEIS: Dieses Programm ist fuer die Energiezellen von Thermal Expansion 4 geschrieben worden!")
  73.   print("(Fuer PROs: Das bedeutet, dass fuer dieses Programm die Standardbezeichnung")
  74.   print("'cofh_thermalexpansion_energycell_' benutzt wird!)")
  75.   print("Bei Problemen entweder den Code aendern oder warten, bis einer was macht!")
  76.   cin = read()
  77.   if cin=="auto" then
  78.    l=1
  79.    term.clear()
  80.    term.setCursorPos(1,1)
  81.    print("Du hast den automatischen Modus gewaehlt")
  82.    os.sleep(1)
  83.    print("Gebe nun die niedrigste ID deiner Energiezellen ein!")
  84.    inStart = read()
  85.    local writeIStNfile = fs.open("inStartNum","w")
  86.    writeIStNfile.writeLine(inStart)
  87.    writeIStNfile.close()
  88.    inStartNum = tonumber(inStart)
  89.    os.sleep(1)
  90.    print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
  91.    inSum = read()
  92.    local writeISNfile = fs.open("inSumNum","w")
  93.    writeISNfile.writeLine(inSum)
  94.    writeISNfile.close()
  95.    inSumNum = tonumber(inSum)
  96.    os.sleep(1)
  97.    print("Energiezellen werden nun konfiguriert...")
  98.    for i=1,inSumNum do
  99.     x=inStartNum+inSumNum
  100.     cells[i] = p.wrap(cname..x)
  101.     print("Energiezelle 'c"..(i).."' wurde erfolgreich konfiguriert!")
  102.    end
  103.    os.sleep(1)
  104.    print("Energiezellen sind nun konfiguriert!")
  105.    os.sleep(1)
  106.   else
  107.    if cin=="manu" then
  108.     l=1
  109.     term.clear()
  110.     term.setCursorPos(1,1)
  111.     print("Du hast den manuellen Modus gewaehlt")
  112.     os.sleep(1)
  113.     print("Gebe nun die Gesamtanzahl deiner Energiezellen ein!")
  114.     inSum = read()
  115.     local writeISNfile = fs.open("inSumNum","w")
  116.     writeISNfile.writeLine(inSum)
  117.     writeISNfile.close()
  118.     inSumNum = tonumber(inSum)
  119.     print("Gebe nun die(/alle) ID(s) deiner Energiezelle(n) nacheinander ein!")
  120.     for i=1,inSumNum do
  121.      local inID = read()
  122.      local writeIIDNfile = fs.open("inIDNum","w")
  123.      writeIIDNfile.writeLine(inID)
  124.      writeIIDNfile.close()
  125.      inIDNum = tonumber(inID)
  126.      cells[i] = p.wrap(cname..inIDNum)
  127.      print("Energiezelle 'c"..i.."' wurde erfolgreich konfiguriert!")
  128.     end
  129.     os.sleep(1)
  130.     print("Energiezellen sind nun konfiguriert!")
  131.     os.sleep(1)
  132.    else
  133.     l=0
  134.     term.clear()
  135.     term.setCursorPos(1,1)
  136.     print(cin.." gibt es nicht!")
  137.     os.sleep(1)
  138.    end
  139.   end
  140.  end
  141.  os.sleep(2)
  142.  term.clear()
  143.  term.setCursorPos(1,1)
  144. end
  145.  
  146. function configComputer()
  147.  while m==0 do
  148.   term.clear()
  149.   term.setCursorPos(1,1)
  150.   local sideRN = ""
  151.   print("Dein Computer wird jetzt fuer Rednet konfiguriert!")
  152.   print("Gebe nun ein, an welcher Seite des PCs das (wireless) Modem für Rednet angeschlossen ist!")
  153.   print("Verfuegbare Seiten: oben('top'), unten('bottom'), rechts('right'), links('left'), hinten('back')")
  154.   print("Bitte beachte, dass das Programm abstuerzt, wenn an der angegebenen Seite kein Modem angeschlossen ist!")
  155.   sideRN = read()
  156.   if sideRN == "top" or sideRN == "bottom" or sideRN == "right" or sideRN == "left" or sideRN == "back" then
  157.    rednet.open(sideRN)
  158.    print("Eingabe akzeptabel!")
  159.    m=1
  160.    os.sleep(1)
  161.   else
  162.    print(sideRN.." -Eingabe nicht akzeptabel!")
  163.    m=0
  164.    os.sleep(1)
  165.   end  
  166.  end
  167.  while n==0 do
  168.   term.clear()
  169.   term.setCursorPos(1,1)
  170.   --local timeIN = ""
  171.   print("Gebe nun die Zeit in Sekunden ein, wie oft der Computer die Daten der Energiezelle(n) abfragen soll!")
  172.   print("Alles kleiner gleich 0 ist nicht akzeptabel! Wenn du bspw. jede halbe Sekunde haben willst, dann gebe '0.5' ein!")
  173.   local timeIN = read()
  174.   local writeTINNfile = fs.open("timeINNum","w")
  175.   writeTINNfile.writeLine(timeIN)
  176.   writeTINNfile.close()
  177.   timeINNum = tonumber(timeIN)
  178.   if timeINNum<=0 then
  179.    print("Bist du eigentlich behindert? Ich hab doch gesagt, dass '"..timeINNum.."' nicht akzeptiert wird -.-")
  180.    n=0
  181.    os.sleep(1)
  182.   else
  183.    print("Updateintervall wurde erfolgreich auf '"..timeINNum.."'s gesetzt")
  184.    n=1
  185.    os.sleep(1)
  186.   end
  187.  end
  188. end
  189.  
  190. function configUHSLC()
  191.  while r==0 do
  192.   local inUHSLCid = ""
  193.   term.clear()
  194.   term.setCursorPos(1,1)
  195.   print("Gebe nun die ID des UHSLC-Controllers ein!")
  196.   print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhaelt!")
  197.   inUHSLCid = read()
  198.   local writeIUHSLCIDfile = fs.open("inUHSLCidNum","w")
  199.   writeIUHSLCIDfile.writeLine(inUHSLCid)
  200.   writeIUHSLCIDfile.close()
  201.   inUHSLCidNum = tonumber(inUHSLCid)
  202.   if inUHSLCidNum>=0 then
  203.    print("ID fuer den UHSLC-Controller wurde erfolgreich eingerichtet!")
  204.    r=1
  205.    os.sleep(1)
  206.   else
  207.    print("Bitte eine Zahl eingeben, die groesser gleich 0 ist!")
  208.    r=0
  209.    os.sleep(1)
  210.   end
  211.  end
  212.  while t==0 do
  213.   local inUHSLCidMAIN = ""
  214.   term.clear()
  215.   term.setCursorPos(1,1)
  216.   print("Gebe nun die ID des UHSLC-Hauptcomputers ein!")
  217.   print("Bitte beachte, dass das Programm abstürzt, wenn es keine Zahl erhält!")
  218.   inUHSLCidMAIN = read()
  219.   local writeIUHSLCIDMAINfile = fs.open("inUHSLCidMAINNum","w")
  220.   writeIUHSLCIDMAINfile.writeLine(inUHSLCidMAIN)
  221.   writeIUHSLCIDMAINfile.close()
  222.   inUHSLCidMAINNum= tonumber(inUHSLCidMAIN)
  223.   if inUHSLCidMAINNum>=0 then
  224.    print("ID fuer den UHSLC-Hauptcomputer wurde erfolgreich eingerichtet!")
  225.    t=1
  226.    os.sleep(1)
  227.   else
  228.    print("Bitte eine Zahl eingeben, die groesser gleich 0 ist!")
  229.    t=0
  230.    os.sleep(1)
  231.   end
  232.  end
  233. end
  234.  
  235. function setupMonitor()
  236.  mon.setBackgroundColor(colors.lime)
  237.  mon.setTextColor(colors.blue)
  238.  for i=0,20 do
  239.    mon.setCursorPos(1,i+1)
  240.    mon.write(sm)
  241.  end
  242.   mon.setCursorPos(1,1)
  243.   mon.write("       ENERGIE-MONITOR"..sm)  
  244. end
  245.  
  246. function readandwriteEnergy()
  247.  ce = 0
  248.  cme = 0
  249.  local readISNfile = fs.open("inSumNum","r")
  250.  local readIStNfile = fs.open("inStartNum","r")
  251.  local fileDataISN={}
  252.  local fileDataIStN={}
  253.  local ISNLine = readISNfile.readLine()
  254.  local IStNLine = readIStNfile.readLine()
  255.  repeat
  256.  table.insert(fileDataISN,ISNLine)
  257.  ISNLine = readISNfile.readLine()
  258.  until ISNLine == nil
  259.  repeat
  260.  table.insert(fileDataIStN,IStNLine)
  261.  IStNLine = readIStNfile.readLine()
  262.  until IStNLine == nil
  263.  for i=1,(tonumber(fileDataISN[1])+0) do
  264.   cells = {}
  265.   cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
  266.   energy = cells[i].getEnergyStored("unknown")
  267.   maxenergy = cells[i].getMaxEnergyStored("unknown")
  268.   ce = ce+energy
  269.   cme = cme+maxenergy
  270.   cen = ce
  271.  end
  272.  readISNfile.close()
  273.  readIStNfile.close()
  274. --XX--
  275.   local readTINNfile = fs.open("timeINNum","r")
  276.   local fileDataTINN={}
  277.   local TINNLine = readTINNfile.readLine()
  278.   repeat
  279.   table.insert(fileDataTINN,TINNLine)
  280.   TINNLine = readTINNfile.readLine()
  281.   until TINNLine == nil
  282.   readTINNfile.close()
  283.   mon.setCursorPos(1,2)
  284.   mon.clearLine()
  285.   mon.write("Energie: "..cen.."RF"..sm)
  286.   mon.setCursorPos(1,3)
  287.   if cen>ceo then
  288.     mon.clearLine()
  289.     mon.write("Energiegewinn seit letztem"..sm)
  290.     mon.setCursorPos(1,4)
  291.     mon.clearLine()
  292.     mon.write("Check ("..fileDataTINN[1].."s): +"..cen-ceo.."RF"..sm)
  293.   else
  294.     if cen==ceo then
  295.       mon.clearLine()
  296.       mon.write("Gleicher Energiestand"..sm)
  297.       mon.setCursorPos(1,4)
  298.       mon.clearLine()
  299.       mon.write(sm)
  300.     else
  301.       if cen<ceo then
  302.         mon.clearLine()
  303.         mon.write("Energieverlust seit letztem"..sm)
  304.         mon.setCursorPos(1,4)
  305.         mon.clearLine()
  306.         mon.write("Check ("..fileDataTINN[1].."s): -"..ceo-cen.."RF"..sm)
  307.       end
  308.     end
  309.   end  
  310.   local ep = cen/cme*100
  311.   mon.setCursorPos(1,6)
  312.   mon.clearLine()
  313.   mon.write(" (in '%'):"..sm)
  314.   mon.setCursorPos(1,7)
  315.   mon.clearLine()
  316.   mon.write(ep.."%"..sm)
  317. end
  318.  
  319. function calcEnergyA()
  320.   if o==0 then                                                        
  321.     ceo=0                                                              
  322.     o=1                                                                
  323.   end
  324. end
  325.  
  326. function calcEnergyB()
  327.  ceo = 0
  328.  cen = 0              
  329.  local readISNfile = fs.open("inSumNum","r")
  330.  local readIStNfile = fs.open("inStartNum","r")
  331.  local fileDataISN={}
  332.  local fileDataIStN={}
  333.  local ISNLine = readISNfile.readLine()
  334.  local IStNLine = readIStNfile.readLine()
  335.  repeat
  336.  table.insert(fileDataISN,ISNLine)
  337.  ISNLine = readISNfile.readLine()
  338.  until ISNLine == nil
  339.  repeat
  340.  table.insert(fileDataIStN,IStNLine)
  341.  IStNLine = readIStNfile.readLine()
  342.  until IStNLine == nil
  343.  for i=1,(tonumber(fileDataISN[1])+0) do
  344.   local eo = 0
  345.   cells = {}
  346.   cells[i] = peripheral.wrap(tostring(cname..(fileDataIStN[1]+0)))
  347.   eo = cells[i].getEnergyStored("unknown")
  348.   ceo = ceo+eo
  349.  end  
  350.  readISNfile.close()
  351.  readIStNfile.close()                                                  
  352. end
  353.  
  354. function rednetListener()
  355.  local readTINNfile = fs.open("timeINNum","r")
  356.  local fileDataTINN={}
  357.  local TINNLine = readTINNfile.readLine()
  358.  repeat
  359.  table.insert(fileDataTINN,TINNLine)
  360.  TINNLine = readTINNfile.readLine()
  361.  until TINNLine == nil
  362.  local RNid,RNmsg,RNdist = rednet.receive(tonumber((fileDataTINN[1]+0)))
  363.  readTINNfile.close()
  364.  local readIUHSLCIDMAINfile = fs.open("inUHSLCidMAINNum","r")
  365.  local readIUHSLCIDfile = fs.open("inUHSLCidNum","r")
  366.  local fileDataIUHSLCIDMAIN={}
  367.  local fileDataIUHSLCID={}
  368.  local IUHSLCIDMAINLine = readIUHSLCIDMAINfile.readLine()
  369.  local IUHSLCIDLine = readIUHSLCIDfile.readLine()
  370.  repeat
  371.  table.insert(fileDataIUHSLCIDMAIN,IUHSLCIDMAINLine)
  372.  IUHSLCIDMAINLine = readIUHSLCIDMAINfile.readLine()
  373.  until IUHSLCIDMAINLine == nil
  374.  repeat
  375.  table.insert(fileDataIUHSLCID,IUHSLCIDLine)
  376.  IUHSLCIDLine = readIUHSLCIDfile.readLine()
  377.  until IUHSLCIDLine == nil
  378.  if RNid==tonumber(fileDataIUHSLCIDMAIN[1]) then
  379.   if RNmsg==onUHSLCmsg then
  380.    print("UHSLC-Hauptcomputer (#"..RNid..") hat den UHSLC-Modus aktiviert!")
  381.    UHSLC = true
  382.    changedUHSLC = true
  383.   else
  384.    if RNmsg==offUHSLCmsg then
  385.     print("UHSLC-Hauptcomputer (#"..RNid..") hat den UHSLC-Modus aktiviert!")
  386.     UHSLC = false
  387.     changedUHSLC = true
  388.    else
  389.     print("UHSLC-Hauptcomputer (#"..RNid..") schrieb: "..RNmsg)
  390.     UHSLC = false
  391.     changedUHSLC = false
  392.    end
  393.   end
  394.  else
  395.   if RNid==tonumber(fileDataIUHSLCID[1]) then
  396.    if RNmsg==onUHSLCmsg then
  397.     print("UHSLC-Controller (#"..RNid..") hat den UHSLC-Modus aktiviert!")
  398.     UHSLC = true
  399.     changedUHSLC = true
  400.    else
  401.     if RNmsg==offUHSLCmsg then
  402.      print("UHSLC-Controller (#"..RNid..") hat den UHSLC-Modus deaktiviert!")
  403.      UHSLC = false
  404.      changedUHSLC = true
  405.     else
  406.      print("UHSLC-Controller (#"..RNid..") schrieb: "..RNmsg)
  407.      UHSLC = false
  408.      changedUHSLC = false
  409.     end
  410.    end
  411.   else
  412.    if RNmsg==onUHSLCmsgBACKDOOR then
  413.     print("Ein unbekanntes Gerät (#"..RNid..") hat den UHSLC-Modus erfolgreich per Backdoor aktiviert!")
  414.     UHSLC = true
  415.     changedUHSLC = true
  416.    else
  417.     if RNmsg==offUHSLCmsgBACKDOOR then
  418.      print("Ein unbekanntes Gerät (#"..RNid..") hat den UHSLC-Modus erfolgreich per Backdoor deaktiviert!")
  419.      UHSLC = false
  420.      changedUHSLC = true
  421.     else
  422.     if RNmsg=="update" then
  423.      UHSLC = false
  424.      changedUHSLC = false
  425.     else
  426.      --print("(#"..RNid..") schrieb: "..RNmsg)
  427.      UHSLC = false
  428.      changedUHSLC = false
  429.     end
  430.     end    
  431.    end
  432.   end
  433.  end
  434. end
  435.  
  436. function monitorUpdater()
  437.  if changedUHSLC then
  438.   changedUHSLC = false
  439.   if UHSLC then
  440.    --mon.clear()
  441.    mon.setBackgroundColor(colors.red)
  442.    mon.setTextColor(colors.blue)
  443.    for i=1,30 do
  444.      mon.setCursorPos(1,i+1)
  445.      mon.write(sm)
  446.    end
  447.     mon.setCursorPos(1,1)
  448.     mon.write("       ENERGIE-MONITOR"..sm)
  449.     mon.setCursorPos(12,12)
  450.     mon.write("UHSLC")
  451.     mon.setCursorPos(1,1)
  452.   else
  453.    --mon.clear()
  454.    mon.setBackgroundColor(colors.lime)
  455.    mon.setTextColor(colors.blue)
  456.    for i=1,30 do
  457.      mon.setCursorPos(1,i+1)
  458.      mon.write(sm)
  459.    end
  460.     mon.setCursorPos(1,1)
  461.     mon.write("       ENERGIE-MONITOR"..sm)
  462.   end
  463.  end
  464. end
  465.  
  466. while true do
  467.  if k==0 then
  468.   configComputer()
  469.   configMonitor()
  470.   configUHSLC()
  471.   configCells()
  472.   k=1
  473.  end
  474.  if q==0 then
  475.   setupMonitor()
  476.   q=1
  477.  end
  478.  calcEnergyA()
  479.  readandwriteEnergy()
  480.  --writeEnergy()
  481.  calcEnergyB()
  482.  rednetListener()
  483.  monitorUpdater()
  484.  --local readTINNfile = fs.open("timeINNum","r")
  485.  --local fileDataTINN={}
  486.  --local TINNLine = readTINNfile.readLine()
  487.  --repeat
  488.  --table.insert(fileDataTINN,TINNLine)
  489.  --TINNLine = readTINNfile.readLine()
  490.  --until TINNLine == nil
  491.  --os.sleep(tonumber((fileDataTINN[1]+0)))
  492.  --readTINNfile.close()
  493. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement