P_AddPlayerScore: negative values remove points

This commit is contained in:
James R 2024-01-22 17:45:30 -08:00
parent 0c7eb20e3d
commit 235d107f50
3 changed files with 7 additions and 4 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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;