Limited Religions

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
Limited Religions

Are you having trouble founding your own Holy City because one Civ has run through all of the religius techs. Well now you can limit each Civ to founding only one Holy City. This is the official release of Limited Religions for BTS 3.19.

Download: http://forums.civfanatics.com/downloads.php?do=file&id=14831

Features:

1. This is now a completely separate mod comp.

2. Has XML option in the GlobalDefinesAlt.xml file to turn Limited Religions on or off.

3. Limits each Civ to founding only one Religion/Holy City. More Holy Cities can be obtained through combat.

4. There are new python code functions to automatically identifying the state religious shrine and the respective missionary. This code also works for any new religions added to your mod, without the need to make any manual changes to the python code. This was a major improvement.

5. Has XML Option in the GlobalDefinesAlt.xml file to limit Missionary production to only state religion Missionaries. This requires the can train callback.

6. The download includes both WoC and standard formats.

7. When using WoC version, remember to swap out your Schema files with those from your mod.


Enjoy,


Orion Veteran :cool:
 
Hey, I stumble upon this mod comp when I am looking to find a limited religion mod to implement into the current mod I am working on. I am wondering if there's a way to change the limit, instead of only founding 1 religion per civ, say, limit to founding 2 religion per civ?

If I am reading the code right, the current check to limit 1 religion found per civ is this piece of if-clause:
if not LimitedReligions.OwnsHolyCity(iPlayer):

I am not familiar enough with the variables, so I am wondering what value actually returned by "LimitedReligions.OwnsHolyCity(iPlayer)"?

Thanks!
 
Nevermind my post. Right after I submit my previous post, I realized that it's part of the function you create in LimitedReligions.py. After I looked at that file, I think I may have found a way to do what I want.

Regardless, thanks for the mod comp!
 
I was playing a game to test this mod comp. However, it looks like the AI found religions as if the "Choose Religion" option has been checked, which in fact, it's not an option I checked (the first religion found was Islam, then Christianity, and Taoism).

Also, when I finished Oracle, I picked Theology, but I wasn't given any religion at all. I re-load the save game, and picked Code of Laws, the same thing happens, I wasn't given any religion at all.

I am attaching two auto-save games, 725BC, the turn before my Oracle finished, and 700BC, the turn right when my Oracle finished. Hopefully you can get a chance to take a lot.
 

Attachments

  • AutoSave.zip
    200.6 KB · Views: 125
I was playing a game to test this mod comp. However, it looks like the AI found religions as if the "Choose Religion" option has been checked, which in fact, it's not an option I checked (the first religion found was Islam, then Christianity, and Taoism).

Also, when I finished Oracle, I picked Theology, but I wasn't given any religion at all. I re-load the save game, and picked Code of Laws, the same thing happens, I wasn't given any religion at all.

I am attaching two auto-save games, 725BC, the turn before my Oracle finished, and 700BC, the turn right when my Oracle finished. Hopefully you can get a chance to take a lot.

I have a fix! Download the updated mod.

1. If you are using the Woc version all you need to do is replace the LimitedReligionsEvents.py file in your mod.
2. If you are using the standard version you need to remerge the onTechAcquired function located in the CvEventManager.py file.

That should do it.

Have Fun!
 
2. If you are using the standard version you need to remerge the onTechAcquired function located in the CvEventManager.py file.

If I understand this, you mean to remerge that from your updated mod to the one I downloaded? Why don't I just use the updated mod to play right away? Or, I misunderstand you?

Edit: Oh, I think I understand now. You've thought that I have merged this mod comp to the mod I am working on. I haven't though, simply on testing your mod out before I start doing anything.
 
If I understand this, you mean to remerge that from your updated mod to the one I downloaded? Why don't I just use the updated mod to play right away? Or, I misunderstand you?

Edit: Oh, I think I understand now. You've thought that I have merged this mod comp to the mod I am working on. I haven't though, simply on testing your mod out before I start doing anything.

Did the fix work for you?
 
I just found out that Gandhi just found Hindu while discovering Meditation. So, I don't think it's still right. I noticed the addition you did, which suppose to fix it. However, below that, the if-clause for whether to found new religion or not:
Code:
if FoundRel:
	# Get Civ's Favorite religion or random pick if favorite religion is not available.
	iNewReligion = LimitedReligions.AI_chooseReligion(iPlayer)
	if iNewReligion != -1:
		# Found the religion.
		#CyInterface().addImmediateMessage("Found Favorite Religion", "")
		pPlayer.foundReligion(iNewReligion, iSlot, True)

if I understand the piece of code correctly, the AI still have an option to choose the religion he prefer, rather than whatever the tech gives?

Edit: Just a thought, the if-clause
Code:
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
I believe should be under the if-clause FoundRel, but I am not sure how to code if choose religion is not part of game option...
 
I just found out that Gandhi just found Hindu while discovering Meditation. So, I don't think it's still right. I noticed the addition you did, which suppose to fix it. However, below that, the if-clause for whether to found new religion or not:
Code:
if FoundRel:
	# Get Civ's Favorite religion or random pick if favorite religion is not available.
	iNewReligion = LimitedReligions.AI_chooseReligion(iPlayer)
	if iNewReligion != -1:
		# Found the religion.
		#CyInterface().addImmediateMessage("Found Favorite Religion", "")
		pPlayer.foundReligion(iNewReligion, iSlot, True)

if I understand the piece of code correctly, the AI still have an option to choose the religion he prefer, rather than whatever the tech gives?

Edit: Just a thought, the if-clause
Code:
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
I believe should be under the if-clause FoundRel, but I am not sure how to code if choose religion is not part of game option...

Do you have this in the GlobalDefinesAlt.xml file?

Code:
<Define>
	<DefineName>OC_LIMITED_RELIGIONS</DefineName>
	<iDefineIntVal>1</iDefineIntVal>
</Define>
 
Yes, it's there. I never made a change to it, so it should be the default value.


OK Try this:

Code:
if FoundRel:
	if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
		# Get Civ's Favorite religion or random pick if favorite religion is not available.
		iNewReligion = LimitedReligions.AI_chooseReligion(iPlayer)
		if iNewReligion != -1:
			# Found the religion.
			#CyInterface().addImmediateMessage("Found Favorite Religion", "")
			pPlayer.foundReligion(iNewReligion, iSlot, True)
							
	else:
		for i in range(gc.getNumReligionInfos()):
			if gc.getReligionInfo(i).getTechPrereq() == iTechType:
				if not gc.getGame().isReligionFounded(i):
					# Found the religion.
					#CyInterface().addImmediateMessage("Found Prerequisit Religion", "")
					pPlayer.foundReligion(i,i,True)
 
OrionVeteran,

I've just merged limited religion mod comp into a mod I am working on. While testing, the strangest thing happens. When I (or AI) discover a tech that comes with religion, I will found that religion, AS WELL AS, asking me to choose another religion. This cause me ends up with 2 religions: the one given by the tech, and another one I chose. This doesn't happen when I play the game with only your mod comp present.

Since I want to allow a civ to be limited to founding 2 religions (instead of 1 rel per civ), I made some changes to the code. The only changes to limited religion mod comp I did was change "OwnHolyCity" to check for how many holy city a civ has in LimitedReligions.py:
Code:
def OwnsHolyCity(iPlayer):
	# Limited Religions
	#Checks to see if player has a Holy City (Any Holy City)
	#Returns True if player has a Holy City
	#Returns False if player does not have a Holy City
	pHolyCity = 0
	pPlayer = gc.getPlayer(iPlayer)
	
	for iCity in range(pPlayer.getNumCities()):
		pCity = pPlayer.getCity(iCity)
		
		for iRel in range(gc.getNumReligionInfos()):
			if pCity.isHasReligion(iRel):
				if pCity.isHolyCityByType(iRel):
					#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Holy City Found!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
					pHolyCity += 1
					break
	
	return pHolyCity

and then, in CvEventManager.py, from:
Code:
# Must not already have a Holy City
if not LimitedReligions.OwnsHolyCity(iPlayer) < 2:
to
Code:
# Must not already have a Holy City
if ( LimitedReligions.OwnsHolyCity(iPlayer) < 2 ):

I am wondering if you could help giving me some insight what I may have done wrong. Thank you so much!

Addit: I revert all changes to the original code, but it still does the same thing in the merged mod.
 
Since I want to allow a civ to be limited to founding 2 religions (instead of 1 rel per civ), I made some changes to the code.


Try This.

Code:
iHolyCityCount = 0
pHolyCity = False
pPlayer = gc.getPlayer(iPlayer)

for iRel in range(gc.getNumReligionInfos()):
	if pCity.isHasReligion(iRel):
		if pCity.isHolyCityByType(iRel):
			#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Holy City Found!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
			iHolyCityCount += 1
			if iHolyCityCount == 2:
				pHolyCity = True
				break
	
return pHolyCity
 
Actually, the mod comp works fine when it's run as a mod by itself. However, it only a problem when I merged it with the mod I am working on. Even with the original code (not the changes to make the 2 limit), it gives me the tech's religion and asks me choose another religion.

I am thinking that it may be possible the issue may or may not related to BUG mod, which I used as well. Do you know or aware of any possible issue that may be caused by BUG in this case?
 
Ok, so I've done several tests:
  • Game with only Limited Religion mod comp
    Everything works fine
  • Game with my mod + Limited Religion mod comp
    Everything works fine
  • Game with BUG mod + Limited Religion mod comp
    I got the religion of the tech I discovered, as well as being asked to choose for another religion, resulting in receiving 2 religions
  • Game with my mod + BUG mod + Limited Religion mod comp
    I got the religion of the tech I discovered, as well as being asked to choose for another religion, resulting in receiving 2 religions

So, I am definite that the issue only crop up when BUG is involved. I think we may be able to conclude that the issue is related to BUG. It may very wall has nothing to do with your mod so I understand if you don't know the causes, though, I wouldn't any suggestion of what to look for. I think I will check on the BUG's codes, and probably open a thread in BUG's forum.
 
Ok, so I've done several tests:
  • Game with only Limited Religion mod comp
    Everything works fine
  • Game with my mod + Limited Religion mod comp
    Everything works fine
  • Game with BUG mod + Limited Religion mod comp
    I got the religion of the tech I discovered, as well as being asked to choose for another religion, resulting in receiving 2 religions
  • Game with my mod + BUG mod + Limited Religion mod comp
    I got the religion of the tech I discovered, as well as being asked to choose for another religion, resulting in receiving 2 religions

So, I am definite that the issue only crop up when BUG is involved. I think we may be able to conclude that the issue is related to BUG. It may very wall has nothing to do with your mod so I understand if you don't know the causes, though, I wouldn't any suggestion of what to look for. I think I will check on the BUG's codes, and probably open a thread in BUG's forum.

I don't want to throw a monkey wrench into your test results, but, I run BUG with everything including Limited Religions. I never get 2 religions. I suspect there is a problem with the merge process. Merging mods is not always easy. You must work on merging one file at a time and be meticulous. Winmerge is an excellent tool, but sometimes you need to have a different viewpoint to insure accuracy.
 
well, as far as I can tell, there are only two files needed to be merged: CvEventManager.py and EntryPoints\CvScreenInterface.py. Am I correct? I uses Notepad++'s compare plugin to check the difference between your files and the originals so I can merge the difference.
 
well, as far as I can tell, there are only two files needed to be merged: CvEventManager.py and EntryPoints\CvScreenInterface.py. Am I correct? I uses Notepad++'s compare plugin to check the difference between your files and the originals so I can merge the difference.

You forgot the CvGameUtils.py file. Three of the most important functions are in that file: cannotTrain, doHolyCity and doHolyCityTech.
 
Top Bottom