Example #1
0
void Map::removeThing(const ThingPtr& thing)
{
    if(!thing)
        return;

    if(MissilePtr shot = thing->asMissile()) {
        auto it = std::find(m_missilesAtFloor[shot->getPos().z].begin(), m_missilesAtFloor[shot->getPos().z].end(), shot);
        if(it != m_missilesAtFloor[shot->getPos().z].end()) {
            m_missilesAtFloor[shot->getPos().z].erase(it);
        }
        return;
    }
    else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {
        auto it = std::find(m_animatedTexts.begin(), m_animatedTexts.end(), animatedText);
        if(it != m_animatedTexts.end())
            m_animatedTexts.erase(it);
        return;
    }
    else if(StaticTextPtr staticText = thing->asStaticText()) {
        auto it = std::find(m_staticTexts.begin(), m_staticTexts.end(), staticText);
        if(it != m_staticTexts.end())
            m_staticTexts.erase(it);
        return;
    }

    if(TilePtr& tile = m_tiles[thing->getPos()])
        tile->removeThing(thing);
}
Example #2
0
void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
{
    if(!thing)
        return;

    Position oldPos = thing->getPos();
    bool teleport = false;
    if(oldPos.isValid() && !oldPos.isInRange(pos,1,1,0))
        teleport = true;

    TilePtr tile = getTile(pos);

    if(CreaturePtr creature = thing->asCreature()) {
        tile->addThing(thing, stackPos);
        m_creatures[creature->getId()] = creature;

        if(teleport)
            g_game.processCreatureTeleport(creature);
    }
    else if(MissilePtr shot = thing->asMissile()) {
        m_missilesAtFloor[shot->getPos().z].push_back(shot);
    }
    else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) {
        m_animatedTexts.push_back(animatedText);
    }
    else if(StaticTextPtr staticText = thing->asStaticText()) {
        bool mustAdd = true;
        for(auto it = m_staticTexts.begin(), end = m_staticTexts.end(); it != end; ++it) {
            StaticTextPtr cStaticText = *it;
            if(cStaticText->getPos() == pos) {
                // try to combine messages
                if(cStaticText->addMessage(staticText->getName(), staticText->getMessageType(), staticText->getFirstMessage())) {
                    mustAdd = false;
                    break;
                }
                else {
                    // must add another message and rearrenge current
                }
            }

        }

        if(mustAdd)
            m_staticTexts.push_back(staticText);
    }
    else {
        tile->addThing(thing, stackPos);
    }

    thing->start();
    thing->setPos(pos);
}
Example #3
0
void Map::removeThing(const ThingPtr& thing)
{
    if(!thing)
        return;

    if(MissilePtr shot = thing->asMissile()) {
        auto it = std::find(m_missilesAtFloor[shot->getPosition().z].begin(), m_missilesAtFloor[shot->getPosition().z].end(), shot);
        if(it != m_missilesAtFloor[shot->getPosition().z].end()) {
            m_missilesAtFloor[shot->getPosition().z].erase(it);
        }
        return;
    }

    if(TilePtr& tile = m_tiles[thing->getPosition()])
        tile->removeThing(thing);
}
Example #4
0
void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
{
    if(!thing)
        return;

    if(MissilePtr shot = thing->asMissile()) {
        m_missilesAtFloor[shot->getPosition().z].push_back(shot);
        return;
    }

    TilePtr tile = getTile(pos);
    tile->addThing(thing, stackPos);

    if(CreaturePtr creature = thing->asCreature())
        m_creatures[creature->getId()] = creature;
}