• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ attack on diagonals tfs 1.5

Izaack

Member
Joined
Jun 18, 2012
Messages
70
Solutions
1
Reaction score
17
Location
México
Hello friends of Otland, I have a question, currently I need to be able to attack on these diagonals, I followed a commit on github on this topic but I discovered that on these two diagonals I cannot get the player to attack when in the old versions of Tibia it could, do you know how? can I solve this problem?

commit.png
In the position the dragons are in I can't attack but if I put them in the reverse position it is possible.
Does anyone know how to solve this problem with these diagonals?​
 
Last edited:
if you want the correct (although not the way it works in rl tibia), take a look at this PR:
Bro, I get that error with that PR, how can I solve it?
 
I assume he means show the error that the pull request gives you.
It does not produce errors when compiling, it simply does not solve the problem of diagonals, although it is not an error, because they say that this is the same as in RL, the question is how to disable it, for people who do not like this "mechanics"
 
It does not produce errors when compiling, it simply does not solve the problem of diagonals, although it is not an error, because they say that this is the same as in RL, the question is how to disable it, for people who do not like this "mechanics"
Exactly as mentioned, there is no error, but in the sqm where the dragons are, the player cannot attack. I need to know how to make it attack those sqm as well. Does anyone have an idea?
 
I created a new sightline formula for black tek, although I am unsure if it would fix this specific problem or not, it is worth a try.

If anyone wants to try it out. Open map.cpp and find the method Map::isSightClear and replace the whole thing for this version.


C++:
bool Map::isSightClear(const Position& fromPos, const Position& toPos, bool sameFloor /*= false*/) const
{
    // Check if fromPos and toPos are the same
    if (fromPos == toPos)
        return true;

    // Calculate distance between fromPos and toPos
    int dx = std::abs(fromPos.x - toPos.x);
    int dy = std::abs(fromPos.y - toPos.y);
    int dz = std::abs(fromPos.z - toPos.z);

    // Check for same floor or skip if they are next to each other
    if (dz == 0 && (dx < 2 && dy < 2)) {
        // Sight is clear or sameFloor is enabled
        bool sightClear = checkSightLine(fromPos.x, fromPos.y, toPos.x, toPos.y, fromPos.z);
        return sightClear || sameFloor || (fromPos.z == 0);
    }

    // Check if fromPos and toPos cross the ground floor
    if ((fromPos.z < 8 && toPos.z > 7) || (fromPos.z > 7 && toPos.z < 8))
        return false;

    // Check if tiles above or below the target are clear
    uint8_t startZ = std::min(fromPos.z, toPos.z);
    uint8_t endZ = std::max(fromPos.z, toPos.z);
    for (uint8_t z = startZ; z < endZ; ++z) {
        if (!isTileClear(toPos.x, toPos.y, z, true))
            return false;
    }

    // Check if we can throw to the tile above the target
    return checkSightLine(fromPos.x, fromPos.y, toPos.x, toPos.y, fromPos.z);
}

I know some might think this function doesn't affect combat, but it absolutely does. Game::isSightClear is basically just a wrapper to Map::isSightClear, and Game::isSightClear is used for combat.

Let me know if it works for you, and or if you have any problems with the code.
 
Back
Top