vacnoa

cavar

Mar 4th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. -- IO Test --
  2. dofile("NearEDGE-Functions")
  3.  
  4.  
  5. -- Direction is relative to the starting orientation of the turtle
  6. Dir = 0
  7.  
  8. --  0
  9. -- 3 1
  10. --  2
  11.  
  12. DirNames =
  13. {
  14.     "in +Z",
  15.     "in +X",
  16.     "in -Z",
  17.     "in -X"
  18. }
  19.  
  20.  
  21. -- Location is NOT the absolute location of the turtle.
  22. --   It is relative to the starting position of the turtle
  23. LocX = 0
  24. LocY = 0
  25. LocZ = 0
  26.  
  27.  
  28. function TurnLeft()
  29.     turtle.turnLeft()
  30.     Dir = (Dir-1)%4
  31. end
  32.  
  33. function TurnRight()
  34.     turtle.turnRight()
  35.     Dir = (Dir+1)%4
  36. end
  37.  
  38. function TurnShortest(dir)
  39.  
  40.     if((Dir-1)%4 == dir) then
  41.         TurnLeft()
  42.     else
  43.         TurnRight()
  44.     end
  45. end
  46.  
  47. function UpdateLocZX()
  48.  
  49.     IsX = Dir%2
  50.     isNeg = (Dir > 1)
  51.  
  52.     local Val = 1
  53.  
  54.     if(isNeg) then
  55.         Val = -1
  56.     end
  57.  
  58.     if(IsX ~= 0) then
  59.         LocX = LocX + Val
  60.     else
  61.         LocZ = LocZ + Val
  62.     end
  63.  
  64.  
  65. end
  66.  
  67. function DoDigMove()
  68.     assert(DigMove(), "Could not move " .. DirNames[Dir+1] .. "!")
  69.     UpdateLocZX()
  70. end
  71.  
  72. function DoDigMoveUp()
  73.     assert(DigMoveUp(), "Could not move up!")
  74.     LocY = LocY + 1
  75. end
  76.  
  77. function DoDigMoveDown()
  78.     assert(DigMoveDown(), "Could not move down!")
  79.     LocY = LocY - 1
  80. end
  81.  
  82.  
  83. function TurnToDir(dir)
  84.     while Dir ~= dir do
  85.         TurnShortest(dir)
  86.     end
  87. end
  88.  
  89. function DigMoveToY(y)
  90.  
  91.     local DisY = (y-LocY)
  92.  
  93.     while LocY ~= y do
  94.         if(DisY>0) then
  95.             DoDigMoveUp()
  96.         else
  97.             DoDigMoveDown()
  98.         end
  99.     end
  100. end
  101.  
  102. function DigMoveToX(x)
  103.  
  104.     local DisX = (x-LocX)
  105.     local dir = 3
  106.  
  107.     if(DisX>0) then
  108.         dir = 1
  109.     end
  110.  
  111.     TurnToDir(dir)
  112.  
  113.     while LocX ~= x do
  114.         DoDigMove()
  115.     end
  116. end
  117.  
  118. function DigMoveToZ(z)
  119.  
  120.     local DisZ = (z-LocZ)
  121.     local dir = 2
  122.  
  123.     if(DisZ>0) then
  124.         dir = 0
  125.     end
  126.  
  127.     TurnToDir(dir)
  128.  
  129.     while LocZ ~= z do
  130.         DoDigMove()
  131.     end
  132. end
  133.  
  134.  
  135. function DigMoveTo(x, y, z)
  136.     DigMoveToY(y)
  137.     DigMoveToX(x)
  138.     DigMoveToZ(z)
  139. end
  140.  
  141.  
  142. takeInitialStep = false
  143.  
  144.  
  145. LenX = 3
  146. LenZ = 3
  147. LenY = 3
  148.  
  149. function CalculateFuelCost()
  150.     local _fuelCost = (LenX*LenY*LenZ-1) + (LenX-1)+(LenY-1)+(LenZ-1)
  151.  
  152.     if(takeInitialStep) then
  153.         _fuelCost = _fuelCost+2
  154.     end
  155.      return _fuelCost
  156. end
  157. function deposit()
  158.     for i=1,16 do
  159.     while turtle.drop() == false and turtle.getItemCount() ~= 0 do
  160.         sleep(1)
  161.     end
  162.     turtle.select(i)
  163.     turtle.drop()
  164.     end
  165.     turtle.select(1)
  166.     return true
  167. end
  168. function check()
  169.     if turtle.getItemCount(15) == 0 then
  170.         return false
  171.     else
  172.         return true
  173.     end
  174. end
  175.  
  176. -----------------------------------------------------------------
  177.  
  178. cls()
  179. term.setCursorPos(8,6)
  180. textutils.slowPrint("DigCubeArea ----")
  181. term.setCursorPos(14,7)
  182. textutils.slowPrint("---- By NearEDGE")
  183. sleep(1)
  184.  
  185. cls()
  186. print("DigCubeArea v1.0\n---------------------------------\n")
  187.  
  188. LenZ = ReadNum("Bloques hacia delante a cavar:")
  189.  
  190. cls()
  191. print("DigCubeArea v1.0\n---------------------------------\n")
  192. LenX = ReadNum("filas:")
  193.  
  194.  
  195. cls()
  196. print("DigCubeArea v1.0\n---------------------------------\n")
  197. LenY = ReadNum("alto:")
  198.  
  199. cls()
  200. print("DigCubeArea v1.0\n---------------------------------\n")
  201. takeInitialStep = BooleanQuery("Empieza un bloque adelantado?")
  202.  
  203. cls()
  204. print("DigCubeArea v1.0\n---------------------------------\n")
  205. __HaltOnInterruption = BooleanQuery("Parar al tener un obstaculo?")
  206.  
  207. cls()
  208. print("DigCubeArea v1.0\n---------------------------------\n")
  209.  
  210. print(string.format(" X: %i\n Y: %i\n Z: %i\n\n Take Initial Step: %s\n Halt on Interruption: %s\n", LenX, LenY, LenZ, tostring(takeInitialStep), tostring(__HaltOnInterruption)))
  211. continue = BooleanQuery("Is this correct?")
  212.  
  213. cls()
  214.  
  215. CurrentFuelLevel = turtle.getFuelLevel()
  216.  
  217. if (continue and CurrentFuelLevel~= "unlimited") then
  218.     FuelNeeded = CalculateFuelCost()
  219.  
  220.     if(FuelNeeded > turtle.getFuelLimit()) then
  221.         print("Esta operación requiere demasiado combustible para esta turtle.\nIntentalo con un advanced turtle!\n\nNecesitas combustible: " .. FuelNeeded)
  222.         continue = false
  223.     else
  224.         if(CurrentFuelLevel < FuelNeeded) then
  225.             RecommendedFuel = GetRecommendedFuel(FuelNeeded)
  226.             print("Esta operación gastara mas combustible del que tienes actualmente.\n\n Inserta al menos "..FuelNeeded.." unidades de combustible, luego pulsa enter para continuar.\n  (Approx. "..RecommendedFuel[2].." "..RecommendedFuel[1].." (Recommended))\n")
  227.  
  228.             io.read()
  229.             FuelConsumed = ConsumeFuel()
  230.  
  231.             CurrentFuelLevel = turtle.getFuelLevel()
  232.  
  233.             if(not FuelConsumed or CurrentFuelLevel < FuelNeeded) then
  234.                 print("Not enough fuel. Stopping!\n")
  235.                 continue = false
  236.             end
  237.         end
  238.     end
  239. end
  240.  
  241. -----------------------------------------------------------------
  242.  
  243.  
  244. if(not continue) then
  245.     print("Intentalo otra vez!")
  246.  
  247. else
  248.     cls()
  249.     print("DigCubeArea v1.0\n---------------------------------\n\n Empezando a cavar, suerte ;)!")
  250.  
  251.  
  252.     ModX = 0
  253.     ModZ = 0
  254.  
  255.     if(takeInitialStep) then
  256.         DoDigMove()
  257.         LocZ = 0
  258.     end
  259.  
  260.  
  261.     while LocY ~= LenY do
  262.         while LocX ~= (LenX-1 + ModX) do
  263.             while LocZ ~= (LenZ-1 + ModZ) do
  264.                 DoDigMove()
  265.             end
  266.  
  267.             oldDir = Dir
  268.             if check() then
  269.                 local lx,ly,lz = LocX, LocY, LocZ
  270.                 DigMoveTo(0,0,0)
  271.                 TurnToDir(2)
  272.                 deposit()
  273.                 DigMoveTo(lx,ly,lz)
  274.                 TurnToDir(Dir)
  275.             end
  276.             DirC = ((ModX*(1/(LenX-1)))*-2)+1
  277.  
  278.             while Dir ~= DirC do
  279.                 TurnShortest(DirC)
  280.             end
  281.  
  282.             DoDigMove()
  283.  
  284.             DirC = (oldDir+2)%4
  285.  
  286.             while Dir ~= DirC do
  287.                 TurnShortest(DirC)
  288.             end
  289.  
  290.             ModZ = LocZ*-1
  291.  
  292.         end
  293.  
  294.         while LocZ ~= (LenZ-1 + ModZ) do
  295.             DoDigMove()
  296.         end
  297.  
  298.         oldDir = Dir
  299.         DirC = (oldDir+2)%4
  300.  
  301.         while Dir ~= DirC do
  302.             TurnShortest(DirC)
  303.         end
  304.  
  305.         ModZ = LocZ*-1
  306.         ModX = LocX*-1
  307.  
  308.         if(LocY ~= LenY-1) then
  309.             DoDigMoveUp()
  310.         else
  311.             break
  312.         end
  313.  
  314.     end
  315.  
  316.     if(takeInitialStep) then
  317.         DigMoveTo(0,0,-1)
  318.     else
  319.         DigMoveTo(0,0,0)
  320.     end
  321.  
  322.     cls()
  323.     print("Finished!")
  324. end
Add Comment
Please, Sign In to add comment