Bazaar developer reference

CvTechAI::AddFlavorWeights(FlavorTypes, int, int)

Defined in
CvTechAI.cpp, line 101
Class
CvTechAI
Hook name
CivHooks::CvTechAI_AddFlavorWeights

Hooks

static bool BeforeCvTechAI_AddFlavorWeights(CvTechAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);static void AfterCvTechAI_AddFlavorWeights(CvTechAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);static void ReplaceCvTechAI_AddFlavorWeights(void (*original)(CvTechAI*, FlavorTypes, int, int), CvTechAI* self, FlavorTypes eFlavor, int iWeight, int iPropagationPercent);CivRegisterBefore<CivHooks::CvTechAI_AddFlavorWeights>(host, &BeforeCvTechAI_AddFlavorWeights);CivRegisterAfter<CivHooks::CvTechAI_AddFlavorWeights>(host, &AfterCvTechAI_AddFlavorWeights);CivRegisterReplace<CivHooks::CvTechAI_AddFlavorWeights>(host, &ReplaceCvTechAI_AddFlavorWeights);

Code

100/// Establish weights for one flavor; can be called multiple times to layer strategies101void CvTechAI::AddFlavorWeights(FlavorTypes eFlavor, int iWeight, int iPropagationPercent)102{103	int* paiTempWeights;104105	// Create a temporary array of weights106	paiTempWeights = (int*)_alloca(sizeof(int) * m_pCurrentTechs->GetTechs()->GetNumTechs());107108	// Loop through all our techs109	for(int iTech = 0; iTech < m_pCurrentTechs->GetTechs()->GetNumTechs(); iTech++)110	{111		const TechTypes eTech = static_cast<TechTypes>(iTech);112		CvTechEntry* entry = m_pCurrentTechs->GetTechs()->GetEntry(iTech);113		if(entry)114		{115			// Set its weight by looking at tech's weight for this flavor and using iWeight multiplier passed in116			paiTempWeights[iTech] = entry->GetFlavorValue(eFlavor) * iWeight;117#if defined(MOD_BUGFIX_MINOR)118			// Applying multipliers is not going to change the fact it's zero!119			if (paiTempWeights[iTech] == 0) continue;120#endif121122			// Multiply the weight by any special player-specific weighting (i.e. to prioritize civ unique bonuses)123			paiTempWeights[iTech] *= m_pCurrentTechs->GetPlayer()->GetPlayerTechs()->GetCivTechPriority(eTech);124125			// Multiply the weight by any locale-specific weighting (i.e. to prioritize unlocking resources)126			paiTempWeights[iTech] *= m_pCurrentTechs->GetPlayer()->GetPlayerTechs()->GetLocaleTechPriority(eTech);127		}128	}129130	// Propagate these values left in the tree so prereqs get bought131	WeightPrereqs(paiTempWeights, iPropagationPercent);132133	// Add these weights over previous ones134	for(int iTech = 0; iTech < m_pCurrentTechs->GetTechs()->GetNumTechs(); iTech++)135	{136		CvTechEntry* entry = m_pCurrentTechs->GetTechs()->GetEntry(iTech);137		if(entry)138		{139#if defined(MOD_BUGFIX_MINOR)140			// Adding zero is not going to achieve a lot!141			if(paiTempWeights[iTech] != 0)142#endif143			m_TechAIWeights.IncreaseWeight(iTech, paiTempWeights[iTech]);144		}145	}146}

Calls

Called by