funkd0ct0r

Untitled

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