Created an ExtendedTraversalPred that can check if the movement from one

tile to another is traversable instead of just the destination being a 
traversable tile


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@18 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mark Johnson
2006-07-21 08:23:42 +00:00
parent 005043bf6c
commit 6913e5a127
@@ -52,6 +52,21 @@ public class AStarPathUtil
public boolean canTraverse (Object traverser, int x, int y);
}
/**
* Provides extended traversibility information when computing paths.
*/
public static interface ExtendedTraversalPred extends TraversalPred
{
/**
* Requests to know if the specific traverser (which was provided
* in the call to {@link #getPath}) can traverse from the specified
* source tile coordinate to the specified destination tile
* coodinate.
*/
public boolean canTraverse (
Object traverser, int sx, int sy, int dx, int dy);
}
/**
* Considers all the possible steps the piece in question can take.
*/
@@ -338,8 +353,15 @@ public class AStarPathUtil
protected boolean isStepValid (int sx, int sy, int dx, int dy)
{
// not traversable if the destination itself fails test
if (!isTraversable(dx, dy)) {
return false;
if (tpred instanceof ExtendedTraversalPred) {
if (!((ExtendedTraversalPred)tpred).canTraverse(
trav, sx, sy, dx, dy)) {
return false;
}
} else {
if (!isTraversable(dx, dy)) {
return false;
}
}
// if the step is diagonal, make sure the corners don't impede