solidity

mine controller

Dec 19th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. -- mine drone controller
  2.  
  3. rednet.close("right")
  4. rednet.open("right")
  5.  
  6. print("start digging at X = ")
  7. local xDig = read() -- 494
  8. print("start digging at Z = ")
  9. local zDig = read() -- 1140
  10. print("drop stuff at X = ")
  11. local xDrop = read() -- 487
  12. print("drop stuff at Y = ")
  13. local yDrop = read() -- 64
  14. print("drop stuff at Z = ")
  15. local zDrop = read() -- 1121
  16. print("drop stuff at F = ")
  17. local fDrop = read() -- 3
  18. print("how many digs in X direction?")
  19. local maxX = read()
  20. print("how many digs in Z direction?")
  21. local maxZ = read()
  22. maxX = maxX - 1
  23. maxZ = maxZ - 1
  24. local args = {xDig, zDig, xDrop, yDrop, zDrop, fDrop}
  25.  
  26. local waitList = {}
  27.  
  28. --local digSpots = {{0,0},{2,1},{4,2},{3,4},{1,3}}
  29.  
  30. for X = 0,maxX do
  31.     args[1] = xDig + X * 5
  32.     for Z = 0,maxZ do
  33.         args[2] = zDig + Z * 5
  34.         msg = ""
  35.         print("mine controller ready, next spot will be "..args[1].." "..args[2])
  36.         repeat
  37.             id, msg, _ = rednet.receive()
  38.         until msg == "drone ready"
  39.         if msg == "drone ready" then
  40.             print("drone "..id.." reports in, sending job at "..args[1].." "..args[2])
  41.             local curId = id
  42.             rednet.send(id, "mine at")
  43.             for i = 1,6 do
  44.                 id, msg, _ = rednet.receive()
  45.                 if (id == curId) and msg == "ack" then
  46.                     rednet.send(id, tostring(args[i]))
  47.                 else
  48.                     rednet.send(id, "wait")
  49.                     i = i - 1
  50.                 end
  51.             end
  52.         end
  53.         id, msg, _ = rednet.receive()
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment