CvVoterDecision::GetTopVotedChoices(int)
- Defined in
- CvVotingClasses.cpp, line 718
- Class
- CvVoterDecision
- Hook name
CivHooks::CvVoterDecision_GetTopVotedChoices
Hooks
static bool BeforeCvVoterDecision_GetTopVotedChoices(CvVoterDecision* self, int iNumTopChoices, std::vector<int>& result);static void AfterCvVoterDecision_GetTopVotedChoices(CvVoterDecision* self, int iNumTopChoices, std::vector<int>& result);static std::vector<int> ReplaceCvVoterDecision_GetTopVotedChoices(std::vector<int> (*original)(CvVoterDecision*, int), CvVoterDecision* self, int iNumTopChoices);CivRegisterBefore<CivHooks::CvVoterDecision_GetTopVotedChoices>(host, &BeforeCvVoterDecision_GetTopVotedChoices);CivRegisterAfter<CivHooks::CvVoterDecision_GetTopVotedChoices>(host, &AfterCvVoterDecision_GetTopVotedChoices);CivRegisterReplace<CivHooks::CvVoterDecision_GetTopVotedChoices>(host, &ReplaceCvVoterDecision_GetTopVotedChoices);
Code
718std::vector<int> CvVoterDecision::GetTopVotedChoices(int iNumTopChoices)719{720 CvWeightedVector<int, 64, true> vChoices;721 for (PlayerVoteList::iterator it = m_vVotes.begin(); it != m_vVotes.end(); it++)722 {723 bool bFirst = true;724725 // Add the votes to an existing choice tally726 for (int i = 0; i < vChoices.size(); i++)727 {728 if (vChoices.GetElement(i) == it->iChoice)729 {730 bFirst = false;731 vChoices.SetWeight(i, vChoices.GetWeight(i) + it->iNumVotes);732 break;733 }734 }735736 // Add the votes to a new tally for a new choice737 if (bFirst)738 {739 vChoices.push_back(it->iChoice, it->iNumVotes);740 }741 }742743 std::vector<int> vTopChoices;744 if (vChoices.size() > 0 && iNumTopChoices > 0)745 {746 vChoices.SortItems();747 int iCurrentWeight = 0;748 for (int i = 0; i < vChoices.size(); i++)749 {750 if ((int)vTopChoices.size() < iNumTopChoices)751 {752 vTopChoices.push_back(vChoices.GetElement(i));753 iCurrentWeight = vChoices.GetWeight(i);754 }755 else if (iCurrentWeight == vChoices.GetWeight(i))756 {757 // Include tied choices758 vTopChoices.push_back(vChoices.GetElement(i));759 }760 else761 {762 break;763 }764 }765 }766767 return vTopChoices;768}
Calls
BaseVector::beginBaseVector::endCvWeightedVector::CvWeightedVectorCvWeightedVector::GetElementCvWeightedVector::GetWeightCvWeightedVector::push_backCvWeightedVector::SetWeightCvWeightedVector::sizeCvWeightedVector::SortItemsstd::vector::push_backstd::vector::sizestd::vector::vectorstd::vector::vector