clintbellanger / flare

Free Libre Action Roleplaying Engine
http://clintbellanger.net/rpg/
GNU General Public License v3.0
166 stars 41 forks source link

Enemy state freeze #941

Closed clintbellanger closed 11 years ago

clintbellanger commented 11 years ago

I added Rapid Fire shot and I've been testing it.

It seems that if it doesn't kill an enemy (e.g. one with a lot of health) the enemy can be stuck in the "Hit" animation/state.

I'm working on debugging it. Here's what I know so far:

clintbellanger commented 11 years ago

I added a debug line in Animation::isLastFrame().

After the zombie freezes, cur_frame keeps incrementing beyond number_frames.

I could resolve the issue by changing isLastFrame() to this (greater/equal instead of just equal)

bool isLastFrame() { return cur_frame >= number_frames - 1; }

But that seems like hiding a bug that exists somewhere else. BehaviorStandard says that the enemy should switch back to Stance if we're on the last frame of Enemy Hit:

https://github.com/clintbellanger/flare/blob/master/src/BehaviorStandard.cpp#L427

Somehow that's not happening correctly when the enemy is hit twice in a row, with specific timing.

clintbellanger commented 11 years ago

Sequence of events from debug mode:

cur_state = ENEMY_HIT
cur_frame=1  cur_frame_index=0
cur_state = ENEMY_HIT
cur_frame=2  cur_frame_index=1
cur_frame=3  cur_frame_index=1
cur_frame=4  cur_frame_index=1
cur_frame=5  cur_frame_index=1

Because of the zombie's speed boost, his hit animation is only 1 frame.

"Hit" is the only sequence-breaking animation that can happen twice in a row (the others are Death/Crit-Death which always happen once). This is a bit confusing because state changes and animation changes are happening at different places, for significant reasons.

clintbellanger commented 11 years ago

The main bad thing is that cur_frame is allowed to go beyond number_frames, which should be forbidden.

I'm going to specifically add code to prevent this from happening, instead of relying on outside functionality to behave.