summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp22
-rw-r--r--src/being.h8
-rw-r--r--src/map.h6
-rw-r--r--src/monster.cpp2
-rw-r--r--src/net/ea/beinghandler.cpp4
-rw-r--r--src/net/ea/playerhandler.cpp10
-rw-r--r--src/net/ea/playerhandler.h2
-rw-r--r--src/net/manaserv/beinghandler.cpp31
-rw-r--r--src/net/manaserv/beinghandler.h4
-rw-r--r--src/net/manaserv/playerhandler.cpp2
-rw-r--r--src/net/manaserv/playerhandler.h2
-rw-r--r--src/net/playerhandler.h2
-rw-r--r--src/player.cpp3
-rw-r--r--src/vector.h26
14 files changed, 99 insertions, 25 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 20d7319a..33f38255 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -503,7 +503,7 @@ void Being::nextTile()
mX = pos.x;
mY = pos.y;
setAction(WALK);
- mWalkTime += (int)(mWalkSpeed / 10);
+ mWalkTime += (int)(mWalkSpeed.x / 10);
}
void Being::logic()
@@ -537,8 +537,8 @@ void Being::logic()
// The deplacement of a point along a vector is calculated
// using the Unit Vector (â) multiplied by the point speed.
// â = a / ||a|| (||a|| is the a length.)
- // Then, diff = (dir/||dir||)*speed, or (dir / ||dir|| / 1/speed).
- Vector diff = (dir / (nominalLength / mWalkSpeed));
+ // Then, diff = (dir/||dir||) * speed.
+ Vector diff = dir.normalized() * mWalkSpeed;
// Test if we don't miss the destination by a move too far:
if (diff.length() > nominalLength)
@@ -799,7 +799,21 @@ int Being::getOffset(char pos, char neg) const
if (mAction != WALK || !(mDirection & (pos | neg)))
return 0;
- int offset = (int)((get_elapsed_time(mWalkTime) * 32) / mWalkSpeed);
+ int offset;
+
+ if (mMap)
+ {
+ offset = (pos == LEFT && neg == RIGHT) ?
+ (int)((get_elapsed_time(mWalkTime)
+ * mMap->getTileWidth()) / mWalkSpeed.x) :
+ (int)((get_elapsed_time(mWalkTime)
+ * mMap->getTileHeight()) / mWalkSpeed.y);
+ }
+ else
+ {
+ offset = (int)((get_elapsed_time(mWalkTime)
+ * DEFAULT_TILE_SIDE_LENGTH) / mWalkSpeed.x);
+ }
// We calculate the offset _from_ the _target_ location
offset -= 32;
diff --git a/src/being.h b/src/being.h
index 79bcc020..79ab1df2 100644
--- a/src/being.h
+++ b/src/being.h
@@ -285,14 +285,14 @@ class Being : public Sprite, public ConfigListener
* in pixels per second for eAthena,
* in tiles per second for Manaserv.
*/
- void setWalkSpeed(float speed) { mWalkSpeed = speed; }
+ void setWalkSpeed(Vector speed) { mWalkSpeed = speed; }
/**
* Gets the walk speed.
* in pixels per second for eAthena,
* in tiles per second for Manaserv (0.1 precision).
*/
- float getWalkSpeed() const { return mWalkSpeed; }
+ Vector getWalkSpeed() const { return mWalkSpeed; }
/**
* Sets the attack speed.
@@ -644,12 +644,12 @@ class Being : public Sprite, public ConfigListener
SpeechBubble *mSpeechBubble;
/**
- * Walk speed.
+ * Walk speed for x and y movement values.
* In pixels per second for eAthena,
* In pixels per ticks for Manaserv.
* @see MILLISECONDS_IN_A_TICK
*/
- float mWalkSpeed;
+ Vector mWalkSpeed;
Vector mPos;
Vector mDest;
diff --git a/src/map.h b/src/map.h
index 116daf40..f5f74995 100644
--- a/src/map.h
+++ b/src/map.h
@@ -256,12 +256,14 @@ class Map : public Properties
/**
* Returns the tile width of this map.
*/
- int getTileWidth() const { return mTileWidth; }
+ int getTileWidth() const
+ { return mTileWidth > 0 ? mTileWidth : DEFAULT_TILE_SIDE_LENGTH; }
/**
* Returns the tile height used by this map.
*/
- int getTileHeight() const { return mTileHeight; }
+ int getTileHeight() const
+ { return mTileHeight > 0 ? mTileHeight : DEFAULT_TILE_SIDE_LENGTH; }
const std::string &getMusicFile() const;
const std::string &getName() const;
diff --git a/src/monster.cpp b/src/monster.cpp
index 7d0d7ab0..0d0757dd 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -75,7 +75,7 @@ void Monster::logic()
{
if ((Net::getNetworkType() == ServerInfo::EATHENA) && (mAction != STAND))
{
- mFrame = (int) ((get_elapsed_time(mWalkTime) * 4) / getWalkSpeed());
+ mFrame = (int) ((get_elapsed_time(mWalkTime) * 4) / getWalkSpeed().x);
if (mFrame >= 4 && mAction != DEAD)
nextTile();
diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp
index 86bfe929..b63e9e8a 100644
--- a/src/net/ea/beinghandler.cpp
+++ b/src/net/ea/beinghandler.cpp
@@ -161,7 +161,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
// Prevent division by 0 when calculating frame
if (speed == 0) { speed = 150; }
- dstBeing->setWalkSpeed(speed);
+ dstBeing->setWalkSpeed(Vector(speed, speed, 0));
dstBeing->setJob(job);
hairStyle = msg.readInt16();
weapon = msg.readInt16();
@@ -521,7 +521,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
}
}
- dstBeing->setWalkSpeed(speed);
+ dstBeing->setWalkSpeed(Vector(speed, speed, 0));
dstBeing->setJob(job);
hairStyle = msg.readInt16();
weapon = msg.readInt16();
diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp
index 1d7a2fb6..f6f54d59 100644
--- a/src/net/ea/playerhandler.cpp
+++ b/src/net/ea/playerhandler.cpp
@@ -229,7 +229,9 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
switch (type)
{
- case 0x0000: player_node->setWalkSpeed(value); break;
+ case 0x0000:
+ player_node->setWalkSpeed(Vector(value, value, 0));
+ break;
case 0x0004: break; // manner
case 0x0005: player_node->setHp(value); break;
case 0x0006: player_node->setMaxHp(value); break;
@@ -639,9 +641,11 @@ int PlayerHandler::getJobLocation()
return JOB;
}
-float PlayerHandler::getDefaultWalkSpeed()
+Vector PlayerHandler::getDefaultWalkSpeed()
{
- return 150;
+ // Return an normalized speed for any side
+ // as the offset is calculated elsewhere.
+ return Vector(150, 150, 0);
}
} // namespace EAthena
diff --git a/src/net/ea/playerhandler.h b/src/net/ea/playerhandler.h
index b60daef3..9e7e9ac3 100644
--- a/src/net/ea/playerhandler.h
+++ b/src/net/ea/playerhandler.h
@@ -66,7 +66,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
int getJobLocation();
- float getDefaultWalkSpeed();
+ Vector getDefaultWalkSpeed();
};
} // namespace EAthena
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp
index 3cafe706..02f136af 100644
--- a/src/net/manaserv/beinghandler.cpp
+++ b/src/net/manaserv/beinghandler.cpp
@@ -91,10 +91,35 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
}
}
-float BeingHandler::giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds)
+Vector BeingHandler::giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds)
{
- return (speedInTilesPerSeconds * (float)DEFAULT_TILE_SIDE_LENGTH)
- / 1000 * (float)MILLISECONDS_IN_A_TICK;
+ Vector speedInTicks;
+ Game *game = Game::instance();
+ Map *map = 0;
+ if (game)
+ {
+ map = game->getCurrentMap();
+ if (map)
+ {
+ speedInTicks.x = speedInTilesPerSeconds
+ * (float)map->getTileWidth()
+ / 1000 * (float)MILLISECONDS_IN_A_TICK;
+ speedInTicks.y = speedInTilesPerSeconds
+ * (float)map->getTileHeight()
+ / 1000 * (float)MILLISECONDS_IN_A_TICK;
+ }
+ }
+
+ if (!game || !map)
+ {
+ speedInTicks.x = speedInTicks.y = speedInTilesPerSeconds
+ * (float)DEFAULT_TILE_SIDE_LENGTH
+ / 1000 * (float)MILLISECONDS_IN_A_TICK;
+ }
+ // We don't use z for now.
+ speedInTicks.z = 0;
+
+ return speedInTicks;
}
static void handleLooks(Player *being, Net::MessageIn &msg)
diff --git a/src/net/manaserv/beinghandler.h b/src/net/manaserv/beinghandler.h
index 1d01de22..6de9a2aa 100644
--- a/src/net/manaserv/beinghandler.h
+++ b/src/net/manaserv/beinghandler.h
@@ -23,6 +23,8 @@
#define NET_MANASERV_BEINGHANDLER_H
#include "net/manaserv/messagehandler.h"
+#include "vector.h"
+#include "map.h"
namespace ManaServ {
@@ -39,7 +41,7 @@ class BeingHandler : public MessageHandler
* Used to optimize Being::logic() calls.
* @see MILLISECONDS_IN_A_TICKS
*/
- static float giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds);
+ static Vector giveSpeedInPixelsPerTicks(float speedInTilesPerSeconds);
private:
void handleBeingAttackMessage(Net::MessageIn &msg);
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 9dbd3027..007aa93f 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -432,7 +432,7 @@ int PlayerHandler::getJobLocation()
return -1;
}
-float PlayerHandler::getDefaultWalkSpeed()
+Vector PlayerHandler::getDefaultWalkSpeed()
{
// Return translation in pixels per ticks.
return ManaServ::BeingHandler::giveSpeedInPixelsPerTicks(6.0f);
diff --git a/src/net/manaserv/playerhandler.h b/src/net/manaserv/playerhandler.h
index edcc5905..6edc96bb 100644
--- a/src/net/manaserv/playerhandler.h
+++ b/src/net/manaserv/playerhandler.h
@@ -73,7 +73,7 @@ class PlayerHandler : public MessageHandler, public Net::PlayerHandler
int getJobLocation();
- float getDefaultWalkSpeed();
+ Vector getDefaultWalkSpeed();
private:
void handleMapChangeMessage(Net::MessageIn &msg);
diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h
index f8fc6b85..0174ede2 100644
--- a/src/net/playerhandler.h
+++ b/src/net/playerhandler.h
@@ -61,7 +61,7 @@ class PlayerHandler
virtual int getJobLocation() = 0;
- virtual float getDefaultWalkSpeed() = 0;
+ virtual Vector getDefaultWalkSpeed() = 0;
virtual ~PlayerHandler() {}
};
diff --git a/src/player.cpp b/src/player.cpp
index 1d0556a6..e537a2b9 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -86,7 +86,8 @@ void Player::logic()
break;
case WALK:
- mFrame = (int) ((get_elapsed_time(mWalkTime) * 6) / getWalkSpeed());
+ mFrame = (int) ((get_elapsed_time(mWalkTime) * 6)
+ / getWalkSpeed().x);
if (mFrame >= 6)
nextTile();
break;
diff --git a/src/vector.h b/src/vector.h
index 3a5c01c1..0122435f 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -71,6 +71,16 @@ class Vector
}
/**
+ * Scale vector operator.
+ */
+ Vector operator*(const Vector &v) const
+ {
+ return Vector(x * v.x,
+ y * v.y,
+ z * v.z);
+ }
+
+ /**
* In-place scale vector operator.
*/
Vector &operator*=(float c)
@@ -145,6 +155,22 @@ class Vector
}
/**
+ * In-place > test vector operator.
+ */
+ bool operator>(const Vector &v)
+ {
+ return (x > v.x || y > v.y || z > v.z);
+ }
+
+ /**
+ * In-place > test vector operator against a float.
+ */
+ bool operator>(float c)
+ {
+ return (x > c || y > c || z > c);
+ }
+
+ /**
* Returns the length of this vector. This method does a relatively
* slow square root.
*/