aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2015-07-01 20:07:37 -0400
committerPaul Gilbert2015-07-01 20:07:37 -0400
commit121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f (patch)
tree708c585dfe2488f82a157ce956ea3f8e6296ee4f
parentdbf82dd92af5f0b8b04dfa4e6175740dc80e24ad (diff)
downloadscummvm-rg350-121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f.tar.gz
scummvm-rg350-121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f.tar.bz2
scummvm-rg350-121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f.zip
SHERLOCK: RT: Fix zone checks in closestZone method
-rw-r--r--engines/sherlock/scene.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp
index c3917fb003..69deedef28 100644
--- a/engines/sherlock/scene.cpp
+++ b/engines/sherlock/scene.cpp
@@ -1380,16 +1380,45 @@ int Scene::whichZone(const Common::Point &pt) {
}
int Scene::closestZone(const Common::Point &pt) {
- int dist = 1000;
int zone = -1;
+ int dist = 9999;
+ int d;
for (uint idx = 0; idx < _zones.size(); ++idx) {
- Common::Point zc((_zones[idx].left + _zones[idx].right) / 2,
- (_zones[idx].top + _zones[idx].bottom) / 2);
- int d = ABS(zc.x - pt.x) + ABS(zc.y - pt.y);
+ Common::Rect &r = _zones[idx];
+ // Check the distance from the point to the center of the zone
+ d = ABS(r.left + (r.width() / 2) - pt.x) + ABS(r.top + (r.height() / 2) - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the upper left of the zone
+ d = ABS((int)(r.left - pt.x)) + ABS((int)(r.top - pt.y));
+ if (d < dist)
+ {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the upper right of the zone
+ d = ABS(r.left + r.width() - pt.x) + ABS(r.top - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the lower left of the zone
+ d = ABS(r.left - pt.x) + ABS(r.top + r.height() - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the lower right of the zone
+ d = ABS(r.left + r.width() - pt.x) + ABS(r.top + r.height() - pt.y);
if (d < dist) {
- // Found a closer zone
dist = d;
zone = idx;
}