Advertisement
Guest User

wedge.lua

a guest
Aug 22nd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. local partnerID=0
  2. local debug=false
  3.  
  4. --Constants
  5. local MY_ID              = os.getComputerID()
  6. local CHARGE_LEVEL       = 500
  7. local RESERVE_FUEL_LEVEL = 10
  8. local TESSERACT          = 1
  9. local CONDUIT            = 2
  10. local DIG_DELAY          = 1
  11. local FUEL               = 16
  12. local FUEL_DELAY         = 10
  13. local FUEL_RATION        = 4
  14.  
  15. function checkFuel()
  16.     if(turtle.getFuelLevel() < RESERVE_FUEL_LEVEL) then
  17.         print("\t->Fuel: FAILURE")
  18.         print("\t\tOut of fuel, attempting refuel")
  19.         refuel()
  20.     end
  21. end
  22. function checkStatus()
  23.     print("----------Checking Wedges's Schedule----------")
  24.  
  25.     if (turtle.getItemCount(TESSERACT) < 1) then
  26.         print("\t->Tesseract: FAILURE")
  27.         print("\t\tPlease insert Tesseract into slot 1")
  28.  
  29.         turtle.select(TESSERACT)
  30.         while (turtle.getItemCount(TESSERACT) == 0) do
  31.             sleep(1)
  32.         end
  33.     end
  34.     print("\t->Tesseract: OK")
  35.  
  36.     if (turtle.getItemCount(CONDUIT) < 1) then
  37.  
  38.         print("\t->Conduit: FAILURE")
  39.         print("\t\tPlease insert conduit into slot 2")
  40.        
  41.         turtle.select(CONDUIT)
  42.         while (turtle.getItemCount(CONDUIT) == 0) do
  43.             sleep(1)
  44.         end
  45.     end
  46.     print("\t->Conduit: OK")
  47.  
  48.     checkFuel()
  49.     print("-------------WEDGE READY TO ROLL-------------")
  50.  
  51. end
  52.  
  53. function pairWithBiggs()
  54.     rednet.open("right")
  55.  
  56.     rednet.broadcast("Waiting to pair with partner")
  57.     local id, msg, distance
  58.     while (id==nil or id==MY_ID) do
  59.         id, msg, distance = rednet.receive()
  60.     end
  61.  
  62.     partnerID = id
  63.     rednet.broadcast("Partner found")
  64. end
  65.  
  66. function sendMessageToBiggs(message)
  67.     rednet.send(partnerID,message)
  68. end
  69.  
  70. function powerDown()
  71.  
  72.     turtle.select(TESSERACT)
  73.     while(turtle.placeDown()==false)do
  74.         turtle.digDown()
  75.         sleep(DIG_DELAY)
  76.     end
  77.  
  78.     turtle.forward()
  79.  
  80.     turtle.select(CONDUIT)
  81.     while(turtle.placeDown()==false)do
  82.         turtle.digDown()
  83.         sleep(DIG_DELAY)
  84.     end    
  85.  
  86.     sendMessageToBiggs("powerdown")
  87. end
  88.  
  89. function powerUp()
  90.    
  91.     turtle.select(CONDUIT)
  92.     turtle.digDown()
  93.  
  94.     turtle.back()
  95.  
  96.     turtle.select(TESSERACT)
  97.     turtle.digDown()
  98.  
  99.     sendMessageToBiggs("powerup")
  100. end
  101.  
  102. function moveForward()
  103.  
  104.     while(turtle.forward()==false) do
  105.         print("ERROR: Problem moving forward!")
  106.     end
  107.  
  108.     sendMessageToBiggs("forward")
  109. end
  110.  
  111. function refuel()
  112.     prevSlot = turtle.getSelectedSlot()
  113.        
  114.     turtle.select(FUEL)
  115.     while(turtle.refuel(FUEL_RATION) == false) do
  116.         print("Error: Not enough fuel in slot 16 to refuel! Minimal 4")
  117.         sleep(FUEL_DELAY)
  118.     end
  119.    
  120.     turtle.select(prevSlot)
  121. end
  122.  
  123. function waitForBiggs()
  124.    
  125.     local id, msg, distance
  126.     while (id==nil or id==MY_ID or id ~= partnerID) do
  127.         id, msg, distance = rednet.receive()
  128.     end
  129.  
  130.     if (msg=="powerdown") then
  131.         powerDown()
  132.     elseif (msg=="powerup") then
  133.         powerUp()
  134.     elseif (msg=="forward") then
  135.         moveForward()
  136.     end
  137. end
  138.  
  139. --Check Wedge has the items he needs
  140. checkStatus()
  141.  
  142. --Wait for Biggs to be ready
  143. pairWithBiggs()
  144.  
  145. while(true) do
  146.     --Check we've got enough fuel
  147.     checkFuel()
  148.     --Wait for a command from Biggs
  149.     waitForBiggs()
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement