Advertisement
Guest User

baueSchacht

a guest
Jul 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.05 KB | None | 0 0
  1. local tArgs = {...}
  2. local aktSchacht = 1
  3. local aktLaenge = 0
  4. local zaehler = 0
  5. local status = ""
  6. function anzeige()
  7.   shell.run("clear")
  8.   print("Fuel: ", turtle.getFuelLevel())
  9.   print("")
  10.   print("Richtung: ", tArgs[3])
  11.   print("Anzahl Schaechte:", tArgs[2])
  12.   print("Aktueller Schacht:", aktSchacht)
  13.   print("")
  14.   print("Schachtgroesse: ", tArgs[1])
  15.   print("Aktuelle Laenge: ", aktLaenge)
  16.   print("")
  17.   print("")
  18.   print(status)
  19. end
  20.  
  21. function testDig()
  22.   turtle.dig()
  23.   if turtle.detect()==true then
  24.     testDig()
  25.   end
  26. end
  27.  
  28. function fackel()
  29.   if zaehler>= 10 then
  30.     turtle.turnLeft()
  31.     testDig()
  32.     turtle.forward()
  33.     testDig()
  34.     turtle.back()
  35.     turtle.select(1)
  36.     turtle.place()
  37.     turtle.up()
  38.     testDig()
  39.     turtle.forward()
  40.     testDig()
  41.     turtle.back()
  42.     turtle.down()
  43.     turtle.turnRight()
  44.     zaehler = 0
  45.   end
  46. end
  47.  
  48. function grabeSchacht()
  49.   status = "Grabe Schacht..."
  50.   turtle.turnRight()
  51.   turtle.turnRight()
  52.   testDig()
  53.   turtle.up()
  54.   testDig()
  55.   turtle.select(1)
  56.   turtle.place()
  57.   turtle.down()
  58.   turtle.turnRight()
  59.   turtle.turnRight()
  60.   for i=1, tArgs[1] do
  61.     testDig()
  62.     turtle.forward()
  63.     turtle.digUp()
  64.     aktLaenge = aktLaenge+1
  65.     zaehler = zaehler+1
  66.     anzeige()
  67.     fackel()
  68.   end
  69.   shell.run("clear")
  70.   status = "Rueckweg..."
  71.   anzeige()
  72.   for i=1, tArgs[1] do
  73.     turtle.back()
  74.   end
  75.   shell.run("clear")
  76. end
  77. ------
  78. function durchsucheSchacht()
  79.   status = "Suche nach Ressourcen..."
  80.   turtle.forward()
  81.  
  82.   while not turtle.detect() do
  83.     anzeige()
  84.     successUnten, dataUnten = turtle.inspectDown()
  85.     if assert(loadfile("istWertvoll"))(dataUnten["name"])==true then
  86.       turtle.digDown()
  87.     end
  88.    
  89.     turtle.turnLeft()
  90.     successLinks, dataLinks = turtle.inspect()
  91.     if assert(loadfile("istWertvoll"))(dataLinks["name"])==true then
  92.       testDig()
  93.     end
  94.     turtle.turnRight()
  95.    
  96.     turtle.turnRight()
  97.     successRechts, dataRechts = turtle.inspect()
  98.     if assert(loadfile("istWertvoll"))(dataRechts["name"])==true then
  99.       testDig()
  100.     end
  101.     turtle.turnLeft()
  102.    
  103.     turtle.forward()
  104.   end
  105.   turtle.turnLeft()
  106.   turtle.turnLeft()
  107.   turtle.up()
  108.  
  109.   for i=1, tArgs[1] do
  110.     successOben, dataOben = turtle.inspectUp()
  111.     if assert(loadfile("istWertvoll"))(dataOben["name"])==true then
  112.       turtle.digUp()
  113.     end
  114.    
  115.     turtle.turnLeft()
  116.     successObenLinks, dataObenLinks = turtle.inspect()
  117.     if assert(loadfile("istWertvoll"))(dataObenLinks["name"])==true then
  118.       testDig()
  119.     end
  120.     turtle.turnRight()
  121.    
  122.     turtle.turnRight()
  123.     successObenRechts, dataObenRechts = turtle.inspect()
  124.     if assert(loadfile("istWertvoll"))(dataObenRechts["name"])==true then
  125.       testDig()
  126.     end
  127.     turtle.turnLeft()
  128.     turtle.forward()
  129.   end
  130.   turtle.down()
  131.   turtle.turnLeft()
  132.   turtle.turnLeft()
  133. end
  134.  
  135. function naechsterSchacht()
  136.   zaehler = 0
  137.   if tArgs[3] == "l" then
  138.     turtle.turnLeft()
  139.     for i=1,3 do
  140.       testDig()
  141.       turtle.forward()
  142.       turtle.digUp()
  143.     end
  144.     turtle.turnRight()
  145.   elseif tArgs[3] == "r" then
  146.     turtle.turnRight()
  147.     for i=1, 3 do
  148.       testDig()
  149.       turtle.forward()
  150.       turtle.digUp()
  151.     end
  152.     turtle.turnLeft()
  153.   else
  154.     print("Fehlerhafte Richtung!")
  155.   end
  156. end
  157.  
  158. function start()
  159. local anzSchaechte = tonumber(tArgs[2])
  160. local schachtVerbrauch = (tonumber(tArgs[1])*4) + (tonumber(tArgs[1])/5) + 2
  161.   print("Fuel aktuell: ", turtle.getFuelLevel())
  162.   print("Voraussichtlicher Verbrauch: ", anzSchaechte*schachtVerbrauch, "(", schachtVerbrauch," pro Schacht)")
  163.   print("")
  164.   print("Auffuellen, Starten oder Abbrechen?")
  165.   print("('auffuellen', 'start', 'abbruch')")
  166.   local aufforderung = read()
  167.   if aufforderung ~= "auffuellen" and aufforderung ~= "start" and aufforderung ~= "abbruch" then
  168.     print("Falsche Eingabe! Programm abgebrochen.")
  169.     return
  170.   end
  171.   if aufforderung == "auffuellen" then
  172.     turtle.refuel()
  173.   elseif aufforderung == "start" then
  174.     if turtle.getFuelLevel() < schachtVerbrauch then
  175.       print("WARNUNG! Voraussichtlicher Verbrauch höher als Fuel!")
  176.       print("Soll Schacht trotzdem gebaut werden?")
  177.       print("('yes', 'no')")
  178.       local tdmBauen = read()
  179.       if tdmBauen ~= "yes" and tdmBauen ~= "no" then
  180.         print("Falsche Eingabe! Programm abgebrochen.")
  181.         return
  182.       end
  183.       if tdmBauen == "no" then
  184.         shell.run("clear")
  185.         start()
  186.       end
  187.     end
  188.   elseif aufforderung == abbruch then
  189.     print("Programm abgebrochen!")
  190.     return
  191.   end
  192. end
  193. ------
  194. --HAUPTPROGRAMM--
  195. local anzSchaechte = tonumber(tArgs[2])
  196. local schachtVerbrauch = (tonumber(tArgs[1])*4) + (tonumber(tArgs[1])/5) + 2
  197.  
  198. if tArgs[3] ~= "r" and tArgs[3] ~= "l" then
  199.   print("Ungueltige Richtung (Nur l oder r)!")
  200.   return
  201. end
  202.  
  203. start()
  204.  
  205. if anzSchaechte == 1 then
  206.   grabeSchacht()
  207.   durchsucheSchacht()
  208. elseif anzSchaechte > 1 then
  209.   for i=1, anzSchaechte-1 do
  210.     aktSchacht = i
  211.     grabeSchacht()
  212.     durchsucheSchacht()
  213.     naechsterSchacht()
  214.   end
  215.   grabeSchacht()
  216.   durchsucheSchacht()
  217. else
  218.   print("Ungueltige Schachtanzahl!")
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement