From 82dc42dc269474b0a8f71d5df0ed3ec647d71d12 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 2 Feb 2012 19:20:34 -0200 Subject: [PATCH] restore drawing elevation for creature names --- src/otclient/core/creature.cpp | 16 ++++++++++++++-- src/otclient/core/creature.h | 4 ++-- src/otclient/core/game.cpp | 11 ++--------- src/otclient/core/map.cpp | 21 ++++++++------------- src/otclient/core/mapview.cpp | 5 ++--- src/otclient/core/tile.cpp | 28 +++++++++++++--------------- src/otclient/util/position.h | 4 ++-- 7 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 31455540..3b542b69 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -504,5 +504,17 @@ void Creature::updateShield() m_showShieldTexture = true; } - - +Point Creature::getDrawOffset() +{ + Point drawOffset; + if(m_walking) { + if(m_walkingTile) + drawOffset -= Point(1,1) * m_walkingTile->getDrawElevation(); + drawOffset += m_walkOffset; + } else { + const TilePtr& tile = getTile(); + if(tile) + drawOffset -= Point(1,1) * tile->getDrawElevation(); + } + return drawOffset; +} diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 1f5a5a86..fa9e1008 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -75,15 +75,15 @@ public: uint8 getShield() { return m_shield; } uint8 getEmblem() { return m_emblem; } bool getPassable() { return m_passable; } + Point getDrawOffset(); + Point getWalkOffset() { return m_walkOffset; } - void updateInvisibleAnimation(); void updateShield(); // walk related void turn(Otc::Direction direction); virtual void walk(const Position& oldPos, const Position& newPos); virtual void stopWalk(); - Point getWalkOffset() { return m_walkOffset; } bool isWalking() { return m_walking; } diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 9c58697f..676aef3a 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -210,6 +210,7 @@ void Game::processCreatureTeleport(const CreaturePtr& creature) { // stop walking on creature teleports creature->stopWalk(); + dump << "stop walk" << creature->getName(); if(creature == m_localPlayer) m_localPlayer->lockWalk(); @@ -237,15 +238,7 @@ void Game::walk(Otc::Direction direction) if(!m_localPlayer->canWalk(direction)) return; - - // 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 + // only do prewalks to walkable tiles TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction)); if(toTile && toTile->isWalkable()) m_localPlayer->preWalk(direction); diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index c13ca90f..455807fa 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -129,6 +129,8 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos) tile->addThing(thing, stackPos); // creature teleported + if(creature == g_game.getLocalPlayer()) + dump << "creature move from" << oldPos << "to" << pos; if(oldPos.isValid() && !oldPos.isInRange(pos,1,1)) g_game.processCreatureTeleport(creature); } else if(MissilePtr missile = thing->asMissile()) { @@ -172,9 +174,10 @@ ThingPtr Map::getThing(const Position& pos, int stackPos) bool Map::removeThing(const ThingPtr& thing) { - if(!thing) { + if(!thing) return false; - } else if(MissilePtr missile = thing->asMissile()) { + + if(MissilePtr missile = thing->asMissile()) { auto it = std::find(m_floorMissiles[missile->getPosition().z].begin(), m_floorMissiles[missile->getPosition().z].end(), missile); if(it != m_floorMissiles[missile->getPosition().z].end()) { m_floorMissiles[missile->getPosition().z].erase(it); @@ -192,7 +195,7 @@ bool Map::removeThing(const ThingPtr& thing) m_staticTexts.erase(it); return true; } - } else if(TilePtr tile = getTile(thing->getPosition())) + } else if(TilePtr tile = thing->getTile()) return tile->removeThing(thing); notificateTileUpdateToMapViews(thing->getPosition()); @@ -272,22 +275,14 @@ void Map::setCentralPosition(const Position& centralPosition) if(teleported) { for(const auto& pair : m_knownCreatures) { const CreaturePtr& creature = pair.second; - const TilePtr& tile = creature->getTile(); - if(tile) { - tile->removeThing(creature); - creature->setPosition(Position()); - } + removeThing(creature); } // remove creatures from tiles that we are not aware anymore } else { for(const auto& pair : m_knownCreatures) { const CreaturePtr& creature = pair.second; if(!isAwareOfPosition(creature->getPosition())) { - const TilePtr& tile = creature->getTile(); - if(tile) { - tile->removeThing(creature); - creature->setPosition(Position()); - } + removeThing(creature); } } } diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index 1a8e2f75..984b691b 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -122,11 +122,10 @@ void MapView::draw(const Rect& rect) // avoid drawing texts on map in far zoom outs if(m_viewRange == NEAR_VIEW) { for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) { - const TilePtr& tile = creature->getTile(); - Position pos = tile->getPosition(); + Position pos = creature->getPosition(); Point p = transformPositionTo2D(pos) - drawOffset; - p += (creature->getWalkOffset()-tile->getDrawElevation() + Point(8, -10)) * scaleFactor; + p += (creature->getDrawOffset() + Point(8, -10)) * scaleFactor; p.x = p.x * horizontalStretchFactor; p.y = p.y * verticalStretchFactor; p += rect.topLeft(); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 9ed7dfef..99a7c1bb 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -38,7 +38,7 @@ Tile::Tile(const Position& position) void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) { - int drawElevation = 0; + m_drawElevation = 0; bool animate = drawFlags & Otc::DrawAnimations; // first bottom items @@ -50,11 +50,11 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) if((thing->isGround() && drawFlags & Otc::DrawGround) || (thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) || (thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) - thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate); + thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate); - drawElevation += thing->getElevation(); - if(drawElevation > Otc::MAX_ELEVATION) - drawElevation = Otc::MAX_ELEVATION; + m_drawElevation += thing->getElevation(); + if(m_drawElevation > Otc::MAX_ELEVATION) + m_drawElevation = Otc::MAX_ELEVATION; } } @@ -67,16 +67,16 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) const ThingPtr& thing = *it; if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->asCreature()) break; - thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate); + thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate); if(thing->isLyingCorpse()) { redrawPreviousTopW = std::max(thing->getDimensionWidth(), redrawPreviousTopW); redrawPreviousTopH = std::max(thing->getDimensionHeight(), redrawPreviousTopH); } - drawElevation += thing->getElevation(); - if(drawElevation > Otc::MAX_ELEVATION) - drawElevation = Otc::MAX_ELEVATION; + m_drawElevation += thing->getElevation(); + if(m_drawElevation > Otc::MAX_ELEVATION) + m_drawElevation = Otc::MAX_ELEVATION; } } @@ -100,8 +100,8 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) if(drawFlags & Otc::DrawCreatures) { if(animate) { for(const CreaturePtr& creature : m_walkingCreatures) { - creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - drawElevation)*scaleFactor, - dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - drawElevation)*scaleFactor), scaleFactor, animate); + creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor, + dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate); } } @@ -109,7 +109,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { CreaturePtr creature = (*it)->asCreature(); if(creature && (!creature->isWalking() || !animate)) - creature->draw(dest - drawElevation, scaleFactor, animate); + creature->draw(dest - m_drawElevation, scaleFactor, animate); } } @@ -123,7 +123,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) if(drawFlags & Otc::DrawOnTop) { for(const ThingPtr& thing : m_things) { if(thing->isOnTop()) - thing->draw(dest - drawElevation, scaleFactor, animate); + thing->draw(dest - m_drawElevation, scaleFactor, animate); } } } @@ -151,8 +151,6 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos) if(!thing) return nullptr; - thing->setPosition(m_position); - if(EffectPtr effect = thing->asEffect()) { m_effects.push_back(effect); return nullptr; diff --git a/src/otclient/util/position.h b/src/otclient/util/position.h index 33b93b19..67bf8178 100644 --- a/src/otclient/util/position.h +++ b/src/otclient/util/position.h @@ -160,9 +160,9 @@ public: bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; } bool operator!=(const Position& other) const { return other.x!=x || other.y!=y || other.z!=z; } - bool isInRange(const Position& pos, int xRange, int yRange) const { return std::abs(x-pos.x) <= xRange && std::abs(y-pos.y) <= yRange; } + bool isInRange(const Position& pos, int xRange, int yRange) const { return std::abs(x-pos.x) <= xRange && std::abs(y-pos.y) <= yRange && z == pos.z; } bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const { - return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange); + return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z); } bool up(int n = 1) {