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.
This commit is contained in:
Callmore 2024-05-19 19:02:32 +00:00 committed by Eidolon
parent 8326292a3f
commit 5fbe9f9827

View file

@ -138,7 +138,7 @@ INT16 K_PowerLevelPlacementScore(player_t *player)
INT16 K_CalculatePowerLevelAvg(void) INT16 K_CalculatePowerLevelAvg(void)
{ {
fixed_t avg = 0; INT32 avg = 0;
UINT8 div = 0; UINT8 div = 0;
SINT8 t = PWRLV_DISABLED; SINT8 t = PWRLV_DISABLED;
UINT8 i; UINT8 i;
@ -166,7 +166,7 @@ INT16 K_CalculatePowerLevelAvg(void)
|| clientpowerlevels[i][t] == 0) // splitscreen player || clientpowerlevels[i][t] == 0) // splitscreen player
continue; continue;
avg += (clientpowerlevels[i][t] << FRACBITS); avg += clientpowerlevels[i][t];
div++; div++;
} }
@ -178,7 +178,7 @@ INT16 K_CalculatePowerLevelAvg(void)
avg /= div; avg /= div;
return (INT16)(avg >> FRACBITS); return (INT16)avg;
} }
void K_UpdatePowerLevels(player_t *player, UINT8 lap, boolean forfeit) void K_UpdatePowerLevels(player_t *player, UINT8 lap, boolean forfeit)