restore drawing elevation for creature names

This commit is contained in:
Eduardo Bart 2012-02-02 19:20:34 -02:00
parent 3a83666b9f
commit 82dc42dc26
7 changed files with 43 additions and 46 deletions

View File

@ -504,5 +504,17 @@ void Creature::updateShield()
m_showShieldTexture = true; 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;
}

View File

@ -75,15 +75,15 @@ public:
uint8 getShield() { return m_shield; } uint8 getShield() { return m_shield; }
uint8 getEmblem() { return m_emblem; } uint8 getEmblem() { return m_emblem; }
bool getPassable() { return m_passable; } bool getPassable() { return m_passable; }
Point getDrawOffset();
Point getWalkOffset() { return m_walkOffset; }
void updateInvisibleAnimation();
void updateShield(); void updateShield();
// walk related // walk related
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
virtual void walk(const Position& oldPos, const Position& newPos); virtual void walk(const Position& oldPos, const Position& newPos);
virtual void stopWalk(); virtual void stopWalk();
Point getWalkOffset() { return m_walkOffset; }
bool isWalking() { return m_walking; } bool isWalking() { return m_walking; }

View File

@ -210,6 +210,7 @@ void Game::processCreatureTeleport(const CreaturePtr& creature)
{ {
// stop walking on creature teleports // stop walking on creature teleports
creature->stopWalk(); creature->stopWalk();
dump << "stop walk" << creature->getName();
if(creature == m_localPlayer) if(creature == m_localPlayer)
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
@ -237,15 +238,7 @@ void Game::walk(Otc::Direction direction)
if(!m_localPlayer->canWalk(direction)) if(!m_localPlayer->canWalk(direction))
return; return;
// only do prewalks to walkable tiles
// 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->getPosition().translatedToDirection(direction)); TilePtr toTile = g_map.getTile(m_localPlayer->getPosition().translatedToDirection(direction));
if(toTile && toTile->isWalkable()) if(toTile && toTile->isWalkable())
m_localPlayer->preWalk(direction); m_localPlayer->preWalk(direction);

View File

@ -129,6 +129,8 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
tile->addThing(thing, stackPos); tile->addThing(thing, stackPos);
// creature teleported // creature teleported
if(creature == g_game.getLocalPlayer())
dump << "creature move from" << oldPos << "to" << pos;
if(oldPos.isValid() && !oldPos.isInRange(pos,1,1)) if(oldPos.isValid() && !oldPos.isInRange(pos,1,1))
g_game.processCreatureTeleport(creature); g_game.processCreatureTeleport(creature);
} else if(MissilePtr missile = thing->asMissile()) { } else if(MissilePtr missile = thing->asMissile()) {
@ -172,9 +174,10 @@ ThingPtr Map::getThing(const Position& pos, int stackPos)
bool Map::removeThing(const ThingPtr& thing) bool Map::removeThing(const ThingPtr& thing)
{ {
if(!thing) { if(!thing)
return false; 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); 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()) { if(it != m_floorMissiles[missile->getPosition().z].end()) {
m_floorMissiles[missile->getPosition().z].erase(it); m_floorMissiles[missile->getPosition().z].erase(it);
@ -192,7 +195,7 @@ bool Map::removeThing(const ThingPtr& thing)
m_staticTexts.erase(it); m_staticTexts.erase(it);
return true; return true;
} }
} else if(TilePtr tile = getTile(thing->getPosition())) } else if(TilePtr tile = thing->getTile())
return tile->removeThing(thing); return tile->removeThing(thing);
notificateTileUpdateToMapViews(thing->getPosition()); notificateTileUpdateToMapViews(thing->getPosition());
@ -272,22 +275,14 @@ void Map::setCentralPosition(const Position& centralPosition)
if(teleported) { if(teleported) {
for(const auto& pair : m_knownCreatures) { for(const auto& pair : m_knownCreatures) {
const CreaturePtr& creature = pair.second; const CreaturePtr& creature = pair.second;
const TilePtr& tile = creature->getTile(); removeThing(creature);
if(tile) {
tile->removeThing(creature);
creature->setPosition(Position());
}
} }
// remove creatures from tiles that we are not aware anymore // remove creatures from tiles that we are not aware anymore
} else { } else {
for(const auto& pair : m_knownCreatures) { for(const auto& pair : m_knownCreatures) {
const CreaturePtr& creature = pair.second; const CreaturePtr& creature = pair.second;
if(!isAwareOfPosition(creature->getPosition())) { if(!isAwareOfPosition(creature->getPosition())) {
const TilePtr& tile = creature->getTile(); removeThing(creature);
if(tile) {
tile->removeThing(creature);
creature->setPosition(Position());
}
} }
} }
} }

View File

@ -122,11 +122,10 @@ void MapView::draw(const Rect& rect)
// avoid drawing texts on map in far zoom outs // avoid drawing texts on map in far zoom outs
if(m_viewRange == NEAR_VIEW) { if(m_viewRange == NEAR_VIEW) {
for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) { for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) {
const TilePtr& tile = creature->getTile(); Position pos = creature->getPosition();
Position pos = tile->getPosition();
Point p = transformPositionTo2D(pos) - drawOffset; 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.x = p.x * horizontalStretchFactor;
p.y = p.y * verticalStretchFactor; p.y = p.y * verticalStretchFactor;
p += rect.topLeft(); p += rect.topLeft();

View File

@ -38,7 +38,7 @@ Tile::Tile(const Position& position)
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
{ {
int drawElevation = 0; m_drawElevation = 0;
bool animate = drawFlags & Otc::DrawAnimations; bool animate = drawFlags & Otc::DrawAnimations;
// first bottom items // first bottom items
@ -50,11 +50,11 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
if((thing->isGround() && drawFlags & Otc::DrawGround) || if((thing->isGround() && drawFlags & Otc::DrawGround) ||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) || (thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) (thing->isOnBottom() && drawFlags & Otc::DrawOnBottom))
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate); thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate);
drawElevation += thing->getElevation(); m_drawElevation += thing->getElevation();
if(drawElevation > Otc::MAX_ELEVATION) if(m_drawElevation > Otc::MAX_ELEVATION)
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; const ThingPtr& thing = *it;
if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->asCreature()) if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->asCreature())
break; break;
thing->draw(dest - drawElevation*scaleFactor, scaleFactor, animate); thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate);
if(thing->isLyingCorpse()) { if(thing->isLyingCorpse()) {
redrawPreviousTopW = std::max(thing->getDimensionWidth(), redrawPreviousTopW); redrawPreviousTopW = std::max(thing->getDimensionWidth(), redrawPreviousTopW);
redrawPreviousTopH = std::max(thing->getDimensionHeight(), redrawPreviousTopH); redrawPreviousTopH = std::max(thing->getDimensionHeight(), redrawPreviousTopH);
} }
drawElevation += thing->getElevation(); m_drawElevation += thing->getElevation();
if(drawElevation > Otc::MAX_ELEVATION) if(m_drawElevation > Otc::MAX_ELEVATION)
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(drawFlags & Otc::DrawCreatures) {
if(animate) { if(animate) {
for(const CreaturePtr& creature : m_walkingCreatures) { for(const CreaturePtr& creature : m_walkingCreatures) {
creature->draw(Point(dest.x + ((creature->getPosition().x - m_position.x)*Otc::TILE_PIXELS - drawElevation)*scaleFactor, 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 - drawElevation)*scaleFactor), scaleFactor, animate); 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) { for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
CreaturePtr creature = (*it)->asCreature(); CreaturePtr creature = (*it)->asCreature();
if(creature && (!creature->isWalking() || !animate)) 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) { if(drawFlags & Otc::DrawOnTop) {
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
if(thing->isOnTop()) 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) if(!thing)
return nullptr; return nullptr;
thing->setPosition(m_position);
if(EffectPtr effect = thing->asEffect()) { if(EffectPtr effect = thing->asEffect()) {
m_effects.push_back(effect); m_effects.push_back(effect);
return nullptr; return nullptr;

View File

@ -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 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 { 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) { bool up(int n = 1) {