Skip to content

Commit

Permalink
Merge branch 'fix-vote-ties' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyLobo committed Oct 7, 2016
2 parents ae9fcb5 + 9904b2c commit 7f9e495
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions mp/src/game/server/vote_controller.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -768,35 +768,26 @@ int CVoteController::GetWinningVoteOption( void )
}
else
{
CUtlVector <int> pVoteCounts;

// 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 ++ )
{
nHighest = ( ( nHighest < m_nVoteOptionCount[iIndex] ) ? m_nVoteOptionCount[iIndex] : nHighest );
pVoteCounts.AddToTail( m_nVoteOptionCount[iIndex] );
}

m_nHighestCountIndex = -1;
for ( int iIndex = 0; iIndex < m_nVoteOptionCount.Count(); iIndex++ )
{
if ( m_nVoteOptionCount[iIndex] == nHighest )
if (nHighest < m_nVoteOptionCount[iIndex])
{
// We have a new highest element => remember it
nHighest = m_nVoteOptionCount[iIndex];
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;
}
else if (nHighest == m_nVoteOptionCount[iIndex])
{
// We have a tie => reset index
m_nHighestCountIndex = -1;
}
}

return m_nHighestCountIndex;
}

return -1;
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 7f9e495

Please sign in to comment.