diff options
author | Paul Gilbert | 2015-07-06 20:26:37 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-07-06 20:26:37 -0400 |
commit | ada51dbdfb3111f309732e17abcbcc4fd1034fdc (patch) | |
tree | dd7b1cbb9f47c0d9b64b3117426027de9c7d0c39 /engines/sherlock/scalpel | |
parent | cc46c92a8e50e1ce799df2758918a644e725dc5a (diff) | |
download | scummvm-rg350-ada51dbdfb3111f309732e17abcbcc4fd1034fdc.tar.gz scummvm-rg350-ada51dbdfb3111f309732e17abcbcc4fd1034fdc.tar.bz2 scummvm-rg350-ada51dbdfb3111f309732e17abcbcc4fd1034fdc.zip |
SHERLOCK: RT: Fix characters walking off-screen
Diffstat (limited to 'engines/sherlock/scalpel')
-rw-r--r-- | engines/sherlock/scalpel/scalpel_people.cpp | 27 | ||||
-rw-r--r-- | engines/sherlock/scalpel/scalpel_people.h | 14 |
2 files changed, 36 insertions, 5 deletions
diff --git a/engines/sherlock/scalpel/scalpel_people.cpp b/engines/sherlock/scalpel/scalpel_people.cpp index db26bb8c0f..53876f8f1c 100644 --- a/engines/sherlock/scalpel/scalpel_people.cpp +++ b/engines/sherlock/scalpel/scalpel_people.cpp @@ -500,6 +500,33 @@ bool ScalpelPeople::loadWalk() { return result; } +const Common::Point ScalpelPeople::restrictToZone(int zoneId, const Common::Point &destPos) { + Scene &scene = *_vm->_scene; + Common::Point walkDest = destPos; + + // The destination isn't in a zone + if (walkDest.x >= (SHERLOCK_SCREEN_WIDTH - 1)) + walkDest.x = SHERLOCK_SCREEN_WIDTH - 2; + + // Trace a line between the centroid of the found closest zone to + // the destination, to find the point at which the zone will be left + const Common::Rect &destRect = scene._zones[zoneId]; + const Common::Point destCenter((destRect.left + destRect.right) / 2, + (destRect.top + destRect.bottom) / 2); + const Common::Point delta = walkDest - destCenter; + Point32 pt(destCenter.x * FIXED_INT_MULTIPLIER, destCenter.y * FIXED_INT_MULTIPLIER); + + // Move along the line until the zone is left + do { + pt += delta; + } while (destRect.contains(pt.x / FIXED_INT_MULTIPLIER, pt.y / FIXED_INT_MULTIPLIER)); + + // Set the new walk destination to the last point that was in the + // zone just before it was left + return Common::Point((pt.x - delta.x * 2) / FIXED_INT_MULTIPLIER, + (pt.y - delta.y * 2) / FIXED_INT_MULTIPLIER); +} + } // End of namespace Scalpel } // End of namespace Sherlock diff --git a/engines/sherlock/scalpel/scalpel_people.h b/engines/sherlock/scalpel/scalpel_people.h index 0f8aa9dcc7..b53da2e6d8 100644 --- a/engines/sherlock/scalpel/scalpel_people.h +++ b/engines/sherlock/scalpel/scalpel_people.h @@ -42,11 +42,6 @@ enum ScalpelSequences { }; class ScalpelPerson : public Person { -protected: - /** - * Get the source position for a character potentially affected by scaling - */ - virtual Common::Point getSourcePoint() const; public: ScalpelPerson() : Person() {} virtual ~ScalpelPerson() {} @@ -72,6 +67,10 @@ public: */ virtual void walkToCoords(const Point32 &destPos, int destDir); + /** + * Get the source position for a character potentially affected by scaling + */ + virtual Common::Point getSourcePoint() const; }; class ScalpelPeople : public People { @@ -98,6 +97,11 @@ public: virtual void setTalkSequence(int speaker, int sequenceNum = 1); /** + * Restrict passed point to zone using Sherlock's positioning rules + */ + virtual const Common::Point restrictToZone(int zoneId, const Common::Point &destPos); + + /** * Load the walking images for Sherlock */ virtual bool loadWalk(); |