funkd0ct0r

Untitled

Mar 31st, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- setup is turtle facing apiary, with a large chest beneath the turtle
  2. -- another chest on top is used for produce and extra drones
  3.  
  4. -- d6qPuqHQ
  5. -- 79C9Mt53
  6. -- gXa8k1tJ
  7. -- fKC8kx5b
  8. -- H0CppXue
  9. -- QTRQHPhM
  10. -- RwTbaqpP
  11.  
  12. local apiary = peripheral.wrap("front")
  13. local chest = peripheral.wrap("bottom")
  14. local chestPushDirection = "up"
  15. local dropToChest = turtle.dropDown
  16. local dropToExtra = turtle.dropUp
  17.  
  18.  
  19. local maxDrones = 6
  20. local minDrones = 3
  21.  
  22.  
  23. local usePurebreed = false --code that breeds more of a species before using it
  24. local purebreedBanList = {["Rocky"] = true} --some bees have too low of fertility, add them here to prevent drone breeding, should only apply to usePurebreed
  25.  
  26. local shutdownMsg = nil
  27.  
  28. bees = {}
  29. stacks = {}
  30.  
  31. function addParent(parent, offspring)
  32. if not bees[parent] then
  33. bees[parent] = {
  34. --name = parent,
  35. score = 0,
  36. mutateFrom = {}
  37. }
  38. end
  39. end
  40.  
  41. function addOffspring(offspring, parentss)
  42. if bees[offspring] then
  43. for i, parents in ipairs(parentss) do
  44. table.insert(bees[offspring].mutateFrom, parents)
  45. end
  46. else
  47. bees[offspring] = {
  48. score = 0,
  49. mutateFrom = parentss
  50. }
  51. end
  52. for i, parents in ipairs(parentss) do
  53. for i, parent in ipairs(parents) do
  54. addParent(parent, offspring)
  55. end
  56. end
  57. end
  58.  
  59.  
  60.  
  61.  
  62. -- produce combinations from 1 or 2 lists
  63. function choose(list, list2)
  64. local newList = {}
  65. if list2 then
  66. for i = 1, #list2 do
  67. for j = 1, #list do
  68. if list[j] ~= list[i] then
  69. table.insert(newList, {list[j], list2[i]})
  70. end
  71. end
  72. end
  73. else
  74. for i = 1, #list do
  75. for j = i, #list do
  76. if list[i] ~= list[j] then
  77. table.insert(newList, {list[i], list[j]})
  78. end
  79. end
  80. end
  81. end
  82. return newList
  83. end
  84.  
  85.  
  86. --bee list from Master Apiarist Database v3.1
  87. --Forestry v2.3.0.7 (683)
  88. --Extra Bees v1.8-dev2
  89. --Magic Bees v2.1.7 (build 78)
  90.  
  91. hivebee = {"Forest", "Meadows", "Mystical", "Unusual", "Attuned", "Wintry", "Marshy", "Water", "Tropical", "Modest", "Sorcerous", "Rocky"}
  92. addOffspring("Common", choose(hivebee))
  93. addOffspring("Cultivated", choose({"Common"}, hivebee))
  94.  
  95. addOffspring("Noble", {{"Common", "Cultivated"}})
  96. addOffspring("Majestic", {{"Noble", "Cultivated"}})
  97. addOffspring("Imperial", {{"Noble", "Majestic"}})
  98. addOffspring("Diligent", {{"Common", "Cultivated"}})
  99. addOffspring("Unweary", {{"Diligent", "Cultivated"}})
  100. addOffspring("Industrious", {{"Diligent", "Unweary"}})
  101. addOffspring("Heroic", {{"Steadfast", "Valiant"}})
  102. addOffspring("Sinister", choose({"Cultivated"}, {"Modest", "Tropical"}))
  103. addOffspring("Fiendish", choose({"Sinister"}, {"Cultivated", "Modest", "Tropical"}))
  104. addOffspring("Frugal", choose({"Modest"}, {"Sinister", "Fiendish"}))
  105. addOffspring("Demonic", {{"Sinister", "Fiendish"}})
  106. addOffspring("Austere", {{"Modest", "Frugal"}})
  107. addOffspring("Exotic", {{"Austere", "Tropical"}})
  108. addOffspring("Edenic", {{"Exotic", "Tropical"}})
  109. addOffspring("Spectral", {{"Hermitic", "Ender"}})
  110. addOffspring("Phantasmal", {{"Spectral", "Ender"}})
  111. addOffspring("Icy", {{"Industrious", "Wintry"}})
  112. addOffspring("Glacial", {{"Icy", "Wintry"}})
  113. addOffspring("Vindictive", {{"Monastic", "Demonic"}})
  114. addOffspring("Vengeful", choose({"Vindictive"}, {"Demonic", "Monastic"}))
  115. addOffspring("Avenging", {{"Vengeful", "Vindictive"}})
  116. addOffspring("Leporine", {{"Meadows", "Forest"}})
  117. addOffspring("Merry", {{"Wintry", "Forest"}})
  118. addOffspring("Tipsy", {{"Wintry", "Meadows"}})
  119. addOffspring("Tricky", {{"Sinister", "Common"}})
  120. addOffspring("Rural", {{"Meadows", "Diligent"}})
  121. addOffspring("Secluded", {{"Monastic", "Austere"}})
  122. addOffspring("Hermitic", {{"Monastic", "Secluded"}})
  123. addOffspring("Arid", {{"Meadows", "Modest"}})
  124. addOffspring("Barren", {{"Arid", "Common"}})
  125. addOffspring("Desolate", {{"Arid", "Barren"}})
  126. addOffspring("Decaying", {{"Desolate", "Modest"}})
  127. addOffspring("Skeletal", {{"Desolate", "Frugal"}})
  128. addOffspring("Creepy", {{"Desolate", "Austere"}})
  129. addOffspring("Decomposing", {{"Gnawing", "Common"}})
  130. addOffspring("Tolerant", {{"Rocky", "Diligent"}})
  131. addOffspring("Robust", {{"Rocky", "Tolerant"}})
  132. addOffspring("Resilient", {{"Imperial", "Robust"}})
  133. addOffspring("Corroded", {{"Resilient", "Forest"}})
  134. addOffspring("Tarnished", {{"Resilient", "Marshy"}})
  135. addOffspring("Rusty", {{"Resilient", "Meadows"}})
  136. addOffspring("Leaden", {{"Resilient", "Unweary"}})
  137. addOffspring("Galvanized", {{"Tarnished", "Cultivated"}})
  138. addOffspring("Impregnable", {{"Resilient", "Noble"}})
  139. addOffspring("Invincible", {{"Resilient", "Ender"}})
  140. addOffspring("Glittering", {{"Corroded", "Imperial"}})
  141. addOffspring("Shining", {{"Rusty", "Imperial"}})
  142. addOffspring("Valuable", {{"Glittering", "Shining"}})
  143. addOffspring("Lapis", {{"Resilient", "Water"}})
  144. addOffspring("Emerald", {{"Lapis", "Noble"}})
  145. addOffspring("Ruby", {{"Emerald", "Austere"}})
  146. addOffspring("Sapphire", {{"Emerald", "Ocean"}})
  147. addOffspring("Diamond", {{"Lapis", "Imperial"}})
  148. addOffspring("Unstable", {{"Austere", "Rocky"}})
  149. addOffspring("Nuclear", {{"Unstable", "Rusty"}})
  150. addOffspring("Radioactive", {{"Nuclear", "Glittering"}})
  151. addOffspring("Ancient", {{"Noble", "Diligent"}})
  152. addOffspring("Primeval", {{"Ancient", "Noble"}})
  153. addOffspring("Prehistoric", {{"Primeval", "Majestic"}})
  154. addOffspring("Relic", {{"Prehistoric", "Imperial"}})
  155. addOffspring("Fossilised", {{"Primeval", "Growing"}})
  156. addOffspring("Resinous", {{"Primeval", "Fungal"}})
  157. addOffspring("Oily", {{"Primeval", "Ocean"}})
  158. addOffspring("Distilled", {{"Oily", "Industrious"}})
  159. addOffspring("Refined", {{"Oily", "Distilled"}})
  160. addOffspring("Elastic", {{"Refined", "Resinous"}})
  161. addOffspring("River", {{"Water", "Common"}})
  162. addOffspring("Ocean", {{"Water", "Diligent"}})
  163. addOffspring("Stained", {{"Ebony", "Ocean"}})
  164. addOffspring("Growing", {{"Diligent", "Forest"}})
  165. addOffspring("Thriving", {{"Growing", "Rural"}})
  166. addOffspring("Blooming", {{"Thriving", "Growing"}})
  167. addOffspring("Sweetened", {{"Valiant", "Diligent"}})
  168. addOffspring("Sugary", {{"Sweetened", "Diligent"}})
  169. addOffspring("Ripening", {{"Sugary", "Forest"}})
  170. addOffspring("Fruity", {{"Ripening", "Rural"}})
  171. addOffspring("Farmed", {{"Cultivated", "Rural"}})
  172. addOffspring("Bovine", {{"Rural", "Water"}})
  173. addOffspring("Caffeinated", {{"Tropical", "Rural"}})
  174. addOffspring("Minty", {{"Tropical", "Farmed"}})
  175. addOffspring("Damp", {{"Common", "Marshy"}})
  176. addOffspring("Boggy", {{"Damp", "Marshy"}})
  177. addOffspring("Fungal", {{"Boggy", "Damp"}})
  178. addOffspring("Furious", {{"Embittered", "Sinister"}})
  179. addOffspring("Volcanic", {{"Embittered", "Furious"}})
  180. addOffspring("Malicious", {{"Sinister", "Tropical"}})
  181. addOffspring("Infectious", {{"Malicious", "Tropical"}})
  182. addOffspring("Virulent", {{"Malicious", "Infectious"}})
  183. addOffspring("Viscous", {{"Water", "Exotic"}})
  184. addOffspring("Glutinous", {{"Viscous", "Exotic"}})
  185. addOffspring("Sticky", {{"Viscous", "Glutinous"}})
  186. addOffspring("Corrosive", {{"Virulent", "Sticky"}})
  187. addOffspring("Caustic", {{"Corrosive", "Fiendish"}})
  188. addOffspring("Acidic", {{"Corrosive", "Caustic"}})
  189. addOffspring("Excited", {{"Cultivated", "Valiant"}})
  190. addOffspring("Energetic", {{"Excited", "Valiant"}})
  191. addOffspring("Frigid", {{"Wintry", "Diligent"}})
  192. addOffspring("Absolute", {{"Ocean", "Frigid"}})
  193. addOffspring("Shadowed", {{"Tolerant", "Sinister"}})
  194. addOffspring("Darkened", {{"Shadowed", "Embittered"}})
  195. addOffspring("Abyssal", {{"Shadowed", "Darkened"}})
  196. addOffspring("Maroon", {{"Forest", "Valiant"}})
  197. addOffspring("Saffron", {{"Meadows", "Valiant"}})
  198. addOffspring("Prussian", {{"Water", "Valiant"}})
  199. addOffspring("Natural", {{"Tropical", "Valiant"}})
  200. addOffspring("Ebony", {{"Rocky", "Valiant"}})
  201. addOffspring("Bleached", {{"Wintry", "Valiant"}})
  202. addOffspring("Sepia", {{"Marshy", "Valiant"}})
  203. addOffspring("Amber", {{"Maroon", "Saffron"}})
  204. addOffspring("Turquoise", {{"Natural", "Prussian"}})
  205. addOffspring("Indigo", {{"Maroon", "Prussian"}})
  206. addOffspring("Slate", {{"Ebony", "Bleached"}})
  207. addOffspring("Azure", {{"Prussian", "Bleached"}})
  208. addOffspring("Lavender", {{"Maroon", "Bleached"}})
  209. addOffspring("Lime", {{"Natural", "Bleached"}})
  210. addOffspring("Fuchsia", {{"Indigo", "Lavender"}})
  211. addOffspring("Ashen", {{"Slate", "Bleached"}})
  212. addOffspring("Celebratory", {{"Austere", "Excited"}})
  213. addOffspring("Jaded", {{"Ender", "Relic"}})
  214. addOffspring("Glowering", {{"Furious", "Excited"}})
  215. addOffspring("Hazardous", {{"Austere", "Desolate"}})
  216. addOffspring("Lustered", {{"Resilient", "Unweary"}})
  217. addOffspring("Abnormal", {{"Secluded", "Ender"}})
  218. addOffspring("Spatial", {{"Abnormal", "Hermitic"}})
  219. addOffspring("Quantum", {{"Spatial", "Spectral"}})
  220. addOffspring("Eldritch", choose({"Cultivated"}, {"Mystical", "Sorcerous", "Unusual", "Attuned"}))
  221. addOffspring("Esoteric", {{"Cultivated", "Eldritch"}})
  222. addOffspring("Mysterious", {{"Eldritch", "Esoteric"}})
  223. addOffspring("Arcane", {{"Esoteric", "Mysterious"}})
  224. addOffspring("Charmed", {{"Cultivated", "Eldritch"}})
  225. addOffspring("Enchanted", {{"Eldritch", "Charmed"}})
  226. addOffspring("Supernatural", {{"Charmed", "Enchanted"}})
  227. addOffspring("Ethereal", {{"Arcane", "Supernatural"}})
  228. addOffspring("Watery", {{"Supernatural", "Ethereal"}})
  229. addOffspring("Earthen", {{"Supernatural", "Ethereal"}})
  230. addOffspring("Firey", {{"Supernatural", "Ethereal"}})
  231. addOffspring("Windy", {{"Supernatural", "Ethereal"}})
  232. addOffspring("Pupil", {{"Monastic", "Arcane"}})
  233. addOffspring("Scholarly", {{"Arcane", "Pupil"}})
  234. addOffspring("Savant", {{"Pupil", "Scholarly"}})
  235. addOffspring("Aware", {{"Ethereal", "Attuned"}})
  236. addOffspring("Spirit", choose({"Aware"}, {"MystEtherealical", "Attuned"}))
  237. addOffspring("Soul", {{"Aware", "Spirit"}})
  238. addOffspring("Skulking", {{"Modest", "Eldritch"}})
  239. addOffspring("Ghastly", {{"Skulking", "Ethereal"}})
  240. addOffspring("Spidery", {{"Tropical", "Skulking"}})
  241. addOffspring("Smouldering", {{"Skulking", "Hateful"}})
  242. addOffspring("Timely", {{"Imperial", "Ethereal"}})
  243. addOffspring("Lordly", {{"Imperial", "Timely"}})
  244. addOffspring("Doctoral", {{"Timely", "Lordly"}})
  245. addOffspring("Infernal", {{"Infernal", "ves"}})
  246. addOffspring("Hateful", {{"Infernal", "Eldritch"}})
  247. addOffspring("Spiteful", {{"Infernal", "Hateful"}})
  248. addOffspring("Withering", {{"Demonic", "Spiteful"}})
  249. addOffspring("Oblivion", {{"Oblivion", "ves"}})
  250. addOffspring("Nameless", {{"Ethereal", "Oblivion"}})
  251. addOffspring("Abandoned", {{"Oblivion", "Nameless"}})
  252. addOffspring("Forlorn", {{"Nameless", "Abandoned"}})
  253. addOffspring("Draconic", {{"Imperial", "Abandoned"}})
  254. addOffspring("Ferrous", {{"Common", "Industrious"}})
  255. addOffspring("Auric", {{"Minium", "Plumbum"}})
  256. addOffspring("Cuprum", {{"Industrious", "Meadows"}})
  257. addOffspring("Stannum", {{"Industrious", "Forest"}})
  258. addOffspring("Argentum", {{"Imperial", "Modest"}})
  259. addOffspring("Plumbum", {{"Stannum", "Common"}})
  260. addOffspring("Aluminum", {{"Industrious", "Cultivated"}})
  261. addOffspring("Ardite", {{"Industrious", "Infernal"}})
  262. addOffspring("Cobalt", {{"Imperial", "Infernal"}})
  263. addOffspring("Manyullyn", {{"Ardite", "Cobalt"}})
  264. addOffspring("Diamandi", {{"Austere", "Auric"}})
  265. addOffspring("Esmeraldi", {{"Austere", "Argentum"}})
  266. addOffspring("Apatine", {{"Rural", "Cuprum"}})
  267. addOffspring("Mutable", {{"Unusual", "Eldritch"}})
  268. addOffspring("Transmuting", {{"Unusual", "Mutable"}})
  269. addOffspring("Crumbling", {{"Unusual", "Mutable"}})
  270. addOffspring("Invisible", {{"Mystical", "Mutable"}})
  271. addOffspring("Aer", {{"Windy", "Windy"}})
  272. addOffspring("Ignis", {{"Firey", "Firey"}})
  273. addOffspring("Aqua", {{"Watery", "Watery"}})
  274. addOffspring("Solum", {{"Earthen", "Earthen"}})
  275. addOffspring("Ordered", {{"Ethereal", "Arcane"}})
  276. addOffspring("Chaotic", {{"Ethereal", "Supernatural"}})
  277. addOffspring("Brainy", {{"Skulking", "Pupil"}})
  278. addOffspring("Batty", {{"Skulking", "Windy"}})
  279. addOffspring("Poultry", {{"Common", "Skulking"}})
  280. addOffspring("Beefy", {{"Common", "Skulking"}})
  281. addOffspring("Porcine", {{"Common", "Skulking"}})
  282. addOffspring("Minium", {{"Frugal", "Eldritch"}})
  283.  
  284.  
  285.  
  286. --find the highest level bee i own that is a parent to species (of type "Princess" or "Drone" if type ~= nil)
  287. --returns parent, offspring, score
  288. --offspring is the next step after parent
  289. --score is the depth of the search
  290.  
  291. function findAvailableParent(species, score, type)
  292.  
  293. for i, stack in pairs(stacks) do
  294. if stack.beeInfo.displayName == species then
  295. if type then
  296. if string.find(stack.name, type) then
  297. return species, nil, score
  298. end
  299. else
  300. return species, nil, score
  301. end
  302. end
  303. end
  304.  
  305. local aScore, aParent, aOffspring
  306. local beeScore = 99999
  307. local beeParent = nil
  308. local beeOffspring = nil
  309.  
  310. for i, parents in ipairs(bees[species].mutateFrom) do
  311. aParent, aOffspring, aScore = findAvailableParent(parents[1], score + 1, type)
  312. if aScore < beeScore then
  313. beeScore = aScore
  314. beeParent = aParent
  315. beeOffspring = aOffspring
  316. end
  317. aParent, aOffspring, aScore = findAvailableParent(parents[2], score + 1, type)
  318. if aScore < beeScore then
  319. beeScore = aScore
  320. beeParent = aParent
  321. beeOffspring = aOffspring
  322. end
  323. end
  324. if beeOffspring == nil then
  325. beeOffspring = species
  326. end
  327. return beeParent, beeOffspring, beeScore
  328. end
  329.  
  330. --finds a princess and drone of the given species if they exist
  331. local function findSpecies(species)
  332. local princessIndex = nil
  333. local droneIndex = nil
  334.  
  335. for i, stack in pairs(stacks) do
  336. if stack.beeInfo.displayName == species then
  337. if string.find(stack.name, "Princess") then
  338. princessIndex = i
  339. end
  340. if string.find(stack.name, "Drone") then
  341. droneIndex = i
  342. end
  343. end
  344. end
  345. return princessIndex, droneIndex
  346. end
  347.  
  348. --breed these two species, they must exists and have a breeding pair
  349. local function breedSpecies(parent1, parent2)
  350. local princess1 = nil
  351. local princess2 = nil
  352. local drone1 = nil
  353. local drone2 = nil
  354.  
  355. princess1, drone1 = findSpecies(parent1)
  356. princess2, drone2 = findSpecies(parent2)
  357.  
  358. if not (princess1 and drone2) then
  359. princess1 = princess2
  360. drone2 = drone1
  361. end
  362.  
  363. print("Breeding " .. parent1 .. " with " .. parent2)
  364.  
  365. if princess1 and drone2 then
  366. chest.pushItem(chestPushDirection, princess1, 1)
  367. turtle.drop()
  368. chest.pushItem(chestPushDirection, drone2, 1)
  369. turtle.drop()
  370. return true
  371. end
  372. return false
  373. end
  374.  
  375. --finds the most common species of type Drone or Princess
  376. local function findExtraBee(type)
  377. local counts = {}
  378. local bestcount = 0
  379. local bestspecies = nil
  380.  
  381. for i, stack in pairs(stacks) do
  382. if string.find(stack.name, type) then
  383. if counts[stack.beeInfo.displayName] then
  384. counts[stack.beeInfo.displayName] = counts[stack.beeInfo.displayName] + stack.qty
  385. else
  386. counts[stack.beeInfo.displayName] = stack.qty
  387. end
  388. if counts[stack.beeInfo.displayName] > bestcount then
  389. bestcount = counts[stack.beeInfo.displayName]
  390. bestspecies = stack.beeInfo.displayName
  391. end
  392. end
  393. end
  394. return bestspecies, bestcount
  395. end
  396.  
  397.  
  398. --attempt to create a princess and minDrones of species, which i own one of
  399. --returns true if already purebred, else begins a breeding cycle
  400.  
  401. local function purebreed(species)
  402. local princessCount = 0
  403. local droneCount = 0
  404.  
  405. --count how many i have
  406.  
  407. for i, stack in pairs(stacks) do
  408. if stack.beeInfo.displayName == species then
  409. if string.find(stack.name, "Princess") then
  410. princessCount = princessCount + stack.qty
  411. end
  412. if string.find(stack.name, "Drone") then
  413. droneCount = droneCount + stack.qty
  414. end
  415. end
  416. end
  417.  
  418. if princessCount >= 1 and droneCount >= minDrones then
  419. return true
  420. end
  421.  
  422. print("Attempting to purebreed " .. species)
  423.  
  424. if princessCount >= 1 and droneCount >= 1 then
  425. if purebreedBanList[species] then
  426. return true
  427. end
  428. breedSpecies(species, species)
  429. return false
  430. end
  431.  
  432. --find something to breed it with, an available parent, or an extra bee
  433.  
  434. local parent1, offspring, score
  435. if(princessCount >= 1) then
  436. parent1, offspring, score = findAvailableParent(species, 0, "Drone")
  437. if score == 99999 then
  438. parent1, score = findExtraBee("Drone")
  439. if score < 2 then
  440. shutdownMsg = "Need more Drones!"
  441. else
  442. print("Used Extra " .. parent1 .. " Drone")
  443. end
  444. else
  445. if usePurebreed then
  446. local princess1, drone1 = findSpecies(parent1)
  447. if princess1 and drone2 and not purebreed(parent1) then
  448. return false
  449. end
  450. end
  451. end
  452. else
  453. parent1, offspring, score = findAvailableParent(species, 0, "Princess")
  454. if score == 99999 then
  455. parent1, score = findExtraBee("Princess")
  456. if score < 2 then
  457. shutdownMsg = "Need more Princesses!"
  458. else
  459. print("Used Extra " .. parent1 .. " Princess")
  460. end
  461. else
  462. if usePurebreed then
  463. local princess1, drone1 = findSpecies(parent1)
  464. if princess1 and drone2 and not purebreed(parent1) then
  465. return false
  466. end
  467. end
  468. end
  469. end
  470. if shutdownMsg then
  471. return false
  472. end
  473.  
  474. breedSpecies(species, parent1)
  475. return false
  476. end
  477.  
  478. --the main breeding function
  479. --uses findavailableparent, then tries to create the designated offspring
  480.  
  481. local function targetSpecies(species)
  482. local parent1
  483. local parent2 = nil
  484.  
  485. --find the highest level bee i have that is a parent to species
  486. --offspring is the next step after parent on the way to species
  487.  
  488. local parent1, offspring, score = findAvailableParent(species, 0, nil)
  489. if score == 0 then
  490. --found species
  491. return true
  492. end
  493. if score == 99999 then
  494. shutdownMsg = "No available parents for " .. species
  495. return false
  496. end
  497.  
  498. print("Targeting Species " .. offspring)
  499.  
  500. local princess1, drone1 = findSpecies(parent1)
  501. local princess2, drone2
  502.  
  503. --find which bee i need to breed parent1 with to get offspring, showing preference for bees that i own
  504.  
  505. for i, parents in ipairs(bees[offspring].mutateFrom) do
  506. if parents[1] == parent1 then
  507. princess2, drone2 = findSpecies(parents[2])
  508. if (princess1 and drone2) or (princess2 and drone1) then
  509. parent2 = parents[2]
  510. break
  511. end
  512. if not parent2 then
  513. parent2 = parents[2]
  514. end
  515. if princess2 or drone2 then
  516. parent2 = parents[2]
  517. end
  518. end
  519. if parents[2] == parent1 then
  520. princess2, drone2 = findSpecies(parents[1])
  521. if (princess1 and drone2) or (princess2 and drone1) then
  522. parent2 = parents[1]
  523. break
  524. end
  525. if not parent2 then
  526. parent2 = parents[1]
  527. end
  528. if princess2 or drone2 then
  529. parent2 = parents[1]
  530. end
  531. end
  532.  
  533. end
  534.  
  535. princess2, drone2 = findSpecies(parent2)
  536.  
  537. if (princess1 and drone2) or (princess2 and drone1) then
  538. --i have both bees i need so breed it now
  539. if usePurebreed then
  540. if princess1 and drone1 and not purebreed(parent1) then
  541. return false
  542. end
  543. if princess2 and drone2 and not purebreed(parent2) then
  544. return false
  545. end
  546. end
  547. breedSpecies(parent1, parent2)
  548. return false
  549. end
  550.  
  551. --i have the species but not princess or drone, so purebreed it
  552. if princess2 or drone2 then
  553. purebreed(parent2)
  554. return false
  555. end
  556.  
  557. --i dont have the species i need to breed with parent, so target it
  558. targetSpecies(parent2)
  559. return false
  560. end
  561.  
  562. local function dropExtraDrones()
  563.  
  564. local species, count = findExtraBee("Drone")
  565.  
  566. if count <= maxDrones then
  567. return
  568. end
  569.  
  570. for i, stack in pairs(stacks) do
  571. if stack.beeInfo.displayName == species and string.find(stack.name, "Drone") then
  572. chest.pushItem(chestPushDirection, i, 1)
  573. dropToExtra()
  574. count = count - 1
  575. if count <= maxDrones then
  576. return
  577. end
  578. end
  579. end
  580.  
  581. end
  582.  
  583. local function dropExtraItems()
  584. stacks = chest.getAllStacks()
  585. for i, stack in pairs(stacks) do
  586. if (not string.find(stack.name, "Drone")) and (not string.find(stack.name, "Princess")) then
  587. chest.pushItem(chestPushDirection, i, stack.qty)
  588. dropToExtra()
  589. end
  590. end
  591.  
  592. end
  593.  
  594. local function printTree(species, level)
  595. if level == nil then level = 0 else level = level + 1 end
  596.  
  597. if bees[species].mutateFrom[1] then
  598. printTree(bees[species].mutateFrom[1][1], level)
  599. end
  600.  
  601. print(string.rep(" ", level * 2) .. species)
  602.  
  603. if bees[species].mutateFrom[1] then
  604. printTree(bees[species].mutateFrom[1][2], level)
  605. end
  606. end
  607.  
  608. local function main(species)
  609.  
  610. for slot = 1, 16 do
  611. if turtle.getItemCount(slot) > 0 then
  612. turtle.select(slot)
  613. dropToChest()
  614. end
  615. end
  616. turtle.select(1)
  617.  
  618. local apiarystacks
  619.  
  620. while(1) do
  621.  
  622. --test for breeding in progress
  623. apiarystacks = apiary.getAllStacks()
  624. while apiarystacks[1] do
  625. sleep(1)
  626. while(turtle.suck()) do
  627. dropToChest()
  628. end
  629.  
  630. apiarystacks = apiary.getAllStacks()
  631. end
  632.  
  633. --clear apiary
  634. while(turtle.suck()) do
  635. dropToChest()
  636. end
  637.  
  638.  
  639. dropExtraItems()
  640.  
  641. --get the list of all items in the chest
  642. stacks = chest.getAllStacks()
  643.  
  644. if targetSpecies(species) then
  645. if purebreed(species) then
  646. shutdownMsg = "Breeding complete: " .. species
  647. end
  648. end
  649.  
  650. if(shutdownMsg) then
  651. print(shutdownMsg)
  652. break
  653. end
  654.  
  655. dropExtraDrones()
  656.  
  657. sleep(1)
  658. end
  659. end
  660.  
  661. local species = ...
  662. if species == nil then
  663. print("Usage")
  664. print(" programname species")
  665. return
  666. end
  667. if bees[species] == nil then
  668. print("Species does not exist in database")
  669. end
  670.  
  671. --printTree(species)
  672. main(species)
Advertisement
Add Comment
Please, Sign In to add comment