Bazaar developer reference

CvPolicyAI::PropagateWeights(int, int, int, int)

Defined in
CvPolicyAI.cpp, line 794
Class
CvPolicyAI
Hook name
CivHooks::CvPolicyAI_PropagateWeights

Hooks

static bool BeforeCvPolicyAI_PropagateWeights(CvPolicyAI* self, int iPolicy, int iWeight, int iPropagationPercent, int iPropagationLevel);static void AfterCvPolicyAI_PropagateWeights(CvPolicyAI* self, int iPolicy, int iWeight, int iPropagationPercent, int iPropagationLevel);static void ReplaceCvPolicyAI_PropagateWeights(void (*original)(CvPolicyAI*, int, int, int, int), CvPolicyAI* self, int iPolicy, int iWeight, int iPropagationPercent, int iPropagationLevel);CivRegisterBefore<CivHooks::CvPolicyAI_PropagateWeights>(host, &BeforeCvPolicyAI_PropagateWeights);CivRegisterAfter<CivHooks::CvPolicyAI_PropagateWeights>(host, &AfterCvPolicyAI_PropagateWeights);CivRegisterReplace<CivHooks::CvPolicyAI_PropagateWeights>(host, &ReplaceCvPolicyAI_PropagateWeights);

Code

793/// Recursive routine to weight all prerequisite policies794void CvPolicyAI::PropagateWeights(int iPolicy, int iWeight, int iPropagationPercent, int iPropagationLevel)795{796	if(iPropagationLevel < m_iPolicyWeightPropagationLevels)797	{798		int iPropagatedWeight = iWeight * iPropagationPercent / 100;799800		// Loop through all prerequisites801		for(int iI = 0; iI < GC.getNUM_OR_TECH_PREREQS(); iI++)802		{803			// Did we find a prereq?804			int iPrereq = m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(iPolicy)->GetPrereqAndPolicies(iI);805			if(iPrereq != NO_POLICY)806			{807				// Apply reduced weight here.  Note that we apply these to the master weight array, not808				// the temporary one.  The temporary one is just used to hold the newly weighted policies809				// (from which this weight propagation must originate).810				m_PolicyAIWeights.IncreaseWeight(iPrereq, iPropagatedWeight);811812				// Recurse to its prereqs (assuming we have any weight left)813				if(iPropagatedWeight > 0)814				{815					PropagateWeights(iPrereq, iPropagatedWeight, iPropagationPercent, iPropagationLevel++);816				}817			}818			else819			{820				break;821			}822		}823	}824}

Calls

Called by