local PROTOCOL = "automine" local PROTOCOL_CTRL = "automineCtrl" function Set(list) local set = {} for _, l in ipairs(list) do set[l] = true end return set end function awaitMessage(types, target) while true do local targetId, msg = rednet.receive(PROTOCOL) if types[msg.type] and msg.name == target then return targetId, msg end end end function run(target) local x, y, z = gps.locate() assert(x, "Couldn't run GPS") local to = vector.new(math.floor(x), math.floor(y), math.floor(z)) print(target .. " will recall to " .. to:tostring()) print("Waiting for " .. target .. "...") local targetId, msg = awaitMessage(Set{"iterationStart", "veinStart"}, target) assert(targetId) print("Sending recall request") rednet.send(targetId, { type = "recall", to = to, }, PROTOCOL_CTRL) local _, msg = awaitMessage(Set{"ackRecall"}, target) assert(msg) print("Received confirmation of recall from " .. target ) end if arg[1] then rednet.open("back") run(arg[1]) else print("usage: " .. arg[0] .. " ") end