Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BeeAnalyzer 4.0
- -- Original code by Direwolf20
- -- Hotfix 1 by Mandydax
- -- Hotfix 2 by Mikeyhun/MaaadMike
- -- Major overhaul by MacLeopold
- -- Breeds bees with best attributes in this order:
- -- fertility, speed, nocturnal, flyer, cave, temperature tolerance, humidity tolerance
- -- other attributes are ignored (lifespawn, flowers, effect and territory)
- -- Can specify multiple target species to help with keeping to the correct line
- local targetSpecies = { ... }
- local currslot = 1
- local princess = 0
- local bestDrone = 0
- local data={}
- local currData = {}
- local princessData = {}
- local droneData = {}
- local countBees = 0
- local beeTable = {}
- local currScore = 0
- local toleranceTable = {}
- local toleranceString = {}
- local needsUpdate = ""
- local needPrincess = false
- s = peripheral.wrap("right")
- -- Scores for all bees
- -- Mundane Bees
- beeTable["Forest"] = 1
- beeTable["Meadows"] = 1
- beeTable["Modest"] = 2
- beeTable["Tropical"] = 2
- beeTable["Wintry"] = 2
- beeTable["Marshy"] = 2
- beeTable["Embittered"] = 2
- -- End Branch
- beeTable["Ender"] = 2
- -- Common Branch
- beeTable["Common"] = 2
- beeTable["Cultivated"] = 4
- -- Noble Branch
- beeTable["Noble"] = 8
- beeTable["Majestic"] = 16
- beeTable["Imperial"] = 32
- -- Industrious Branch
- beeTable["Diligent"] = 8
- beeTable["Unweary"] = 16
- beeTable["Industrious"] = 32
- -- Heroic Branch
- beeTable["Steadfast"] = 8
- beeTable["Valiant"] = 16
- beeTable["Heroic"] = 32
- -- Infernal Branch
- beeTable["Sinister"] = 8
- beeTable["Fiendish"] = 16
- beeTable["Demonic"] = 32
- -- Austere Branch
- beeTable["Frugal"] = 16
- beeTable["Austere"] = 32
- -- Tropical Branch
- beeTable["Exotic"] = 16
- beeTable["Edenic"] = 32
- -- Wintry Branch
- beeTable["Icy"] = 16
- beeTable["Glacial"] = 32
- beeTable["Frigid"] = 16
- beeTable["Absolute"] = 32
- -- Festive Branch
- beeTable["Leporine"] = 32
- beeTable["Merry"] = 32
- beeTable["Tipsy"] = 32
- beeTable["Celebratory"] = 64
- -- Agrarian Branch
- beeTable["Rural"] = 8
- beeTable["Farmed"] = 16
- -- Boggy Branch
- beeTable["Swamp"] = 16
- beeTable["Boggy"] = 32
- beeTable["Fungal"] = 64
- -- Extra Bees
- -- Agricultural Branch
- beeTable["Fermented"] = 16
- beeTable["Bovine"] = 16
- beeTable["Caffeine"] = 16
- beeTable["Citrus"] = 32
- beeTable["Minty"] = 32
- -- Barren Branch
- beeTable["Arid"] = 8
- beeTable["Barren"] = 16
- beeTable["Desolate"] = 32
- -- Hostile Branch
- beeTable["Decaying"] = 64
- beeTable["Skeletal"] = 64
- beeTable["Creepy"] = 64
- -- Rocky Branch
- beeTable["Rocky"] = 2
- beeTable["Tolerant"] = 8
- beeTable["Hardy"] = 16
- beeTable["Resilient"] = 32
- -- Rusty Branch
- beeTable["Rusty"] = 64
- beeTable["Corroded"] = 64
- beeTable["Tarnished"] = 64
- beeTable["Leaden"] = 64
- -- Metallic Branch
- beeTable["Lustered"] = 64
- beeTable["Galvanized"] = 128
- beeTable["Invincible"] = 64
- -- Alloyed Branch
- beeTable["Impregnable"] = 64
- beeTable["Resolute"] = 128
- beeTable["Brazen"] = 256
- beeTable["Fortified"] = 128
- beeTable["Lustrous"] = 64
- -- Precious Branch
- beeTable["Shining"] = 128
- beeTable["Glittering"] = 256
- beeTable["Precious"] = 512
- beeTable["Valuable"] = 512
- -- Mineral Branch
- beeTable["Lapis"] = 64
- beeTable["Sodalite"] = 128
- beeTable["Pyrite"] = 128
- beeTable["Bauxite"] = 64
- beeTable["Cinnabar"] = 64
- beeTable["Sphalerite"] = 128
- -- Gemstone Branch
- beeTable["Emerald"] = 128
- beeTable["Ruby"] = 256
- beeTable["Sapphire"] = 256
- beeTable["Olivine"] = 256
- beeTable["Diamond"] = 512
- -- Nuclear Branch
- beeTable["Unstable"] = 64
- beeTable["Nuclear"] = 128
- beeTable["Radioactive"] = 256
- -- Historic Branch
- beeTable["Ancient"] = 16
- beeTable["Primeval"] = 32
- beeTable["Prehistoric"] = 64
- beeTable["Relic"] = 128
- -- Fossilized Branch
- beeTable["Fossiled"] = 64
- beeTable["Resinous"] = 64
- beeTable["Oily"] = 64
- beeTable["Preserved"] = 64
- -- Refined Branch
- beeTable["Distilled"] = 128
- beeTable["Refined"] = 256
- beeTable["Tarry"] = 512
- beeTable["Elastic"] = 512
- -- Aquatic Branch
- beeTable["Water"] = 2
- beeTable["River"] = 8
- beeTable["Ocean"] = 8
- beeTable["Stained"] = 16
- -- Saccharine Branch
- beeTable["Sweetened"] = 16
- beeTable["Sugary"] = 32
- beeTable["Fruity"] = 64
- -- Classical Branch
- beeTable["Marbled"] = 2
- beeTable["Gothic"] = 64
- beeTable["Renaissance"] = 128
- beeTable["Classical"] = 256
- -- Volcanic Branch
- beeTable["Angry"] = 16
- beeTable["Furious"] = 32
- beeTable["Volcanic"] = 64
- beeTable["Glowering"] = 64
- -- Viscous Branch
- beeTable["Viscous"] = 32
- beeTable["Glutinous"] = 64
- beeTable["Sticky"] = 128
- -- Virulent Branch
- beeTable["Malicious"] = 16
- beeTable["Infectious"] = 32
- beeTable["Virulent"] = 64
- -- Caustic Branch
- beeTable["Corrosive"] = 128
- beeTable["Caustic"] = 256
- beeTable["Acidic"] = 512
- -- Energetic Branch
- beeTable["Excited"] = 32
- beeTable["Energetic"] = 64
- beeTable["Ecstatic"] = 128
- -- Shadow Branch
- beeTable["Shadowed"] = 64
- beeTable["Darkened"] = 128
- beeTable["Abyssmal"] = 256
- -- Primary Branch
- beeTable["Maroon"] = 32
- beeTable["Saffron"] = 32
- beeTable["Prussian"] = 32
- beeTable["Natural"] = 32
- beeTable["Ebony"] = 32
- beeTable["Bleached"] = 32
- beeTable["Sepia"] = 32
- -- Secondary Branch
- beeTable["Amber"] = 64
- beeTable["Turquoise"] = 64
- beeTable["Indigo"] = 64
- beeTable["Slate"] = 64
- beeTable["Azure"] = 64
- beeTable["Lavender"] = 64
- beeTable["Lime"] = 64
- -- Tertiary Branch
- beeTable["Fuchsia"] = 128
- beeTable["Ashen"] = 128
- -- Hungry Branch
- beeTable["Hungry"] = 16
- beeTable["Starved"] = 32
- beeTable["Ravenous"] = 64
- -- Confused Branch
- beeTable["Dazed"] = 64
- beeTable["Irrational"] = 128
- beeTable["Delirious"] = 256
- -- Forestry Branch
- beeTable["Pulped"] = 32
- beeTable["Spoiled"] = 64
- beeTable["Decomposed"] = 128
- -- Wooden Branch
- beeTable["Wooden"] = 16
- beeTable["Lumbered"] = 32
- beeTable["Timbered"] = 64
- -- Beastly Branch
- beeTable["Jaded"] = 256
- -- Thaumic Bees
- -- Arcane Branch
- beeTable["Esoteric"] = 64
- beeTable["Mysterious"] = 128
- beeTable["Arcane"] = 256
- -- Supernatural Branch
- beeTable["Charmed"] = 32
- beeTable["Enchanted"] = 64
- beeTable["Supernatural"] = 128
- -- Scholarly Branch
- beeTable["Pupil"] = 512
- beeTable["Scholarly"] = 1024
- beeTable["Savant"] = 2048
- -- Thaumic Branch
- beeTable["Stark"] = 512
- beeTable["Aura"] = 1024
- beeTable["Ignis"] = 1024
- beeTable["Aqua"] = 1024
- beeTable["Solum"] = 1024
- beeTable["Praecantatio"] = 1024
- -- Skulking Branch
- beeTable["Skulking"] = 256
- beeTable["Brainy"] = 512
- beeTable["Gossamer"] = 512
- beeTable["Wispy"] = 1024
- beeTable["Batty"] = 512
- beeTable["Ghastly"] = 512
- -- Aware Branch
- beeTable["Aware"] = 64
- beeTable["Vis"] = 128
- beeTable["Pure"] = 256
- beeTable["Flux"] = 256
- beeTable["Node"] = 512
- beeTable["Rejuvenating"] = 256
- -- Time Branch
- beeTable["Timely"] = 128
- beeTable["Lordly"] = 256
- beeTable["Doctoral"] = 512
- -- Soulful Branch
- beeTable["Spirit"] = 128
- beeTable["Soul"] = 256
- -- Alchemical Branch
- beeTable["Minium"] = 256
- -- Metallic Branch
- beeTable["Iron"] = 64
- beeTable["Copper"] = 64
- beeTable["Tin"] = 64
- beeTable["Silver"] = 64
- beeTable["Lead"] = 64
- beeTable["Gold"] = 128
- -- Gem Branch
- beeTable["Diamond"] = 512
- beeTable["Emerald"] = 128
- -- Fleshy Branch
- beeTable["Poultry"] = 512
- beeTable["Beefy"] = 512
- beeTable["Porcine"] = 512
- -- Only scores species that you specify on the command line
- local targeting = false
- local targetFound = false
- if #targetSpecies > 0 then
- for key, value in pairs(beeTable) do
- targetFound = false
- for i, target in ipairs(targetSpecies) do
- if key == target then
- print("Targeting "..key.." species.")
- targeting = true
- targetFound = true
- break
- end
- end
- if not targetFound then
- beeTable[key] = 0
- end
- end
- if not targeting then
- print("Did not find target species")
- return
- end
- end
- -- Fix for some versions returning bees.species.*
- function fixName(name)
- return name:gsub("bees%.species%.",""):gsub("^.", string.upper)
- end
- toleranceTable["NONE"] = 0
- toleranceTable["UP_1"] = 1
- toleranceTable["UP_2"] = 2
- toleranceTable["DOWN_1"] = 1
- toleranceTable["DOWN_2"] = 2
- toleranceTable["BOTH_1"] = 2
- toleranceTable["BOTH_2"] = 4
- toleranceString["NONE"] = " "
- toleranceString["UP_1"] = " +1 "
- toleranceString["UP_2"] = " +2 "
- toleranceString["DOWN_1"] = " -1 "
- toleranceString["DOWN_2"] = " -2 "
- toleranceString["BOTH_1"] = "+-1 "
- toleranceString["BOTH_2"] = "+-2 "
- function getBees()
- io.write("waiting for bees.")
- -- catalog bees in own inventory
- local free = {}
- for i = 1,16 do
- turtle.select(i)
- if turtle.getItemCount(i) > 0 then
- countBees = countBees + 1
- if #free > 0 then
- j = table.remove(free, 1)
- turtle.transferTo(j)
- table.insert(free, i)
- end
- else
- table.insert(free, i)
- end
- end
- -- get any bees from apiary
- if countBees < 2 or needPrincess then
- turtle.select(1)
- while not turtle.suck() do
- sleep(10)
- io.write(".")
- end
- countBees = countBees + 1
- end
- for i = 1,6 do
- if turtle.suck() then countBees = countBees + 1 end
- end
- print()
- end
- function returnBees()
- turtle.select(princess)
- s.dropSneaky(1,1)
- turtle.select(bestDrone)
- s.dropSneaky(0,1)
- end
- function ditchCombs()
- turtle.turnLeft()
- m = peripheral.wrap("front")
- for i = 1,8 do
- turtle.suck()
- while (not m.isBee()) and (turtle.getItemCount(i) > 0) do
- turtle.select(i)
- turtle.drop()
- if not m.isBee() then
- turtle.suck()
- turtle.dropDown()
- turtle.select(countBees)
- turtle.transferTo(i, 1)
- countBees = countBees - 1
- end
- end
- end
- turtle.turnRight()
- end
- function scanBees()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, countBees do
- turtle.select(i)
- turtle.drop()
- end
- end
- function determineBest(slot)
- local primScore = beeTable[data["speciesPrimary"]]
- local secScore = beeTable[data["speciesSecondary"]]
- if primScore == nil or secScore == nil then
- needsUpdate = data["speciesPrimary"]..":"..data["speciesSecondary"]
- end
- primScore = (primScore ~= nil and primScore or 0)
- secScore = (secScore ~= nil and secScore or 0)
- local useNew = false
- local score = 0
- score = primScore + secScore
- if(bestDrone == 0) then
- useNew = true
- else
- if (score > currScore) then
- useNew = true
- elseif (score == currScore) then
- if data["fertility"] > currData["fertility"] then
- useNew = true
- elseif data["fertility"] < currData["fertility"] then
- useNew = false
- elseif data["speed"] > currData["speed"] then
- useNew = true
- elseif data["speed"] < currData["speed"] then
- useNew = false
- elseif data["nocturnal"] and not currData["nocturnal"] then
- useNew = true
- elseif not data["nocturnal"] and currData["nocturnal"] then
- useNew = false
- elseif data["tolerantFlyer"] and not currData["tolerantFlyer"] then
- useNew = true
- elseif not data["tolerantFlyer"] and currData["tolerantFlyer"] then
- useNew = false
- elseif data["caveDwelling"] and not currData["caveDwelling"] then
- useNew = true
- elseif not data["caveDwelling"] and currData["caveDwelling"] then
- useNew = false
- elseif toleranceTable[data["toleranceTemperature"]] > toleranceTable[currData["toleranceTemperature"]] then
- useNew = true
- elseif toleranceTable[data["toleranceTemperature"]] < toleranceTable[currData["toleranceTemperature"]] then
- useNew = false
- elseif toleranceTable[data["toleranceHumidity"]] > toleranceTable[currData["toleranceHumidity"]] then
- useNew = true
- elseif toleranceTable[data["toleranceHumidity"]] < toleranceTable[currData["toleranceHumidity"]] then
- useNew = false
- end
- end
- end
- if useNew then
- bestDrone = slot
- currScore = score
- currData = data
- end
- return score, useNew
- end
- function log2(num)
- return num == 0 and 0.0 or math.log(num)/math.log(2)
- end
- function analyzeBees()
- print("analyzing "..countBees.." bees...")
- local score = 0
- local useNew = false
- print()
- print("typ species f spd n f c tmp hmd score")
- print("-|-|-------|-|---|-|-|-|---|---|-----")
- for i = 1, countBees do
- turtle.select(i)
- while not s.suckSneaky(0,1) do
- sleep(5)
- end
- turtle.turnRight()
- turtle.drop()
- m = peripheral.wrap("front")
- data = m.analyze()
- data["speciesPrimary"] = fixName(data["speciesPrimary"])
- data["speciesSecondary"] = fixName(data["speciesSecondary"])
- io.write(i.." ")
- if (data["type"] == "princess") then
- princess = i
- princessData = data
- io.write("P ")
- useNew = false
- score = 0
- else
- io.write("d ")
- score, useNew = determineBest(i)
- end
- io.write(data["speciesPrimary"]:gsub("bees%.species%.",""):sub(1,3)..":"..data["speciesSecondary"]:gsub("bees%.species%.",""):sub(1,3).." ")
- io.write(tostring(data["fertility"]).." ")
- io.write(data["speed"] == 1 and "1.0 " or tostring(data["speed"]).." ")
- if data["nocturnal"] then
- io.write("n ")
- else
- io.write(" ")
- end
- if data["tolerantFlyer"] then
- io.write("f ")
- else
- io.write(" ")
- end
- if data["caveDwelling"] then
- io.write("c ")
- else
- io.write(" ")
- end
- io.write(toleranceString[data["toleranceTemperature"]])
- io.write(toleranceString[data["toleranceHumidity"]])
- io.write(string.format("%5.1d", log2(score)).." ")
- if useNew then
- io.write("*")
- droneData = data
- end
- print()
- turtle.suck()
- turtle.turnLeft()
- end
- if princess ~= 0 then
- print("breeding princess ("..princess..") with drone ("..bestDrone..")")
- else
- print("no princess")
- end
- print()
- end
- function dropExcess()
- for i = 1, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- -- Drop same drones so they won't interfere
- function dropDupe()
- for i = 1, countBees do
- turtle.select(i)
- local count = turtle.getItemCount(i)
- if count > 1 then
- print("dropping "..tostring(turtle.getItemCount(i)-1).." excess drones...")
- turtle.dropDown(count - 1)
- end
- end
- turtle.select(1)
- end
- function isPurebred()
- if princessData["speciesPrimary"] ~= princessData["speciesSecondary"] then
- return false
- end
- for key, value in pairs(princessData) do
- if value ~= droneData[key] and key ~= "territory" and key ~= "type" then
- return false
- end
- end
- return true
- end
- ------=============================
- -- clear out system
- while turtle.detect() do
- turtle.turnRight()
- end
- local i = 1
- turtle.select(i)
- while turtle.getItemCount(i) > 0 do
- i = i + 1
- turtle.select(i)
- end
- turtle.turnRight()
- while s.suckSneaky(0,1) do
- i = i + 1
- turtle.select(i)
- end
- turtle.turnRight()
- turtle.suck()
- turtle.turnRight()
- while turtle.suck() do
- end
- -- start breeding loop
- while true do
- currslot = 1
- princess = 0
- bestDrone = 0
- data = {}
- currData = {}
- princessData = {}
- droneData = {}
- countBees = 0
- currScore = 0
- getBees()
- ditchCombs()
- if (turtle.getItemCount(2) > 0) then
- dropDupe()
- scanBees()
- analyzeBees()
- if countBees <= 2 and isPurebred() then
- print("Bees are purebred")
- turtle.turnLeft()
- return
- end
- if needsUpdate == "" then
- turtle.turnRight()
- turtle.turnRight()
- if princess ~= 0 then
- returnBees()
- dropExcess()
- else
- needPrincess = true
- end
- else
- turtle.turnLeft()
- print("Please add new species to bee table: "..needsUpdate)
- return
- end
- end
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement