Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- robot = require("robot")
- c=require("component")
- m=c.modem
- computer = require("computer")
- event = require("event")
- me = c.upgrade_me
- dronaddress = ""
- dron = false
- dronOffset = {}
- rdMat = {}
- port = 3685
- _G.x=_G.x or 0
- _G.y=_G.y or 0
- _G.z=_G.z or 0
- args = {...}
- function inputNum()
- while true do
- local input = io.read()
- if not tonumber(input) == nil then
- print("Nezadali jste číslo.")
- else
- return tonumber(input)
- end
- end
- end
- function sendToMe()
- for i = 1, robot.inventorySize() do
- robot.select(i)
- me.sendItems()
- end
- robot.select(1)
- end
- function checkInv()
- for i=1, robot.inventorySize() do
- if robot.count(i) == 0 then
- return true
- end
- end
- print("V inventáři není již místo.")
- if me~=nill then
- return empty()
- else
- goBack()
- return false
- end
- -- callDron()
- -- for i=1,robot.inventorySize() do
- -- if robot.count(i) == 0 then
- -- return true
- -- end
- -- end
- return false
- end
- function checkTool()
- if not (robot.durability() == nil) then
- local dur = robot.durability() >=0.1
- if not dur then
- print("Odolnost nástroje není dostatečná.")
- return repair()
- end
- return dur
- else
- print("Chybí pracovní nástroj.")
- repair()
- return true
- end
- end
- function checkEnergy()
- local ener = computer.energy()/computer.maxEnergy() >= 0.1
- if not ener then
- print("Nabití baterie je nedostatečné.")
- recharge()
- return checkEnergy()
- end
- return ener
- end
- function recharge()
- lx = x
- ly = y
- lz = z
- goBack()
- cFac(0)
- while(computer.energy()/computer.maxEnergy() < 0.98) do
- os.sleep(10)
- end
- goPos(minx,miny,minz)
- goPos(lx,ly,lz)
- end
- function repair()
- lx = x
- ly = y
- lz = z
- goBack()
- cFac(0)
- io.write("Chcete-li pokračovat, vyměňte nástroj a zadejte C, jinak zadejte cokoliv.")
- c = io.read()
- if(c == "C") then
- goPos(minx,miny,minz)
- goPos(lx,ly,lz)
- else return false
- end
- end
- function empty()
- lx = x
- ly = y
- lz = z
- goBack()
- cFac(0)
- sendToMe()
- goPos(minx,miny,minz)
- goPos(lz,ly,lz)
- end
- function check()
- return checkInv() and checkTool() and checkEnergy()
- end
- function go(len)
- for i = 1, len do
- while robot.detect() do
- if not robot.swing() then
- break
- end
- end
- robot.forward()
- end
- end
- function cFac(face)
- local f = face - facing
- if f<0 then
- f = f + 4
- end
- if f == 1 then
- robot.turnLeft()
- elseif f==2 then
- robot.turnAround()
- elseif f == 3 then
- robot.turnRight()
- end
- facing = face
- end
- function goPos(tx,ty,tz)
- if tx ~= x then
- if tx>x then
- cFac(0)
- go(tx-x)
- elseif tx<x then
- cFac(2)
- go(x-tx)
- end
- x=tx
- end
- if tz~=z then
- if tz>z then
- cFac(3)
- go(tz-z)
- elseif tz<z then
- cFac(1)
- go(z-tz)
- end
- z=tz
- end
- if y~=ty then
- if ty<y then
- for i=1,(y-ty) do
- robot.swingUp()
- robot.up()
- end
- elseif ty>y then
- for i=1,(ty-y) do
- robot.swingDown()
- robot.down()
- end
- end
- y=ty
- end
- end
- function checkVal()
- print("Jsou vámi zadané hodnoty správné? (Y/n)")
- if io.read() == "n" then
- print("Chcete zadat nové hodnoty? (Y/n)")
- if io.read() == "n" then
- return false
- else
- mineCuboid()
- return false
- end
- else
- return true
- end
- end
- function mineCuboid()
- print("Hodnoty zadávejte relativně k současné poloze.")
- print("Zadejte vzdálenost začátku těžby.")
- minx = inputNum()
- print("Zadejte strop těžené oblasti.")
- miny = -inputNum()
- print("Zadejte levou stěnu těžené oblasti.")
- minz = -inputNum()
- print("Zadejte vzdálenost konce těžby.")
- maxx = inputNum()
- print("Zadejte hloubku těžby.")
- maxy = inputNum()
- print("Zadejte pravou stěnu těžené oblasti.")
- maxz = inputNum()
- -- return Cuboid(minx,miny,minz,maxx,maxy,maxz)
- --end
- --function Cuboid(minx,miny,minz,maxx,many,maxz)
- if checkVal() then
- if not check() then
- return false
- end
- for i=miny,maxy do
- goPos(minx,i,minz)
- for j=minz+1,maxz do
- if not check() then
- return false
- end
- if x==minx then
- goPos(maxx,i,j)
- elseif x==maxx then
- goPos(minx,i,j)
- else goBack()
- end
- end
- if x==minx and check() then
- goPos(maxx,y,z)
- end
- end
- goBack()
- sendToMe()
- return true
- else
- return false
- end
- end
- function goBack()
- if x==maxx then
- goPos(x-1,y,z)
- end
- goPos(minx,0,0)
- goPos(0,0,0)
- cFac(0)
- end
- function sendDron(cmd)
- m.send(dronaddress,port,cmd)
- end
- function dronInit()
- m.open(port)
- print("Spusťte drona.")
- local _, _, address = event.pull(60,"modem.message")
- dronaddress = address
- if dronnaddress=="" or dronaddress == nil then
- print("Dron nebyl detekován a nebude s ním tedy komunikováno.")
- return false
- end
- print(dronaddress)
- sendDron("drone = component.proxy(component.list('drone')())")
- print("Kolik bloků je dron vpravo (je-li vlevo použijte znaménko '-')?")
- dronOffset[2] = tonumber(io.read())
- print("Kolik bloků je dron za robotem (le-li před ním použijte znaménko '-')?.")
- dronOffset[0] = tonumber(io.read())
- print("Kolim bloků je dron nad robotem (je-li pod ním použijte znaménko '-')?")
- dronOffset[1] = tonumber(io.read())
- print("Zadejte otočení robota číslem: S=0; J=2; V=1; Z=3.")
- local f = tonumber(io.read())
- for i=0,2 do
- rdMat[i] = {}
- for j=0,2 do
- rdMat[i][j] = 0
- end
- end
- if f == 0 then
- rdMat[0][2] = -1
- rdMat[1][1] = -1
- rdMat[2][0] = -1
- end
- if f == 1 then
- rdMat[0][0] = -1
- rdMat[1][1] = -1
- rdMat[2][2] = 1
- end
- if f == 2 then
- rdMat[0][2] = 1
- rdMat[1][1] = -1
- rdMat[2][0] = 1
- end
- if f == 3 then
- rdMat[0][0] = 1
- rdMat[1][1] = -1
- rdMat[2][2] = -1
- end
- return true
- end
- function transform(rx,ry,rz)
- dx = rx*rdMat[0][0]+ry*rdMat[0][1]+rz*rdMat[0][2]
- dy = rx*rdMat[1][0]+ry*rdMat[1][1]+rz*rdMat[1][2]
- dz = rx*rdMat[2][0]+ry*rdMat[2][1]+rz*rdMat[2][2]
- return dx, dy, dz
- end
- function callDron()
- sendDron("drone.move("..transform(-dronOffset[0],-dronOffset[1]-1,dronOffset[2])..") while drone.getVelocity()>0 do end drone.move("..transform(x,y,z)..") while drone.getVelocity()>0 do end for i=1,drone.inventorySize() do drone.suck(0) end os.sleep(10) drone.move("..transform(-x,-y,-z)..") while drone.getVelocity()>0 do end for i=1,drone.inventorySize() do drone.select(i) drone.drop(0) end")
- os.sleep(60)
- end
- function testDron()
- if dron then
- sendDron("drone.move(0,1,0)")
- end
- end
- function main(args)
- x=0
- y=0
- z=0
- facing = 0
- -- dron = dronInit()
- -- for num,i in ipairs(args) do
- -- if tonumber(i) then
- -- args[num] = tonumber(i)
- -- end
- -- end
- -- if table.getn(args) == 6 then
- -- Cuboid(args[1],args[2],args[3],args[4],args[5],args[6])
- -- if args ~=nil then
- -- Cuboid(args)
- -- else
- mineCuboid()
- -- end
- -- testDron()
- -- recharge()
- end
- main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement