Prettyprint <3

This commit is contained in:
Dominic Zimmer 2020-07-06 00:51:43 +02:00
parent 85fcb6576d
commit 96dc469e4b

View File

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