Advertisement
ecco7777

CC Computer Controlled Drawbridge Array

Jun 4th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. function wrapPs(peripheralName)
  2. periTab={}
  3. sideTab={}
  4. if peripheralName==nil then
  5. print("Fehler")
  6. end
  7. local peripherals = peripheral.getNames()
  8. local i2 = 1
  9. for i =1, #peripherals do
  10. if peripheral.getType(peripherals[i])==peripheralName then
  11. periTab[i2]=peripheral.wrap(peripherals[i])
  12. sideTab[i2]=peripherals[i]
  13. i2=i2+1
  14. end
  15. end
  16. if periTab~={} then
  17. return periTab,sideTab
  18. else
  19. return nil
  20. end
  21. end
  22.  
  23. mes={}
  24. for i=1,256 do
  25. mes[i]=peripheral.wrap("tileinterface_"..i+11)
  26. end
  27.  
  28. container=peripheral.wrap("right")
  29. --mes,mesSide=wrapPs("tileinterface")
  30.  
  31. function pullArray(me,height)
  32. for i=1,height do
  33. me.pullItem("up",i)
  34. end
  35. end
  36.  
  37. function pushArray(me,height)
  38. for i=1,height do
  39. me.exportItem(material[i],"up",1)
  40. end
  41. end
  42.  
  43. function scanMaterials()
  44. material={}
  45. for i=1,16 do
  46. if container.getStackInSlot(i)~=nil then
  47. material[i]={id=container.getStackInSlot(i).id,dmg=container.getStackInSlot(i).dmg}
  48. end
  49. end
  50. return material
  51. end
  52.  
  53. function fillAll(height)
  54. for i=1,256 do
  55. pushArray(mes[i],height)
  56. end
  57. end
  58.  
  59. function suckAll(height)
  60. for i=1,256 do
  61. pullArray(mes[i],height)
  62. end
  63. end
  64.  
  65. function init_maze(width, height)
  66.    local result = {}
  67.    for y = 0, height - 1 do
  68.       for x = 0, width - 1 do
  69.          result[y * width + x] = 1
  70.       end
  71.       result[y * width + 0] = 0
  72.       result[y * width + width - 1] = 0
  73.    end
  74.    for x = 0, width - 1 do
  75.       result[0 * width + x] = 0
  76.       result[(height - 1) * width + x] = 0
  77.    end
  78.    return result
  79. end
  80.  
  81. function carve_maze(maze, width, height, x, y)
  82.    local r = math.random(0, 3)
  83.    maze[y * width + x] = 0
  84.    for i = 0, 3 do
  85.       local d = (i + r) % 4
  86.       local dx = 0
  87.       local dy = 0
  88.       if d == 0 then
  89.          dx = 1
  90.       elseif d == 1 then
  91.          dx = -1
  92.       elseif d == 2 then
  93.          dy = 1
  94.       else
  95.          dy = -1
  96.       end
  97.       local nx = x + dx
  98.       local ny = y + dy
  99.       local nx2 = nx + dx
  100.       local ny2 = ny + dy
  101.       if maze[ny * width + nx] == 1 then
  102.          if maze[ny2 * width + nx2] == 1 then
  103.             maze[ny * width + nx] = 0
  104.             carve_maze(maze, width, height, nx2, ny2)
  105.          end
  106.       end
  107.    end
  108. end
  109.  
  110. function fillMaze(height)
  111. maze=init_maze(16,16)
  112. carve_maze(maze, 16, 16, 2, 2)
  113.     for i=0, 255 do
  114.         if maze[i]==1 then
  115.         pushArray(mes[i+1],height)
  116.         end
  117.     end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement