Merging 2 event managers

Shiggs713

Immortal
Joined
Mar 11, 2007
Messages
2,361
Location
Indianapolis
Hi all, I'm having some troubles merging these two files, and actually making it work. Its two event managers, one from the mongol camp mod, and another from a "barebones" north america mod, which has dynamic winter. Kevinman made it especially for the ACW mod, and I'd really like to keep both dynamic winter and the camp unit.

the two files in question are the eventmanagers for both "mods".
I've already merged the import calls but thats it.

here's WinterModEventManager.py, its the one I want to keep;
Code:
##-------------------------------------------------------------------
## Tests winter freeze global map change
##-------------------------------------------------------------------

from CvPythonExtensions import *
import CvUtil
import CvEventManager
import WinterMod
import IceMod
import MongolCamp

gc = CyGlobalContext()

class WinterEventManager(CvEventManager.CvEventManager):

	def __init__(self):
		CvEventManager.CvEventManager.__init__(self)
		
		self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")
		self.TERRAIN_PLAINS = gc.getInfoTypeForString("TERRAIN_PLAINS")
		self.TERRAIN_SNOW = gc.getInfoTypeForString("TERRAIN_SNOW")
		self.TERRAIN_TUNDRA = gc.getInfoTypeForString("TERRAIN_TUNDRA")
		self.TERRAIN_GRASSTHINSOIL = gc.getInfoTypeForString("TERRAIN_GRASSTHINSOIL")
		self.TERRAIN_PLAINSARID = gc.getInfoTypeForString("TERRAIN_PLAINSARID")
		self.TERRAIN_WASTELAND = gc.getInfoTypeForString("TERRAIN_WASTELAND")

	def onBeginGameTurn(self, argsList):
		CvEventManager.CvEventManager.onBeginGameTurn(self, argsList)
		iGameTurn = argsList[0]
		map = CyMap()
		for x in range(map.getGridWidth()):
			for y in range(map.getGridHeight()):
				plot = map.plot(x, y)
				IceMod.IceCover(plot)
				WinterMod.SnowCover(plot)
				WinterMod.SnowGraphics(plot)
				WinterMod.TreeGraphics(plot)

and here's the one I want to merge with winterModEventManager, its just regular old CvCustomEventManager.py;

Code:
from CvPythonExtensions import *
import CvUtil
import CvEventManager

## Below are Sub-Eventmanagers
import MongolCamp

