Advertisement
Ulthean

digAndExcavate

Jan 12th, 2013
12,489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.94 KB | None | 0 0
  1. -- VALUES FOR THE DIRECTIONS
  2. local up = "up"
  3. local down = "down"
  4. local forward = "forward"
  5. local back  = "back"
  6. local right = "right"
  7. local left = "left"
  8.  
  9. -- ------------------------------------------------------------ --
  10. -- START OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS --
  11. -- ------------------------------------------------------------ --
  12.  
  13. -- LOAD FUNCTIONS FROM THE OTHER FILES
  14. os.loadAPI("api_sharedFunctions")
  15. os.loadAPI("api_turtleExt")
  16. os.loadAPI("api_digTunnels")
  17. os.loadAPI("api_digShafts")
  18. os.loadAPI("api_digOres")
  19.  
  20. -- GET THE CONFIGURATION OF THE PROGRAM
  21. local args={...}
  22. local configuration = api_sharedFunctions.getConfig("config", args)
  23. if configuration == nil then
  24.   return
  25. end
  26.  
  27. -- USED TO KEEP TRACK OF THE CURRENT POSITION
  28. configuration.currentL = 1
  29. configuration.currentT = 1
  30. configuration.currentS = 0
  31.  
  32. -- USED TO KEEP TRACK OF THE NUMBER OF EXCAVATED ORES
  33. configuration.numOres = 0
  34.  
  35. -- CHECK THE MINIMAL FUEL VALUE SPECIFIED BY THE USER
  36. if (configuration.departureFuel < 400) then
  37.   print("Warning: Low fuel value chosen")
  38.   print("Do you wish to proceed? (Y/N)")
  39.   local answer=io.read()
  40.   if not (answer=="Y") then
  41.     return
  42.   end
  43. end
  44.  
  45. -- CHECK THE NUMBER OF BLOCKS PROVIDED BY THE USER
  46. api_sharedFunctions.dropoffAndRestock(configuration, configuration.numIgnoreBlocks, true, true, true)
  47. if not api_digOres.enoughBlocksProvided(configuration) then
  48.   term.clear()
  49.   print("ERROR:")
  50.   print("-------------------------------")
  51.   print("You said you wanted to turtle")
  52.   print("To ignore "..configuration.numIgnoreBlocks.." blocks but didn't")
  53.   print("place them all in the chest")
  54.   print("chest direction="..configuration.ignoreDir)
  55.   print("-------------------------------")
  56.   print("ABORTING")
  57.   print("")
  58.   print("")
  59.   print("")
  60.   print("")
  61.   api_sharedFunctions.dropoff(configuration, configuration.numIgnoreBlocks, true, true)
  62.   return
  63. end
  64. if configuration.singleChest then
  65.   api_sharedFunctions.dropoffAndRestock(configuration, configuration.numIgnoreBlocks, false, false, true)
  66. end
  67.  
  68. -- FOR EVERY LEVEL
  69. for curL = 1 + configuration.skipL, configuration.numL do
  70.   local firstT = 1
  71.   if curL == 1 + configuration.skipL then
  72.     firstT = firstT + configuration.skipT
  73.   end
  74.   -- FOR EVERY TUNNEL
  75.   for curT = firstT, configuration.numT do
  76.     -- DROP THE IGNORE ITEMS
  77.     if not configuration.singleChest or (curL ~= 1 + configuration.skipL) or (curT ~= firstT) then
  78.       api_sharedFunctions.moveToLocation(configuration, curL, curT, 0)
  79.       api_sharedFunctions.dropoffAndRestock(configuration, configuration.numIgnoreBlocks, false, false, true)
  80.     end
  81.     local firstS = 0
  82.     if (curL == 1 + configuration.skipL) and (curT == 1 + configuration.skipT) and (configuration.skipS~=0) then
  83.       firstS = 1 + configuration.skipS
  84.     end
  85.     -- FOR EVERY SHAFT: DIG THE TUNNEL LEADING TO IT
  86.     for curS = firstS, configuration.numS do
  87.       api_sharedFunctions.moveToLocation(configuration, curL, curT, curS)
  88.       api_digTunnels.digSegment(configuration)
  89.       if api_sharedFunctions.needsRestocking(configuration) then
  90.         api_sharedFunctions.dropoffAndRestock(configuration, 0, false, false, false)
  91.       end
  92.     end
  93.     firstS = math.max(firstS, 1)
  94.     -- FOR EVERY SHAFT: DIG IT
  95.     for curS = firstS, configuration.numS do
  96.       api_sharedFunctions.moveToLocation(configuration, curL, curT, curS)
  97.       api_turtleExt.turnTo(left)
  98.       api_digShafts.digShaft(configuration, left)
  99.       if api_sharedFunctions.needsRestocking(configuration) then
  100.         api_turtleExt.turnTo(left)
  101.         api_sharedFunctions.dropoffAndRestock(configuration, 0, false, false, false)
  102.         api_turtleExt.turnTo(right)
  103.       end
  104.       api_digShafts.digShaft(configuration, right)
  105.       api_turtleExt.turnTo(right)
  106.       if api_sharedFunctions.needsRestocking(configuration) then
  107.         api_sharedFunctions.dropoffAndRestock(configuration, 0, false, false, false)
  108.       end
  109.     end
  110.     -- RETRIEVE THE IGNORE ITEMS
  111.     api_sharedFunctions.moveToLocation(configuration, curL, curT, 0)
  112.     api_sharedFunctions.dropoffAndRestock(configuration, configuration.numIgnoreBlocks, true, false, true)
  113.     -- FOR EVERY SHAFT: DIG THE ORES
  114.     for curS = firstS, configuration.numS do
  115.       api_sharedFunctions.moveToLocation(configuration, curL, curT, curS)
  116.       api_turtleExt.turnTo(left)
  117.       api_digOres.excavateShaft(configuration, left)
  118.       api_digOres.excavateShaft(configuration, right)
  119.       api_turtleExt.turnTo(right)
  120.     end
  121.   end
  122. end
  123.  
  124. -- RETURN TO START AND DROPOFF
  125. api_sharedFunctions.moveToLocation(configuration, 1, 1, 0)
  126. api_sharedFunctions.dropoff(configuration, configuration.numIgnoreBlocks, true, true)
  127. print("Execution finished")
  128. print("Number of ores dug: "..configuration.numOres)
  129.  
  130. -- ---------------------------------------------------------- --
  131. -- END OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS --
  132. -- ---------------------------------------------------------- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement