Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RoboLib by Andronio
- local cmp = require("component")
- local comp = require("computer")
- local r = require("robot")
- local rlib = {}
- local path,x,y,z,side,svPath = "",0,0,0,1,false
- function rlib.report(msg)
- print(msg)
- if cmp.isAvailable('tunnel') then
- cmp.tunnel.send(msg)
- end
- end
- function rlib.CL(bool)
- if rlib.cc('chunkloader') then
- cmp.chunkloader.setActive(bool)
- end
- end
- function rlib.fw()
- while r.detect() do
- r.swing()
- end
- if r.forward() then
- if svPath then
- path = path.."F"
- end
- else
- rlib.fw()
- end
- if side == 1 then
- y = y + 1
- elseif side == 2 then
- x = x + 1
- elseif side == 3 then
- y = y - 1
- elseif side == 4 then
- x = x - 1
- else
- while true do
- rlib.report("E1: Unexpected side("..side.."). Stucked at "..x.." "..y.." "..z)
- comp.beep(1000,2)
- os.sleep(13)
- end
- end
- end
- function rlib.bw()
- if not r.back() then
- r.turnAround()
- while r.detect() do
- r.swing()
- end
- r.turnAround()
- rlib.bw()
- end
- if svPath then
- path = path.."B"
- end
- if side == 1 then
- y = y - 1
- elseif side == 2 then
- x = x - 1
- elseif side == 3 then
- y = y + 1
- elseif side == 4 then
- x = x + 1
- else
- while true do
- rlib.report("E1: Unexpected side("..side.."). Stucked at "..x.." "..y.." "..z)
- comp.beep(1000,2)
- os.sleep(13)
- end
- end
- end
- function rlib.l()
- r.turnLeft()
- if side == 1 then
- side = 4
- else
- side = side - 1
- end
- if svPath then
- path = path.."L"
- end
- end
- function rlib.r()
- r.turnRight()
- if side == 4 then
- side = 1
- else
- side = side + 1
- end
- if svPath then
- path = path.."R"
- end
- end
- function rlib.a()
- r.turnAround()
- if side == 4 then
- side = 2
- elseif side == 3 then
- side = 1
- else
- sid= side + 2
- end
- if svPath then
- path = path.."A"
- end
- end
- function rlib.u()
- while r.detectUp() do
- r.swingUp()
- end
- if r.up() then
- if svPath then
- path = path.."U"
- end
- else
- rlib.u()
- end
- z = z + 1
- end
- function rlib.d()
- while r.detectDown() do
- r.swingDown()
- end
- if r.down() then
- if svPath then
- path = path.."D"
- end
- else
- rlib.d()
- end
- z = z - 1
- end
- function rlib.resCoords()
- x,y,z,side=0,0,0,1
- end
- function rlib.resPath()
- path = ""
- end
- function rlib.getCoords()
- return x,y,z,side
- end
- function rlib.savePath(bool)
- svPath = bool
- end
- function rlib.getPath()
- if svPath then
- return path
- else
- return "No path saved"
- end
- end
- function rlib.goBackByPath()
- if svPath then
- svPath = false
- for i=#path,1,-1 do
- local nwint = string.sub(path,i,i)
- if nwint == "F" then
- rlib.bw()
- elseif nwint == "B" then
- rlib.fw()
- elseif nwint == "L" then
- rlib.r()
- elseif nwint == "R" then
- rlib.l()
- elseif nwint == "U" then
- rlib.d()
- elseif nwint == "D" then
- rlib.u()
- elseif nwint == "A" then
- rlib.a()
- else
- while true do
- rlib.report("E1: I stucked at "..x.." "..y.." "..z)
- comp.beep(1000,2)
- os.sleep(13)
- end
- end
- end
- path = ""
- svPath = true
- rlib.report("I got home!")
- else
- while true do
- rlib.report("E1: No path saved. I'm at "..x.." "..y.." "..z)
- comp.beep(1000,2)
- os.sleep(13)
- end
- end
- end
- function rlib.goBackFast()
- svPath = false
- if x < 0 then
- if side == 1 then
- rlib.r()
- elseif side == 3 then
- rlib.l()
- elseif side == 4 then
- rlib.a()
- end
- for i=x,0,1 do
- rlib.fw()
- end
- else
- if side == 1 then
- rlib.l()
- elseif side == 3 then
- rlib.r()
- elseif side == 2 then
- rlib.a()
- end
- for i=x,0,-1 do
- rlib.fw()
- end
- end
- if y < 0 then
- if side == 2 then
- rlib.l()
- elseif side == 3 then
- rlib.a()
- elseif side == 4 then
- rlib.r()
- end
- for i=y,0,1 do
- rlib.fw()
- end
- else
- if side == 1 then
- rlib.a()
- elseif side == 4 then
- rlib.l()
- elseif side == 2 then
- rlib.r()
- end
- for i=y,0,-1 do
- rlib.fw()
- end
- end
- if z < 0 then
- for i=z,0,1 do
- rlib.u()
- end
- else
- for i=z,0,-1 do
- rlib.d()
- end
- end
- if side == 2 then
- rlib.l()
- elseif side == 3 then
- rlib.a()
- elseif side == 4 then
- rlib.r()
- end
- rlib.report("I got home!")
- if path then
- rlib.report("The path was "..path)
- end
- rlib.resCoords()
- end
- function rlib.CCWD(cmpn,loc)
- local type = "N/D"
- local cmpnm = "N/D"
- local status = "N/D"
- local componlist = {
- {"geolyzer","Geolyzer","Геоанализатор"},
- {"keyboard","Keyboard","Клавиатура"},
- {"screen","Screen","Экран"},
- {"chunkloader","Chunkloader","Чанклоадер"},
- {"generator","Generator","Генератор"},
- {"crafting","Crafting Table","Рабочий стол"},
- {"tractor_beam","Tractor Beam","Тянущий луч"},
- {"inventory_controller","Inventory Controller","Контроллер инвентаря"}
- }
- if loc == 'En' then
- if cmpn == 'geolyzer' or cmpn == 'keyboard' or cmpn == 'screen' then
- type = "Component"
- else
- type = "Upgrade"
- end
- elseif loc == 'Ru' then
- if cmpn == 'geolyzer' or cmpn == 'keyboard' or cmpn == 'screen' then
- type = "Компонент"
- else
- type = "Улучшение"
- end
- end
- for i=1,#componlist do
- if cmpn == componlist[i][1] then
- if loc == 'En' then
- cmpnm = componlist[i][2]
- elseif loc == 'Ru' then
- cmpnm = componlist[i][3]
- end
- break
- end
- end
- if rlib.cc(cmpn) then
- if loc == 'En' then
- status = 'Installed'
- elseif loc == 'Ru' then
- status = 'Присутствует'
- end
- else
- if loc == 'En' then
- status = 'None'
- elseif loc == 'Ru' then
- status = 'Отсутствует'
- end
- end
- return type.." -> "..cmpnm..": "..status
- end
- return rlib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement