From 5fbe9f9827b55326c250a878edc2c9eba13cb5f1 Mon Sep 17 00:00:00 2001 From: Callmore Date: Sun, 19 May 2024 19:02:32 +0000 Subject: [PATCH] Use integer arithmetic for pwrlv avg calculation This fixes an oversight with pwrlv average calculation that causes the total to overflow with enough players or high enough pwrlv. Hopefully this might fix that bug where pwrlv is shown as negative on the server select menu. Maintainer note: This is still imprecise but it fixes the overflow without potentially disrupting game code. --- src/k_pwrlv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index dd95294a2..ca2c09a0a 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -138,7 +138,7 @@ INT16 K_PowerLevelPlacementScore(player_t *player) INT16 K_CalculatePowerLevelAvg(void) { - fixed_t avg = 0; + INT32 avg = 0; UINT8 div = 0; SINT8 t = PWRLV_DISABLED; UINT8 i; @@ -166,7 +166,7 @@ INT16 K_CalculatePowerLevelAvg(void) || clientpowerlevels[i][t] == 0) // splitscreen player continue; - avg += (clientpowerlevels[i][t] << FRACBITS); + avg += clientpowerlevels[i][t]; div++; } @@ -178,7 +178,7 @@ INT16 K_CalculatePowerLevelAvg(void) avg /= div; - return (INT16)(avg >> FRACBITS); + return (INT16)avg; } void K_UpdatePowerLevels(player_t *player, UINT8 lap, boolean forfeit)