Prettyprint <3
This commit is contained in:
parent
85fcb6576d
commit
96dc469e4b
@ -1,4 +1,11 @@
|
|||||||
args = {...}
|
args = {...}
|
||||||
|
status = {
|
||||||
|
name = os.getComputerLabel(),
|
||||||
|
id = os.getComputerID(),
|
||||||
|
fuel = "",
|
||||||
|
state = "init",
|
||||||
|
job = nil
|
||||||
|
}
|
||||||
|
|
||||||
function noop() end
|
function noop() end
|
||||||
|
|
||||||
@ -143,7 +150,7 @@ function digShaft()
|
|||||||
end
|
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
|
||||||
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||||
z = z - 1
|
z = z - 1
|
||||||
@ -304,7 +311,7 @@ function goToJob()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function waitForJob()
|
function waitForJob()
|
||||||
print("Waiting for job...")
|
--print("Waiting for job...")
|
||||||
while true do
|
while true do
|
||||||
status, block = turtle.inspectDown()
|
status, block = turtle.inspectDown()
|
||||||
if status and block["name"] == "computercraft:wired_modem_full" then
|
if status and block["name"] == "computercraft:wired_modem_full" then
|
||||||
@ -320,12 +327,12 @@ function waitForJob()
|
|||||||
sender, message, proto = rednet.receive("newjob", 2)
|
sender, message, proto = rednet.receive("newjob", 2)
|
||||||
if message then
|
if message then
|
||||||
job = tonumber(message)
|
job = tonumber(message)
|
||||||
print("Received job "..tostring(job))
|
--print("Received job "..tostring(job))
|
||||||
return job
|
return job
|
||||||
else
|
else
|
||||||
if not retrying then
|
if not retrying then
|
||||||
retrying = true
|
retrying = true
|
||||||
print("No job received. I will keep retrying.")
|
--print("No job received. I will keep retrying.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -340,22 +347,61 @@ function emptyToBarrel()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function drawStatus()
|
||||||
|
print("Turtle ("..status["id"]..")")
|
||||||
|
print()
|
||||||
|
print(" \""..status["name"].."\"")
|
||||||
|
print()
|
||||||
|
print()
|
||||||
|
if status["job"] then
|
||||||
|
print("Current job: "..status["job"])
|
||||||
|
else
|
||||||
|
print("Current job: ")
|
||||||
|
end
|
||||||
|
print()
|
||||||
|
print("Last job fuel consumption: "..status["fuel"])
|
||||||
|
print()
|
||||||
|
print("Status:")
|
||||||
|
print(" "..status["state"])
|
||||||
|
print()
|
||||||
|
print()
|
||||||
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
status["state"] = "Waiting for job..."
|
||||||
|
drawStatus()
|
||||||
thejob = waitForJob()
|
thejob = waitForJob()
|
||||||
|
status["job"] = thejob
|
||||||
|
status["state"] = "Refueling..."
|
||||||
|
drawStatus()
|
||||||
doRefuel()
|
doRefuel()
|
||||||
fuel = turtle.getFuelLevel()
|
fuel = turtle.getFuelLevel()
|
||||||
|
status["state"] = "Headed to the jobsite..."
|
||||||
|
drawStatus()
|
||||||
goToJob()
|
goToJob()
|
||||||
x, z = ithSpot(thejob)
|
x, z = ithSpot(thejob)
|
||||||
digTo(x,z)
|
digTo(x,z)
|
||||||
|
status["state"] = "Digging the Shaft..."
|
||||||
|
drawStatus()
|
||||||
digShaft()
|
digShaft()
|
||||||
|
status["state"] = "Returning to the station..."
|
||||||
|
drawStatus()
|
||||||
goToSpawn(x, z)
|
goToSpawn(x, z)
|
||||||
path = math.floor(math.random() + 0.5)
|
path = math.floor(math.random() + 0.5)
|
||||||
|
status["state"] = "Unloading Inventory..."
|
||||||
|
drawStatus()
|
||||||
goToBarrel(path)
|
goToBarrel(path)
|
||||||
emptyToBarrel()
|
emptyToBarrel()
|
||||||
leaveBarrel(path)
|
leaveBarrel(path)
|
||||||
fuelconsumed = fuel - turtle.getFuelLevel()
|
fuelconsumed = fuel - turtle.getFuelLevel()
|
||||||
print("I consumed "..tostring(fuelconsumed).." fuel")
|
--print("I consumed "..tostring(fuelconsumed).." fuel")
|
||||||
print("Reporting Duty")
|
--print("Reporting Duty")
|
||||||
|
status["fuel"] = fuelconsumed
|
||||||
|
status["state"] = "Reporting duty..."
|
||||||
|
drawStatus()
|
||||||
reportDuty(thejob, fuelconsumed)
|
reportDuty(thejob, fuelconsumed)
|
||||||
|
status["job"] = nil
|
||||||
|
status["state"] = "Going back in line..."
|
||||||
|
drawStatus()
|
||||||
enqueueTurtle()
|
enqueueTurtle()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user