From 235d107f5070d11b1f5925a90b0a95d9e559c784 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 22 Jan 2024 17:45:30 -0800 Subject: [PATCH] P_AddPlayerScore: negative values remove points --- src/lua_baselib.c | 2 +- src/p_local.h | 2 +- src/p_user.c | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 2395614b0..93f79311a 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1097,7 +1097,7 @@ static int lib_pPlayerZMovement(lua_State *L) static int lib_pAddPlayerScore(lua_State *L) { player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); - UINT32 amount = (UINT32)luaL_checkinteger(L, 2); + INT32 amount = (UINT32)luaL_checkinteger(L, 2); NOHUD INLEVEL if (!player) diff --git a/src/p_local.h b/src/p_local.h index 15383f6c6..cf79a5ac7 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -146,7 +146,7 @@ extern consvar_t cv_tilting; extern fixed_t t_cam_dist[MAXSPLITSCREENPLAYERS], t_cam_height[MAXSPLITSCREENPLAYERS], t_cam_rotate[MAXSPLITSCREENPLAYERS]; -void P_AddPlayerScore(player_t *player, UINT32 amount); +void P_AddPlayerScore(player_t *player, INT32 amount); void P_ResetCamera(player_t *player, camera_t *thiscam); boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam); void P_SlideCameraMove(camera_t *thiscam); diff --git a/src/p_user.c b/src/p_user.c index e5bdfd520..2ec456914 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -570,7 +570,7 @@ void P_GivePlayerLives(player_t *player, INT32 numlives) } // Adds to the player's score -void P_AddPlayerScore(player_t *player, UINT32 amount) +void P_AddPlayerScore(player_t *player, INT32 amount) { if (!((gametyperules & GTR_POINTLIMIT))) return; @@ -578,8 +578,11 @@ void P_AddPlayerScore(player_t *player, UINT32 amount) if (player->exiting) // srb2kart return; + // Don't underflow. // Don't go above MAXSCORE. - if (player->roundscore + amount < MAXSCORE) + if (amount < 0 && (UINT32)-amount > player->roundscore) + player->roundscore = 0; + else if (player->roundscore + amount < MAXSCORE) player->roundscore += amount; else player->roundscore = MAXSCORE;