python randomization - what's wrong here?

Saarlaender

Chieftain
Joined
Jan 14, 2006
Messages
60
Hi everyone,

'm working on a religion mod. Already incorporated Protestantism and ancient polytheism, all works fine. Now I was trying to script it so that when a religion is spread to a city where there is already a religion, there is a chance that the people will not be added, but convert - so that the "original" religion disappears on cpnversion. Well, it doesn't seem to work.
2 possibilities:
1) on religion spread doesn't cover missionaries at all?
2) randon function horribly wrong?
3)= I can#t just put it there and it needs to be somewhere completely different?
-2 and 3 both because I don't really know what I'm doing, mainly I'm just playing with the Inquisitor mod's and Kael's scripts without actually knowing the first thing about python....

so here it goes, I hope some gracious soul will spot my mistake and hit me on the head like they shoud for what is certainly a mountain of blatant violations :)

Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005

from CvPythonExtensions import *
import CvUtil
import CvEventManager
import sys
import CustomFunctions
import CvScreensInterface
import CvDebugTools
import CvWBPopups
import PyHelpers
import Popup as PyPopup
import CvCameraControls
import CvTopCivs
import CvWorldBuilderScreen
import CvAdvisorUtils
import CvTechChooser
	
gc = CyGlobalContext()
cf = CustomFunctions.CustomFunctions()

# globals
###################################################
class CvCustomEventManager(CvEventManager.CvEventManager):
	def __init__(self):
		# initialize base class
		self.parent = CvEventManager.CvEventManager
		self.parent.__init__(self)

	def onBuildingBuilt(self, argsList):
		'Building Completed'
		pCity, iBuildingType = argsList
		game = CyGame()
		if ((not self.bMultiPlayer) and (pCity.getOwner() == CyGame().getActivePlayer()) and isWorldWonderClass(gc.getBuildingInfo(iBuildingType).getBuildingClassType())):
			# If this is a wonder...
			popupInfo = CyPopupInfo()
			popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
			popupInfo.setData1(iBuildingType)
			popupInfo.setData2(pCity.getID())
			popupInfo.setData3(0)
			popupInfo.setText(u"showWonderMovie")
			popupInfo.addPopup(pCity.getOwner())

                Inquisition = gc.getInfoTypeForString('BUILDING_INQUISITION')
    		if iBuildingType == Inquisition:
                    cf.Inquisit(pCity)
                    pCity.setHasRealBuilding(Inquisition, False)

	def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity, iCatholic, iProtestant, iJewish, iHindu, iPolytheism, iIslam = argsList
		iCatholic = gc.getInfoTypeForString('RELIGION_CHRISTIANITY')
		iProtestant = gc.getInfoTypeForString('RELIGION_PROTESTANTISM')
		iJewish = gc.getInfoTypeForString('RELIGION_JUDAISM')
		iHindu = gc.getInfoTypeForString('RELIGION_HINDUISM')
		iPolytheism = gc.getInfoTypeForString('RELIGION_POLYTHEISM')
		iIslam = gc.getInfoTypeForString('RELIGION_ISLAM')
		rand = CyGame().getSorenRandNum(100, "Bob")		

		player = PyPlayer(iOwner)
		pPlayer = gc.getPlayer(iOwner)
		if iReligion == iCatholic:
			if (rand <= 40):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 20):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken haben den Propheten Mohammed erkannt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)


		if iReligion == iProtestant:
			if (rand <= 20):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind in den Schoß der Kirche zurückgekehrt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

	
		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zur Heiligen Kirche konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iProtestantism) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden haben Jesus als ihren persönlichen Erlöser erkannt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 40):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 60):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)


		if iReligion == iIslam:
			if (rand <= 25):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zur Heiligen Kirche konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 25):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iPolytheism) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime haben die Opfer für Zeus wiederaufgenommen!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Katholizismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
 
Firstly, if you don't already have them on, switch on Civ 4's debugging tools. In the Civ 4 main .ini file set these variables to the following values:
Code:
HidePythonExceptions = 0
ShowPythonDebugMsgs = 1
LoggingEnabled = 1
MessageLog = 1
This should make the game throw up an error if there is something wrong with the way the code is formed. Very useful!

