Advertisement
funkd0ct0r

Untitled

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