Bazaar developer reference

CvPolicyAI::AddFlavorWeights(FlavorTypes, int, int)

Defined in
CvPolicyAI.cpp, line 110
Class
CvPolicyAI
Hook name
CivHooks::CvPolicyAI_AddFlavorWeights

Hooks

static bool BeforeCvPolicyAI_AddFlavorWeights(CvPolicyAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);static void AfterCvPolicyAI_AddFlavorWeights(CvPolicyAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);static void ReplaceCvPolicyAI_AddFlavorWeights(void (*original)(CvPolicyAI*, FlavorTypes, int, int), CvPolicyAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);CivRegisterBefore<CivHooks::CvPolicyAI_AddFlavorWeights>(host, &BeforeCvPolicyAI_AddFlavorWeights);CivRegisterAfter<CivHooks::CvPolicyAI_AddFlavorWeights>(host, &AfterCvPolicyAI_AddFlavorWeights);CivRegisterReplace<CivHooks::CvPolicyAI_AddFlavorWeights>(host, &ReplaceCvPolicyAI_AddFlavorWeights);

Code

109/// Establish weights for one flavor; can be called multiple times to layer strategies110void CvPolicyAI::AddFlavorWeights(FlavorTypes eFlavor, int iWeight, int iPropagationPercent)111{112	int iPolicy;113	CvPolicyEntry* entry;114	int* paiTempWeights;115116	CvPolicyXMLEntries* pkPolicyEntries = m_pCurrentPolicies->GetPolicies();117	// Create a temporary array of weights118	paiTempWeights = (int*)_alloca(sizeof(int*) * pkPolicyEntries->GetNumPolicies());119120	// Loop through all our policies121	for(iPolicy = 0; iPolicy < pkPolicyEntries->GetNumPolicies(); iPolicy++)122	{123		entry = pkPolicyEntries->GetPolicyEntry(iPolicy);124125		// Set its weight by looking at policy's weight for this flavor and using iWeight multiplier passed in126		if(entry)127			paiTempWeights[iPolicy] = entry->GetFlavorValue(eFlavor) * iWeight;128		else129			paiTempWeights[iPolicy] = 0;130	}131132	// Propagate these values left in the tree so prereqs get bought133	if(iPropagationPercent > 0)134	{135		WeightPrereqs(paiTempWeights, iPropagationPercent);136	}137138	// Add these weights over previous ones139	for(iPolicy = 0; iPolicy < m_pCurrentPolicies->GetPolicies()->GetNumPolicies(); iPolicy++)140	{141		m_PolicyAIWeights.IncreaseWeight(iPolicy, paiTempWeights[iPolicy]);142	}143}

Calls

Called by