Secondly, I can only see one thing that is a bit dodgy at first glance.
Code:
iReligion, iOwner, pSpreadCity, iCatholic, iProtestant, iJewish, iHindu, iPolytheism, iIslam = argsList
should read:
Code:
iReligion, iOwner, pSpreadCity = argsList
I'm not sure what adding those extra things would do, but it isn't neccessary, and it may be where your code is tripping up. In the events manager I would always use the defaults for argsList - I have never had the need to do anything else.

Thirdly, I love the way that I still see "CyGame().getSorenRandNum(100, "Bob")" coming up time and time again. I'm pretty certain that "Bob" comes from some example code I posted about a month ago...


EDIT: It would also seem your code is doing the wrong thing:
Code:
		if iReligion == iCatholic:
			if (rand <= 40):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
translates into English as:

If the religion to be spread is Catholic
If the random number is less than or equal to 40
If the city has protestantism in it, and isn't the catholic holy city
Set it so that the city does is not Catholic (thereby counteracting the spread)
Make a message

From your first post it would seem that you don't want to set it so the city isn't Catholic, but so the city isn't Protestant, yes?
 
ah, that's yours.. yep, I copied it from someone that was not you. But thanks. Actually, I added the extra argslist later after I saw this not working.
So - the rand here should work? I basically threw my code right after the inquicition mod's code without doing anything else (since I have no clue.) But alas, it doen't work. Does onSpreadReligion even cover religions spread by missionary?
 
Yeah, onReligionSpread's beginning is definitely odd.

Python lets you pass around tuples, and Civ makes extensive use of that. So all the event handlers expect tuples, and unpack their arguments from them first thing.

onReligionSpread is being passed something like [0, 0, <rome>], when Judaism spreads into player 0's city rome. You're extracting the first three things, but then that long line tells the computer you expected half a dozen OTHER parameters which aren't there. Nothing good will come of that.
 
Saarlaender said:
ah, that's yours.. yep, I copied it from someone that was not you. But thanks. Actually, I added the extra argslist later after I saw this not working.
So - the rand here should work? I basically threw my code right after the inquicition mod's code without doing anything else (since I have no clue.) But alas, it doen't work. Does onSpreadReligion even cover religions spread by missionary?

It definitly covers missionaries. It also kicks when you take over a city (even when your not adding a religion) and when you raze a city (not sure why, but it does).

And all of my SorenRand's have "Bob" in them because I copied the origional code line from TGA.

And the code all looks good, exceot the arglist line, as TGA pointed out.
 
so there's the off chance, then, that nothing happened because the rands always came out leaving the religion there?
 
Saarlaender said:
so there's the off chance, then, that nothing happened because the rands always came out leaving the religion there?

Doubtful, did you change the arglist line? This is my religionspread:

Code:
	def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity = argsList
		iOrder = gc.getInfoTypeForString('RELIGION_THE_ORDER')
		iVeil = gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')
		player = PyPlayer(iOwner)
		pPlayer = gc.getPlayer(iOwner)
		if iReligion == iVeil:
			if (pSpreadCity.isHasReligion(iOrder) and pSpreadCity.isHolyCityByType(iVeil) == False):
				pSpreadCity.setHasReligion(iReligion, False, False, False)
				CyInterface().addMessage(iOwner,True,25,'The Ashen Veil was removed from a city.','AS2D_ORDER_DINK',1,'Art/Interface/Buttons/Religions/Order.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iOrder:
			if (pSpreadCity.isHasReligion(iVeil) and pSpreadCity.isHolyCityByType(iOrder) == False):
				pSpreadCity.setHasReligion(iReligion, False, False, False)
				CyInterface().addMessage(iOwner,True,25,'The Order was removed from a city.','AS2D_ASHEN_DINK',1,'Art/Interface/Buttons/Religions/Ashen.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
			if (pPlayer.getStateReligion() == iOrder and pSpreadCity.isHasReligion(iVeil) == False and pSpreadCity.getOccupationTimer() <= 0):
				iRnd = CyGame().getSorenRandNum(100, "Bob")
				if (iRnd <= 75):
					eTeam = gc.getTeam(pPlayer.getTeam())
					if eTeam.isHasTech(gc.getInfoTypeForString('TECH_FANATICISM')):
						iUnit = gc.getInfoTypeForString('UNIT_CRUSADER')
						CyInterface().addMessage(iOwner,True,25,'A Crusader has joined your cause.','AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Units/Crusader.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
					else:
						iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ORDER')
						CyInterface().addMessage(iOwner,True,25,'A Disciple has joined your cause.','AS2D_UNIT_BUILD_UNIT',1,'Art/Interface/Buttons/Units/Discipleorder.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
					newUnit = pPlayer.initUnit(iUnit, pSpreadCity.getX(), pSpreadCity.getY(), UnitAITypes.NO_UNITAI)

		if (not self.__LOG_RELIGIONSPREAD):
			return
		CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
			%(gc.getReligionInfo(iReligion).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))
 
yes, changed the arglist. But that wasn't the matter.

I'm sure you recognized that my code IS yours - you gave me this code last week on here, I merely adapted it to my religions.

-response to edit: yes, it shouldn't counter the spread, it should remove what's there. I'll go over that again. Thank you!
 
If that function is in another place that the CvEventManager.py then it is possible that its just not reading the changed function. I had that problem when I tried to use a custom CvEventManager.py and I ended up just trashing it is changing the real file.
 
it's in a custom event manager - but with the inquisitor code which works.

Inquisitor mod which originally "made" the file, i just added to it - could it be that it doen't connect to anything? does it have to be called somewhere else? That could be the problem if it had to...
 
Saarlaender said:
it's in a custom event manager - but with the inquisitor code which works.

Inquisitor mod which originally "made" the file, i just added to it - could it be that it doen't connect to anything? does it have to be called somewhere else? That could be the problem if it had to...

Try putting it in the real CvEventManager.py and see if it works.
 
Saarlaender said:
just drop it in? in which class block?

In place of the existing onReligionSpread
 
no. not doing it. founded three religions, sent missionaries all around - got more and more in the same city, none got replaced.
I placed the entire onReligionSpread code in the events file (after i copied it into the mod folder, so i now have a cvEventManager in my Mods's python folder). I kept the original message tag in and overwrote the rest, like this:

Code:
def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity = argsList
		iCatholic = gc.getInfoTypeForString('RELIGION_CHRISTIANITY')
		iProtestant = gc.getInfoTypeForString('RELIGION_PROTESTANTISM')
		iJewish = gc.getInfoTypeForString('RELIGION_JUDAISM')
		iHindu = gc.getInfoTypeForString('RELIGION_HINDUISM')
		iPolytheism = gc.getInfoTypeForString('RELIGION_POLYTHEISM')
		iIslam = gc.getInfoTypeForString('RELIGION_ISLAM')
		rand = CyGame().getSorenRandNum(100, "Bob")		

		player = PyPlayer(iOwner)
		pPlayer = gc.getPlayer(iOwner)
		if iReligion == iCatholic:
			if (rand <= 40):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 20):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken haben den Propheten Mohammed erkannt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iHinduism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iCatholic:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)


		if iReligion == iProtestant:
			if (rand <= 20):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iHinduism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind in den Scho&#223; der Kirche zur&#252;ckgekehrt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iProtestant:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Protestanten sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Polytheism.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

	
		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zur Heiligen Kirche konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 80):
				if (pSpreadCity.isHasReligion(iProtestantism) and pSpreadCity.isHolyCityByType(iProtestantism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden haben Jesus als ihren pers&#246;nlichen Erl&#246;ser erkannt!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 40):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iHinduism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iPolytheism:
			if (rand <= 60):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Heiden sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)


		if iReligion == iIslam:
			if (rand <= 25):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zur Heiligen Kirche konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 25):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 15):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iHinduism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iPolytheism) and pSpreadCity.isHolyCityByType(iPolytheism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime haben die Opfer f&#252;r Zeus wiederaufgenommen!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iIslam:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iJewish) and pSpreadCity.isHolyCityByType(iJewish) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Muslime sind zum Judentum konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iIslam) and pSpreadCity.isHolyCityByType(iIslam) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Islam konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iCatholic) and pSpreadCity.isHolyCityByType(iCatholic) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Katholizismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 30):
				if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iProtestant) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)

		if iReligion == iJewish:
			if (rand <= 10):
				if (pSpreadCity.isHasReligion(iHinduism) and pSpreadCity.isHolyCityByType(iHinduism) == False):
					pSpreadCity.setHasReligion(iReligion, False, False, False)
					CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Juden sind zum Hinduismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
		
		CvUtil.pyPrint('%s has spread to Player %d Civilization %s city of %s'
			%(gc.getReligionInfo(iReligion).getDescription(), iOwner, player.getCivilizationName(), pSpreadCity.getName()))

an observation:
shouldn't the line in each if clause that now reads:
pSpreadCity.setHasReligion(iReligion, False, False, False)

have "iReligion" replaced by "i(whatever is found there)", as is queried in the first line? doesn't this code remove the spreading religion, not ther one found, as iReligion is the one that spreads?
-still, it has no effect; it should be the spread that doesn't work iof this were so, but that also blows, I just pile up more religions in the city as this compiles now..
 
I just noticed that the religion you are removing from the city is iReligion (ie: the one that is spreading). From your first post it sounded like you want it to remove the religion that already existed. If you wanted to do that you should have it read:

Code:
if iReligion == iCatholic:
	if (rand <= 40):
		if (pSpreadCity.isHasReligion(iProtestant) and pSpreadCity.isHolyCityByType(iProtestant) == False):
			pSpreadCity.setHasReligion([B]iProtestant[/B], False, False, False)
			CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Die Katholiken sind zum Protestantismus konvertiert!','AS2D_RELIGION_CONVERT',1,'Art/Interface/Buttons/Religions/Catholic.dds',ColorTypes(8),pSpreadCity.getX(),pSpreadCity.getY(),True,True)
 
yep, noticed and fixed. Still, in my trial run, it should have ot spread the religion, then (or spread and removed it, but it also didn't do that, either. It just spread normall,y like it always does, completely ignoring any code i wrote.. could it be the cache?
 
Saarlaender said:
yep, noticed and fixed. Still, in my trial run, it should have ot spread the religion, then (or spread and removed it, but it also didn't do that, either. It just spread normall,y like it always does, completely ignoring any code i wrote.. could it be the cache?

Yeah, it sounds like it's not kicking. Definitly try clearing cache.
 
Have you got debugging enabled, as I suggested?

If so, you could add a few print lines which will tell you the states of the variables, and to confirm that the event is firing.

Something like:
Code:
print("XXX -- onReligionSpread triggered")
immediatly after the the trigger, and then maybe something to print the random number to make sure that that is working properly. The logs should be being made in the logs directory.
 
strange. it is kicking, but not working. (another strange thing: even after clearing the cache, it keeps screaming about undefined taoist units that I took out in BuildingINfos - which no loonger contains this tag.)
anyhow:
Debugging got me some errors i now fixed, but should these really halt the whole routine?

When Polytheism was discovered by another civ, I got no notification, instead, I got an exception call saying:
cvEventInterface (not modded): error in onEvent.
cvEventManager (modded): error in handleEvent (not modded).
cvEventManager : error in religionSpread (modded)
global name: iProtestantism is not defined.

- that's on me. it is iProtestant in my script and I called it ism later.

Then, when Victoria converted to chistianity (which I had founded), same error, same tags, just this time: global name iHinduism is not defined.
- again on me: I defined iHindu. not ism.

but still; the religions in question were not the ones involved in the spread process. does this make the whole routine not work? the ones I needed in my trial (iJewish and iCatholic) were right. Still, no loss of religion at conversion. Just kept piling up.
 
ok. I'm an idiot. How do I print the random number?
print (rand) - nope, error call.
CvUtil.pyPrint(rand) - nope.
CvUtil.pyPrint('rand is %')
%(rand) - not either.
stumbling in the dark...
 
Back
Top Bottom