Bazaar developer reference

CvReligionAI::ChooseProphetConversionCity(bool) const

Defined in
CvReligionClasses.cpp, line 5570
Class
CvReligionAI
Hook name
CivHooks::CvReligionAI_ChooseProphetConversionCity

Hooks

static bool BeforeCvReligionAI_ChooseProphetConversionCity(const CvReligionAI* self, bool bOnlyBetterThanEnhancingReligion, CvCity *& result);static void AfterCvReligionAI_ChooseProphetConversionCity(const CvReligionAI* self, bool bOnlyBetterThanEnhancingReligion, CvCity *& result);static CvCity * ReplaceCvReligionAI_ChooseProphetConversionCity(CvCity * (*original)(const CvReligionAI*, bool), const CvReligionAI* self, bool bOnlyBetterThanEnhancingReligion);CivRegisterBefore<CivHooks::CvReligionAI_ChooseProphetConversionCity>(host, &BeforeCvReligionAI_ChooseProphetConversionCity);CivRegisterAfter<CivHooks::CvReligionAI_ChooseProphetConversionCity>(host, &AfterCvReligionAI_ChooseProphetConversionCity);CivRegisterReplace<CivHooks::CvReligionAI_ChooseProphetConversionCity>(host, &ReplaceCvReligionAI_ChooseProphetConversionCity);

Code

5569/// If we were going to use a prophet to convert a city, which one would it be?5570CvCity *CvReligionAI::ChooseProphetConversionCity(bool bOnlyBetterThanEnhancingReligion) const5571{5572	CvCity *pBestCity = NULL;5573	CvCity *pHolyCity = NULL;5574	int iBestScore = 50;  // Not zero because we don't want prophets to ALWAYS pick something up55755576	// Make sure we're spreading a religion and find holy city5577	ReligionTypes eReligion = GetReligionToSpread();5578	if (eReligion <= RELIGION_PANTHEON)5579	{5580		return pBestCity;5581	}55825583	const CvReligion* pkReligion = GC.getGame().GetGameReligions()->GetReligion(eReligion, m_pPlayer->GetID());5584	if (pkReligion)5585	{5586		CvPlot* pkPlot = GC.getMap().plot(pkReligion->m_iHolyCityX, pkReligion->m_iHolyCityY);5587		if(pkPlot)5588		{5589			pHolyCity = pkPlot->getPlotCity();5590		}5591	}5592	if (!pHolyCity)5593	{5594		return pBestCity;5595	}55965597	// Look at our cities first, checking them for followers of other religions5598	int iLoop;5599	CvCity* pLoopCity;5600	for(pLoopCity = m_pPlayer->firstCity(&iLoop); pLoopCity != NULL; pLoopCity = m_pPlayer->nextCity(&iLoop))5601	{5602		ReligionTypes eMajorityReligion = pLoopCity->GetCityReligions()->GetReligiousMajority();5603		int iHeretics = pLoopCity->GetCityReligions()->GetFollowersOtherReligions(eReligion);5604		int iDistanceToHolyCity = plotDistance(pLoopCity->getX(), pLoopCity->getY(), pHolyCity->getX(), pHolyCity->getY());56055606		// If this is the holy city and it has been converted, want to go there no matter what5607		if (pLoopCity == pHolyCity && eMajorityReligion != eReligion)5608		{5609			return pHolyCity;5610		}56115612		// Otherwise score this city5613		int iScore = (iHeretics * 100) / (iDistanceToHolyCity + 1);5614		if (eMajorityReligion != eReligion && eMajorityReligion > RELIGION_PANTHEON)5615		{5616			iScore *= 3;5617		}56185619		// Don't give it any score if our religion hasn't been enhanced yet5620		else if (bOnlyBetterThanEnhancingReligion)5621		{5622			iScore = 0;5623		}56245625		if (iScore > iBestScore)5626		{5627			iBestScore = iScore;5628			pBestCity = pLoopCity;5629		}5630	}56315632	// Now try other players, assuming don't need to enhance religion5633	if (!bOnlyBetterThanEnhancingReligion)5634	{5635		for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)5636		{5637			CvPlayer &kLoopPlayer = GET_PLAYER((PlayerTypes)iPlayerLoop);5638			if(kLoopPlayer.isAlive() && iPlayerLoop != m_pPlayer->GetID())5639			{5640				int iCityLoop;5641				for(pLoopCity = GET_PLAYER((PlayerTypes)iPlayerLoop).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iPlayerLoop).nextCity(&iCityLoop))5642				{5643					if (!pLoopCity->GetCityReligions()->IsDefendedAgainstSpread(eReligion))5644					{5645						ReligionTypes eMajorityReligion = pLoopCity->GetCityReligions()->GetReligiousMajority();5646						int iHeretics = pLoopCity->GetCityReligions()->GetFollowersOtherReligions(eReligion);5647						int iDistanceToHolyCity = plotDistance(pLoopCity->getX(), pLoopCity->getY(), pHolyCity->getX(), pHolyCity->getY());56485649						// Score this city5650						int iScore = (iHeretics * 50) / (iDistanceToHolyCity + 1);56515652						//    - high score if this city has another religion as its majority5653						if (eMajorityReligion != eReligion)5654						{5655							iScore *= 3;5656						}56575658						//    - Holy city will anger folks, let's not do that one right away5659						ReligionTypes eCityOwnersReligion = GET_PLAYER((PlayerTypes)iPlayerLoop).GetReligions()->GetReligionCreatedByPlayer();5660						if (eCityOwnersReligion > RELIGION_PANTHEON && pLoopCity->GetCityReligions()->IsHolyCityForReligion(eCityOwnersReligion))5661						{5662							iScore /= 2;5663						}56645665						//    - City not owned by religion founder, won't anger folks as much5666						const CvReligion* pkMajorityReligion = GC.getGame().GetGameReligions()->GetReligion(eMajorityReligion, NO_PLAYER);5667						if (pkMajorityReligion && pkMajorityReligion->m_eFounder != pLoopCity->getOwner())5668						{5669							iScore *= 2;5670						}56715672						if (iScore > iBestScore)5673						{5674							iBestScore = iScore;5675							pBestCity = pLoopCity;5676						}5677					}5678				}5679			}5680		}5681	}56825683	return pBestCity;5684}

Calls

Called by