From 396244780a8853c5b8876027ce6a2be323cc44e4 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 9 Sep 2024 14:59:51 +0100 Subject: [PATCH 1/4] Don't attempt to use adjusted EXP counter in invalid contexts - Introduces new function K_GetDisplayEXP - Replaces duplicated code between HUD and tally - Returns UINT16_MAX in div/0 case for invalid result (resolves #1458) - Hides EXP HUD/tally if no EXP can be earned --- src/k_hud.cpp | 19 ++++++++++++------- src/k_kart.c | 23 +++++++++++++++++++++++ src/k_kart.h | 2 ++ src/k_tally.cpp | 9 +++++++-- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/k_hud.cpp b/src/k_hud.cpp index 225c748b1..6dcff1430 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -3116,17 +3116,19 @@ static void K_drawKartTeamScores(void) } } -static void K_drawKartLaps(void) +static boolean K_drawKartLaps(void) { INT32 splitflags = V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_SPLITSCREEN; INT32 bump = 0; boolean drewsticker = false; + UINT16 displayEXP = K_GetDisplayEXP(stplyr); + // Jesus Christ. // I do not understand the way this system of offsets is laid out at all, // so it's probably going to be pretty bad to maintain. Sorry. - if (numlaps != 1) + if (numlaps != 1 && displayEXP != UINT16_MAX) { if (r_splitscreen > 1) bump = 27; @@ -3196,10 +3198,12 @@ static void K_drawKartLaps(void) } } - UINT16 displayEXP = std::clamp(FixedMul(std::max(stplyr->exp, FRACUNIT/2), (500/K_GetNumGradingPoints())*stplyr->gradingpointnum), 0, 999); - // EXP - if (r_splitscreen > 1) + if (displayEXP == UINT16_MAX) + { + ; + } + else if (r_splitscreen > 1) { INT32 fx = 0, fy = 0, fr = 0; INT32 flipflag = 0; @@ -3263,6 +3267,8 @@ static void K_drawKartLaps(void) Draw row = Draw(LAPS_X+23+bump, LAPS_Y+3).flags(V_HUDTRANS|V_SLIDEIN|splitflags).font(Draw::Font::kThinTimer); row.text("{:03}", displayEXP); } + + return drewsticker; } #define RINGANIM_FLIPFRAME (RINGANIM_NUMFRAMES/2) @@ -6823,8 +6829,7 @@ void K_drawKartHUD(void) { if (gametyperules & GTR_CIRCUIT) { - K_drawKartLaps(); - gametypeinfoshown = true; + gametypeinfoshown = K_drawKartLaps(); } else if (gametyperules & GTR_BUMPERS) { diff --git a/src/k_kart.c b/src/k_kart.c index f1a2aebec..4bf1b8110 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -15237,6 +15237,29 @@ fixed_t K_GetExpAdjustment(player_t *player) return result; } +UINT16 K_GetDisplayEXP(player_t *player) +{ + UINT32 numgradingpoints = K_GetNumGradingPoints(); + + if (!numgradingpoints) + return UINT16_MAX; + + fixed_t result = max(player->exp, FRACUNIT/2); + result = FixedMul(result, (500/numgradingpoints)*player->gradingpointnum); + + // bro where is. bro where is std::clamp + if (result < 0) + { + result = 0; + } + else if (result > 999) + { + result = 999; + } + + return result; +} + UINT32 K_GetNumGradingPoints(void) { return numlaps * (1 + Obj_GetCheckpointCount()); diff --git a/src/k_kart.h b/src/k_kart.h index 81bb5c9a4..0a8953ce2 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -298,6 +298,8 @@ boolean K_PlayerCanUseItem(player_t *player); fixed_t K_GetExpAdjustment(player_t *player); +UINT16 K_GetDisplayEXP(player_t *player); + UINT32 K_GetNumGradingPoints(void); #ifdef __cplusplus diff --git a/src/k_tally.cpp b/src/k_tally.cpp index b095ff202..d6fbe90e3 100644 --- a/src/k_tally.cpp +++ b/src/k_tally.cpp @@ -343,8 +343,13 @@ void level_tally_t::Init(player_t *player) if ((gametypes[gt]->rules & GTR_CIRCUIT) == GTR_CIRCUIT) { - laps = std::clamp(FixedMul(std::max(stplyr->exp, FRACUNIT/2), (500/K_GetNumGradingPoints())*player->gradingpointnum), 0, 999); - totalLaps = 500; + UINT16 displayEXP = K_GetDisplayEXP(player); + + if (displayEXP != UINT16_MAX) + { + laps = displayEXP; + totalLaps = 500; + } } if (battleprisons) From 2104b0b0f544c254ec6a86a670cc7641cc53b420 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 9 Sep 2024 15:02:21 +0100 Subject: [PATCH 2/4] Disable EXP in K_Cooperative - HUD, tally, and roulette(!!) - In basegame, affects Sealed Stars --- src/k_kart.c | 3 +++ src/k_roulette.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 4bf1b8110..f15e4f14f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -15262,6 +15262,9 @@ UINT16 K_GetDisplayEXP(player_t *player) UINT32 K_GetNumGradingPoints(void) { + if (K_Cooperative()) + return 0; + return numlaps * (1 + Obj_GetCheckpointCount()); } diff --git a/src/k_roulette.c b/src/k_roulette.c index 671bca774..2bb29c5c7 100644 --- a/src/k_roulette.c +++ b/src/k_roulette.c @@ -1380,8 +1380,10 @@ void K_FillItemRouletteData(const player_t *player, itemroulette_t *const roulet roulette->preexpdist = K_GetItemRouletteDistance(player, roulette->playing); roulette->dist = roulette->preexpdist; - if (gametyperules & GTR_CIRCUIT) + if ((gametyperules & GTR_CIRCUIT) && !K_Cooperative()) + { roulette->dist = FixedMul(roulette->preexpdist, max(player->exp, FRACUNIT/2)); + } // =============================================================================== // Dynamic Roulette. Oh boy! From 1b0674d041e3f6cd5f1f1a492bdfe561de5bba65 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sat, 18 Jan 2025 18:47:58 -0500 Subject: [PATCH 3/4] Grading adjustment --- src/k_tally.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/k_tally.cpp b/src/k_tally.cpp index d6fbe90e3..a5bfad77c 100644 --- a/src/k_tally.cpp +++ b/src/k_tally.cpp @@ -243,10 +243,9 @@ INT32 level_tally_t::CalculateGrade(void) case TALLY_BONUS_LAP: { // Use a special curve for this. - // The difference between 0 and 1 lap points is an important difference in skill, - // while the difference between 5 and 6 is not very notable. - const fixed_t frac = std::min(FRACUNIT, (laps * FRACUNIT) / std::max(1, static_cast(totalLaps))); - ours += Easing_OutSine(frac, 0, bonusWeights[i]); + // Low Exp amounts are guaranteed, higher than half is where skill expression starts + const fixed_t frac = std::min(FRACUNIT, (laps * FRACUNIT) / std::max(1, static_cast(totalLaps + 80))); // Magic number here is to ensure A ranks only go to those that can maintain positive EXP + ours += Easing_InCubic(frac, 0, bonusWeights[i]); break; } case TALLY_BONUS_PRISON: From d4bb225ab2191847eed68f0763bac7ab0caa9b68 Mon Sep 17 00:00:00 2001 From: Ashnal Date: Sat, 18 Jan 2025 20:23:59 -0500 Subject: [PATCH 4/4] Fix hud overlap for 1 lap maps --- src/k_hud.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/k_hud.cpp b/src/k_hud.cpp index 6dcff1430..c214680ca 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -6829,7 +6829,8 @@ void K_drawKartHUD(void) { if (gametyperules & GTR_CIRCUIT) { - gametypeinfoshown = K_drawKartLaps(); + K_drawKartLaps(); + gametypeinfoshown = true; } else if (gametyperules & GTR_BUMPERS) {