Exemplo n.º 1
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);
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
void ProtocolGame::parseCreatureMove(InputMessage& msg)
{
    Position oldPos = parsePosition(msg);
    int oldStackpos = msg.getU8();
    Position newPos = parsePosition(msg);

    ThingPtr thing = g_map.getTile(oldPos)->getThing(oldStackpos);
    if(!thing) {
        logTraceError("could not get thing");
        return;
    }

    CreaturePtr creature = thing->asCreature();
    if(!creature) {
        logTraceError("thing is not a creature");
        return;
    }

    // update map tiles
    g_map.removeThing(thing);
    g_map.addThing(thing, newPos);

    g_game.processCreatureMove(creature, oldPos, newPos);
}