summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-11-21 15:08:20 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-11-21 15:08:20 +0000
commit6b4436ee8d777f720f80a3436e30f34213258810 (patch)
tree6615196d1e35325bf1ceaff25dc712fc9ee06bf3 /src/being.cpp
parenta4b503456499b91a2f0ea9840944ce84bd1422c6 (diff)
downloadmana-6b4436ee8d777f720f80a3436e30f34213258810.tar.gz
mana-6b4436ee8d777f720f80a3436e30f34213258810.tar.bz2
mana-6b4436ee8d777f720f80a3436e30f34213258810.tar.xz
mana-6b4436ee8d777f720f80a3436e30f34213258810.zip
Added interpolation of tile offset for intermediate steps in long moves.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/being.cpp b/src/being.cpp
index d5f37371..22c56a6d 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -149,9 +149,9 @@ void Being::adjustCourse(Uint16 srcX, Uint16 srcY, Uint16 dstX, Uint16 dstY)
{
onPath = j;
}
- // Set intermediate steps to tile centers.
- i->x = i->x * 32 + 16;
- i->y = i->y * 32 + 16;
+ // Do not set any offset for intermediate steps.
+ i->x = i->x * 32;
+ i->y = i->y * 32;
++j;
}
p1_length = mMap->getMetaTile(dstX / 32, dstY / 32)->Gcost;
@@ -218,8 +218,8 @@ void Being::adjustCourse(Uint16 srcX, Uint16 srcY, Uint16 dstX, Uint16 dstY)
bestPath.pop_back();
for (Path::iterator i = bestPath.begin(), i_end = bestPath.end(); i != i_end; ++i)
{
- i->x = i->x * 32 + 16;
- i->y = i->y * 32 + 16;
+ i->x = i->x * 32;
+ i->y = i->y * 32;
}
// Concatenate paths.
@@ -260,6 +260,23 @@ Being::setPath(const Path &path, int mod)
mPath = path;
mSpeedModifier = mod >= 512 ? (mod <= 2048 ? mod : 2048) : 512; // TODO: tune bounds
+ int sz = mPath.size();
+ if (sz > 1)
+ {
+ // The path contains intermediate steps, so avoid going through tile
+ // centers for them. Instead, interpolate the tile offset.
+ int sx = mX & 31, sy = mY & 31;
+ int dx = (mPath.back().x & 31) - sx;
+ int dy = (mPath.back().y & 31) - sy;
+ Path::iterator j = mPath.begin();
+ for (int i = 0; i < sz - 1; ++i)
+ {
+ j->x |= sx + dx * (i + 1) / (sz - 1);
+ j->y |= sy + dy * (i + 1) / (sz - 1);
+ ++j;
+ }
+ }
+
if (mAction != WALK && mAction != DEAD)
{
mWalkTime = tick_time;