Bazaar developer reference

CvPlayerPolicies::DoSwitchToPolicyBranch(PolicyBranchTypes)

Defined in
CvPolicyClasses.cpp, line 3879
Class
CvPlayerPolicies
Hook name
CivHooks::CvPlayerPolicies_DoSwitchToPolicyBranch

Hooks

static bool BeforeCvPlayerPolicies_DoSwitchToPolicyBranch(CvPlayerPolicies* self, PolicyBranchTypes eBranchType);static void AfterCvPlayerPolicies_DoSwitchToPolicyBranch(CvPlayerPolicies* self, PolicyBranchTypes eBranchType);static void ReplaceCvPlayerPolicies_DoSwitchToPolicyBranch(void (*original)(CvPlayerPolicies*, PolicyBranchTypes), CvPlayerPolicies* self, PolicyBranchTypes eBranchType);CivRegisterBefore<CivHooks::CvPlayerPolicies_DoSwitchToPolicyBranch>(host, &BeforeCvPlayerPolicies_DoSwitchToPolicyBranch);CivRegisterAfter<CivHooks::CvPlayerPolicies_DoSwitchToPolicyBranch>(host, &AfterCvPlayerPolicies_DoSwitchToPolicyBranch);CivRegisterReplace<CivHooks::CvPlayerPolicies_DoSwitchToPolicyBranch>(host, &ReplaceCvPlayerPolicies_DoSwitchToPolicyBranch);

Code

3878/// We're going to be using eBranchType now3879void CvPlayerPolicies::DoSwitchToPolicyBranch(PolicyBranchTypes eBranchType)3880{3881	// Must be unlocked3882	if(!IsPolicyBranchUnlocked(eBranchType))3883	{3884		return;3885	}38863887	// Is this branch blocked?3888	if(IsPolicyBranchBlocked(eBranchType))3889	{3890		// Anarchy time!3891		int iNumTurnsAnarchy = /*1*/ GC.getSWITCH_POLICY_BRANCHES_ANARCHY_TURNS();3892		GetPlayer()->ChangeAnarchyNumTurns(iNumTurnsAnarchy);38933894		// Turn off blocking3895		SetPolicyBranchBlocked(eBranchType, false);3896	}38973898	// Does THIS Branch block any other branch?3899	int iBranchLoop;3900	for(iBranchLoop = 0; iBranchLoop < m_pPolicies->GetNumPolicyBranches(); iBranchLoop++)3901	{3902		const PolicyBranchTypes eDisableBranch = static_cast<PolicyBranchTypes>(iBranchLoop);3903		CvPolicyBranchEntry* pkDisablePolicyBranchInfo = GC.getPolicyBranchInfo(eBranchType);3904		if(pkDisablePolicyBranchInfo)3905		{3906			if(pkDisablePolicyBranchInfo->GetPolicyBranchDisables(eDisableBranch) > 0)3907			{3908				SetPolicyBranchBlocked(eDisableBranch, true);3909			}3910		}39113912	}39133914//	std::vector<PolicyBranchTypes> veOtherPoliciesToUnblock;3915	bool bUnlockBranch;39163917	// Do a pass over the Policies to see if there are any we can safely unblock3918	for(iBranchLoop = 0; iBranchLoop < m_pPolicies->GetNumPolicyBranches(); iBranchLoop++)3919	{3920		const PolicyBranchTypes eActivateBranch = static_cast<PolicyBranchTypes>(iBranchLoop);3921		CvPolicyBranchEntry* pkActivateBranchInfo = GC.getPolicyBranchInfo(eActivateBranch);3922		if(pkActivateBranchInfo)3923		{3924			// Must be activatable3925			if(!IsPolicyBranchUnlocked(eActivateBranch))3926			{3927				continue;3928			}39293930			// Must be blocked now3931			if(!IsPolicyBranchBlocked(eActivateBranch))3932			{3933				continue;3934			}39353936			// Let's try to unblock this3937			bUnlockBranch = true;39383939			// Loop through all Policies we have and make sure they don't interfere with us3940			for(int iOtherBranchLoop = 0; iOtherBranchLoop < m_pPolicies->GetNumPolicyBranches(); iOtherBranchLoop++)3941			{3942				const PolicyBranchTypes eOtherBranch = static_cast<PolicyBranchTypes>(iOtherBranchLoop);3943				CvPolicyBranchEntry* pkOtherPolicyBranchInfo = GC.getPolicyBranchInfo(eOtherBranch);3944				if(pkOtherPolicyBranchInfo)3945				{3946					// Don't test branch against itself3947					if(eActivateBranch != eOtherBranch)3948					{3949						// Is this other branch unlocked and unblocked?3950						if(IsPolicyBranchUnlocked(eOtherBranch))3951						{3952							if(!IsPolicyBranchBlocked(eOtherBranch))3953							{3954								// Do we block them?3955								if(pkActivateBranchInfo->GetPolicyBranchDisables(eOtherBranch) > 0)3956								{3957									bUnlockBranch = false;3958								}3959								// Do they block us?3960								if(pkOtherPolicyBranchInfo->GetPolicyBranchDisables(eActivateBranch) > 0)3961								{3962									bUnlockBranch = false;3963								}3964							}3965						}39663967						// We've identified that eActivateBranch conflicts with something, so leave it be3968						if(!bUnlockBranch)3969						{3970							break;3971						}3972					}3973				}3974			}39753976			// We know that eActivateBranch doesn't affect anything, so unblock it!3977			if(bUnlockBranch)3978			{3979				SetPolicyBranchBlocked(eActivateBranch, false);3980			}3981		}3982	}39833984	// This Dirty bit must only be set when changing something for the active player3985	if(GC.getGame().getActivePlayer() == GetPlayer()->GetID())3986	{3987		GC.GetEngineUserInterface()->setDirty(Policies_DIRTY_BIT, true);3988	}3989}

Calls

Called by