aboutsummaryrefslogtreecommitdiff
path: root/engines/sherlock/tattoo
diff options
context:
space:
mode:
authorPaul Gilbert2015-07-01 21:10:57 -0400
committerPaul Gilbert2015-07-01 21:10:57 -0400
commitdc4689e4b901971448f2625a96d5708a0c6e8ddf (patch)
tree3b8ef050736472384bd56a93546d22e1a519865f /engines/sherlock/tattoo
parent121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f (diff)
downloadscummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.tar.gz
scummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.tar.bz2
scummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.zip
SHERLOCK: Split up closestZone versions for each game
Diffstat (limited to 'engines/sherlock/tattoo')
-rw-r--r--engines/sherlock/tattoo/tattoo_scene.cpp48
-rw-r--r--engines/sherlock/tattoo/tattoo_scene.h5
2 files changed, 53 insertions, 0 deletions
diff --git a/engines/sherlock/tattoo/tattoo_scene.cpp b/engines/sherlock/tattoo/tattoo_scene.cpp
index 0f02f3e872..f19eb73a54 100644
--- a/engines/sherlock/tattoo/tattoo_scene.cpp
+++ b/engines/sherlock/tattoo/tattoo_scene.cpp
@@ -717,6 +717,54 @@ void TattooScene::synchronize(Serializer &s) {
vm._runningProlog = false;
}
+int TattooScene::closestZone(const Common::Point &pt) {
+ int zone = -1;
+ int dist = 9999;
+ int d;
+
+ for (uint idx = 0; idx < _zones.size(); ++idx) {
+ 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) {
+ dist = d;
+ zone = idx;
+ }
+ }
+
+ return zone;
+}
+
} // End of namespace Tattoo
} // End of namespace Sherlock
diff --git a/engines/sherlock/tattoo/tattoo_scene.h b/engines/sherlock/tattoo/tattoo_scene.h
index 81d76374f3..c3d6e3b929 100644
--- a/engines/sherlock/tattoo/tattoo_scene.h
+++ b/engines/sherlock/tattoo/tattoo_scene.h
@@ -96,6 +96,11 @@ protected:
* Synchronize the data for a savegame
*/
virtual void synchronize(Serializer &s);
+
+ /**
+ * Returns the index of the closest zone to a given point.
+ */
+ virtual int closestZone(const Common::Point &pt);
public:
StreamingImageFile _activeCAnim;
Common::Array<SceneTripEntry> _sceneTripCounters;