Advertisement
Guest User

Bees

a guest
Apr 7th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.56 KB | None | 0 0
  1. -- BeeAnalyzer 3.0
  2. -- Original code by Direwolf20
  3. -- Hotfix 1 by Mandydax
  4. -- Hotfix 2 by Mikeyhun/MaaadMike
  5.  
  6. local currslot = 1
  7. local princess = 0
  8. local bestDrone = 0
  9. local data=""
  10. local countBees = 0
  11. local beeTable = {}
  12. local currScore = 0
  13.  
  14. s = peripheral.wrap("right")
  15.  
  16. function regTable()
  17.    beeTable["bees.species.industrious"] = 31
  18.    beeTable["bees.species.imperial"] = 30
  19.    beeTable["bees.species.unweary"] = 21
  20.    beeTable["bees.species.majestic"] = 20
  21.    beeTable["bees.species.diligent"] = 11
  22.    beeTable["bees.species.noble"] = 10
  23.    beeTable["bees.species.cultivated"] = 6
  24.    beeTable["bees.species.common"] = 5
  25.    beeTable["bees.species.forest"] = 1
  26.    beeTable["bees.species.meadows"] = 1
  27. end  
  28.  
  29. function getBees()
  30.    turtle.select(1)
  31.    for i = 1,6 do
  32.      if turtle.suck() then countBees = countBees + 1 end
  33.    end
  34. end
  35.  
  36. function returnBees()
  37.    turtle.turnRight()
  38.    turtle.turnRight()
  39.    turtle.select(princess)
  40.    s.dropSneaky(1,1)
  41.    turtle.select(bestDrone)
  42.    s.dropSneaky(0,1)
  43. end
  44.  
  45. function ditchCombs()  
  46.    turtle.turnLeft()
  47.    m = peripheral.wrap("front")
  48.    for i = 1,8 do
  49.      turtle.suck()
  50.      while (not m.isBee()) and (turtle.getItemCount(i) > 0) do
  51.      turtle.select(i)
  52.      turtle.drop()
  53.      if not m.isBee() then
  54.         print("Gotta ditch the combs!")
  55.         turtle.suck()
  56.         turtle.dropDown()
  57.         turtle.select(countBees)
  58.         turtle.transferTo(i, 1)
  59.         countBees = countBees - 1
  60.      end
  61.    end
  62.    end
  63. end
  64.  
  65. function scanBees()
  66.    turtle.turnLeft()
  67.    for i = 1, countBees do
  68.      turtle.select(i)
  69.      turtle.drop()
  70.    end
  71.    print("Sleeping for a minute while the bee scans")
  72.    sleep(26)
  73. end
  74.  
  75. function determineBest(slot)
  76.    local primScore = (beeTable[data["speciesPrimary"]] ~= nil and beeTable[data["speciesPrimary"]] or 0)
  77.    local secScore = (beeTable[data["speciesSecondary"]] ~= nil and beeTable[data["speciesSecondary"]] or 0)
  78.    score = primScore + secScore
  79.    print("Current: "..currScore)
  80.    if primScore == 0 and secScore == 0 then print("Warning bee species not in registry table! Evalutaing as 0!") end
  81.    print("NewScore: "..score)
  82.    if(bestDrone == 0) then
  83.      bestDrone = slot
  84.      currScore = score
  85.    else
  86.      if (score > currScore) then
  87.        bestDrone = slot
  88.        currScore = score
  89.      end
  90.    end  
  91. end
  92.  
  93. function analyzeBees()
  94.   for i = 1, countBees do
  95.     turtle.select(i)
  96.     s.suckSneaky(0,1)
  97.     turtle.turnRight()
  98.     turtle.drop()
  99.     m = peripheral.wrap("front")
  100.     data = m.analyze()
  101.     if (data["type"] == "princess") then
  102.       princess = i
  103.       print("Princess = "..i)
  104.     else
  105.       determineBest(i)
  106.     end
  107.     print(data["speciesPrimary"]..":"..data["speciesSecondary"])
  108.     print("BestDrone = "..bestDrone)
  109.     turtle.suck()
  110.     turtle.turnLeft()
  111.     if i ~= countBees then sleep(26) end
  112.    end
  113. end
  114.  
  115.  
  116. function dropExcess()
  117.   for i = 1, 16 do
  118.     turtle.select(i)
  119.     turtle.dropDown()
  120.    end  
  121. end
  122.  
  123. -- Drop same drones so they won't interfere
  124. function dropDupe()
  125.   for i = 1, countBees do
  126.     turtle.select(i)
  127.     local count = turtle.getItemCount(i)
  128.     if count > 1 then
  129.       print("Dropping excess drones.")
  130.       turtle.dropDown(count - 1)
  131.     end
  132.   end
  133.   turtle.select(1)
  134. end
  135. ------=============================
  136.  
  137. currslot = 1
  138. princess = 0
  139. bestDrone = 0
  140. data=""
  141. countBees = 0
  142. beeTable = {}
  143. currScore = 0
  144.  
  145. regTable()
  146. dropExcess()
  147. getBees()
  148. if (turtle.getItemCount(2) > 0) then
  149.    ditchCombs()
  150.    dropDupe()
  151.    scanBees()
  152.    analyzeBees()
  153.    returnBees()
  154.    dropExcess()
  155. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement