• 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!

TFS A* Algorithm :D

I am on it
Post automatically merged:


No it only includes the two repos by gigastar (me). Those are also old and I didn't have to do everything I did in those repos. You should be able to add any of those other changes by other authors after you install my system
i asked to extrodus i have added those
 
After some testing it seems like things are working pretty good, much better than before. However one issue seems to be showing, when the player stops moving the monsters return to delayed behavior. Almost feels like it should wait until there is no players on screen to begin that behavior; I've included a video to show you what I mean.
View attachment 83231
Try this fix:

creature.cpp

find: Creature::eek:nWalk()
and add this at the top
C++:
const Position& targetPos = attackedCreature->getPosition();
if (attackedCreature && followPosition == targetPos) {
    FindPathParams fpp;
    getPathSearchParams(attackedCreature, fpp);

    const Position& creaturePos = getPosition();
    if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) < fpp.maxTargetDist) {
        forceUpdateFollowPath = true;
    }
}
 
Last edited:
Try this fix:

creature.cpp

find: Creature::eek:nWalk()
and add this at the top
C++:
const Position& targetPos = attackedCreature->getPosition();
if (attackedCreature && followPosition == targetPos) {
    FindPathParams fpp;
    getPathSearchParams(attackedCreature, fpp);

    const Position& creaturePos = getPosition();
    if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) < fpp.maxTargetDist) {
        forceUpdateFollowPath = true;
    }
}

Thanks for the quick response however it seems like its the same issue as shown in the video before so I wont record another one; one thing I should note is that these monsters are set to always flee. (Max Health 80, <flag runonhealth="80"/>)

Another key note is that when the player stops moving, they act the exact same as if you stand in PZ, 1 sqm every 1 second. So I almost think it might be an issue that it's not running on health correctly when the player isnt moving.

Full code block from tested compile:
Code:
void Creature::onWalk()
{
    const Position& targetPos = attackedCreature->getPosition();
    if (attackedCreature && followPosition == targetPos) {
        FindPathParams fpp;
        getPathSearchParams(attackedCreature, fpp);

        const Position& creaturePos = getPosition();
        if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) < fpp.maxTargetDist) {
            forceUpdateFollowPath = true;
        }
    }
 
    if (getWalkDelay() <= 0) {
        Direction dir;
        uint32_t flags = FLAG_IGNOREFIELDDAMAGE;
        if (getNextStep(dir, flags)) {
            ReturnValue ret = g_game.internalMoveCreature(this, dir, flags);
            if (ret != RETURNVALUE_NOERROR) {
                if (Player* player = getPlayer()) {
                    player->sendCancelMessage(ret);
                    player->sendCancelWalk();
                }

                forceUpdateFollowPath = true;
            }
        } else {
            stopEventWalk();

            if (listWalkDir.empty()) {
                onWalkComplete();
            }
        }
    }

    if (cancelNextWalk) {
        listWalkDir.clear();
        onWalkAborted();
        cancelNextWalk = false;
    }

    if (eventWalk != 0) {
        eventWalk = 0;
        addEventWalk();
    }
}
 
Thanks for the quick response however it seems like its the same issue as shown in the video before so I wont record another one; one thing I should note is that these monsters are set to always flee. (Max Health 80, <flag runonhealth="80"/>)

Another key note is that when the player stops moving, they act the exact same as if you stand in PZ, 1 sqm every 1 second. So I almost think it might be an issue that it's not running on health correctly when the player isnt moving.

Full code block from tested compile:
Code:
void Creature::onWalk()
{
    const Position& targetPos = attackedCreature->getPosition();
    if (attackedCreature && followPosition == targetPos) {
        FindPathParams fpp;
        getPathSearchParams(attackedCreature, fpp);

        const Position& creaturePos = getPosition();
        if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) < fpp.maxTargetDist) {
            forceUpdateFollowPath = true;
        }
    }
 
    if (getWalkDelay() <= 0) {
        Direction dir;
        uint32_t flags = FLAG_IGNOREFIELDDAMAGE;
        if (getNextStep(dir, flags)) {
            ReturnValue ret = g_game.internalMoveCreature(this, dir, flags);
            if (ret != RETURNVALUE_NOERROR) {
                if (Player* player = getPlayer()) {
                    player->sendCancelMessage(ret);
                    player->sendCancelWalk();
                }

                forceUpdateFollowPath = true;
            }
        } else {
            stopEventWalk();

            if (listWalkDir.empty()) {
                onWalkComplete();
            }
        }
    }

    if (cancelNextWalk) {
        listWalkDir.clear();
        onWalkAborted();
        cancelNextWalk = false;
    }

    if (eventWalk != 0) {
        eventWalk = 0;
        addEventWalk();
    }
}
C++:
const Position& targetPos = attackedCreature->getPosition();
if (attackedCreature && followPosition == targetPos) {
    FindPathParams fpp;
    getPathSearchParams(attackedCreature, fpp);

    const Position& creaturePos = getPosition();
    const Monster* monster = getMonster();
    if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) <
            fpp.maxTargetDist || monster->isFleeing()) {
        forceUpdateFollowPath = true;
    }
}
 
C++:
const Position& targetPos = attackedCreature->getPosition();
if (attackedCreature && followPosition == targetPos) {
    FindPathParams fpp;
    getPathSearchParams(attackedCreature, fpp);

    const Position& creaturePos = getPosition();
    const Monster* monster = getMonster();
    if (Position::getDistanceX(creaturePos, targetPos) + Position::getDistanceY(creaturePos, targetPos) <
            fpp.maxTargetDist || monster->isFleeing()) {
        forceUpdateFollowPath = true;
    }
}

Hmm, same issue; as soon as I stop moving the monsters start the 1sqm per second behavior.

Also I just noticed if you click "use" on a dead body/street lamp or anything useable, it says "There is no way" (however if you stand right next to it, works as intended) This issue is present both with or without the changes you asked me to add above. Normal behavior is the player would walk to the tile and return a message "You can not use this object" or walk to + use the item.
 
Last edited:
Hmm, same issue; as soon as I stop moving the monsters start the 1sqm per second behavior.

Also I just noticed if you click "use" on a dead body/street lamp or anything useable, it says "There is no way" (however if you stand right next to it, works as intended) This issue is present both with or without the changes you asked me to add above. Normal behavior is the player would walk to the tile and return a message "You can not use this object" or walk to + use the item.
I already have the fix for player search problem. Once I get this problem solved I will add that in as well to the repo
Post automatically merged:

Alright, try replacing your follow creature with this.. I don't seem to have the same problem and this is the only mod I have made from the repo

You can remove the other code you have added to fix it

creature.cpp
replace: Creature::setFollowCreature(Creature* creature)
C++:
bool Creature::setFollowCreature(Creature* creature)
{
    if (creature) {
        if (followCreature == creature) {
            return true;
        }

        const Position& creaturePos = creature->getPosition();
        if (creaturePos.z != getPosition().z || !canSee(creaturePos)) {
            followCreature = nullptr;
            return false;
        }

        if (!listWalkDir.empty()) {
            listWalkDir.clear();
            onWalkAborted();
        }

        hasFollowPath = false;
        followCreature = creature;
        followPosition = creaturePos;
    } else {
        followCreature = nullptr;
    }

    onFollowCreature(creature);
    return true;
}
 
Last edited:
@Itutorial Great to have you back! I'm looking forward into this. From the state I updated my own fork, should I move forward from this commit to the last one? Would be nice if I wouldn't have to commit back and just update from my current sources state.

1711474225041.png

I ask this specifically because of this quote:
did you added all these?
(refering to the changes from here Commits · ralke23/Greed-TFS-1.5-Downgrades (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commits/8.60/))

Regards, and thnks in advance!
 
I followed the pull request commits to test what I currently have if that's what you're asking, sorry I don't fully understand.
there are commits that did not passed the revision did you add those too? im asking because i followed these:
In that order:

and don't know if it's right
Post automatically merged:

@Itutorial Great to have you back! I'm looking forward into this. From the state I updated my own fork, should I move forward from this commit to the last one? Would be nice if I wouldn't have to commit back and just update from my current sources state.

View attachment 83249

I ask this specifically because of this quote:

