Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------Variables and tables that will be needed later
- local arg1, arg2, arg3 = ...
- local PCID = os.getComputerID()
- local turtleAmount = turtle.getItemCount(1)
- local p
- local k
- local tableTurtlePCIDs = {}
- local deploymentCoords = {}
- -------Just opening up the rednet
- rednet.open("right")
- --------Checks if a number is odd or not
- function odd(number)
- if (number % 2) == 0 then
- return false
- else
- return true
- end
- end
- ------Checks if a number is prime or not
- function prime(n)
- for i = 2, n^(1/2) do
- if (n % i) == 0 then
- return false
- end
- return true
- end
- end
- ------This function uses math to divide the location up by sectors to count how many turtles will be needed for the whole quarry.
- function getSectors (x, y, turtleAmount)
- turtleAmount = tonumber (turtleAmount)
- turtleAmount2 = tonumber (turtleAmount)
- turtleAmount3 = tonumber (turtleAmount)
- x = tonumber (x)
- y = tonumber (y)
- print ("Arguments: " .. x .. ", " .. y .. ", " .. turtleAmount)
- totalArea = x * y
- print ("Total Sector Area: " .. totalArea)
- local l = true
- local w = true
- local j = 2
- local m = 2
- local g = false
- if prime (x) == true and prime (y) == true then
- sectorCount = 1
- length = length
- width = width
- else
- repeat
- if (x % turtleAmount3) == 0 then
- l = false
- else
- turtleAmount3 = turtleAmount3 - 1
- l = true
- end
- sleep (0.5)
- until l == false
- turtlesPerX = turtleAmount3
- repeat
- if (y % turtleAmount2) == 0 then
- w = false
- else
- turtleAmount2 = turtleAmount2 - 1
- w = true
- end
- sleep (0.5)
- until w == false
- turtlesPerY = turtleAmount2
- print ("Debug: x = " .. turtlesPerX)
- print ("Debug: y = " .. turtlesPerY)
- length = x / turtlesPerX
- width = y / turtlesPerY
- areaPerSector = width * length
- sectorCount = totalArea / areaPerSector
- if sectorCount > turtleAmount then
- print ("Too many sectors, attempting to lower sector amount (will use less turtles)")
- repeat
- repeat
- length = length+1
- until x % length == 0
- repeat
- width=width+1
- until y % width == 0
- areaPerSector = width * length
- sectorCount = totalArea / areaPerSector
- print ("getSectors sectorCount Debug: " .. sectorCount)
- turtlesPerX = x / length
- print ("getSectors sectorsPerX Debug: " .. turtlesPerX)
- turtlesPerY = y / width
- print ("getSectors sectorsPerY Debug: " .. turtlesPerY)
- sleep (2)
- print ("getSectors length Debug: " .. length)
- print ("getSectors width Debug: " .. width)
- until sectorCount <= turtleAmount
- end
- end
- return length, width, sectorCount, turtlesPerX, turtlesPerY
- end
- ------Uses basic math to find the coordinates that each turtle will be deployed to
- function getDeploymentCoords (sectorsPerRow, sectorsPerColumn, x, y, length, width, turtleCountNeeded)
- local deploymentTable = {}
- local xCoords = {}
- local sectorsPerRow = tonumber (sectorsPerRow)
- local sectorsPerColumn = tonumber (sectorsPerColumn)
- length2 = length
- local x = x
- local y = y
- local j = 1
- local k = 1
- local l = 1
- local yCoords = {}
- print ("getDeploymentCoords sectorsPerRow Debug: " .. sectorsPerRow)
- print ("getDeploymentCoords sectorsPerColumn Debug: " .. sectorsPerColumn)
- for i=1, tonumber (sectorsPerRow) do
- for i=1, sectorsPerColumn do
- print ("getDeploymentCoords x Debug: " .. length2)
- table.insert (xCoords, length2)
- length2 = length2 + x
- sleep (2)
- end
- table.insert (yCoords, width)
- width = width + y
- print ("getDeploymentCoords y Debug: " .. width)
- length2 = length
- sleep (2)
- end
- for i=1, sectorsPerRow do
- for i=1, sectorsPerColumn do
- table.insert (deploymentTable, xCoords[j])
- sleep (0.1)
- table.insert (deploymentTable, yCoords[k])
- print ("getDeploymentCoords xCoords Debug :" .. xCoords[j])
- print ("getDeploymentCoords yCoords Debug: " .. yCoords[k])
- j = j + 1
- end
- k = k + 1
- end
- return deploymentTable
- end
- -------Function to place turtles
- function placeTurtles()
- local i
- local turtleID = 1
- for i = 1, turtleCountNeeded do
- local q = true
- repeat
- if turtle.place() == true then
- sleep(0.5)
- peripheral.call("front", "turnOn")
- local packet2 = {turtleID, turtleCountNeeded, plrPos, miningDimensions, rowsPerTurtle, deploymentCoords, length, width}
- sleep(2)
- rednet.broadcast(packet2)
- q = false
- else
- q = true
- end
- sleep(2)
- until q == false
- turtleID = turtleID+1
- end
- end
- k, packet, p = rednet.receive()
- PhonePCID = packet[1]
- plrPos = {packet[2], packet[3], packet[4]}
- miningDimensions = {packet[5], packet[6], packet[7], packet[8]}
- length, width, turtleCountNeeded, sectorsPerColumn, sectorsPerRow = getSectors(miningDimensions[1], miningDimensions[3], turtleAmount)
- deploymentCoords = getDeploymentCoords(sectorsPerRow, sectorsPerColumn, length, width, plrPos[1], plrPos[3], turtleCountNeeded)
- print(length)
- print(width)
- print(turtleCountNeeded)
- placeTurtles()
Add Comment
Please, Sign In to add comment