Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- f, b, l, r, u, d
- -- 44, 64, -10
- -- 39, 64, -10
- -- localX 0
- -- localY 5
- -- f f f f l f f f l f f r f f l f f
- -- r f f f f l l r
- -- 0, 4
- -- 0, -4
- -- A +x
- -- l
- -- <-o->
- -- -yl +y
- -- V -x
- -- Calculate f / r from where you stand. It's all relative to your direction. Important that we keep note of each turn.
- function travelLogCalc(log)
- localX = 0
- localY = 0
- localZ = 0
- -- px, py, mx, my
- -- north, east, south, west
- directions = {1, 1, -1, -1}
- dir = 0
- -- Calculate fasted route to travel
- for i = #log, 1, -1 do
- currentDir = (dir % 4) + 1
- move = log[i]
- if move == "f" then
- if currentDir == 1 or currentDir == 3 then
- localX = localX - directions[(currentDir % 4) + 1]
- elseif currentDir == 2 or currentDir == 4 then
- localY = localY - directions[(currentDir % 4) + 1]
- end
- elseif move == "b" then
- if currentDir == 1 or currentDir == 3 then
- localX = localX + directions[(currentDir % 4) + 1]
- elseif currentDir == 2 or currentDir == 4 then
- localY = localY + directions[(currentDir % 4) + 1]
- end
- elseif move == "r" then
- dir = dir + 1
- elseif move == "l" then
- dir = dir - 1
- elseif move == "u" then
- localZ = localZ - 1
- elseif move == "d" then
- localZ = localZ + 1
- end
- end
- return { localX, localY, localZ, dir }
- end
- function travelEngine(args)
- log = {}
- localX = args[1]
- localY = args[2]
- localZ = args[3]
- -- we skip adding one since we already have turned to the right
- lookAtDir = (args[4] % 4) + 1
- turtle.turnRight()
- table.insert(log, "r")
- if localY > 0 then
- for i = 1, localY do
- if turtle.forward() then
- table.insert(log, "f")
- end
- end
- elseif localY < 0 then
- -- invert localY
- localY = -localY
- for i = 1, localY do
- if turtle.back() then
- table.insert(log, "b")
- end
- end
- end
- turtle.turnLeft()
- table.insert(log, "l")
- if localX > 0 then
- for i = 1, localX do
- if turtle.forward() then
- table.insert(log, "f")
- end
- end
- elseif localX < 0 then
- -- invert localX
- localX = -localX
- for i = 1, localX do
- if turtle.back() then
- table.insert(log, "b")
- end
- end
- end
- if localZ > 0 then
- for i = 1, localZ do
- if turtle.up() then
- table.insert(log, "u")
- end
- end
- elseif localZ < 0 then
- localZ = -localZ
- for i = 1, localZ do
- if turtle.down() then
- table.insert(log, "d")
- end
- end
- end
- -- This is a little scuffed
- turtle.turnLeft()
- table.insert(log, "l")
- for i = 1, lookAtDir do
- turtle.turnRight()
- table.insert(log, "r")
- end
- return log
- end
- function createTravelLog()
- log = {}
- for i = 1, 3 do
- if turtle.forward() then
- table.insert(log, "f")
- end
- end
- turtle.turnRight()
- table.insert(log, "r")
- turtle.forward()
- table.insert(log, "f")
- turtle.turnRight()
- table.insert(log, "r")
- for i = 1, 2 do
- if turtle.forward() then
- table.insert(log, "f")
- end
- end
- --[[
- turtle.turnLeft()
- table.insert(log, "l")
- turtle.forward()
- table.insert(log, "f")
- turtle.turnLeft()
- table.insert(log, "l")
- for i = 1, 3 do
- if turtle.forward() then
- table.insert(log, "f")
- end
- end
- --]]
- return log
- end
- -- travelLog = {"f", "f", "f", "f", "f", "f", "f", "r", "f","r", "f", "f", "f", "f", "f", "f", "f", "l", "f","l", "f", "f", "f", "f", "f", "f", "f"}
- travelLog = createTravelLog()
- print(table.concat(travelLog,", "))
- cords = travelLogCalc(travelLog)
- --print(table.concat(cords,", "))
- wayBack = travelEngine(cords)
- cords2 = travelLogCalc(wayBack)
- print(table.concat(wayBack, ", "))
- print(table.concat(cords2, ", "))
- travelEngine(cords2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement