diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-25 15:03:40 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-04-25 15:45:47 +0200 |
commit | 2ce00c5f8ffb341ee65395d9700ca304851097b9 (patch) | |
tree | 6c2b77338d184c1664d82ead304b0f5031660660 /src/game-server | |
parent | 25496f7f506852d669e3c655fa922390a8e4751c (diff) | |
download | manaserv-2ce00c5f8ffb341ee65395d9700ca304851097b9.tar.gz manaserv-2ce00c5f8ffb341ee65395d9700ca304851097b9.tar.xz manaserv-2ce00c5f8ffb341ee65395d9700ca304851097b9.zip |
Simplified BeingComponent::updateDirection
Same as in the client.
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/being.cpp | 79 | ||||
-rw-r--r-- | src/game-server/map.h | 2 |
2 files changed, 7 insertions, 74 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 6f5b858..4ddec98 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -172,82 +172,16 @@ void BeingComponent::updateDirection(Entity &entity, // We update the being direction on each tile to permit other beings // entering in range to always see the being with a direction value. - // We first handle simple cases - - // If the character has reached its destination, - // don't update the direction since it's only a matter of keeping - // the previous one. if (currentPos == destPos) return; - if (currentPos.x == destPos.x) - { - if (currentPos.y > destPos.y) - setDirection(entity, UP); - else - setDirection(entity, DOWN); - return; - } - - if (currentPos.y == destPos.y) - { - if (currentPos.x > destPos.x) - setDirection(entity, LEFT); - else - setDirection(entity, RIGHT); - return; - } + const int dx = destPos.x - currentPos.x; + const int dy = destPos.y - currentPos.y; - // Now let's handle diagonal cases - // First, find the lower angle: - if (currentPos.x < destPos.x) - { - // Up-right direction - if (currentPos.y > destPos.y) - { - // Compute tan of the angle - if ((currentPos.y - destPos.y) / (destPos.x - currentPos.x) < 1) - // The angle is less than 45°, we look to the right - setDirection(entity, RIGHT); - else - setDirection(entity, UP); - return; - } - else // Down-right - { - // Compute tan of the angle - if ((destPos.y - currentPos.y) / (destPos.x - currentPos.x) < 1) - // The angle is less than 45°, we look to the right - setDirection(entity, RIGHT); - else - setDirection(entity, DOWN); - return; - } - } + if (std::abs(dx) > std::abs(dy)) + setDirection(entity, (dx < 0) ? LEFT : RIGHT); else - { - // Up-left direction - if (currentPos.y > destPos.y) - { - // Compute tan of the angle - if ((currentPos.y - destPos.y) / (currentPos.x - destPos.x) < 1) - // The angle is less than 45°, we look to the left - setDirection(entity, LEFT); - else - setDirection(entity, UP); - return; - } - else // Down-left - { - // Compute tan of the angle - if ((destPos.y - currentPos.y) / (currentPos.x - destPos.x) < 1) - // The angle is less than 45°, we look to the left - setDirection(entity, LEFT); - else - setDirection(entity, DOWN); - return; - } - } + setDirection(entity, (dy < 0) ? UP : DOWN); } void BeingComponent::move(Entity &entity) @@ -300,7 +234,7 @@ void BeingComponent::move(Entity &entity) * class has been used, because that seems to be the most logical * place extra functionality will be added. */ - for (PathIterator pathIterator = mPath.begin(); + for (Path::iterator pathIterator = mPath.begin(); pathIterator != mPath.end(); pathIterator++) { const unsigned char walkmask = @@ -652,4 +586,3 @@ void BeingComponent::inserted(Entity *entity) // in sync with the zone that we're currently present in. mOld = entity->getComponent<ActorComponent>()->getPosition(); } - diff --git a/src/game-server/map.h b/src/game-server/map.h index 9f058fb..2ade1d7 100644 --- a/src/game-server/map.h +++ b/src/game-server/map.h @@ -31,7 +31,7 @@ #include "utils/string.h" typedef std::list<Point> Path; -typedef Path::iterator PathIterator; + enum BlockType { BLOCKTYPE_NONE = -1, |