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