Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Soup by stylishbob
- --Variables
- tArgs = {...}
- local version = 0.2
- local turtleSide = "right"
- local turtleMineDiameter = 3
- local turtleAreaMine = turtleMineDiameter * turtleMineDiameter
- print(turtleAreaMine)
- local maxSize = 500
- local screenX, screenY = term.getSize()
- local startCoords = {x = 0, y = 0, z =0, direction = "north"}
- local coord = {x = startCoords.x, y = startCoords.y, z = startCoords.z, direction = startCoords.direction}
- local turtleCoords = {}
- --Functions
- local smart = {
- dig = function()
- while turtle.detect() == true do
- turtle.dig()
- os.sleep(0.2)
- if turtle.detect() == false then
- break
- end
- end
- end,
- digUp = function()
- while turtle.detectUp() == true do
- turtle.digUp()
- os.sleep(0.2)
- if turtle.detectUp() == false then
- break
- end
- end
- end,
- forward = function(distance)
- if distance == nil then
- distance = 1
- end
- for i = 1, distance do
- while turtle.forward() == false do
- turtle.dig()
- os.sleep(0.2)
- if turtle.forward() == true then
- break
- end
- end
- if direction == "north" then
- coord.y = coord.y + 1
- elseif direction == "east" then
- coord.x = coord.x + 1
- elseif direction == "south" then
- coord.y = coord.y - 1
- elseif direction == "west" then
- coord.x = coord.x - 1
- else
- print("Invalid Direction")
- end
- end
- return coord.x,coord.y
- end,
- turn = function(turn)
- if turn == "left" then
- turtle.turnLeft()
- if coord.direction == "north" then
- coord.direction = "west"
- elseif coord.direction == "east" then
- coord.direction = "north"
- elseif coord.direction == "south" then
- coord.direction = "east"
- elseif coord.direction == "west" then
- coord.direction = "south"
- else
- print("Error: Invalid Direction")
- end
- elseif turn == "right" then
- turtle.turnRight()
- if direction == "north" then
- direction = "east"
- elseif direction == "east" then
- direction = "south"
- elseif direction == "south" then
- direction = "west"
- elseif direction == "west" then
- direction = "north"
- else
- print("Error: Invalid Direction")
- end
- else
- print("Invalid Direction")
- end
- end,
- setDirection = function(strFacing)
- repeat
- self.setDirection()
- until coord.direction == strFacing
- end,
- up = function(strAmount)
- amount = tonumber(strAmount)
- if amount == nil then
- amount = 1
- end
- for i = 1, amount do
- turtle.up()
- end
- end,
- down = function(strAmount)
- amount = tonumber(strAmount)
- if amount == nil then
- amount = 1
- end
- for i = 1, amount do
- turtle.down()
- end
- end,
- goto = function(x, y, z)
- local function alignForward()
- repeat
- self.forward()
- until coord.x == x
- end
- if coord.x > x then
- alignForward()
- elseif coord.x < x then
- alignForward()
- end
- end
- }
- function openModem()
- print("Opening Modem...")
- rednet.open(turtleSide)
- end
- function processNumber(number)
- --Makes number divisible by three.
- if number == nil then
- print("Error: No Value")
- return false
- end
- if number % turtleMineDiameter ~= 0 then
- print("Desired size invalid! Auto-Correcting...")
- repeat
- number = number + 1
- until number % turtleMineDiameter == 0
- end
- return number
- end
- function estimateTime()
- --5 Seconds for 1 layer
- local argTime = tArgs[2]
- local t = tonumber(argTime)
- local time = 5 * argTime
- local min = time / 60
- return round(min,1)
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function waitInput()
- print("Press Any Key to Continue")
- bRead = true
- while(bRead) do
- local sEvent = os.pullEvent("key")
- if(sEvent == "key") then
- break
- end
- end
- end
- function checkStock(item,strNum,strSlot)
- num = tonumber(strNum)
- slot = tonumber(strSlot)
- turtle.select(slot)
- if turtle.getItemCount(slot) < num then
- while turtle.getItemCount(slot) <= num do
- print("Insert "..num.." "..item.." in Slot #"..slot)
- os.sleep(0.4)
- if turtle.getItemCount(slot) >= num then
- shell.run("clear")
- break
- end
- shell.run("clear")
- end
- else
- print("Slot "..slot.." Supply: OK")
- os.sleep(0.6)
- shell.run("clear")
- end
- turtle.select(1)
- end
- function turtleOn(side)
- peripheral.call(side, 'turnOn')
- end
- function tprint (tbl, indent)
- if not indent then indent = 0 end
- for k, v in pairs(tbl) do
- formatting = string.rep(" ", indent) .. k .. ": "
- if type(v) == "table" then
- print(formatting)
- tprint(v, indent+1)
- else
- print(formatting .. v)
- end
- end
- end
- --Scripts
- function deploy(x, y, numTurtle)
- --Calculates the lanes in the quarry job.
- local lanesX = x / turtleMineDiameter
- local lanesY = y / turtleMineDiameter
- print(lanesX.." Lanes of Turtles")
- local origin = {x= 1,y = 1}
- y = y + 1
- x = x + 1
- for i = 1, lanesX do
- local test = y - lanesY * i
- table.insert(turtleCoords,i, test)
- end
- for i = 1, lanesY do
- local test = x - lanesX * i
- table.insert(turtleCoords,i,test)
- end
- tprint(turtleCoords)
- end
- --The Client portion of the program.
- function clientMode()
- print("Started in Client Mode!")
- openModem()
- print("Waiting for command!")
- local senderID, message, distance = rednet.receive()
- end
- function masterMode()
- --Local Variables
- --Simple task variables.
- function checkNumber(entry)
- if tonumber(entry) == nil then
- print("Invalid Entry! Please enter a number!")
- return false
- elseif tonumber(entry) == 0 then
- print("Please enter a number greater than 0")
- return false
- elseif tonumber(entry) > maxSize then
- print("Too Large! Must be under "..maxSize)
- return false
- end
- return true
- end
- print("Started in Master Mode!")
- openModem()
- --Gets desired size of quarry.
- for i = 1,2 do
- while true do
- if i == 1 then
- term.write("Insert Desired Quarry X size: ")
- quarrySizeX = read()
- if checkNumber(quarrySizeX) == true then
- xSize = processNumber(quarrySizeX)
- print("Selected X = "..xSize)
- break
- end
- elseif i == 2 then
- term.write("Insert Desired Quarry Y size: ")
- quarrySizeY = read()
- if checkNumber(quarrySizeY) ~= false then
- ySize = processNumber(quarrySizeY)
- print("Selected Y = "..ySize)
- break
- end
- end
- end
- end
- shell.run("clear")
- print("Quarry Size will be "..xSize.." X "..ySize..".")
- --Calculating things...
- print("Calculating Setup!")
- print(string.rep("=",screenX))
- --Turtle mines 3x3
- quarryArea = xSize * ySize
- print("Area of Quarry:"..quarryArea)
- requiredTurtles = quarryArea / turtleAreaMine
- print("Amount of Turtles required for Job:"..requiredTurtles)
- if tArgs[2] ~= nil then
- print("Estimated Time:"..estimateTime().." Minutes.")
- end
- --Checks whether user wishes to continue or not.
- print(string.rep("=",screenX))
- waitInput()
- layout(quarryArea, xSize, ySize)
- for i = 1, requiredTurtles do
- end
- end
- --Main Program
- shell.run("clear")
- print("You are running:")
- print("Soup v"..version.." Alpha by stylishbob")
- --Mode Selector / Selects the mode to run in
- if tArgs[1] == "client" then
- deploy(9, 9, 9)
- elseif tArgs[1] == "master" then
- masterMode()
- elseif tArgs[1] == "test" then
- smart.setDirection("south")
- else
- print("Invalid Entry! Client or Master Mode!")
- end
Advertisement
Add Comment
Please, Sign In to add comment