Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --MasterPC--never break it or you're fucked...
- --variables--
- local worker = {}
- local wtblin = 0 --"workerTableIndex" - for RednetListener()
- local rednetTimeout = 2
- local jobNumber = 0 --for GetJobForTurtle()
- --functions--
- function JobConstructor()
- job = {}
- local i = 0
- local length --this is how many subjobs per job are given
- local ilje = 1 --indexLastJobEnd
- function DoNumberShit(_k)
- --print(_k)
- --print(i)
- if _k == length then ilje = ilje + length end
- i = i + 1
- end
- --JobTurtlePlacer--
- job[i] = "TurtlePlacer"
- i = i + 1
- ilje = 1
- --JobDigFirstTunnelRight
- length = 7-1
- for k = 0,length do
- job[i] = "Digger 2 0 " .. 3*(k)+1 .. " x 48"
- DoNumberShit(k)
- end
- -- --JobDigSecondTunnelRight at y = -1 --
- -- length = 7-1
- -- for k = 0, length do
- -- job[i] = "Digger 4 -1 " .. 3*(k)+1 .. " x 46"
- -- DoNumberShit(k)
- -- end
- -- --[[ --JobDigFirstTunnel Straight at x = 3 --
- -- length = 6
- -- for k = 0, length do
- -- job[i] = "Digger 4 -1 " .. 3*(k)+1 .. " y 49"
- -- DoNumberShit(k)
- -- end ]]
- --JobDigTerrain from (-2, 0, 0) to (50, 50, ~~20)
- length = 50
- for k = -2, 50 do
- for h = 0, 6 do
- job[i] = "Digger " .. k .. " 0 " .. 3*(h)+1 .. " y 50"
- DoNumberShit(k)
- end
- end
- --JobExcavate from (-2, 0, 0) to (50, 50, ~~ground)
- local xLength = 50
- local yLength = 50
- local zLength = computerHeight - 1 --positive if excavating downwards
- local zJobCount = math.floor(zLength/3)
- for x = 0, xLength do
- for z = 0, zJobCount-1 do
- job[i] = "Miner " .. x .. " 0 " .. -(3*z+2) .. " y " .. yLength
- --print(job[i]) sleep(1)
- i = i + 1
- end
- end
- print("Total Jobs to do: " .. i)
- end
- function Split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function SendAndGetResponse(_recID, _message)
- SendMessage(_recID, _message)
- local startedTime = os.clock()
- while (os.clock() - startedTime) <= rednetTimeout do
- local id, msg, dis = rednet.receive(rednetTimeout)
- if id == _recID or _recID == 0 then
- local splitMessage = Split(msg, " ")
- if (splitMessage[1] == "pa") then
- return msg
- end
- end
- end
- return false
- end
- function SendAndGetResponseNoTimeout(_recID, _message)
- sendMessage(_recID ,_message)
- while true do
- local id, msg, dis = rednet.receive(0)
- if id == _recID or _recID == 0 then
- local splitMessage = split(msg, " ")
- if (splitMessage[1] == "pa") then
- return msg
- end
- end
- end
- end
- function SendMessage(_recID, _message)
- rednet.send(_recID, _message)
- end
- function RednetListener()
- while true do
- --print("Ready for RednetInput")
- local id, message, distance = rednet.receive()
- local splitMessage = Split(message, " ")
- if splitMessage[1] == "pa" then
- if splitMessage[2] == "setup" then
- if splitMessage[3] == "locate" then
- rednet.send(id, "pa setup masterHere")
- worker[wtblin] = id
- wtblin = wtblin + 1
- print("Worker" .. wtblin .. " listed")
- print("Has id " .. tonumber(worker[wtblin-1]))
- end
- elseif splitMessage[2] == "job" then
- if splitMessage[3] == "request" then
- local job = GetJobForTurtle()
- print("Turtle " .. id .. " now has job " .. job)
- if SendAndGetResponse(id, "pa job do " .. job) ~= "pa job confirm" then
- jobNumber = jobNumber - 1
- print("JobRequestReceived - but not confirmed!!!")
- end
- end
- end
- end
- end
- end
- function GetJobForTurtle()
- jobNumber = jobNumber + 1
- return job[jobNumber - 1]
- end
- function GetHeightFromPlayer()
- print("Please type the computers actual height (look at minimap)")
- computerHeight = tonumber(read())
- while computerHeight < 1 or computerHeight > 255 do
- print("must be between 1 and 255!")
- computerHeight = tonumber(read())
- end
- print("computerHeight set to " .. computerHeight)
- end
- --welcome message--
- rednet.open("top")
- print("Welcome to Project Alpha!")
- GetHeightFromPlayer()
- JobConstructor()
- RednetListener()
Advertisement
Add Comment
Please, Sign In to add comment