summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp6
-rw-r--r--src/net/tmwa/beinghandler.cpp132
2 files changed, 84 insertions, 54 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 8c7f45bb..b79b65b3 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -673,6 +673,8 @@ void Being::logic()
mText = 0;
}
+ ActorSprite::logic();
+
if ((mAction != DEAD) && !mSpeedPixelsPerTick.isNull())
{
const Vector dest = (mPath.empty()) ?
@@ -680,7 +682,7 @@ void Being::logic()
mPath.front().y);
// Avoid going to flawed destinations
- if (mDest.x <= 0 || mDest.y <= 0)
+ if (dest.x <= 0 || dest.y <= 0)
{
// We make the being stop move in that case.
mDest = mPos;
@@ -768,8 +770,6 @@ void Being::logic()
}
}
- ActorSprite::logic();
-
// Remove it after 3 secs. TODO: Just play the dead animation before removing
if (!isAlive() && Net::getGameHandler()->removeDeadBeings() &&
get_elapsed_time(mActionTime) > 3000)
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index 40c1107b..40dfe083 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -216,31 +216,40 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
{
Uint16 srcX, srcY, dstX, dstY;
msg.readCoordinatePair(srcX, srcY, dstX, dstY);
- dstBeing->setAction(Being::STAND);
- Vector pos(srcX * tileWidth + tileWidth / 2,
- srcY * tileHeight + tileHeight / 2);
-
- dstX = dstX * tileWidth + tileWidth / 2;
- dstY = dstY * tileHeight + tileHeight / 2;
- // Don't set the position as the movement algorithm can guess
- // it and it would break the animation played, when we're
- // close enough.
- if (std::abs((float)dstX - pos.x) > POS_DEST_DIFF_TOLERANCE
- || std::abs((float)dstY - pos.y) > POS_DEST_DIFF_TOLERANCE)
- dstBeing->setPosition(pos);
-
- // We turn the destination back to a pixel one.
- dstBeing->setDestination(dstX, dstY);
+ //dstBeing->setAction(Being::STAND); Useless
+ // Avoid dealing with flawed destination
+ if (srcX && srcY && dstX && dstY)
+ {
+ Vector pos(srcX * tileWidth + tileWidth / 2,
+ srcY * tileHeight + tileHeight / 2);
+
+ Vector dest(dstX * tileWidth + tileWidth / 2,
+ dstY * tileHeight + tileHeight / 2);
+ // Don't set the position as the movement algorithm
+ // can guess it and it would break the animation played,
+ // when we're close enough.
+ if (std::abs(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE
+ || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE)
+ dstBeing->setPosition(pos);
+
+ // We turn the destination back to a pixel one.
+ dstBeing->setDestination(dest.x, dest.y);
+ }
}
else
{
Uint8 dir;
Uint16 x, y;
msg.readCoordinates(x, y, dir);
- Vector pos(x * tileWidth + tileWidth / 2,
- y * tileHeight + tileHeight / 2);
- dstBeing->setPosition(pos);
- dstBeing->setDirection(dir);
+
+ // Avoid dealing with flawed destination
+ if (x && y)
+ {
+ Vector pos(x * tileWidth + tileWidth / 2,
+ y * tileHeight + tileHeight / 2);
+ dstBeing->setPosition(pos);
+ dstBeing->setDirection(dir);
+ }
}
msg.readInt8(); // unknown
@@ -281,20 +290,23 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
msg.readCoordinatePair(srcX, srcY, dstX, dstY);
msg.readInt32(); // Server tick
- //dstBeing->setAction(Being::STAND); <-- Not needed anymore.
-
- Vector pos(srcX * tileWidth + tileWidth / 2,
- srcY * tileHeight + tileHeight / 2);
- Vector dest(dstX * tileWidth + tileWidth / 2,
- dstY * tileHeight + tileHeight / 2);
- // Don't set the position as the movement algorithm can guess
- // it and it would break the animation played, when we're
- // close enough.
- if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE
- || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE)
- dstBeing->setPosition(pos);
+ //dstBeing->setAction(Being::STAND); // Useless.
+ // Avoid dealing with flawed destination
+ if (srcX && srcY && dstX && dstY)
+ {
+ Vector pos(srcX * tileWidth + tileWidth / 2,
+ srcY * tileHeight + tileHeight / 2);
+ Vector dest(dstX * tileWidth + tileWidth / 2,
+ dstY * tileHeight + tileHeight / 2);
+ // Don't set the position as the movement algorithm can guess
+ // it and it would break the animation played, when we're
+ // close enough.
+ if (std::abs(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE
+ || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE)
+ dstBeing->setPosition(pos);
- dstBeing->setDestination(dest.x, dest.y);
+ dstBeing->setDestination(dest.x, dest.y);
+ }
}
break;
@@ -603,28 +615,39 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
{
Uint16 srcX, srcY, dstX, dstY;
msg.readCoordinatePair(srcX, srcY, dstX, dstY);
- Vector pos(srcX * tileWidth + tileWidth / 2,
- srcY * tileHeight + tileHeight / 2);
- Vector dest(dstX * tileWidth + tileWidth / 2,
- dstY * tileHeight + tileHeight / 2);
- // Don't set the position as the movement algorithm can guess
- // it and it would break the animation played, when we're
- // close enough.
- if (std::abs((float)dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE
- || std::abs((float)dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE)
- dstBeing->setPosition(pos);
-
- dstBeing->setDestination(dest.x, dest.y);
+ //dstBeing->setAction(Being::STAND); // Useless.
+ // Avoid dealing with flawed destination
+ if (srcX && srcY && dstX && dstY)
+ {
+ Vector pos(srcX * tileWidth + tileWidth / 2,
+ srcY * tileHeight + tileHeight / 2);
+ Vector dest(dstX * tileWidth + tileWidth / 2,
+ dstY * tileHeight + tileHeight / 2);
+
+ // Don't set the position as the movement algorithm
+ // can guess it and it would break the animation played,
+ // when we're close enough.
+ if (std::abs(dest.x - pos.x) > POS_DEST_DIFF_TOLERANCE
+ || std::abs(dest.y - pos.y) > POS_DEST_DIFF_TOLERANCE)
+ dstBeing->setPosition(pos);
+
+ dstBeing->setDestination(dest.x, dest.y);
+ }
}
else
{
Uint8 dir;
Uint16 x, y;
msg.readCoordinates(x, y, dir);
- dstBeing->setPosition(Vector(x * tileWidth + tileWidth / 2,
- y * tileHeight + tileHeight / 2));
- dstBeing->setDirection(dir);
+ // Avoid dealing with flawed destination
+ if (x && y)
+ {
+ Vector pos(x * tileWidth + tileWidth / 2,
+ y * tileHeight + tileHeight / 2);
+ dstBeing->setPosition(pos);
+ dstBeing->setDirection(dir);
+ }
}
gmstatus = msg.readInt16();
@@ -681,10 +704,17 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
Uint16 x, y;
x = msg.readInt16();
y = msg.readInt16();
- dstBeing->setPosition(Vector(x * tileWidth + tileWidth / 2,
- y * tileHeight + tileHeight / 2));
- if (dstBeing->getCurrentAction() == Being::MOVE)
- dstBeing->setAction(Being::STAND);
+ // Avoid dealing with flawed destination
+ if (x && y)
+ {
+ Vector pos(x * tileWidth + tileWidth / 2,
+ y * tileHeight + tileHeight / 2);
+ dstBeing->setPosition(pos);
+ if (dstBeing->getCurrentAction() == Being::MOVE)
+ {
+ dstBeing->setAction(Being::STAND);
+ }
+ }
}
}
break;