Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findPath2(int sx, int sy, int maxdist, int dungeonset, int width, int height, int cellno)
- {
- int CellsX[10000];
- int CellsY[10000];
- int CellsDist[10000];
- int MD = DGN[dungeonset];
- for (int i = 0; i < 10000; i++)
- {
- CellsX[i] = -1;
- CellsY[i] = -1;
- CellsDist[i] = -1;
- }
- Set2DArray(PathArray, sx, sy, width, height, 0);
- CellsX[0] = sx;
- CellsY[0] = sy;
- CellsDist[0] = 0;
- while (CellsX[0] >= 0) {
- int cell = GetLastCell(CellsX);
- int fakedir = -1;
- if (cell != 0) fakedir = AngleDir8(Angle(CellsX[cell], CellsY[cell], sx, sy));
- // See which adjacent cells are open.
- bool unmadeCells[8];
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- 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;
- if (fakedir == 0) {unmadeCells[1] = false; unmadeCells[6] = false; unmadeCells[7] = false;}
- if (fakedir == 1) {unmadeCells[0] = false; unmadeCells[4] = false; unmadeCells[5] = false;}
- if (fakedir == 2) {unmadeCells[3] = false; unmadeCells[5] = false; unmadeCells[7] = false;}
- if (fakedir == 3) {unmadeCells[1] = false; unmadeCells[4] = false; unmadeCells[6] = false;}
- if (fakedir == 4) {unmadeCells[1] = false; unmadeCells[3] = false; unmadeCells[7] = false;}
- if (fakedir == 5) {unmadeCells[1] = false; unmadeCells[2] = false; unmadeCells[6] = false;}
- if (fakedir == 6) {unmadeCells[0] = false; unmadeCells[3] = false; unmadeCells[5] = false;}
- if (fakedir == 7) {unmadeCells[0] = false; unmadeCells[2] = false; unmadeCells[3] = false;}
- if (cell == 0 && !unmadeCells[cellno]) return;
- if (unmadeCells[0] == true || unmadeCells[1] == true || unmadeCells[2] == true || unmadeCells[3] == true)
- {
- for (int i = 0; i< 4; i++)
- {
- if (unmadeCells[i] == true)
- {
- CellsX[cell + 1] = CellsX[cell] + GetDirectionalX(i);
- CellsY[cell + 1] = CellsY[cell] + GetDirectionalY(i);
- CellsDist[cell + 1] = CellsDist[cell] + 1;
- Set2DArray(PathArray, CellsX[cell + 1], CellsY[cell + 1], width, height, CellsDist[cell + 1]);
- }
- }
- }
- else if (unmadeCells[4] == true || unmadeCells[5] == true || unmadeCells[6] == true || unmadeCells[7] == true)
- {
- for (int i = 4; i< 8; i++)
- {
- if (unmadeCells[i] == true)
- {
- CellsX[cell + 1] = CellsX[cell] + GetDirectionalX(i);
- CellsY[cell + 1] = CellsY[cell] + GetDirectionalY(i);
- CellsDist[cell + 1] = CellsDist[cell] + 1.1;
- Set2DArray(PathArray, CellsX[cell + 1], CellsY[cell + 1], width, height, CellsDist[cell + 1]);
- }
- }
- }
- else {
- // No adjacent uncarved cells.
- CellsX[cell] = -1;
- CellsY[cell] = -1;
- CellsDist[cell] = -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement