From 4faf85eab4d5031386ec3babfe020c9b772cf217 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 17 Oct 2025 11:20:02 +0100 Subject: [PATCH] Fix code provided by ring-racers!51 It just straight up wasn't functional, and ERRORMODE pointed me to it Make the provideable amount use INT32 so the max/min macros actually do something (but also don't use nested min-maxes just to reduce reliance on macros) --- src/k_kart.c | 26 ++++++++++++++++++-------- src/k_kart.h | 8 ++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index e300bd5f2..f36094d72 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -72,24 +72,34 @@ // comeback is Battle Mode's karma comeback, also bool // mapreset is set when enough players fill an empty server -UINT8 K_SetPlayerItemAmount(player_t *player, UINT8 amount) +UINT8 K_SetPlayerItemAmount(player_t *player, INT32 amount) { - player->itemamount = max(min(UINT8_MAX, amount), 0); - return player->itemamount; + if (amount & ~UINT8_MAX) + { + // having bits outside of valid range means time to cap + amount = (amount < 0) ? 0 : UINT8_MAX; + } + + return (player->itemamount = amount); } -UINT8 K_SetPlayerBackupItemAmount(player_t *player, UINT8 amount) +UINT8 K_SetPlayerBackupItemAmount(player_t *player, INT32 amount) { - player->backupitemamount = max(min(UINT8_MAX, amount), 0); - return player->backupitemamount; + if (amount & ~UINT8_MAX) + { + // having bits outside of valid range means time to cap + amount = (amount < 0) ? 0 : UINT8_MAX; + } + + return (player->backupitemamount = amount); } -UINT8 K_AdjustPlayerItemAmount(player_t *player, SINT8 amount) +UINT8 K_AdjustPlayerItemAmount(player_t *player, INT32 amount) { return K_SetPlayerItemAmount(player, player->itemamount + amount); } -UINT8 K_AdjustPlayerBackupItemAmount(player_t *player, SINT8 amount) +UINT8 K_AdjustPlayerBackupItemAmount(player_t *player, INT32 amount) { return K_SetPlayerBackupItemAmount(player, player->backupitemamount + amount); } diff --git a/src/k_kart.h b/src/k_kart.h index 8dbc7f5fe..1f8231b42 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -125,10 +125,10 @@ Make sure this matches the actual number of states #define AUTORESPAWN_TIME (10*TICRATE) #define AUTORESPAWN_THRESHOLD (7*TICRATE) -UINT8 K_SetPlayerItemAmount(player_t *player, UINT8 amount); -UINT8 K_SetPlayerBackupItemAmount(player_t *player, UINT8 amount); -UINT8 K_AdjustPlayerItemAmount(player_t *player, SINT8 amount); -UINT8 K_AdjustPlayerBackupItemAmount(player_t *player, SINT8 amount); +UINT8 K_SetPlayerItemAmount(player_t *player, INT32 amount); +UINT8 K_SetPlayerBackupItemAmount(player_t *player, INT32 amount); +UINT8 K_AdjustPlayerItemAmount(player_t *player, INT32 amount); +UINT8 K_AdjustPlayerBackupItemAmount(player_t *player, INT32 amount); angle_t K_ReflectAngle(angle_t angle, angle_t against, fixed_t maxspeed, fixed_t yourspeed);