From 316419951297ae08c1e7b5bd2f1ce048743d1b7b Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Tue, 31 May 2022 21:53:19 -0400 Subject: [PATCH] Reset state when bouncing --- src/k_follower.c | 119 ++++++++++++++++++++++------------------------- src/k_follower.h | 12 +++++ 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/src/k_follower.c b/src/k_follower.c index af43b80f2..2a5f92a05 100644 --- a/src/k_follower.c +++ b/src/k_follower.c @@ -129,7 +129,6 @@ void K_SetFollowerByNum(INT32 playernum, INT32 skinnum) K_SetFollowerByNum(playernum, -1); // Not found, then set -1 (nothing) as our follower. } - /*-------------------------------------------------- static void K_SetFollowerState(mobj_t *f, statenum_t state) @@ -176,6 +175,35 @@ static void K_SetFollowerState(mobj_t *f, statenum_t state) } } +/*-------------------------------------------------- + static void K_UpdateFollowerState(mobj_t *f, statenum_t state, followerstate_t type) + + Sets a follower object's state & current state type tracker. + If the state tracker already matches, then this is ignored. + + Input Arguments:- + f - The follower's mobj_t. + state - The state to set. + type - State type tracker. + + Return:- + None +--------------------------------------------------*/ +static void K_UpdateFollowerState(mobj_t *f, statenum_t state, followerstate_t type) +{ + if (f == NULL || P_MobjWasRemoved(f) == true) + { + // safety net + return; + } + + if (f->extravalue1 != (INT32)type) + { + K_SetFollowerState(f, state); + f->extravalue1 = type; + } +} + /*-------------------------------------------------- void K_HandleFollower(player_t *player) @@ -299,8 +327,9 @@ void K_HandleFollower(player_t *player) // so let's spawn one! P_SetTarget(&player->follower, P_SpawnMobj(sx, sy, sz, MT_FOLLOWER)); - K_SetFollowerState(player->follower, fl.idlestate); - P_SetTarget(&player->follower->target, player->mo); // we need that to know when we need to disappear + K_UpdateFollowerState(player->follower, fl.idlestate, FOLLOWERSTATE_IDLE); + + P_SetTarget(&player->follower->target, player->mo); // we need that to know when we need to disappear P_InitAngle(player->follower, player->mo->angle); // This is safe to only spawn it here, the follower is removed then respawned when switched. @@ -314,16 +343,6 @@ void K_HandleFollower(player_t *player) P_SetTarget(&player->follower->hnext->hnext, bmobj); // this seems absolutely stupid, I know, but this will make updating the momentums/flags of these a bit easier. P_SetTarget(&bmobj->target, player->follower); // Ditto } - - player->follower->extravalue1 = 0; // extravalue1 is used to know what "state set" to use. - /* - 0 = idle - 1 = forwards - 2 = hurt - 3 = win - 4 = lose - 5 = hitconfirm (< this one uses ->movecount as timer to know when to end, and goes back to normal states afterwards, unless hurt) - */ } else // follower exists, woo! { @@ -431,10 +450,11 @@ void K_HandleFollower(player_t *player) { player->follower->z = fh; - if (!(player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz <= 0) + if (!(player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz <= 0 && fl.bobamp != 0) { // Ground bounce player->follower->momz = P_GetMobjZMovement(player->mo) + FixedMul(fl.bobamp, player->follower->scale); + player->follower->extravalue1 = FOLLOWERSTATE_RESET; } else if (player->follower->momz < 0) { @@ -446,10 +466,11 @@ void K_HandleFollower(player_t *player) { player->follower->z = ch; - if ((player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz >= 0) + if ((player->mo->eflags & MFE_VERTICALFLIP) && player->follower->momz >= 0 && fl.bobamp != 0) { // Ground bounce player->follower->momz = P_GetMobjZMovement(player->mo) - FixedMul(fl.bobamp, player->follower->scale); + player->follower->extravalue1 = FOLLOWERSTATE_RESET; } else if (player->follower->momz > 0) { @@ -512,11 +533,7 @@ void K_HandleFollower(player_t *player) // spin out player->follower->angle = player->drawangle; - if (player->follower->extravalue1 != 2) - { - player->follower->extravalue1 = 2; - K_SetFollowerState(player->follower, fl.hurtstate); - } + K_UpdateFollowerState(player->follower, fl.hurtstate, FOLLOWERSTATE_HURT); if (player->mo->health <= 0) { @@ -524,58 +541,32 @@ void K_HandleFollower(player_t *player) player->follower->momz = player->mo->momz; } } + else if (player->exiting) + { + // win/ loss animations + if (K_IsPlayerLosing(player)) + { + // L + K_UpdateFollowerState(player->follower, fl.losestate, FOLLOWERSTATE_LOSE); + } + else + { + // W + K_UpdateFollowerState(player->follower, fl.winstate, FOLLOWERSTATE_WIN); + } + } else if (player->follower->movecount) { - if (player->follower->extravalue1 != 5) - { - player->follower->extravalue1 = 5; - K_SetFollowerState(player->follower, fl.hitconfirmstate); - } - + K_UpdateFollowerState(player->follower, fl.hitconfirmstate, FOLLOWERSTATE_HITCONFIRM); player->follower->movecount--; } - else if (player->speed > 10*player->mo->scale) // animation for moving fast enough + else if (player->speed > 10*player->mo->scale) // animation for moving fast enough { - if (player->follower->extravalue1 != 1) - { - player->follower->extravalue1 = 1; - K_SetFollowerState(player->follower, fl.followstate); - } + K_UpdateFollowerState(player->follower, fl.followstate, FOLLOWERSTATE_FOLLOW); } else { - // animations when nearly still. This includes winning and losing. - if (player->follower->extravalue1 != 0) - { - if (player->exiting) - { - // win/ loss animations - if (K_IsPlayerLosing(player)) - { - // L - if (player->follower->extravalue1 != 4) - { - player->follower->extravalue1 = 4; - K_SetFollowerState(player->follower, fl.losestate); - } - } - else - { - // W - if (player->follower->extravalue1 != 3) - { - player->follower->extravalue1 = 3; - K_SetFollowerState(player->follower, fl.winstate); - } - } - } - else - { - // normal standstill - player->follower->extravalue1 = 0; - K_SetFollowerState(player->follower, fl.idlestate); - } - } + K_UpdateFollowerState(player->follower, fl.idlestate, FOLLOWERSTATE_IDLE); } } } diff --git a/src/k_follower.h b/src/k_follower.h index 27e070814..0466bdfac 100644 --- a/src/k_follower.h +++ b/src/k_follower.h @@ -29,6 +29,18 @@ typedef enum FOLLOWERMODE__MAX } followermode_t; +typedef enum +{ + FOLLOWERSTATE_RESET, // Set to this to reset the state entirely. + FOLLOWERSTATE_IDLE, + FOLLOWERSTATE_FOLLOW, + FOLLOWERSTATE_HURT, + FOLLOWERSTATE_WIN, + FOLLOWERSTATE_LOSE, + FOLLOWERSTATE_HITCONFIRM, // Uses movecount as a timer for how long to play this state. + FOLLOWERSTATE__MAX +} followerstate_t; + // // We'll define these here because they're really just a mobj that'll follow some rules behind a player //