Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TODO: add more args to configure
- -- preffered fuel?, height Layers?
- local PROGRAM_NAME = "STRIP_MINE"
- local PROGRAM_VERSION = "v2.0.1"
- -- expected args
- local cycles = 1
- local mineDistance = 96
- local refuelCount = 3
- local argCount = 3 -- #of expected args
- for argIndex=1,#arg,1 do
- if(argIndex>argCount) then
- print("Incorrect number of args")
- print("Defaulting to:")
- break
- end
- if(argIndex==1) then cycles = tonumber(arg[argIndex]) end
- if(argIndex==2) then mineDistance = tonumber(arg[argIndex]) end
- if(argIndex==3) then refuelCount = tonumber(arg[argIndex]) end
- if(argIndex==#arg) then print("Args received:") end
- --if(argIndex>argCount) then print("Discarding unknown arg "..arg[argIndex]) -- could be used but will leave disabled, safer to just use defaults
- end
- if(#arg==0) then
- print("No args")
- print("Defaulting to:")
- end
- print("Cycles= "..cycles..", Mine Distance= "..mineDistance.." blocks"..", fuelConsume#= "..refuelCount)
- print("waiting a few seconds so you can verify the args")
- sleep(2)
- --make a dependencies table with pastebin download links
- local DEPENDENCIES = {
- [1] = {
- ["name"] = "wLibMining",
- ["link"] = "rJjmGPwk",
- ["path"] = "wisher/"
- },
- [2] = {
- ["name"] = "wLibVariables",
- ["link"] = "P1xXXYKC",
- ["path"] = "wisher/"
- }
- }
- -- Ensures all Libraries/Apis are downloaded
- function checkDependencies()
- local libList = {} -- for libs physically located on the robot
- local apiExist = false
- for i, v in ipairs(DEPENDENCIES) do
- local libName = DEPENDENCIES[i]["path"]..DEPENDENCIES[i]["name"]
- libList[i] = shell.resolveProgram(libName) -- attempts to add the filename of dependency[i] to libList to prove it exists
- if(libList[i]==libName) then --if the lib exists then set true so file is not downloaded
- print("Found file: "..DEPENDENCIES[i]["name"])
- apiExist = true
- sleep(0.2) -- for readability
- end
- if(apiExist==false) then -- if the lib doesnt exist, download it by using the link in dependancy[i]
- local libLink = DEPENDENCIES[i]["link"]
- shell.run("pastebin", "get", libLink, libName)
- sleep(0.2) -- for readability
- end -- at this point the file should be downloaded and we SHOULD be able to continue the for loop normally?
- end
- end
- checkDependencies()
- -- Dynamically initializes DEPENDENCIES globally, only if one with the same name doesnt already exist
- for keyLibIndex, valueLibName in ipairs(DEPENDENCIES) do
- local libraryName = DEPENDENCIES[keyLibIndex]["name"]
- local libraryPath = DEPENDENCIES[keyLibIndex]["path"]..DEPENDENCIES[keyLibIndex]["name"]
- if(_G[libraryName]) then
- print("Already Loaded: "..libraryName)
- end
- if(not _G[libraryName]) then
- _G[libraryName] = require(libraryPath)
- print("Loaded: "..libraryName)
- end
- end
- sleep(3) -- for readability
- -- to move forward and dig, iterate this in a for loop to move needed number of times
- -- when coding is more advanced we will use this better
- function forward()
- -- check/ensure atleast 3 slots free to store mined items, stripmine may mine up to 3 blocks per movement
- if (not wLibMining.emptySlots(3)) then
- wLibMining.dropItems()
- end
- wLibMining.detectAndDigStrip()
- turtle.forward()
- fuelLog = fuelLog + 1
- end
- --to return from far end of a strip
- function turnReturnStrip()
- turtle.turnRight()
- forward()
- turtle.turnRight()
- end
- --to begin a new strip, use if there is more than 1 cycle
- function turnNewStrip()
- turtle.turnLeft()
- forward()
- turtle.turnLeft()
- end
- -- Main Function
- function start()
- -- split into halves so robot finished beside where it started for strip mines
- -- bear in mind if more than 1 cycle is present the turtle needs an inventory to deploy
- -- TODO: adjust checkFuel, dropItems to calculate when to do that based on mineDistance
- local fuelThreshold = 80 * refuelCount - 70 -- assumes the smallest fuel source, larger ones shouldnt be problematic
- print("Initiating: " ..PROGRAM_NAME.." "..PROGRAM_VERSION)
- wLibMining.checkFuel(refuelCount, fuelThreshold)
- repeat
- print("1st half of Cycle "..cycles)
- for i=1,mineDistance,1 do
- if((turtle.getFuelLevel()) / (fuelThreshold - 1) == 1) then wLibMining.checkFuel(refuelCount, fuelThreshold) end
- --if(i%47==0) then wLibMining.checkFuel(refuelCount, fuelThreshold) end
- -- if(i%10==0) then wLibMining.dropItems() end -- not needed now as checked on each forward()
- forward()
- end
- print("Halfway through STRIP MINE Cycle")
- print("Turning!")
- turnReturnStrip()
- print("Finished Turning!")
- if((turtle.getFuelLevel()) / (fuelThreshold - 1) == 1) then wLibMining.checkFuel(refuelCount, fuelThreshold) end
- print("2nd half of STRIP MINE Cycle"..cycles)
- for i=1,mineDistance,1 do
- if((turtle.getFuelLevel()) / (fuelThreshold - 1) == 1) then wLibMining.checkFuel(refuelCount, fuelThreshold) end
- -- if(i%47==0) then wLibMining.checkFuel(refuelCount, fuelThreshold) end
- -- if(i%10==0) then wLibMining.dropItems() end -- not needed now as checked on each forward()
- forward()
- if(cycles>1) and (i==mineDistance) then
- wLibMining.placeInventoryLocal()
- if(wLibMining.depositInventory()) then
- wLibMining.exportInventoryMining()
- end
- if(not wLibMining.depositInventory()) then
- cycles = 1
- end
- if(not wLibMining.emptySlots(3)) then cycles = 1 end -- if unable to clear inventory into export too acceptable level then stop
- if(cycles>1) then turnNewStrip() end
- end
- end
- cycles = cycles-1
- until cycles==0
- print("Completed STRIP MINE")
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement