Giter Club home page Giter Club logo

Comments (4)

oleg-derevenetz avatar oleg-derevenetz commented on July 2, 2024

Yeah, it's very interesting bug. I'm not very familiar with the hero movement animation logic in AI::HeroesMove(), but it seems that in this case it advances the hero's sprite_index too much, and it causes extra movement in the Heroes::MoveStep() method which normally shouldn't happen (because MP2::OBJ_COAST for the hero on the water is an object that needs to be interacted with while being next to it, not on it). sprite_index eventually becomes 17 before the last step, which causes makeStep( true ) to be ultimately called at line 279 here:

const int currentHeroFrameIndex = ( sprite_index % heroFrameCountPerTile );
if ( currentHeroFrameIndex == 0 ) {
if ( isNeedStayFrontObject( *this, world.GetTiles( nextStepIndex ) ) ) {
makeStep( false );
return true;
}
if ( GetKingdom().isControlHuman() ) {
const fheroes2::Point & mp = GetCenter();
playHeroWalkingSound( world.GetTiles( mp.x, mp.y ).GetGround() );
}
}
else if ( currentHeroFrameIndex == 1 ) {
// This is a start of hero's movement. We should clear fog around him.
Scout( nextStepIndex );
}
else if ( currentHeroFrameIndex == 8 ) {
sprite_index -= 8;
makeStep( true );
// if we continue to move into the same direction we must skip first frame as it's for stand position only
if ( isMoveEnabled() && GetDirection() == path.GetFrontDirection() && !isNeedStayFrontObject( *this, world.GetTiles( path.GetFrontIndex() ) ) ) {
if ( GetKingdom().isControlHuman() ) {
playHeroWalkingSound( world.GetTiles( heroIndex ).GetGround() );
}
++sprite_index;
}
return true;
}

which normally shouldn't be, because currentHeroFrameIndex should become 0 before accessing objects that need to be interacted with while being next to them (i.e. hero should be in "standing" state near these objects) - in this case isNeedStayFrontObject() check at line 260 should do its job and hero will interact with the coast object properly. This is how this looks like (in the step-by-step mode):

fheroes2.engine.version_.1.0.12.2024-02-29.22-28-30.mp4

Hi @ihhub since I am not very familiar with the implementation of the animation for the AI-controlled heroes, are there any tips on how to fix this in the "right" way? Can this happen to human-controlled heroes under some circumstances? Could you please take a look as soon as you have time for that?

from fheroes2.

ihhub avatar ihhub commented on July 2, 2024

Sure. I will take a look.

from fheroes2.

ihhub avatar ihhub commented on July 2, 2024

Hi @kuuff , can you try a build from #8450 ?

from fheroes2.

kuuff avatar kuuff commented on July 2, 2024

@ihhub, yeah, I tried, it fixes the issue, it doesn't crash. Great work!

from fheroes2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.