funkd0ct0r

Untitled

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