Advertisement
Ulthean

digOres

Jan 12th, 2013
12,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 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_digOres")
  15. os.loadAPI("api_sharedFunctions")
  16. os.loadAPI("api_turtleExt")
  17.  
  18. -- GET THE CONFIGURATION OF THE PROGRAM
  19. local args={...}
  20. local configuration = api_sharedFunctions.getConfig("config", args)
  21. if configuration == nil then
  22.   return
  23. end
  24.  
  25. -- USED TO KEEP TRACK OF THE CURRENT POSITION
  26. configuration.currentL = 1
  27. configuration.currentT = 1
  28. configuration.currentS = 0
  29.  
  30. -- USED TO KEEP TRACK OF THE NUMBER OF EXCAVATED ORES
  31. configuration.numOres = 0
  32.  
  33. -- CHECK THE MINIMAL FUEL VALUE SPECIFIED BY THE USER
  34. if (configuration.departureFuel < 400) then
  35.   print("Warning: Low fuel value chosen")
  36.   print("Do you wish to proceed? (Y/N)")
  37.   local answer=io.read()
  38.   if not (answer=="Y") then
  39.     return
  40.   end
  41. end
  42.  
  43. -- CHECK THE NUMBER OF BLOCKS PROVIDED BY THE USER
  44. api_sharedFunctions.dropoffAndRestock(configuration, configuration.numIgnoreBlocks, true, true, true)
  45. if not api_digOres.enoughBlocksProvided(configuration) then
  46.   term.clear()
  47.   print("ERROR:")
  48.   print("-------------------------------")
  49.   print("You said you wanted to turtle")
  50.   print("To ignore "..configuration.numIgnoreBlocks.." blocks but didn't")
  51.   print("place them all in the chest")
  52.   print("chest direction="..configuration.ignoreDir)
  53.   print("-------------------------------")
  54.   print("ABORTING")
  55.   print("")
  56.   print("")
  57.   print("")
  58.   print("")
  59.   api_sharedFunctions.dropoff(configuration, configuration.numIgnoreBlocks, true, true)
  60.   return
  61. end
  62.  
  63. -- FOR EVERY LEVEL
  64. for curL = 1 + configuration.skipL, configuration.numL do
  65.   local firstT = 1
  66.   if curL == 1 + configuration.skipL then
  67.     firstT = firstT + configuration.skipT
  68.   end
  69.   -- FOR EVERY TUNNEL
  70.   for curT = firstT, configuration.numT do
  71.     local firstS = 1
  72.     if (curL == 1 + configuration.skipL) and (curT == 1 + configuration.skipT) and (configuration.skipS~=0) then
  73.       firstS = 1 + configuration.skipS
  74.     end
  75.     -- FOR EVERY SHAFT
  76.     for curS = firstS, configuration.numS do
  77.       api_sharedFunctions.moveToLocation(configuration, curL, curT, curS)
  78.       api_turtleExt.turnTo(left)
  79.       api_digOres.excavateShaft(configuration, left)
  80.       api_digOres.excavateShaft(configuration, right)
  81.       api_turtleExt.turnTo(right)
  82.       if api_sharedFunctions.needsRestocking(configuration) then
  83.         api_sharedFunctions.dropoffAndRestock(configuration, 0, false, false, false)
  84.       end
  85.     end
  86.   end
  87. end
  88.  
  89. -- RETURN TO START AND DROPOFF
  90. api_sharedFunctions.moveToLocation(configuration, 1, 1, 0)
  91. api_sharedFunctions.dropoff(configuration, configuration.numIgnoreBlocks, true, true)
  92. print("Execution finished")
  93. print("Number of ores dug: "..configuration.numOres)
  94.  
  95. -- ---------------------------------------------------------- --
  96. -- END OF THE CODE THAT GETS EXECUTED WHEN THE PROGRAM STARTS --
  97. -- ---------------------------------------------------------- --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement