Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. void findPath2(int sx, int sy, int maxdist, int dungeonset, int width, int height, int cellno)
  2. {
  3. int CellsX[10000];
  4. int CellsY[10000];
  5. int CellsDist[10000];
  6. int MD = DGN[dungeonset];
  7. for (int i = 0; i < 10000; i++)
  8. {
  9. CellsX[i] = -1;
  10. CellsY[i] = -1;
  11. CellsDist[i] = -1;
  12. }
  13. Set2DArray(PathArray, sx, sy, width, height, 0);
  14.  
  15. CellsX[0] = sx;
  16. CellsY[0] = sy;
  17. CellsDist[0] = 0;
  18.  
  19. while (CellsX[0] >= 0) {
  20. int cell = GetLastCell(CellsX);
  21. int fakedir = -1;
  22. if (cell != 0) fakedir = AngleDir8(Angle(CellsX[cell], CellsY[cell], sx, sy));
  23. // See which adjacent cells are open.
  24. bool unmadeCells[8];
  25. if (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell], width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell], width, height) < 9999 && (CellsDist[cell] + 1) < Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell], width, height))) unmadeCells[2] = true;
  26. if (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell], width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell], width, height) < 9999 && (CellsDist[cell] + 1) < Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell], width, height))) unmadeCells[3] = true;
  27. if (Get2DArray(PathArray, CellsX[cell], CellsY[cell] - 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell], CellsY[cell] - 1, width, height) < 9999 && (CellsDist[cell] + 1) < Get2DArray(PathArray, CellsX[cell], CellsY[cell] - 1, width, height))) unmadeCells[0] = true;
  28. if (Get2DArray(PathArray, CellsX[cell], CellsY[cell] + 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell], CellsY[cell] + 1, width, height) < 9999 && (CellsDist[cell] + 1) < Get2DArray(PathArray, CellsX[cell], CellsY[cell] + 1, width, height))) unmadeCells[1] = true;
  29. if (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] - 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] - 1, width, height) < 9999 && (CellsDist[cell] + 1.1) < Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] - 1, width, height))) unmadeCells[4] = true;
  30. if (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] - 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] - 1, width, height) < 9999 && (CellsDist[cell] + 1.1) < Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] - 1, width, height))) unmadeCells[5] = true;
  31. if (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] + 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] + 1, width, height) < 9999 && (CellsDist[cell] + 1.1) < Get2DArray(PathArray, CellsX[cell] - 1, CellsY[cell] + 1, width, height))) unmadeCells[6] = true;
  32. if (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] + 1, width, height) == 9999 || (Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] + 1, width, height) < 9999 && (CellsDist[cell] + 1.1) < Get2DArray(PathArray, CellsX[cell] + 1, CellsY[cell] + 1, width, height))) unmadeCells[7] = true;
  33. if (fakedir == 0) {unmadeCells[1] = false; unmadeCells[6] = false; unmadeCells[7] = false;}
  34. if (fakedir == 1) {unmadeCells[0] = false; unmadeCells[4] = false; unmadeCells[5] = false;}
  35. if (fakedir == 2) {unmadeCells[3] = false; unmadeCells[5] = false; unmadeCells[7] = false;}
  36. if (fakedir == 3) {unmadeCells[1] = false; unmadeCells[4] = false; unmadeCells[6] = false;}
  37. if (fakedir == 4) {unmadeCells[1] = false; unmadeCells[3] = false; unmadeCells[7] = false;}
  38. if (fakedir == 5) {unmadeCells[1] = false; unmadeCells[2] = false; unmadeCells[6] = false;}
  39. if (fakedir == 6) {unmadeCells[0] = false; unmadeCells[3] = false; unmadeCells[5] = false;}
  40. if (fakedir == 7) {unmadeCells[0] = false; unmadeCells[2] = false; unmadeCells[3] = false;}
  41. if (cell == 0 && !unmadeCells[cellno]) return;
  42. if (unmadeCells[0] == true || unmadeCells[1] == true || unmadeCells[2] == true || unmadeCells[3] == true)
  43. {
  44. for (int i = 0; i< 4; i++)
  45. {
  46. if (unmadeCells[i] == true)
  47. {
  48. CellsX[cell + 1] = CellsX[cell] + GetDirectionalX(i);
  49. CellsY[cell + 1] = CellsY[cell] + GetDirectionalY(i);
  50. CellsDist[cell + 1] = CellsDist[cell] + 1;
  51. Set2DArray(PathArray, CellsX[cell + 1], CellsY[cell + 1], width, height, CellsDist[cell + 1]);
  52. }
  53. }
  54. }
  55. else if (unmadeCells[4] == true || unmadeCells[5] == true || unmadeCells[6] == true || unmadeCells[7] == true)
  56. {
  57. for (int i = 4; i< 8; i++)
  58. {
  59. if (unmadeCells[i] == true)
  60. {
  61. CellsX[cell + 1] = CellsX[cell] + GetDirectionalX(i);
  62. CellsY[cell + 1] = CellsY[cell] + GetDirectionalY(i);
  63. CellsDist[cell + 1] = CellsDist[cell] + 1.1;
  64. Set2DArray(PathArray, CellsX[cell + 1], CellsY[cell + 1], width, height, CellsDist[cell + 1]);
  65. }
  66. }
  67. }
  68. else {
  69. // No adjacent uncarved cells.
  70. CellsX[cell] = -1;
  71. CellsY[cell] = -1;
  72. CellsDist[cell] = -1;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement