diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/beinghandler.cpp | 4 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 72371da5..f96cdcd5 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -32,6 +32,7 @@ #include "../localplayer.h" #include "../log.h" #include "../main.h" +#include "../npc.h" #include "../particle.h" #include "../sound.h" @@ -268,7 +269,7 @@ void BeingHandler::handleBeingAttackMessage(MessageIn &msg) int attackType = msg.readInt8(); if (!being) return; - + switch (direction) { case DIRECTION_UP: being->setDirection(Being::UP); break; @@ -347,3 +348,4 @@ void BeingHandler::handleBeingDirChangeMessage(MessageIn &msg) case DIRECTION_RIGHT: being->setDirection(Being::RIGHT); break; } } + diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ad271f15..beb59250 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -50,6 +50,11 @@ extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; +/* Max. distance we are willing to scroll after a teleport; + * everything beyond will reset the port hard. + */ +static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * 32; + /** * Listener used for handling the overweigth message. */ @@ -292,6 +297,7 @@ PlayerHandler::handleMapChangeMessage(MessageIn &msg) const std::string mapName = msg.readString(); const unsigned short x = msg.readInt16(); const unsigned short y = msg.readInt16(); + const bool nearby = (engine->getCurrentMapName() == mapName); logger->log("Changing map to %s (%d, %d)", mapName.c_str(), x, y); @@ -301,8 +307,16 @@ PlayerHandler::handleMapChangeMessage(MessageIn &msg) current_npc = 0; const Vector &playerPos = player_node->getPosition(); - const float scrollOffsetX = x - (int) playerPos.x; - const float scrollOffsetY = y - (int) playerPos.y; + float scrollOffsetX = 0.0f; + float scrollOffsetY = 0.0f; + + /* Scroll if neccessary */ + if (!nearby + || (abs(x - (int) playerPos.x) > MAP_TELEPORT_SCROLL_DISTANCE) + || (abs(y - (int) playerPos.y) > MAP_TELEPORT_SCROLL_DISTANCE)) { + scrollOffsetX = x - (int) playerPos.x; + scrollOffsetY = y - (int) playerPos.y; + } player_node->setAction(Being::STAND); player_node->setPosition(x, y); |