tibia-client/src/client/tile.cpp

664 lines
19 KiB
C++
Raw Normal View History

2011-08-28 15:17:58 +02:00
/*
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
2011-08-28 15:17:58 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
2011-08-15 16:11:24 +02:00
#include "tile.h"
#include "item.h"
2012-06-21 19:54:20 +02:00
#include "thingtypemanager.h"
#include "map.h"
2011-08-20 04:08:27 +02:00
#include "game.h"
#include "localplayer.h"
2011-08-31 22:22:57 +02:00
#include "effect.h"
#include "protocolgame.h"
#include "lightview.h"
2011-08-20 04:08:27 +02:00
#include <framework/graphics/fontmanager.h>
2011-08-15 16:11:24 +02:00
2012-06-23 23:30:54 +02:00
Tile::Tile(const Position& position) :
m_position(position),
m_drawElevation(0),
m_minimapColor(0),
m_flags(0)
2011-08-15 16:11:24 +02:00
{
}
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags, LightView *lightView)
{
bool animate = drawFlags & Otc::DrawAnimations;
2012-01-31 18:06:55 +01:00
2013-08-17 23:06:58 +02:00
/* Flags to be checked for. */
static const tileflags_t flags[] = {
TILESTATE_HOUSE,
TILESTATE_PROTECTIONZONE,
TILESTATE_OPTIONALZONE,
TILESTATE_HARDCOREZONE,
TILESTATE_NOLOGOUT
2013-08-17 23:06:58 +02:00
};
2013-08-14 18:58:13 +02:00
2011-08-31 22:22:57 +02:00
// first bottom items
2012-02-02 21:54:49 +01:00
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
m_drawElevation = 0;
2012-01-30 19:18:10 +01:00
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
break;
2013-08-17 23:06:58 +02:00
bool restore = false;
if(g_map.showZones() && thing->isGround()) {
for(unsigned int i = 0; i < sizeof(flags) / sizeof(tileflags_t); ++i) {
tileflags_t flag = flags[i];
if(hasFlag(flag) && g_map.showZone(flag)) {
g_painter->setOpacity(g_map.getZoneOpacity());
g_painter->setColor(g_map.getZoneColor(flag));
restore = true;
break;
}
}
}
if((thing->isGround() && drawFlags & Otc::DrawGround) ||
(thing->isGroundBorder() && drawFlags & Otc::DrawGroundBorders) ||
(thing->isOnBottom() && drawFlags & Otc::DrawOnBottom)) {
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
2013-08-17 23:06:58 +02:00
if(restore) {
2013-08-18 18:28:49 +02:00
g_painter->resetOpacity();
g_painter->resetColor();
2013-08-17 23:06:58 +02:00
}
}
2012-01-30 19:18:10 +01:00
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
2012-01-30 19:18:10 +01:00
}
}
2012-02-02 21:54:49 +01:00
int redrawPreviousTopW = 0;
int redrawPreviousTopH = 0;
2012-02-02 21:10:14 +01:00
2012-02-02 21:54:49 +01:00
if(drawFlags & Otc::DrawItems) {
2012-02-02 21:10:14 +01:00
// now common items in reverse order
2012-01-30 19:18:10 +01:00
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it;
2012-06-05 17:36:27 +02:00
if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->isCreature())
2012-01-30 19:18:10 +01:00
break;
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
2012-01-30 19:18:10 +01:00
2012-02-02 21:10:14 +01:00
if(thing->isLyingCorpse()) {
redrawPreviousTopW = std::max<int>(thing->getWidth(), redrawPreviousTopW);
redrawPreviousTopH = std::max<int>(thing->getHeight(), redrawPreviousTopH);
2012-02-02 21:10:14 +01:00
}
m_drawElevation += thing->getElevation();
if(m_drawElevation > Otc::MAX_ELEVATION)
m_drawElevation = Otc::MAX_ELEVATION;
2012-01-30 19:18:10 +01:00
}
}
2011-08-20 04:08:27 +02:00
2012-02-02 21:54:49 +01:00
// after we render 2x2 lying corpses, we must redraw previous creatures/ontop above them
if(redrawPreviousTopH > 0 || redrawPreviousTopW > 0) {
int topRedrawFlags = drawFlags & (Otc::DrawCreatures | Otc::DrawEffects | Otc::DrawOnTop | Otc::DrawAnimations);
if(topRedrawFlags) {
2012-02-03 14:21:13 +01:00
for(int x=-redrawPreviousTopW;x<=0;++x) {
for(int y=-redrawPreviousTopH;y<=0;++y) {
2012-02-02 21:10:14 +01:00
if(x == 0 && y == 0)
continue;
const TilePtr& tile = g_map.getTile(m_position.translated(x,y));
2012-02-02 21:54:49 +01:00
if(tile)
tile->draw(dest + Point(x*Otc::TILE_PIXELS, y*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, topRedrawFlags);
2012-02-02 21:10:14 +01:00
}
}
}
}
// creatures
2012-01-30 19:18:10 +01:00
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 - m_drawElevation)*scaleFactor,
dest.y + ((creature->getPosition().y - m_position.y)*Otc::TILE_PIXELS - m_drawElevation)*scaleFactor), scaleFactor, animate, lightView);
}
}
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
2012-06-05 17:36:27 +02:00
const ThingPtr& thing = *it;
if(!thing->isCreature())
continue;
CreaturePtr creature = thing->static_self_cast<Creature>();
if(creature && (!creature->isWalking() || !animate))
creature->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
2011-09-01 00:42:52 +02:00
}
}
2011-08-20 04:08:27 +02:00
2011-08-31 22:22:57 +02:00
// effects
2013-08-17 23:06:58 +02:00
if(drawFlags & Otc::DrawEffects)
for(const EffectPtr& effect : m_effects)
effect->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate, lightView);
2011-08-20 04:08:27 +02:00
2011-08-31 22:22:57 +02:00
// top items
2013-08-17 23:06:58 +02:00
if(drawFlags & Otc::DrawOnTop)
for(const ThingPtr& thing : m_things)
if(thing->isOnTop())
thing->draw(dest, scaleFactor, animate, lightView);
// draw translucent light (for tiles beneath holes)
if(hasTranslucentLight() && lightView) {
Light light;
2012-11-30 12:03:42 +01:00
light.intensity = 1;
lightView->addLightSource(dest + Point(16,16) * scaleFactor, scaleFactor, light);
}
2011-08-31 22:22:57 +02:00
}
2011-08-31 22:22:57 +02:00
void Tile::clean()
{
2012-02-02 21:10:14 +01:00
while(!m_things.empty())
removeThing(m_things.front());
2011-08-31 22:22:57 +02:00
}
2011-08-31 01:39:14 +02:00
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);
}
void Tile::addThing(const ThingPtr& thing, int stackPos)
2011-08-15 16:11:24 +02:00
{
if(!thing)
return;
2011-08-31 22:22:57 +02:00
if(thing->isEffect()) {
m_effects.push_back(thing->static_self_cast<Effect>());
} else {
2012-08-02 17:18:45 +02:00
// priority 854
// 0 - ground, --> -->
// 1 - ground borders --> -->
// 2 - bottom (walls), --> -->
// 3 - on top (doors) --> -->
// 4 - creatures, from top to bottom <-- -->
// 5 - items, from top to bottom <-- <--
if(stackPos < 0 || stackPos == 255) {
int priority = thing->getStackPriority();
2012-08-02 16:47:32 +02:00
2012-08-02 17:18:45 +02:00
// -1 or 255 => auto detect position
// -2 => append
2012-08-15 01:13:53 +02:00
bool append;
if(stackPos == -2)
append = true;
else {
append = (priority <= 3);
// newer protocols does not store creatures in reverse order
if(g_game.getProtocolVersion() >= 854 && priority == 4)
2012-08-15 01:13:53 +02:00
append = !append;
}
2012-08-02 17:18:45 +02:00
2012-08-02 16:47:32 +02:00
for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) {
int otherPriority = m_things[stackPos]->getStackPriority();
2012-08-02 17:18:45 +02:00
if((append && otherPriority > priority) || (!append && otherPriority >= priority))
break;
}
} else if(stackPos > (int)m_things.size())
stackPos = m_things.size();
2011-12-30 15:15:23 +01:00
m_things.insert(m_things.begin() + stackPos, thing);
if(m_things.size() > MAX_THINGS)
removeThing(m_things[MAX_THINGS]);
/*
// check stack priorities
// this code exists to find stackpos bugs faster
int lastPriority = 0;
for(const ThingPtr& thing : m_things) {
int priority = thing->getStackPriority();
assert(lastPriority <= priority);
lastPriority = priority;
2011-08-15 16:11:24 +02:00
}
*/
}
thing->setPosition(m_position);
thing->onAppear();
if(thing->isTranslucent())
checkTranslucentLight();
}
2012-02-02 21:10:14 +01:00
bool Tile::removeThing(ThingPtr thing)
2012-01-30 01:00:12 +01:00
{
if(!thing)
return false;
bool removed = false;
if(thing->isEffect()) {
EffectPtr effect = thing->static_self_cast<Effect>();
2012-01-30 01:00:12 +01:00
auto it = std::find(m_effects.begin(), m_effects.end(), effect);
if(it != m_effects.end()) {
m_effects.erase(it);
removed = true;
}
} else {
auto it = std::find(m_things.begin(), m_things.end(), thing);
if(it != m_things.end()) {
m_things.erase(it);
removed = true;
}
}
thing->onDisappear();
if(thing->isTranslucent())
checkTranslucentLight();
2012-01-30 01:00:12 +01:00
return removed;
}
2011-08-31 22:22:57 +02:00
ThingPtr Tile::getThing(int stackPos)
{
2011-08-31 22:22:57 +02:00
if(stackPos >= 0 && stackPos < (int)m_things.size())
return m_things[stackPos];
return nullptr;
2011-08-15 16:11:24 +02:00
}
2012-07-15 07:46:56 +02:00
EffectPtr Tile::getEffect(uint16 id)
{
for(const EffectPtr& effect : m_effects)
if(effect->getId() == id)
return effect;
return nullptr;
}
bool Tile::hasThing(const ThingPtr& thing)
{
return std::find(m_things.begin(), m_things.end(), thing) != m_things.end();
}
int Tile::getThingStackPos(const ThingPtr& thing)
{
for(uint stackpos = 0; stackpos < m_things.size(); ++stackpos)
if(thing == m_things[stackpos])
return stackpos;
return -1;
}
ThingPtr Tile::getTopThing()
2012-01-03 21:41:00 +01:00
{
2012-07-15 08:16:40 +02:00
if(isEmpty())
return nullptr;
2013-08-18 18:28:49 +02:00
for(const ThingPtr& thing : m_things)
2012-07-15 07:46:56 +02:00
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature())
return thing;
2012-01-03 21:41:00 +01:00
return m_things[m_things.size() - 1];
}
std::vector<ItemPtr> Tile::getItems()
{
std::vector<ItemPtr> items;
for(const ThingPtr& thing : m_things) {
if(!thing->isItem())
continue;
ItemPtr item = thing->static_self_cast<Item>();
items.push_back(item);
}
return items;
}
2011-08-31 22:22:57 +02:00
std::vector<CreaturePtr> Tile::getCreatures()
{
2011-08-31 22:22:57 +02:00
std::vector<CreaturePtr> creatures;
for(const ThingPtr& thing : m_things) {
if(thing->isCreature())
creatures.push_back(thing->static_self_cast<Creature>());
2011-08-31 22:22:57 +02:00
}
return creatures;
2011-08-15 16:11:24 +02:00
}
2011-08-31 22:22:57 +02:00
ItemPtr Tile::getGround()
2011-08-15 16:11:24 +02:00
{
2011-08-31 22:22:57 +02:00
ThingPtr firstObject = getThing(0);
if(!firstObject)
return nullptr;
if(firstObject->isGround() && firstObject->isItem())
return firstObject->static_self_cast<Item>();
2011-08-31 22:22:57 +02:00
return nullptr;
2011-08-15 16:11:24 +02:00
}
2011-08-31 01:39:14 +02:00
int Tile::getGroundSpeed()
{
int groundSpeed = 100;
if(ItemPtr ground = getGround())
groundSpeed = ground->getGroundSpeed();
return groundSpeed;
}
uint8 Tile::getMinimapColorByte()
{
uint8 color = 255; // alpha
2013-08-14 18:58:13 +02:00
if(m_minimapColor != 0)
return m_minimapColor;
for(const ThingPtr& thing : m_things) {
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())
break;
uint8 c = thing->getMinimapColor();
if(c != 0)
color = c;
}
return color;
}
2012-01-04 14:02:35 +01:00
ThingPtr Tile::getTopLookThing()
{
2012-01-04 14:39:08 +01:00
if(isEmpty())
return nullptr;
2012-01-06 17:16:47 +01:00
for(uint i = 0; i < m_things.size(); ++i) {
2012-01-04 14:02:35 +01:00
ThingPtr thing = m_things[i];
2012-01-30 01:00:12 +01:00
if(!thing->isIgnoreLook() && (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()))
2012-01-04 14:02:35 +01:00
return thing;
2012-01-02 20:01:48 +01:00
}
2012-01-04 14:02:35 +01:00
2012-01-04 14:39:08 +01:00
return m_things[0];
2012-01-04 14:02:35 +01:00
}
ThingPtr Tile::getTopUseThing()
{
if(isEmpty())
return nullptr;
2012-01-06 17:16:47 +01:00
for(uint i = 0; i < m_things.size(); ++i) {
2012-01-04 14:02:35 +01:00
ThingPtr thing = m_things[i];
2012-06-05 17:36:27 +02:00
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()))
2012-01-04 14:02:35 +01:00
return thing;
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isCreature())
return thing;
}
2012-01-04 14:02:35 +01:00
return m_things[0];
}
CreaturePtr Tile::getTopCreature()
{
CreaturePtr creature;
2012-01-06 17:16:47 +01:00
for(uint i = 0; i < m_things.size(); ++i) {
2012-01-04 14:02:35 +01:00
ThingPtr thing = m_things[i];
if(thing->isLocalPlayer()) // return local player if there is no other creature
creature = thing->static_self_cast<Creature>();
2012-06-05 17:36:27 +02:00
else if(thing->isCreature() && !thing->isLocalPlayer())
return thing->static_self_cast<Creature>();
2012-01-04 14:02:35 +01:00
}
2012-06-03 02:00:09 +02:00
if(!creature && !m_walkingCreatures.empty())
creature = m_walkingCreatures.back();
2012-08-22 02:27:48 +02:00
// check for walking creatures in tiles around
if(!creature) {
for(int xi=-1;xi<=1;++xi) {
for(int yi=-1;yi<=1;++yi) {
Position pos = m_position.translated(xi, yi);
if(pos == m_position)
continue;
const TilePtr& tile = g_map.getTile(pos);
if(tile) {
for(const CreaturePtr& c : tile->getCreatures()) {
if(c->isWalking() && c->getLastStepFromPosition() == m_position && c->getStepProgress() < 0.75f) {
creature = c;
}
}
}
}
}
}
2012-01-04 14:02:35 +01:00
return creature;
}
2012-01-20 02:12:26 +01:00
ThingPtr Tile::getTopMoveThing()
{
if(isEmpty())
return nullptr;
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
2012-06-05 17:36:27 +02:00
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()) {
2012-01-20 02:12:26 +01:00
if(i > 0 && thing->isNotMoveable())
return m_things[i-1];
return thing;
}
}
2012-08-02 14:13:01 +02:00
for(const ThingPtr& thing : m_things) {
if(thing->isCreature())
return thing;
}
2012-01-20 02:12:26 +01:00
return m_things[0];
}
ThingPtr Tile::getTopMultiUseThing()
2012-01-09 21:54:37 +01:00
{
if(isEmpty())
return nullptr;
2013-04-09 23:54:10 +02:00
if(CreaturePtr topCreature = getTopCreature())
return topCreature;
2012-01-09 21:54:37 +01:00
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(thing->isForceUse())
return thing;
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop()) {
if(i > 0 && thing->isSplash())
2012-01-09 21:54:37 +01:00
return m_things[i-1];
return thing;
}
}
for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[i];
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnTop())
return thing;
}
2012-01-09 21:54:37 +01:00
return m_things[0];
}
bool Tile::isWalkable(bool ignoreCreatures)
2011-11-05 21:34:49 +01:00
{
if(!getGround())
return false;
for(const ThingPtr& thing : m_things) {
2012-01-30 01:00:12 +01:00
if(thing->isNotWalkable())
2011-11-05 21:34:49 +01:00
return false;
2011-12-30 15:15:23 +01:00
if(!ignoreCreatures) {
if(thing->isCreature()) {
CreaturePtr creature = thing->static_self_cast<Creature>();
if(!creature->isPassable() && creature->canBeSeen())
return false;
}
2011-12-30 15:15:23 +01:00
}
2011-11-05 21:34:49 +01:00
}
return true;
}
bool Tile::isPathable()
{
2013-08-14 18:58:13 +02:00
for(const ThingPtr& thing : m_things)
2012-08-22 04:10:56 +02:00
if(thing->isNotPathable())
return false;
return true;
}
2011-09-02 00:00:46 +02:00
bool Tile::isFullGround()
{
2012-01-30 01:00:12 +01:00
ItemPtr ground = getGround();
if(ground && ground->isFullGround())
2011-09-02 00:00:46 +02:00
return true;
return false;
}
2011-08-31 22:22:57 +02:00
bool Tile::isFullyOpaque()
2011-08-31 01:39:14 +02:00
{
2011-08-31 22:22:57 +02:00
ThingPtr firstObject = getThing(0);
2012-01-30 01:00:12 +01:00
return firstObject && firstObject->isFullGround();
2011-08-31 01:39:14 +02:00
}
2011-09-02 00:00:46 +02:00
2012-12-04 00:18:39 +01:00
bool Tile::isSingleDimension()
{
if(!m_walkingCreatures.empty())
return false;
2013-08-14 18:58:13 +02:00
for(const ThingPtr& thing : m_things)
2012-12-04 00:18:39 +01:00
if(thing->getHeight() != 1 || thing->getWidth() != 1)
return false;
return true;
}
2011-09-02 00:00:46 +02:00
bool Tile::isLookPossible()
{
2013-08-14 18:58:13 +02:00
for(const ThingPtr& thing : m_things)
2012-06-21 19:54:20 +02:00
if(thing->blockProjectile())
2011-09-02 00:00:46 +02:00
return false;
return true;
}
2012-01-04 15:30:28 +01:00
bool Tile::isClickable()
{
2013-02-28 22:39:27 +01:00
bool hasGround = false;
bool hasOnBottom = false;
bool hasIgnoreLook = false;
2012-01-04 15:30:28 +01:00
for(const ThingPtr& thing : m_things) {
2013-02-28 22:39:27 +01:00
if(thing->isGround())
hasGround = true;
if(thing->isOnBottom())
hasOnBottom = true;
if((hasGround || hasOnBottom) && !hasIgnoreLook)
2012-01-04 15:30:28 +01:00
return true;
}
return false;
}
2012-01-30 01:00:12 +01:00
bool Tile::isEmpty()
{
return m_things.size() == 0;
}
bool Tile::isDrawable()
{
return !m_things.empty() || !m_walkingCreatures.empty() || !m_effects.empty();
}
2012-02-02 17:55:42 +01:00
bool Tile::mustHookEast()
{
for(const ThingPtr& thing : m_things)
if(thing->isHookEast())
return true;
return false;
}
bool Tile::mustHookSouth()
{
for(const ThingPtr& thing : m_things)
if(thing->isHookSouth())
return true;
return false;
}
2011-12-30 15:15:23 +01:00
bool Tile::hasCreature()
{
for(const ThingPtr& thing : m_things)
if(thing->isCreature())
2011-12-30 15:15:23 +01:00
return true;
return false;
}
2013-03-15 00:57:02 +01:00
bool Tile::limitsFloorsView(bool isFreeView)
2012-01-02 20:01:48 +01:00
{
2012-01-30 01:00:12 +01:00
// ground and walls limits the view
ThingPtr firstThing = getThing(0);
2013-03-15 00:57:02 +01:00
2013-08-14 18:58:13 +02:00
if(isFreeView) {
2013-03-15 00:57:02 +01:00
if(firstThing && !firstThing->isDontHide() && (firstThing->isGround() || firstThing->isOnBottom()))
return true;
2013-08-14 18:58:13 +02:00
} else if(firstThing && !firstThing->isDontHide() && (firstThing->isGround() || (firstThing->isOnBottom() && firstThing->blockProjectile())))
return true;
2012-01-30 01:00:12 +01:00
return false;
2012-01-02 20:01:48 +01:00
}
2012-02-02 21:10:14 +01:00
2013-03-15 00:57:02 +01:00
2012-02-02 21:10:14 +01:00
bool Tile::canErase()
{
2013-01-22 19:04:36 +01:00
return m_walkingCreatures.empty() && m_effects.empty() && m_things.empty() && m_flags == 0 && m_minimapColor == 0;
2012-02-02 21:10:14 +01:00
}
2012-08-02 03:33:56 +02:00
bool Tile::hasElevation(int elevation)
{
int count = 0;
for(const ThingPtr& thing : m_things)
if(thing->getElevation() > 0)
count++;
return count >= elevation;
}
void Tile::checkTranslucentLight()
{
2012-11-30 12:03:42 +01:00
if(m_position.z != Otc::SEA_FLOOR)
return;
Position downPos = m_position;
if(!downPos.down())
return;
TilePtr tile = g_map.getOrCreateTile(downPos);
if(!tile)
return;
bool translucent = false;
for(const ThingPtr& thing : m_things) {
if(thing->isTranslucent() || thing->hasLensHelp()) {
translucent = true;
break;
}
}
if(translucent)
2013-08-18 18:28:49 +02:00
tile->m_flags |= TILESTATE_TRANSLUECENT_LIGHT;
else
2013-08-18 18:28:49 +02:00
tile->m_flags &= ~TILESTATE_TRANSLUECENT_LIGHT;
}
2013-08-17 23:06:58 +02:00
2013-08-18 18:28:49 +02:00
/* vim: set ts=4 sw=4 et :*/