Bazaar developer reference

CvAdvisorRecommender::FindUnassignedAdvisorForBuildable(PlayerTypes, CvCityBuildable &)

Defined in
CvAdvisorRecommender.cpp, line 535
Class
CvAdvisorRecommender
Hook name
CivHooks::CvAdvisorRecommender_FindUnassignedAdvisorForBuildable

Hooks

static bool BeforeCvAdvisorRecommender_FindUnassignedAdvisorForBuildable(CvAdvisorRecommender* self, PlayerTypes arg0, CvCityBuildable& buildable, AdvisorTypes& result);static void AfterCvAdvisorRecommender_FindUnassignedAdvisorForBuildable(CvAdvisorRecommender* self, PlayerTypes arg0, CvCityBuildable& buildable, AdvisorTypes& result);static AdvisorTypes ReplaceCvAdvisorRecommender_FindUnassignedAdvisorForBuildable(AdvisorTypes (*original)(CvAdvisorRecommender*, PlayerTypes, CvCityBuildable&), CvAdvisorRecommender* self, PlayerTypes arg0, CvCityBuildable& buildable);CivRegisterBefore<CivHooks::CvAdvisorRecommender_FindUnassignedAdvisorForBuildable>(host, &BeforeCvAdvisorRecommender_FindUnassignedAdvisorForBuildable);CivRegisterAfter<CivHooks::CvAdvisorRecommender_FindUnassignedAdvisorForBuildable>(host, &AfterCvAdvisorRecommender_FindUnassignedAdvisorForBuildable);CivRegisterReplace<CivHooks::CvAdvisorRecommender_FindUnassignedAdvisorForBuildable>(host, &ReplaceCvAdvisorRecommender_FindUnassignedAdvisorForBuildable);

Code

535AdvisorTypes CvAdvisorRecommender::FindUnassignedAdvisorForBuildable(PlayerTypes /*ePlayer*/, CvCityBuildable& buildable)536{537	int aiAdvisorValues[NUM_ADVISOR_TYPES];538	for(uint ui = 0; ui < NUM_ADVISOR_TYPES; ui++)539	{540		aiAdvisorValues[ui] = 0;541	}542543	CvBuildingEntry* pBuilding = NULL;544	CvUnitEntry*     pUnit     = NULL;545	CvProjectEntry*  pProject  = NULL;546	switch(buildable.m_eBuildableType)547	{548	case CITY_BUILDABLE_UNIT:549		pUnit = GC.getUnitInfo((UnitTypes)buildable.m_iIndex);550		break;551	case CITY_BUILDABLE_BUILDING:552		pBuilding = GC.getBuildingInfo((BuildingTypes)buildable.m_iIndex);553		break;554	case CITY_BUILDABLE_PROJECT:555		pProject = GC.getProjectInfo((ProjectTypes)buildable.m_iIndex);556		break;557	}558559	for(int i = 0; i < GC.getNumFlavorTypes(); i++)560	{561		FlavorTypes eFlavor = (FlavorTypes)i;562		int iFlavorValue = 0;563		if(pBuilding)564		{565			iFlavorValue = pBuilding->GetFlavorValue(eFlavor);566		}567		else if(pUnit)568		{569			iFlavorValue = pUnit->GetFlavorValue(eFlavor);570		}571		else if(pProject)572		{573			iFlavorValue = pProject->GetFlavorValue(eFlavor);574		}575576		if(iFlavorValue <= 0)577		{578			continue;579		}580581		for(uint uiAdvisor = 0; uiAdvisor < NUM_ADVISOR_TYPES; uiAdvisor++)582		{583			AdvisorTypes eAdvisor = (AdvisorTypes)uiAdvisor;584			aiAdvisorValues[uiAdvisor] += iFlavorValue * AdvisorInterestInFlavor(eAdvisor, eFlavor);585		}586	}587588	AdvisorTypes eWinningAdvisor = NO_ADVISOR_TYPE;589	int iHighestValue = 0;590	for(uint ui = 0; ui < NUM_ADVISOR_TYPES; ui++)591	{592		// skip this advisor if already assigned593		if(m_aRecommendedBuilds[ui].m_eBuildableType != NOT_A_CITY_BUILDABLE)594		{595			continue;596		}597598		if(aiAdvisorValues[ui] > iHighestValue)599		{600			eWinningAdvisor = (AdvisorTypes)ui;601			iHighestValue = aiAdvisorValues[ui];602		}603	}604605	return eWinningAdvisor;606607}

Calls

Called by