python function isn't called - why?

Saarlaender

Chieftain
Joined
Jan 14, 2006
Messages
60
Hi all,
I'm still working on getting my religion mod to gain more functions. Now, I am trying to get cities with multiple religions to convert themselves with one of them, and to make it possible that multiple religions spread to a city without a missionary. The funtions seem to not be called, though - I included messages if the function gets called and something happens, and also if nothing happens (to see if it works at all). Well, the funktions are supposed to be called at the beginning of each player turn:
Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList
		self.reform(iPlayer)
		self.convert(iPlayer)
		self.multiples(iPlayer)

now, I can't be certain yet about reform, but convert and multiples do not get called, at least they don't generate the messages they should:

Code:
	def convert(self, iPlayer):
		pPlayer = gc.getPlayer(iPlayer)
		iRefCityList = self.getCityList(pPlayer)
		szReligionList = [ ]
		for pCity in iRefCityList:
			iConvert = CyGame().getSorenRandNum(100, "Conversion")
			if (iConvert <= 10 and self.safeguard(pCity) >= 2):
				for i in range(gc.getNumReligionInfos()):
					if pCity.isHasReligion(i):
						szReligionList.append(i)

				if len(szReligionList) != 0:
						iTarget = szReligionList[CyRandom().get(len(szReligionList), "Get a random number for religion removal.")]
						pCity.setHasReligion(iTarget, False, True, True)
						CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Konversion!')
			else:
				CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'keine Konversion -')
		return

no message, neither "conversion" nor "no conversion" (Keine Konversion, in German.)

neither in the so far only rudimentary multiples function:
Code:
	def multiples(self, iPlayer):
		pPlayer = gc.getPlayer(iPlayer)
		iRefCityList = self.getCityList(pPlayer)
		for pCity in iRefCityList:
			iAdd = CyGame().getSorenRandNum(100, "Spread")
			if (pCity.isConnectedToCapital(iPlayer) and iAdd <=20):
				self.addreligion(pCity)
			else:
				CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'keine mr -')
		return
again, no messages whatsoever.
what am I messing up?
 
Do you have error logging on? If not turn it on. If yes what does it say? (the setting(s) are in civilization4.ini)
 
Saarlaender,

I am assuming that your onBeginPlayerTurn method is in a custom event handler correct? If that is so, did you also create a custom CvEventInterface class that replaces the normal event handler? If you need to see an example you download the great general amped or great doctor mods.
 
nope, all added into the event manager. I'm a complete newbie at these things, that doesn't work? I was told once to do that as that would make it safer that they're actually loaded and used, as compared to a custom event manager?
-downloaded the great doctor mod, looking at it now..
 
This part in the custom manager I don't understand at all. waht does it do?
Code:
class CvGDEventManager(CvEventManager.CvEventManager):
	def __init__(self):
		# initialize base class
		self.parent = CvEventManager.CvEventManager
		self.parent.__init__(self)
		self.pPlot_remembered = [-1,""]
 
If nothing happends and there's no error there are two options. Either it's not loaded at all or the code don't do what you expect it to, so you just don't notice that it does happend. I'm going to go with the second and I would assume this is your problem: self.getCityList(pPlayer)

Since you didn't include the getCityList function I don't know if that really is the problem, but I think what you want is the PyPlayer function and not some function in CvEventManager.
 
Code:
class CvGDEventManager(CvEventManager.CvEventManager):
[TAB]def __init__(self):
[TAB][TAB]# initialize base class
[TAB][TAB]self.parent = CvEventManager.CvEventManager
[TAB][TAB]self.parent.__init__(self)
[TAB][TAB]self.pPlot_remembered = [-1,""]

The __init__(self) method is automatically called when an instance of the CvGDEventManager is created.

The "self.parent = CvEventManager.CvEventManager" sets the instance of the CvGDEventManager's base class.

The "self.parent.__init__(self)" initializes the parent.

The "self.pPlot_remembered = [-1,""]" isn't really needed and I should have removed it from my code before distributing my code :D.

Anyways can I see a copy of your CvEventInterface.py file to see if your problem is there?
 
see, this is where it kicks me that in the end, I don't really know what I'm doing. I'm a sociologist, not a programmer.. :)
here's the getCityList from the CvEventmanager (meaning, in the same file):
Code:
	def getCityList(self, pPlayer):
		iPlayerID = pPlayer.getID()
		lCity = []
		(loopCity, iter) = pPlayer.firstCity(false)
		while(loopCity):
			cityOwner = loopCity.getOwner()
			if ( not loopCity.isNone() and loopCity.getOwner() == pPlayer ): #only valid cities
				pCity = pPlayer.getCity(loopCity.getID())
				city = PyCity(self.getID(), loopCity.getID())
				lCity.append(pCity)
			(loopCity, iter) = pPlayer.nextCity(iter, false)
		return lCity

if that's not what I want, then how do I get the PyPlaer function?
sorry for being such a klutz on this...
 
snarko said:
If nothing happends and there's no error there are two options. Either it's not loaded at all or the code don't do what you expect it to, so you just don't notice that it does happend. I'm going to go with the second and I would assume this is your problem: self.getCityList(pPlayer)

