Bazaar developer reference

CvReligionAI::ChooseMissionaryTargetCity(UnitHandle)

Defined in
CvReligionClasses.cpp, line 5334
Class
CvReligionAI
Hook name
CivHooks::CvReligionAI_ChooseMissionaryTargetCity

Hooks

static bool BeforeCvReligionAI_ChooseMissionaryTargetCity(CvReligionAI* self, UnitHandle pUnit, CvCity*& result);static void AfterCvReligionAI_ChooseMissionaryTargetCity(CvReligionAI* self, UnitHandle pUnit, CvCity*& result);static CvCity* ReplaceCvReligionAI_ChooseMissionaryTargetCity(CvCity* (*original)(CvReligionAI*, UnitHandle), CvReligionAI* self, UnitHandle pUnit);CivRegisterBefore<CivHooks::CvReligionAI_ChooseMissionaryTargetCity>(host, &BeforeCvReligionAI_ChooseMissionaryTargetCity);CivRegisterAfter<CivHooks::CvReligionAI_ChooseMissionaryTargetCity>(host, &AfterCvReligionAI_ChooseMissionaryTargetCity);CivRegisterReplace<CivHooks::CvReligionAI_ChooseMissionaryTargetCity>(host, &ReplaceCvReligionAI_ChooseMissionaryTargetCity);

Code

5333/// Find the city where a missionary should next spread his religion5334CvCity* CvReligionAI::ChooseMissionaryTargetCity(UnitHandle pUnit)5335{5336	ReligionTypes eMyReligion = GetReligionToSpread();5337	int iBestScore = 0;5338	CvCity* pBestCity = NULL;53395340	if(eMyReligion <= RELIGION_PANTHEON)5341	{5342		return NULL;5343	}53445345#pragma warning ( push )5346#pragma warning ( disable : 6011 ) // Dereferencing NULL pointer5347	AI_PERF_FORMAT("AI-perf-tact.csv", ("ChooseMissionaryTargetCity: %s %d, Turn %03d, %s", pUnit->getName().c_str(), pUnit->GetID(), GC.getGame().getElapsedGameTurns(), m_pPlayer->getCivilizationShortDescription()) );5348#pragma warning ( pop )53495350	// Loop through all the players5351	for(int iI = 0; iI < MAX_PLAYERS; iI++)5352	{5353		CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);5354		if(kPlayer.isAlive())5355		{5356			// Loop through each of their cities5357			int iLoop;5358			CvCity* pLoopCity;5359			for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))5360			{5361				if(pLoopCity && !pLoopCity->GetCityReligions()->IsDefendedAgainstSpread(eMyReligion))5362				{5363					int iScore = ScoreCityForMissionary(pLoopCity, pUnit);5364					if(iScore > iBestScore)5365					{5366						iBestScore = iScore;5367						pBestCity = pLoopCity;5368					}5369				}5370			}5371		}5372	}53735374	return pBestCity;5375}

Calls

Called by