gc = CyGlobalContext()
class CvCustomEventManager(CvEventManager.CvEventManager, object):

	CustomEvents = {}
		
	def __init__(self, *args, **kwargs):

		super(CvCustomEventManager, self).__init__(*args, **kwargs)
		# map the initial EventHandlerMap values into the new data structure
		for eventType, eventHandler in self.EventHandlerMap.iteritems():
			self.setEventHandler(eventType, eventHandler)
		
		# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
		MongolCamp.MongolCamp(self)

	def beginEvent( self, context, argsList=-1 ):
		"Begin Event"
		if(self.CustomEvents.has_key(context)):
			return self.CustomEvents[context][2](argsList)
		else:
			return CvEventManager.CvEventManager.beginEvent(self, context, argsList)
			
	def applyEvent( self, argsList ):
		'Apply the effects of an event '
		context, playerID, netUserData, popupReturn = argsList
		
		if(self.CustomEvents.has_key(context)):
			entry = self.CustomEvents[context]
			# the apply function
			return entry[1]( playerID, netUserData, popupReturn )   
		else:
			return CvEventManager.CvEventManager.applyEvent(self, argsList)


	def addCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def removeCustomEventDefinition(self, eventType):
		del self.CustomEvents[eventType]

	def setCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def addEventHandler(self, eventType, eventHandler):
		"""Adds a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.

		"""
		self.EventHandlerMap[eventType].append(eventHandler)

	def removeEventHandler(self, eventType, eventHandler):
		"""Removes a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  It is an error if 
		the given handler is not found in the list of installed handlers.

		"""
		self.EventHandlerMap[eventType].remove(eventHandler)
	
	def setEventHandler(self, eventType, eventHandler):
		"""Removes all previously installed event handlers for the given 
		event type and installs a new handler .
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  This method is 
		primarily useful for overriding, rather than extending, the default 
		event handler functionality.

		"""
		self.EventHandlerMap[eventType] = [eventHandler]

	def setPopupHandler(self, eventType, popupHandler):
		"""Removes all previously installed popup handlers for the given 
		event type and installs a new handler.

		The eventType should be an integer.  It must be unique with respect
		to the integers assigned to built in events.  The popupHandler should
		be a list made up of (name, beginFunction, applyFunction).  The name
		is used in debugging output.  The begin and apply functions are invoked
		by beginEvent and applyEvent, respectively, to manage a popup dialog
		in response to the event.

		"""
		self.Events[eventType] = popupHandler

	def handleEvent(self, argsList):
		"""Handles events by calling all installed handlers."""
		self.origArgsList = argsList
		flagsIndex = len(argsList) - 6
		self.bDbg, self.bMultiPlayer, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[flagsIndex:]		
		eventType = argsList[0]
		return {
			"kbdEvent": self._handleConsumableEvent,
			"mouseEvent": self._handleConsumableEvent,
			"OnSave": self._handleOnSaveEvent,
			"OnLoad": self._handleOnLoadEvent
		}.get(eventType, self._handleDefaultEvent)(eventType, argsList[1:])

	def _handleDefaultEvent(self, eventType, argsList):
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				eventHandler(argsList[:len(argsList) - 6])

	def _handleConsumableEvent(self, eventType, argsList):
		"""Handles events that can be consumed by the handlers, such as
		keyboard or mouse events.
		
		If a handler returns non-zero, processing is terminated, and no 
		subsequent handlers are invoked.

		"""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = eventHandler(argsList[:len(argsList) - 6])
				if (result > 0):
					return result
		return 0

	# TODO: this probably needs to be more complex
	def _handleOnSaveEvent(self, eventType, argsList):
		"""Handles OnSave events by concatenating the results obtained
		from each handler to form an overall consolidated save string.

		"""
		result = ""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = result + eventHandler(argsList[:len(argsList) - 6])
		return result

	# TODO: this probably needs to be more complex
	def _handleOnLoadEvent(self, eventType, argsList):
		"""Handles OnLoad events."""
		return self._handleDefaultEvent(eventType, argsList)

thanks anyone for your help,

Shiggs
 
In WinterModEventManager remove all traces of CvEventManager. Delete two lines:

Code:
[B][COLOR="Red"][s]import CvEventManager[/s][/COLOR][/B]

and

Code:
[B][COLOR="Red"][s]CvEventManager.CvEventManager.__init__(self)[/s][/COLOR][/B]

and the red part of this line:

Code:
class WinterEventManager([s][B][COLOR=Red]CvEventManager.CvEventManager[/COLOR][/B][/s]):

Change the __init__() declaration and insert one line like so:

Code:
def __init__(self, [COLOR=Red][B]eventManager[/B][/COLOR]):
    [COLOR=Red][B]eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)[/B][/COLOR]

Now in CvCustomEventManager import WinterModEventManager

Code:
import MongolCamp
[B][COLOR="Red"]import CvCustomEventManager[/COLOR][/B]

and add a line at the end if its __init__() function:

Code:
MongolCamp.MongolCamp(self)
[COLOR=Red][B]WinterModEventManager.WinterModEventManager(self)[/B][/COLOR]

You are hooking up WinterModEventManager in exactly the same way that MongolCamp is hooked up.
 
ok I did all that, and now neither of them work. Before these changes, only wintermod worked.
cvCustomEventManager.py
Code:
from CvPythonExtensions import *
import CvUtil
import CvEventManager
[COLOR="Blue"]import WinterModEventManager[/COLOR]

## Below are Sub-Eventmanagers
import MongolCamp

gc = CyGlobalContext()
class CvCustomEventManager(CvEventManager.CvEventManager, object):

	CustomEvents = {}
		
	def __init__(self, *args, **kwargs):

		super(CvCustomEventManager, self).__init__(*args, **kwargs)
		# map the initial EventHandlerMap values into the new data structure
		for eventType, eventHandler in self.EventHandlerMap.iteritems():
			self.setEventHandler(eventType, eventHandler)
		
		# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
		MongolCamp.MongolCamp(self)
		[COLOR="Blue"]WinterModEventManager.WinterModEventManager(self)[/COLOR]

	def beginEvent( self, context, argsList=-1 ):
		"Begin Event"
		if(self.CustomEvents.has_key(context)):
			return self.CustomEvents[context][2](argsList)
		else:
			return CvEventManager.CvEventManager.beginEvent(self, context, argsList)
			
	def applyEvent( self, argsList ):
		'Apply the effects of an event '
		context, playerID, netUserData, popupReturn = argsList
		
		if(self.CustomEvents.has_key(context)):
			entry = self.CustomEvents[context]
			# the apply function
			return entry[1]( playerID, netUserData, popupReturn )   
		else:
			return CvEventManager.CvEventManager.applyEvent(self, argsList)


	def addCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def removeCustomEventDefinition(self, eventType):
		del self.CustomEvents[eventType]

	def setCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def addEventHandler(self, eventType, eventHandler):
		"""Adds a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.

		"""
		self.EventHandlerMap[eventType].append(eventHandler)

	def removeEventHandler(self, eventType, eventHandler):
		"""Removes a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  It is an error if 
		the given handler is not found in the list of installed handlers.

		"""
		self.EventHandlerMap[eventType].remove(eventHandler)
	
	def setEventHandler(self, eventType, eventHandler):
		"""Removes all previously installed event handlers for the given 
		event type and installs a new handler .
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  This method is 
		primarily useful for overriding, rather than extending, the default 
		event handler functionality.

		"""
		self.EventHandlerMap[eventType] = [eventHandler]

	def setPopupHandler(self, eventType, popupHandler):
		"""Removes all previously installed popup handlers for the given 
		event type and installs a new handler.

		The eventType should be an integer.  It must be unique with respect
		to the integers assigned to built in events.  The popupHandler should
		be a list made up of (name, beginFunction, applyFunction).  The name
		is used in debugging output.  The begin and apply functions are invoked
		by beginEvent and applyEvent, respectively, to manage a popup dialog
		in response to the event.

		"""
		self.Events[eventType] = popupHandler

	def handleEvent(self, argsList):
		"""Handles events by calling all installed handlers."""
		self.origArgsList = argsList
		flagsIndex = len(argsList) - 6
		self.bDbg, self.bMultiPlayer, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[flagsIndex:]		
		eventType = argsList[0]
		return {
			"kbdEvent": self._handleConsumableEvent,
			"mouseEvent": self._handleConsumableEvent,
			"OnSave": self._handleOnSaveEvent,
			"OnLoad": self._handleOnLoadEvent
		}.get(eventType, self._handleDefaultEvent)(eventType, argsList[1:])

	def _handleDefaultEvent(self, eventType, argsList):
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				eventHandler(argsList[:len(argsList) - 6])

	def _handleConsumableEvent(self, eventType, argsList):
		"""Handles events that can be consumed by the handlers, such as
		keyboard or mouse events.
		
		If a handler returns non-zero, processing is terminated, and no 
		subsequent handlers are invoked.

		"""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = eventHandler(argsList[:len(argsList) - 6])
				if (result > 0):
					return result
		return 0

	# TODO: this probably needs to be more complex
	def _handleOnSaveEvent(self, eventType, argsList):
		"""Handles OnSave events by concatenating the results obtained
		from each handler to form an overall consolidated save string.

		"""
		result = ""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = result + eventHandler(argsList[:len(argsList) - 6])
		return result

	# TODO: this probably needs to be more complex
	def _handleOnLoadEvent(self, eventType, argsList):
		"""Handles OnLoad events."""
		return self._handleDefaultEvent(eventType, argsList)

wintermodEventManager
Code:
from CvPythonExtensions import *
import WinterMod
import IceMod

gc = CyGlobalContext()

class WinterEventManager():

[COLOR="Blue"]	def __init__(self, eventManager):
    eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)		[/COLOR]
		
		self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")
		self.TERRAIN_PLAINS = gc.getInfoTypeForString("TERRAIN_PLAINS")
		self.TERRAIN_SNOW = gc.getInfoTypeForString("TERRAIN_SNOW")
		self.TERRAIN_TUNDRA = gc.getInfoTypeForString("TERRAIN_TUNDRA")
		self.TERRAIN_GRASSTHINSOIL = gc.getInfoTypeForString("TERRAIN_GRASSTHINSOIL")
		self.TERRAIN_PLAINSARID = gc.getInfoTypeForString("TERRAIN_PLAINSARID")
		self.TERRAIN_WASTELAND = gc.getInfoTypeForString("TERRAIN_WASTELAND")

	def onBeginGameTurn(self, argsList):
		[COLOR="RoyalBlue"]CvEventManager.CvEventManager.onBeginGameTurn(self, argsList)[/COLOR]
		iGameTurn = argsList[0]
		map = CyMap()
		for x in range(map.getGridWidth()):
			for y in range(map.getGridHeight()):
				plot = map.plot(x, y)
				IceMod.IceCover(plot)
				WinterMod.SnowCover(plot)
				WinterMod.SnowGraphics(plot)
				WinterMod.TreeGraphics(plot)

I also changed to cvEventInterface to use the cvCustomEventManager intead of winterModEventManager, for the event manager. It might also be important to note the file structure that its using. The "Entry Points", and "Mongol Camp" folders both contain only code for the mongol camp.

And that winterMod.py and iceMod.py is the python that actually makes the winter move.

Also that last, "royal blue" line, i tried changing to

onBeginGameTurn(self, argsList)

but it still didn't work.

thanks,

Shiggs
 
...
wintermodEventManager
Code:
from CvPythonExtensions import *
import WinterMod
import IceMod

gc = CyGlobalContext()

class WinterEventManager():

	def __init__(self, eventManager):
[COLOR="Red"]    eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)[/COLOR]		
		
		self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")
		self.TERRAIN_PLAINS = gc.getInfoTypeForString("TERRAIN_PLAINS")
		self.TERRAIN_SNOW = gc.getInfoTypeForString("TERRAIN_SNOW")
		self.TERRAIN_TUNDRA = gc.getInfoTypeForString("TERRAIN_TUNDRA")
		self.TERRAIN_GRASSTHINSOIL = gc.getInfoTypeForString("TERRAIN_GRASSTHINSOIL")
		self.TERRAIN_PLAINSARID = gc.getInfoTypeForString("TERRAIN_PLAINSARID")
		self.TERRAIN_WASTELAND = gc.getInfoTypeForString("TERRAIN_WASTELAND")

	def onBeginGameTurn(self, argsList):
		CvEventManager.CvEventManager.onBeginGameTurn(self, argsList)
		iGameTurn = argsList[0]
		map = CyMap()
		for x in range(map.getGridWidth()):
			for y in range(map.getGridHeight()):
				plot = map.plot(x, y)
				IceMod.IceCover(plot)
				WinterMod.SnowCover(plot)
				WinterMod.SnowGraphics(plot)
				WinterMod.TreeGraphics(plot)
...

That line in red seems to have spaces instead of tabs. I'm fairly sure you shouldn't combine spaces and tabs in python.
 
ok, I tab over now. I just copied and pasted what Emperor Fool wrote. get back to you momentarily.

so now it looks like this;

Code:
...
	def __init__(self, eventManager):
		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)		
		
		self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")
		self.TERRAIN_PLAINS = gc.getInfoTypeForString("TERRAIN_PLAINS")
...

still doesn't work. :confused:

edit:

maybe this will be easier if someone would be so kind.

those are both original python folders.
 
WinterMod no longer extends CvEventManager, so remove this line that you added:

Code:
CvEventManager.CvEventManager.onBeginGameTurn(self, argsList)

Please post the contents of Logs/PythonErr.log. If it doesn't exist or is empty, see the logging instructions on this page.
 
hhhm that site appears to be down atm. I removed that and neither work still. I turned on python exceptions and got a whole host of errors and couldn't even launch perhaps unless i hit enter many times.

the first python exception is "Traceback (most recent call last):"
then "File "<string>", line1, in ?"

I'll try to check back and see if that site is up again soon.

well even though that site doesn't work atm, I think I figured out how to post my python error log maybe;

