Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- local miners = {}
- local loaders = {}
- local fuelBosses = {}
- local needFuel = {}
- needFuel[2] = {}
- local next = next
- local powerStations = {}
- local reverseStations = {}
- local tArgs = {...}
- function findTurtles()
- local gotMsg = true
- local id, msg, dist
- rednet.broadcast("checkIn_"..os.getComputerID())
- while gotMsg do
- id,msg,dist = rednet.receive(1)
- if msg == "Miner" then
- print(id..":"..msg)
- miners[#miners+1] = id
- elseif msg == "chunkloader" then
- print(id..":"..msg)
- loaders[#loaders+1] = id
- elseif msg == "fuelBoss" then
- print(id..":"..msg)
- fuelBosses[#fuelBosses+1] = id
- miners[#miners+1] = id
- elseif msg == "powerStation" then
- print(id..":"..msg)
- powerStations[dist] = id
- elseif msg == "Done" then
- else
- print("Done")
- gotMsg = false
- end
- end
- end
- function checkFuel()
- for x,y in pairs(powerStations) do
- rednet.send(y, "checkStationFuel_"..os.getComputerID())
- reverseStations[y] = x
- end
- local gotmsg = true
- while gotmsg do
- local id, msg, dist = rednet.receive(1)
- if msg == "true" then
- needFuel[2][#needFuel[2]+1] = reverseStations[id]
- elseif msg == "Done" then
- else
- gotmsg = false
- end
- end
- if turtle.getFuelLevel() < 600 then
- needFuel[1] = 1
- end
- if needFuel[1] ~= nil or next(needFuel[2]) ~= nil then
- rednet.send(fuelBosses[1], "fuelBoss_"..textutils.serialize(needFuel))
- rednet.receive()
- if needFuel[1] ~= nil then
- turtle.select(3)
- turtle.refuel()
- turtle.select(1)
- end
- if next(needFuel[2]) ~= nil then
- for x,y in pairs(needFuel[2]) do
- rednet.send(powerStations[y], "eatFuel")
- end
- local q = 0
- while q < #needFuel[2] do
- rednet.receive()
- q=q+1
- end
- end
- needFuel = {}
- needFuel[2] ={}
- end
- end
- function place()
- for x,y in pairs(powerStations) do
- rednet.send(y, "placePower")
- end
- local t = 0
- while t < #powerStations do
- local id,msg,dist=rednet.receive()
- t=t+1
- end
- turtle.select(1)
- turtle.place()
- turtle.down()
- turtle.select(2)
- turtle.place()
- turtle.attack()
- end
- function remove()
- for x,y in pairs(powerStations) do
- rednet.send(y, "removePower")
- end
- local t = 0
- while t < #powerStations do
- local id,msg,dist=rednet.receive()
- t=t+1
- end
- turtle.select(2)
- turtle.dig()
- turtle.up()
- turtle.select(1)
- turtle.dig()
- end
- function minersGo()
- for x,y in pairs(miners) do
- if tArgs[2] ~= nil then
- rednet.send(y, "cycle_"..tostring(tArgs[2]))
- else
- rednet.send(y, "cycle")
- end
- end
- place()
- local total = 0
- while total < #miners do
- local id,msg,dist=rednet.receive()
- total = total+1
- end
- remove()
- end
- function moveLoaders()
- for x,y in pairs(loaders) do
- rednet.send(y,"chunkLoad")
- rednet.receive()
- sleep(0.5)
- end
- end
- findTurtles()
- if tArgs[1] == nil then tArgs[1] = 1 end
- for i = 1,tArgs[1] do
- print("Interation: "..tostring(i).." of "..tostring(tArgs[1]))
- minersGo()
- turtle.forward()
- checkFuel()
- moveLoaders()
- end
Advertisement
Add Comment
Please, Sign In to add comment