Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- WICHTIGE KOMPONENTE:
- ####################
- navigation
- inventory_controller
- inventory_upgrade
- tank_controller
- ####################
- ]]
- -- Imports --
- local robot = require("robot")
- local computer = require("computer")
- local term = require("term")
- local os = require("os")
- local component = require("component")
- local sides = require("sides")
- local string = require("string")
- local shell = require("shell")
- -- MOUNT
- local fs = require("filesystem")
- proxy = ...
- mountDirectory = "/PM"
- if fs.isDirectory(mountDirectory) == false then
- fs.mount(proxy, mountDirectory)
- end
- --[[ Variablen ]]
- debug_mode = 1 --[[ [1]TRUE | [0]FALSE
- Protokoliert jeden Roboter-Schritt! ]]
- version = "0.70" --[[ Version ]]
- pause = true --true/false (an/aus)
- pause_time = 3 -- Minuten
- config_std = {30000000,1,""} --[[ Standard Konfiguration
- 30.000.000 , 1 , R
- Wenn "1", dann gräbt NUR gerade ]]
- config_std_0 = 30000000
- config_std_1 = 1
- config_std_2 = ""
- ParkingStatus = false -- ist Parking-State erlaubt? > true | false <
- ExtractItems = {"EnderStorage:enderChest",
- "ThermalExpansion:Tesseract"}
- WhitelistItems = {"",
- ""}
- InventorySize = 0
- StartInventorySlot = 1
- CurrentInventorySlot = StartInventorySlot
- LastInventorySlot = StartInventorySlot
- function checkStartSlots()
- InventorySize = robot.inventorySize()
- robot.select(StartInventorySlot)
- end
- config = {30000000,1,""} --[[ Benutzer Konfiguration
- 30.000.000 , 1 , R
- Wenn "1", dann gräbt NUR gerade ]]
- config_0 = 30000000
- config_1 = 1
- config_2 = ""
- tests = 0
- MaxHeight = 66
- MaxTotalHeight = 265
- CurrentDirection = 0
- ParkingDirection = 0
- --[[1=North,2=East,3=South,4=West]]
- sucker = 0
- chunkloader = 0
- chunkloaderStatus = false
- state = string.lower("init")
- -- States: Init | Work | Parking | BackToWork
- --
- -- Listen
- dot = {
- "", --0
- ".", --1
- "..", --2
- "...", --3
- "....", --4
- ".....", --5
- "......", --6
- ".......", --7
- "........", --8
- ".........", --9
- "..........", --10
- "...........", --11
- "............", --12
- ".............", --13
- "..............", --14
- "...............", --15
- "................", --16
- ".................", --17
- "..................", --18
- "...................", --19
- "....................", --20
- }
- dash_bar = {
- " ", --0
- ". ", --1
- ".. ", --2
- "... ", --3
- ".... ", --4
- "..... ", --5
- "...... ", --6
- "....... ", --7
- "........ ", --8
- "......... ", --9
- ".......... ", --10
- "........... ", --11
- "............ ", --12
- "............. ", --13
- ".............. ", --14
- "............... ", --15
- "................ ", --16
- "................. ", --17
- ".................. ", --18
- "................... ", --19
- "...................." --20
- }
- -- Funktionen
- function continueDialog(msg)
- io.write(msg)
- io.read()
- end
- function info()
- print("+-----------------------------+\n| PowerMining | Version: "..version.." |\n+-----------------------------+")
- end
- function DirectionToText()
- if CurrentDirection == 0 then
- return ""
- elseif CurrentDirection == 1 then
- return "North"
- elseif CurrentDirection == 2 then
- return "East"
- elseif CurrentDirection == 3 then
- return "South"
- elseif CurrentDirection == 4 then
- return "West"
- end
- end
- function ParkingDirectionToText()
- if ParkingDirection == 0 then
- return ""
- elseif ParkingDirection == 1 then
- return "North"
- elseif ParkingDirection == 2 then
- return "East"
- elseif ParkingDirection == 3 then
- return "South"
- elseif ParkingDirection == 4 then
- return "West"
- end
- end
- function StatusConfigScreen(var)
- --Length-Anzeige
- if var == 1 or var == 2 or var == 3 then
- print("Length: | "..config_0)
- end
- --Width-Anzeige
- if var == 2 or var == 3 then
- print("Width: | "..config_1)
- end
- --Direction-Anzeige
- if var == 3 then
- if config_1 ~= "1" then
- print("Direction: | "..config_2)
- end
- end
- end
- function show_inventory_info()
- print("Inventare | " .. robot.tankCount() )
- end
- function show_tank_info()
- print("Anzahl Tanks | " .. robot.tankCount() )
- if robot.tankCount() ~= 0 then
- print("Tank Info: | " .. robot.tankLevel() .. "mb/" .. robot.tankLevel()+robot.tankSpace() .. "mb")
- print("Frei | " .. robot.tankSpace() .. "mb")
- end
- end
- function loading(msg) for i=1,1 do for b=1,5 do term.clear() info() print(msg..dot[b]) os.sleep(0.1) end end term.clear() info() end
- --[[ DEBUG_MSG ]]
- function debug_msg(msg)
- if debug_mode == 1 then
- print("([DEBUG]: "..msg..")")
- end
- end
- --Direction
- --Positions-Funktionen
- startPositionConfig = {}
- startPositionX = ""
- startPositionY = ""
- startPositionZ = ""
- function getstartPosition(msg1,msg2) --GetPosition
- return print(msg1, startPositionX, startPositionY, startPositionZ, msg2)
- end
- function setstartPosition() --SetPosition
- startPositionX,
- startPositionY,
- startPositionZ = navi.getPosition()
- startPositionConfig[0] = startPositionX
- startPositionConfig[1] = startPositionY
- startPositionConfig[2] = startPositionZ
- end
- currentPositionConfig = {}
- currentPositionX = ""
- currentPositionY = ""
- currentPositionZ = ""
- function getcurrentPosition(msg1,msg2) --GetPosition
- return print(msg1, currentPositionX, currentPositionY, currentPositionZ, msg2)
- end
- function setcurrentPosition() --SetPosition
- currentPositionX,
- currentPositionY,
- currentPositionZ = navi.getPosition()
- currentPositionConfig[0] = currentPositionX
- currentPositionConfig[1] = currentPositionY
- currentPositionConfig[2] = currentPositionZ
- end
- lastPositionConfig = {}
- lastPositionX = ""
- lastPositionY = ""
- lastPositionZ = ""
- function getlastPosition(msg1,msg2) --GetPosition
- return print(msg1, lastPositionX, lastPositionY, lastPositionZ, msg2)
- end
- function setlastPosition() --SetPosition
- if state == "work" then
- lastPositionX,
- lastPositionY,
- lastPositionZ = navi.getPosition()
- lastPositionConfig[0] = lastPositionX
- lastPositionConfig[1] = lastPositionY
- lastPositionConfig[2] = lastPositionZ
- end
- end
- parkingPositionConfig = {}
- parkingPositionX = ""
- parkingPositionY = ""
- parkingPositionZ = ""
- parkingPositionD = ""
- function getparkingPosition(msg1,msg2) --GetPosition
- return print(msg1, parkingPositionX, parkingPositionY, parkingPositionZ, ParkingDirectionToText(), msg2)
- end
- function setparkingPosition(x,y,z) --SetPosition
- parkingPositionX = x
- parkingPositionY = y
- parkingPositionZ = z
- parkingPositionConfig[0] = parkingPositionX
- parkingPositionConfig[1] = parkingPositionY
- parkingPositionConfig[2] = parkingPositionZ
- end
- DifferenceToStartPositionConfig = {}
- DifferenceToStartPositionX = ""
- DifferenceToStartPositionY = ""
- DifferenceToStartPositionZ = ""
- function setDifferenceToStartPosition()
- DifferenceToStartPositionX = currentPositionX - startPositionX
- DifferenceToStartPositionY = currentPositionY - startPositionY
- DifferenceToStartPositionZ = currentPositionZ - startPositionZ
- end
- function getDifferenceToStartPosition(msg1,msg2)
- setDifferenceToStartPosition()
- return print(msg1, DifferenceToStartPositionX, DifferenceToStartPositionY, DifferenceToStartPositionZ, msg2)
- end
- DifferenceToParkingPositionConfig = {}
- DifferenceToParkingPositionX = ""
- DifferenceToParkingPositionY = ""
- DifferenceToParkingPositionZ = ""
- function setDifferenceToParkingPosition()
- DifferenceToParkingPositionX = parkingPositionX - currentPositionX
- DifferenceToParkingPositionY = parkingPositionY - currentPositionY
- DifferenceToParkingPositionZ = parkingPositionZ - currentPositionZ
- end
- function getDifferenceToParkingPosition(msg1,msg2)
- setDifferenceToParkingPosition()
- return print(msg1, DifferenceToParkingPositionX, DifferenceToParkingPositionY, DifferenceToParkingPositionZ, msg2)
- end
- function StatusScreen()
- term.clear()
- print("------------------------------+")
- StatusConfigScreen(3)
- print("------------------------------+")
- getcurrentPosition("Derzeit: ",DirectionToText())
- --getlastPosition("Zuletzt: ","")
- getDifferenceToStartPosition(" ", "")
- getstartPosition("Start: ","")
- print("------------------------------+")
- if ParkingStatus == true then
- getDifferenceToParkingPosition(" ", "")
- getparkingPosition("Parkplatz: ","")
- print("------------------------------+")
- end
- show_tank_info()
- print("------------------------------+")
- end
- --Überprüfung von Componenten
- successComponentsTable = {}
- function successComponents(c) successComponentsTable[c]="" end
- failureComponentsTable = {}
- function failureComponents(c) failureComponentsTable[c]="" end
- componentDescribe = {}
- componentErrorMsg = {}
- checkPrimaryIfFalse = 0
- checkSecundaryIfFalse = 0
- function writePrimaryToIfFalse()
- checkPrimaryIfFalse = checkPrimaryIfFalse + 1
- end
- function writeSecundaryToIfFalse()
- checkSecundaryIfFalse = checkSecundaryIfFalse +1
- end
- --
- function successComponentsOutput()
- term.clear()
- info()
- for c,d in pairs(componentDescribe) do
- for cpnnt in pairs(successComponentsTable) do
- if cpnnt == c then
- print("[\""..string.upper(c).."\"]:\n"..d)
- end
- end
- end
- end
- function failureComponentsOutput()
- term.clear()
- info()
- for c,d in pairs(componentErrorMsg) do
- for cpnnt in pairs(failureComponentsTable) do
- if cpnnt == c then
- print("[\""..string.upper(c).."\"]:\n"..d)
- end
- end
- end
- end
- --
- function checkComponent(var)
- for com in pairs(component) do
- if var == com then
- return true
- end
- end
- end
- --
- function comFeedback(msg)
- if msg ~= "" then msg=""..msg..":" end
- print("[I] Initialisiert | [E] Error")
- print("-------------------------------")
- if msg ~= "" then print(msg) end
- end
- --
- function checkCom(comVar)
- if checkComponent(comVar) == true then
- print("[I] "..comVar)
- successComponents(comVar)
- else
- print("[E] "..comVar)
- failureComponents(comVar)
- writePrimaryToIfFalse()
- end
- end
- --
- function runCheckPrimaryComponents()
- -- [[PRIMÄR]]
- checkPrimaryIfFalse = 0
- comFeedback("Primär")
- --"navigation"
- componentDescribe["navigation"] = "Ist essentiell wichtig um mit Koordinaten umgehen zu können. Und überhaupt Koordinaten erkennen zu können."
- componentErrorMsg["navigation"] = "Muss installiert werden um mit mit Koordinaten umgehen zu können."
- if checkComponent("navigation") == true then
- navi = component.navigation
- startPositionX, startPositionY, startPositionZ = navi.getPosition()
- sPX, sPY, sPZ = navi.getPosition()
- cPX, cPY, cPZ = navi.getPosition()
- setstartPosition()
- setcurrentPosition()
- print("[I] ".."navigation")
- successComponents("navigation")
- else
- print("[E] ".."navigation")
- failureComponents("navigation")
- writePrimaryToIfFalse()
- end
- --"inventory_controller"
- componentDescribe["inventory_controller"] = "Wird gebraucht, um erweitert mit dem eigenem Inventar zu interagieren!"
- componentErrorMsg["inventory_controller"] = "Muss für erweiterte Inventar-Behandlungen installiert sein."
- checkCom("inventory_controller")
- --"tank_controller"
- componentDescribe["tank_controller"] = "Wird gebraucht, um Flüssigkeiten auffüllen zu können."
- componentErrorMsg["tank_controller"] = "Muss installiert sein, um Eimer/Tanks auffüllen zu können."
- checkCom("tank_controller")
- --ENDE
- -- Was passiert, wenn ein PRIMÄRES Komponent fehlt?
- if checkPrimaryIfFalse ~= 0 then
- if checkPrimaryIfFalse == 1 then msg=" Primäres Upgrade ist NICHT installiert!" end
- if checkPrimaryIfFalse > 1 then msg=" Primäre Upgrades sind NICHT installiert!" end
- print("\n"..checkPrimaryIfFalse..msg)
- continueDialog("\nBestätige um Informationen zu erhalten...")
- failureComponentsOutput()
- continueDialog("\nBestätige um zu beenden...")
- failureComponentsOutput()
- os.exit()
- else
- --continueDialog("\nBestätige um fortzufahren...")
- os.sleep(1)
- end
- end
- function runCheckSecundaryComponents()
- -- [[SEKUNDÄR]]
- checkSecundaryIfFalse = 0
- comFeedback("Sekundär")
- --"tractor_beam"
- componentDescribe["tractor_beam"] = "Wird benötigt um Items um sich herum aufzusammeln."
- componentErrorMsg["tractor_beam"] = "Damit kann der Roboter Items um sich herum aufsammeln."
- if checkComponent("tractor_beam") == true then
- sucker = component.tractor_beam -- If Sucker ~= 0 then end
- print("[I] ".."tractor_beam")
- successComponents("tractor_beam")
- else
- print("[E] ".."tractor_beam")
- failureComponents("tractor_beam")
- writeSecundaryToIfFalse()
- end
- --"chunkloader"
- componentDescribe["chunkloader"] = "Chunkloader ist dazu da um Chunk(s), in dem sich der Roboter befindet, aktiv zu halten, sodass der Roboter uneingeschrängt weiter arbeiten kann."
- componentErrorMsg["chunkloader"] = "Chunkloader ist dazu da um Chunk(s) um den Roboter aktiv zu halten, damit der Roboter weiter arbeiten kann."
- if checkComponent("chunkloader") == true then
- chunkloader = component.chunkloader -- If chunkloader ~= 0 then end
- print("[I] ".."chunkloader")
- successComponents("chunkloader")
- else
- print("[E] ".."chunkloader")
- failureComponents("chunkloader")
- writeSecundaryToIfFalse()
- end
- --ENDE
- -- Was passiert, wenn ein SEKUNDÄRES Komponent fehlt?
- if checkSecundaryIfFalse ~= 0 then
- if checkSecundaryIfFalse == 1 then msg=" Sekundäres Upgrade ist NICHT verfügbar!" end
- if checkSecundaryIfFalse > 1 then msg=" Sekundäre Upgrades sind NICHT verfügbar!" end
- print("\n"..checkSecundaryIfFalse..msg)
- continueDialog("\nBestätige um fortzufahren...")
- end
- end
- --
- function chunkloaderActivate()
- if chunkloader ~= 0 then
- if chunkloader.isActive() == false then
- chunkloader.setActive(true)
- chunkloaderStatus = true
- else
- chunkloader.setActive(true)
- chunkloaderStatus = true
- end
- end
- end
- function chunkloaderDeactivate()
- if chunkloader ~= 0 then
- if chunkloader.isActive() == true then
- chunkloader.setActive(false)
- chunkloaderStatus = false
- else
- chunkloader.setActive(false)
- chunkloaderStatus = false
- end
- end
- end
- ----------------------------------------------------------------------------------------------
- --[[ Funktionen: robot.drain() ]]
- function Drain()
- boo,t = robot.detect()
- if t == "liquid" then
- if robot.tankSpace() >= 1000 then
- robot.drain()
- robot.drainUp()
- robot.drainDown()
- else
- StatusScreen()
- debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
- end
- end
- end
- function DrainUp()
- booUp,tUp = robot.detectUp()
- if tUp == "liquid" then
- if robot.tankSpace() >= 1000 then
- robot.drain()
- robot.drainUp()
- robot.drainDown()
- else
- StatusScreen()
- debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
- end
- end
- end
- function DrainDown()
- booDown,tDown = robot.detect()
- if tDown == "liquid" then
- if robot.tankSpace() >= 1000 then
- robot.drain()
- robot.drainUp()
- robot.drainDown()
- else
- StatusScreen()
- debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
- end
- end
- end
- function DrainAll()
- DrainUp()
- Drain()
- DrainDown()
- end
- --[[ Funktionen: robot.DefaultFunctionsUsing() ]]
- function defaultUsedFunctions()
- StatusScreen()
- end
- --[[ Funktionen: robot.swing() ]]
- function Swing()
- Drain()
- while robot.detect() do
- robot.swing()
- defaultUsedFunctions()
- end
- end
- function SwingUp()
- DrainUp()
- while robot.detectUp() do
- robot.swingUp()
- defaultUsedFunctions()
- end
- end
- function SwingDown()
- DrainDown()
- while robot.detectDown() do
- robot.swingDown()
- defaultUsedFunctions()
- end
- end
- --[[ Funktionen: robot.move() | robot.up/down/right/left ]]
- function MoveForward(x)
- for i=1,x do
- DrainAll()
- setlastPosition()
- Swing()
- robot.forward()
- setcurrentPosition()
- defaultUsedFunctions()
- end
- end
- function MoveBack(x)
- robot.turnAround()
- for i=1,x do
- DrainAll()
- Swing()
- setlastPosition()
- MoveForward(1)
- setcurrentPosition()
- defaultUsedFunctions()
- end
- robot.turnAround()
- end
- function Back(x)
- for i=1,x do
- DrainAll()
- setlastPosition()
- robot.back()
- setcurrentPosition()
- defaultUsedFunctions()
- end
- end
- function MoveUp(x)
- for i=1,x do
- DrainAll()
- setlastPosition()
- SwingUp()
- Swing()
- if robot.detectUp() ~= true then
- robot.up()
- else
- while robot.detect() == true do
- Swing()
- end
- while robot.detectUp() == true do
- SwingUp()
- end
- while robot.detectDown() == true do
- SwingDown()
- end
- end
- setcurrentPosition()
- defaultUsedFunctions()
- end
- end
- function MoveDown(x)
- for i=1,x do
- DrainAll()
- setlastPosition()
- SwingDown()
- Swing()
- SwingUp()
- if robot.detectUp() ~= true and robot.detectDown() ~= true then
- robot.down()
- else
- while robot.detect() == true do
- Swing()
- end
- while robot.detectUp() == true do
- SwingUp()
- end
- while robot.detectDown() == true do
- SwingDown()
- end
- end
- setcurrentPosition()
- defaultUsedFunctions()
- end
- end
- function TurnLeft(x)
- for i=1,x do
- DrainAll()
- CurrentDirection = CurrentDirection - 1
- if CurrentDirection == 0 then
- CurrentDirection = 4
- end
- robot.turnLeft()
- defaultUsedFunctions()
- end
- end
- function TurnRight(x)
- for i=1,x do
- DrainAll()
- CurrentDirection = CurrentDirection + 1
- if CurrentDirection == 5 then
- CurrentDirection = 1
- end
- robot.turnRight()
- defaultUsedFunctions()
- end
- end
- -----
- -- Save Moving
- function MoveForwardUntilBlock(x)
- for i=1,x do
- robot.forward()
- defaultUsedFunctions()
- boo,t = robot.detect()
- if t == "solid" then
- break
- end
- end
- end
- function MoveSafedForward(x)
- for i=1,x do
- robot.forward()
- defaultUsedFunctions()
- end
- end
- function MoveSafedBack(x)
- for i=1,x do
- robot.back()
- defaultUsedFunctions()
- end
- end
- function MoveSafedUp(x)
- for i=1,x do
- robot.up()
- defaultUsedFunctions()
- end
- end
- function MoveSafedDown(x)
- for i=1,x do
- robot.down()
- defaultUsedFunctions()
- end
- end
- -----
- --[[ Funktionen: robot.ExtractItems ]]
- function FillTanks()
- if robot.tankLevel() ~= 0 then
- if itemname == "ThermalExpansion:Tesseract" then
- for i=1,robot.tankLevel()/1000 do
- robot.fill()
- defaultUsedFunctions()
- end
- end
- end
- end
- function Fill(itemname)
- if robot.tankLevel() ~= 0 then
- if itemname == "ThermalExpansion:Tesseract" then
- for i=1,robot.tankLevel()/1000 do
- robot.fill()
- defaultUsedFunctions()
- end
- end
- end
- end
- function Extract()
- if robot.space(InventorySize) ~= 64 then
- for i=1,InventorySize do
- CurrentInventorySlot = robot.select(i)
- item = component.inventory_controller.getStackInInternalSlot(i).name
- for l=0,#ExtractItems do
- items = ExtractItems[l]
- if item == items then
- LastInventorySlot = i
- Back(1)
- robot.place()
- for s=2,InventorySize do
- CurrentInventorySlot = robot.select(s)
- robot.drop()
- end
- Fill(item)
- robot.select(1)
- robot.swing()
- robot.select(1)
- MoveForward(1)
- return true
- end
- if l == #ExtractItems then
- return false
- end
- end
- end
- end
- end
- -----
- -- TurnToParkingDirection
- function TurnToParkingDirection()
- if ParkingDirection ~= CurrentDirection then
- if ParkingDirection < CurrentDirection then
- while ParkingDirection ~= CurrentDirection do
- TurnRight(1)
- end
- elseif ParkingDirection > CurrentDirection then
- while ParkingDirection ~= CurrentDirection do
- TurnLeft(1)
- end
- end
- end
- end
- function TurnToDirection(x)
- if x ~= CurrentDirection then
- if x < CurrentDirection then
- while x ~= CurrentDirection do
- TurnRight(1)
- end
- elseif x > CurrentDirection then
- while x ~= CurrentDirection do
- TurnLeft(1)
- end
- end
- end
- end
- ----------
- -- Erkennung in welhe Richtung gerade geguckt wird.
- function detectCurrentDirection()
- MoveForward(1)
- --
- if lastPositionX < currentPositionX then
- CurrentDirection = 2
- return 2
- elseif lastPositionX > currentPositionX then
- CurrentDirection = 4
- return 4
- elseif lastPositionZ < currentPositionZ then
- CurrentDirection = 3
- return 3
- elseif lastPositionZ > currentPositionZ then
- CurrentDirection = 1
- return 1
- end
- --
- end
- -----
- -- Detect Inventory
- function DetectInventoryItem(item)
- -- InventorySize = InventorySize (64)
- for i=1,InventorySize do
- robot.select(i)
- if robot.space(i) ~= 64 then
- item_name = component.inventory_controller.getStackInInternalSlot(i).name
- if item_name == item then
- return true
- end
- end
- end
- end
- if DetectInventoryItem("minecraft:cobblestone") == true then term.clear() print("ERFOLGREICH)") end
- ----------
- function MoveDownUntilStartHeight()
- if pause == true then
- for t=0,pause_time-1 do
- rest = pause_time - t
- term.clear()
- print("Pause: Energie aufladen.")
- print("Noch "..rest.." Minuten.")
- os.sleep(60)
- end
- end
- setcurrentPosition()
- i = currentPositionY
- while i > startPositionY do
- i = i - 1
- MoveDown(1)
- end
- Extract()
- end
- function MoveDownUntilDetect()
- while robot.detectDown() ~= true do
- robot.down()
- end
- end
- function MoveUpUntilNoDetection()
- for i=currentPositionY,MaxTotalHeight do -- MaxTotalHeight oben bei Configuation
- MoveUp(1)
- if lastPositionY == currentPositionY then
- if currentPositionY < MaxHeight then -- MaxHeight oben bei Configuration
- if DetectInventoryItem("minecraft:cobblestone") == true then
- robot.place()
- robot.down()
- robot.place()
- robot.up()
- robot.placeDown()
- if robot.detectDown() ~= true then
- MoveDownUntilStartHeight()
- break
- end
- else
- MoveDownUntilStartHeight()
- break
- end
- else
- MoveDownUntilStartHeight()
- break
- end
- end
- end
- end
- ----------------------------------------------------------------------------------------------
- --[[ ErkennungsFunktionen / CONFIG ]]
- function isint(n)
- if n == "" then
- print("Fehler!")
- os.sleep(1)
- print("Programm wird abgebrochen.\nDiskette neu einlegen!")
- os.sleep(1)
- os.exit()
- else
- return n == math.floor(n)
- end
- end
- --[[ CONFIG-Fragebogen ]]
- -- config_0 == Length
- -- config_1 == Width
- -- config_2 == [L]inks/[R]echts
- function l(x)
- config_0 = x
- end
- function w(x)
- config_1 = x
- end
- function d(x)
- config_2 = x
- end
- function config_current_screen(var)
- --Length-Anzeige
- if var == 1 or var == 2 or var == 3 then
- print("Length: | "..config_0)
- end
- --Width-Anzeige
- if var == 2 or var == 3 then
- print("Width: | "..config_1)
- end
- --Direction-Anzeige
- if var == 3 then
- if config_1 ~= "1" then
- print("Direction: | "..config_2)
- end
- end
- end
- function config_current_parking_screen(var)
- --X-Anzeige
- if var == 1 or var == 2 or var == 3 or var == 4 then
- print("X: | "..parkingPositionConfig[0])
- end
- --Y-Anzeige
- if var == 2 or var == 3 or var == 4 then
- print("Y: | "..parkingPositionConfig[1])
- end
- --Z-Anzeige
- if var == 3 or var == 4 then
- print("Z: | "..parkingPositionConfig[2])
- end
- -- X+/X-|Z+/Z- | Anzeige
- if var == 4 then
- print("X/Z Richtung: | "..parkingPositionConfig[3])
- end
- end
- function setLength(msg)
- term.clear()
- info()
- io.write("Length: (Standard: "..config_std_0..")"..msg.."\n")
- config_0 = io.read()
- if isint(config_0) == "" then
- config_0 = config_0
- end
- end
- function setWidth(msg)
- term.clear()
- info()
- config_current_screen(1)
- io.write("Width: (Standard: "..config_std_1..")"..msg.."\n")
- config_1 = io.read()
- if isint(config_1) then
- return true
- end
- end
- function setDirection(msg)
- term.clear()
- info()
- config_current_screen(2)
- io.write("Direction: (L/R)"..msg.."\n")
- config_2 = string.upper(io.read())
- if config_2 == "L" or config_2 == "R" then
- else
- setDirection(" (Nur 'L' oder 'R' möglich!)")
- end
- end
- --[[
- parkingPositionX
- parkingPositionY
- parkingPositionZ
- parkingPositionConfig[0]
- parkingPositionConfig[1]
- parkingPositionConfig[2]
- ]]
- function setParkingCoordinatesX(msg)
- term.clear()
- info()
- config_current_screen(3)
- print("------------------------------+")
- config_current_parking_screen(0)
- io.write("Parkplatz: X-Koordinaten:"..msg.."\n")
- local X = io.read()
- parkingPositionConfig[0] = X
- parkingPositionX = X
- if isint(parkingPositionConfig[0]) == "" then
- --
- end
- end
- function setParkingCoordinatesY(msg)
- term.clear()
- info()
- config_current_screen(3)
- print("------------------------------+")
- config_current_parking_screen(1)
- io.write("Parkplatz: Y-Koordinaten:"..msg.."\n")
- local Y = io.read()
- parkingPositionConfig[1] = Y
- parkingPositionY = Y
- if isint(parkingPositionConfig[1]) == "" then
- --
- end
- end
- function setParkingCoordinatesZ(msg)
- term.clear()
- info()
- config_current_screen(3)
- print("------------------------------+")
- config_current_parking_screen(2)
- io.write("Parkplatz: Z-Koordinaten:"..msg.."\n")
- local Z = io.read()
- parkingPositionConfig[2] = Z
- parkingPositionZ = Z
- if isint(parkingPositionConfig[2]) == "" then
- --
- end
- end
- function setParkingCoordinatesD(msg)
- term.clear()
- info()
- config_current_screen(3)
- print("------------------------------+")
- config_current_parking_screen(3)
- io.write("Parkplatz: X/Z-Richtung:"..msg.."\n")
- var = string.upper(io.read())
- parkingPositionConfig[3] = var
- parkingPositionD = var
- if var == "N" then
- ParkingDirection = 1
- elseif var == "E" then
- ParkingDirection = 2
- elseif var == "S" then
- ParkingDirection = 3
- elseif var == "W" then
- ParkingDirection = 4
- else
- setParkingCoordinatesD(" FEHLER!\nN = North/Norden\nE = East/Osten\nS = South/Süden\nW = West/Westen\nNur möglich: N / E / S / W")
- end
- end
- function setParkingCoordinates()
- term.clear()
- info()
- config_current_screen(3)
- print("------------------------------+")
- --
- setParkingCoordinatesX("( X ("..currentPositionX..") )")
- setParkingCoordinatesY("( Y ("..currentPositionY..") )")
- setParkingCoordinatesZ("( Z ("..currentPositionZ..") )")
- setParkingCoordinatesD("\n\nN = North/Norden\nE = East/Osten\nS = South/Süden\nW = West/Westen")
- term.clear()
- for i=1,1 do for b=1,21 do term.clear() config_current_parking_screen(4) print("\nÜberprüfung:\n["..dash_bar[b].."]") os.sleep(0.01) end end
- os.sleep(0.5)
- end
- function fragebogen()
- --Config-Length-FRAGE
- setLength("")
- --Config-Width-FRAGE
- setWidth("")
- --Config-Direction-FRAGE
- if config_1 ~= "1" then
- setDirection("")
- else
- d("")
- end
- --Config-Ergebnis
- term.clear()
- for i=1,1 do for b=1,21 do term.clear() config_current_screen(3) print("\nÜberprüfung:\n["..dash_bar[b].."]") os.sleep(0.01) end end
- os.sleep(0.5)
- end
- --[[ ]]
- --[[ Funktionen: Direction:LEFT ]]
- --[[ ]]
- function ExecuteLeft()
- print("Execute Left")
- end
- --[[ ]]
- --[[ Funktionen: Direction:RIGHT ]]
- --[[ ]]
- function ExecuteRight()
- print("Execute Right")
- end
- --[[ ]]
- --[[ Funktionen: Direction:FORWARD ]]
- --[[ ]]
- function ExecuteForward()
- for i=1,config_0 do
- if i == 1 then
- detectCurrentDirection()
- else
- MoveForward(1)
- end
- MoveUpUntilNoDetection()
- end
- state = "parking"
- end
- --[[ DETECT AND CHOOSE DIRECTION ]]
- function detectWorkDirection()
- if config_2 == "L" then
- ExecuteLeft() -- LInks ausführen
- end
- if config_2 == "R" then
- ExecuteRight() -- Rechts ausführen
- end
- if config_1 == "1" then
- ExecuteForward() -- Forwärts ausführen
- end
- end
- ----------------------------------------------------------------------------------------------
- --[[ HAUPTPROGRAM ]]
- function mainInitialisierung()
- loading("Initialisiere Start Einstellungen\n")
- checkStartSlots()
- MoveDownUntilDetect()
- term.clear()
- loading("Initialisiere Primäre Komponente\n")
- runCheckPrimaryComponents()
- term.clear()
- loading("Initialisiere Sekundäre Komponente\n")
- runCheckSecundaryComponents()
- loading("Floppy Disk\n")
- end
- function mainShowConfigScreen()
- term.clear()
- --info()
- print("------------------------------+")
- --ShowConfigScreen
- config_current_screen(3)
- print("------------------------------+")
- getstartPosition("Start: ","")
- getcurrentPosition("Derzeit: ","")
- getlastPosition("Zuletzt: ","")
- if ParkingStatus == true then
- getparkingPosition("Parkplatz: ","")
- end
- print("------------------------------+")
- show_tank_info()
- print("------------------------------+")
- end
- function mainShowConfiguredScreen()
- term.clear()
- info()
- --ShowConfigScreen
- if config_2 == "" then config_current_screen(2) else config_current_screen(3) end
- print("------------------------------+")
- getstartPosition("Start: ","")
- if ParkingStatus == true then
- getparkingPosition("Parkplatz: ","")
- end
- print("------------------------------+")
- show_tank_info()
- print("------------------------------+")
- end
- function mainInit()
- mainInitialisierung()
- chunkloaderActivate()
- --
- fragebogen()
- if ParkingStatus == true then
- setParkingCoordinates()
- end
- --l("30000000") w("1") d("")
- --
- mainShowConfiguredScreen()
- os.sleep(0.1)
- --Drain()
- function finishQuestion(msg)
- mainShowConfiguredScreen()
- io.write("Ist alles korrekt? "..msg..'\n')
- var = string.upper(io.read())
- if var == "J" or var == "N" then
- if var == "J" then
- state = string.lower("work")
- elseif var == "N" then
- state = string.lower("init")
- mainInit()
- end
- else
- finishQuestion("(Nur (J/N) möglich!)")
- end
- end
- finishQuestion("(J/N)")
- end
- -----
- function mainBackToWork()
- print("Enter state: 'backtowork'")
- end
- -----
- function mainParking()
- print("Enter state: 'parking'")
- mainShowConfiguredScreen()
- print("FERTIG!")
- print("Kehre zurück zur Startposition.")
- robot.turnAround()
- MoveForwardUntilBlock(config_0)
- robot.turnAround()
- defaultUsedFunctions()
- end
- -----
- function mainWork()
- mainShowConfigScreen()
- print("Enter state: 'work'")
- detectWorkDirection()
- end
- -----
- function main()
- if state == string.lower("init") then
- mainInit()
- end
- if state == string.lower("work") then
- mainWork()
- end
- if state == string.lower("parking") then
- mainParking()
- end
- if state == string.lower("backtowork") then
- mainBackToWork()
- end
- end
- main()
- --[[ ROBOT:MOVING --]] -- Kommentare
- -- robot.Up()
- -- robot.down()
- -- robot.forward()
- -- robot.back()
- -- robot.turnRight()
- -- robot.turnLeft()
- -- robot.turnAround()
- -- robot.swing()
- -- robot.swingDown()
- -- robot.swingUp()
- -- robot.use()
- -- robot.useDown()
- -- robot.useUp()
- -- robot.place()
- -- robot.placeDown()
- -- robot.placeUp()
- -- robot.suck()
- -- robot.suckDown()
- -- robot.suckUp()
- -- robot.drop()
- -- robot.dropDown()
- -- robot.dropUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement