aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Menshakov2009-11-14 11:45:15 +0000
committerVladimir Menshakov2009-11-14 11:45:15 +0000
commit813fa3d3753618fc83311359d32412cc51f15309 (patch)
treea8c822b5b3b7f74cbd61907cc5c2869fe3c9573f
parentcc1119940c833f7b61a977306c0a1a9cdf98cd6f (diff)
downloadscummvm-rg350-813fa3d3753618fc83311359d32412cc51f15309.tar.gz
scummvm-rg350-813fa3d3753618fc83311359d32412cc51f15309.tar.bz2
scummvm-rg350-813fa3d3753618fc83311359d32412cc51f15309.zip
stick to the closest points to the destination instead of walkboxes' centers
svn-id: r45893
-rw-r--r--engines/teenagent/objects.h14
-rw-r--r--engines/teenagent/scene.cpp10
2 files changed, 17 insertions, 7 deletions
diff --git a/engines/teenagent/objects.h b/engines/teenagent/objects.h
index 495ca773ac..3753330d96 100644
--- a/engines/teenagent/objects.h
+++ b/engines/teenagent/objects.h
@@ -78,6 +78,20 @@ struct Rect {
inline bool contains(const Rect & rect) const {
return rect.left >= left && rect.right <= right && rect.top >= top && rect.bottom <= bottom;
}
+
+ inline Common::Point closest_to(const Common::Point & src) const {
+ Common::Point p(src);
+ if (p.x < left)
+ p.x = left;
+ if (p.x > right)
+ p.x = right;
+
+ if (p.y < top)
+ p.y = top;
+ if (p.y > bottom)
+ p.y = bottom;
+ return p;
+ }
protected:
byte * _base;
diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp
index 79ce6b1b66..3e5ade2c27 100644
--- a/engines/teenagent/scene.cpp
+++ b/engines/teenagent/scene.cpp
@@ -165,15 +165,11 @@ bool Scene::findPath(Scene::Path &p, const Common::Point &src, const Common::Poi
search(nodes, n, m, start / m, start % m, -1, end, 1);
int v = end;
+ Common::Point prev(dst);
do {
debug(1, "backtrace %d", v);
- Common::Point c = nodes[v].rect.center();
- if (end / m == v / m) { //same y
- c.y = dst.y;
- }
- if (end % m == v % m) {
- c.x = dst.x;
- }
+ Common::Point c = nodes[v].rect.closest_to(prev);
+ prev = c;
p.push_front(c);
if (v == start)
break;