aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2015-07-01 21:10:57 -0400
committerPaul Gilbert2015-07-01 21:10:57 -0400
commitdc4689e4b901971448f2625a96d5708a0c6e8ddf (patch)
tree3b8ef050736472384bd56a93546d22e1a519865f
parent121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f (diff)
downloadscummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.tar.gz
scummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.tar.bz2
scummvm-rg350-dc4689e4b901971448f2625a96d5708a0c6e8ddf.zip
SHERLOCK: Split up closestZone versions for each game
-rw-r--r--engines/sherlock/scalpel/scalpel_scene.cpp19
-rw-r--r--engines/sherlock/scalpel/scalpel_scene.h5
-rw-r--r--engines/sherlock/scene.cpp48
-rw-r--r--engines/sherlock/scene.h2
-rw-r--r--engines/sherlock/tattoo/tattoo_scene.cpp48
-rw-r--r--engines/sherlock/tattoo/tattoo_scene.h5
6 files changed, 78 insertions, 49 deletions
diff --git a/engines/sherlock/scalpel/scalpel_scene.cpp b/engines/sherlock/scalpel/scalpel_scene.cpp
index fa820d95fd..4e6e9e4c7c 100644
--- a/engines/sherlock/scalpel/scalpel_scene.cpp
+++ b/engines/sherlock/scalpel/scalpel_scene.cpp
@@ -702,6 +702,25 @@ int ScalpelScene::startCAnim(int cAnimNum, int playRate) {
return 1;
}
+int ScalpelScene::closestZone(const Common::Point &pt) {
+ int dist = 1000;
+ int zone = -1;
+
+ 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);
+
+ if (d < dist) {
+ // Found a closer zone
+ dist = d;
+ zone = idx;
+ }
+ }
+
+ return zone;
+}
+
} // End of namespace Scalpel
} // End of namespace Sherlock
diff --git a/engines/sherlock/scalpel/scalpel_scene.h b/engines/sherlock/scalpel/scalpel_scene.h
index 77e86cf9cf..fa65ecd95b 100644
--- a/engines/sherlock/scalpel/scalpel_scene.h
+++ b/engines/sherlock/scalpel/scalpel_scene.h
@@ -65,6 +65,11 @@ protected:
* Draw all the shapes, people and NPCs in the correct order
*/
virtual void drawAllShapes();
+
+ /**
+ * Returns the index of the closest zone to a given point.
+ */
+ virtual int closestZone(const Common::Point &pt);
public:
ScalpelScene(SherlockEngine *vm) : Scene(vm) {}
diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp
index 69deedef28..3d406fe134 100644
--- a/engines/sherlock/scene.cpp
+++ b/engines/sherlock/scene.cpp
@@ -1379,54 +1379,6 @@ int Scene::whichZone(const Common::Point &pt) {
return -1;
}
-int Scene::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;
-}
-
void Scene::synchronize(Serializer &s) {
if (s.isSaving())
saveSceneStatus();
diff --git a/engines/sherlock/scene.h b/engines/sherlock/scene.h
index 5037b9d2cf..4ffe1ac340 100644
--- a/engines/sherlock/scene.h
+++ b/engines/sherlock/scene.h
@@ -297,7 +297,7 @@ public:
/**
* Returns the index of the closest zone to a given point.
*/
- int closestZone(const Common::Point &pt);
+ virtual int closestZone(const Common::Point &pt) = 0;
/**
* Synchronize the data for a savegame
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;