From a52ff707fe851cac10351a66d8dcca5213438d04 Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Mon, 2 Jan 2012 17:01:48 -0200 Subject: [PATCH] look improvements --- modules/game_textmessage/textmessage.lua | 1 - src/otclient/core/game.cpp | 21 +++++-- src/otclient/core/tile.cpp | 16 +++-- src/otclient/core/tile.h | 1 + src/otclient/ui/uimap.cpp | 78 +++++++++++------------- src/otclient/util/position.h | 2 +- 6 files changed, 65 insertions(+), 54 deletions(-) diff --git a/modules/game_textmessage/textmessage.lua b/modules/game_textmessage/textmessage.lua index a3300474..f56b1156 100644 --- a/modules/game_textmessage/textmessage.lua +++ b/modules/game_textmessage/textmessage.lua @@ -32,7 +32,6 @@ end -- hooked events function TextMessage.onTextMessage(type, message) local messageType = messageTypes[type - messageTypes.first] - print(messageType.color) if messageType.showOnConsole then -- TODO diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b5fb88ea..6af322f1 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -158,13 +158,22 @@ void Game::turn(Otc::Direction direction) void Game::look(const Position& position) { - const TilePtr& tile = g_map.getTile(position); - if(tile) { - int stackpos = tile->getLookStackpos(); - ThingPtr thing = tile->getThing(stackpos); - if(thing) - m_protocolGame->sendLookAt(position, thing->getId(), stackpos); + Position tilePos = position; + TilePtr tile = nullptr; + int stackpos = -1; + + while(true) { + tile = g_map.getTile(tilePos); + stackpos = tile->getLookStackpos(); + if(stackpos != -1 || tilePos.z >= Map::MAX_Z) + break; + + tilePos.coveredDown(); } + + ThingPtr thing = tile->getThing(stackpos); + if(thing) + m_protocolGame->sendLookAt(tilePos, thing->getId(), stackpos); } void Game::talkChannel(int channelType, int channelId, const std::string& message) diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index d80ae580..ae749c4c 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -183,10 +183,13 @@ ItemPtr Tile::getGround() int Tile::getLookStackpos() { - // TODO: this needs to be improved - // check if thing has look property. - // check other floors - return m_things.size() - 1; + for(int i = m_things.size() - 1; i >= 0; --i) { + ThingType *type = m_things[i]->getType(); + if(!type->properties[ThingType::IgnoreLook] && + (type->properties[ThingType::IsGround] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsOnTop])) + return i; + } + return -1; } bool Tile::isWalkable() @@ -247,6 +250,11 @@ bool Tile::hasCreature() return false; } +bool Tile::isEmpty() +{ + return m_things.size() == 0; +} + /*bool Tile::canAttack() { return hasCreature(); diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 75951a08..a37650db 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -52,6 +52,7 @@ public: bool isFullyOpaque(); bool isLookPossible(); bool hasCreature(); + bool isEmpty(); void useItem(); diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index 52ccca49..798441bb 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -58,50 +58,44 @@ void UIMap::onStyleApply(const OTMLNodePtr& styleNode) bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) { - if(m_mapRect.contains(mousePos)) { - Point relativeStretchMousePos = mousePos - m_mapRect.topLeft(); - Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS); - - PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height()); - PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor; - - PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS; - Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition(); - - TilePtr tile = g_map.getTile(tilePos); - if(tile) - tile->useItem(); - - // cool testing \/ - if(button == Fw::MouseLeftButton) { - MissilePtr shot = MissilePtr(new Missile()); - shot->setId(1); - shot->setPath(g_map.getCentralPosition(), tilePos); - g_map.addThing(shot, g_map.getCentralPosition()); - - AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setPosition(g_map.getCentralPosition()); - animatedText->setColor(12); - animatedText->setText("text"); - - g_map.addThing(animatedText, g_map.getCentralPosition()); - } - else if(button == Fw::MouseRightButton) { - EffectPtr effect = EffectPtr(new Effect()); - effect->setId(6); - g_map.addThing(effect, tilePos); - - AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setPosition(g_map.getCentralPosition()); - animatedText->setColor(12); - animatedText->setText("8"); - g_map.addThing(animatedText, g_map.getCentralPosition()); - - g_game.look(tilePos); - } + if(!m_mapRect.contains(mousePos)) + return UIWidget::onMousePress(mousePos, button); + + // Get tile position + Point relativeStretchMousePos = mousePos - m_mapRect.topLeft(); + Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS); + + PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height()); + PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor; + + PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS; + Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition(); + + // Get tile + TilePtr tile = nullptr; + + // We must check every floor, from top to bottom + int firstFloor = g_map.getFirstVisibleFloor(); + tilePos.perspectiveUp(tilePos.z - firstFloor); + for(int i = firstFloor; i <= Map::MAX_Z; i++) { + tile = g_map.getTile(tilePos); + if(!tile->isEmpty()) + break; + tilePos.coveredDown(); + } + + if(!tile || tile->isEmpty()) + return true; + + //tile->useItem(); + + if(button == Fw::MouseLeftButton) { + } + else if(button == Fw::MouseRightButton) { + g_game.look(tilePos); } - return UIWidget::onMousePress(mousePos, button); + return true; } void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect) diff --git a/src/otclient/util/position.h b/src/otclient/util/position.h index d48ed9fe..a39dba44 100644 --- a/src/otclient/util/position.h +++ b/src/otclient/util/position.h @@ -98,7 +98,7 @@ public: return Otc::InvalidDirection; } - bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 15; } + bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 16; } Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); } Position& operator+=(const Position& other) { x+=other.x; y+=other.y; z +=other.z; return *this; }