Advertisement
MarsP4ste

Raum-Mining

Apr 13th, 2020 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.63 KB | None | 0 0
  1. ---By MarsGame
  2.  
  3. local movesT = 0----Debug for Fuel Count
  4.  
  5.  
  6. ---User Variables
  7. local p = -1
  8. local pos = -1
  9. local a = -1
  10. local b = -1
  11. local c = -1
  12.  
  13.  
  14. ---System Variables
  15. local way = 0
  16. local maxFuel = turtle.getFuelLimit()
  17. if maxFuel == "unlimited" then maxFuel = -1 end
  18. local length = 0
  19. local length2 = 0
  20. local width = 0
  21. local width2 = 0
  22. local height = 0
  23. local totalFuelReq = 0
  24.  
  25.  
  26. ---Functions
  27. function printQuestions() ---Get Dimension and Pos of Turtle
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30.     print("Wo ist die Turtle im Raum?")
  31.     print("Oben Links: 1   Oben Rechts: 2")
  32.     print("Unten Links: 3   Unten Rechts: 4")
  33.     local pGO = 0
  34.     while pGO == 0 do
  35.         term.setCursorPos(1,4)
  36.         term.clearLine()
  37.         write("--) ")
  38.         p = io.read()
  39.         p = p + 0
  40.         if p == 1 or p == 2 or p == 3 or p == 4 then
  41.             pGO = 1
  42.         end
  43.     end
  44.     pos = p
  45.     print("Wie gross soll der Raum sein?")
  46.     local aGo = 0
  47.     while aGo == 0  do
  48.         term.setCursorPos(1,6)
  49.         term.clearLine()
  50.         write("Laenge (Vorne)--) ")
  51.         a = io.read()
  52.         a = a - 1
  53.         if a > 0 then
  54.             aGo = 1
  55.         end
  56.     end
  57.     length = a
  58.     length2 = a
  59.     local bGo = 0
  60.     while bGo == 0  do
  61.         term.setCursorPos(1,7)
  62.         term.clearLine()
  63.         write("Breite (Seite)--) ")
  64.         b = io.read()
  65.         b = b - 0
  66.         if b > 0 then
  67.             bGo = 1
  68.         end
  69.     end
  70.     width = b
  71.     local cGo = 0
  72.     while cGo == 0  do
  73.         term.setCursorPos(1,8)
  74.         term.clearLine()
  75.         write("Hoehe (Oben/Unten)--) ")
  76.         c = io.read()
  77.         c = c - 0
  78.         if c > 0 then
  79.             cGo = 1
  80.         end
  81.     end
  82.     height = c
  83.     way = turtle.getFuelLevel()
  84. end
  85.  
  86.  
  87. function printFuel() ---Print Fuel Screen
  88.     term.setCursorPos(1,1)
  89.     term.clear()
  90.     turtle.select(1)
  91.     if maxFuel ~= -1 then
  92.         totalFuelReq = ((2 * a) * b * c) + (b * c) ---Every move needs 1 Fuel
  93.         if totalFuelReq > way then
  94.             print("Benoetigter Treibstoff: "..totalFuelReq)
  95.             print("Die Turtle hat "..way.." Treibstoff")
  96.             if totalFuelReq <= maxFuel then
  97.                 print("Du kannst fuer diesen Auftrag jetzt Auffuellen, damit er durchlaeuft.")
  98.                 print("Lege dazu Treibstoff in Slot 1 (Oben Links)")
  99.                 print("Treibstoff ist fast alles, was im Ofen benutzt werden kann.")
  100.                 print("Zum Tanken druecke '1'")
  101.                 print("Um jetzt zu starten '3', hier stoppt die Turtle wenn der Treibstoff zu ende geht!")
  102.             else
  103.                 print("Dieser Raum ist zu gross um mit einmal Tanken alles zu schaffen!")
  104.                 print("Du kannst aber den Tank so voll machen wie es geht, damit die Turtle lange läuft.")
  105.                 print("Wenn sie Treibstoff braucht wartet sie bis sie welches bekommt.")
  106.                 print("Zum Tanken lege Treibstoff in Slot 1 (Oben Links)")
  107.                 print("Treibstoff ist fast alles, was im Ofen benutzt werden kann.")
  108.                 print("Zum Tanken druecke '1'")
  109.                 print("Um jetzt zu starten '3'")
  110.             end
  111.             local fuelStop = 0
  112.             while fuelStop == 0 do
  113.                 local event,key = os.pullEvent("key")
  114.                 if key == keys.three then
  115.                     fuelStop = 1
  116.                     term.setCursorPos(1,10)
  117.                     print("Der Raum wird nun freigelegt.")
  118.                     sleep(2)
  119.                 elseif key == keys.one then
  120.                     turtle.refuel()
  121.                     term.setCursorPos(1,2)
  122.                     term.clearLine()
  123.                     print("Die Turtle hat "..way.." Treibstoff")
  124.                 end
  125.             end
  126.         else
  127.             print("Die Turtle hat genut Treibstoff fuer diesen Auftrag.")
  128.             sleep(2)
  129.         end
  130.     else
  131.         print("In den Einstellungen wurde festgesetzt, dass Turtles keinen Treibstoff brauchen.")
  132.         sleep(2)
  133.     end
  134. end
  135.  
  136.  
  137. function ref() ---refuel, if Fuel gets Empty while running
  138.     if maxFuel ~= -1 then
  139.         way = turtle.getFuelLevel()
  140.         local FuelErr = 0
  141.         if way < 10 then
  142.             turtle.select(1)
  143.             while not turtle.refuel(1) do
  144.                 if FuelErr == 0 then
  145.                     FuelErr = 1
  146.                     print("In Slot 1 ist kein Treibstoff (Kohle etc.)")
  147.                 end
  148.                 sleep(2)
  149.             end
  150.             print("Treibstoff nachgetankt.")
  151.         end
  152.     end
  153. end
  154.  
  155.  
  156. function moveForward() ---Go forward/Mine if not possible
  157.     ref()
  158.     while not turtle.forward() do
  159.         turtle.dig()
  160.         turtle.attack()
  161.         sleep(.25)
  162.     end
  163.     movesT = (movesT + 1) ---Debug
  164. end
  165.  
  166.  
  167. function go() ---Dig Room
  168.     ---the height
  169.     while height > 0 do
  170.         height = (height - 1)
  171.        
  172.         ---the width
  173.         while width > 0 do
  174.             width = (width - 1)
  175.            
  176.             ---the length
  177.             while length > 0 do
  178.                 length = (length - 1)
  179.                 moveForward()
  180.             end
  181.    
  182.             turtle.turnRight()
  183.             turtle.turnRight()
  184.             ---the length back
  185.             while length2 > 0 do
  186.                 moveForward()
  187.                 length2 = (length2 - 1)
  188.             end
  189.    
  190.             length2 = a + 0
  191.             length = a + 0
  192.             ---turning for next line
  193.             if not (width <= 0) then
  194.                 if pos == 1 or pos == 3 then
  195.                     turtle.turnLeft()
  196.                     moveForward()
  197.                     turtle.turnLeft()
  198.                 else
  199.                     turtle.turnRight()
  200.                     moveForward()
  201.                     turtle.turnRight()
  202.                 end
  203.            
  204.                 width2 = (width2 + 1)
  205.             end
  206.         end
  207.        
  208.         width = b + 0
  209.        
  210.         if pos == 2 or pos == 4 then
  211.             turtle.turnLeft()
  212.         else
  213.             turtle.turnRight()
  214.         end
  215.        
  216.         while width2 > 0 do
  217.             moveForward()
  218.             width2 = (width2 - 1)
  219.         end
  220.         if not (height <= 0) then
  221.             if pos == 3 or pos == 4 then
  222.                 while not turtle.up() do
  223.                     turtle.digUp()
  224.                     movesT = (movesT + 1) ---Debug
  225.                 end
  226.             else
  227.                 while not turtle.down() do
  228.                     turtle.digDown()
  229.                     movesT = (movesT + 1) ---Debug
  230.                 end
  231.             end
  232.         end
  233.         if pos == 1 or pos == 3 then
  234.             turtle.turnRight()
  235.         else
  236.             turtle.turnLeft()
  237.         end
  238.     end
  239. end
  240.  
  241.  
  242. ---Start Programm
  243. printQuestions()
  244. printFuel()
  245. go()
  246. print("Fertig.")
  247. print("Fuel used:"..movesT)
  248. print("Fuel prediction:"..totalFuelReq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement