C++ some help in condition for function

gohamvsgoku

Member
Joined
Aug 21, 2017
Messages
85
Reaction score
5
in my sources, i found this function responsible to send the player to the temple if he does not have an empty tile to connect

E.g player logout disconnects on some tables around, when connect it is automatically sent to the temple.

C++:
bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos/* = false*/, bool forceLogin/* = false*/)
{
    bool foundTile;
    bool placeInPZ;

    Tile* tile = getTile(centerPos.x, centerPos.y, centerPos.z);
    if (tile) {
        placeInPZ = tile->hasFlag(TILESTATE_PROTECTIONZONE);

        ReturnValue ret;
        if (creature->getPlayer()) {
            ret = tile->queryAdd(0, *creature, 1, 0);
        } else {
            ret = tile->queryAdd(0, *creature, 1, (creature->getMonster() ? FLAG_PLACECHECK : FLAG_IGNOREBLOCKITEM));
        }

        foundTile = forceLogin || ret == RETURNVALUE_NOERROR || ret == RETURNVALUE_PLAYERISNOTINVITED;
    } else {
        placeInPZ = false;
        foundTile = false;
    }

    if (!foundTile) {
        static std::vector<std::pair<int32_t, int32_t>> extendedRelList {
                               {0, -2},
                     {-1, -1}, {0, -1}, {1, -1},
            {-2, 0}, {-1,  0},          {1,  0}, {2, 0},
                     {-1,  1}, {0,  1}, {1,  1},
                               {0,  2}
        };

        static std::vector<std::pair<int32_t, int32_t>> normalRelList {
            {-1, -1}, {0, -1}, {1, -1},
            {-1,  0},          {1,  0},
            {-1,  1}, {0,  1}, {1,  1}
        };

        std::vector<std::pair<int32_t, int32_t>>& relList = (extendedPos ? extendedRelList : normalRelList);

        if (extendedPos) {
            std::shuffle(relList.begin(), relList.begin() + 4, getRandomGenerator());
            std::shuffle(relList.begin() + 4, relList.end(), getRandomGenerator());
        } else {
            std::shuffle(relList.begin(), relList.end(), getRandomGenerator());
        }

        for (const auto& it : relList) {
            Position tryPos(centerPos.x + it.first, centerPos.y + it.second, centerPos.z);

            tile = getTile(tryPos.x, tryPos.y, tryPos.z);
            if (!tile || (placeInPZ && !tile->hasFlag(TILESTATE_PROTECTIONZONE))) {
                continue;
            }

            if (tile->queryAdd(0, *creature, 1, (creature->getMonster() ? FLAG_PLACECHECK : 0)) == RETURNVALUE_NOERROR) {
                if (!extendedPos || isSightClear(centerPos, tryPos, false)) {
                    foundTile = true;
                    break;
                }
            }
        }

        if (!foundTile) {
            return false;
        }
    }

    int32_t index = 0;
    uint32_t flags = 0;
    Item* toItem = nullptr;

    Cylinder* toCylinder = tile->queryDestination(index, *creature, &toItem, flags);
    toCylinder->internalAddThing(creature);

    const Position& dest = toCylinder->getPosition();
    getQTNode(dest.x, dest.y)->addCreature(creature);
    return true;
}
how to make this function not work if the tile that the player is connecting to is TILESTATE_PVPZONE?

is possible to create a condition for this within the function? 🤔

using 1.2 tfs
 
Top