Guest User

Untitled

a guest
Jun 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. public static boolean canReach(final int startX, final int startY,
  2. final int destX, final int destY, final boolean isObject) {
  3. // Documentation part:
  4. // The blocks info
  5. // When you can walk freely it's 0, also used to create a noclip
  6. final int[][] via = new int[104][104];
  7. final int[][] cost = new int[104][104];
  8. final int[] tileQueueX = new int[4000];
  9. final int[] tileQueueY = new int[4000];
  10.  
  11. for (int xx = 0; xx < 104; xx++) {
  12. for (int yy = 0; yy < 104; yy++) {
  13. via[xx][yy] = 0;
  14. cost[xx][yy] = 99999999;
  15. }
  16. }
  17.  
  18. int curX = startX;
  19. int curY = startY;
  20. via[startX][startY] = 99;
  21. cost[startX][startY] = 0;
  22. int head = 0;
  23. int tail = 0;
  24. tileQueueX[head] = startX;
  25. tileQueueY[head] = startY;
  26. head++;
  27. final int pathLength = tileQueueX.length;
  28. final int blocks[][] = Bot.getClient().getGroundDataArray()[Bot
  29. .getClient().getPlane()].getBlocks();
  30. while (tail != head) {
  31. curX = tileQueueX[tail];
  32. curY = tileQueueY[tail];
  33.  
  34. if (!isObject && curX == destX && curY == destY) {
  35. return true;
  36. } else if (isObject) {
  37. if (curX == destX && curY == destY + 1 || curX == destX
  38. && curY == destY - 1 || curX == destX + 1
  39. && curY == destY || curX == destX - 1 && curY == destY) {
  40. return true;
  41. }
  42. }
  43. tail = (tail + 1) % pathLength;
  44.  
  45. // Big and ugly block of code
  46. final int thisCost = cost[curX][curY] + 1;
  47. // Can go south (by determining, whether the north side of the
  48. // south tile is blocked :P)
  49. if (curY > 0 && via[curX][curY - 1] == 0
  50. && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  51. tileQueueX[head] = curX;
  52. tileQueueY[head] = curY - 1;
  53. head = (head + 1) % pathLength;
  54. via[curX][curY - 1] = 1;
  55. cost[curX][curY - 1] = thisCost;
  56. }
  57. // Can go west
  58. if (curX > 0 && via[curX - 1][curY] == 0
  59. && (blocks[curX - 1][curY] & 0x1280108) == 0) {
  60. tileQueueX[head] = curX - 1;
  61. tileQueueY[head] = curY;
  62. head = (head + 1) % pathLength;
  63. via[curX - 1][curY] = 2;
  64. cost[curX - 1][curY] = thisCost;
  65. }
  66. // Can go north
  67. if (curY < 104 - 1 && via[curX][curY + 1] == 0
  68. && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  69. tileQueueX[head] = curX;
  70. tileQueueY[head] = curY + 1;
  71. head = (head + 1) % pathLength;
  72. via[curX][curY + 1] = 4;
  73. cost[curX][curY + 1] = thisCost;
  74. }
  75. // Can go east
  76. if (curX < 104 - 1 && via[curX + 1][curY] == 0
  77. && (blocks[curX + 1][curY] & 0x1280180) == 0) {
  78. tileQueueX[head] = curX + 1;
  79. tileQueueY[head] = curY;
  80. head = (head + 1) % pathLength;
  81. via[curX + 1][curY] = 8;
  82. cost[curX + 1][curY] = thisCost;
  83. }
  84. // Can go southwest
  85. if (curX > 0 && curY > 0 && via[curX - 1][curY - 1] == 0
  86. && (blocks[curX - 1][curY - 1] & 0x128010e) == 0
  87. && (blocks[curX - 1][curY] & 0x1280108) == 0
  88. && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  89. tileQueueX[head] = curX - 1;
  90. tileQueueY[head] = curY - 1;
  91. head = (head + 1) % pathLength;
  92. via[curX - 1][curY - 1] = 3;
  93. cost[curX - 1][curY - 1] = thisCost;
  94. }
  95. // Can go northwest
  96. if (curX > 0 && curY < 104 - 1 && via[curX - 1][curY + 1] == 0
  97. && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  98. && (blocks[curX - 1][curY] & 0x1280108) == 0
  99. && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  100. tileQueueX[head] = curX - 1;
  101. tileQueueY[head] = curY + 1;
  102. head = (head + 1) % pathLength;
  103. via[curX - 1][curY + 1] = 6;
  104. cost[curX - 1][curY + 1] = thisCost;
  105. }
  106. // Can go southeast
  107. if (curX < 104 - 1 && curY > 0 && via[curX + 1][curY - 1] == 0
  108. && (blocks[curX + 1][curY - 1] & 0x1280183) == 0
  109. && (blocks[curX + 1][curY] & 0x1280180) == 0
  110. && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  111. tileQueueX[head] = curX + 1;
  112. tileQueueY[head] = curY - 1;
  113. head = (head + 1) % pathLength;
  114. via[curX + 1][curY - 1] = 9;
  115. cost[curX + 1][curY - 1] = thisCost;
  116. }
  117. // can go northeast
  118. if (curX < 104 - 1 && curY < 104 - 1
  119. && via[curX + 1][curY + 1] == 0
  120. && (blocks[curX + 1][curY + 1] & 0x12801e0) == 0
  121. && (blocks[curX + 1][curY] & 0x1280180) == 0
  122. && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  123. tileQueueX[head] = curX + 1;
  124. tileQueueY[head] = curY + 1;
  125. head = (head + 1) % pathLength;
  126. via[curX + 1][curY + 1] = 12;
  127. cost[curX + 1][curY + 1] = thisCost;
  128. }
  129. }
  130. return false;
  131. }
Add Comment
Please, Sign In to add comment