Bazaar developer reference

CvPolicyAI::WeighBranch(PolicyBranchTypes)

Defined in
CvPolicyAI.cpp, line 827
Class
CvPolicyAI
Hook name
CivHooks::CvPolicyAI_WeighBranch

Hooks

static bool BeforeCvPolicyAI_WeighBranch(CvPolicyAI* self, PolicyBranchTypes eBranch, int& result);static void AfterCvPolicyAI_WeighBranch(CvPolicyAI* self, PolicyBranchTypes eBranch, int& result);static int ReplaceCvPolicyAI_WeighBranch(int (*original)(CvPolicyAI*, PolicyBranchTypes), CvPolicyAI* self, PolicyBranchTypes eBranch);CivRegisterBefore<CivHooks::CvPolicyAI_WeighBranch>(host, &BeforeCvPolicyAI_WeighBranch);CivRegisterAfter<CivHooks::CvPolicyAI_WeighBranch>(host, &AfterCvPolicyAI_WeighBranch);CivRegisterReplace<CivHooks::CvPolicyAI_WeighBranch>(host, &ReplaceCvPolicyAI_WeighBranch);

Code

826/// Priority for opening up this branch827int CvPolicyAI::WeighBranch(PolicyBranchTypes eBranch)828{829	int iWeight = 0;830831	CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(eBranch);832	if(pkPolicyBranchInfo)833	{834		for(int iPolicyLoop = 0; iPolicyLoop < m_pCurrentPolicies->GetPolicies()->GetNumPolicies(); iPolicyLoop++)835		{836			const PolicyTypes ePolicyLoop = static_cast<PolicyTypes>(iPolicyLoop);837			CvPolicyEntry* pkLoopPolicyInfo = GC.getPolicyInfo(ePolicyLoop);838			if(pkLoopPolicyInfo)839			{840				// Policy we don't have?841				if(!m_pCurrentPolicies->HasPolicy(ePolicyLoop))842				{843					// From this branch we are considering opening?844					if(pkLoopPolicyInfo->GetPolicyBranchType() == eBranch)845					{846						// With no prereqs?847						if(pkLoopPolicyInfo->GetPrereqAndPolicies(0) == NO_POLICY)848						{849							iWeight += m_PolicyAIWeights.GetWeight(iPolicyLoop);850						}851					}852				}853			}854		}855856		// Add weight of free policy from branch857		iWeight += m_PolicyAIWeights.GetWeight(pkPolicyBranchInfo->GetFreePolicy());858	}859860	return iWeight;861}

Calls

Called by