(refering to the changes from here Commits · ralke23/Greed-TFS-1.5-Downgrades (https://github.com/ralke23/Greed-TFS-1.5-Downgrades/commits/8.60/))

Regards, and thnks in advance!
these ones right?
Untitled.png
 
Last edited:
Are any of those changes in commit connected to player attack? Cause I feel like since I added code sometimes player get lagged autoattack for 3,4 seconds. Those situations are very rare but they happen. Is it something with the code or I screwed something?
 
there are commits that did not passed the revision did you add those too? im asking because i followed these:

and don't know if it's right
Post automatically merged:


these ones right?
View attachment 83254
Those are the old changes from my previous version. I had to ditch it for a while. This is the newest version that you should follow:

You should revert any changes you made from the: Gigastar A* and Gigastar pathfinding call.. Also the PLAYER_SEARCHDIST should be reverted as it is not needed anymore.


Are any of those changes in commit connected to player attack? Cause I feel like since I added code sometimes player get lagged autoattack for 3,4 seconds. Those situations are very rare but they happen. Is it something with the code or I screwed something?
There is nothing that should have modified attack behavior. I will check on my side to see if the same issue is present. How fast do you have the attacks? If they are less than, I think, 500ms or about it causes bugs, as far as I am aware.
 
Last edited:
Those are the old changes from my previous version. I had to ditch it for a while. This is the newest version that you should follow:

You should revert any changes you made from the: Gigastar A* and Gigastar pathfinding call.. Also the PLAYER_SEARCHDIST should be reverted as it is not needed anymore.



There is nothing that should have modified attack behavior. I will check on my side to see if the same issue is present. How fast do you have the attacks? If they are less than, I think, 500ms or about it causes bugs, as far as I am aware.
I never changed default code for attack speed, or attack behavior in general. We've noticed the problem just now after code change. I'll keep an eye on the situation but still for me the code is great. Thanks anyway, difference between what it was and what is is now is enormous. I'm just wandering about how it affects performance at this point.
 
Well if you are worried about performance you can mess with this value in creature.h
C++:
static constexpr int32_t EVENT_CREATURE_PATH_INTERVAL = 20;

You could set this value to 100ms and still have the same behavior if you want to make sure you are getting max performance. The fastest paths are up to 1000x faster as I have explained before and still 10x as fast on the worst paths. A thing to note is that paths are not drawn every 20ms which is what that value represents. It just checks to see if a path needs to be drawn. So most of the time it reads one conditional and then returns. Suffice to say even at 20ms it should still be far more efficient cost wise. Somewhere between 10x and 1000x which is why we can draw the paths far more often. Again the paths are only drawn when needed so yes its very performant, not perfect, but so much better you don't have to worry.
 
Well if you are worried about performance you can mess with this value in creature.h
C++:
static constexpr int32_t EVENT_CREATURE_PATH_INTERVAL = 20;

You could set this value to 100ms and still have the same behavior if you want to make sure you are getting max performance. The fastest paths are up to 1000x faster as I have explained before and still 10x as fast on the worst paths. A thing to note is that paths are not drawn every 20ms which is what that value represents. It just checks to see if a path needs to be drawn. So most of the time it reads one conditional and then returns. Suffice to say even at 20ms it should still be far more efficient cost wise. Somewhere between 10x and 1000x which is why we can draw the paths far more often. Again the paths are only drawn when needed so yes its very performant, not perfect, but so much better you don't have to worry.
Hello, is it advisable to use this optimization on my 7.4 server?
 
ok reverted everything almost eight commits
Lua:
Commits on Mar 27, 2024


Revert "Gigastar A* Pathfinding"



pasturryx
committed24 minutes ago









0d98d33



commit 10 de los que estoy kitando falta el 11vo y otro mas



pasturryx
committed28 minutes ago









88e9c0e



Revert "Update creature.cpp"



pasturryx
committed30 minutes ago









1324a0b



Revert "Method setMasterPosition"



pasturryx
committed33 minutes ago









aae8c9b



Revert "Update Follow Path"



pasturryx
committed36 minutes ago









da682ad



Revert "PLAYER_SEARCHDIST"



pasturryx
committed37 minutes ago









e64abd2



Revert "getPathTo (position to pos)"



pasturryx
committed38 minutes ago









93462e5



Revert "Add followPosition to followCreature"



pasturryx
committed39 minutes ago









b0d9ea5



Revert "Summon keepDistance, isInRange, distance check."



pasturryx
committed39 minutes ago









b098b3b



Revert "Corrections"



pasturryx
committed40 minutes ago









a9a6e85



Revert "fix in creature.cpp after tfs a algorithm"



pasturryx
committed41 minutes ago









209f41a



Revert "fix monster ai"



pasturryx
committed41 minutes ago









a241ce3


now i have justt to edit or add this?
 
I never changed default code for attack speed, or attack behavior in general. We've noticed the problem just now after code change. I'll keep an eye on the situation but still for me the code is great. Thanks anyway, difference between what it was and what is is now is enormous. I'm just wandering about how it affects performance at this point.
the problem was solved or not yet? can you show me which commits to add and which ones not? please?
 
the problem was solved or not yet? can you show me which commits to add and which ones not? please?
I didn't have this problem since yesterday so I guess it must have been some kind of lag or smth. I suggest you add it in chronological order as it is on github, omit those things which are marked with cross and that's it.
 
in addition to this Optimize pathfinding by NRH-AA · Pull Request #4637 · otland/forgottenserver (https://github.com/otland/forgottenserver/pull/4637/files#diff-742a716324b97c7b673cb41a50625f5583e55761b4cd8bacaaadf2b2480d0050)

have to add which ones of the following ones?
 
Back
Top