Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- maps = require("map")
- local map = maps.loadMap()
- local tileset = maps.loadTiles(true)
- maps.scanner()
- pf = require("path")
- local curPath = {}
- local manualMode = false
- local update = true
- imp = require("impTurtle")
- imp.setBearing()
- local pos = imp.info().position
- local center = {x=tonumber(pos.x),y=tonumber(pos.y),z=tonumber(pos.z)}
- local displayMap = function()
- pos = imp.info().position
- map = maps.loadMap()
- d = maps.draw(map,tileset,9,center.y,center.x,center.z)
- for termX,col in pairs(d) do
- for termY,b in pairs(d[termX]) do
- if b.y == center.y and b.y == pos.y and b.x == pos.x and b.z == pos.z then
- d[termX][termY].name = "Me!"
- term.current().setCursorPos(termX,termY)
- if manualMode then
- term.current().setTextColor(colors.pink)
- if imp.info().bearing == "west" then
- term.current().write("\27")
- elseif imp.info().bearing == "east" then
- term.current().write("\26")
- elseif imp.info().bearing == "north" then
- term.current().write("\24")
- elseif imp.info().bearing == "south" then
- term.current().write("\25")
- end
- else
- term.current().setTextColor(colors.yellow)
- term.current().write("\2")
- end
- term.current().setTextColor(colors.white)
- else
- for i = 1,#curPath do
- if i == 1 then
- curPath[i].colour = colors.green
- elseif i == 2 or i == 3 then
- curPath[i].colour = colors.lime
- elseif i >= 4 and i <= 6 then
- curPath[i].colour = colors.yellow
- elseif i >= 7 and i <= 10 then
- curPath[i].colour = colors.orange
- elseif i >= 11 and i <= 15 then
- curPath[i].colour = colors.red
- elseif i >= 16 and i <= 20 then
- curPath[i].colour = colors.purple
- elseif i >= 21 and i <= 30 then
- curPath[i].colour = colors.magenta
- elseif i >= 31 and i <= 50 then
- curPath[i].colour = colors.pink
- else
- curPath[i].colour = colors.white
- end
- if b.y == center.y and b.y == curPath[i].y and b.x == curPath[i].x and b.z == curPath[i].z then
- term.current().setCursorPos(termX,termY)
- term.current().setTextColor(curPath[i].colour)
- term.current().write(curPath[i].tile)
- term.current().setTextColor(colors.white)
- end
- end
- end
- end
- end
- end
- while true do
- if turtle and turtle.getFuelLevel() < 1 then
- turtle.refuel()
- end
- if update then
- displayMap()
- update = false
- end
- local evt = {os.pullEvent()}
- if evt[1] == "key" or "mouse_click" then update = true end
- if evt[1] == "key" then
- if evt[2] == keys.leftCtrl or evt[2] == keys.rightCtrl then
- manualMode = not manualMode
- if manualMode then path = {} end
- elseif evt[2] == keys.enter then
- for i = 1,#curPath do
- local mvmt = curPath[1].dir
- if mvmt == "w" or mvmt == "n" or mvmt == "e" or mvmt == "s" then
- local face = string.sub(imp.info().bearing,1,1)
- while mvmt ~= face do
- if face == "w" and mvmt == "n" or face == "e" and mvmt == "s" or face == "n" and mvmt == "e" or face == "s" and mvmt == "w" then
- imp.right()
- elseif face == "w" and mvmt == "s" or face == "e" and mvmt == "n" or face == "n" and mvmt == "w" or face == "s" and mvmt == "e" then
- imp.left()
- else
- imp.right()
- end
- face = string.sub(imp.info().bearing,1,1)
- end
- imp.forward()
- elseif mvmt == "u" then
- imp.up()
- elseif mvmt == "d" then
- imp.down()
- end
- pos = imp.info().position
- center = {x=tonumber(pos.x),y=tonumber(pos.y),z=tonumber(pos.z)}
- maps.scanner()
- table.remove(curPath,1)
- displayMap()
- end
- while turtle.inspect() do imp.left() end
- curPath = {}
- elseif evt[2] == keys.leftShift then
- imp.left()
- elseif evt[2] == keys.rightShift then
- imp.right()
- elseif evt[2] == keys.left then
- if manualMode then
- imp.left()
- else
- center.x = center.x - 1
- end
- elseif evt[2] == keys.right then
- if manualMode then
- imp.right()
- else
- center.x = center.x + 1
- end
- elseif evt[2] == keys.up then
- if manualMode then
- imp.forward()
- maps.scanner()
- else
- center.z = center.z - 1
- end
- elseif evt[2] == keys.down then
- if manualMode then
- imp.back()
- maps.scanner()
- else
- center.z = center.z + 1
- end
- elseif evt[2] == keys.pageDown then
- if manualMode then
- imp.down()
- maps.scanner()
- else
- center.y = center.y - 1
- end
- elseif evt[2] == keys.pageUp then
- if manualMode then
- imp.up()
- maps.scanner()
- else
- center.y = center.y + 1
- end
- elseif evt[2] == keys.home then
- imp.goToMarker()
- elseif evt[2] == keys.space then
- pos = imp.info().position
- center = {x=tonumber(pos.x),y=tonumber(pos.y),z=tonumber(pos.z)}
- elseif evt[2] == keys.tab then
- shell.run("clear")
- print("Map Controls:")
- print(" - Delete: Delete Current Map")
- print(" - Arrow Keys: Navigate Map X/Z")
- print(" - Page Up/Down: Navigate Map Level")
- print(" - Spacebar: Center Map on Turtle")
- print(" - Left Click: Get Block Info")
- print(" - Right Click: Pathfind to Block")
- print(" - Insert: Add Location Marker")
- print(" - Home: Return to Marker/Start")
- print(" - Left/Right Shift: Rotate Turtle")
- print("Manual Controls: (Ctrl to Switch Mode)")
- print(" - Arrow Keys: Move Turtle F/B/L/R")
- write(" - Page Up/Down: Move Turtle Up/Down")
- os.pullEvent("key")
- elseif evt[2] == keys.insert then
- imp.setMarker()
- elseif evt[2] == keys.delete then
- shell.run("clear")
- print("This will delete the entire map. \nPress enter to confirm.")
- e = {os.pullEvent("key")}
- if e[2] == keys.enter and fs.exists("//data/map.txt") then
- fs.delete("//data/map.txt")
- map = maps.loadMap()
- imp.clearPath()
- print("Map deleted.")
- elseif fs.exists("//data/map.txt") then
- print("Process terminated.")
- else
- print("No map found.")
- end
- print("\nPress any key to continue.")
- os.pullEvent("key")
- end
- elseif evt[1] == "mouse_click" and evt[2] == 1 then
- if #curPath > 0 then
- curPath = {}
- else
- local x,y = evt[3], evt[4]
- if d[x] and d[x][y] then
- pos = imp.info().position
- shell.run("clear")
- print("Block:", d[x][y].name)
- print("Position:", d[x][y].x, d[x][y].y, d[x][y].z)
- if d[x][y].name ~= "Me!" then
- local pathable = pf.find(pos.x,pos.y,pos.z,d[x][y].x,d[x][y].y,d[x][y].z)
- print("Pathable: "..tostring(pathable[1]))
- end
- print("\nPress any key to continue")
- os.pullEvent("key")
- end
- end
- elseif evt[1] == "mouse_click" and evt[2] == 2 and not manualMode then
- curPath = {}
- pos = imp.info().position
- local x,y = evt[3], evt[4]
- if d[x] and d[x][y] then
- pathing = pf.find(pos.x,pos.y,pos.z,d[x][y].x,d[x][y].y,d[x][y].z)
- if pathing[1] then
- for i = 1,#pathing[2] do
- curPath[i] = {}
- if i == 1 then
- curPath[i].x = pos.x
- curPath[i].y = pos.y
- curPath[i].z = pos.z
- else
- curPath[i].x = curPath[i-1].x
- curPath[i].y = curPath[i-1].y
- curPath[i].z = curPath[i-1].z
- end
- curPath[i].dir = string.sub(pathing[2],i,i)
- if curPath[i].dir == "w" then
- curPath[i].tile = "\27"
- curPath[i].x = curPath[i].x - 1
- elseif curPath[i].dir == "e" then
- curPath[i].tile = "\26"
- curPath[i].x = curPath[i].x + 1
- elseif curPath[i].dir == "n" then
- curPath[i].tile = "\24"
- curPath[i].z = curPath[i].z - 1
- elseif curPath[i].dir == "s" then
- curPath[i].tile = "\25"
- curPath[i].z = curPath[i].z + 1
- elseif curPath[i].dir == "u" then
- curPath[i].tile = "\30"
- curPath[i].y = curPath[i].y + 1
- elseif curPath[i].dir == "d" then
- curPath[i].tile = "\31"
- curPath[i].y = curPath[i].y - 1
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment