|
|
|
@ -38,7 +38,7 @@ Tile::Tile(const Position& position)
|
|
|
|
|
|
|
|
|
|
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
|
|
|
|
{
|
|
|
|
|
m_drawElevation = 0;
|
|
|
|
|
int drawElevation = 0;
|
|
|
|
|
|
|
|
|
|
// first bottom items
|
|
|
|
|
if(drawFlags & Otc::DrawGround || drawFlags & Otc::DrawWalls) {
|
|
|
|
@ -47,11 +47,11 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if((drawFlags & Otc::DrawGround && thing->isGround()) || (drawFlags & Otc::DrawWalls))
|
|
|
|
|
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor);
|
|
|
|
|
thing->draw(dest - drawElevation*scaleFactor, scaleFactor);
|
|
|
|
|
|
|
|
|
|
m_drawElevation += thing->getElevation();
|
|
|
|
|
if(m_drawElevation > Otc::MAX_ELEVATION)
|
|
|
|
|
m_drawElevation = Otc::MAX_ELEVATION;
|
|
|
|
|
drawElevation += thing->getElevation();
|
|
|
|
|
if(drawElevation > Otc::MAX_ELEVATION)
|
|
|
|
|
drawElevation = Otc::MAX_ELEVATION;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -59,37 +59,28 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
|
|
|
|
if(drawFlags & Otc::DrawCommonItems) {
|
|
|
|
|
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
|
|
|
|
const ThingPtr& thing = *it;
|
|
|
|
|
if(thing->asCreature() || thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround())
|
|
|
|
|
if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->asCreature())
|
|
|
|
|
break;
|
|
|
|
|
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor);
|
|
|
|
|
thing->draw(dest - drawElevation*scaleFactor, scaleFactor);
|
|
|
|
|
|
|
|
|
|
m_drawElevation += thing->getElevation();
|
|
|
|
|
if(m_drawElevation > Otc::MAX_ELEVATION)
|
|
|
|
|
m_drawElevation = Otc::MAX_ELEVATION;
|
|
|
|
|
drawElevation += thing->getElevation();
|
|
|
|
|
if(drawElevation > Otc::MAX_ELEVATION)
|
|
|
|
|
drawElevation = Otc::MAX_ELEVATION;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we can render creatures in 3x3 range
|
|
|
|
|
// creatures
|
|
|
|
|
if(drawFlags & Otc::DrawCreatures) {
|
|
|
|
|
for(int xi = -1; xi <= 1; ++xi) {
|
|
|
|
|
for(int yi = -1; yi <= 1; ++yi) {
|
|
|
|
|
const TilePtr& tile = g_map.getTile(m_position.translated(xi, yi, 0));
|
|
|
|
|
if(!tile)
|
|
|
|
|
continue;
|
|
|
|
|
for(const CreaturePtr& creature : tile->getCreatures()) {
|
|
|
|
|
int tileSize = Otc::TILE_PIXELS * scaleFactor;
|
|
|
|
|
Rect creatureRect(dest.x + xi*tileSize + (creature->getWalkOffset().x - creature->getDisplacementX())*scaleFactor,
|
|
|
|
|
dest.y + yi*tileSize + (creature->getWalkOffset().y - creature->getDisplacementY())*scaleFactor,
|
|
|
|
|
tileSize, tileSize);
|
|
|
|
|
Rect thisTileRect(dest.x, dest.y, tileSize, tileSize);
|
|
|
|
|
|
|
|
|
|
// only render creatures where bottom right is inside our rect
|
|
|
|
|
if(thisTileRect.contains(creatureRect.bottomRight())) {
|
|
|
|
|
creature->draw(Point(dest.x + xi*tileSize - m_drawElevation*scaleFactor,
|
|
|
|
|
dest.y + yi*tileSize - m_drawElevation*scaleFactor), scaleFactor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
|
|
|
|
CreaturePtr creature = (*it)->asCreature();
|
|
|
|
|
if(creature && !creature->isWalking())
|
|
|
|
|
creature->draw(dest - drawElevation, scaleFactor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -103,7 +94,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
|
|
|
|
if(drawFlags & Otc::DrawWalls) {
|
|
|
|
|
for(const ThingPtr& thing : m_things) {
|
|
|
|
|
if(thing->isOnTop())
|
|
|
|
|
thing->draw(dest - m_drawElevation, scaleFactor);
|
|
|
|
|
thing->draw(dest - drawElevation, scaleFactor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -114,6 +105,18 @@ void Tile::clean()
|
|
|
|
|
m_effects.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Tile::addWalkingCreature(const CreaturePtr& creature)
|
|
|
|
|
{
|
|
|
|
|
m_walkingCreatures.push_back(creature);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Tile::removeWalkingCreature(const CreaturePtr& creature)
|
|
|
|
|
{
|
|
|
|
|
auto it = std::find(m_walkingCreatures.begin(), m_walkingCreatures.end(), creature);
|
|
|
|
|
if(it != m_walkingCreatures.end())
|
|
|
|
|
m_walkingCreatures.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos)
|
|
|
|
|
{
|
|
|
|
|
if(!thing)
|
|
|
|
|