Advertisement
cc-editor

lager-main

Mar 13th, 2022 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.17 KB | None | 0 0
  1. function Settings()
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.     term.write("Setup-Modus für Fachtechniker")
  5.     local pin = "----"
  6.     repeat
  7.         term.setCursorPos(1,2)
  8.         term.write("Bitte Fachtechniker-PIN eingeben:")
  9.         term.setCursorPos(1,3)
  10.         term.write("(zum Verlassen ENTER drücken)")
  11.         term.setCursorPos(1,4)
  12.         pin = io.read()
  13.         if pin == "" then
  14.             return false
  15.         elseif pin ~= "0000" then
  16.             term.setCursorPos(1,4)
  17.             term.clearLine()
  18.             term.setCursorPos(1,1)
  19.             term.clearLine()
  20.             term.write("FALSCHER PIN")
  21.         end
  22.     until (pin == "0000")
  23.    
  24.     local connectors = {}
  25.     local okKey
  26.     local id
  27.     local color
  28.    
  29.     repeat
  30.         -- hellblau
  31.         id, color = selectionMenu.selectionMenu("Farbe für Gleis 1 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  32.         connectors["gleis1"] = color
  33.         -- gelb
  34.         id, color = selectionMenu.selectionMenu("Farbe für Gleis 2 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  35.         connectors["gleis2"] = color   
  36.         -- hellgrün
  37.         id, color = selectionMenu.selectionMenu("Farbe für Gleis 5 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  38.         connectors["gleis5"] = color   
  39.         -- rosa
  40.         id, color = selectionMenu.selectionMenu("Farbe für Gleis 6 auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  41.         connectors["gleis6"] = color
  42.         -- magenta
  43.         id, color = selectionMenu.selectionMenu("Farbe für Entladen auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  44.         connectors["entladen"] = color
  45.         -- orange
  46.         id, color = selectionMenu.selectionMenu("Farbe für Beladen auswählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  47.         connectors["beladen"] = color
  48.         -- grau
  49.         id, color = selectionMenu.selectionMenu("Farbe für Fließband-Inverter wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  50.         connectors["band_richtung"] = color
  51.         -- hellgrau
  52.         id, color = selectionMenu.selectionMenu("Farbe für Sensor Band unten wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  53.         connectors["band_unten"] = color
  54.         -- türkis
  55.         id, color = selectionMenu.selectionMenu("Farbe für Sensor Band oben wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  56.         connectors["band_oben"] = color
  57.         -- violett
  58.         id, color = selectionMenu.selectionMenu("Farbe für Sensor Beladung wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  59.         connectors["band_beladung"] = color
  60.         -- blau
  61.         id, color = selectionMenu.selectionMenu("Farbe für Zähler Band unten wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  62.         connectors["zaehler_unten"] = color
  63.         -- braun
  64.         id, color = selectionMenu.selectionMenu("Farbe für Zähler Band oben wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  65.         connectors["zaehler_oben"] = color
  66.         -- grün
  67.         id, color = selectionMenu.selectionMenu("Farbe für Beladungs-Stopper wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  68.         connectors["beladung_invert"] = color
  69.         -- rot
  70.         id, color = selectionMenu.selectionMenu("Farbe für Hauptschalter wählen", {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768},{"Weiß","Orange","Magenta","Hellblau","Gelb","Hellgrün","Rosa","Grau","Hellgrau","Türkis","Violett","Blau","Braun","Grün","Rot","Schwarz"})
  71.         connectors["notaus"] = color
  72.        
  73.         id, color = selectionMenu.selectionMenu("Seite für Input wählen", "left", "right", "top", "bottom", "front", "back")
  74.         connectors["input"] = color
  75.         id, color = selectionMenu.selectionMenu("Seite für Output wählen", "left", "right", "top", "bottom", "front", "back")
  76.         connectors["output"] = color
  77.         id, color = selectionMenu.selectionMenu("Seite für Monitor wählen", "left", "right", "top", "bottom", "front", "back")
  78.         connectors["monitor"] = color
  79.         id, color = selectionMenu.selectionMenu("Seite für Modem wählen", "left", "right", "top", "bottom", "front", "back")
  80.         connectors["modem"] = color
  81.        
  82.         term.clear()
  83.         term.setCursorPos(1,1)
  84.         term.setTextColor(connectors["gleis1"])
  85.         print("Gleis 1")
  86.         term.setTextColor(connectors["gleis2"])
  87.         print("Gleis 2")
  88.         term.setTextColor(connectors["gleis5"])
  89.         print("Gleis 5")
  90.         term.setTextColor(connectors["gleis6"])
  91.         print("Gleis 6")
  92.         term.setTextColor(connectors["entladen"])
  93.         print("Entladen")
  94.         term.setTextColor(connectors["beladen"])
  95.         print("Beladen")
  96.         term.setTextColor(connectors["band_richtung"])
  97.         print("Fließband Richtung")
  98.         term.setTextColor(connectors["band_unten"])
  99.         print("Fließband Sensor unten")
  100.         term.setTextColor(connectors["band_oben"])
  101.         print("Fließband Sensor oben")
  102.         term.setTextColor(connectors["band_beladung"])
  103.         print("Fließband Sensor Beladung")
  104.         term.setTextColor(connectors["zaehler_unten"])
  105.         print("Fließband Zähler unten")
  106.         term.setTextColor(connectors["zaehler_oben"])
  107.         print("Fließband Zähler oben")
  108.         term.setTextColor(connectors["beladung_invert"])
  109.         print("Fließband Beladung Invertierer")
  110.         term.setTextColor(connectors["notaus"])
  111.         print("Hauptschalter")
  112.        
  113.         term.setTextColor(colors.white)
  114.         print("Kabel-Input: " .. connectors["input"])
  115.         print("Kabel-Output: " .. connectors["output"])
  116.         print("Monitor: " .. connectors["monitor"])
  117.         print("Modem: ".. connectors["modem"])
  118.         print()
  119.         print("Auswahl OK ? (j/n)")
  120.         okKey = io.read()  
  121.     until(okKey == "j")
  122.    
  123.     local file = fs.open("/lager/redstone/connectors","w")
  124.     file.write(textutils.serialize(connectors))
  125.     file.close()
  126.    
  127.     return true
  128. end
  129.  
  130. function Silofuellung()
  131.  
  132.     local silo = {}
  133.     silo["namen"] = {}
  134.     silo["pc-id"] = {}
  135.     silo["silo-nr"] = {}
  136.    
  137.     if fs.exists("/lager/redstone/silos") then
  138.         local file = fs.open("/lager/redstone/silos","r")
  139.         silo = textutils.unserialize(file.readAll())
  140.         file.close()
  141.     end
  142.    
  143.     term.clear()
  144.     term.setCursorPos(1,1)
  145.     term.write("Setup-Modus für Fachtechniker")
  146.     local pin = "----"
  147.     repeat
  148.         term.setCursorPos(1,2)
  149.         term.write("Bitte Fachtechniker-PIN eingeben:")
  150.         term.setCursorPos(1,3)
  151.         term.write("(zum Verlassen ENTER drücken)")
  152.         term.setCursorPos(1,4)
  153.         pin = io.read()
  154.         if pin == "" then
  155.             return false
  156.         elseif pin ~= "0000" then
  157.             term.setCursorPos(1,4)
  158.             term.clearLine()
  159.             term.setCursorPos(1,1)
  160.             term.clearLine()
  161.             term.write("FALSCHER PIN")
  162.         end
  163.     until (pin == "0000")
  164.    
  165.     local name
  166.     local pcID
  167.     local siloNr
  168.     local okKey
  169.    
  170.     repeat
  171.         repeat
  172.             term.clear()
  173.             term.setCursorPos(1,1)
  174.             print("Item-Name eingeben:")
  175.             name = io.read()
  176.             print("PC-ID eingeben:")
  177.             pcID = tonumber(io.read())
  178.             print("Silo-Nr eingeben:")
  179.             siloNr = io.read()
  180.             siloNr = "silo" .. siloNr
  181.            
  182.             print("Auswahl OK ? (j/n)")
  183.             okKey = io.read()
  184.         until (okKey == "j")
  185.        
  186.         table.insert(silo["namen"], name)
  187.         table.insert(silo["pc-id"], pcID)
  188.         table.insert(silo["silo-nr"], siloNr)  
  189.    
  190.         term.clear()
  191.         term.setCursorPos(1,1)
  192.         print("Weiteres Silo speichern? (j/n)")
  193.         okKey = io.read()
  194.    
  195.     until ( okKey ~= "j")
  196.    
  197.     local file = fs.open("/lager/redstone/silos","w")
  198.     file.write(textutils.serialize(silo))
  199.     file.close()   
  200.    
  201.     return true
  202. end
  203.  
  204. function Entladen()
  205.     term.clear()
  206.     term.setCursorPos(1,1)
  207.     local id
  208.     sel = "0"
  209.     id = selectionMenu.selectionMenu("Gleis zum Entladen wählen", "Gleis 1", "Gleis 2", "Gleis 5", "Gleis 6", "Abbrechen")
  210.     if id == 1 then
  211.         sel = "gleis1"
  212.     elseif id == 2 then
  213.         sel = "gleis2"
  214.     elseif id == 3 then
  215.         sel = "gleis5"
  216.     elseif id == 4 then
  217.         sel = "gleis6"
  218.     elseif id == 5 then
  219.         return
  220.     end
  221.    
  222.     redstone.setBundledOutput(Connectors["output"], colors.combine(Connectors[sel],Connectors["entladen"],Connectors["band_richtung"], Connectors["notaus"]))  
  223.    
  224.     term.clear()
  225.     term.setCursorPos(1,1)
  226.     print("Entladevorgang aktiv")
  227.     print("Beliebige Taste drücken um Vorgang abzubrechen")
  228.    
  229.     local screen
  230.     if peripheral.isPresent(Connectors["monitor"]) then
  231.         screen = peripheral.wrap(Connectors["monitor"])
  232.         screen.clear()
  233.         screen.setTextScale(0.8)
  234.         screen.setCursorPos(1,1)
  235.         screen.write("Entladevorgang aktiv")
  236.         screen.setCursorPos(1,2)
  237.         screen.write("Monitor anklicken um Vorgang abzubrechen")
  238.     end
  239.    
  240.     parallel.waitForAny(Entladen_Normal, Entladen_Voll)
  241. end
  242.  
  243. function Entladen_Normal()
  244.     local new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  245.     local old_sensor_state = new_senor_state
  246.    
  247.     while (not (old_sensor_state and (not new_senor_state))) and Beendet == false do
  248.         local event = {os.pullEvent()}     
  249.         if event[1] == "redstone" then
  250.             old_sensor_state = new_senor_state
  251.             new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  252.         elseif (event[1] == "key" or event[1] == "monitor_touch") and Beendet == false then
  253.             Beendet = true
  254.             Beende_Entladen(sel)
  255.             return
  256.         end
  257.     end
  258.     if Beendet == false then
  259.         Beendet = true
  260.         Beende_Entladen(sel)
  261.         return
  262.     end
  263. end
  264.  
  265. function Entladen_Voll()
  266.     while Beendet == false do
  267.         local event = {os.pullEvent("rednet_message")}
  268.  
  269.         if event[4] == "lager_voll" then
  270.             Beendet = true
  271.             Lager_Voll(sel, event[2], event[3])
  272.             return
  273.         end
  274.     end
  275. end
  276.  
  277. function Beende_Entladen(sel)
  278.  
  279.     redstone.setBundledOutput(Connectors["output"], colors.combine(Connectors[sel],Connectors["band_richtung"], Connectors["notaus"]))
  280.    
  281.     term.clear()
  282.     term.setCursorPos(1,1)
  283.     print("Entladevorgang wird beendet")
  284.     print("Prüfe auf überschüssige Items")
  285.     print()
  286.     print("BITTE WARTEN")
  287.    
  288.     local screen
  289.     if peripheral.isPresent(Connectors["monitor"]) then
  290.         screen = peripheral.wrap(Connectors["monitor"])
  291.         screen.clear()
  292.         screen.setTextScale(0.8)
  293.         screen.setCursorPos(1,1)
  294.         screen.write("Entladevorgang wird beendet")
  295.         screen.setCursorPos(1,2)
  296.         screen.write("Prüfe auf überschüssige Items")
  297.         screen.setCursorPos(1,4)
  298.         screen.write("BITTE WARTEN")
  299.     end
  300.    
  301.     local new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_oben"])
  302.     local old_sensor_state = new_senor_state
  303.    
  304.     while not (old_sensor_state and (not new_senor_state)) do
  305.         local event = {os.pullEvent()}     
  306.         if event[1] == "redstone" then
  307.             old_sensor_state = new_senor_state
  308.             new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_oben"])
  309.         elseif (event[1] == "rednet_message" and event[4] == "lager_voll") then
  310.             Lager_Voll(sel, event[2], event[3])
  311.             return     
  312.         end
  313.     end
  314.    
  315.     os.startTimer(15)
  316.     local timer_end = false
  317.     while not timer_end do
  318.         local event = {os.pullEvent()}
  319.         if event[1] == "timer" then
  320.             timer_end = true
  321.         elseif (event[1] == "rednet_message" and event[4] == "lager_voll") then
  322.             Lager_Voll(sel, event[2], event[3])
  323.             return
  324.         end
  325.     end
  326.    
  327.     redstone.setBundledOutput(Connectors["output"], 0)
  328.    
  329.     term.clear()
  330.     term.setCursorPos(1,1)
  331.     print("Entladevorgang abgeschlossen")
  332.     print("Beliebige Taste drücken um zum Menü zurückzukehren")
  333.  
  334.     if peripheral.isPresent(Connectors["monitor"]) then
  335.         screen.clear()
  336.         screen.setTextScale(0.8)
  337.         screen.setCursorPos(1,1)
  338.         screen.write("Entladevorgang abgeschlossen")
  339.         screen.setCursorPos(1,2)
  340.         screen.write("Monitor anklicken um zum Menü zurückzukehren")
  341.     end
  342.    
  343.     while true do
  344.         local event = os.pullEvent()
  345.         if (event == "key" or event == "monitor_touch") then
  346.             term.clear()
  347.             if peripheral.isPresent(Connectors["monitor"]) then
  348.                 screen.clear()
  349.             end
  350.             return
  351.         end
  352.     end
  353. end
  354.  
  355. function Lager_Voll(sel, pc, volles_lager)
  356.  
  357.     for index, val in pairs(Silos["pc-id"]) do
  358.         if pc ~= val then
  359.             rednet.send(val, "stop", "block")
  360.         end
  361.     end
  362.    
  363.     redstone.setBundledOutput(Connectors["output"], colors.combine(Connectors[sel],Connectors["beladen"], Connectors["notaus"]))
  364.    
  365.     term.clear()
  366.     term.setCursorPos(1,1)
  367.     print("Lager voll!")
  368.     print("Kein Platz mehr für " .. volles_lager)
  369.     print("Überschüssige Items werden in Zug zurückgeführt")
  370.     print()
  371.     print("BITTE WARTEN")
  372.    
  373.     local screen
  374.     if peripheral.isPresent(Connectors["monitor"]) then
  375.         screen = peripheral.wrap(Connectors["monitor"])
  376.         screen.clear()
  377.         screen.setTextScale(0.8)
  378.         screen.setCursorPos(1,1)
  379.         screen.write("Lager voll!")
  380.         screen.setCursorPos(1,2)
  381.         screen.write("Kein Platz mehr für " .. volles_lager)
  382.         screen.setCursorPos(1,3)
  383.         screen.write("Überschüssige Items werden in Zug zurückgeführt")
  384.         screen.setCursorPos(1,5)
  385.         screen.write("BITTE WARTEN")
  386.     end
  387.    
  388.     local new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  389.     local old_sensor_state = new_senor_state
  390.    
  391.     while not (old_sensor_state and (not new_senor_state)) do
  392.         local event = {os.pullEvent()}     
  393.         if event[1] == "redstone" then
  394.             old_sensor_state = new_senor_state
  395.             new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  396.         end
  397.     end
  398.    
  399.     os.sleep(20)
  400.     redstone.setBundledOutput(Connectors["output"], 0)
  401.    
  402.     rednet.send(pc,"ok","entladen_ok")
  403.    
  404.     for index, val in pairs(Silos["pc-id"]) do
  405.         rednet.send(val,"ok", "lager_ok")
  406.     end
  407.    
  408.     term.clear()
  409.     term.setCursorPos(1,1)
  410.     print("Entladen abgebrochen")
  411.     print("Überschüssige Items im Zug")
  412.     print("Beliebige Taste drücken um zum Menü zurückzukehren")
  413.    
  414.     local screen
  415.     if peripheral.isPresent(Connectors["monitor"]) then
  416.         screen = peripheral.wrap(Connectors["monitor"])
  417.         screen.clear()
  418.         screen.setTextScale(0.8)
  419.         screen.setCursorPos(1,1)
  420.         screen.write("Entladen abgebrochen")
  421.         screen.setCursorPos(1,2)
  422.         screen.write("Überschüssige Items im Zug")
  423.         screen.setCursorPos(1,3)
  424.         screen.write("Monitor anklicken um zum Menü zurückzukehren")
  425.     end
  426.    
  427.     while true do
  428.         local event = os.pullEvent()
  429.         if (event == "key" or event == "monitor_touch") then
  430.             term.clear()
  431.             if peripheral.isPresent(Connectors["monitor"]) then
  432.                 screen.clear()
  433.             end
  434.             return
  435.         end
  436.     end
  437.    
  438. end
  439.  
  440. function Beladen()
  441.  
  442.     term.clear()
  443.     term.setCursorPos(1,1)
  444.     local id
  445.     local idg
  446.     local sel
  447.     idg, id = selectionMenu.selectionMenu("Item auswählen", Silos["namen"])
  448.    
  449.     id = indexOf(Silos["namen"], id)
  450.    
  451.     term.clear()
  452.     term.setCursorPos(1,1)
  453.     idg = selectionMenu.selectionMenu("Gleis zum Entladen wählen", "Gleis 1", "Gleis 2", "Gleis 5", "Gleis 6", "Abbrechen")
  454.     if idg == 1 then
  455.         sel = "gleis1"
  456.     elseif idg == 2 then
  457.         sel = "gleis2"
  458.     elseif idg == 3 then
  459.         sel = "gleis5"
  460.     elseif idg == 4 then
  461.         sel = "gleis6"
  462.     elseif idg == 5 then
  463.         return
  464.     end
  465.    
  466.     for index, val in pairs(Silos["pc-id"]) do
  467.         if Silos["pc-id"][id] ~= val then
  468.             rednet.send(val, "stop", "block")
  469.         end
  470.     end
  471.    
  472.     rednet.send(Silos["pc-id"][id], Silos["silo-nr"][id], "beladen")
  473.     redstone.setBundledOutput(Connectors["output"], colors.combine(Connectors[sel],Connectors["beladen"], Connectors["notaus"]))   
  474.    
  475.     term.clear()
  476.     term.setCursorPos(1,1)
  477.     print("Beladevorgang aktiv")
  478.     print("Beliebige Taste drücken um Vorgang abzubrechen")
  479.    
  480.     local screen
  481.     if peripheral.isPresent(Connectors["monitor"]) then
  482.         screen = peripheral.wrap(Connectors["monitor"])
  483.         screen.clear()
  484.         screen.setTextScale(0.8)
  485.         screen.setCursorPos(1,1)
  486.         screen.write("Beladevorgang aktiv")
  487.         screen.setCursorPos(1,2)
  488.         screen.write("Monitor anklicken um Vorgang abzubrechen")
  489.     end
  490.    
  491.     local new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  492.     local old_sensor_state = new_senor_state
  493.    
  494.     while not (old_sensor_state and (not new_senor_state)) do
  495.         local event = {os.pullEvent()} 
  496.         if event[1] == "redstone" and redstone.testBundledInput(Connectors["input"],Connectors["band_beladung"]) then
  497.             rednet.send(Silos["pc-id"][id],"ok", "lager_ok")
  498.             Beende_Beladen(sel, "zug")
  499.             return
  500.         elseif event[1] == "redstone" then
  501.             old_sensor_state = new_senor_state
  502.             new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_unten"])
  503.         elseif (event[1] == "key" or event[1] == "monitor_touch") then
  504.             rednet.send(Silos["pc-id"][id],"ok", "lager_ok")
  505.             Beende_Beladen(sel, "abbruch")
  506.             return
  507.         end
  508.     end
  509.    
  510.     for index, val in pairs(Silos["pc-id"]) do
  511.         rednet.send(val,"ok", "lager_ok")
  512.     end
  513.     Beende_Beladen(sel, "lager")
  514. end
  515.  
  516. function Beende_Beladen(sel, grund)
  517.  
  518.     redstone.setBundledOutput(Connectors["output"], colors.combine(Connectors[sel],Connectors["band_richtung"], Connectors["notaus"]))
  519.  
  520.     term.clear()
  521.     term.setCursorPos(1,1)
  522.     if grund == "zug" then
  523.         print("Zug ist voll")
  524.         print("Beladevorgang wird beendet")
  525.     elseif grund == "abbruch" then
  526.         print("Beladevorgang wurde abgebrochen")
  527.     elseif grund == "lager" then
  528.         print("Lager ist leer")
  529.         print("Beladevorgang wurde abgebrochen")
  530.     end
  531.    
  532.     print("Fließband wird bereinigt ...")
  533.    
  534.     local screen
  535.     if peripheral.isPresent(Connectors["monitor"]) then
  536.         screen = peripheral.wrap(Connectors["monitor"])
  537.         screen.clear()
  538.         screen.setTextScale(0.8)
  539.         screen.setCursorPos(1,1)
  540.         screen.write("Beladevorgang wird beendet")
  541.         screen.setCursorPos(1,2)
  542.         screen.write("Fließband wird bereinigt ...")
  543.     end
  544.    
  545.     local new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_oben"])
  546.     local old_sensor_state = new_senor_state
  547.    
  548.     while not (old_sensor_state and (not new_senor_state)) do
  549.         local event = {os.pullEvent()}     
  550.         if event[1] == "redstone" then
  551.             old_sensor_state = new_senor_state
  552.             new_senor_state = redstone.testBundledInput(Connectors["input"],Connectors["band_oben"])   
  553.         end
  554.     end
  555.    
  556.     os.sleep(15)
  557.    
  558.     redstone.setBundledOutput(Connectors["output"], 0)
  559.    
  560.     term.clear()
  561.     term.setCursorPos(1,1)
  562.     print("Beladevorgang abgeschlossen")
  563.     print("Beliebige Taste drücken um zum Menü zurückzukehren")
  564.  
  565.     if peripheral.isPresent(Connectors["monitor"]) then
  566.         screen.clear()
  567.         screen.setTextScale(0.8)
  568.         screen.setCursorPos(1,1)
  569.         screen.write("Beladevorgang abgeschlossen")
  570.         screen.setCursorPos(1,2)
  571.         screen.write("Monitor anklicken um zum Menü zurückzukehren")
  572.     end
  573.    
  574.     while true do
  575.         local event = os.pullEvent()
  576.         if (event == "key" or event == "monitor_touch") then
  577.             term.clear()
  578.             if peripheral.isPresent(Connectors["monitor"]) then
  579.                 screen.clear()
  580.             end
  581.             return
  582.         end
  583.     end
  584. end
  585.  
  586. function indexOf ( tab, value )
  587.     for index, val in pairs(tab) do
  588.         if value == val then
  589.           return index
  590.         end
  591.     end
  592.    
  593.     return -1
  594. end
  595.  
  596. -- #################
  597. -- # Hauptprogramm #
  598. -- #################
  599.  
  600. os.loadAPI("selectionMenu")
  601. if not fs.exists("/lager/redstone/connectors") then
  602.     if not Settings() then
  603.         term.clear()
  604.         return
  605.     end
  606. end
  607.  
  608. local file = fs.open("/lager/redstone/connectors","r")
  609. Connectors = textutils.unserialize(file.readAll())
  610. file.close()
  611.  
  612. if not fs.exists("/lager/redstone/silos") then
  613.     if not Silofuellung() then
  614.         term.clear()
  615.         return
  616.     end
  617. end
  618.  
  619. local file = fs.open("/lager/redstone/silos","r")
  620. Silos = textutils.unserialize(file.readAll())
  621. file.close()
  622.  
  623. rednet.open(Connectors["modem"])
  624.  
  625. while true do
  626.     local screen
  627.     if peripheral.isPresent(Connectors["monitor"]) then
  628.         screen = peripheral.wrap(Connectors["monitor"])
  629.         screen.clear()
  630.     end
  631.    
  632.     Beendet = false
  633.  
  634.     local id
  635.     id = selectionMenu.selectionMenu("Aktion auswählen", "Entladen", "Beladen", "Fachtechniker-Einstellungen", "Silo-Belegung")
  636.     if id == 1 then
  637.         Beendet = false
  638.         Entladen()
  639.     elseif id == 2 then
  640.         Beladen()
  641.     elseif id == 3 then
  642.         Settings()
  643.         file = fs.open("/lager/redstone/connectors","r")
  644.         Connectors = textutils.unserialize(file.readAll())
  645.         file.close()
  646.     elseif id == 4 then
  647.         Silofuellung()
  648.         file = fs.open("/lager/redstone/silos","r")
  649.         Silos = textutils.unserialize(file.readAll())
  650.         file.close()
  651.     end
  652. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement