Check for Global presence of Religion?

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
What I'd like to do sounds simple enough. Basically take this:
Code:
if pCity.isHolyCityByType(iReligionLoop):
		iHC = -50
And make it
Code:
if pCity.isHolyCityByType(iReligionLoop):
     if: #Check.RealNumbforiReligionGlobal > 1
          return -1
     else:
           iHC = -50

So how do I globally check if the Religion is present, is there a way to get the AI to count it's global presence, and return it as a real number?
 
Well, you could loop over all the players and call CyPlayer.getHasReligionCount(ReligionType eIndex) for each. If you want a global count of how many cities the religion is in, something like this should work:
Code:
def globalHasReligionCount(eReligion):
	iCount = 0
	for i in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(i)	
		iCount = iCount + pPlayer.getHasReligionCount(eReligion)
	return iCount

If you just wanted to know if a religion exists you could probably go with CyGame.isReligionFounded(ReligionType eIndex)
 
Something like this might work?
Code:
if pCity.isHolyCityByType(iReligionLoop):
     def globalHasReligionCount(eReligion):
          iCount = o
          for in range(gc.getMAX_PLAYERS()):
               pPlayer = gc.getPlayer(i)	
	       iCount = iCount + pPlayer.getHasReligionCount(eReligion)
	   if( iCount > 1 )
                return false
          else:
                iHC = -50

Where is it directing the computer to search for the specific religion type of the Holy City?
 
What I posted was in the form of a separate utility function. The eReligion parameter of that function is the religion type. In your code snippet, "iReligionLoop" is the index of the religion you are dealing with. Based on the name I was assuming that you are running some kind of loop over the religions. Is that not the case?

Anyhow, one way to combine them would be like this:
Code:
# earlier in the loop
iCount = 0
for i in range(gc.getMAX_PLAYERS()):
	pPlayer = gc.getPlayer(i)	
	iCount = iCount + pPlayer.getHasReligionCount(iReligionLoop)

# then later, where you check the city
if pCity.isHolyCityByType(iReligionLoop):
	if iCount > 1:
		return -1
	else:
		iHC = -50

Or, you could place the globalHasReligionCount function definition elsewhere in the module and then simply call it when necessary like so:
Code:
if pCity.isHolyCityByType(iReligionLoop):
	if globalHasReligionCount(iReligionLoop) > 1:
		return -1
	else:
		iHC = -50
Code:
def globalHasReligionCount(eReligion):
	iCount = 0
	for i in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(i)	
		iCount = iCount + pPlayer.getHasReligionCount(eReligion)
	return iCount
 
Thanks Dresden I've been sidetracked trying to figure out how to get the Rev Effects from the Revolutions mod to display, as all empire effects are hidden, and you only are shown the local ones. I haven't made much progress there, so I'll be picking this back up and see if I can get it to work.

I never liked the fact you could eliminate Holy Cities so easily using the Inquisitions mod component, and this looks like a good fix for it.
 
Top Bottom