CvVoterDecision::GetDecision()
- Defined in
- CvVotingClasses.cpp, line 633
- Class
- CvVoterDecision
- Hook name
CivHooks::CvVoterDecision_GetDecision- Overrides
- CvResolutionDecision::GetDecision()
Hooks
static bool BeforeCvVoterDecision_GetDecision(CvVoterDecision* self, int& result);static void AfterCvVoterDecision_GetDecision(CvVoterDecision* self, int& result);static int ReplaceCvVoterDecision_GetDecision(int (*original)(CvVoterDecision*), CvVoterDecision* self);CivRegisterBefore<CivHooks::CvVoterDecision_GetDecision>(host, &BeforeCvVoterDecision_GetDecision);CivRegisterAfter<CivHooks::CvVoterDecision_GetDecision>(host, &AfterCvVoterDecision_GetDecision);CivRegisterReplace<CivHooks::CvVoterDecision_GetDecision>(host, &ReplaceCvVoterDecision_GetDecision);
Code
633int CvVoterDecision::GetDecision()634{635 CvWeightedVector<int, 64, true> vChoices;636 for (PlayerVoteList::iterator it = m_vVotes.begin(); it != m_vVotes.end(); it++)637 {638 bool bFirst = true;639 640 // Add the votes to an existing choice tally641 for (int i = 0; i < vChoices.size(); i++)642 {643 if (vChoices.GetElement(i) == it->iChoice)644 {645 bFirst = false;646 vChoices.SetWeight(i, vChoices.GetWeight(i) + it->iNumVotes);647 break;648 }649 }650651 // Add the votes to a new tally for a new choice652 if (bFirst)653 {654 vChoices.push_back(it->iChoice, it->iNumVotes);655 }656 }657658 if (vChoices.size() > 0)659 {660 vChoices.SortItems();661 662 // Is there a tie?663 if (vChoices.size() > 1)664 {665 if (vChoices.GetWeight(0) == vChoices.GetWeight(1))666 {667 switch (GetType())668 {669 // Decisions about players go to the host in a tie, as long as the host is part of the tie670 case RESOLUTION_DECISION_ANY_MEMBER:671 case RESOLUTION_DECISION_MAJOR_CIV_MEMBER:672 case RESOLUTION_DECISION_OTHER_MAJOR_CIV_MEMBER:673 {674 PlayerTypes eHost = NO_PLAYER;675 CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague();676 if (pLeague != NULL)677 {678 eHost = pLeague->GetHostMember();679 }680681 int iWeightAtTop = vChoices.GetWeight(0);682 for (int i = 0; i < vChoices.size(); i++)683 {684 CvAssert(vChoices.GetWeight(i) <= iWeightAtTop);685 if (vChoices.GetWeight(i) < iWeightAtTop)686 {687 break;688 }689690 if ((PlayerTypes)vChoices.GetElement(i) == eHost)691 {692 return eHost;693 }694 }695 }696 break;697 // All other decisions are CHOICE_NONE in a tie, so nothing happens698 default:699 {700 return LeagueHelpers::CHOICE_NONE;701 }702 }703 }704 }705 706 return vChoices.GetElement(0);707 }708 return LeagueHelpers::CHOICE_NONE;709}
Calls
BaseVector::beginBaseVector::end- CvGame::GetGameLeagues()
- CvGameLeagues::GetActiveLeague()
- CvGlobals::getGame()
- CvLeague::GetHostMember() const
- CvResolutionDecision::GetType() const
CvWeightedVector::CvWeightedVectorCvWeightedVector::GetElementCvWeightedVector::GetWeightCvWeightedVector::push_backCvWeightedVector::SetWeightCvWeightedVector::sizeCvWeightedVector::SortItems
Called by
- CvActiveResolution::DoEffects(PlayerTypes)
- CvActiveResolution::RemoveEffects(PlayerTypes)
- CvEnactProposal::IsPassed(int)
- CvLeague::FinishSession()
- CvLeague::LogProposalResolved(CvEnactProposal *)
- CvLeague::LogProposalResolved(CvRepealProposal *)
- CvLeague::NotifyProposalResult(CvEnactProposal *)
- CvRepealProposal::IsPassed(int)
- CvLuaLeague::lGetRepealProposals(lua_State *)
- CvLuaLeague::lGetRepealProposalsOnHold(lua_State *)
- CvLuaLeague::lResolutionTableHelper(lua_State *, const int, CvResolution &)