From bc1f14147d92cc8373680220fd1d10b8c56091fb Mon Sep 17 00:00:00 2001 From: Blixibon Date: Wed, 17 Sep 2025 12:25:07 -0500 Subject: [PATCH] Add string support to game_round_win reason keyvalue --- src/game/server/tf/entity_roundwin.cpp | 61 +++++++++++++++++++ src/game/server/tf/entity_roundwin.h | 2 + .../shared/teamplayroundbased_gamerules.h | 2 + 3 files changed, 65 insertions(+) diff --git a/src/game/server/tf/entity_roundwin.cpp b/src/game/server/tf/entity_roundwin.cpp index 92ead3bda67..d1ef8dcdbf8 100644 --- a/src/game/server/tf/entity_roundwin.cpp +++ b/src/game/server/tf/entity_roundwin.cpp @@ -11,6 +11,34 @@ // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" +#ifdef MAPBASE +// Matches up with WINREASON_ enum, but with WINREASON_ removed for comparison reasons +static const char *g_pszWinReasons[] = { + "NONE", + "ALL_POINTS_CAPTURED", + "OPPONENTS_DEAD", + "FLAG_CAPTURE_LIMIT", + "DEFEND_UNTIL_TIME_LIMIT", + "STALEMATE", + "TIMELIMIT", + "WINLIMIT", + "WINDIFFLIMIT", +#ifdef TF_DLL + "RD_REACTOR_CAPTURED", + "RD_CORES_COLLECTED", + "RD_REACTOR_RETURNED", + "PD_POINTS", + "SCORED", + "STOPWATCH_WATCHING_ROUNDS", + "STOPWATCH_WATCHING_FINAL_ROUND", + "STOPWATCH_PLAYING_ROUNDS", +#endif +}; + +// Add any new win reasons to the array above +COMPILE_TIME_ASSERT( ARRAYSIZE( g_pszWinReasons ) == WINREASON_COUNT ); +#endif + //============================================================================= // // CTeamplayRoundWin tables. @@ -42,6 +70,39 @@ CTeamplayRoundWin::CTeamplayRoundWin() m_iWinReason = WINREASON_DEFEND_UNTIL_TIME_LIMIT; } +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +bool CTeamplayRoundWin::KeyValue( const char *szKeyName, const char *szValue ) +{ +#ifdef MAPBASE + if ( FStrEq( szKeyName, "win_reason" ) ) + { + // Allow string input + if ( szValue[0] == 'W' ) + { + // Strip the WINREASON_ so that we only compare the part that matters + const char *pszCompareValue = szValue + 10; + for ( int i = 0; i < ARRAYSIZE( g_pszWinReasons ); i++ ) + { + if ( FStrEq( pszCompareValue, g_pszWinReasons[i] ) ) + { + m_iWinReason = i; + return true; + } + } + + // Win reason string does not match any known value + Warning( "%s: Invalid win reason \"%s\"", GetDebugName(), szValue ); + } + + // Fall through to base class for integer handling + } +#endif + + return BaseClass::KeyValue( szKeyName, szValue ); +} + //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- diff --git a/src/game/server/tf/entity_roundwin.h b/src/game/server/tf/entity_roundwin.h index c1b0bfa15f0..d980fa17efe 100644 --- a/src/game/server/tf/entity_roundwin.h +++ b/src/game/server/tf/entity_roundwin.h @@ -22,6 +22,8 @@ class CTeamplayRoundWin : public CPointEntity CTeamplayRoundWin(); + bool KeyValue( const char *szKeyName, const char *szValue ); + // Input void InputRoundWin( inputdata_t &inputdata ); diff --git a/src/game/shared/teamplayroundbased_gamerules.h b/src/game/shared/teamplayroundbased_gamerules.h index 65f4010a7e8..723677d39d8 100644 --- a/src/game/shared/teamplayroundbased_gamerules.h +++ b/src/game/shared/teamplayroundbased_gamerules.h @@ -100,6 +100,8 @@ enum { WINREASON_STOPWATCH_WATCHING_FINAL_ROUND, WINREASON_STOPWATCH_PLAYING_ROUNDS, #endif + + WINREASON_COUNT, }; enum stalemate_reasons_t