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