Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- benchbench (8 8 114) = 768970
- r=require("robot")
- comp = require("component")
- local computer = require("computer")
- if comp.isAvailable("chunkloader") then comp.chunkloader.setActive(true) end
- if not comp.isAvailable("inventory_controller") then
- print("\t Контроллер инвентаря не обнаружен, возможны проблемы и ошибки. Принудительная остановка программы.")
- os.exit()
- end
- if r.durability() ~= nil then
- ppp = 0
- else
- print("\t Инструмент не обнаружен, возможны проблемы и ошибки. Принудительная остановка программы.")
- os.exit()
- end
- inv = comp.inventory_controller
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: zcarier <width> <lenght> <height>" )
- return
- end
- local width = tonumber( tArgs[1] )
- if width < 1 then
- print( "Quary width must be positive" )
- return
- end
- local lenght = tonumber( tArgs[2] )
- if lenght < 1 then
- print( "Quary lenght must be positive" )
- return
- end
- local height = tonumber( tArgs[3] )
- if height < 1 then
- print( "Quary height must be positive" )
- return
- end
- -- инициализация констант
- maxslot=16
- --min = 16, max = 27
- inv_size = r.inventorySize()
- -- направления
- forward = 0
- upward = 1
- downward = 2
- backward = 3
- -- функция перемещения с проверкой на наличие существа или блока по направлению движения
- function moveit(direction)
- if direction == forward then
- while r.detect() do
- r.swing()
- -- os.sleep(0.5)
- end
- while not r.forward() do
- r.swing()
- -- os.sleep(0.5)
- end
- end
- if direction == upward then
- while r.detectUp() do
- r.swingUp()
- -- os.sleep(0.5)
- end
- while not r.up() do
- r.swingUp()
- -- os.sleep(0.5)
- end
- end
- if direction == downward then
- while r.detectDown() do
- r.swingDown()
- -- os.sleep(0.5)
- end
- while not r.down() do
- r.swingDown()
- -- os.sleep(0.5)
- end
- end
- if direction == backward then
- r.turnAround()
- while r.detect() do
- r.swing()
- -- os.sleep(0.5)
- end
- while not r.forward() do
- r.swing()
- -- os.sleep(0.5)
- end
- r.turnAround()
- end
- end
- -- функция добычи с проверкой блока по направлению движения
- function digit(direction)
- if direction == forward then
- while r.detect() do
- r.swing()
- -- os.sleep(0.5)
- end
- end
- if direction == upward then
- while r.detectUp() do
- r.swingUp()
- -- os.sleep(0.5)
- end
- end
- if direction == downward then
- while r.detectDown() do
- r.swingDown()
- -- os.sleep(0.5)
- end
- end
- end
- ----
- -- функция проверки заполнености инвентаря
- function emptycheck()
- local inv_check = false
- for slot = 1, inv_size-3 do
- if r.count(slot) == 0 then inv_check = true end
- end
- return inv_check
- end
- ----
- -- функция разгрузки (позаимствована у artem211 и Doob =)
- function dropit()
- while true do
- if r.detect() then
- if inv.getInventorySize(3) ~= nil then
- for i=1,inv_size-2 do
- if inv.getStackInInternalSlot(i) ~= nil then
- r.select(i)
- if not r.drop() then
- print("Сундук переполнен. Освободите место под складирование.")
- while not r.drop() do
- os.sleep(5)
- end
- end
- end
- end
- r.select(1)
- break
- else
- print("Блок не является сундуком.")
- os.sleep(5)
- end
- else
- print("Установите сундук!")
- os.sleep(5)
- end
- end
- r.select(1)
- end
- ---------------------
- --- Основной цикл ---
- ---------------------
- print ("Excavate quary started...")
- for h=1, height do
- digit(forward)
- moveit(forward)
- for w=1, width do
- for l=1, lenght-2 do
- digit(forward)
- moveit(forward)
- if not emptycheck() or r.durability() < 0.16 or (computer.energy()/computer.maxEnergy()) < 0.16 then
- if w == 1 then
- r.turnAround()
- else
- if w%2 == 0 then r.turnRight() else r.turnLeft() end
- dxw=w-1
- for bw=1, dxw do moveit(forward) end
- r.turnLeft()
- end
- if w%2 == 0 then
- dxl=lenght-l-1
- else
- dxl=l+1
- end
- for bl=1, dxl do moveit(forward) end
- if h ~= 1 then
- dxh=h-1
- for bh=1, dxh do moveit(upward) end
- end
- if not emptycheck() then
- print("...unload...")
- dropit()
- r.select(1)
- end
- if r.durability() < 0.16 then
- print("...charge tool...")
- -- moveit(upward)
- r.turnRight()
- r.select(inv_size-1)
- inv.equip()
- while inv.getStackInInternalSlot(slot).damage > 1 do
- r.drop(3)
- os.sleep(10)
- r.suck(3)
- end
- inv.equip()
- r.select(1)
- r.turnLeft()
- -- moveit(downward)
- end
- if (computer.energy()/computer.maxEnergy()) < 0.16 then
- -- moveit(downward)
- print('...charge...')
- while (computer.energy()/computer.maxEnergy()) < 0.99 do os.sleep(10) end
- -- moveit(upward)
- end
- r.turnAround()
- if h ~= 1 then
- for bbh=1, dxh do moveit(downward) end
- end
- for bbl=1, dxl do moveit(forward) end
- if w ~= 1 then
- r.turnRight()
- for bbw=1, dxw do moveit(forward) end
- if w%2 == 0 then r.turnRight() else r.turnLeft() end
- end
- end
- end
- if w ~= width then
- if w%2 == 0 then r.turnLeft() else r.turnRight() end
- digit(forward)
- moveit(forward)
- if w%2 == 0 then r.turnLeft() else r.turnRight() end
- end
- end
- if width%2 == 0 then
- moveit(forward)
- else
- r.turnAround()
- for l=1, lenght-1 do moveit(forward) end
- end
- r.turnRight()
- for w=1, width-1 do
- digit(forward)
- moveit(forward)
- if not emptycheck() or r.durability() < 0.16 or (computer.energy()/computer.maxEnergy()) < 0.16 then
- r.turnRight()
- moveit(forward)
- r.turnLeft()
- dxw=width-w-1
- for bw=1, dxw do moveit(forward) end
- r.turnLeft()
- moveit(forward)
- if h ~= 1 then
- dxh=h-1
- for bh=1, dxh do moveit(upward) end
- end
- if not emptycheck() then
- print("...unload...")
- dropit()
- r.select(1)
- end
- if r.durability() < 0.16 then
- print("...charge tool...")
- -- moveit(upward)
- r.turnRight()
- r.select(inv_size-1)
- inv.equip()
- while inv.getStackInInternalSlot(slot).damage > 1 do
- r.drop(3)
- os.sleep(10)
- r.suck(3)
- end
- inv.equip()
- r.select(1)
- r.turnLeft()
- -- moveit(downward)
- end
- if (computer.energy()/computer.maxEnergy()) < 0.16 then
- -- moveit(downward)
- print('...charge...')
- while (computer.energy()/computer.maxEnergy()) < 0.99 do os.sleep(10) end
- -- moveit(upward)
- end
- r.turnAround()
- if h ~= 1 then
- for bbh=1, dxh do moveit(downward) end
- end
- moveit(forward)
- r.turnRight()
- for bbw=1, dxw do moveit(forward) end
- r.turnRight()
- moveit(forward)
- r.turnRight()
- end
- end
- if h ~= height then
- r.turnRight()
- digit(downward)
- moveit(downward)
- else
- if h ~= 1 then
- for bh=1, h-1 do moveit(upward) end
- r.turnRight()
- end
- end
- end
- print ("Excavating done.")
- print ("-----------------------------")
- print ("I'm ready. Get me up, papa...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement