Advertisement
NanoBob

the bees

Dec 11th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 KB | None | 0 0
  1. ender = peripheral.wrap("bottom")
  2. dronesCab = peripheral.wrap("right")
  3. princessesCab = peripheral.wrap("left")
  4.  
  5. local receiveFrequency={colors.pink,colors.magenta,colors.cyan}
  6. local sendFrequency={colors.purple,colors.magenta,colors.cyan}
  7.  
  8. local apiarys={
  9.     {apiary="powered_tile_2",chest="ender_chest_0",direction="east",counterDirection="west",},
  10.     {apiary="powered_tile_3",chest="ender_chest_1",direction="east",counterDirection="west",},
  11.     {apiary="powered_tile_4",chest="ender_chest_2",direction="east",counterDirection="west",},
  12.     {apiary="powered_tile_5",chest="ender_chest_5",direction="west",counterDirection="east",},
  13.     {apiary="powered_tile_6",chest="ender_chest_4",direction="west",counterDirection="east",},
  14.     {apiary="powered_tile_7",chest="ender_chest_3",direction="west",counterDirection="east",},
  15. }
  16.  
  17. for id,data in pairs(apiarys) do
  18.     apiarys[id]={apiary=peripheral.wrap(data.apiary),chest=peripheral.wrap(data.chest),direction=data.direction,counterDirection=data.counterDirection}
  19. end
  20.  
  21. function getDrones()
  22.     local drones={}
  23.     for id,data in pairs(dronesCab.getAllStacks()) do
  24.         local name=string.lower(data.select().display_name)
  25.         if string.match(name,"drone")~=nil then
  26.             drones[ string.gsub(name," drone","") ] = true
  27.             drones[ name ] = true
  28.         end
  29.     end
  30.     return drones
  31. end
  32.  
  33. function getPrincesses()
  34.     local princesses={}
  35.     for id,data in pairs(princessesCab.getAllStacks()) do
  36.         local name=string.lower(data.select().display_name)
  37.         if string.match(name,"princess")~=nil then
  38.             princesses[ string.gsub(name," princess","") ] = true
  39.             princesses[ name ] = true
  40.         end
  41.     end
  42.     return princesses
  43. end
  44.  
  45. function hasDrone(name)
  46.     local drones=getDrones()
  47.     if drones[name]==true then
  48.         return true
  49.     end
  50.     return false
  51. end
  52.  
  53. function hasPrincess(name)
  54.     local princesses=getPrincesses()
  55.     if princesses[name]==true then
  56.         return true
  57.     end
  58.     return false
  59. end
  60.  
  61. function getDroneSlot(target)
  62.     if hasDrone(target)==false then return false end
  63.     for id,data in pairs(dronesCab.getAllStacks()) do
  64.         local name=string.lower(data.select().display_name)
  65.         if name==target then
  66.             return id
  67.         end
  68.     end
  69.     return false
  70. end
  71.  
  72. function getPrincessSlot(target)
  73.     if hasPrincess(target)==false then return false end
  74.     for id,data in pairs(princessesCab.getAllStacks()) do
  75.         local name=string.lower(data.select().display_name)
  76.         if name==target then
  77.             return id
  78.         end
  79.     end
  80.     return false
  81. end
  82.  
  83. function convert(array)
  84.     local comboTable={}
  85.     for id,combo in pairs(array) do
  86.         comboTable[id]={
  87.             string.lower(combo.allele1.name),
  88.             string.lower(combo.allele2.name),
  89.         }
  90.     end
  91.     return comboTable
  92. end
  93.  
  94.  
  95.  
  96. function startBreed(drone,princess)
  97.     local pSlot=getPrincessSlot(princess.." princess")
  98.     local dSlot=getDroneSlot(drone.." drone")
  99.     ender.setColors(sendFrequency[1],sendFrequency[2],sendFrequency[3])
  100.     princessesCab.pushItem("down",pSlot,1,1)
  101.     sleep(1)
  102.     dronesCab.pushItem("down",dSlot,1,1)
  103.     sleep(6)
  104.     local sorted=false
  105.     while sorted==false do
  106.         print("Checking apiaries for empty spots")
  107.         for id,apiary in pairs(apiarys) do
  108.             apiary.chest.setColors(sendFrequency[1],sendFrequency[2],sendFrequency[3])
  109.             sleep(0.5)
  110.             if apiary.chest.pushItem(apiary.direction,1,1,1)==1 then
  111.                 apiary.chest.pushItem(apiary.direction,2,1,2)
  112.                 sorted=true
  113.                 apiarys[id].breeding=drone.." drone + "..princess.." princess"
  114.             elseif apiary.chest.pushItem(apiary.direction,2,1,1)==1 then
  115.                 apiary.chest.pushItem(apiary.direction,1,1,2)
  116.                 sorted=true
  117.                 apiarys[id].breeding=drone.." drone + "..princess.." princess"
  118.             end
  119.             apiary.chest.setColors(receiveFrequency[1],receiveFrequency[2],receiveFrequency[3])
  120.         end
  121.         if sorted==false then
  122.             print("None found")
  123.             sleep(5)
  124.         end
  125.     end
  126.     return true
  127. end
  128.  
  129. function emptyApiaries()
  130.     for id,apiary in pairs(apiarys) do
  131.         apiary.chest.setColors(receiveFrequency[1],receiveFrequency[2],receiveFrequency[3])
  132.         sleep(0.1)
  133.         for i=7,15 do
  134.             apiary.apiary.pushItem(apiary.counterDirection,i,10,i)
  135.         end
  136.     end
  137. end
  138.  
  139. function tryBreed(targetBee)
  140.     term.clear()
  141.     term.setCursorPos(1,1)
  142.     print("Attempting to breed a "..targetBee.." bee")
  143.     local attempts
  144.     local combos=convert(apiarys[1].apiary.getBeeParents(targetBee))
  145.     for i,combo in pairs( combos ) do
  146.         --print("Possible combo: "..combo[1].."+"..combo[2])
  147.         if hasDrone(combo[1])==true and hasPrincess(combo[2])==true then
  148.             print(combo[1].." + "..combo[2].." = "..targetBee)
  149.             if startBreed(combo[1],combo[2])==false then break end
  150.             return
  151.         elseif hasDrone(combo[2])==true and hasPrincess(combo[1])==true then
  152.             print(combo[2].." + "..combo[1].." = "..targetBee)
  153.             if startBreed(combo[2],combo[1])==false then break end
  154.             return 
  155.         end
  156.         if debugmode==true then
  157.             if hasDrone(combo[1])==true then
  158.                 print("Possible combo requires a "..combo[2].." princess")
  159.             elseif hasDrone(combo[2])==true then
  160.                 print("Possible combo requires a "..combo[1].." princess")
  161.             elseif hasPrincess(combo[1])==true then
  162.                 print("Possible combo requires a "..combo[1].." drone")
  163.             elseif hasPrincess(combo[2])==true then
  164.                 print("Possible combo requires a "..combo[1].." drone")
  165.             end
  166.         end
  167.     end
  168.     print("No combos found, please supply more bees.")
  169. end
  170.  
  171. function breed(bee)
  172.     while true do
  173.         if hasPrincess(bee.." princess")==true then
  174.             return true
  175.         end
  176.         tryBreed(bee)
  177.         emptyApiaries()
  178.         sleep(5)
  179.     end
  180. end
  181.  
  182.  
  183. function getTarget()
  184.     term.clear()
  185.     term.setCursorPos(1,1)
  186.     term.write("Target bee: ")
  187.     local target=read()
  188.     breed(target)
  189. end
  190.  
  191. getTarget()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement