Skip to content

Commit bc1f141

Browse files
committed
Add string support to game_round_win reason keyvalue
1 parent 225a124 commit bc1f141

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

src/game/server/tf/entity_roundwin.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,34 @@
1111
// memdbgon must be the last include file in a .cpp file!!!
1212
#include "tier0/memdbgon.h"
1313

14+
#ifdef MAPBASE
15+
// Matches up with WINREASON_ enum, but with WINREASON_ removed for comparison reasons
16+
static const char *g_pszWinReasons[] = {
17+
"NONE",
18+
"ALL_POINTS_CAPTURED",
19+
"OPPONENTS_DEAD",
20+
"FLAG_CAPTURE_LIMIT",
21+
"DEFEND_UNTIL_TIME_LIMIT",
22+
"STALEMATE",
23+
"TIMELIMIT",
24+
"WINLIMIT",
25+
"WINDIFFLIMIT",
26+
#ifdef TF_DLL
27+
"RD_REACTOR_CAPTURED",
28+
"RD_CORES_COLLECTED",
29+
"RD_REACTOR_RETURNED",
30+
"PD_POINTS",
31+
"SCORED",
32+
"STOPWATCH_WATCHING_ROUNDS",
33+
"STOPWATCH_WATCHING_FINAL_ROUND",
34+
"STOPWATCH_PLAYING_ROUNDS",
35+
#endif
36+
};
37+
38+
// Add any new win reasons to the array above
39+
COMPILE_TIME_ASSERT( ARRAYSIZE( g_pszWinReasons ) == WINREASON_COUNT );
40+
#endif
41+
1442
//=============================================================================
1543
//
1644
// CTeamplayRoundWin tables.
@@ -42,6 +70,39 @@ CTeamplayRoundWin::CTeamplayRoundWin()
4270
m_iWinReason = WINREASON_DEFEND_UNTIL_TIME_LIMIT;
4371
}
4472

73+
//-----------------------------------------------------------------------------
74+
// Purpose:
75+
//-----------------------------------------------------------------------------
76+
bool CTeamplayRoundWin::KeyValue( const char *szKeyName, const char *szValue )
77+
{
78+
#ifdef MAPBASE
79+
if ( FStrEq( szKeyName, "win_reason" ) )
80+
{
81+
// Allow string input
82+
if ( szValue[0] == 'W' )
83+
{
84+
// Strip the WINREASON_ so that we only compare the part that matters
85+
const char *pszCompareValue = szValue + 10;
86+
for ( int i = 0; i < ARRAYSIZE( g_pszWinReasons ); i++ )
87+
{
88+
if ( FStrEq( pszCompareValue, g_pszWinReasons[i] ) )
89+
{
90+
m_iWinReason = i;
91+
return true;
92+
}
93+
}
94+
95+
// Win reason string does not match any known value
96+
Warning( "%s: Invalid win reason \"%s\"", GetDebugName(), szValue );
97+
}
98+
99+
// Fall through to base class for integer handling
100+
}
101+
#endif
102+
103+
return BaseClass::KeyValue( szKeyName, szValue );
104+
}
105+
45106
//-----------------------------------------------------------------------------
46107
// Purpose:
47108
//-----------------------------------------------------------------------------

src/game/server/tf/entity_roundwin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class CTeamplayRoundWin : public CPointEntity
2222

2323
CTeamplayRoundWin();
2424

25+
bool KeyValue( const char *szKeyName, const char *szValue );
26+
2527
// Input
2628
void InputRoundWin( inputdata_t &inputdata );
2729

src/game/shared/teamplayroundbased_gamerules.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ enum {
100100
WINREASON_STOPWATCH_WATCHING_FINAL_ROUND,
101101
WINREASON_STOPWATCH_PLAYING_ROUNDS,
102102
#endif
103+
104+
WINREASON_COUNT,
103105
};
104106

105107
enum stalemate_reasons_t

0 commit comments

Comments
 (0)