Advertisement
NaNoXiDo

Power Mining - v0.70

Aug 26th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.15 KB | None | 0 0
  1. --[[
  2. WICHTIGE KOMPONENTE:
  3. ####################
  4. navigation
  5. inventory_controller
  6. inventory_upgrade
  7. tank_controller
  8.  
  9. ####################
  10. ]]
  11. -- Imports --
  12. local robot = require("robot")
  13. local computer = require("computer")
  14. local term = require("term")
  15. local os = require("os")
  16. local component = require("component")
  17. local sides = require("sides")
  18. local string = require("string")
  19. local shell = require("shell")
  20. -- MOUNT
  21. local fs = require("filesystem")
  22. proxy = ...
  23. mountDirectory = "/PM"
  24. if fs.isDirectory(mountDirectory) == false then
  25.   fs.mount(proxy, mountDirectory)
  26. end
  27.  
  28. --[[ Variablen ]]
  29. debug_mode = 1 --[[ [1]TRUE | [0]FALSE
  30. Protokoliert jeden Roboter-Schritt! ]]
  31. version = "0.70" --[[ Version ]]
  32.  
  33. pause = true --true/false (an/aus)
  34. pause_time = 3 -- Minuten
  35.  
  36. config_std = {30000000,1,""} --[[ Standard Konfiguration
  37.                    30.000.000 , 1 , R
  38.                     Wenn "1", dann gräbt NUR gerade ]]
  39. config_std_0 = 30000000
  40. config_std_1 = 1
  41. config_std_2 = ""
  42.  
  43. ParkingStatus = false -- ist Parking-State erlaubt? > true | false <
  44.  
  45. ExtractItems = {"EnderStorage:enderChest",
  46.                 "ThermalExpansion:Tesseract"}
  47. WhitelistItems = {"",
  48.                   ""}
  49. InventorySize = 0
  50. StartInventorySlot = 1
  51. CurrentInventorySlot = StartInventorySlot
  52. LastInventorySlot = StartInventorySlot
  53. function checkStartSlots()
  54.  
  55.   InventorySize = robot.inventorySize()
  56.   robot.select(StartInventorySlot)
  57. end
  58.  
  59. config     = {30000000,1,""} --[[ Benutzer Konfiguration
  60.                    30.000.000 , 1 , R
  61.                     Wenn "1", dann gräbt NUR gerade ]]
  62. config_0 = 30000000
  63. config_1 = 1
  64. config_2 = ""
  65.  
  66. tests = 0
  67. MaxHeight = 66
  68. MaxTotalHeight = 265
  69. CurrentDirection = 0
  70. ParkingDirection = 0
  71. --[[1=North,2=East,3=South,4=West]]
  72.  
  73. sucker = 0
  74. chunkloader = 0
  75. chunkloaderStatus = false
  76. state = string.lower("init")
  77. -- States: Init | Work | Parking | BackToWork
  78.  
  79. --
  80.  
  81. -- Listen
  82. dot = {
  83. "", --0
  84. ".", --1
  85. "..", --2
  86. "...", --3
  87. "....", --4
  88. ".....", --5
  89. "......", --6
  90. ".......", --7
  91. "........", --8
  92. ".........", --9
  93. "..........", --10
  94. "...........", --11
  95. "............", --12
  96. ".............", --13
  97. "..............", --14
  98. "...............", --15
  99. "................", --16
  100. ".................", --17
  101. "..................", --18
  102. "...................", --19
  103. "....................", --20
  104. }
  105.  
  106. dash_bar = {
  107. "                    ", --0
  108. ".                   ", --1
  109. "..                  ", --2
  110. "...                 ", --3
  111. "....                ", --4
  112. ".....               ", --5
  113. "......              ", --6
  114. ".......             ", --7
  115. "........            ", --8
  116. ".........           ", --9
  117. "..........          ", --10
  118. "...........         ", --11
  119. "............        ", --12
  120. ".............       ", --13
  121. "..............      ", --14
  122. "...............     ", --15
  123. "................    ", --16
  124. ".................   ", --17
  125. "..................  ", --18
  126. "................... ", --19
  127. "...................."  --20
  128. }
  129.  
  130. -- Funktionen
  131.  
  132. function continueDialog(msg)
  133.   io.write(msg)
  134.   io.read()
  135. end
  136.  
  137. function info()
  138.   print("+-----------------------------+\n| PowerMining | Version: "..version.." |\n+-----------------------------+")
  139. end
  140.  
  141. function DirectionToText()
  142.   if     CurrentDirection == 0 then
  143.     return ""
  144.   elseif CurrentDirection == 1 then
  145.     return "North"
  146.   elseif CurrentDirection == 2 then
  147.     return "East"
  148.   elseif CurrentDirection == 3 then
  149.     return "South"
  150.   elseif CurrentDirection == 4 then
  151.     return "West"
  152.   end
  153. end
  154.  
  155. function ParkingDirectionToText()
  156.   if     ParkingDirection == 0 then
  157.     return ""
  158.   elseif ParkingDirection == 1 then
  159.     return "North"
  160.   elseif ParkingDirection == 2 then
  161.     return "East"
  162.   elseif ParkingDirection == 3 then
  163.     return "South"
  164.   elseif ParkingDirection == 4 then
  165.     return "West"
  166.   end
  167. end
  168.  
  169. function StatusConfigScreen(var)
  170.   --Length-Anzeige
  171.   if var == 1 or var == 2 or var == 3 then
  172.     print("Length:       | "..config_0)
  173.   end
  174.  
  175.   --Width-Anzeige
  176.   if var == 2 or var == 3 then
  177.     print("Width:        | "..config_1)
  178.   end
  179.  
  180.   --Direction-Anzeige
  181.   if var == 3 then
  182.     if config_1 ~= "1" then
  183.       print("Direction:    | "..config_2)
  184.     end
  185.   end
  186. end
  187.  
  188. function show_inventory_info()
  189.   print("Inventare     | " .. robot.tankCount() )
  190. end
  191.  
  192. function show_tank_info()
  193.   print("Anzahl Tanks  | " .. robot.tankCount() )
  194.   if robot.tankCount() ~= 0 then
  195.   print("Tank Info:    | " .. robot.tankLevel() .. "mb/" .. robot.tankLevel()+robot.tankSpace() .. "mb")
  196.   print("Frei          | " .. robot.tankSpace() .. "mb")
  197.   end
  198. end
  199.  
  200. 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
  201.  
  202. --[[ DEBUG_MSG ]]
  203. function debug_msg(msg)
  204.   if debug_mode == 1 then
  205.     print("([DEBUG]: "..msg..")")
  206.   end
  207. end
  208.  
  209. --Direction
  210.  
  211. --Positions-Funktionen
  212. startPositionConfig = {}
  213. startPositionX = ""
  214. startPositionY = ""
  215. startPositionZ = ""
  216. function getstartPosition(msg1,msg2) --GetPosition
  217.   return print(msg1, startPositionX, startPositionY, startPositionZ, msg2)
  218. end
  219. function setstartPosition() --SetPosition
  220.   startPositionX,
  221.   startPositionY,
  222.   startPositionZ = navi.getPosition()
  223.   startPositionConfig[0] = startPositionX
  224.   startPositionConfig[1] = startPositionY
  225.   startPositionConfig[2] = startPositionZ
  226. end
  227.  
  228. currentPositionConfig = {}
  229. currentPositionX = ""
  230. currentPositionY = ""
  231. currentPositionZ = ""
  232. function getcurrentPosition(msg1,msg2) --GetPosition
  233.     return print(msg1, currentPositionX, currentPositionY, currentPositionZ, msg2)
  234. end
  235. function setcurrentPosition() --SetPosition
  236.   currentPositionX,
  237.   currentPositionY,
  238.   currentPositionZ = navi.getPosition()
  239.   currentPositionConfig[0] = currentPositionX
  240.   currentPositionConfig[1] = currentPositionY
  241.   currentPositionConfig[2] = currentPositionZ
  242. end
  243.  
  244. lastPositionConfig = {}
  245. lastPositionX = ""
  246. lastPositionY = ""
  247. lastPositionZ = ""
  248. function getlastPosition(msg1,msg2) --GetPosition
  249.   return print(msg1, lastPositionX, lastPositionY, lastPositionZ, msg2)
  250. end
  251. function setlastPosition() --SetPosition
  252.   if state == "work" then
  253.     lastPositionX,
  254.     lastPositionY,
  255.     lastPositionZ = navi.getPosition()
  256.     lastPositionConfig[0] = lastPositionX
  257.     lastPositionConfig[1] = lastPositionY
  258.     lastPositionConfig[2] = lastPositionZ
  259.   end
  260. end
  261.  
  262. parkingPositionConfig = {}
  263. parkingPositionX = ""
  264. parkingPositionY = ""
  265. parkingPositionZ = ""
  266. parkingPositionD = ""
  267. function getparkingPosition(msg1,msg2) --GetPosition
  268.     return print(msg1, parkingPositionX, parkingPositionY, parkingPositionZ, ParkingDirectionToText(), msg2)
  269. end
  270. function setparkingPosition(x,y,z) --SetPosition
  271.   parkingPositionX = x
  272.   parkingPositionY = y
  273.   parkingPositionZ = z
  274.   parkingPositionConfig[0] = parkingPositionX
  275.   parkingPositionConfig[1] = parkingPositionY
  276.   parkingPositionConfig[2] = parkingPositionZ
  277. end
  278.  
  279. DifferenceToStartPositionConfig = {}
  280. DifferenceToStartPositionX = ""
  281. DifferenceToStartPositionY = ""
  282. DifferenceToStartPositionZ = ""
  283. function setDifferenceToStartPosition()
  284.   DifferenceToStartPositionX = currentPositionX - startPositionX
  285.   DifferenceToStartPositionY = currentPositionY - startPositionY
  286.   DifferenceToStartPositionZ = currentPositionZ - startPositionZ
  287. end
  288. function getDifferenceToStartPosition(msg1,msg2)
  289.   setDifferenceToStartPosition()
  290.   return print(msg1, DifferenceToStartPositionX, DifferenceToStartPositionY, DifferenceToStartPositionZ, msg2)
  291. end
  292.  
  293. DifferenceToParkingPositionConfig = {}
  294. DifferenceToParkingPositionX = ""
  295. DifferenceToParkingPositionY = ""
  296. DifferenceToParkingPositionZ = ""
  297. function setDifferenceToParkingPosition()
  298.   DifferenceToParkingPositionX =  parkingPositionX - currentPositionX
  299.   DifferenceToParkingPositionY =  parkingPositionY - currentPositionY
  300.   DifferenceToParkingPositionZ =  parkingPositionZ - currentPositionZ
  301. end
  302. function getDifferenceToParkingPosition(msg1,msg2)
  303.   setDifferenceToParkingPosition()
  304.   return print(msg1, DifferenceToParkingPositionX, DifferenceToParkingPositionY, DifferenceToParkingPositionZ, msg2)
  305. end
  306.  
  307. function StatusScreen()
  308.   term.clear()
  309.   print("------------------------------+")
  310.   StatusConfigScreen(3)
  311.   print("------------------------------+")
  312.   getcurrentPosition("Derzeit:   ",DirectionToText())
  313. --getlastPosition("Zuletzt: ","")
  314.   getDifferenceToStartPosition("         ", "")
  315.   getstartPosition("Start:     ","")
  316.   print("------------------------------+")
  317.   if ParkingStatus == true then
  318.     getDifferenceToParkingPosition("           ", "")
  319.     getparkingPosition("Parkplatz: ","")
  320.     print("------------------------------+")
  321.   end
  322.   show_tank_info()
  323.   print("------------------------------+")
  324. end
  325.  
  326. --Überprüfung von Componenten
  327. successComponentsTable = {}
  328. function successComponents(c) successComponentsTable[c]="" end
  329. failureComponentsTable = {}
  330. function failureComponents(c) failureComponentsTable[c]="" end
  331. componentDescribe = {}
  332. componentErrorMsg = {}
  333. checkPrimaryIfFalse = 0
  334. checkSecundaryIfFalse = 0
  335. function writePrimaryToIfFalse()
  336.   checkPrimaryIfFalse = checkPrimaryIfFalse + 1
  337. end
  338. function writeSecundaryToIfFalse()
  339.   checkSecundaryIfFalse = checkSecundaryIfFalse +1
  340. end
  341. --
  342. function successComponentsOutput()
  343.   term.clear()
  344.   info()
  345.   for c,d in pairs(componentDescribe) do
  346.     for cpnnt in pairs(successComponentsTable) do
  347.       if cpnnt == c then
  348.         print("[\""..string.upper(c).."\"]:\n"..d)
  349.       end
  350.     end
  351.   end
  352. end
  353. function failureComponentsOutput()
  354.   term.clear()
  355.   info()
  356.   for c,d in pairs(componentErrorMsg) do
  357.     for cpnnt in pairs(failureComponentsTable) do
  358.       if cpnnt == c then
  359.         print("[\""..string.upper(c).."\"]:\n"..d)
  360.       end
  361.     end
  362.   end
  363. end
  364. --
  365. function checkComponent(var)
  366.   for com in pairs(component) do
  367.     if var == com then
  368.       return true
  369.     end
  370.   end
  371. end
  372. --
  373. function comFeedback(msg)
  374.   if msg ~= "" then msg=""..msg..":" end
  375.   print("[I] Initialisiert | [E] Error")
  376.   print("-------------------------------")
  377.   if msg ~= "" then print(msg) end
  378. end
  379. --
  380. function checkCom(comVar)
  381.   if checkComponent(comVar) == true then
  382.     print("[I] "..comVar)
  383.     successComponents(comVar)
  384.   else
  385.     print("[E] "..comVar)
  386.     failureComponents(comVar)
  387.     writePrimaryToIfFalse()
  388.   end
  389. end
  390. --
  391. function runCheckPrimaryComponents()
  392.   -- [[PRIMÄR]]
  393.   checkPrimaryIfFalse = 0
  394.   comFeedback("Primär")
  395.   --"navigation"
  396.   componentDescribe["navigation"] = "Ist essentiell wichtig um mit Koordinaten umgehen zu können. Und überhaupt Koordinaten erkennen zu können."
  397.   componentErrorMsg["navigation"] = "Muss installiert werden um mit mit Koordinaten umgehen zu können."
  398.   if checkComponent("navigation") == true then
  399.     navi = component.navigation
  400.     startPositionX, startPositionY, startPositionZ = navi.getPosition()
  401.     sPX, sPY, sPZ = navi.getPosition()
  402.     cPX, cPY, cPZ = navi.getPosition()
  403.     setstartPosition()
  404.     setcurrentPosition()
  405.     print("[I] ".."navigation")
  406.     successComponents("navigation")
  407.   else
  408.     print("[E] ".."navigation")
  409.     failureComponents("navigation")
  410.     writePrimaryToIfFalse()
  411.   end
  412.   --"inventory_controller"
  413.   componentDescribe["inventory_controller"] = "Wird gebraucht, um erweitert mit dem eigenem Inventar zu interagieren!"
  414.   componentErrorMsg["inventory_controller"] = "Muss für erweiterte Inventar-Behandlungen installiert sein."
  415.   checkCom("inventory_controller")
  416.   --"tank_controller"
  417.   componentDescribe["tank_controller"] = "Wird gebraucht, um Flüssigkeiten auffüllen zu können."
  418.   componentErrorMsg["tank_controller"] = "Muss installiert sein, um Eimer/Tanks auffüllen zu können."
  419.   checkCom("tank_controller")
  420.   --ENDE
  421.   -- Was passiert, wenn ein PRIMÄRES Komponent fehlt?
  422.   if checkPrimaryIfFalse ~= 0 then
  423.     if checkPrimaryIfFalse == 1 then msg=" Primäres Upgrade ist NICHT installiert!" end
  424.     if checkPrimaryIfFalse > 1 then msg=" Primäre Upgrades sind NICHT installiert!" end
  425.     print("\n"..checkPrimaryIfFalse..msg)
  426.     continueDialog("\nBestätige um Informationen zu erhalten...")
  427.     failureComponentsOutput()
  428.     continueDialog("\nBestätige um zu beenden...")
  429.     failureComponentsOutput()
  430.     os.exit()
  431.   else
  432.     --continueDialog("\nBestätige um fortzufahren...")
  433.     os.sleep(1)
  434.   end
  435. end
  436. function runCheckSecundaryComponents()
  437.   -- [[SEKUNDÄR]]
  438.   checkSecundaryIfFalse = 0
  439.   comFeedback("Sekundär")
  440.   --"tractor_beam"
  441.   componentDescribe["tractor_beam"] = "Wird benötigt um Items um sich herum aufzusammeln."
  442.   componentErrorMsg["tractor_beam"] = "Damit kann der Roboter Items um sich herum aufsammeln."
  443.   if checkComponent("tractor_beam") == true then
  444.     sucker = component.tractor_beam -- If Sucker ~= 0 then end
  445.     print("[I] ".."tractor_beam")
  446.     successComponents("tractor_beam")
  447.   else
  448.     print("[E] ".."tractor_beam")
  449.     failureComponents("tractor_beam")
  450.     writeSecundaryToIfFalse()
  451.   end
  452.     --"chunkloader"
  453.   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."
  454.   componentErrorMsg["chunkloader"] = "Chunkloader ist dazu da um Chunk(s) um den Roboter aktiv zu halten, damit der Roboter weiter arbeiten kann."
  455.   if checkComponent("chunkloader") == true then
  456.     chunkloader = component.chunkloader -- If chunkloader ~= 0 then end
  457.     print("[I] ".."chunkloader")
  458.     successComponents("chunkloader")
  459.   else
  460.     print("[E] ".."chunkloader")
  461.     failureComponents("chunkloader")
  462.     writeSecundaryToIfFalse()
  463.   end
  464.   --ENDE
  465.   -- Was passiert, wenn ein SEKUNDÄRES Komponent fehlt?
  466.   if checkSecundaryIfFalse ~= 0 then
  467.     if checkSecundaryIfFalse == 1 then msg=" Sekundäres Upgrade ist NICHT verfügbar!" end
  468.     if checkSecundaryIfFalse > 1 then msg=" Sekundäre Upgrades sind NICHT verfügbar!" end
  469.     print("\n"..checkSecundaryIfFalse..msg)
  470.     continueDialog("\nBestätige um fortzufahren...")
  471.   end
  472. end
  473. --
  474. function chunkloaderActivate()
  475.   if chunkloader ~= 0 then
  476.     if chunkloader.isActive() == false then
  477.       chunkloader.setActive(true)
  478.       chunkloaderStatus = true
  479.     else
  480.       chunkloader.setActive(true)
  481.       chunkloaderStatus = true
  482.     end
  483.   end
  484. end
  485. function chunkloaderDeactivate()
  486.   if chunkloader ~= 0 then
  487.     if chunkloader.isActive() == true then
  488.       chunkloader.setActive(false)
  489.       chunkloaderStatus = false
  490.     else
  491.       chunkloader.setActive(false)
  492.       chunkloaderStatus = false
  493.     end
  494.   end
  495. end
  496. ----------------------------------------------------------------------------------------------
  497.  
  498. --[[ Funktionen: robot.drain() ]]
  499. function Drain()
  500.   boo,t = robot.detect()
  501.   if t == "liquid" then
  502.     if robot.tankSpace() >= 1000 then
  503.       robot.drain()
  504.       robot.drainUp()
  505.       robot.drainDown()
  506.     else
  507.       StatusScreen()
  508.       debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
  509.     end
  510.   end
  511. end
  512. function DrainUp()
  513.   booUp,tUp = robot.detectUp()
  514.   if tUp == "liquid" then
  515.     if robot.tankSpace() >= 1000 then
  516.       robot.drain()
  517.       robot.drainUp()
  518.       robot.drainDown()
  519.     else
  520.       StatusScreen()
  521.       debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
  522.     end
  523.   end
  524. end
  525. function DrainDown()
  526.   booDown,tDown = robot.detect()
  527.   if tDown == "liquid" then
  528.     if robot.tankSpace() >= 1000 then
  529.       robot.drain()
  530.       robot.drainUp()
  531.       robot.drainDown()
  532.     else
  533.       StatusScreen()
  534.       debug_msg("Tank ist voll! (" .. robot.tankLevel() .. "mb)")
  535.     end
  536.   end
  537. end
  538.  
  539. function DrainAll()
  540.   DrainUp()
  541.   Drain()
  542.   DrainDown()  
  543. end
  544.  
  545. --[[ Funktionen: robot.DefaultFunctionsUsing() ]]
  546. function defaultUsedFunctions()
  547.   StatusScreen()
  548. end
  549.  
  550. --[[ Funktionen: robot.swing() ]]
  551. function Swing()
  552.   Drain()
  553.   while robot.detect() do
  554.     robot.swing()
  555.     defaultUsedFunctions()
  556.   end
  557. end
  558.  
  559. function SwingUp()
  560.   DrainUp()
  561.   while robot.detectUp() do
  562.     robot.swingUp()
  563.     defaultUsedFunctions()
  564.   end
  565. end
  566.  
  567. function SwingDown()
  568.   DrainDown()
  569.   while robot.detectDown() do
  570.     robot.swingDown()
  571.     defaultUsedFunctions()
  572.   end
  573. end
  574.  
  575. --[[ Funktionen: robot.move() | robot.up/down/right/left ]]
  576. function MoveForward(x)
  577.   for i=1,x do
  578.     DrainAll()
  579.     setlastPosition()
  580.     Swing()
  581.     robot.forward()
  582.     setcurrentPosition()
  583.     defaultUsedFunctions()
  584.   end
  585. end
  586.  
  587. function MoveBack(x)
  588.   robot.turnAround()
  589.   for i=1,x do
  590.     DrainAll()
  591.     Swing()
  592.     setlastPosition()
  593.     MoveForward(1)
  594.     setcurrentPosition()
  595.     defaultUsedFunctions()
  596.   end
  597.   robot.turnAround()
  598. end
  599.  
  600. function Back(x)
  601.   for i=1,x do
  602.     DrainAll()
  603.     setlastPosition()
  604.     robot.back()
  605.     setcurrentPosition()
  606.     defaultUsedFunctions()
  607.   end
  608. end
  609.  
  610. function MoveUp(x)
  611.   for i=1,x do
  612.     DrainAll()
  613.     setlastPosition()
  614.     SwingUp()
  615.     Swing()
  616.     if robot.detectUp() ~= true then
  617.       robot.up()
  618.     else
  619.       while robot.detect() == true do
  620.         Swing()
  621.       end
  622.       while robot.detectUp() == true do
  623.         SwingUp()
  624.       end
  625.       while robot.detectDown() == true do
  626.         SwingDown()
  627.       end
  628.     end
  629.     setcurrentPosition()
  630.     defaultUsedFunctions()
  631.   end
  632. end
  633.  
  634. function MoveDown(x)
  635.   for i=1,x do
  636.     DrainAll()
  637.     setlastPosition()
  638.     SwingDown()
  639.     Swing()
  640.     SwingUp()
  641.     if robot.detectUp() ~= true and robot.detectDown() ~= true then
  642.       robot.down()
  643.     else
  644.       while robot.detect() == true do
  645.         Swing()
  646.       end
  647.       while robot.detectUp() == true do
  648.         SwingUp()
  649.       end
  650.       while robot.detectDown() == true do
  651.         SwingDown()
  652.       end
  653.     end
  654.     setcurrentPosition()
  655.     defaultUsedFunctions()
  656.   end
  657. end
  658.  
  659. function TurnLeft(x)
  660.   for i=1,x do
  661.     DrainAll()
  662.     CurrentDirection = CurrentDirection - 1
  663.     if CurrentDirection == 0 then
  664.       CurrentDirection = 4
  665.     end
  666.     robot.turnLeft()
  667.     defaultUsedFunctions()
  668.   end
  669. end
  670.  
  671. function TurnRight(x)
  672.   for i=1,x do
  673.     DrainAll()
  674.     CurrentDirection = CurrentDirection + 1
  675.     if CurrentDirection == 5 then
  676.       CurrentDirection = 1
  677.     end
  678.     robot.turnRight()
  679.     defaultUsedFunctions()
  680.   end
  681. end
  682. -----
  683. -- Save Moving
  684.  
  685. function MoveForwardUntilBlock(x)
  686.   for i=1,x do
  687.     robot.forward()
  688.     defaultUsedFunctions()
  689.     boo,t = robot.detect()
  690.     if t == "solid" then
  691.       break
  692.     end
  693.   end
  694. end
  695.  
  696. function MoveSafedForward(x)
  697.   for i=1,x do
  698.     robot.forward()
  699.     defaultUsedFunctions()
  700.   end
  701. end
  702.  
  703. function MoveSafedBack(x)
  704.   for i=1,x do
  705.     robot.back()
  706.     defaultUsedFunctions()
  707.   end
  708. end
  709.  
  710. function MoveSafedUp(x)
  711.   for i=1,x do
  712.     robot.up()
  713.     defaultUsedFunctions()
  714.   end
  715. end
  716.  
  717. function MoveSafedDown(x)
  718.   for i=1,x do
  719.     robot.down()
  720.     defaultUsedFunctions()
  721.   end
  722. end
  723. -----
  724. --[[ Funktionen: robot.ExtractItems ]]
  725. function FillTanks()
  726.   if robot.tankLevel() ~= 0 then
  727.     if itemname == "ThermalExpansion:Tesseract" then
  728.       for i=1,robot.tankLevel()/1000 do
  729.         robot.fill()
  730.         defaultUsedFunctions()
  731.       end
  732.     end
  733.   end
  734. end
  735.  
  736. function Fill(itemname)
  737.   if robot.tankLevel() ~= 0 then
  738.     if itemname == "ThermalExpansion:Tesseract" then
  739.       for i=1,robot.tankLevel()/1000 do
  740.         robot.fill()
  741.         defaultUsedFunctions()
  742.       end
  743.     end
  744.   end
  745. end
  746.  
  747. function Extract()
  748.   if robot.space(InventorySize) ~= 64 then
  749.     for i=1,InventorySize do
  750.       CurrentInventorySlot = robot.select(i)
  751.       item = component.inventory_controller.getStackInInternalSlot(i).name
  752.       for l=0,#ExtractItems do
  753.         items = ExtractItems[l]
  754.         if item == items then
  755.           LastInventorySlot = i
  756.           Back(1)
  757.           robot.place()
  758.           for s=2,InventorySize do
  759.             CurrentInventorySlot = robot.select(s)
  760.             robot.drop()
  761.           end
  762.           Fill(item)
  763.           robot.select(1)
  764.           robot.swing()
  765.           robot.select(1)
  766.           MoveForward(1)
  767.           return true
  768.         end
  769.         if l == #ExtractItems then
  770.           return false
  771.         end
  772.       end
  773.     end
  774.   end
  775. end
  776.  
  777. -----
  778. -- TurnToParkingDirection
  779. function TurnToParkingDirection()
  780.   if ParkingDirection ~= CurrentDirection then
  781.     if ParkingDirection < CurrentDirection then
  782.       while ParkingDirection ~= CurrentDirection do
  783.          TurnRight(1)
  784.       end
  785.     elseif ParkingDirection > CurrentDirection then
  786.       while ParkingDirection ~= CurrentDirection do
  787.          TurnLeft(1)
  788.       end
  789.     end
  790.   end
  791. end
  792.  
  793. function TurnToDirection(x)
  794.   if x ~= CurrentDirection then
  795.     if x < CurrentDirection then
  796.       while x ~= CurrentDirection do
  797.          TurnRight(1)
  798.       end
  799.     elseif x > CurrentDirection then
  800.       while x ~= CurrentDirection do
  801.          TurnLeft(1)
  802.       end
  803.     end
  804.   end
  805. end
  806.  
  807. ----------
  808. -- Erkennung in welhe Richtung gerade geguckt wird.
  809. function detectCurrentDirection()
  810.   MoveForward(1)
  811.   --
  812.   if     lastPositionX < currentPositionX then
  813.     CurrentDirection = 2
  814.     return 2
  815.   elseif lastPositionX > currentPositionX then
  816.     CurrentDirection = 4
  817.     return 4
  818.   elseif lastPositionZ < currentPositionZ then
  819.     CurrentDirection = 3
  820.     return 3
  821.   elseif lastPositionZ > currentPositionZ then
  822.     CurrentDirection = 1
  823.     return 1
  824.   end
  825.   --
  826. end
  827. -----
  828. -- Detect Inventory
  829. function DetectInventoryItem(item)
  830.   -- InventorySize = InventorySize (64)
  831.   for i=1,InventorySize do
  832.     robot.select(i)
  833.     if robot.space(i) ~= 64 then
  834.       item_name = component.inventory_controller.getStackInInternalSlot(i).name
  835.       if item_name == item then
  836.         return true
  837.       end
  838.     end
  839.   end
  840. end
  841. if DetectInventoryItem("minecraft:cobblestone") == true then term.clear() print("ERFOLGREICH)") end
  842.  
  843. ----------
  844. function MoveDownUntilStartHeight()
  845.   if pause == true then
  846.     for t=0,pause_time-1 do
  847.       rest = pause_time - t
  848.       term.clear()
  849.       print("Pause: Energie aufladen.")
  850.       print("Noch "..rest.." Minuten.")
  851.       os.sleep(60)
  852.     end
  853.   end
  854.   setcurrentPosition()
  855.   i = currentPositionY
  856.   while i > startPositionY do
  857.     i = i - 1
  858.     MoveDown(1)
  859.   end
  860.   Extract()
  861. end
  862.  
  863. function MoveDownUntilDetect()
  864.   while robot.detectDown() ~= true do
  865.     robot.down()
  866.   end
  867. end
  868.  
  869. function MoveUpUntilNoDetection()
  870.   for i=currentPositionY,MaxTotalHeight do -- MaxTotalHeight oben bei Configuation
  871.     MoveUp(1)
  872.     if lastPositionY == currentPositionY then
  873.       if currentPositionY < MaxHeight then -- MaxHeight oben bei Configuration
  874.         if DetectInventoryItem("minecraft:cobblestone") == true then
  875.           robot.place()
  876.           robot.down()
  877.           robot.place()
  878.           robot.up()
  879.           robot.placeDown()
  880.           if robot.detectDown() ~= true then
  881.             MoveDownUntilStartHeight()
  882.             break
  883.           end
  884.         else
  885.           MoveDownUntilStartHeight()
  886.           break
  887.         end
  888.       else
  889.         MoveDownUntilStartHeight()
  890.         break
  891.       end
  892.     end
  893.   end
  894. end
  895.  
  896. ----------------------------------------------------------------------------------------------
  897. --[[ ErkennungsFunktionen / CONFIG ]]
  898. function isint(n)
  899.   if n == "" then
  900.     print("Fehler!")
  901.     os.sleep(1)
  902.     print("Programm wird abgebrochen.\nDiskette neu einlegen!")
  903.     os.sleep(1)
  904.     os.exit()
  905.   else
  906.     return n == math.floor(n)
  907.   end
  908. end
  909.  
  910. --[[ CONFIG-Fragebogen ]]
  911. -- config_0 == Length
  912. -- config_1 == Width
  913. -- config_2 == [L]inks/[R]echts
  914.  
  915. function l(x)
  916.   config_0 = x
  917. end
  918.  
  919. function w(x)
  920.   config_1 = x
  921. end
  922.  
  923. function d(x)
  924.   config_2 = x
  925. end
  926.  
  927. function config_current_screen(var)
  928.   --Length-Anzeige
  929.   if var == 1 or var == 2 or var == 3 then
  930.     print("Length:       | "..config_0)
  931.   end
  932.  
  933.   --Width-Anzeige
  934.   if var == 2 or var == 3 then
  935.     print("Width:        | "..config_1)
  936.   end
  937.  
  938.   --Direction-Anzeige
  939.   if var == 3 then
  940.     if config_1 ~= "1" then
  941.       print("Direction:    | "..config_2)
  942.     end
  943.   end
  944. end
  945. function config_current_parking_screen(var)
  946.   --X-Anzeige
  947.   if var == 1 or var == 2 or var == 3 or var == 4 then
  948.     print("X:            | "..parkingPositionConfig[0])
  949.   end
  950.  
  951.   --Y-Anzeige
  952.   if var == 2 or var == 3 or var == 4 then
  953.     print("Y:            | "..parkingPositionConfig[1])
  954.   end
  955.  
  956.   --Z-Anzeige
  957.   if var == 3 or var == 4 then
  958.     print("Z:            | "..parkingPositionConfig[2])
  959.   end
  960.  
  961.   -- X+/X-|Z+/Z- | Anzeige
  962.   if var == 4 then
  963.     print("X/Z Richtung: | "..parkingPositionConfig[3])
  964.   end
  965. end
  966.  
  967. function setLength(msg)
  968.     term.clear()
  969.     info()
  970.     io.write("Length: (Standard: "..config_std_0..")"..msg.."\n")
  971.     config_0 = io.read()
  972.     if isint(config_0) == "" then
  973.       config_0 = config_0
  974.     end
  975. end
  976.  
  977. function setWidth(msg)
  978.   term.clear()
  979.   info()
  980.   config_current_screen(1)
  981.   io.write("Width: (Standard: "..config_std_1..")"..msg.."\n")
  982.   config_1 = io.read()
  983.   if isint(config_1) then
  984.     return true
  985.   end
  986. end
  987.  
  988. function setDirection(msg)
  989.   term.clear()
  990.   info()
  991.   config_current_screen(2)
  992.   io.write("Direction: (L/R)"..msg.."\n")
  993.   config_2 = string.upper(io.read())
  994.   if config_2 == "L" or config_2 == "R" then
  995.    
  996.   else
  997.     setDirection(" (Nur 'L' oder 'R' möglich!)")
  998.   end
  999. end
  1000. --[[
  1001.   parkingPositionX
  1002.   parkingPositionY
  1003.   parkingPositionZ
  1004.   parkingPositionConfig[0]
  1005.   parkingPositionConfig[1]
  1006.   parkingPositionConfig[2]
  1007. ]]
  1008. function setParkingCoordinatesX(msg)
  1009.   term.clear()
  1010.   info()
  1011.   config_current_screen(3)
  1012.   print("------------------------------+")
  1013.   config_current_parking_screen(0)
  1014.   io.write("Parkplatz: X-Koordinaten:"..msg.."\n")
  1015.   local X = io.read()
  1016.   parkingPositionConfig[0] = X
  1017.   parkingPositionX = X
  1018.   if isint(parkingPositionConfig[0]) == "" then
  1019.     --
  1020.   end
  1021. end
  1022. function setParkingCoordinatesY(msg)
  1023.   term.clear()
  1024.   info()
  1025.   config_current_screen(3)
  1026.   print("------------------------------+")
  1027.   config_current_parking_screen(1)
  1028.   io.write("Parkplatz: Y-Koordinaten:"..msg.."\n")
  1029.   local Y = io.read()
  1030.   parkingPositionConfig[1] = Y
  1031.   parkingPositionY = Y
  1032.   if isint(parkingPositionConfig[1]) == "" then
  1033.     --
  1034.   end
  1035. end
  1036. function setParkingCoordinatesZ(msg)
  1037.   term.clear()
  1038.   info()
  1039.   config_current_screen(3)
  1040.   print("------------------------------+")
  1041.   config_current_parking_screen(2)
  1042.   io.write("Parkplatz: Z-Koordinaten:"..msg.."\n")
  1043.   local Z = io.read()
  1044.   parkingPositionConfig[2] = Z
  1045.   parkingPositionZ = Z
  1046.   if isint(parkingPositionConfig[2]) == "" then
  1047.     --
  1048.   end
  1049. end
  1050. function setParkingCoordinatesD(msg)
  1051.   term.clear()
  1052.   info()
  1053.   config_current_screen(3)
  1054.   print("------------------------------+")
  1055.   config_current_parking_screen(3)
  1056.   io.write("Parkplatz: X/Z-Richtung:"..msg.."\n")
  1057.   var = string.upper(io.read())
  1058.   parkingPositionConfig[3] = var
  1059.   parkingPositionD = var
  1060.   if     var == "N" then
  1061.     ParkingDirection = 1
  1062.   elseif var == "E" then
  1063.     ParkingDirection = 2
  1064.   elseif var == "S" then
  1065.     ParkingDirection = 3
  1066.   elseif var == "W" then
  1067.     ParkingDirection = 4
  1068.   else
  1069.     setParkingCoordinatesD(" FEHLER!\nN = North/Norden\nE = East/Osten\nS = South/Süden\nW = West/Westen\nNur möglich: N / E / S / W")
  1070.   end
  1071. end
  1072. function setParkingCoordinates()
  1073.   term.clear()
  1074.   info()
  1075.   config_current_screen(3)
  1076.   print("------------------------------+")
  1077.   --
  1078.   setParkingCoordinatesX("( X ("..currentPositionX..") )")
  1079.   setParkingCoordinatesY("( Y ("..currentPositionY..") )")
  1080.   setParkingCoordinatesZ("( Z ("..currentPositionZ..") )")
  1081.   setParkingCoordinatesD("\n\nN = North/Norden\nE = East/Osten\nS = South/Süden\nW = West/Westen")
  1082.   term.clear()
  1083.   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
  1084.   os.sleep(0.5)
  1085. end
  1086.  
  1087. function fragebogen()
  1088.   --Config-Length-FRAGE
  1089.   setLength("")
  1090.  
  1091.   --Config-Width-FRAGE
  1092.   setWidth("")
  1093.  
  1094.   --Config-Direction-FRAGE
  1095.   if config_1 ~= "1" then
  1096.     setDirection("")
  1097.   else
  1098.     d("")
  1099.   end
  1100.  
  1101.   --Config-Ergebnis
  1102.   term.clear()
  1103.   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
  1104.   os.sleep(0.5)
  1105. end
  1106.  
  1107.  
  1108. --[[                             ]]
  1109. --[[ Funktionen: Direction:LEFT  ]]
  1110. --[[                             ]]
  1111. function ExecuteLeft()
  1112.   print("Execute Left")
  1113. end
  1114.  
  1115. --[[                             ]]
  1116. --[[ Funktionen: Direction:RIGHT ]]
  1117. --[[                             ]]
  1118. function ExecuteRight()
  1119.   print("Execute Right")
  1120. end
  1121.  
  1122. --[[                               ]]
  1123. --[[ Funktionen: Direction:FORWARD ]]
  1124. --[[                               ]]
  1125. function ExecuteForward()
  1126.   for i=1,config_0 do
  1127.     if i == 1 then
  1128.       detectCurrentDirection()
  1129.     else
  1130.       MoveForward(1)
  1131.     end
  1132.     MoveUpUntilNoDetection()
  1133.   end
  1134.   state = "parking"
  1135. end
  1136.  
  1137. --[[ DETECT AND CHOOSE DIRECTION ]]
  1138. function detectWorkDirection()
  1139.   if config_2 == "L" then
  1140.     ExecuteLeft() -- LInks ausführen
  1141.   end
  1142.   if config_2 == "R" then
  1143.     ExecuteRight() -- Rechts ausführen
  1144.   end
  1145.   if config_1 == "1" then
  1146.     ExecuteForward() -- Forwärts ausführen
  1147.   end
  1148. end
  1149.  
  1150. ----------------------------------------------------------------------------------------------
  1151.  
  1152.  
  1153. --[[ HAUPTPROGRAM ]]
  1154. function mainInitialisierung()
  1155.   loading("Initialisiere Start Einstellungen\n")
  1156.   checkStartSlots()
  1157.   MoveDownUntilDetect()
  1158.   term.clear()
  1159.   loading("Initialisiere Primäre Komponente\n")
  1160.   runCheckPrimaryComponents()
  1161.   term.clear()
  1162.   loading("Initialisiere Sekundäre Komponente\n")
  1163.   runCheckSecundaryComponents()
  1164.   loading("Floppy Disk\n")
  1165. end
  1166. function mainShowConfigScreen()
  1167.   term.clear()
  1168.   --info()
  1169.   print("------------------------------+")
  1170.   --ShowConfigScreen
  1171.   config_current_screen(3)
  1172.   print("------------------------------+")
  1173.   getstartPosition("Start:   ","")
  1174.   getcurrentPosition("Derzeit: ","")
  1175.   getlastPosition("Zuletzt: ","")
  1176.   if ParkingStatus == true then
  1177.     getparkingPosition("Parkplatz: ","")
  1178.   end
  1179.   print("------------------------------+")
  1180.   show_tank_info()
  1181.   print("------------------------------+")
  1182. end
  1183. function mainShowConfiguredScreen()
  1184.   term.clear()
  1185.   info()
  1186.   --ShowConfigScreen
  1187.   if config_2 == "" then config_current_screen(2) else config_current_screen(3) end
  1188.   print("------------------------------+")
  1189.   getstartPosition("Start:   ","")
  1190.   if ParkingStatus == true then
  1191.     getparkingPosition("Parkplatz: ","")
  1192.   end
  1193.   print("------------------------------+")
  1194.   show_tank_info()
  1195.   print("------------------------------+")
  1196. end
  1197. function mainInit()
  1198.   mainInitialisierung()
  1199.   chunkloaderActivate()
  1200.   --
  1201.   fragebogen()
  1202.   if ParkingStatus == true then
  1203.     setParkingCoordinates()
  1204.   end
  1205.   --l("30000000") w("1") d("")
  1206.   --
  1207.   mainShowConfiguredScreen()
  1208.   os.sleep(0.1)
  1209.   --Drain()
  1210.   function finishQuestion(msg)
  1211.     mainShowConfiguredScreen()
  1212.     io.write("Ist alles korrekt? "..msg..'\n')
  1213.     var = string.upper(io.read())
  1214.     if var == "J" or var == "N" then
  1215.       if var == "J" then
  1216.         state = string.lower("work")
  1217.       elseif var == "N" then
  1218.         state = string.lower("init")
  1219.         mainInit()
  1220.       end
  1221.     else
  1222.       finishQuestion("(Nur (J/N) möglich!)")
  1223.     end
  1224.   end
  1225.   finishQuestion("(J/N)")
  1226. end
  1227.  
  1228. -----
  1229. function mainBackToWork()
  1230.   print("Enter state: 'backtowork'")
  1231. end
  1232.  
  1233. -----
  1234. function mainParking()
  1235.   print("Enter state: 'parking'")
  1236.   mainShowConfiguredScreen()
  1237.   print("FERTIG!")
  1238.   print("Kehre zurück zur Startposition.")
  1239.   robot.turnAround()
  1240.   MoveForwardUntilBlock(config_0)
  1241.   robot.turnAround()
  1242.   defaultUsedFunctions()
  1243. end
  1244.  
  1245. -----
  1246. function mainWork()
  1247.   mainShowConfigScreen()
  1248.   print("Enter state: 'work'")
  1249.   detectWorkDirection()
  1250. end
  1251. -----
  1252.  
  1253. function main()
  1254.   if state == string.lower("init") then
  1255.     mainInit()
  1256.   end
  1257.   if state == string.lower("work") then
  1258.     mainWork()
  1259.   end
  1260.   if state == string.lower("parking") then
  1261.     mainParking()
  1262.   end
  1263.   if state == string.lower("backtowork") then
  1264.     mainBackToWork()
  1265.   end
  1266. end
  1267. main()
  1268.  
  1269.  
  1270. --[[ ROBOT:MOVING --]] -- Kommentare
  1271.  
  1272. -- robot.Up()
  1273. -- robot.down()
  1274. -- robot.forward()
  1275. -- robot.back()
  1276.  
  1277. -- robot.turnRight()
  1278. -- robot.turnLeft()
  1279. -- robot.turnAround()
  1280.  
  1281. -- robot.swing()
  1282. -- robot.swingDown()
  1283. -- robot.swingUp()
  1284.  
  1285. -- robot.use()
  1286. -- robot.useDown()
  1287. -- robot.useUp()
  1288.  
  1289. -- robot.place()
  1290. -- robot.placeDown()
  1291. -- robot.placeUp()
  1292.  
  1293. -- robot.suck()
  1294. -- robot.suckDown()
  1295. -- robot.suckUp()
  1296.  
  1297. -- robot.drop()
  1298. -- robot.dropDown()
  1299. -- robot.dropUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement