Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tracker = { }
- function Tracker.getDistance(id)
- for i = 1, 10 do
- Message.send(59999, 'getInfo')
- local _, _, msg, distance = Message.waitForMessage('info', 1)
- local fromId = msg.contents.id
- if id == fromId and distance then
- Logger.log('turtle', 'distance: ' .. distance)
- return distance
- end
- end
- end
- local function locate(id, d1, boundingBox)
- local function checkBB(boundingBox)
- if boundingBox then
- local heading = turtle.getHeadingInfo(turtle.point.heading)
- local x = turtle.point.x + heading.xd
- local z = turtle.point.z + heading.zd
- if x < boundingBox.ax or x > boundingBox.bx or
- z < boundingBox.az or z > boundingBox.bz then
- return true
- end
- end
- return false
- end
- if checkBB(boundingBox) then
- turtle.turnAround()
- end
- if d1 == 1 then
- return d1
- end
- turtle.forward()
- local d2 = Tracker.getDistance(id)
- if not d2 then return end
- if d2 == 1 then return d2 end
- if d2 > d1 then
- turtle.turnAround()
- end
- d1 = d2
- while true do
- if checkBB(boundingBox) then
- break
- end
- turtle.forward()
- d2 = Tracker.getDistance(id)
- if not d2 then return end
- if d2 == 1 then return d2 end
- if d2 > d1 then
- turtle.back()
- return d1
- end
- d1 = d2
- end
- return d2
- end
- function Tracker.track(id, d1, nozcheck, boundingBox)
- d1 = locate(id, d1, boundingBox)
- if not d1 then return end
- turtle.turnRight()
- d1 = locate(id, d1, boundingBox)
- if not d1 then return end
- --if math.floor(d1) == d1 then
- d1 = math.floor(d1)
- local y = d1
- if not nozcheck then
- turtle.up()
- d2 = Tracker.getDistance(id)
- if not d2 then return end
- --TL2.down()
- y = -math.floor(d2)
- if d1 < d2 then
- y = math.floor(d2)
- end
- end
- return { x = turtle.point.x, z = turtle.point.y, y = y }
- --end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement