aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/walking.cpp
diff options
context:
space:
mode:
authorRobert Špalek2009-11-01 12:57:06 +0000
committerRobert Špalek2009-11-01 12:57:06 +0000
commitc1cc230e4b41c9e6fff7b531158e50d0bc18a57a (patch)
tree1404ac074fc40d4dc3afa13811c58669d3eeec86 /engines/draci/walking.cpp
parent5c7a120471000a1e048c5bc7688af77e95886caa (diff)
downloadscummvm-rg350-c1cc230e4b41c9e6fff7b531158e50d0bc18a57a.tar.gz
scummvm-rg350-c1cc230e4b41c9e6fff7b531158e50d0bc18a57a.tar.bz2
scummvm-rg350-c1cc230e4b41c9e6fff7b531158e50d0bc18a57a.zip
Debugged computation and displaying of optimal walking paths
svn-id: r45597
Diffstat (limited to 'engines/draci/walking.cpp')
-rw-r--r--engines/draci/walking.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp
index c08e97346c..ad1642132e 100644
--- a/engines/draci/walking.cpp
+++ b/engines/draci/walking.cpp
@@ -57,7 +57,7 @@ bool WalkingMap::isWalkable(int x, int y) const {
return getPixel(x / _deltaX, y / _deltaY);
}
-Sprite *WalkingMap::newOverlayFromMap() const {
+Sprite *WalkingMap::newOverlayFromMap(byte colour) const {
// HACK: Create a visible overlay from the walking map so we can test it
byte *wlk = new byte[_realWidth * _realHeight];
memset(wlk, 255, _realWidth * _realHeight);
@@ -65,7 +65,7 @@ Sprite *WalkingMap::newOverlayFromMap() const {
for (int i = 0; i < _mapWidth; ++i) {
for (int j = 0; j < _mapHeight; ++j) {
if (getPixel(i, j)) {
- drawOverlayRectangle(i, j, 2, wlk);
+ drawOverlayRectangle(i, j, colour, wlk);
}
}
}
@@ -274,6 +274,9 @@ bool WalkingMap::findShortestPath(int x1, int y1, int x2, int y2, WalkingMap::Pa
void WalkingMap::obliquePath(const WalkingMap::Path& path, WalkingMap::Path *obliquedPath) const {
// Prune the path to only contain vertices where the direction is changing.
obliquedPath->clear();
+ if (path.empty()) {
+ return;
+ }
obliquedPath->push_back(path[0]);
uint index = 1;
while (index < path.size()) {
@@ -315,8 +318,8 @@ void WalkingMap::obliquePath(const WalkingMap::Path& path, WalkingMap::Path *obl
bool allPointsOk = true;
// Testing only points between (i.e., without the end-points) is OK.
for (int step = 1; step < steps; ++step) {
- const int x = (v1.x * (steps-step) + v3.x * step) / steps;
- const int y = (v1.y * (steps-step) + v3.y * step) / steps;
+ const int x = (v1.x * (steps-step) + v3.x * step + steps/2) / steps;
+ const int y = (v1.y * (steps-step) + v3.y * step + steps/2) / steps;
if (!getPixel(x, y)) {
allPointsOk = false;
break;
@@ -340,15 +343,17 @@ Sprite *WalkingMap::newOverlayFromPath(const WalkingMap::Path &path, byte colour
// Draw only points in the interval [v1, v2). These half-open
// half-closed intervals connect all the way to the last point.
for (int step = 0; step < steps; ++step) {
- const int x = (v1.x * (steps-step) + v2.x * step) / steps;
- const int y = (v1.y * (steps-step) + v2.y * step) / steps;
+ const int x = (v1.x * (steps-step) + v2.x * step + steps/2) / steps;
+ const int y = (v1.y * (steps-step) + v2.y * step + steps/2) / steps;
drawOverlayRectangle(x, y, colour, wlk);
}
}
// Draw the last point. This works also when the path has no segment,
// but just one point.
- const PathVertex &vLast = path[path.size()-1];
- drawOverlayRectangle(vLast.x, vLast.y, colour, wlk);
+ if (path.size() > 0) {
+ const PathVertex &vLast = path[path.size()-1];
+ drawOverlayRectangle(vLast.x, vLast.y, colour, wlk);
+ }
Sprite *ov = new Sprite(_realWidth, _realHeight, wlk, 0, 0, false);
// ov has taken the ownership of wlk.