Bazaar developer reference

CvReligionAI::DoFaithPurchases()

Defined in
CvReligionClasses.cpp, line 5796
Class
CvReligionAI
Hook name
CivHooks::CvReligionAI_DoFaithPurchases

Hooks

static bool BeforeCvReligionAI_DoFaithPurchases(CvReligionAI* self);static void AfterCvReligionAI_DoFaithPurchases(CvReligionAI* self);static void ReplaceCvReligionAI_DoFaithPurchases(void (*original)(CvReligionAI*), CvReligionAI* self);CivRegisterBefore<CivHooks::CvReligionAI_DoFaithPurchases>(host, &BeforeCvReligionAI_DoFaithPurchases);CivRegisterAfter<CivHooks::CvReligionAI_DoFaithPurchases>(host, &AfterCvReligionAI_DoFaithPurchases);CivRegisterReplace<CivHooks::CvReligionAI_DoFaithPurchases>(host, &ReplaceCvReligionAI_DoFaithPurchases);

Code

5795/// Spend faith if already have an enhanced religion5796void CvReligionAI::DoFaithPurchases()5797{5798	ReligionTypes eReligion = GetReligionToSpread();57995800	CvGameReligions* pReligions = GC.getGame().GetGameReligions();5801	const CvReligion* pMyReligion = pReligions->GetReligion(eReligion, m_pPlayer->GetID());5802	BuildingClassTypes eFaithBuilding = FaithBuildingAvailable(eReligion);5803	bool bTooManyMissionaries = m_pPlayer->GetNumUnitsWithUnitAI(UNITAI_MISSIONARY) > GC.getRELIGION_MAX_MISSIONARIES();58045805	CvString strLogMsg;5806	if(GC.getLogging())5807	{5808		strLogMsg = m_pPlayer->getCivilizationShortDescription();5809	}58105811	// Save for another prophet if haven't enhanced religion yet5812	if(pMyReligion == NULL || !pMyReligion->m_bEnhanced)5813	{5814		// Unless all religions gone and we didn't start one5815		if(pMyReligion == NULL && pReligions->GetNumReligionsStillToFound() <= 0)5816		{5817			// Fill our cities with any Faith buildings possible5818			if(!BuyAnyAvailableFaithBuilding())5819			{5820#if defined(MOD_CONFIG_GAME_IN_XML)5821				if(m_pPlayer->GetCurrentEra() >= GD_INT_GET(RELIGION_GP_FAITH_PURCHASE_ERA))5822#else5823				if(m_pPlayer->GetCurrentEra() >= GC.getInfoTypeForString("ERA_INDUSTRIAL"))5824#endif5825				{5826					UnitTypes eGPType = GetDesiredFaithGreatPerson();5827					if (eGPType != NO_UNIT)5828					{5829						BuyGreatPerson(eGPType);58305831						if(GC.getLogging())5832						{5833							strLogMsg += ", Saving for Great Person, ";5834							CvUnitEntry *pkEntry = GC.getUnitInfo(eGPType);5835							if (pkEntry)5836							{5837								strLogMsg += pkEntry->GetDescription();5838							}5839						}				5840					}5841				}5842			}5843		}5844	}5845	else5846	{5847		// Do we need a prophet pronto to reestablish our religion?5848#if defined(MOD_BUGFIX_UNITCLASS_NOT_UNIT)5849		UnitTypes eProphetType = m_pPlayer->GetSpecificUnitType("UNITCLASS_PROPHET", true);5850#else5851		UnitTypes eProphetType = (UnitTypes)GC.getInfoTypeForString("UNIT_PROPHET", true);5852#endif5853#if defined(MOD_GLOBAL_TRULY_FREE_GP)5854		if (eProphetType != NO_UNIT && ChooseProphetConversionCity(true/*bOnlyBetterThanEnhancingReligion*/) && m_pPlayer->GetReligions()->GetNumProphetsSpawned(false) <= 5)5855#else5856		if (eProphetType != NO_UNIT && ChooseProphetConversionCity(true/*bOnlyBetterThanEnhancingReligion*/) && m_pPlayer->GetReligions()->GetNumProphetsSpawned() <= 5)5857#endif5858		{5859			BuyGreatPerson(eProphetType);58605861			if(GC.getLogging())5862			{5863				strLogMsg += ", Saving for Prophet, ";5864				strLogMsg += GC.getUnitInfo(eProphetType)->GetDescription();5865			}				5866		}58675868		// Besides prophets, first priority is to convert all our non-puppet cities5869		else if(!bTooManyMissionaries && !AreAllOurCitiesConverted(eReligion, false /*bIncludePuppets*/))5870		{5871			BuyMissionary(eReligion);58725873			if(GC.getLogging())5874			{5875				strLogMsg += ", Saving for Missionary, Need to Convert Non-Puppet Cities";5876			}5877		}58785879		// Next priority is to establish our faith building in every non-puppet city5880		else if(eFaithBuilding != NO_BUILDINGCLASS && !AreAllOurCitiesHaveFaithBuilding(eReligion, false /*bIncludePuppets*/))5881		{5882			BuyFaithBuilding(eReligion, eFaithBuilding);58835884			if(GC.getLogging())5885			{5886				strLogMsg += ", Saving for Faith Building, For Our Non-Puppet Cities";5887			}5888		}58895890		// Try to build other buildings with Faith if we took that belief5891		else if (CanBuyNonFaithBuilding())5892		{5893			if (!BuyAnyAvailableNonFaithBuilding())5894			{5895				if(GC.getLogging())5896				{5897					strLogMsg += ", Saving for Science Building, Have Reformation Belief";5898				}5899			}5900		}59015902		// If in Industrial, see if we want to save for buying a great person5903#if defined(MOD_CONFIG_GAME_IN_XML)5904		else if (m_pPlayer->GetCurrentEra() >= GD_INT_GET(RELIGION_GP_FAITH_PURCHASE_ERA) && GetDesiredFaithGreatPerson() != NO_UNIT)5905#else5906		else if (m_pPlayer->GetCurrentEra() >= GC.getInfoTypeForString("ERA_INDUSTRIAL") && GetDesiredFaithGreatPerson() != NO_UNIT)5907#endif5908		{5909			UnitTypes eGPType = GetDesiredFaithGreatPerson();5910			BuyGreatPerson(eGPType);59115912			if(GC.getLogging())5913			{5914				strLogMsg += ", Saving for Great Person, ";5915				strLogMsg += GC.getUnitInfo(eGPType)->GetDescription();5916			}				5917		}59185919		// Might as well convert puppet-cities to build our religious strength5920		else if(!bTooManyMissionaries && eFaithBuilding != NO_BUILDINGCLASS && !AreAllOurCitiesHaveFaithBuilding(eReligion, true /*bIncludePuppets*/))5921		{5922			BuyMissionary(eReligion);59235924			if(GC.getLogging())5925			{5926				strLogMsg += ", Saving for Missionary, Need to Convert Puppet Cities";5927			}5928		}59295930		// Have civs nearby to target who didn't start a religion?5931		else if(!bTooManyMissionaries && HaveNearbyConversionTarget(eReligion, false /*bCanIncludeReligionStarter*/))5932		{5933			BuyMissionary(eReligion);59345935			if(GC.getLogging())5936			{5937				strLogMsg += ", Saving for Missionary, Need to Convert Cities of Non-Religion Starters";5938			}5939		}59405941		// Have cities Inquisitors can defend?5942		else if(!HaveEnoughInquisitors(eReligion))5943		{5944			BuyInquisitor(eReligion);59455946			if(GC.getLogging())5947			{5948				strLogMsg += ", Saving for Inquisitors, Need to Defend Our Cities";5949			}5950		}59515952		// Have civs nearby to target who did start a religion?5953		else if(!bTooManyMissionaries && HaveNearbyConversionTarget(eReligion, true /*bCanIncludeReligionStarter*/))5954		{5955			BuyMissionary(eReligion);59565957			if(GC.getLogging())5958			{5959				strLogMsg += ", Saving for Missionary, Need to Convert Cities of Religion Starters";5960			}5961		}59625963		// Any faith buildings from other religions we can buy?5964		else5965		{5966			BuyAnyAvailableFaithBuilding();5967		}59685969		if(GC.getLogging())5970		{5971			CvString strFaith;5972			strFaith.Format(", Faith: %d", m_pPlayer->GetFaith());5973			strLogMsg += strFaith;5974			GC.getGame().GetGameReligions()->LogReligionMessage(strLogMsg);5975		}5976	}5977}

Calls

Called by