Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- robot= require('robot')
- c= require('component')
- g= c.generator
- i= c.inventory_controller
- local cell_fuel= 16
- local MAX= 100
- SOUTH= 0 -- юг +z
- EAST= 3 -- восток +x
- NORTH= 2 -- север -z
- WEST= 1 -- запад -x
- Max_World_Y= 300
- Min_World_Y= 0
- local SEEDCELL= 15
- local NULLCELL= 16
- io.write('Side:')
- local sides= io.read()+0
- io.write('X:')
- local x= io.read()+0
- io.write('Y:')
- local y= io.read()+0
- io.write('Z:')
- local z= io.read()+0
- function fuel()
- robot.select(cell_fuel)
- count_fuel= robot.count()
- g.insert(count_fuel)
- end
- function turnLeft()
- sides= sides-1
- if (sides<0) then sides= 3 end
- robot.turnLeft()
- end
- function turnRight()
- sides= sides+1
- if (sides>3) then sides= 0 end
- robot.turnRight()
- end
- function forward()
- if (robot.detect()) then
- return false
- end
- if (sides == SOUTH) then
- z=z+1
- elseif (sides == EAST) then
- x= x+1
- elseif (sides == NORTH) then
- z= z-1
- elseif(sides == WEST) then
- x= x-1
- end
- robot.forward()
- end
- function up()
- if (y>=Max_World_Y) then
- y= Max_World_Y
- elseif (robot.detectUp() ~= true) then
- y= y+1
- robot.up()
- end
- end
- function down()
- if (y<=Min_World_Y) then
- y= Min_World_Y
- elseif (robot.detectDown() ~= true) then
- y= y-1
- robot.down()
- end
- end
- function seeds()
- while true do
- seeds_list= {}
- for i=1,14 do
- robot.select(i)
- if (robot.compareTo(SEEDCELL)) then
- seeds_list[#seeds_list+1]= i
- end
- end
- if (seeds_list ~= nil) then
- return seeds_list
- else
- print('Need seeds!')
- os.sleep(1)
- end
- end
- end
- function turns(side)
- while true do
- if (side == sides) then
- break
- end
- turnRight()
- end
- end
- function right()
- turnRight()
- robot.swing()
- forward()
- turnRight()
- end
- function left()
- turnLeft()
- robot.swing()
- forward()
- turnLeft()
- end
- function createcell(seedss_list)
- seedss_list= update_seeds(seedss_list)
- local toolcell= seedss_list[1]
- robot.select(toolcell)
- robot.useDown()
- i.equip()
- robot.useDown()
- i.equip()
- end
- function updatecell(seedss_list)
- seedss_list= update_seeds(seedss_list)
- local toolcell= seedss_list[1]
- robot.select(toolcell)
- i.equip()
- robot.swingDown()
- robot.useDown()
- i.equip()
- end
- function gotos(X,Y,Z,side)
- while true do
- if (y < Y) then
- if (robot.detectUp() ~= true) then
- up()
- else
- robot.digUp()
- end
- elseif(y > Y) then
- if(robot.detectDown() ~= true) then
- down()
- else
- robot.digDown()
- end
- elseif(y == Y) then
- break
- end
- end
- while true do
- if (z < Z) then
- turns(0)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (z > Z) then
- turns(2)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (z == Z) then
- break
- end
- end
- while true do
- if (x < X) then
- turns(3)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (x > X) then
- turns(1)
- if (robot.detect() ~= true) then
- forward()
- else
- robot.dig()
- end
- end
- if (x == X) then
- break
- end
- end
- turns(side)
- end
- function update_seeds(seedss_list)
- if (robot.count(seedss_list[1]) <= 1) then
- table.remove(seedss_list,1)
- end
- return seedss_list
- end
- function Allcount(seed1_list)
- count= 0
- for i=1,#seed-list do
- count= count+robot.count(seed1_list[i])
- end
- return count
- end
- function createField(xx,yy)
- local Y= 0
- local stats= 0
- s_l= seeds()
- while Y<=yy do
- local X= 0
- Y= Y+1
- while X<=xx do
- X= X+1
- createcell(s_l)
- if (X ~= xx+1) then
- forward()
- end
- end
- if (stats == 0) then
- right(s_l)
- stats= 1
- elseif (stats == 1) then
- left(s_l)
- stats= 0
- end
- end
- end
- function dropAll(seed1_list)
- for i=3,14 do
- robot.select(i)
- robot.drop(robot.count(i))
- end
- end
- function update_Field(x,y,CHEST_SIDEs)
- local Y= 0
- local stats= 0
- while true do
- s_l= seeds()
- while Y<= y do
- local X= 0
- Y= Y+1
- while X<= x do
- X= X+1
- updatecell(s_l)
- if (X ~= x+1) then
- forward()
- end
- end
- if (stats == 0) then
- right()
- stats= 1
- elseif (stats == 1) then
- left()
- stats= 0
- end
- end
- gotos(0,0,0,CHEST_SIDEs)
- dropAll(s_l)
- turnRight()
- turnRight()
- hour= 3600
- now_time= 0
- while true do
- now_time= now_time+1
- print(now_time)
- os.sleep(1)
- if (now_time >= hour) then
- break
- end
- end
- end
- end
- local startX= x
- local startY= y
- local startZ= z
- local sidess= sides
- local stats= 0
- length_x= 0
- length_y = 0
- fuel()
- while true do
- io.write('Enter length X:')
- length_x= io.read()+0
- io.write('Enter length Y:')
- length_y= io.read()+0
- io.write('Enter chest side')
- CHEST_SIDE= io.read()+0
- if (length_x <= MAX and length_y <=MAX) then break end
- end
- stat= true
- while true do
- print('Enter mode 1 - create Farm 2 - update Farm')
- mode= io.read()+0
- if (mode == 1) then
- print(length_x,' ',length_y)
- createField(length_x,length_y)
- gotos(0,0,0,sidess)
- print('Finish')
- break
- end
- if (mode == 2) then
- update_Field(length_x,length_y,CHEST_SIDE)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement