Make digging gravel safe. Report fuel values
This commit is contained in:
parent
e077be9e95
commit
7a61b20e63
@ -39,22 +39,25 @@ function ithSpot(i)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- function digTo(x, z)
|
-- move safely into the direction, not hurting other turtles, but freeing the path if needed.
|
||||||
-- print("Digging to ("..tostring(x)..", "..tostring(z)..")")
|
function moveSafe(moveAction, inspectAction, digAction)
|
||||||
-- while z > 0 do
|
while true do
|
||||||
-- turtle.dig()
|
local status, block = inspectAction()
|
||||||
-- turtle.forward()
|
if status then
|
||||||
-- turtle.digUp()
|
if block["name"]:lower():find("turtle") then
|
||||||
-- z = z - 1
|
-- turtle in front of me. lets wait for it to move
|
||||||
-- end
|
sleep(0.6)
|
||||||
-- turtle.turnRight()
|
else
|
||||||
-- while x > 0 do
|
digAction()
|
||||||
-- turtle.dig()
|
end
|
||||||
-- turtle.forward()
|
else
|
||||||
-- turtle.digUp()
|
-- nothing in the way, try to move
|
||||||
-- x = x - 1
|
if moveAction() then
|
||||||
-- end
|
break
|
||||||
-- end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- If the block in front of the turtle is desired, take it.
|
-- If the block in front of the turtle is desired, take it.
|
||||||
function grabOres()
|
function grabOres()
|
||||||
@ -142,43 +145,22 @@ end
|
|||||||
function digTo(x, z)
|
function digTo(x, z)
|
||||||
print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")")
|
print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")")
|
||||||
while z > 0 do
|
while z > 0 do
|
||||||
turtle.dig()
|
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||||
turtle.forward()
|
|
||||||
turtle.digUp()
|
|
||||||
z = z - 1
|
z = z - 1
|
||||||
|
repeat sleep(0.6)
|
||||||
|
until (not turtle.digUp())
|
||||||
end
|
end
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
while x > 0 do
|
while x > 0 do
|
||||||
turtle.dig()
|
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||||
turtle.forward()
|
|
||||||
turtle.digUp()
|
|
||||||
x = x - 1
|
x = x - 1
|
||||||
end
|
repeat sleep(0.6)
|
||||||
end
|
until (not turtle.digUp())
|
||||||
|
|
||||||
-- move safely into the direction, not hurting other turtles, but freeing the path if needed.
|
|
||||||
function moveSafe(moveAction, inspectAction, digAction)
|
|
||||||
while true do
|
|
||||||
local status, block = inspectAction()
|
|
||||||
if status then
|
|
||||||
if block["name"]:lower():find("turtle") then
|
|
||||||
-- turtle in front of me. lets wait for it to move
|
|
||||||
sleep(0.6)
|
|
||||||
else
|
|
||||||
digAction()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- nothing in the way, try to move
|
|
||||||
if moveAction() then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function goToSpawn(x, z)
|
function goToSpawn(x, z)
|
||||||
turtle.digUp()
|
moveSafe(turtle.up, turtle.inspectUp, turtle.digUp)
|
||||||
turtle.up()
|
|
||||||
while z > 0 do
|
while z > 0 do
|
||||||
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||||
z = z - 1
|
z = z - 1
|
||||||
@ -240,7 +222,7 @@ function leaveBarrel(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function reportDuty(id)
|
function reportDuty(id, fuelconsumed)
|
||||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||||
@ -254,6 +236,8 @@ function reportDuty(id)
|
|||||||
moveSafeForward()
|
moveSafeForward()
|
||||||
rednet.open("bottom")
|
rednet.open("bottom")
|
||||||
rednet.broadcast(tostring(id), "jobs")
|
rednet.broadcast(tostring(id), "jobs")
|
||||||
|
sleep(0.6)
|
||||||
|
rednet.broadcast(tostring(fuelconsumed), "fuel")
|
||||||
while true do
|
while true do
|
||||||
sender, message, proto = rednet.receive("jobcomplete")
|
sender, message, proto = rednet.receive("jobcomplete")
|
||||||
if message == "thanks" then
|
if message == "thanks" then
|
||||||
@ -299,18 +283,17 @@ function enqueueTurtle()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function doRefuel()
|
function doRefuel()
|
||||||
|
moveSafeForward()
|
||||||
|
turtle.turnRight()
|
||||||
while turtle.getFuelLevel() < 1500 do
|
while turtle.getFuelLevel() < 1500 do
|
||||||
turtle.suck(4)
|
turtle.suck(4)
|
||||||
selectFuel()
|
selectFuel()
|
||||||
turtle.refuel()
|
turtle.refuel()
|
||||||
end
|
end
|
||||||
|
turtle.turnLeft()
|
||||||
end
|
end
|
||||||
|
|
||||||
function goToJob()
|
function goToJob()
|
||||||
moveSafeForward()
|
|
||||||
turtle.turnRight()
|
|
||||||
doRefuel()
|
|
||||||
turtle.turnLeft()
|
|
||||||
moveSafeForward()
|
moveSafeForward()
|
||||||
moveSafeForward()
|
moveSafeForward()
|
||||||
moveSafeForward()
|
moveSafeForward()
|
||||||
@ -344,8 +327,9 @@ function emptyToBarrel()
|
|||||||
end
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
fuel = turtle.getFuelLevel()
|
|
||||||
thejob = waitForJob()
|
thejob = waitForJob()
|
||||||
|
doRefuel()
|
||||||
|
fuel = turtle.getFuelLevel()
|
||||||
goToJob()
|
goToJob()
|
||||||
x, z = ithSpot(thejob)
|
x, z = ithSpot(thejob)
|
||||||
digTo(x,z)
|
digTo(x,z)
|
||||||
@ -355,8 +339,8 @@ while true do
|
|||||||
goToBarrel(path)
|
goToBarrel(path)
|
||||||
emptyToBarrel()
|
emptyToBarrel()
|
||||||
leaveBarrel(path)
|
leaveBarrel(path)
|
||||||
reportDuty(thejob)
|
|
||||||
enqueueTurtle()
|
|
||||||
fuelconsumed = fuel - turtle.getFuelLevel()
|
fuelconsumed = fuel - turtle.getFuelLevel()
|
||||||
print("Consumed "..tostring(fuelconsumed).." fuel")
|
reportDuty(thejob, fuelconsumed)
|
||||||
|
print("I consumed "..tostring(fuelconsumed).." fuel")
|
||||||
|
enqueueTurtle()
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,12 @@ while true do
|
|||||||
else
|
else
|
||||||
-- numberic job is complete
|
-- numberic job is complete
|
||||||
completejob = tonumber(message)
|
completejob = tonumber(message)
|
||||||
print("Job "..tostring(completejob).." was completed")
|
fuelused = "??"
|
||||||
|
fuelsender, fuelmessage, fuelproto = rednet.receive("fuel")
|
||||||
|
if fuelmessage then
|
||||||
|
fuelused = fuelmessage
|
||||||
|
end
|
||||||
|
print("Job "..tostring(completejob).." was completed, "..fu elused.." fuel was used")
|
||||||
rednet.broadcast("thanks", "jobcomplete")
|
rednet.broadcast("thanks", "jobcomplete")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user