Bazaar developer reference

CvPlayerPolicies::SetPolicy(PolicyTypes, bool, bool)

Defined in
CvPolicyClasses.cpp, line 2824
Class
CvPlayerPolicies
Hook name
CivHooks::CvPlayerPolicies_SetPolicy

Hooks

static bool BeforeCvPlayerPolicies_SetPolicy(CvPlayerPolicies* self, PolicyTypes eIndex, bool bNewValue, bool bFree);static void AfterCvPlayerPolicies_SetPolicy(CvPlayerPolicies* self, PolicyTypes eIndex, bool bNewValue, bool bFree);static void ReplaceCvPlayerPolicies_SetPolicy(void (*original)(CvPlayerPolicies*, PolicyTypes, bool, bool), CvPlayerPolicies* self, PolicyTypes eIndex, bool bNewValue, bool bFree);CivRegisterBefore<CivHooks::CvPlayerPolicies_SetPolicy>(host, &BeforeCvPlayerPolicies_SetPolicy);CivRegisterAfter<CivHooks::CvPlayerPolicies_SetPolicy>(host, &AfterCvPlayerPolicies_SetPolicy);CivRegisterReplace<CivHooks::CvPlayerPolicies_SetPolicy>(host, &ReplaceCvPlayerPolicies_SetPolicy);

Code

2822/// Accessor: set whether player has a policy2823#if defined(MOD_API_EXTENSIONS)2824void CvPlayerPolicies::SetPolicy(PolicyTypes eIndex, bool bNewValue, bool bFree)2825#else2826void CvPlayerPolicies::SetPolicy(PolicyTypes eIndex, bool bNewValue)2827#endif2828{2829	CvAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");2830	CvAssertMsg(eIndex < m_pPolicies->GetNumPolicies(), "eIndex is expected to be within maximum bounds (invalid Index)");28312832	CvPolicyEntry* pkPolicyInfo = GC.getPolicyInfo(eIndex);2833	if(pkPolicyInfo == NULL)2834		return;28352836	if(HasPolicy(eIndex) != bNewValue)2837	{2838		m_pabHasPolicy[eIndex] = bNewValue;28392840		int iChange = bNewValue ? 1 : -1;2841#if defined(MOD_API_EXTENSIONS)2842		m_pabFreePolicy[eIndex] = bFree;2843		if (bFree) iChange = 0;2844#endif2845		GetPlayer()->ChangeNumPolicies(iChange);28462847		if(bNewValue)2848		{2849			DoNewPolicyPickedForHistory(eIndex);28502851			if(m_pPlayer->GetID() == GC.getGame().getActivePlayer())2852				GC.GetEngineUserInterface()->SetPolicyNotificationSeen(false);2853		}28542855		PolicyBranchTypes eThisBranch = (PolicyBranchTypes) pkPolicyInfo->GetPolicyBranchType();28562857		if(eThisBranch != NO_POLICY_BRANCH_TYPE)2858		{2859			bool bBranchFinished;28602861			// We don't have this Policy, so this branch is definitely not finished2862			if(!bNewValue)2863			{2864				bBranchFinished = false;2865			}2866			// We now have this Policy, so we MAY have this branch finished2867			else2868			{2869				bBranchFinished = true;28702871				// Is the branch this policy is in finished?2872				for(int iPolicyLoop = 0; iPolicyLoop < GetPolicies()->GetNumPolicies(); iPolicyLoop++)2873				{2874					const PolicyTypes eLoopPolicy = static_cast<PolicyTypes>(iPolicyLoop);28752876					CvPolicyEntry* pkLoopPolicyInfo = GC.getPolicyInfo(eLoopPolicy);2877					if(pkLoopPolicyInfo)2878					{2879						// This policy belongs to our branch2880						if(pkLoopPolicyInfo->GetPolicyBranchType() == eThisBranch)2881						{2882							// We don't have this policy!2883							if(!HasPolicy(eLoopPolicy))2884							{2885								bBranchFinished = false;28862887								// No need to continue, we already know we don't have the branch2888								break;2889							}2890						}2891					}2892				}2893			}28942895			SetPolicyBranchFinished(eThisBranch, bBranchFinished);28962897			if(bBranchFinished)2898			{2899				CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(eThisBranch);2900				if(pkPolicyBranchInfo)2901				{2902					PolicyTypes eFinisher = (PolicyTypes)pkPolicyBranchInfo->GetFreeFinishingPolicy();2903					if(eFinisher != NO_POLICY)2904					{2905						GetPlayer()->setHasPolicy(eFinisher, true);2906						GetPlayer()->ChangeNumFreePoliciesEver(1);2907					}2908				}2909			}2910		}2911	}2912}

Calls

Called by