Simple Python Edit Request

ArbitraryGuy

Rusty Shackleford?
Joined
Jul 11, 2003
Messages
1,076
I'm working on the next version of my European Empires Mod. I'm aiming for "history" here, and I was thinking I could greatly enhance it if only one religion were allowed in a city at a time. I'm not fully python functional, yet... so I need some assistance.

I need to do the following to implement this: upon religion spread to a city, whether by missionary or by chance, old religions (and their buildings) need to be removed (holy cities can't be converted, of course). I also need to decrease the success rate of missionary conversion. I'm thinking this should be pretty simple, but don't know where to start. Any help in the right direction would be greatly appreciated.

Thanks a bunch.

AG
 
Shouldn't be too hard. Take a peek in CvEventManager.py and look for the onReligionSpread() event handler. From there you should be able to find out which religions the spread-to city has and remove all but the one that triggered the spread. The thing about not allowing spreading to Holy Cities will be trickier -- I think you'll have to test if the city is a Holy City and if it is remove the reliigon that was just spread there. No idea about missionary success rates, maybe that's in the XML somewhere...
 
Unfortunatly, that file only contains the following

Code:
def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity = argsList
		player = PyPlayer(iOwner)
		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()))

		CvAdvisorUtils.cityAdvise(pCity, iPlayer)

It's just the handler for displaying the message about religion spread, not the function... do you know where the function is? Thanks.
 
ArbitraryGuy said:
Unfortunatly, that file only contains the following

Code:
def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity = argsList
		player = PyPlayer(iOwner)
		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()))

		CvAdvisorUtils.cityAdvise(pCity, iPlayer)

It's just the handler for displaying the message about religion spread, not the function... do you know where the function is? Thanks.

Ok, I did a search in the main Python file directories (python, python/EntryPoints, python/Screen), and I'm pretty sure the code you want to alter is in the C (or C++, anyone know which it is?) code.

So, basically, you would have to modify the Python at this point where eotinb highlights to get what you want.

That should be easy enough, but it IS rather klugish.

For example (in pseudocode):
Code:
def onReligionSpread(self, argsList):
		'Religion Has Spread to a City'
		iReligion, iOwner, pSpreadCity = argsList
		player = PyPlayer(iOwner)
		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()))

		CvAdvisorUtils.cityAdvise(pCity, iPlayer)

[B]            for (each religion type):
                        if (religion is not iReligion):
                                 set the city has religion (using CyCity.setHasReligion) to false[/B]

Oh, yeah, and all you would have to do is just create a subclass of CvEventManager, alter CvScreensInterface to call that class instead and just change that function, onReligionSpread.

Hope that helps.

Req
 
Requies said:
Oh, yeah, and all you would have to do is just create a subclass of CvEventManager, alter CvScreensInterface to call that class instead and just change that function, onReligionSpread.

Hope that helps.

Req

Thanks! Although, I have no idea how to program it at least I can fiddle around with it.
 
Req's subclass method is cleaner, but I think it is easier to just add the code right into CvEventManager.py. Either will work. His pseudocode is just what I was talking about. Take a look at the Python documentation for guidance with the language itself (available at python.org).
 
eotinb said:
Req's subclass method is cleaner, but I think it is easier to just add the code right into CvEventManager.py. Either will work. His pseudocode is just what I was talking about. Take a look at the Python documentation for guidance with the language itself (available at python.org).

What? All you need to do is just type

Code:
class NewClass (OldClass):
and then copy over the functions you want to change.

Heathen! :spank:

:D

Req
 
Well, maybe by "easier" I meant it is easier for me to leave my mods the way I already did them rather than redoing them with subclasses. :)
 
eotinb said:
Well, maybe by "easier" I meant it is easier for me to leave my mods the way I already did them rather than redoing them with subclasses. :)

Heh, I understand.

Though, actually, I was thinking of changing your mods so that they subclass instead. So, if I do it for you, would you object? :p

Req
 
Uh, no. Not at all. In fact I would be grateful. But perhaps we have gotten this thread off-topic enough. We can continue this discussion over PM, OK?
 
Top Bottom