funkd0ct0r

Untitled

Mar 23rd, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.39 KB | None | 0 0
  1. -- this version for computer instead of turtle
  2. -- online has problems tho, displayname can be bee.species.meadows, and name is garbled but does contain lower drone princess
  3. -- mcFAZqmW--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. local function fixStacks()
  278. for i, stack in pairs(stacks) do
  279. if string.find(stack.beeInfo.displayName, "bees.species.") then
  280. stack.beeInfo.displayName = string.upper(string.sub(stack.beeInfo.displayName, 14, 14)) .. string.sub(stack.beeInfo.displayName, 15, -1)
  281. end
  282. if string.find(stack.name, "drone") then
  283. stack.name = "Drone"
  284. end
  285. if string.find(stack.name, "princess") then
  286. stack.name = "Princess"
  287. end
  288. end
  289. end
  290.  
  291. --find the highest level bee i own that is a parent to species (of type "Princess" or "Drone" if type ~= nil)
  292. --returns parent, offspring, score
  293. --offspring is the next step after parent
  294. --score is the depth of the search
  295.  
  296. function findAvailableParent(species, score, type)
  297.  
  298. for i, stack in pairs(stacks) do
  299. if stack.beeInfo.displayName == species then
  300. if type then
  301. if string.find(stack.name, type) then
  302. return species, nil, score
  303. end
  304. else
  305. return species, nil, score
  306. end
  307. end
  308. end
  309.  
  310. local aScore, aParent, aOffspring
  311. local beeScore = 99999
  312. local beeParent = nil
  313. local beeOffspring = nil
  314.  
  315. for i, parents in ipairs(bees[species].mutateFrom) do
  316. aParent, aOffspring, aScore = findAvailableParent(parents[1], score + 1, type)
  317. if aScore < beeScore then
  318. beeScore = aScore
  319. beeParent = aParent
  320. beeOffspring = aOffspring
  321. end
  322. aParent, aOffspring, aScore = findAvailableParent(parents[2], score + 1, type)
  323. if aScore < beeScore then
  324. beeScore = aScore
  325. beeParent = aParent
  326. beeOffspring = aOffspring
  327. end
  328. end
  329. if beeOffspring == nil then
  330. beeOffspring = species
  331. end
  332. return beeParent, beeOffspring, beeScore
  333. end
  334.  
  335. --finds a princess and drone of the given species if they exist
  336. local function findSpecies(species)
  337. local princessIndex = nil
  338. local droneIndex = nil
  339.  
  340. for i, stack in pairs(stacks) do
  341. if stack.beeInfo.displayName == species then
  342. if string.find(stack.name, "Princess") then
  343. princessIndex = i
  344. end
  345. if string.find(stack.name, "Drone") then
  346. droneIndex = i
  347. end
  348. end
  349. end
  350. return princessIndex, droneIndex
  351. end
  352.  
  353. --breed these two species, they must exists and have a breeding pair
  354. local function breedSpecies(parent1, parent2)
  355. local princess1 = nil
  356. local princess2 = nil
  357. local drone1 = nil
  358. local drone2 = nil
  359.  
  360. princess1, drone1 = findSpecies(parent1)
  361. princess2, drone2 = findSpecies(parent2)
  362.  
  363. if not (princess1 and drone2) then
  364. princess1 = princess2
  365. drone2 = drone1
  366. end
  367.  
  368. print("Breeding " .. parent1 .. " with " .. parent2)
  369.  
  370. if princess1 and drone2 then
  371. chest.pushItem("north", princess1, 1, 1)
  372. chest.pushItem("north", drone2, 1, 2)
  373. return true
  374. end
  375. return false
  376. end
  377.  
  378. --finds the most common species of type Drone or Princess
  379. local function findExtraBee(type, msg)
  380. local counts = {}
  381. local bestcount = 0
  382. local bestspecies = nil
  383.  
  384. for i, stack in pairs(stacks) do
  385. if string.find(stack.name, type) then
  386. if counts[stack.beeInfo.displayName] then
  387. counts[stack.beeInfo.displayName] = counts[stack.beeInfo.displayName] + stack.qty
  388. else
  389. counts[stack.beeInfo.displayName] = stack.qty
  390. end
  391. if counts[stack.beeInfo.displayName] > bestcount then
  392. bestcount = counts[stack.beeInfo.displayName]
  393. bestspecies = stack.beeInfo.displayName
  394. end
  395. end
  396. end
  397. if bestcount < 2 then
  398. shutdownMsg = "Need more " .. type .. "s!";
  399. else
  400. if msg == "Used" then
  401. print("Used Extra " .. bestspecies .. " " .. type)
  402. end
  403. end
  404. return bestspecies, bestcount
  405. end
  406.  
  407. --helper function used when testing for low fertility
  408. local function getTotalDroneCount()
  409. stacks = chest.getAllStacks()
  410. fixStacks()
  411. local count = 0
  412. for i, stack in pairs(stacks) do
  413. if string.find(stack.name, "Drone") then
  414. count = count + 1
  415. end
  416. end
  417. return count
  418. end
  419.  
  420. --attempt to create a princess and minDrones of species, which i own one of
  421. --returns true if already purebred, else begins a breeding cycle
  422.  
  423. local function purebreed(species)
  424. local princessCount = 0
  425. local droneCount = 0
  426.  
  427. --count how many i have
  428.  
  429. for i, stack in pairs(stacks) do
  430. if stack.beeInfo.displayName == species then
  431. if string.find(stack.name, "Princess") then
  432. princessCount = princessCount + stack.qty
  433. end
  434. if string.find(stack.name, "Drone") then
  435. droneCount = droneCount + stack.qty
  436. end
  437. end
  438. end
  439.  
  440. if princessCount >= 1 and droneCount >= minDrones then
  441. return true
  442. end
  443.  
  444. print("Attempting to purebreed " .. species)
  445.  
  446. if princessCount >= 1 and droneCount >= 1 then
  447. if purebreedBanList[species] then
  448. return true
  449. end
  450. purebreedBee = species
  451. purebreedDroneCount = getTotalDroneCount()
  452. breedSpecies(species, species)
  453. return false
  454. end
  455.  
  456. --find something to breed it with, an available parent, or an extra bee
  457.  
  458. local parent1, offspring, score
  459. if(princessCount >= 1) then
  460. parent1, offspring, score = findAvailableParent(species, 0, "Drone")
  461. if score == 99999 then
  462. parent1, score = findExtraBee("Drone", "Used")
  463. else
  464. --the purebreeding code sometimes gets stuck on low fertility bees
  465. local princess1, drone1 = findSpecies(parent1)
  466. if princess1 and drone2 and not purebreed(parent1) then
  467. return false
  468. end
  469. end
  470. else
  471. parent1, offspring, score = findAvailableParent(species, 0, "Princess")
  472. if score == 99999 then
  473. parent1, score = findExtraBee("Princess", "Used")
  474. else
  475. --local princess1, drone1 = findSpecies(parent1)
  476. if princess1 and drone2 and not purebreed(parent1) then
  477. return false
  478. end
  479. end
  480. end
  481. if shutdownMsg then
  482. return false
  483. end
  484.  
  485. breedSpecies(species, parent1)
  486. return false
  487. end
  488.  
  489. --the main breeding function
  490. --uses findavailableparent, then tries to create the designated offspring
  491.  
  492. local function targetSpecies(species)
  493. local parent1
  494. local parent2 = nil
  495.  
  496. --find the highest level bee i have that is a parent to species
  497. --offspring is the next step after parent on the way to species
  498.  
  499. local parent1, offspring, score = findAvailableParent(species, 0, nil)
  500. if score == 0 then
  501. --found species
  502. return true
  503. end
  504. if score == 99999 then
  505. shutdownMsg = "No available parents for " .. species
  506. return false
  507. end
  508.  
  509. print("Targeting Species " .. offspring)
  510.  
  511. local princess1, drone1 = findSpecies(parent1)
  512. local princess2, drone2
  513.  
  514. --find which bee i need to breed parent1 with to get offspring, showing preference for bees that i own
  515.  
  516. for i, parents in ipairs(bees[offspring].mutateFrom) do
  517. if parents[1] == parent1 then
  518. princess2, drone2 = findSpecies(parents[2])
  519. if (princess1 and drone2) or (princess2 and drone1) then
  520. parent2 = parents[2]
  521. break
  522. end
  523. if not parent2 then
  524. parent2 = parents[2]
  525. end
  526. if princess2 or drone2 then
  527. parent2 = parents[2]
  528. end
  529. end
  530. if parents[2] == parent1 then
  531. princess2, drone2 = findSpecies(parents[1])
  532. if (princess1 and drone2) or (princess2 and drone1) then
  533. parent2 = parents[1]
  534. break
  535. end
  536. if not parent2 then
  537. parent2 = parents[1]
  538. end
  539. if princess2 or drone2 then
  540. parent2 = parents[1]
  541. end
  542. end
  543.  
  544. end
  545.  
  546. princess2, drone2 = findSpecies(parent2)
  547.  
  548. if (princess1 and drone2) or (princess2 and drone1) then
  549. --i have both bees i need so breed it now
  550. --the purebreeding code sometimes gets stuck on low fertility bees
  551. if princess1 and drone1 and not purebreed(parent1) then
  552. return false
  553. end
  554. if princess2 and drone2 and not purebreed(parent2) then
  555. return false
  556. end
  557. breedSpecies(parent1, parent2)
  558. return false
  559. end
  560.  
  561. --i have the species but not princess or drone, so purebreed it
  562. if princess2 or drone2 then
  563. purebreed(parent2)
  564. return false
  565. end
  566.  
  567. --i dont have the species i need to breed with parent, so target it
  568. targetSpecies(parent2)
  569. return false
  570. end
  571.  
  572. local function dropExtraDrones()
  573.  
  574. local species, count = findExtraBee("Drone", "Dropping")
  575. shutdownMsg = nil
  576.  
  577. if count <= maxDrones then
  578. return
  579. end
  580.  
  581. for i, stack in pairs(stacks) do
  582. if stack.beeInfo.displayName == species and string.find(stack.name, "Drone") then
  583. chest.pushItem("south", i, 1)
  584. count = count - 1
  585. if count <= maxDrones then
  586. return
  587. end
  588. end
  589. end
  590.  
  591. end
  592.  
  593. local function dropExtraItems()
  594. stacks = chest.getAllStacks()
  595. fixStacks()
  596. for i, stack in pairs(stacks) do
  597. if (not string.find(stack.name, "Drone")) and (not string.find(stack.name, "Princess")) then
  598. chest.pushItem("south", i, stack.qty)
  599. end
  600. end
  601.  
  602. end
  603.  
  604. local function main(species)
  605.  
  606. local apiarystacks
  607.  
  608. while(1) do
  609.  
  610. --test for breeding in progress
  611. apiarystacks = apiary.getAllStacks()
  612. while apiarystacks[1] do
  613. sleep(2)
  614. apiarystacks = apiary.getAllStacks()
  615. end
  616.  
  617. --clear apiary
  618. for slot = 3, 8 do
  619. if apiarystacks[slot] then
  620. apiary.pushItem("south", slot, apiarystacks[slot].qty)
  621. end
  622. end
  623.  
  624. if purebreedBee then
  625. if purebreedDroneCount == getTotalDroneCount() then
  626. purebreedBanList[purebreedBee] = 1
  627. end
  628. purebreedBee = nil
  629. end
  630.  
  631. dropExtraItems()
  632.  
  633. --get the list of all items in the chest
  634. stacks = chest.getAllStacks()
  635. fixStacks()
  636. if targetSpecies(species) then
  637. if purebreed(species) then
  638. shutdownMsg = "Breeding complete: " .. species
  639. end
  640. end
  641.  
  642. if(shutdownMsg) then
  643. print(shutdownMsg)
  644. break
  645. end
  646.  
  647. dropExtraDrones()
  648.  
  649. sleep(1)
  650. end
  651. end
  652.  
  653. local species = ...
  654. if species == nil then
  655. print("Usage")
  656. print(" programname species")
  657. return
  658. end
  659. if bees[species] == nil then
  660. print("Species does not exist in database")
  661. end
  662.  
  663. main(species)
Advertisement
Add Comment
Please, Sign In to add comment