ravneravn

bee breeder

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