Bazaar developer reference

CvBuilderTaskingAI::GetResourceWeight(ResourceTypes, ImprovementTypes, int)

Defined in
CvBuilderTaskingAI.cpp, line 1973
Class
CvBuilderTaskingAI
Hook name
CivHooks::CvBuilderTaskingAI_GetResourceWeight

Hooks

static bool BeforeCvBuilderTaskingAI_GetResourceWeight(CvBuilderTaskingAI* self, ResourceTypes eResource, ImprovementTypes eImprovement, int iQuantity, int& result);static void AfterCvBuilderTaskingAI_GetResourceWeight(CvBuilderTaskingAI* self, ResourceTypes eResource, ImprovementTypes eImprovement, int iQuantity, int& result);static int ReplaceCvBuilderTaskingAI_GetResourceWeight(int (*original)(CvBuilderTaskingAI*, ResourceTypes, ImprovementTypes, int), CvBuilderTaskingAI* self, ResourceTypes eResource, ImprovementTypes eImprovement, int iQuantity);CivRegisterBefore<CivHooks::CvBuilderTaskingAI_GetResourceWeight>(host, &BeforeCvBuilderTaskingAI_GetResourceWeight);CivRegisterAfter<CivHooks::CvBuilderTaskingAI_GetResourceWeight>(host, &AfterCvBuilderTaskingAI_GetResourceWeight);CivRegisterReplace<CivHooks::CvBuilderTaskingAI_GetResourceWeight>(host, &ReplaceCvBuilderTaskingAI_GetResourceWeight);

Code

1972/// Return the weight of this resource1973int CvBuilderTaskingAI::GetResourceWeight(ResourceTypes eResource, ImprovementTypes eImprovement, int iQuantity)1974{1975	int iWeight = 0;1976	CvResourceInfo* pkResource = GC.getResourceInfo(eResource);1977	if(pkResource == NULL)1978	{1979		return 0;1980	}19811982	for(int i = 0; i < GC.getNumFlavorTypes(); i++)1983	{1984		int iResourceFlavor = pkResource->getFlavorValue((FlavorTypes)i);1985		int iPersonalityFlavorValue = m_pPlayer->GetFlavorManager()->GetPersonalityIndividualFlavor((FlavorTypes)i);1986		int iResult = iResourceFlavor * iPersonalityFlavorValue;19871988		if(iResult > 0)1989		{1990			iWeight += iResult;1991		}19921993		int iImprovementFlavor = 1;1994		if(eImprovement != NO_IMPROVEMENT)1995		{1996			iImprovementFlavor = GC.getImprovementInfo(eImprovement)->GetFlavorValue(i);1997		}19981999		int iUsableByCityWeight = iPersonalityFlavorValue * iImprovementFlavor;2000		if(iUsableByCityWeight > 0)2001		{2002			iWeight += iUsableByCityWeight;2003		}2004	}20052006	// if the empire is unhappy (or close to it) and this is a luxury resource the player doesn't have, provide a super bonus to getting it2007	if(pkResource->getResourceUsage() == RESOURCEUSAGE_LUXURY)2008	{2009		int iModifier = GC.getBUILDER_TASKING_PLOT_EVAL_MULTIPLIER_LUXURY_RESOURCE() * pkResource->getHappiness();20102011		//if (m_pPlayer->IsEmpireUnhappy() || m_pPlayer->GetExcessHappiness() <= 2)2012		//{2013		//}2014		if(m_pPlayer->getNumResourceAvailable(eResource) == 0)2015		{2016			// full bonus2017		}2018		else2019		{2020			iModifier = (iModifier * 3) / 4; // 3/4ths the awesome bonus, so that we pick up extra resources 2021		}20222023		iWeight *= iModifier;2024	}2025	else if(pkResource->getResourceUsage() == RESOURCEUSAGE_STRATEGIC && pkResource->getTechCityTrade())2026	{2027		bool bHasTech = GET_TEAM(m_pPlayer->getTeam()).GetTeamTechs()->HasTech((TechTypes) pkResource->getTechCityTrade());2028		if(bHasTech)2029		{2030			// measure quantity2031			int iMultiplyingAmount = iQuantity * 200;20322033			// if we don't have any currently available2034			if(m_pPlayer->getNumResourceAvailable(eResource) == 0)2035			{2036				// if we have some of the strategic resource, but all is used2037				if(m_pPlayer->getNumResourceUsed(eResource) > 0)2038				{2039					iMultiplyingAmount *= 4;2040				}2041				else2042				{2043					// if we don't have any of it2044					iMultiplyingAmount *= 4;2045				}2046			}20472048			iWeight *= iMultiplyingAmount;2049		}2050	}20512052	return iWeight;2053}

Calls

Called by