funkd0ct0r

Untitled

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