Skip to content

Commit

Permalink
Don't put pathfinding points very close to blocking tiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed Jun 13, 2012
1 parent d115167 commit 57a56f2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/astar.cpp
Expand Up @@ -505,6 +505,17 @@ ASR_RETVAL fpathAStarRoute(MOVE_CONTROL *psMove, PATHJOB *psJob)

PathExploredTile &tile = context.map[map_coord(p.x) + map_coord(p.y)*mapWidth];
newP = p - Vector2i(tile.dx, tile.dy)*(TILE_UNITS/64);
Vector2i mapP = map_coord(newP);
int xSide = newP.x - world_coord(mapP.x) > TILE_UNITS/2? 1 : -1; // 1 if newP is on right-hand side of the tile, or -1 if newP is on the left-hand side of the tile.
int ySide = newP.y - world_coord(mapP.y) > TILE_UNITS/2? 1 : -1; // 1 if newP is on bottom side of the tile, or -1 if newP is on the top side of the tile.
if (context.isBlocked(mapP.x + xSide, mapP.y))
{
newP.x = world_coord(mapP.x) + TILE_UNITS/2; // Point too close to a blocking tile on left or right side, so move the point to the middle.
}
if (context.isBlocked(mapP.x, mapP.y + ySide))
{
newP.y = world_coord(mapP.y) + TILE_UNITS/2; // Point too close to a blocking tile on rop or bottom side, so move the point to the middle.
}
if (map_coord(p) == Vector2i(context.tileS.x, context.tileS.y) || p == newP)
{
break; // We stopped moving, because we reached the destination or the closest reachable tile to context.tileS. Give up now.
Expand Down

0 comments on commit 57a56f2

Please sign in to comment.