From 8c00644cf269d788ee7ebfc291373e049257ba23 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 10 Jul 2015 08:23:12 -0400 Subject: SHERLOCK: RT: Fix interacting with characters --- engines/sherlock/scene.cpp | 10 +++------- engines/sherlock/scene.h | 18 ++++++----------- engines/sherlock/tattoo/tattoo_scene.cpp | 33 ++++++++++++++++++++++++++++++++ engines/sherlock/tattoo/tattoo_scene.h | 6 ++++++ 4 files changed, 48 insertions(+), 19 deletions(-) (limited to 'engines/sherlock') diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp index 2f8762e7bd..e56561fb5f 100644 --- a/engines/sherlock/scene.cpp +++ b/engines/sherlock/scene.cpp @@ -1338,7 +1338,7 @@ Exit *Scene::checkForExit(const Common::Rect &r) { return nullptr; } -int Scene::findBgShape(const Common::Rect &r) { +int Scene::findBgShape(const Common::Point &pt) { if (!_doBgAnimDone) // New frame hasn't been drawn yet return -1; @@ -1347,10 +1347,10 @@ int Scene::findBgShape(const Common::Rect &r) { Object &o = _bgShapes[idx]; if (o._type != INVALID && o._type != NO_SHAPE && o._type != HIDDEN && o._aType <= PERSON) { - if (r.intersects(o.getNewBounds())) + if (o.getNewBounds().contains(pt)) return idx; } else if (o._type == NO_SHAPE) { - if (r.intersects(o.getNoShapeBounds())) + if (o.getNoShapeBounds().contains(pt)) return idx; } } @@ -1358,10 +1358,6 @@ int Scene::findBgShape(const Common::Rect &r) { return -1; } -int Scene::findBgShape(const Common::Point &pt) { - return findBgShape(Common::Rect(pt.x, pt.y, pt.x + 1, pt.y + 1)); -} - int Scene::checkForZones(const Common::Point &pt, int zoneType) { int matches = 0; diff --git a/engines/sherlock/scene.h b/engines/sherlock/scene.h index 8ae6327ce2..0fbda38fe8 100644 --- a/engines/sherlock/scene.h +++ b/engines/sherlock/scene.h @@ -269,18 +269,6 @@ public: */ int toggleObject(const Common::String &name); - /** - * Attempts to find a background shape within the passed bounds. If found, - * it will return the shape number, or -1 on failure. - */ - int findBgShape(const Common::Rect &r); - - /** - * Attempts to find a background shape within the passed bounds. If found, - * it will return the shape number, or -1 on failure. - */ - int findBgShape(const Common::Point &pt); - /** * Checks to see if the given position in the scene belongs to a given zone type. * If it is, the zone is activated and used just like a TAKL zone or aFLAG_SET zone. @@ -297,6 +285,12 @@ public: */ virtual int closestZone(const Common::Point &pt) = 0; + /** + * Attempts to find a background shape within the passed bounds. If found, + * it will return the shape number, or -1 on failure. + */ + virtual int findBgShape(const Common::Point &pt); + /** * Synchronize the data for a savegame */ diff --git a/engines/sherlock/tattoo/tattoo_scene.cpp b/engines/sherlock/tattoo/tattoo_scene.cpp index f8ca2651c6..badc58d86f 100644 --- a/engines/sherlock/tattoo/tattoo_scene.cpp +++ b/engines/sherlock/tattoo/tattoo_scene.cpp @@ -708,6 +708,39 @@ void TattooScene::setNPCPath(int npc) { talk.talkTo(pathFile); } +int TattooScene::findBgShape(const Common::Point &pt) { + People &people = *_vm->_people; + + if (!_doBgAnimDone) + // New frame hasn't been drawn yet + return -1; + + int result = Scene::findBgShape(pt); + if (result == -1) { + // No shape found, so check whether a character is highlighted + for (int idx = 1; idx < MAX_CHARACTERS && result == -1; ++idx) { + Person &person = people[idx]; + + if (person._type == CHARACTER) { + int scaleVal = getScaleVal(person._position); + Common::Rect charRect; + + if (scaleVal == SCALE_THRESHOLD) + charRect = Common::Rect(person.frameWidth(), person.frameHeight()); + else + charRect = Common::Rect(person._imageFrame->sDrawXSize(scaleVal), person._imageFrame->sDrawYSize(scaleVal)); + charRect.moveTo(person._position.x / FIXED_INT_MULTIPLIER, person._position.y / FIXED_INT_MULTIPLIER + - charRect.height()); + + if (charRect.contains(pt)) + result = 1000 + idx; + } + } + } + + return result; +} + void TattooScene::synchronize(Serializer &s) { TattooEngine &vm = *(TattooEngine *)_vm; Scene::synchronize(s); diff --git a/engines/sherlock/tattoo/tattoo_scene.h b/engines/sherlock/tattoo/tattoo_scene.h index 695fef3d49..432233f501 100644 --- a/engines/sherlock/tattoo/tattoo_scene.h +++ b/engines/sherlock/tattoo/tattoo_scene.h @@ -132,6 +132,12 @@ public: * A negative playRate can also be specified to play the animation in reverse */ virtual int startCAnim(int cAnimNum, int playRate = 1); + + /** + * Attempts to find a background shape within the passed bounds. If found, + * it will return the shape number, or -1 on failure. + */ + virtual int findBgShape(const Common::Point &pt); }; } // End of namespace Tattoo -- cgit v1.2.3