# HG changeset patch # User Adam Kaminski # Date 1635042913 14400 # Sat Oct 23 22:35:13 2021 -0400 # Node ID d1ff301e9bb2020db82c72c97aef1374046e1f1b # Parent 06e9878fff7d0e86e0f4f0d8b55d8e1d69ad5b51 Fixed SetPlayerScore not refreshing the HUD if the score changed. This function now also returns zero if the score wasn't changed. diff -r 06e9878fff7d -r d1ff301e9bb2 src/d_player.h --- a/src/d_player.h Sat Oct 23 22:23:30 2021 -0400 +++ b/src/d_player.h Sat Oct 23 22:35:13 2021 -0400 @@ -781,6 +781,8 @@ void PLAYER_SpectatorJoinsGame ( player_t *pPlayer ); void PLAYER_SetPoints( player_t *pPlayer, ULONG ulPoints ); void PLAYER_SetWins( player_t *pPlayer, ULONG ulWins ); +void PLAYER_SetKills( player_t *pPlayer, ULONG ulKills ); +void PLAYER_SetDeaths( player_t *pPlayer, ULONG ulDeaths ); // [BB] PLAYER_GetHealth and PLAYER_GetLivesLeft are helper functions for PLAYER_GetPlayerWithSingleHighestValue. LONG PLAYER_GetHealth( ULONG ulPlayer ); LONG PLAYER_GetLivesLeft( ULONG ulPlayer ); diff -r 06e9878fff7d -r d1ff301e9bb2 src/p_acs.cpp --- a/src/p_acs.cpp Sat Oct 23 22:23:30 2021 -0400 +++ b/src/p_acs.cpp Sat Oct 23 22:35:13 2021 -0400 @@ -7472,7 +7472,8 @@ case ACSF_SetPlayerScore: { const ULONG ulPlayer = static_cast ( args[0] ); - int oldvalue; + // [AK] With the exception of frags, the new score must not be a negative value. + const LONG lScore = ( args[1] == SCORE_FRAGS || args[2] >= 0 ) ? args[2] : 0; if ( PLAYER_IsValidPlayer( ulPlayer ) ) { @@ -7480,73 +7481,71 @@ { case SCORE_FRAGS: { - // [AK] Keep the original value of the player's frags. - oldvalue = players[ulPlayer].fragcount; - players[ulPlayer].fragcount = args[2]; - - // [AK] If we're the server, tell the clients the player's new frag count. - if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].fragcount )) - SERVERCOMMANDS_SetPlayerFrags( ulPlayer ); + // [AK] Don't do anything if the frag count won't change. + if ( players[ulPlayer].fragcount == lScore ) + return 0; + + PLAYER_SetFragcount( &players[ulPlayer], lScore, true, true ); return 1; } case SCORE_POINTS: { - // [AK] Keep the original value of the player's points. - oldvalue = players[ulPlayer].lPointCount; - players[ulPlayer].lPointCount = args[2]; - - // [AK] If we're the server, tell the clients the player's new point count. - if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].lPointCount )) - SERVERCOMMANDS_SetPlayerPoints( ulPlayer ); + // [AK] Don't do anything if the point count won't change. + if ( players[ulPlayer].lPointCount == lScore ) + return 0; + + PLAYER_SetPoints( &players[ulPlayer], lScore ); return 1; } case SCORE_WINS: { - // [AK] Keep the original value of the player's wins. - oldvalue = players[ulPlayer].ulWins; - players[ulPlayer].ulWins = args[2] >= 0 ? args[2] : 0; - - // [AK] If we're the server, tell the clients the player's new win count. - if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( static_cast( oldvalue ) != players[ulPlayer].ulWins )) - SERVERCOMMANDS_SetPlayerWins( ulPlayer ); + // [AK] Don't do anything if the win count won't change. + if ( players[ulPlayer].ulWins == static_cast( lScore ) ) + return 0; + + PLAYER_SetWins( &players[ulPlayer], lScore ); return 1; } case SCORE_DEATHS: { - // [AK] Keep the original value of the player's deaths. - oldvalue = players[ulPlayer].ulDeathCount; - players[ulPlayer].ulDeathCount = args[2] >= 0 ? args[2] : 0; - - // [AK] If we're the server, tell the clients the player's new death count. - if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( static_cast( oldvalue ) != players[ulPlayer].ulDeathCount )) - SERVERCOMMANDS_SetPlayerDeaths( ulPlayer ); + // [AK] Don't do anything if the death count won't change. + if ( players[ulPlayer].ulDeathCount == static_cast( lScore ) ) + return 0; + + PLAYER_SetDeaths( &players[ulPlayer], lScore ); return 1; } case SCORE_KILLS: { - // [AK] Keep the original value of the player's kills. - oldvalue = players[ulPlayer].killcount; - players[ulPlayer].killcount = args[2]; - - // [AK] If we're the server, tell the clients the player's new kill count. - if (( NETWORK_GetState() == NETSTATE_SERVER ) && ( oldvalue != players[ulPlayer].killcount )) - SERVERCOMMANDS_SetPlayerKillCount( ulPlayer ); + // [AK] Don't do anything if the kill count won't change. + if ( players[ulPlayer].killcount == lScore ) + return 0; + + PLAYER_SetKills( &players[ulPlayer], lScore ); return 1; } case SCORE_ITEMS: { - players[ulPlayer].itemcount = args[2]; + // [AK] Don't do anything if the item count won't change. + if ( players[ulPlayer].itemcount == lScore ) + return 0; + + players[ulPlayer].itemcount = lScore; return 1; } case SCORE_SECRETS: { - players[ulPlayer].secretcount = args[2]; + // [AK] Don't do anything if the secret count won't change. + if ( players[ulPlayer].secretcount == lScore ) + return 0; + + players[ulPlayer].secretcount = lScore; return 1; } } diff -r 06e9878fff7d -r d1ff301e9bb2 src/p_interaction.cpp --- a/src/p_interaction.cpp Sat Oct 23 22:23:30 2021 -0400 +++ b/src/p_interaction.cpp Sat Oct 23 22:35:13 2021 -0400 @@ -2854,6 +2854,42 @@ //***************************************************************************** // +void PLAYER_SetKills( player_t *pPlayer, ULONG ulKills ) +{ + // Set the player's kill count. + pPlayer->killcount = ulKills; + + // Refresh the HUD since a score has changed. + HUD_Refresh( ); + + if ( NETWORK_GetState( ) == NETSTATE_SERVER ) + { + // If we're the server, notify the clients of the kill count change. + SERVERCOMMANDS_SetPlayerKillCount( pPlayer - players ); + + // Also, update the scoreboard. + SERVERCONSOLE_UpdatePlayerInfo( pPlayer - players, UDF_FRAGS ); + SERVERCONSOLE_UpdateScoreboard( ); + } +} + +//***************************************************************************** +// +void PLAYER_SetDeaths( player_t *pPlayer, ULONG ulDeaths ) +{ + // Set the player's death count. + pPlayer->ulDeathCount = ulDeaths; + + // Refresh the HUD since a score has changed. + HUD_Refresh( ); + + // If we're the server, notify the clients of the death count change. + if ( NETWORK_GetState( ) == NETSTATE_SERVER ) + SERVERCOMMANDS_SetPlayerDeaths( pPlayer - players ); +} + +//***************************************************************************** +// LONG PLAYER_GetHealth( ULONG ulPlayer ) { return players[ulPlayer].health;