Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot=require("robot")
- local component=require("component")
- local computer=require("computer")
- local ic = component.inventory_controller
- local a = {...}
- local xLength=tonumber(a[1]) or 1024
- local zLength=tonumber(a[2]) or 20
- local zDepth=tonumber(a[3]) or 2
- local dLayer=tonumber(a[4]) or 3
- local nStart=5
- local tDumpster ={
- "minecraft:cobblestone",
- "minecraft:dirt",
- "minecraft:gravel",
- "chisel:granite",
- "chisel:limestone",
- "chisel:andesite",
- "chisel:diorite"
- }
- -- 1 слот - кирка
- local nKir=1
- -- 2 слот - рычаг
- local nRyc=2
- -- 3 слот - зарядник
- local nZar=3
- -- 4 слот - трансивер
- local nTra=4
- local function goForward()
- -- Для прохождения обсидиана, приходится жертвовать быстродействием. При встрече непреодолимых блоков, требуется вернуться назад и закончить работу.
- local k=0
- -- Если произведено 10 попытки пройти, то блок непроходимый. Возвращаемся назад. Если будут ложные срабатывания, то увеличить попытки.
- while not robot.forward() do k=k+1 robot.select(nKir) ic.equip() robot.swing() ic.equip() robot.use() if k>9 then return false end end
- robot.suck()
- return true
- end
- local function goUp()
- while not robot.up() do robot.useUp() robot.swingUp() end
- end
- local function goDown()
- while not robot.down() do robot.select(nKir) ic.equip() robot.swingDown() ic.equip() robot.useDown() end
- end
- local function goBack()
- if not robot.back() then robot.turnAround() goForward() robot.turnAround() end
- end
- local function doPlace()
- if not robot.place() then goForward() goBack() robot.place() end
- end
- local function suckLaser()
- ll=false
- for jj=9,16 do if ic.getStackInSlot(3,jj) ~= nil then if ic.getStackInSlot(3,jj).label=="Mining Laser" then ic.suckFromSlot(3,jj) ll=true end end end
- return ll
- end
- -- Проверка на мусор
- local function dumpster(sNN)
- local log=false
- local i,j=1,#tDumpster
- repeat
- if sNN==tDumpster[i] then log=true end
- i=i+1
- until log or i>j
- return log
- end
- -- Выгрузка инвентаря в указанную сторону. Если нет сундука, то выброс мусора и уплотнение.
- -- Слоты до указанного не трогаются.
- local function drop(nSd, nSt)
- if ic.getInventorySize(nSd) ~= nil then
- for i = nSt, robot.inventorySize() do
- robot.select(i)
- -- while getStackInSlot(nSd,1) ~= nil do os.sleep(0.5) end
- -- ic.dropIntoSlot(nSd,1)
- robot.drop()
- end
- else
- local i,j=nSt, robot.inventorySize()
- while i ~= j do
- robot.select(j)
- local t = ic.getStackInInternalSlot(j)
- if t ~= nil then
- local sN = t.name
- if dumpster(sN) then robot.drop() j=j-1
- else robot.transferTo(i) i=i+1
- end
- else
- j=j-1
- end
- end
- end
- robot.select(nStart)
- end
- local function zaryad()
- goForward()
- -- Устанавливаем трансивер
- robot.select(nTra) doPlace()
- -- Заряжаем лазер или бур
- robot.select(nKir) ic.equip() robot.drop() drop(3,nStart) robot.select(nKir) while not suckLaser() do os.sleep(15) end ic.equip() robot.select(nStart)
- -- Устанавливаем зарядник
- goUp() robot.select(nZar) doPlace() robot.select(nStart)
- -- Устанавливаем рычаг и включаем его
- goUp() robot.select(nRyc) robot.placeDown(3) ic.equip() robot.useDown(3) ic.equip() robot.select(nStart)
- -- Встаем на зарядку
- goForward() while computer.energy()<0.99* computer.maxEnergy() do os.sleep(15) end robot.select(1)
- -- Снимаем
- goBack() goDown() goForward()
- goBack() goDown() goForward()
- goBack() goBack() robot.select(nStart)
- end
- -- Тело программы
- -- Индикатор проходимости
- lL=true
- -- Копаем dLayer тоннелей
- for dL=1,dLayer do
- -- Копаем тоннель высотой zDepth длиной xLength с уступами, чтобы не превысить максимальную высоту полета робота.
- for zD=0,zDepth-1 do
- for x=1,xLength-zD do lL=goForward()
- -- Если блок непроходимый, то запоминаем текущую позицицию Х.
- if not lL then xLength=x break end
- end
- -- Если был непроходимый блок, то завершаем раскопки.
- if not lL then break end
- goDown() robot.turnAround() end
- -- Если был непроходимый блок, то завершаем раскопки и запоминаем количество подъемов.
- if not lL then dLayer=dL break end
- -- Поднимаемся на высоту следующего тоннеля
- for zL=1,zLength+zDepth do goUp() end
- -- Если робот или инструмент разрядились более чем на 50%, то заряжаемся.
- robot.select(1) ic.equip() tL=ic.getStackInInternalSlot(1) ic.equip()
- local robEn=computer.energy()/computer.maxEnergy()
- local lasDm=tL.damage/tL.maxDamage
- print(robEn, lasDm)
- if (robEn<0.5) or (lasDm>0.5) then zaryad() end
- end
- if lL then
- for h=1,(zDepth+zLength)*dLayer do goDown() end
- else
- for h=1,xLength do goBack() end
- for h=1,(zDepth+zLength)*(dLayer-1) do goDown() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement