aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorWalter van Niftrik2009-10-30 03:54:50 +0000
committerWalter van Niftrik2009-10-30 03:54:50 +0000
commitdba613ecd254906c1fb4128ddecfae3121dc39d5 (patch)
treedc9e2fc1bf33555e5a7b5a6e91da138ba21f23fb /engines/sci
parente36798585fae492e425fdf5697cd9c31bb42c1d7 (diff)
downloadscummvm-rg350-dba613ecd254906c1fb4128ddecfae3121dc39d5.tar.gz
scummvm-rg350-dba613ecd254906c1fb4128ddecfae3121dc39d5.tar.bz2
scummvm-rg350-dba613ecd254906c1fb4128ddecfae3121dc39d5.zip
SCI: AvoidPath: Don't discard contained-access polygon when starting point
is right next to it. svn-id: r45521
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/engine/kpathing.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp
index adb5b0075b..e64d24296e 100644
--- a/engines/sci/engine/kpathing.cpp
+++ b/engines/sci/engine/kpathing.cpp
@@ -1050,6 +1050,21 @@ static int nearest_intersection(PathfindingState *s, const Common::Point &p, con
}
/**
+ * Checks whether a point is nearby a contained-access polygon (distance 1 pixel)
+ * @param point the point
+ * @param polygon the contained-access polygon
+ * @return true when point is nearby polygon, false otherwise
+ */
+static bool nearbyPolygon(const Common::Point &point, Polygon *polygon) {
+ assert(polygon->type == POLY_CONTAINED_ACCESS);
+
+ return ((contained(Common::Point(point.x, point.y + 1), polygon) != CONT_INSIDE)
+ || (contained(Common::Point(point.x, point.y - 1), polygon) != CONT_INSIDE)
+ || (contained(Common::Point(point.x + 1, point.y), polygon) != CONT_INSIDE)
+ || (contained(Common::Point(point.x - 1, point.y), polygon) != CONT_INSIDE));
+}
+
+/**
* Checks that the start point is in a valid position, and takes appropriate action if it's not.
* @param s the pathfinding state
* @param start the start point
@@ -1075,12 +1090,14 @@ static Common::Point *fixup_start_point(PathfindingState *s, const Common::Point
case POLY_CONTAINED_ACCESS:
// Remove contained access polygons that do not contain
// the start point (containment test is inverted here).
- if (cont == CONT_INSIDE) {
+ // SSCI appears to be using a small margin of error here,
+ // so we do the same.
+ if ((cont == CONT_INSIDE) && !nearbyPolygon(start, *it)) {
delete *it;
it = s->polygons.erase(it);
continue;
}
- break;
+ // Fall through
case POLY_BARRED_ACCESS:
case POLY_NEAREST_ACCESS:
if (cont == CONT_INSIDE) {
@@ -1095,7 +1112,7 @@ static Common::Point *fixup_start_point(PathfindingState *s, const Common::Point
return NULL;
}
- if (type == POLY_BARRED_ACCESS)
+ if ((type == POLY_BARRED_ACCESS) || (type == POLY_CONTAINED_ACCESS))
warning("AvoidPath: start position at unreachable location");
// The original start position is in an invalid location, so we