Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- dir = { ["canalyzer"]=1, ["apiary"]=2, ["analyzer"]=3 }
- nDir = 2
- inv = {}
- rednet.open("right")
- status = "active"
- species1 = {}
- species2 = {}
- types = {}
- target = { [1]="bees.species.common", [2]="bees.species.meadows", [3]="bees.species.marbled"}
- invmod = peripheral.wrap("left")
- fail = false
- for i=1,16 do
- inv[i] = "n"
- end
- end
- function turnLeft()
- if nDir > 1 then
- turtle.turnLeft()
- nDir = nDir - 1
- end
- end
- function turnRight()
- if nDir < 3 then
- turtle.turnRight()
- nDir = nDir + 1
- end
- end
- function turnTo(str)
- while nDir ~= dir[str] do
- if nDir < dir[str] then
- turnRight()
- else
- turnLeft()
- end
- end
- end
- function extract()
- turnTo("apiary")
- out = "empty"
- print("Waiting for apiary.")
- countBees = 0
- while out == "empty" do
- turtle.suck()
- if turtle.getItemCount(1) > 0 then
- for i=1,4 do
- turtle.suck()
- end
- if turtle.getItemCount(2) > 0 then
- out = "b"
- print("Found bees in apiary.")
- else
- out = "c"
- print("Found comb in apiary.")
- end
- end
- end
- end
- function dumbComb()
- for i=1,16 do
- if inv[i] == "c" then
- turtle.select(i)
- turtle.dropDown()
- inv[i] = "n"
- end
- end
- turtle.select(1)
- end
- function sortComb()
- turnTo("canalyzer")
- print("Sorting out the comb.")
- p = peripheral.wrap("front")
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- turtle.drop()
- if p.isBee() then
- inv[i] = "b"
- else
- inv[i] = "c"
- end
- turtle.suck()
- end
- end
- dumbComb()
- turtle.select(1)
- end
- function countItems()
- numbees = 0
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- numbees = numbees + 1
- end
- end
- end
- function countStacks()
- stacks = {}
- for i=1,16 do
- stacks[i] = turtle.getItemCount(i)
- end
- end
- function findBestDrone()
- bestScore = 0
- bestDrone = 0
- countItems()
- for i=1,numbees do
- score = 0
- if types[i] == "drone" then
- if species1[i] == target[1] then
- score = score + 2
- elseif species1[i] == target[2] or species1[i] == target[3] then
- score = score + 1
- end
- if species2[i] == target[1] then
- score = score + 2
- elseif species2[i] == target[2] or species2[i] == target[3] then
- score = score + 1
- end
- if score > bestScore then
- bestSpecies = string.sub(species1[i],14,#species1[i]).." - "..string.sub(species2[i],14,#species2[i])
- bestScore = score
- bestDrone = i
- end
- end
- end
- print("Found best drone in slot "..bestDrone..":")
- print(bestSpecies)
- end
- function checkPrincess()
- countItems()
- for i=1,numbees do
- if types[i] == "princess" then
- if species1[i] == target[1] and species2[i] == target[1] then
- return true
- else
- return false
- end
- end
- end
- fail = true
- end
- function analyzeBees()
- turnTo("analyzer")
- print("Analyzing bees.")
- countItems()
- countStacks()
- countBees = 0
- for i=1,16 do
- if inv[i] == "b" then
- turtle.select(i)
- if turtle.drop() then countBees = countBees + 1 end
- end
- end
- turtle.select(1)
- for i=1,16 do
- if inv[i] == "b" then
- os.sleep(26)
- turtle.select(i)
- invmod.suckSneaky(0,stacks[i])
- end
- end
- turnTo("canalyzer")
- p = peripheral.wrap("front")
- countItems()
- species1 = {}
- species2 = {}
- types = {}
- for i=1,numbees do
- turtle.select(i)
- turtle.drop()
- data = p.analyze()
- species1[i] = data["speciesPrimary"]
- species2[i] = data["speciesSecondary"]
- types[i] = data["type"]
- turtle.suck()
- end
- end
- function dropExtra()
- print("Dropping extra drones.")
- for i=1,16 do
- turtle.select(i)
- turtle.dropDown()
- inv[i] = "n"
- end
- turtle.select(1)
- end
- function dropBees()
- turnTo("apiary")
- print("Dropping off best couple.")
- countItems()
- for i=1,numbees do
- if types[i] == "princess" then
- turtle.select(i)
- invmod.dropSneaky(1,1)
- end
- if bestDrone == i then
- turtle.select(i)
- invmod.dropSneaky(0,1)
- end
- end
- turtle.select(1)
- dropExtra()
- end
- startup()
- while true do
- event,pr1,pr2,pr3 = os.pullEvent()
- if status == "active" then
- extract()
- if out == "b" then
- sortComb()
- analyzeBees()
- findBestDrone()
- if checkPrincess() and bestScore == 4 then
- print("Job finished.")
- turnTo("apiary")
- break
- else
- if fail then
- print("Something went wrong!")
- break
- end
- dropBees()
- end
- elseif out == "c" then
- sortComb()
- end
- else
- os.sleep(5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment