From 5765294c474ef3f02026b23414258f1058605c66 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 14 Aug 2016 16:43:39 +0200 Subject: [PATCH 1/5] Remove unreachable return --- mp/src/game/server/vote_controller.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/mp/src/game/server/vote_controller.cpp b/mp/src/game/server/vote_controller.cpp index 40a905c60..c13867cae 100644 --- a/mp/src/game/server/vote_controller.cpp +++ b/mp/src/game/server/vote_controller.cpp @@ -795,8 +795,6 @@ int CVoteController::GetWinningVoteOption( void ) return m_nHighestCountIndex; } - - return -1; } //----------------------------------------------------------------------------- From 5c4f1b4d8b2558334822495573b3eb7922c3dcc3 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 14 Aug 2016 17:02:21 +0200 Subject: [PATCH 2/5] Remove useless local variable --- mp/src/game/server/vote_controller.cpp | 3 --- 1 file changed, 3 deletions(-) mode change 100644 => 100755 mp/src/game/server/vote_controller.cpp diff --git a/mp/src/game/server/vote_controller.cpp b/mp/src/game/server/vote_controller.cpp old mode 100644 new mode 100755 index c13867cae..292b96048 --- a/mp/src/game/server/vote_controller.cpp +++ b/mp/src/game/server/vote_controller.cpp @@ -768,15 +768,12 @@ int CVoteController::GetWinningVoteOption( void ) } else { - CUtlVector pVoteCounts; - // Which option had the most votes? // driller: Need to handle ties int nHighest = m_nVoteOptionCount[0]; for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex ++ ) { nHighest = ( ( nHighest < m_nVoteOptionCount[iIndex] ) ? m_nVoteOptionCount[iIndex] : nHighest ); - pVoteCounts.AddToTail( m_nVoteOptionCount[iIndex] ); } m_nHighestCountIndex = -1; From fff0df5e58c908c342805e061d4397a7435762ca Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 14 Aug 2016 16:32:46 +0200 Subject: [PATCH 3/5] Remove useless use of a ternary operator --- mp/src/game/server/vote_controller.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mp/src/game/server/vote_controller.cpp b/mp/src/game/server/vote_controller.cpp index 292b96048..178720a0f 100755 --- a/mp/src/game/server/vote_controller.cpp +++ b/mp/src/game/server/vote_controller.cpp @@ -773,7 +773,11 @@ int CVoteController::GetWinningVoteOption( void ) int nHighest = m_nVoteOptionCount[0]; for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex ++ ) { - nHighest = ( ( nHighest < m_nVoteOptionCount[iIndex] ) ? m_nVoteOptionCount[iIndex] : nHighest ); + if (nHighest < m_nVoteOptionCount[iIndex]) + { + // We have a new highest element => remember it + nHighest = m_nVoteOptionCount[iIndex]; + } } m_nHighestCountIndex = -1; From d83dc769d52b901282a9edcdba5d2c254bee4635 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 14 Aug 2016 17:26:33 +0200 Subject: [PATCH 4/5] Simplify vote evaluation algorithm --- mp/src/game/server/vote_controller.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/mp/src/game/server/vote_controller.cpp b/mp/src/game/server/vote_controller.cpp index 178720a0f..b8cc6b053 100755 --- a/mp/src/game/server/vote_controller.cpp +++ b/mp/src/game/server/vote_controller.cpp @@ -771,26 +771,14 @@ int CVoteController::GetWinningVoteOption( void ) // Which option had the most votes? // driller: Need to handle ties int nHighest = m_nVoteOptionCount[0]; + m_nHighestCountIndex = 0; for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex ++ ) { if (nHighest < m_nVoteOptionCount[iIndex]) { // We have a new highest element => remember it nHighest = m_nVoteOptionCount[iIndex]; - } - } - - m_nHighestCountIndex = -1; - for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex++ ) - { - if ( m_nVoteOptionCount[iIndex] == nHighest ) - { m_nHighestCountIndex = iIndex; - // henryg: break on first match, not last. this avoids a crash - // if we are all tied at zero and we pick something beyond the - // last vote option. this code really ought to ignore attempts - // to tally votes for options beyond the last valid one! - break; } } From 9904b2c7347b2b2791ea69bb765c19dfed402d16 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 14 Aug 2016 17:31:35 +0200 Subject: [PATCH 5/5] Properly handle ties --- mp/src/game/server/vote_controller.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mp/src/game/server/vote_controller.cpp b/mp/src/game/server/vote_controller.cpp index b8cc6b053..e34600bdf 100755 --- a/mp/src/game/server/vote_controller.cpp +++ b/mp/src/game/server/vote_controller.cpp @@ -769,7 +769,6 @@ int CVoteController::GetWinningVoteOption( void ) else { // Which option had the most votes? - // driller: Need to handle ties int nHighest = m_nVoteOptionCount[0]; m_nHighestCountIndex = 0; for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex ++ ) @@ -780,6 +779,11 @@ int CVoteController::GetWinningVoteOption( void ) nHighest = m_nVoteOptionCount[iIndex]; m_nHighestCountIndex = iIndex; } + else if (nHighest == m_nVoteOptionCount[iIndex]) + { + // We have a tie => reset index + m_nHighestCountIndex = -1; + } } return m_nHighestCountIndex;