From b859f669521f8921efbb1cfb107f712f7a8dc5ec Mon Sep 17 00:00:00 2001 From: Henrique Date: Mon, 29 Aug 2011 02:54:28 -0300 Subject: [PATCH] diagonal walking, there is a map bug --- CMakeLists.txt | 2 +- src/otclient/const.h | 6 ++- src/otclient/core/creature.cpp | 54 ++++++++++++++++++++++----- src/otclient/core/game.cpp | 12 ++++++ src/otclient/net/protocolgame.h | 4 ++ src/otclient/net/protocolgamesend.cpp | 30 ++++++++++++++- src/otclient/ui/uimap.cpp | 12 ++++++ 7 files changed, 106 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d5f8214..a7c3040c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE}) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable") + SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch") SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline") SET(CMAKE_CXX_FLAGS_RELEASE "-O2") diff --git a/src/otclient/const.h b/src/otclient/const.h index f64cd68d..743b954f 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -79,7 +79,11 @@ namespace Otc North = 0, East, South, - West + West, + NorthEast, + SouthEast, + SouthWest, + NorthWest }; enum SpeakClasses { diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index ee4b5604..013120df 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -62,18 +62,15 @@ void Creature::draw(int x, int y) // 1000 * groundSpeed / playerSpeed // TODO 1: FIX RENDER STEP 2 - // TODO 2: FIX SHAKY EFFECT + // TODO 2: FIX DIAGONAL WALKING, BUGS MAP // TODO 3: ADD ANIMATION - // TODO 4: ADD DIAGONAL WALKING x += m_walkOffsetX; y += m_walkOffsetY; const ThingAttributes& attributes = getAttributes(); - // Render creature - m_xDiv = m_direction; for(m_yDiv = 0; m_yDiv < attributes.ydiv; m_yDiv++) { // continue if we dont have this addon. @@ -117,13 +114,14 @@ void Creature::draw(int x, int y) int pixelsWalked = std::floor((g_platform.getTicks() - m_lastTicks) / m_walkTimePerPixel); int remainingTime = (g_platform.getTicks() - m_lastTicks) % (int)m_walkTimePerPixel; - if(m_direction == Otc::North) + if(m_direction == Otc::North || m_direction == Otc::NorthEast || m_direction == Otc::NorthWest) m_walkOffsetY = std::max(m_walkOffsetY - pixelsWalked, 0); - else if(m_direction == Otc::East) - m_walkOffsetX = std::min(m_walkOffsetX + pixelsWalked, 0); - else if(m_direction == Otc::South) + else if(m_direction == Otc::South || m_direction == Otc::SouthEast || m_direction == Otc::SouthWest) m_walkOffsetY = std::min(m_walkOffsetY + pixelsWalked, 0); - else if(m_direction == Otc::West) + + if(m_direction == Otc::East || m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) + m_walkOffsetX = std::min(m_walkOffsetX + pixelsWalked, 0); + else if(m_direction == Otc::West || m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) m_walkOffsetX = std::max(m_walkOffsetX - pixelsWalked, 0); //double walkOffset = std::max(m_walkOffsetX, m_walkOffsetY); @@ -178,6 +176,7 @@ void Creature::walk(const Position& position) m_walkOffsetX = 0; m_walkOffsetY = 0; m_walkingFromPosition = m_position; + int walkTimeFactor = 1; // update map tiles g_map.removeThingByPtr(asThing()); @@ -201,11 +200,46 @@ void Creature::walk(const Position& position) m_direction = Otc::West; m_walkOffsetX = 32; } + else if(m_walkingFromPosition + Position(1, -1, 0) == m_position) { + m_direction = Otc::NorthEast; + m_walkOffsetX = -32; + m_walkOffsetY = 32; + walkTimeFactor = 2; + } + else if(m_walkingFromPosition + Position(1, 1, 0) == m_position) { + m_direction = Otc::SouthEast; + m_walkOffsetX = -32; + m_walkOffsetY = -32; + walkTimeFactor = 2; + } + else if(m_walkingFromPosition + Position(-1, 1, 0) == m_position) { + m_direction = Otc::SouthWest; + m_walkOffsetX = 32; + m_walkOffsetY = -32; + walkTimeFactor = 2; + } + else if(m_walkingFromPosition + Position(-1, -1, 0) == m_position) { + m_direction = Otc::NorthWest; + m_walkOffsetX = 32; + m_walkOffsetY = 32; + walkTimeFactor = 2; + } else { // Teleport // we teleported, dont walk or change direction m_walking = false; } + // Calculate xDiv + if(m_direction >= 4) { + if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) + m_xDiv = Otc::East; + else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) + m_xDiv = Otc::West; + } + else { + m_xDiv = m_direction; + } + // get walk speed int groundSpeed = 0; @@ -213,7 +247,7 @@ void Creature::walk(const Position& position) if(ground) groundSpeed = ground->getAttributes().speed; - float walkTime = 1000.0 * (float)groundSpeed / m_speed; + float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed; walkTime = walkTime == 0 ? 1000 : walkTime; m_walkTimePerPixel = walkTime / 32.0; diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 9f97802c..7e4a0562 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -87,6 +87,18 @@ void Game::walk(Otc::Direction direction) case Otc::West: m_protocolGame->sendWalkWest(); break; + case Otc::NorthEast: + m_protocolGame->sendWalkNorthEast(); + break; + case Otc::SouthEast: + m_protocolGame->sendWalkSouthEast(); + break; + case Otc::SouthWest: + m_protocolGame->sendWalkSouthWest(); + break; + case Otc::NorthWest: + m_protocolGame->sendWalkNorthWest(); + break; } } diff --git a/src/otclient/net/protocolgame.h b/src/otclient/net/protocolgame.h index 710fe631..40cc82d7 100644 --- a/src/otclient/net/protocolgame.h +++ b/src/otclient/net/protocolgame.h @@ -47,6 +47,10 @@ public: void sendWalkEast(); void sendWalkSouth(); void sendWalkWest(); + void sendWalkNorthEast(); + void sendWalkSouthEast(); + void sendWalkSouthWest(); + void sendWalkNorthWest(); void sendTurnNorth(); void sendTurnEast(); void sendTurnSouth(); diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index 837efca8..8a2076b2 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -102,6 +102,34 @@ void ProtocolGame::sendWalkWest() send(oMsg); } +void ProtocolGame::sendWalkNorthEast() +{ + OutputMessage oMsg; + oMsg.addU8(0x6A); + send(oMsg); +} + +void ProtocolGame::sendWalkSouthEast() +{ + OutputMessage oMsg; + oMsg.addU8(0x6B); + send(oMsg); +} + +void ProtocolGame::sendWalkSouthWest() +{ + OutputMessage oMsg; + oMsg.addU8(0x6C); + send(oMsg); +} + +void ProtocolGame::sendWalkNorthWest() +{ + OutputMessage oMsg; + oMsg.addU8(0x6D); + send(oMsg); +} + void ProtocolGame::sendTurnNorth() { OutputMessage oMsg; @@ -129,5 +157,3 @@ void ProtocolGame::sendTurnWest() oMsg.addU8(0x72); send(oMsg); } - - diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 2382227b..b105b0c9 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -52,6 +52,18 @@ bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers) } else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) { g_game.walk(Otc::West); return true; + } else if(keyCode == Fw::KeyNumpad9) { + g_game.walk(Otc::NorthEast); + return true; + } else if(keyCode == Fw::KeyNumpad3) { + g_game.walk(Otc::SouthEast); + return true; + } else if(keyCode == Fw::KeyNumpad1) { + g_game.walk(Otc::SouthWest); + return true; + } else if(keyCode == Fw::KeyNumpad7) { + g_game.walk(Otc::NorthWest); + return true; } } else if(keyboardModifiers == Fw::KeyboardCtrlModifier) { if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {