MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / BuildVoteLeaders

Method BuildVoteLeaders

core/MenuVoting.cpp:661–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

659}
660
661void VoteMenuHandler::BuildVoteLeaders()
662{
663 if (m_NumVotes == 0 || !sm_vote_hintbox.GetBool())
664 {
665 m_leaderList[0] = '\0';
666 return;
667 }
668
669 menu_vote_result_t vote;
670 menu_vote_result_t::menu_item_vote_t item_vote[256];
671
672 memset(&vote, 0, sizeof(vote));
673
674 /* Build the item list */
675 for (unsigned int i=0; i<m_Items; i++)
676 {
677 if (m_Votes[i] > 0)
678 {
679 item_vote[vote.num_items].count = m_Votes[i];
680 item_vote[vote.num_items].item = i;
681 vote.num_votes += m_Votes[i];
682 vote.num_items++;
683 }
684 }
685 vote.item_list = item_vote;
686 assert(vote.num_votes);
687
688 /* Sort the item list descending */
689 qsort(item_vote,
690 vote.num_items,
691 sizeof(menu_vote_result_t::menu_item_vote_t),
692 SortVoteItems);
693
694 /* Take the top 3 (if applicable) and draw them */
695 int len = 0;
696 for (unsigned int i=0; i<vote.num_items && i<3; i++)
697 {
698 int curItem = vote.item_list[i].item;
699 ItemDrawInfo dr;
700 m_pCurMenu->GetItemInfo(curItem, &dr);
701 len += g_SourceMod.Format(m_leaderList + len, sizeof(m_leaderList) - len, "\n%i. %s: (%i)", i+1, dr.display, vote.item_list[i].count);
702 }
703}
704
705SourceMod::ResultType VoteMenuHandler::OnTimer(ITimer *pTimer, void *pData)
706{

Callers

nothing calls this directly

Calls 3

GetBoolMethod · 0.80
GetItemInfoMethod · 0.80
FormatMethod · 0.80

Tested by

no test coverage detected