From a5b4ee2c193c99cd79b110b1a5ab2314d25149ec Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 20 Jan 2012 13:00:24 -0200 Subject: [PATCH] fix walk up/down with parcels --- modules/core_widgets/uiprogressbar.lua | 2 +- modules/game/game.otmod | 4 +-- src/framework/platform/win32window.cpp | 9 ++----- src/otclient/core/game.cpp | 36 +++++++++++++++++++------- src/otclient/core/game.h | 1 + src/otclient/core/localplayer.cpp | 10 ++----- src/otclient/core/map.cpp | 8 ++++++ src/otclient/core/tile.cpp | 12 ++++----- 8 files changed, 49 insertions(+), 33 deletions(-) diff --git a/modules/core_widgets/uiprogressbar.lua b/modules/core_widgets/uiprogressbar.lua index 5d7cb3fa..a9f0c34e 100644 --- a/modules/core_widgets/uiprogressbar.lua +++ b/modules/core_widgets/uiprogressbar.lua @@ -10,7 +10,7 @@ function UIProgressBar.create() end function UIProgressBar:setPercent(percent) - self.m_percent = percent + self.m_percent = math.max(math.min(percent, 100), 0) self:updateBackground() end diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 7187fcb1..45533180 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -7,9 +7,9 @@ Module dependencies: - game_healthbar - game_inventory - - game_skills + //- game_skills - game_textmessage - - game_viplist + //- game_viplist - game_console - game_outfit - game_containers diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index eb9421b8..ab866e22 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -27,6 +27,8 @@ #include #include +#define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8))) + WIN32Window::WIN32Window() { m_window = 0; @@ -536,7 +538,6 @@ void WIN32Window::swapBuffers() void WIN32Window::restoreMouseCursor() { - logTraceDebug(); if(m_cursor) { DestroyCursor(m_cursor); m_cursor = NULL; @@ -547,13 +548,11 @@ void WIN32Window::restoreMouseCursor() void WIN32Window::showMouse() { - logTraceDebug(); ShowCursor(true); } void WIN32Window::hideMouse() { - logTraceDebug(); ShowCursor(false); } @@ -562,12 +561,8 @@ void WIN32Window::displayFatalError(const std::string& message) MessageBoxA(m_window, message.c_str(), "FATAL ERROR", MB_OK | MB_ICONERROR); } -#define LSB_BIT_SET(p, n) (p[(n)/8] |= (1 <<((n)%8))) -#define HSB_BIT_SET(p, n) (p[(n)/8] |= (128 >>((n)%8))) - void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot) { - logTraceDebug(); std::stringstream fin; g_resources.loadFile(file, fin); diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index f75858fa..fff88903 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -138,14 +138,17 @@ void Game::processInventoryChange(int slot, const ItemPtr& item) void Game::processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos) { - // walk - if(oldPos.isInRange(newPos, 1, 1, 0)) { - creature->walk(oldPos, newPos); - // teleport - } else { - // stop walking on teleport - creature->stopWalk(); - } + if(!oldPos.isInRange(newPos, 1, 1, 0)) + logError("unexpected creature move"); + + // animate walk + creature->walk(oldPos, newPos); +} + +void Game::processCreatureTeleport(const CreaturePtr& creature) +{ + // stop walking on creature teleports + creature->stopWalk(); } void Game::processAttackCancel() @@ -170,7 +173,21 @@ void Game::walk(Otc::Direction direction) if(!m_localPlayer->canWalk(direction)) return; - m_localPlayer->preWalk(direction); + + // TODO: restore check for blockable tiles + /* + if(toTile && !toTile->isWalkable() && !fromTile->getElevation() >= 3) { + g_game.processTextMessage("statusSmall", "Sorry, not possible."); + return false; + }*/ + + // only do prewalk to walkable tiles + TilePtr toTile = g_map.getTile(m_localPlayer->getPos() + Position::getPosFromDirection(direction)); + if(toTile && toTile->isWalkable()) + m_localPlayer->preWalk(direction); + else + m_localPlayer->lockWalk(); + forceWalk(direction); } @@ -368,6 +385,7 @@ int Game::getThingStackpos(const ThingPtr& thing) { // thing is at map if(thing->getPos().x != 65535) { + dump << thing->getPos(); TilePtr tile = g_map.getTile(thing->getPos()); if(tile) return tile->getThingStackpos(thing); diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index 9b6f1f05..110cee1d 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -51,6 +51,7 @@ public: void processContainerAddItem(int containerId, const ItemPtr& item); void processInventoryChange(int slot, const ItemPtr& item); void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos); + void processCreatureTeleport(const CreaturePtr& creature); void processAttackCancel(); void processWalkCancel(Otc::Direction direction); diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index ef8c4de9..38835ee9 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -87,7 +87,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction) return false; // avoid doing more walks than wanted when receiving a lot of walks from server - if(!m_lastPrewalkDone && !prewalkTimeouted) + if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted) return false; // cannot walk while locked @@ -96,13 +96,6 @@ bool LocalPlayer::canWalk(Otc::Direction direction) else m_walkLocked = false; - // check for blockable tiles in the walk direction - TilePtr tile = g_map.getTile(m_pos + Position::getPosFromDirection(direction)); - if(!tile || !tile->isWalkable()) { - g_game.processTextMessage("statusSmall", "Sorry, not possible."); - return false; - } - return true; } @@ -122,6 +115,7 @@ void LocalPlayer::cancelWalk(Otc::Direction direction) void LocalPlayer::stopWalk() { Creature::stopWalk(); + m_lastPrewalkDone = true; m_lastPrewalkDestionation = Position(); } diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index 3987a7be..74d3b9b6 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -244,11 +244,19 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos) if(!thing) return; + Position oldPos = thing->getPos(); + bool teleport = false; + if(oldPos.isValid() && !oldPos.isInRange(pos,1,1,0)) + teleport = true; + TilePtr tile = getTile(pos); if(CreaturePtr creature = thing->asCreature()) { tile->addThing(thing, stackPos); m_creatures[creature->getId()] = creature; + + if(teleport) + g_game.processCreatureTeleport(creature); } else if(MissilePtr shot = thing->asMissile()) { m_missilesAtFloor[shot->getPos().z].push_back(shot); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index cfa3c446..c6d38a05 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -152,12 +152,12 @@ ThingPtr Tile::getTopThing() ThingPtr Tile::removeThingByStackpos(int stackPos) { - ThingPtr oldObject; + ThingPtr oldThing; if(stackPos >= 0 && stackPos < (int)m_things.size()) { - oldObject = m_things[stackPos]; + oldThing = m_things[stackPos]; m_things.erase(m_things.begin() + stackPos); } - return oldObject; + return oldThing; } ThingPtr Tile::removeThing(const ThingPtr& thing) @@ -168,13 +168,13 @@ ThingPtr Tile::removeThing(const ThingPtr& thing) m_effects.erase(it); return thing; } - ThingPtr oldObject; + ThingPtr oldThing; auto it = std::find(m_things.begin(), m_things.end(), thing); if(it != m_things.end()) { - oldObject = *it; + oldThing = *it; m_things.erase(it); } - return oldObject; + return oldThing; } std::vector Tile::getCreatures()