Bazaar developer reference

CvLeagueAI::FindBestVoteChoices(CvEnactProposal *, VoteConsiderationList &)

Defined in
CvVotingClasses.cpp, line 8732
Class
CvLeagueAI
Hook name
CivHooks::CvLeagueAI_FindBestVoteChoices

Hooks

static bool BeforeCvLeagueAI_FindBestVoteChoices(CvLeagueAI* self, CvEnactProposal * pProposal, CvWeightedVector<CvLeagueAI::VoteConsideration, 32> & considerations);static void AfterCvLeagueAI_FindBestVoteChoices(CvLeagueAI* self, CvEnactProposal * pProposal, CvWeightedVector<CvLeagueAI::VoteConsideration, 32> & considerations);static void ReplaceCvLeagueAI_FindBestVoteChoices(void (*original)(CvLeagueAI*, CvEnactProposal *, CvWeightedVector<CvLeagueAI::VoteConsideration, 32> &), CvLeagueAI* self, CvEnactProposal * pProposal, CvWeightedVector<CvLeagueAI::VoteConsideration, 32> & considerations);CivRegisterBefore<CivHooks::CvLeagueAI_FindBestVoteChoices>(host, &BeforeCvLeagueAI_FindBestVoteChoices);CivRegisterAfter<CivHooks::CvLeagueAI_FindBestVoteChoices>(host, &AfterCvLeagueAI_FindBestVoteChoices);CivRegisterReplace<CivHooks::CvLeagueAI_FindBestVoteChoices>(host, &ReplaceCvLeagueAI_FindBestVoteChoices);

Code

8731// Find the best choices for a particular proposal, and add the data directly to the reference list parameter8732void CvLeagueAI::FindBestVoteChoices(CvEnactProposal* pProposal, VoteConsiderationList& considerations)8733{8734	VoteConsiderationList vScoredChoices;8735	int iMaxChoicesToConsider = 1;87368737	CvAssert(GC.getGame().GetGameLeagues()->GetNumActiveLeagues() > 0);8738	if (!(GC.getGame().GetGameLeagues()->GetNumActiveLeagues() > 0)) return;8739	CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague();8740	CvAssert(pLeague != NULL);8741	if (!(pLeague != NULL)) return;87428743	switch (pProposal->GetVoterDecision()->GetType())8744	{8745	case RESOLUTION_DECISION_YES_OR_NO:8746		{8747			iMaxChoicesToConsider = 1;8748			break;8749		}8750	case RESOLUTION_DECISION_ANY_MEMBER:8751	case RESOLUTION_DECISION_MAJOR_CIV_MEMBER:8752	case RESOLUTION_DECISION_OTHER_MAJOR_CIV_MEMBER:8753		{8754			iMaxChoicesToConsider = 1;8755			break;8756		}8757	default:8758		{8759			CvAssertMsg(false, "Unexpected decision type when evaluating choices for AI on a proposed resolution.");8760			break;8761		}8762	}87638764	std::vector<int> vChoices = pLeague->GetChoicesForDecision(pProposal->GetVoterDecision()->GetType(), GetPlayer()->GetID());8765	for (uint i = 0; i < vChoices.size(); i++)8766	{8767		VoteConsideration consideration(/*bEnact*/ true, pProposal->GetID(), vChoices[i]);8768		int iScore = ScoreVoteChoice(pProposal, vChoices[i]);8769		iScore = MAX(iScore, 0); // No negative weights8770		vScoredChoices.push_back(consideration, iScore);8771	}87728773	if (vScoredChoices.size() > 0)8774	{8775		vScoredChoices.SortItems();8776		for (int i = 0; i < vScoredChoices.size() && i < iMaxChoicesToConsider; i++)8777		{8778			considerations.push_back(vScoredChoices.GetElement(i), vScoredChoices.GetWeight(i));8779			LogVoteChoiceConsidered(pProposal, vScoredChoices.GetElement(i).iChoice, vScoredChoices.GetWeight(i));8780		}8781	}8782}

Calls

Called by