Code:
sys.path = ['..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\email', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\encodings', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\build', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\py', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\tools', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\colourchooser', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\editor', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\floatcanvas', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\masked', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\mixins', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\lib\\ogl', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\af', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ca', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\cs', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\da', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\de', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\el', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\es', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\eu', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\fi', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\fr', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\hi', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\hu', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\id', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\it', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ja', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\lv', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\nb', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\nl', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\pl', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\pt_BR', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ru', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\sl', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\sv', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\tr', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\uk', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\zh_CN', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\zh_TW', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\af\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ca\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\cs\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\da\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\de\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\el\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\es\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\eu\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\fi\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\fr\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\hi\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\hu\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\id\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\it\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ja\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\lv\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\nb\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\nl\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\pl\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\pt_BR\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\ru\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\sl\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\sv\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\tr\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\uk\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\zh_CN\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\locale\\zh_TW\\LC_MESSAGES', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\py\\tests', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\tools\\XRCed', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM\\wx\\tools\\XRCed\\src-images', '..\\WARLORDS\\ASSETS\\PYTHON\\SYSTEM']

sys.modules = {'zipimport': <module 'zipimport' (built-in)>, 'signal': <module 'signal' (built-in)>, '__builtin__': <module '__builtin__' (built-in)>, 'sys': <module 'sys' (built-in)>, '__main__': <module '__main__' (built-in)>, 'exceptions': <module 'exceptions' (built-in)>, 'CvPythonExtensions': <module 'CvPythonExtensions' (built-in)>}

sys.builtin_module_names = ('CvPythonExtensions', '__builtin__', '__main__', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_csv', '_heapq', '_hotshot', '_locale', '_multibytecodec', '_random', '_sre', '_subprocess', '_symtable', '_weakref', '_winreg', 'array', 'audioop', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'collections', 'datetime', 'errno', 'exceptions', 'gc', 'imageop', 'imp', 'itertools', 'marshal', 'math', 'md5', 'mmap', 'msvcrt', 'nt', 'operator', 'parser', 'regex', 'rgbimg', 'sha', 'signal', 'strop', 'struct', 'sys', 'thread', 'time', 'xxsubtype', 'zipimport')
load_module CvEventInterface
load_module WinterModEventManager
load_module CvEventManager
load_module CvUtil
load_module traceback
load_module CvScreensInterface
load_module CvMainInterface
load_module ScreenInput
load_module CvScreenEnums
load_module time
load_module CvDomesticAdvisor
load_module CvTechChooser
load_module CvForeignAdvisor
load_module math
load_module CvExoticForeignAdvisor
load_module IconGrid
load_module DomPyHelpers
load_module PyHelpers
load_module TechTree
load_module re
load_module CvMilitaryAdvisor
load_module CvFinanceAdvisor
load_module CvReligionScreen
load_module CvCorporationScreen
load_module CvCivicsScreen
load_module string
load_module CvVictoryScreen
load_module CvEspionageAdvisor
load_module CvOptionsScreen
load_module CvReplayScreen
load_module CvHallOfFameScreen
load_module CvDanQuayle
load_module CvGameUtils
load_module CvUnVictoryScreen
load_module CvDawnOfMan
load_module CvTechSplashScreen
load_module CvTopCivs
load_module random
load_module CvInfoScreen
load_module CvIntroMovieScreen
load_module CvVictoryMovieScreen
load_module CvWonderMovieScreen
load_module CvEraMovieScreen
load_module CvSpaceShipScreen
load_module CvPediaMain
load_module CvPediaScreen
load_module CvScreen
load_module CvPediaTech
load_module CvPediaUnit
load_module CvPediaBuilding
load_module CvPediaPromotion
load_module CvPediaUnitChart
load_module CvPediaBonus
load_module CvPediaTerrain
load_module CvPediaFeature
load_module CvPediaImprovement
load_module CvPediaCivic
load_module CvPediaCivilization
load_module CvPediaLeader
load_module CvPediaSpecialist
load_module CvPediaHistory
load_module CvPediaProject
load_module CvPediaReligion
load_module CvPediaCorporation
load_module CvWorldBuilderScreen
load_module Popup
load_module CvWorldBuilderDiplomacyScreen
load_module CvDebugTools
load_module CvDebugInfoScreen
load_module CvMapGeneratorUtil
load_module CvGFCScreen
load_module CvPopupInterface
load_module CvScreenUtilsInterface
load_module CvScreenUtils
init-ing world builder screen
load_module CvWBPopups
load_module CvCameraControls
load_module CvAdvisorUtils
load_module WinterMod
load_module cPickle
load_module Consts
load_module IceMod
PY:OnInit
load_module CvAppInterface
 
Bah, the link was broken (two http://'s) but I fixed it. Turn off Python exceptions and turn on the logging system, then post PythonErr.log--no 2 in the name.
 
Code:
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "<string>", line 52, in load_module
  File "CvEventInterface", line 2, in ?
  File "<string>", line 35, in load_module
  File "<string>", line 13, in _get_code
  File "
WinterModEventManager
", line 
11

    
class WinterEventManager():
 
you meant the one in wintermod right so its like this:

Code:
from CvPythonExtensions import *
import WinterMod
import IceMod

gc = CyGlobalContext()

class WinterEventManager:

	def __init__(self, eventManager):
		eventManager.addEventHandler("BeginGameTurn", self.onBeginGameTurn)		
		
		self.TERRAIN_GRASS = gc.getInfoTypeForString("TERRAIN_GRASS")\
...

still got many problems it appears. If thats what you meant:
Code:
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "<string>", line 52, in load_module
  File "CvEventInterface", line 6, in ?
NameError
: 
name 'CvCustomEventManager' is not defined

Failed to load python module CvEventInterface.
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface

god hates me
 
I'm starting to think you can't actually do it that way, they must be integrated, I think, because wintermod, icemod ect. ect. all call upon the cvEventInterface, so at minimum, (once again, I think) the wintermodeventmanager must be the actual event manager, not some import of the actual one.
 
I'm starting to think you can't actually do it that way, they must be integrated, I think, because wintermod, icemod ect. ect. all call upon the cvEventInterface, so at minimum, (once again, I think) the wintermodeventmanager must be the actual event manager, not some import of the actual one.

"Don't throw away your 'knife' yet." I think that it can be done, but you just need to wait for EmperorFool or someone else to answer. Problems aren't solved in one day, so be patient. I would help, but this is way beyond my skills. :)
 
yea, I'm not giving up. Its just frustrating, this is a very simple problem. I've written entire programs from scratch before, stuff way more complicated than this.

I'm actually 1 class away from having an associates in computer programming. I've of course never studied python... Mostly visual basic and a small amount of java.

Those two languages are so much better than python its not even funny.
 
Writing small standalone programs is easy, compared to what you are doing here. You are integrating small changes into a big software system which is difficult to understand. There are things I don't like about python, and I don't want to start a language war, but python has a much better structure than visual basic.
 
yea i know there are positives and negatives for every language. Maybe the structure is better, but you won't find as powerful of an IDE for python as you will for vb. Its just so much easier to use and understand.
 
You need to import CvCustomEventManager in CvEventInterface.py. You got a NameError which means the module mentioned hasn't seen the name in the error. Google How to Think Like a Computer Scientist; it's a great tutorial on Python. I have the link at home if you can't find it. It's a free online book.

What you're trying to do is absolutely possible; you just gotta do it just right. :)
 
this is my cvEventInterface;
Code:
from CvPythonExtensions import *
import CvCustomEventManager

eventManager = CvCustomEventManager.CvCustomEventManager()

def getEventManager():
	return eventManager

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)

it was already like that. Originally it was importing, and making the winterEventManager, the event manager, but I changed it a few days ago.

edit:

Interesting book. I read the Preface, looks good. I bookmarked it. ;)
 
Which line of what you posted is line 6? Can you also post your up-to-date CvCustomEventManager.py module?
 
this one is line 6;
Code:
def getEventManager():

and here's the CvCustomEventManager in its entirety;
Code:
## Copyright (c) 2005-2006, Gillmer J. Derge.

## This file is part of Civilization IV Unit Allegiance Mod
##
## Civilization IV Unit Allegiance Mod is free software; you can redistribute
## it and/or modify it under the terms of the GNU General Public
## License as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.
##
## Civilization IV Unit Allegiance Mod is distributed in the hope that it will
## be useful, but WITHOUT ANY WARRANTY; without even the implied
## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Civilization IV Unit Allegiance Mod; if not, write to the Free
## Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA
	

from CvPythonExtensions import *
import CvUtil
import CvEventManager

## Below are Sub-Eventmanagers
import MongolCamp
import WinterModEventManager

gc = CyGlobalContext()
class CvCustomEventManager(CvEventManager.CvEventManager, object):

	CustomEvents = {}
		
	def __init__(self, *args, **kwargs):

		super(CvCustomEventManager, self).__init__(*args, **kwargs)
		# map the initial EventHandlerMap values into the new data structure
		for eventType, eventHandler in self.EventHandlerMap.iteritems():
			self.setEventHandler(eventType, eventHandler)
		
		# --> INSERT EVENT HANDLER INITIALIZATION HERE <--
		MongolCamp.MongolCamp(self)
		WinterModEventManager.WinterModEventManager(self)

	def beginEvent( self, context, argsList=-1 ):
		"Begin Event"
		if(self.CustomEvents.has_key(context)):
			return self.CustomEvents[context][2](argsList)
		else:
			return CvEventManager.CvEventManager.beginEvent(self, context, argsList)
			
	def applyEvent( self, argsList ):
		'Apply the effects of an event '
		context, playerID, netUserData, popupReturn = argsList
		
		if(self.CustomEvents.has_key(context)):
			entry = self.CustomEvents[context]
			# the apply function
			return entry[1]( playerID, netUserData, popupReturn )   
		else:
			return CvEventManager.CvEventManager.applyEvent(self, argsList)


	def addCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def removeCustomEventDefinition(self, eventType):
		del self.CustomEvents[eventType]

	def setCustomEventDefinition(self, eventType, eventDefinition):
		self.CustomEvents[eventType] = eventDefinition

	def addEventHandler(self, eventType, eventHandler):
		"""Adds a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.

		"""
		self.EventHandlerMap[eventType].append(eventHandler)

	def removeEventHandler(self, eventType, eventHandler):
		"""Removes a handler for the given event type.
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  It is an error if 
		the given handler is not found in the list of installed handlers.

		"""
		self.EventHandlerMap[eventType].remove(eventHandler)
	
	def setEventHandler(self, eventType, eventHandler):
		"""Removes all previously installed event handlers for the given 
		event type and installs a new handler .
		
		A list of supported event types can be found in the initialization 
		of EventHandlerMap in the CvEventManager class.  This method is 
		primarily useful for overriding, rather than extending, the default 
		event handler functionality.

		"""
		self.EventHandlerMap[eventType] = [eventHandler]

	def setPopupHandler(self, eventType, popupHandler):
		"""Removes all previously installed popup handlers for the given 
		event type and installs a new handler.

		The eventType should be an integer.  It must be unique with respect
		to the integers assigned to built in events.  The popupHandler should
		be a list made up of (name, beginFunction, applyFunction).  The name
		is used in debugging output.  The begin and apply functions are invoked
		by beginEvent and applyEvent, respectively, to manage a popup dialog
		in response to the event.

		"""
		self.Events[eventType] = popupHandler

	def handleEvent(self, argsList):
		"""Handles events by calling all installed handlers."""
		self.origArgsList = argsList
		flagsIndex = len(argsList) - 6
		self.bDbg, self.bMultiPlayer, self.bAlt, self.bCtrl, self.bShift, self.bAllowCheats = argsList[flagsIndex:]		
		eventType = argsList[0]
		return {
			"kbdEvent": self._handleConsumableEvent,
			"mouseEvent": self._handleConsumableEvent,
			"OnSave": self._handleOnSaveEvent,
			"OnLoad": self._handleOnLoadEvent
		}.get(eventType, self._handleDefaultEvent)(eventType, argsList[1:])

	def _handleDefaultEvent(self, eventType, argsList):
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				eventHandler(argsList[:len(argsList) - 6])

	def _handleConsumableEvent(self, eventType, argsList):
		"""Handles events that can be consumed by the handlers, such as
		keyboard or mouse events.
		
		If a handler returns non-zero, processing is terminated, and no 
		subsequent handlers are invoked.

		"""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = eventHandler(argsList[:len(argsList) - 6])
				if (result > 0):
					return result
		return 0

	# TODO: this probably needs to be more complex
	def _handleOnSaveEvent(self, eventType, argsList):
		"""Handles OnSave events by concatenating the results obtained
		from each handler to form an overall consolidated save string.

		"""
		result = ""
		if self.EventHandlerMap.has_key(eventType):
			for eventHandler in self.EventHandlerMap[eventType]:
				# the last 6 arguments are for internal use by handleEvent
				result = result + eventHandler(argsList[:len(argsList) - 6])
		return result

	# TODO: this probably needs to be more complex
	def _handleOnLoadEvent(self, eventType, argsList):
		"""Handles OnLoad events."""
		return self._handleDefaultEvent(eventType, argsList)

thanks for all the help EmperorFool, you'll be in ACW's credits shortly
 
Back
Top Bottom