diff options
-rw-r--r-- | src/game-server/being.cpp | 3 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 2 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 2 | ||||
-rw-r--r-- | src/utils/speedconv.cpp | 16 | ||||
-rw-r--r-- | src/utils/speedconv.h | 18 |
5 files changed, 28 insertions, 13 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 9400f5df..e266da0d 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -432,7 +432,8 @@ bool Being::recalculateBaseAttribute(unsigned int attr) newBase = 3.0 + getModifiedAttribute(ATTR_AGI) * 0.08; // Provisional. break; case ATTR_MOVE_SPEED_RAW: - newBase = utils::tpsToSpeed(getModifiedAttribute(ATTR_MOVE_SPEED_TPS)); + newBase = utils::tpsToRawSpeed( + getModifiedAttribute(ATTR_MOVE_SPEED_TPS)); break; case ATTR_INV_CAPACITY: // Provisional diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index d78f04ba..661aca5e 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -107,7 +107,7 @@ Monster::Monster(MonsterClass *specy): // Set the speed in tiles per second. setAttribute(ATTR_MOVE_SPEED_RAW, - utils::tpsToSpeed(getAttribute(ATTR_MOVE_SPEED_TPS))); + utils::tpsToRawSpeed(getAttribute(ATTR_MOVE_SPEED_TPS))); setSize(specy->getSize()); // Set positions relative to target from which the monster can attack diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index f79f2f8d..2635974e 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -661,7 +661,7 @@ static int being_walk(lua_State *s) if (lua_isnumber(s, 4)) { being->setAttribute(ATTR_MOVE_SPEED_TPS, lua_tonumber(s, 4)); - being->setAttribute(ATTR_MOVE_SPEED_RAW, utils::tpsToSpeed( + being->setAttribute(ATTR_MOVE_SPEED_RAW, utils::tpsToRawSpeed( being->getModifiedAttribute(ATTR_MOVE_SPEED_TPS))); } diff --git a/src/utils/speedconv.cpp b/src/utils/speedconv.cpp index f6be2e7b..29ab059c 100644 --- a/src/utils/speedconv.cpp +++ b/src/utils/speedconv.cpp @@ -20,12 +20,20 @@ #include "utils/speedconv.h" -double utils::tpsToSpeed(double tps) +#include "defines.h" + +// Defines the max base scale used to compute the raw speed system. +// The raw speed is the number of tile moves per server tick * 100 +// since a server tick is currently 100 ms. +// TODO: Deharcode the magic value by obtaining the server tick time. +#define MAX_MOVE_TIME 32000 + +double utils::tpsToRawSpeed(double tps) { - return (32000 / (tps * DEFAULT_TILE_LENGTH)); + return (MAX_MOVE_TIME / (tps * DEFAULT_TILE_LENGTH)); } -double utils::speedToTps(double speed) +double utils::rawSpeedToTps(double speed) { - return (32000 / (speed * DEFAULT_TILE_LENGTH)); + return (MAX_MOVE_TIME / (speed * DEFAULT_TILE_LENGTH)); } diff --git a/src/utils/speedconv.h b/src/utils/speedconv.h index 33e1a944..7dca10e7 100644 --- a/src/utils/speedconv.h +++ b/src/utils/speedconv.h @@ -24,21 +24,27 @@ // Simple helper functions for converting between tiles per // second and the internal speed representation -#include "defines.h" - namespace utils { /** - * tpsToSpeed() + * Translate the speed in tiles per second (tps) + * into the raw speed used internally. + * The raw speed is the number of tiles moves per server tick * 100 + * since a server tick is currently 100 ms. + * * @param tps The speed value in tiles per second + * * @returns The speed value in the internal representation */ - double tpsToSpeed(double); + double tpsToRawSpeed(double); + /** - * speedToTps() + * Translate the raw speed used internally into a tile per second one. + * * @param speed The speed value in the internal representation + * * @returns The speed value in tiles per second */ - double speedToTps(double); + double rawSpeedToTps(double); } #endif // SPEEDCONV_H |