Since you didn't include the getCityList function I don't know if that really is the problem, but I think what you want is the PyPlayer function and not some function in CvEventManager.

Snarko, I would agree with you if we had a copy of the complete CvEventManager file, but I think his convert and multiples methods are in a separate file that could be importing the PyPlayer class. Then of course I could be completely mistaken and those methods are actually in his CvEventManager class. Saarlaender, care to shed some light on this mystery?
 
here it is. I haven't chenged anything here; the changes are from the SettlerReligion mod which I have included. Should I have added something?

(can't attach; board doesn't accept .py attachments.)
Code:
# Sid Meier's Civilization 4
# Copyright Firaxis Games 2005
#
# CvEventInterface.py
#
# These functions are App Entry Points from C++
# WARNING: These function names should not be changed
# WARNING: These functions can not be placed into a class
#
# No other modules should import this
#
import CvUtil
import CvCustomEventManager
from CvPythonExtensions import *

normalEventManager = CvCustomEventManager.CvCustomEventManager()

def getEventManager():
	return normalEventManager

def onEvent(argsList):
	'Called when a game event happens - return 1 if the event was consumed'
	return getEventManager().handleEvent(argsList)

def applyEvent(argsList):
	context, playerID, netUserData, popupReturn = argsList
	return getEventManager().applyEvent(argsList)

def beginEvent(context, argsList=-1):
	return getEventManager().beginEvent(context, argsList)
 
They're ALL in the CvEventManager. I had a separate file first until someone told me not to do that.
 
What is the name of your event manager class file? If it isn't CvCustomEventManager, then that tells me that you need to merge your event manager with the CvCustomEventManager so it includes your new code onBeginPlayerTurn, etc. methods
 
ok......
...what?
not sure i know what you're asking. There's only this one file in the EntryPoints folder; in the modded python folder, there's the extended vEventManager, a CvCustomEventManager, CustomFunctions (inherited from SettlerReligion and the inquisitor mod - I don't do anything with those), and Settlerreligion.py. Again, I don't use those. All my modding is in the CvEventManager. There, all my functions are under

class CvEventManager
(there is no other class in that file).

Now, I have no clue if I answered your question even remotely..
 
Saarlaender said:
ok......
...what?
not sure i know what you're asking. There's only this one file in the EntryPoints folder; in the modded python folder, there's the extended vEventManager, a CvCustomEventManager, CustomFunctions (inherited from SettlerReligion and the inquisitor mod - I don't do anything with those), and Settlerreligion.py. Again, I don't use those. All my modding is in the CvEventManager. There, all my functions are under

class CvEventManager
(there is no other class in that file).

Now, I have no clue if I answered your question even remotely..

Ah, well that explains to me exactly what is going on in your code. Basically, what you need to do is merge your code from your CvEventManager file into the CvCustomEventManager.py file. Otherwise the game will never call your onBeginPlayerTurn method. The other option is to change the line (in CvEventInterface.py):
normalEventManager = CvCustomEventManager.CvCustomEventManager()

to:
normalEventManager = CvEventManager.CvEventManager()

but then you will lose all the functionality added by the SettlerReligion mod.

I would be more than happy to merge everthing into the CvCustomEventManager.py file. I just need you to provide me with your CvEventManager.py file and the CvCustomEventManager.py.
 
Thank you. Please also tell me what you did, though, so I know how to do it myself next time (and so that I learn how all these things actually work, besides just wildly adding functions...)
 

Attachments

Saarlaender said:
Thank you. Please also tell me what you did, though, so I know how to do it myself next time (and so that I learn how all these things actually work, besides just wildly adding functions...)

I think I did everything correctly, though one of the things I noticed is that your event manager code seems to be from a different version of Civ4. What version of Civ4 are you running?

Anyways, I merged the CvCustomEventManger.py and CvEventManger.py files. The resulting file is much smaller since I only moved the modified parts of the CvEventManager.py file into the CvCustomEventManager.py file.

EDIT: let me know if you are running into issues and I'll try to help you.
 

Attachments

thank you. do I just delete what's been moved to custom from the general CvEventManager, including th entire onBeginPlayerTurn and onReligionSpread routine? Plus, you included def's I didn't touch, like handleEvent. do they need to go from the eventmanager too now that they're in the custon file?
 
Saarlaender said:
thank you. do I just delete what's been moved to custom from the general CvEventManager, including th entire onBeginPlayerTurn routine?

Before I answer your question, let me ask this ...

You aren't modifying the original files from the <Civ4 Install dir>\Assets\Python directory, are you?

Now to answer your question, if you are working on a copy of the CvEventManager.py file then you can just leave it as it is. It is not even being used by the game. Only the CvCustomEventManager.py file is being used by the game.

If you are modifying the original Civ4 files (ignore the following if you are not), then I would highly suggest that you read the following thread that explains how to setup the mod infrastructure:
http://forums.civfanatics.com/showthread.php?t=132476

and restore the original files.
 
nope, it's all in a mod folder and the original is untouched. :)
so I can basically just delete the EventManager in the mod folder?
 
Back
Top Bottom