Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drone = component.proxy(component.list("drone")())
- local FARM_DIRECTION_NS = 0
- local FARM_DIRECTION_EW = -1
- local FARM_WIDTH = 8
- local FARM_HEIGHT = 8
- local function sleep(timeout)
- checkArg(1, timeout, "number", "nil")
- local deadline = computer.uptime() + (timeout or 0)
- repeat
- computer.pullSignal(deadline - computer.uptime())
- until computer.uptime() >= deadline
- end
- local function checkE()
- local en = computer.energy()
- return en
- end
- local function drop()
- drone.drop(2)
- end
- local function dropAll()
- for i=4,2,-1
- do
- drone.select(i)
- drop()
- end
- drone.select(1)
- end
- local function move(x,y,z)
- drone.move(x,y,z)
- travelx = travelx + x
- travely = travely + y
- travelz = travelz + z
- end
- local function swing()
- for i=5,0,-1 do
- drone.swing(i)
- end
- sleep(0.2)
- end
- local function swingHor()
- for i=1,5,1 do
- drone.swing(i)
- end
- sleep(0.2)
- end
- local function suck(x)
- drone.suck(x)
- end
- local function suckAll()
- for i=0,5,1 do
- suck(i)
- end
- end
- local function layer(n)
- for i=3,1,-1 do
- suckAll()
- swingHor()
- move(-1,0,0)
- end
- end
- local function placeD()
- drone.place(0)
- end
- local function plant()
- drone.setStatusText("PLANTING")
- drone.select(1)
- move(-8,1,0)
- sleep(2)
- placeD()
- move(-1,0,0)
- sleep(0.3)
- placeD()
- move(0,0,-1)
- sleep(0.3)
- placeD()
- move(1,0,0)
- sleep(0.3)
- placeD()
- returnHome()
- end
- local function harvest()
- drone.setStatusText("CUTTING")
- move(0,30,0)
- sleep(3)
- move(-7,0,1)
- sleep(2)
- layer(30)
- swingHor()
- move(0,0,-1)
- for i=1,4,1 do
- move(1,0,0)
- swingHor()
- suckAll()
- end
- returnHome()
- dropAll()
- sleep(2)
- end
- local function resetP()
- travelx, travely, travelz = 0,0,0
- end
- function returnHome()
- travelx = travelx * -1
- travely = travely * -1
- travelz = travelz * -1
- sleep(1)
- move(travelx,travely,travelz)
- sleep(2)
- resetP()
- end
- local function getToPosition()
- for i=1,20,1 do
- local somethingInFront = drone.detect(4)
- if somethingInFront then
- -- Move on top of the fence
- sleep(0.5)
- move(0, 0, 1)
- sleep(0.5)
- move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 1)
- sleep(0.5)
- -- Move to the left corner of the farm
- for i=1,20,1 do
- local somethingBelow = drone.detect(0)
- -- Then we went past the fence, go back in
- if not somethingBelow then
- sleep(0.5)
- if FARM_DIRECTION_EW ~= 0 then
- move(0, -2, 0)
- else
- move(-2, 0, 0)
- end
- sleep(0.5)
- move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 1)
- sleep(0.5)
- return
- end
- -- Go left until we find the end
- sleep(0.5)
- if FARM_DIRECTION_EW ~= 0 then
- move(0, 1, 0)
- else
- move(1, 0, 0)
- end
- sleep(0.5)
- end
- end
- sleep(0.5)
- move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 0)
- sleep(0.5)
- end
- returnHome()
- end
- local function checkPlants()
- resetP()
- job = 0
- drone.setStatusText("CHECKING")
- for i=1,20,0 do
- local seedsBelow = drone.compare(0, true)
- drone.select(1)
- if seedsBelow then
- job = 1
- break
- end
- drone.select(2)
- local wheatBelow = drone.compare(0, true)
- if wheatBelow then
- job = 2
- break
- end
- move(FARM_DIRECTION_EW, FARM_DIRECTION_NS, 0)
- end
- returnHome()
- end
- --start
- resetP()
- job = 0
- drone.setStatusText("ROM\nOK.v4.14.")
- sleep(1)
- -- Main loop
- checkPlants()
- drone.setStatusText(tostring(job))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement