bool Pathfinder(SHIP_PLAYER_FIGHTER_STATHOLDER *ship, int x, int y)
///////////////////////////////////////////////////////////////////
//Pathfinding step for AI
//x and y are absolute, not tile coordinates
//It sets the wnted position on the ship.
///////////////////////////////////////////////////////////////////
{
int count, count2, count3, count4;
bool found; //bool for when target is found
x = x / 16;
y = y / 16;
int my_x = ship->x / 16;
int my_y = ship->y / 16;
int curcount = 1; //The current distance being checked
//First Step: Set arrays
for(count = 0; count < map_size * 1024 / 16; count++)
for(count2 = 0; count2 < map_size * 768 / 16; count2++)
{
//If it is or is near a wall, make it off limits
if(Walls[count][count2].type > 0)
AIPath[count][count2] = 30000;
else
AIPath[count][count2] = -1;
AIChecked[count][count2] = false;
}
//Set the target cell to 0
AIPath[x][y] = 0;
//Assign distance values
//Step 1
//provide known values
for(count = -1; count < 2; count++)
for(count2 = -1; count2 < 2; count2++)
{
//set up areas to be checked for first pass
AIChecked[x + count][y + count2] = true;
}
while(!found)
{
//Cycle through all unchecked tiles
for(count = x - curcount; count < x + curcount + 1; count++)
for(count2 = y - curcount; count2 < y + curcount + 1; count2++)
{
if(AIChecked[count][count2])
{
//This tile should be checked
//Lets get to it
if(AIPath[count][count2] < 30000)//if not a wall
{
if(AIPath[count][count2] == 0)
found = true;
AIPath[count][count2] = curcount; //Set its distance value
AIChecked[count][count2] = false;
//Set everything around it as checked
for(count3 = -1; count3 < 2; count3++)
for(count4 = -1; count4 < 2; count4++)
{
//set up areas to be checked for first pass
if(AIPath[count][count2]<0)
AIChecked[count + count3][count2 + count4] = true;
}
}
}
}
curcount++;
}
//Final step: determine which way to go.
for(count3 = 0; count3 < 5; count3++)
for(count = -1; count < 2; count++)
for(count2 = -1; count2 < 2; count2++)
{
//set up areas to be checked for first pass
if(AIPath[my_x + count][my_y + count2] <= curcount)
{
my_x = my_x + count;
my_y = my_y + count2;
curcount = AIPath[my_x + count][my_y + count2];
}
}
ship->AI.want_x = my_x * 16;
ship->AI.want_y = my_y * 16;
return(1);
return(true);
}
Any help would be appreciated.
Why isn't my Pathfinder working?
I read up on A* and set up some code. However, it doesn''t work. The bots don''t even choose the right target.
I''m not sure if its just little oversights on my part, or if my whole setup is screwed, but I''m sure you guys, with programming experience far beyond me (notice the ass-kissing) can show me what I''m doing wrong.
Heres the code:
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement