Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --EN:
- --This program uses virtual maps from ScanArea
- --program. It will build exactly what's saved
- --in the map.
- --
- --Download ScanArea from http://pastebin.com/1hFiZ7Ub
- --CZ:
- --Tenhle program pouziva virtualni mapy vytvorene
- --programem ScanArea a stavi podle nich.
- --
- --Stahnete si ScanArea z http://pastebin.com/1hFiZ7Ub
- --
- --Input ------------------------------------------
- --
- local tArgs = { ... }
- if #tArgs ~= 1 and #tArgs ~= 2 then
- print("Usage: BuildArea <map name>")
- return
- end
- if fs.exists(tArgs[1]) == false then
- print("Current file does not exist")
- return
- end
- --Runned by another program?
- local runByProgram = tArgs[2] == "T"
- --Clear screen
- if runByProgram == false then
- term.clear()
- term.setCursorPos(1, 1)
- print("Info: Fuel place only in the last slot")
- print(" Material place anywhere except the last slot")
- print("")
- end
- --
- --Main variables ---------------------------------
- --
- local VirtualMap = {}
- local X
- local Y
- local WeirdFile = false
- local nSelected = 1
- --
- --Methods ----------------------------------------
- --
- local function CheckForAll()
- --material
- local bCheck = true
- while bCheck do
- bCheck = false
- if turtle.getItemCount(nSelected) == 0 then
- nSelected = nSelected + 1
- turtle.select(nSelected)
- bCheck = true
- end
- if nSelected == 16 then
- bCheck = false
- nSelected = 1
- turtle.select(nSelected)
- print("Out of material, fill me Im waiting...")
- while turtle.getItemCount(1) == 0 do
- os.sleep(1)
- end
- print("Thanks!")
- end
- end
- --fuel
- if turtle.getFuelLevel() == 0 then
- turtle.select(16)
- local bFirst = true
- while turtle.refuel(1) == false do
- if bFirst then
- print("Out of fuel, waiting...")
- end
- os.sleep(1)
- bFirst = false
- end
- print("Thanks!")
- turtle.select(nSelected)
- end
- end
- local function BuildLine(index, inverted)
- local x = 1
- while x <= X do
- if inverted then
- if VirtualMap[index][X - (x - 1)] then
- CheckForAll()
- turtle.placeDown()
- end
- else
- if VirtualMap[index][x] then
- CheckForAll()
- turtle.placeDown()
- end
- end
- if x ~= X then
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- x = x + 1
- end
- end
- --
- --Code -------------------------------------------
- --
- --Read file
- file = fs.open(tArgs[1], "r")
- local l = 0
- local ch = 1
- local line = file.readLine()
- if line == nil then
- WeirdFile = true
- end
- while line ~= nil do
- l = l + 1
- VirtualMap[l] = {}
- ch = 1
- while ch <= #line do
- if string.sub(line, ch, ch) == "1" then
- VirtualMap[l][ch] = true
- elseif string.sub(line, ch, ch) == "0" then
- VirtualMap[l][ch] = false
- else
- WeirdFile = true
- end
- ch = ch + 1
- end
- line = file.readLine()
- end
- file.close()
- for n=2, l do
- if #VirtualMap[n] ~= #VirtualMap[1] then
- WeirdFile = true
- end
- end
- if WeirdFile then
- print("This file is weird! Is it really a map?")
- return
- end
- --Get area size
- X = #VirtualMap[1]
- Y = #VirtualMap
- --Ask for continue
- if runByProgram == false then
- local bAgain = true
- while bAgain do
- print("The area is "..tostring(X).."x"..tostring(Y))
- print("Do you want to continue? (y/n) ")
- local input = read()
- if input == "y" then
- bAgain = false
- elseif input == "n" then
- print("Ok, ending...")
- return
- else
- print("Wrong answer!")
- print("")
- end
- end
- end
- --Build
- turtle.select(1)
- local invertedLine = false
- local y = 1
- while y <= Y do
- BuildLine(y, invertedLine)
- if y ~= Y then
- if invertedLine then
- CheckForAll()
- shell.run("/rom/programs/turtle/go left forward left")
- invertedLine = false
- else
- CheckForAll()
- shell.run("/rom/programs/turtle/go right forward right")
- invertedLine = true
- end
- end
- y = y + 1
- end
- --Return
- if invertedLine then
- shell.run("/rom/programs/turtle/go right")
- for n=1, (Y - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go right")
- else
- shell.run("/rom/programs/turtle/go left")
- for n=1, (Y - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go left")
- for n=1, (X - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go left 2")
- end
- if runByProgram == false then
- print("All done!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement