From e4a968fb74af4d0730f7188f7cca3296f5956d81 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Mon, 4 Aug 2008 19:11:24 +0000 Subject: [PATCH] Fix problem introduced in previous bugfix to paths, which made us create non-optimal paths for single tile obstructions that are also valid targets, such as oil derricks. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5776 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/fpath.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fpath.c b/src/fpath.c index 6a766e63c..bf2556e75 100644 --- a/src/fpath.c +++ b/src/fpath.c @@ -71,6 +71,7 @@ typedef struct _jobDone } PATHRESULT; +#define NUM_BASIC 8 #define NUM_DIR 24 // Convert a direction into an offset, spanning two tiles @@ -516,6 +517,7 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY) int nearestDir = NUM_DIR; int dir; + objTrace(psDroid->id, "BLOCKED(%d,%d) - trying workaround", map_coord(tX), map_coord(tY)); for (dir = 0; dir < NUM_DIR; dir++) { int x = map_coord(tX) + aDirOffset[dir].x; @@ -532,6 +534,11 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY) nearestDir = dir; } } + + if (dir == NUM_BASIC - 1 && nearestDir != NUM_DIR) + { + break; // found a solution without checking at greater distance + } } if (nearestDir == NUM_DIR) @@ -544,6 +551,7 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY) { tX = world_coord(map_coord(tX) + aDirOffset[nearestDir].x) + TILE_SHIFT / 2; tY = world_coord(map_coord(tY) + aDirOffset[nearestDir].y) + TILE_SHIFT / 2; + objTrace(psDroid->id, "Workaround found at (%d, %d)", map_coord(tX), map_coord(tY)); } } return fpathRoute(&psDroid->sMove, psDroid->id, psDroid->pos.x, psDroid->pos.y, tX, tY, psPropStats->propulsionType, psDroid->droidType);