int main() { printf("Initial stage:\n"); Display(); SeekPath(maxstep);//print all possible paths getchar(); return 0; }
bool PathFindingAI(int NpcIndex) { bool retval = true; /* '*************************************************** */ /* 'Author: Gulfas Morgolock */ /* 'Last Modification: - */ /* 'This function seeks the shortest path from the Npc */ /* 'to the user's location. */ /* '*************************************************** */ int Y; int X; /* 'Makes a loop that looks at */ for (Y = (Npclist[NpcIndex].Pos.Y - 10); Y <= (Npclist[NpcIndex].Pos.Y + 10); Y++) { /* '5 tiles in every direction */ for (X = (Npclist[NpcIndex].Pos.X - 10); X <= (Npclist[NpcIndex].Pos.X + 10); X++) { /* 'Make sure tile is legal */ if (X > MinXBorder && X < MaxXBorder && Y > MinYBorder && Y < MaxYBorder) { /* 'look for a user */ if (MapData[Npclist[NpcIndex].Pos.Map][X][Y].UserIndex > 0) { /* 'Move towards user */ int tmpUserIndex; tmpUserIndex = MapData[Npclist[NpcIndex].Pos.Map][X][Y].UserIndex; if (UserList[tmpUserIndex].flags.Muerto == 0 && UserList[tmpUserIndex].flags.invisible == 0 && UserList[tmpUserIndex].flags.Oculto == 0 && UserList[tmpUserIndex].flags.AdminPerseguible) { Npclist[NpcIndex].PFINFO.Target.X = UserList[tmpUserIndex].Pos.X; Npclist[NpcIndex].PFINFO.Target.Y = UserList[tmpUserIndex].Pos.Y; Npclist[NpcIndex].PFINFO.TargetUser = tmpUserIndex; SeekPath(NpcIndex); return retval; } } } } } return retval; }
void SeekPath(int stepleft) { DuplicatePos(stepleft, 'b'); int i = 0, j = 0, k = 0, l = 0, x = 0, y = 0, activeCount = 0; //int o, p;//more spaces involved for (x = 0;x <= y;x++) { DuplicatePos(stepleft + maxstep, 'b'); Compare(x, 0, stepleft, 1); if (stepleft > 0) { DuplicatePos((stepleft + maxstep + maxstep), 'b'); for (i = 1;i <= maxlength;i++) { for (j = 1;j <= (int)pow(2, i);j++) { if (pos[0][i][j] == 0) continue; else { Detach(i, j); DuplicatePos(stepleft + maxstep + maxstep + maxstep, 'b'); for (k = 1;k <= maxlength;k++)//k = 0 need to examine { for (l = 1;l <= (int)pow(2, k);l++) { if (pos[0][k][l] < 1 && pos[0][k - 1][(l + 1) / 2] >= 1) { if (l % 2 == 1 && pos[0][k][l] == 0) { Attach(k, l); //printf("\n1step%d %d,%d ---> %d,%d:\n", maxstep + 1 - stepleft, i, j, k, l); //Display(); if (stepleft > 1) { SaveStep(i, j, k, l, x, stepleft); Compare(x, 0, stepleft, 0); //printf("1"); SeekPath(stepleft - 1); } else { activeCount = Active(1); SaveStep(i, j, k, l, x, stepleft); Compare(x, activeCount, stepleft, 0); //printf("1"); } } else if (l % 2 == 0 && pos[0][k][l - 1] >= 1 && pos[0][k][l - 1] != 2 && pos[1][0][1] != 2) { if (pos[0][k][l] == -1)//case 1 -1 ---> 1 1 { SideSwitch(k, l - 1); Attach(k, l - 1); //printf("\n2step%d %d,%d ---> %d,%d:\n", maxstep + 1 - stepleft, i, j, k, l - 1); //Display(); if (stepleft > 1) { SaveStep(i, j, k, l - 1, x, stepleft); Compare(x, 0, stepleft, 0); //printf("2"); SeekPath(stepleft - 1); } else { activeCount = Active(1); SaveStep(i, j, k, l - 1, x, stepleft); Compare(x, activeCount, stepleft, 0); //printf("2"); } } else if (pos[0][k][l] == -2)//case 1 -2 ---> 1 1 { Attach(k, l); //printf("\n3step%d %d,%d ---> %d,%d:\n", maxstep + 1 - stepleft, i, j, k, l); //Display(); if (stepleft > 1) { SaveStep(i, j, k, l, x, stepleft); Compare(x, 0, stepleft, 0); //printf("3"); SeekPath(stepleft - 1); } else { activeCount = Active(1); SaveStep(i, j, k, l, x, stepleft); Compare(x, activeCount, stepleft, 0); //printf("3"); } } else if (pos[0][k][l] == 0)//case 1 0 ---> 1 1 ,two ways to attach, left and right { //attach left SideSwitch(k, l - 1); Attach(k, l - 1); //printf("\n4step%d %d,%d ---> %d,%d:\n", maxstep + 1 - stepleft, i, j, k, l - 1); //Display(); if (stepleft > 1) { SaveStep(i, j, k, l - 1, x, stepleft); Compare(x, 0, stepleft, 0); //printf("4"); SeekPath(stepleft - 1); } else { activeCount = Active(1); SaveStep(i, j, k, l - 1, x, stepleft); Compare(x, activeCount, stepleft, 0); //printf("4"); } DuplicatePos(stepleft + maxstep + maxstep + maxstep, 'r'); //attach right Attach(k, l); //printf("\n5step%d %d,%d ---> %d,%d:\n", maxstep + 1 - stepleft, i, j, k, l); //Display(); if (stepleft > 1) { SaveStep(i, j, k, l, x, stepleft); Compare(x, 0, stepleft, 0); //printf("5"); SeekPath(stepleft - 1); } else { activeCount = Active(1); SaveStep(i, j, k, l, x, stepleft); Compare(x, activeCount, stepleft, 0); //printf("5"); } } } DuplicatePos(stepleft + maxstep + maxstep + maxstep, 'r'); } } } DuplicatePos(stepleft + maxstep + maxstep, 'r'); } } } } DuplicatePos(stepleft + maxstep, 'r'); y += Active(0); } }