Bazaar developer reference

CvPlayerAI::AI_considerAnnex()

Defined in
CvPlayerAI.cpp, line 716
Class
CvPlayerAI
Hook name
CivHooks::CvPlayerAI_AI_considerAnnex

Hooks

static bool BeforeCvPlayerAI_AI_considerAnnex(CvPlayerAI* self);static void AfterCvPlayerAI_AI_considerAnnex(CvPlayerAI* self);static void ReplaceCvPlayerAI_AI_considerAnnex(void (*original)(CvPlayerAI*), CvPlayerAI* self);CivRegisterBefore<CivHooks::CvPlayerAI_AI_considerAnnex>(host, &BeforeCvPlayerAI_AI_considerAnnex);CivRegisterAfter<CivHooks::CvPlayerAI_AI_considerAnnex>(host, &AfterCvPlayerAI_AI_considerAnnex);CivRegisterReplace<CivHooks::CvPlayerAI_AI_considerAnnex>(host, &ReplaceCvPlayerAI_AI_considerAnnex);

Code

716void CvPlayerAI::AI_considerAnnex()717{718	AI_PERF("AI-perf.csv", "AI_ considerAnnex");719720	// if the empire is unhappy, don't consider annexing721	if (IsEmpireUnhappy())722	{723		return;724	}725726	// if we're going for a culture victory, don't consider annexing727	if (GetDiplomacyAI()->IsGoingForCultureVictory())728	{729		return;730	}731732	// for Venice733	if (GetPlayerTraits()->IsNoAnnexing())734	{735		return;736	}737738	// if their capital city is puppeted, annex it739	CvCity* pCity = getCapitalCity();740	if (pCity && pCity->IsPuppet())741	{742		// we should only annex one city a turn, and sense this is one, we're done!743		pCity->DoAnnex();744		return;745	}746747	std::vector<CityAndProduction> aCityAndProductions;748	int iLoop = 0;749	pCity = NULL;750751	// Find first coastal city in same area as settler752	for(pCity = firstCity(&iLoop); pCity != NULL; pCity = nextCity(&iLoop))753	{754		CityAndProduction kEval;755		kEval.pCity = pCity;756		kEval.iProduction = pCity->getYieldRateTimes100(YIELD_PRODUCTION, false);757		aCityAndProductions.push_back(kEval);758	}759	760	std::stable_sort(aCityAndProductions.begin(), aCityAndProductions.end(), CityAndProductionEval());761	762	CvCity* pTargetCity = NULL;763	float fCutoffValue = GC.getNORMAL_ANNEX();764	BuildingClassTypes eCourthouseType = NO_BUILDINGCLASS;765	// find courthouse766	for(int eBuildingType = 0; eBuildingType < GC.getNumBuildingInfos(); eBuildingType++)767	{768		const BuildingTypes eBuilding = static_cast<BuildingTypes>(eBuildingType);769		CvBuildingEntry* buildingInfo = GC.getBuildingInfo(eBuilding);770771		if(buildingInfo)772		{773			if (buildingInfo->IsNoOccupiedUnhappiness())774			{775				eCourthouseType = (BuildingClassTypes)buildingInfo->GetBuildingClassType();776				break;777			}778		}779	}780781	bool bCourthouseImprovement = false;782	if (eCourthouseType != NO_BUILDINGCLASS)783	{784		if (GetPlayerPolicies()->GetBuildingClassProductionModifier(eCourthouseType) > 0)785		{786			bCourthouseImprovement = true;787		}788	}789790	if (bCourthouseImprovement)791	{792		fCutoffValue = GC.getAGGRESIVE_ANNEX();793	}794795	uint uiCutOff = (uint)(aCityAndProductions.size() * fCutoffValue);796	for (uint ui = 0; ui < uiCutOff; ui++)797	{798		if (aCityAndProductions[ui].pCity->IsPuppet())799		{800			pTargetCity = aCityAndProductions[ui].pCity;801			break;802		}803	}804805	if (pTargetCity)806	{807		if (!pTargetCity->IsResistance())808		{809			pTargetCity->DoAnnex();810		}811	}812}

Calls

Called by