Spread religion by conquering cities

Shandalar

Chieftain
Joined
Mar 22, 2011
Messages
15
Hi all,

I want to modify BTS so that when a civilisation running Theocracy conquers a city, all religions already present in that city* get removed, and the religion of the conquering civilisation is automatically spread to that city.

Could anyone please advise me on how to make this modification?

Many thanks!

*if possible, I would like all buildings associated with that religion removed too.
 
In my mod I have a wonder, King Richard's Crusade, which does the exact same thing you are describing. So I am sure it is possible, unfortunately I am not the person who coded it. I am sure there is a wonder out there like this, so the code is readily available and I don't think altering it to work with a civic should be too difficult.
 
I have all the bits in various places, I can put something together for you as soon as I have access to my code.
 
Okay, I've rewritten my code because it makes a couple of assumptions that won't hold in a normal BtS mod, but here it is:

Spoiler :
Code:
	def onCityAcquiredAndKept(self, argsList):
		'City Acquired and Kept'
		iOwner,pCity = argsList
		CvUtil.pyPrint('City Acquired and Kept Event: %s' %(pCity.getName()))

		iTheocracy = gc.getInfoTypeForString("CIVIC_THEOCRACY")
		iCivicoptionReligion = gc.getInfoTypeForString("CIVICOPTION_RELIGION")

		iTemple = gc.getInfoTypeForString("BUILDING_JEWISH_TEMPLE")
		iMonastery = gc.getInfoTypeForString("BUILDING_JEWISH_MONASTERY")
		iCathedral = gc.getInfoTypeForString("BUILDING_JEWISH_CATHEDRAL")

		iNumReligions = 7

		pPlayer = gc.getPlayer(iOwner)
		iStateReligion = pPlayer.getStateReligion()

		# if player runs theocracy and has a state religion, spread his religion and remove all others, including buildings
		if pPlayer.getCivics(iCivicoptionReligion) == iTheocracy and iStateReligion >= 0:
			for iReligion in range(iNumReligions):
				if iReligion == iStateReligion: continue

				if pCity.isHasReligion(iReligion) and not pCity.isHolyCityByType(iReligion):
					pCity.setHasReligion(iReligion, False, False, False)
				if pCity.hasBuilding(iTemple + iReligion*4):
					pCity.setHasRealBuilding(iTemple + iReligion*4, False)
				if pCity.hasBuilding(iCathedral + iReligion*4):
					pCity.setHasRealBuilding(iCathedral + iReligion*4, False)
				if pCity.hasBuilding(iMonastery + iReligion*4):
					pCity.setHasRealBuilding(iMonastery + iReligion*4, False)

			if not pCity.isHasReligion(iStateReligion):
				pCity.setHasReligion(iStateReligion, True, True, False)
I'm making the following assumptions:
- the Jewish religious buildings are the first in the building XML and all other religious buildings come right after them in groups of four (temple, monastery, cathedral, shrine)
- there are seven religions (otherwise change the iNumReligions variable)

Just overwrite your onCityAcquiredAndKept() method in CvEventManager.py with this (keep your own changes if there are any of course). I've modified your requirements a bit so the ability only triggers when you have Theocracy AND a state religion, and protected holy cities from being removed by this.

I haven't tested it, if anything is wrong, just write me again. A PM has the highest chance of being noticed :)
 
1) isCivics(iTheocracy) alone will do
2) setNumRealBuilding not setHasRealBuilding
3) The if statements are all redundant except for the holy city check

Hardcoded python is generally more efficient but not suitable for python newbies, because everytime they make changes in XML, the python is screwed as well.

For instance, rather than iNumReligions = 7, gc.getNumReligionInfos() will serve the purpose better, so that whether the modder adds/removes religions, he would not have to edit the python, which he obviously don't have much experience.

Of course, the general way will be to loop through all buildings and remove all religious buildings that do not belong to the state religion, to ignore whatever changes are made in the XML such as
1) Not 7 religions
2) Judaism is not even one of the religions
3) Different religious buildings other than the original types
 
Sweeet, thanks Leoreth! I'll give it a try and see what happens.

Platyping, I'll give your suggestions a try when I understand more about what I'm doing. :)
 
Hi, so Leoreth very helpfully created some code to make this work.

Here it is in case anyone else wants to use it. Just find the onCityAcquiredAndKept() section of CvEventManager.py and replace it with this:

Code:
def onCityAcquiredAndKept(self, argsList):
		'City Acquired and Kept'
		iOwner,pCity = argsList
		CvUtil.pyPrint('City Acquired and Kept Event: %s' %(pCity.getName()))

		iTheocracy = gc.getInfoTypeForString("CIVIC_THEOCRACY")
		iCivicoptionReligion = gc.getInfoTypeForString("CIVICOPTION_RELIGION")

		iTemple = gc.getInfoTypeForString("BUILDING_JEWISH_TEMPLE")
		iMonastery = gc.getInfoTypeForString("BUILDING_JEWISH_MONASTERY")
		iCathedral = gc.getInfoTypeForString("BUILDING_JEWISH_CATHEDRAL")

		iNumReligions = 7

		pPlayer = gc.getPlayer(iOwner)
		iStateReligion = pPlayer.getStateReligion()

		# if player runs theocracy and has a state religion, spread his religion and remove all others, including buildings
		if pPlayer.getCivics(iCivicoptionReligion) == iTheocracy and iStateReligion >= 0:
			for iReligion in range(iNumReligions):
				if iReligion == iStateReligion: continue

				if pCity.isHasReligion(iReligion) and not pCity.isHolyCityByType(iReligion):
					pCity.setHasReligion(iReligion, False, False, False)
				if pCity.getNumBuilding(iTemple + iReligion*4):
					pCity.setNumRealBuilding(iTemple + iReligion*4, 0) > 0
				if pCity.getNumBuilding(iCathedral + iReligion*4):
					pCity.setNumRealBuilding(iCathedral + iReligion*4, 0) > 0
				if pCity.getNumBuilding(iMonastery + iReligion*4):
					pCity.setNumRealBuilding(iMonastery + iReligion*4, 0) > 0

			if not pCity.isHasReligion(iStateReligion):
				pCity.setHasReligion(iStateReligion, True, True, False)

Just to summarise, when a civiliation running theocracy conquers a city, this code (should) removes all religions present in that city, spreads the conquering civilisation's religion to the city, and also removes any buildings which are associated with the removed religions (an exception is when a holy city is conquered - neither the shrine, nor its religion will be removed in this case).

In addition to the above, I also reduced the hammer costs of missionaries and altered the spread factors of each of the religions, to slightly reduce those of the very early religions and greatly increase those of the later religions.

The purpose of these adjustments is to increase the impact that the later religions (Taoism, Christianity and Islam) can have on the game. I always found that they were a bit irrelevant. Hopefully these adjustments provide a simple way to spread religions in the mid-late game, which the AI will also use.
 
Top Bottom