Hooks
static bool BeforeCvLeagueAI_AllocateProposals(CvLeagueAI* self, CvLeague* pLeague);static void AfterCvLeagueAI_AllocateProposals(CvLeagueAI* self, CvLeague* pLeague);static void ReplaceCvLeagueAI_AllocateProposals(void (*original)(CvLeagueAI*, CvLeague*), CvLeagueAI* self, CvLeague* pLeague);CivRegisterBefore<CivHooks::CvLeagueAI_AllocateProposals>(host, &BeforeCvLeagueAI_AllocateProposals);CivRegisterAfter<CivHooks::CvLeagueAI_AllocateProposals>(host, &AfterCvLeagueAI_AllocateProposals);CivRegisterReplace<CivHooks::CvLeagueAI_AllocateProposals>(host, &ReplaceCvLeagueAI_AllocateProposals);
Code
9744void CvLeagueAI::AllocateProposals(CvLeague* pLeague)9745{9746 ProposalConsiderationList vConsiderations;97479748 std::vector<ResolutionTypes> vInactive = pLeague->GetInactiveResolutions();9749 ActiveResolutionList vActive = pLeague->GetActiveResolutions();97509751 if (!vActive.empty())9752 {9753 for (uint iResolutionIndex = 0; iResolutionIndex < vActive.size(); iResolutionIndex++)9754 {9755 int iID = vActive[iResolutionIndex].GetID();9756 if (pLeague->CanProposeRepeal(iID, GetPlayer()->GetID()))9757 {9758 ProposalConsideration consideration(/*bEnact*/ false, iResolutionIndex, LeagueHelpers::CHOICE_NONE);9759 int iScore = ScoreProposal(pLeague, &vActive[iResolutionIndex]);9760 vConsiderations.push_back(consideration, iScore);9761 }9762 }9763 }97649765 if (!vInactive.empty())9766 {9767 for (uint iResolutionIndex = 0; iResolutionIndex < vInactive.size(); iResolutionIndex++)9768 {9769 ResolutionTypes eResolution = vInactive[iResolutionIndex];9770 CvResolutionEntry* pkInfo = GC.getResolutionInfo(eResolution);9771 if (pkInfo)9772 {9773 std::vector<int> vAllChoices = pLeague->GetChoicesForDecision(pkInfo->GetProposerDecision(), GetPlayer()->GetID());9774 if (vAllChoices.empty())9775 {9776 if (pLeague->CanProposeEnact(eResolution, GetPlayer()->GetID(), LeagueHelpers::CHOICE_NONE))9777 {9778 ProposalConsideration consideration(/*bEnact*/ true, iResolutionIndex, LeagueHelpers::CHOICE_NONE);9779 int iScore = ScoreProposal(pLeague, eResolution, LeagueHelpers::CHOICE_NONE);9780 vConsiderations.push_back(consideration, iScore);9781 }9782 }9783 else9784 {9785 for (uint i = 0; i < vAllChoices.size(); i++)9786 {9787 int iChoice = vAllChoices[i];9788 if (pLeague->CanProposeEnact(eResolution, GetPlayer()->GetID(), iChoice))9789 {9790 ProposalConsideration consideration(/*bEnact*/ true, iResolutionIndex, iChoice);9791 int iScore = ScoreProposal(pLeague, eResolution, iChoice);9792 vConsiderations.push_back(consideration, iScore);9793 }9794 }9795 }9796 }9797 }9798 }97999800 // Choose by weight from the top N9801 CvAssertMsg(vConsiderations.size() > 0, "No proposals available for the AI to make. Please send Anton your save file and version.");9802 if (vConsiderations.size() > 0)9803 {9804 vConsiderations.SortItems();98059806 // Even if we don't like anything, make sure we have something to choose from9807 if (vConsiderations.GetTotalWeight() <= 0)9808 {9809 for (int i = 0; i < vConsiderations.size(); i++)9810 {9811 vConsiderations.SetWeight(i, 1);9812 }9813 }98149815 RandomNumberDelegate fn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);9816 ProposalConsideration proposal = vConsiderations.ChooseFromTopChoices(MIN(vConsiderations.size(), LeagueHelpers::AI_CHOOSE_PROPOSAL_FROM_TOP), &fn, "Choosing proposal from top choices");9817 if (proposal.bEnact)9818 {9819 ResolutionTypes eResolution = vInactive[proposal.iIndex];9820 pLeague->DoProposeEnact(eResolution, GetPlayer()->GetID(), proposal.iChoice);9821 }9822 else9823 {9824 int iID = vActive[proposal.iIndex].GetID();9825 pLeague->DoProposeRepeal(iID, GetPlayer()->GetID());9826 }9827 }9828}