From c50edc684c4aca84000c6f19bc06f23d79e44c8a Mon Sep 17 00:00:00 2001 From: toaster Date: Wed, 25 Oct 2023 16:11:57 +0100 Subject: [PATCH] Tally in GP contexts: Recognise earned lives from other sources, not just Ring Total - If owner->xtralife isn't 0... - For every 20 Rings we count up, increment livesAdded. - If at the end of the ring count livesAdded is less than owner->xtralife, set livesAdded to that value. - Every time livesAdded is changed, play the sound and set the blink. - Caps the number of added lives to the same as P_GivePlayerLives would permit. --- src/k_tally.cpp | 34 +++++++++++++++++++++++++--------- src/k_tally.h | 1 + src/p_user.c | 8 +++++++- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/k_tally.cpp b/src/k_tally.cpp index 15e11a2c7..e3063a5e7 100644 --- a/src/k_tally.cpp +++ b/src/k_tally.cpp @@ -295,6 +295,7 @@ void level_tally_t::Init(player_t *player) time = std::min(static_cast(player->realtime), (100 * 60 * TICRATE) - 1); ringPool = player->totalring; + livesAdded = 0; position = numPlayers = 0; rings = 0; @@ -567,7 +568,10 @@ boolean level_tally_t::IncrementLine(void) } value = &displayStat[i]; - lives_check = (stats[i] == TALLY_STAT_TOTALRINGS); + lives_check = ( + stats[i] == TALLY_STAT_TOTALRINGS // Rings also shows the Lives. + && livesAdded < owner->xtralife // Don't check if we've maxxed out! + ); switch (stats[i]) { @@ -649,14 +653,30 @@ boolean level_tally_t::IncrementLine(void) return true; } + const boolean playSounds = P_IsDisplayPlayer(owner); + if (*value == dest) { // We've reached our destination + + if (lives_check == true) + { + // This is only true if Rings alone aren't responsible for our added lives. + // Generally for Prison Break, but could be earned in custom contexts too. + livesAdded = owner->xtralife; + xtraBlink = TICRATE; + + if (playSounds == true) + { + S_StopSoundByNum(sfx_cdfm73); + S_StartSound(NULL, sfx_cdfm73); + } + } + return true; } const INT32 prevVal = *value; - const boolean playSounds = P_IsDisplayPlayer(owner); if (playSounds == true && tickSound == 0) { @@ -693,6 +713,7 @@ boolean level_tally_t::IncrementLine(void) // Handle extra life sound & blinking if (extra > oldExtra) { + livesAdded++; xtraBlink = TICRATE; if (playSounds == true) @@ -1190,13 +1211,8 @@ void level_tally_t::Draw(void) .colormap(owner->skin, color) .patch(faceprefix[owner->skin][r_splitscreen ? FACE_MINIMAP : FACE_RANK]); - const UINT8 lifethreshold = 20; - const UINT8 oldExtra = ringPool / lifethreshold; - const UINT8 extra = displayStat[i] / lifethreshold; - const INT32 increase = (extra - oldExtra); - - UINT8 lives_num = owner->lives + increase; - if (xtraBlink > 0 && (xtraBlink & 1) == 0 && increase > 0) + UINT8 lives_num = std::min(owner->lives + livesAdded, 10); + if (xtraBlink > 0 && (xtraBlink & 1) == 0 && livesAdded > 0) { lives_num = 0; } diff --git a/src/k_tally.h b/src/k_tally.h index 0cf03e8ca..1eb37020f 100644 --- a/src/k_tally.h +++ b/src/k_tally.h @@ -72,6 +72,7 @@ struct level_tally_t // Stats INT32 time; UINT16 ringPool; + UINT8 livesAdded; tally_stat_e stats[TALLY_WINDOW_SIZE]; // Possible grade metrics diff --git a/src/p_user.c b/src/p_user.c index 311800caf..fbe435952 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1364,6 +1364,12 @@ void P_DoAllPlayersExit(pflags_t flags, boolean trygivelife) UINT8 i; const boolean dofinishsound = (musiccountdown == 0); + if (grandprixinfo.gp == false + || (flags & PF_NOCONTEST)) + { + trygivelife = false; + } + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i] || players[i].spectator) @@ -1382,7 +1388,7 @@ void P_DoAllPlayersExit(pflags_t flags, boolean trygivelife) continue; } - P_GivePlayerLives(&players[i], 1); + players[i].xtralife++; } if (!dofinishsound)