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

sourcecode Creature::getStepDuration()

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,452
Solutions
1
Reaction score
626
Location
Estonia
When it comes to figuring out what to change in sourcecode I'm worse than complete noob.

Can anyone translate what does this function do?
What must be changed so diagonal movements won't take more time to travel trough?
I don't like the way diagonal moving works, I want it to go with no penalty or with very small downside.

Code:
int64_t Creature::getStepDuration() const
{
    if (isRemoved()) {
        return 0;
    }

    uint32_t calculatedStepSpeed;
    uint32_t groundSpeed;

    int32_t stepSpeed = getStepSpeed();
    if (stepSpeed > -Creature::speedB) {
        calculatedStepSpeed = floor((Creature::speedA * log((stepSpeed / 2) + Creature::speedB) + Creature::speedC) + 0.5);
        if (calculatedStepSpeed <= 0) {
            calculatedStepSpeed = 1;
        }
    } else {
        calculatedStepSpeed = 1;
    }

    Item* ground = _tile->getGround();
    if (ground) {
        groundSpeed = Item::items[ground->getID()].speed;
        if (groundSpeed == 0) {
            groundSpeed = 150;
        }
    } else {
        groundSpeed = 150;
    }

    double duration = std::floor(1000 * groundSpeed / calculatedStepSpeed);
    int64_t stepDuration = std::ceil(duration / 50) * 50;

    const Monster* monster = getMonster();
    if (monster && monster->isTargetNearby() && !monster->isFleeing() && !monster->getMaster()) {
        stepDuration *= 2;
    }

    return stepDuration;
}
 
Look at the function just above:
Code:
int64_t Creature::getStepDuration(Direction dir) const
{
    int64_t stepDuration = getStepDuration();
    if ((dir & DIRECTION_DIAGONAL_MASK) != 0) {
        stepDuration *= 3;
    }
    return stepDuration;
}
https://github.com/ranisalt/forgottenserver/blob/master/src/creature.cpp#L1388-L1395

I think you can figure it out ;)
it did not work.
diagonal movements are still the same as before.
Wibbens suggested me to check next function below it. the one on post 1, but i cant even understand, what i have to change there to make diagonal movements work.
 
it did not work.
diagonal movements are still the same as before.
Wibbens suggested me to check next function below it. the one on post 1, but i cant even understand, what i have to change there to make diagonal movements work.
In C++, you can overload functions, which means you have more than one function of the same name, but different parameters in each. Upon stepping, it will call the best possible function based on what's passed to it. In this case, it always calls getStepDuration(Direction dir). This function calls the next function which is getStepDuration() which calculates general step speed. It then multiplies it by 3 if it's diagonal. Simply change
Code:
int64_t Creature::getStepDuration(Direction dir) const
{
int64_t stepDuration = getStepDuration();
if ((dir & DIRECTION_DIAGONAL_MASK) != 0) {
stepDuration *= 3;
}
return stepDuration;
}
to
Code:
int64_t Creature::getStepDuration(Direction dir) const
{
int64_t stepDuration = getStepDuration();

return stepDuration;
}

Alternatively, if you don't want to mess around with functions, simply change the function used in each case in the source:
Line 1434 in player.cpp:
Code:
setNextAction(OTSYS_TIME() + getStepDuration(dir));
change to
Code:
setNextAction(OTSYS_TIME() + getStepDuration());
 
In C++, you can overload functions, which means you have more than one function of the same name, but different parameters in each. Upon stepping, it will call the best possible function based on what's passed to it. In this case, it always calls getStepDuration(Direction dir). This function calls the next function which is getStepDuration() which calculates general step speed. It then multiplies it by 3 if it's diagonal. Simply change
Code:
int64_t Creature::getStepDuration(Direction dir) const
{
int64_t stepDuration = getStepDuration();
if ((dir & DIRECTION_DIAGONAL_MASK) != 0) {
stepDuration *= 3;
}
return stepDuration;
}
to
Code:
int64_t Creature::getStepDuration(Direction dir) const
{
int64_t stepDuration = getStepDuration();

return stepDuration;
}

Alternatively, if you don't want to mess around with functions, simply change the function used in each case in the source:
Line 1434 in player.cpp:
Code:
setNextAction(OTSYS_TIME() + getStepDuration(dir));
change to
Code:
setNextAction(OTSYS_TIME() + getStepDuration());
I had the first solution. but in some reason it doesnt change anything.
There is no way I can recheck it, other the fact i know what source i sent to wibbenz to compile.

sure gona try with the second solution too.
 
There's one more place you need to remove extra diagonal cost that I found:
https://github.com/ranisalt/forgottenserver/blob/master/src/creature.cpp#L505-L508
oh well, nothing changed. Still can't move diagonally with no penalties.
Well 1 thing changed though. compiled version is 1 kb smaller xD

EDIT:
Hmm, comparing the moving in live server(old compile) and test server (new compile).
Something has changed actually. In test server, it thinks about ~second and then continues moving in live server it thinks about ~2 seconds.

so I guess it better afterall.
 
Last edited:
I think the client itself has a limitation on that. It expects diagonal movement to take more time than x- or y-axis movement and it waits before sending the next walk packet. Try OTClient if you aren't yet to see if there are any changes.
 
I think the client itself has a limitation on that. It expects diagonal movement to take more time than x- or y-axis movement and it waits before sending the next walk packet. Try OTClient if you aren't yet to see if there are any changes.
Alright, i will try to remember that when i take on OTC.
For now, its not the right time, but I'm planning to learn it after I'm done with scripting systems to server.
 

Similar threads

Back
Top