funkd0ct0r

Untitled

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