[Python] CvCustomEventManager help

Joined
Sep 15, 2006
Messages
511
I'm trying to figure out the python set up for Civ4 and the custom syntax. I'll looked through Jeckel's Fort ZOC modcomp and NavalEnhansment modcomp. And am trying to duplicate his structure.

I modified the first part of the CvCustomEventManager like below
Spoiler :
import Popup as PyPopup
import CvEventManager
import CvJZoCEventManager
import ClassicThunderEventManager

class CvCustomEventManager(CvEventManager.CvEventManager, object):

"""Extends the standard event manager by adding support for multiple
handlers for each event.

Methods exist for both adding and removing event handlers. A set method
also exists to override the default handlers. Clients should not depend
on event handlers being called in a particular order.

This approach works best with mods that have implemented the design
pattern suggested on Apolyton by dsplaisted.

http://apolyton.net/forums/showthread.php?threadid=142916

The example given in the 8th post in the thread would be handled by adding
the following lines to the CvCustomEventManager constructor. The RealFort,
TechConquest, and CulturalDecay classes can remain unmodified.

self.addEventHandler("unitMove", rf.onUnitMove)
self.addEventHandler("improvementBuilt", rf.onImprovementBuilt)
self.addEventHandler("techAcquired", rf.onTechAcquired)
self.addEventHandler("cityAcquired", tc.onCityAcquired)
self.addEventHandler("EndGameTurn", cd.onEndGameTurn)

Note that the naming conventions for the event type strings vary from event
to event. Some use initial capitalization, some do not; some eliminate the
"on..." prefix used in the event handler function name, some do not. Look
at the unmodified CvEventManager.py source code to determine the correct
name for a particular event.

Take care with event handlers that also extend CvEventManager. Since
this event manager handles invocation of the base class handler function,
additional handlers should not also call the base class function themselves.

"""

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 <--

# --------- Revolution mod -------------
CvJZoCEventManager.CvJZoCEventManager(self)

# --------- Seige mod -------------
ClassicThunderEventManager.ClassicThunderEventManager(self)


Created a folser named ClassicThunderSeigeMod and created this cript in it, ClassicThunderEventManager. The problem is that nothing happens although from what I can tell everytime a play builds a city all his units should die.
Spoiler :
## Seige Mod by ClassicThunder

from CvPythonExtensions import *
import CvUtil
import CvConfigParser
import CvPath
import CvScreensInterface
import CvDebugTools
import CvWBPopups
import PyHelpers
import Popup as PyPopup
import CvCameraControls
import CvTopCivs
import CvWorldBuilderScreen
import CvAdvisorUtils
import CvTechChooser
##ClassicThunder's Custom Utilities
##import ClassicThunderUtilities

gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo

def loadConfigurationData():
pass

class ClassicThunderEventManager:
def __init__(self, eventManager):
# initialize base class
eventManager.addEventHandler("unitMove", self.onUnitMove)
eventManager.addEventHandler("cityBuilt", self.onCityBuilt)
eventManager.addEventHandler("cityRazed", self.onCityRazed)

def onUnitMove(self, argsList):
#ClassicThunderUtilities.alert(iPlayer, "A unit has been moved.")

def onCityBuilt(self, argsList):
city, iPlayer = argsList
iPlayer.killUnits()

def onCityRazed(self, argsList):
#city, iPlayer = argsList
#ClassicThunderUtilities.alert(iPlayer, "A city has been razed.")




Thanks in advance for any help and thanks to Jeckel for the Modcomps!

ClassicThunder
 
You need to change the following line in Python\EntryPoints\CvEventInterface.py

Code:
normalEventManager = CvEventManager.CvEventManager()

to

Code:
normalEventManager = ClassicThunderEventManager.ClassicThunderEventManager()

You should also include an import statement at the top to import ClassicThunderEventManager
 
each mod has one event manager... so you change that in your mod's python\entrypoint folder. (take a look at an existing mod, such as DesertWar or AmericanRevolution to see how they do it)

Basically, the event manager contains the python that is automatically called from the CvGameCoreDLL, and is one of the steps in the bridge between the game and the python script.

Game -> DLL -> Cy* C++ classes -> Python

By writing a class based off of the EventManager class, the DLL is sure that its interface with python is intact. However, if you want to override any of the default handling (to call your own code, instead) you need to override the event manager. Changing that line is what redirects the DLL from the default CvEventManager to your own custom one
 
Back
Top Bottom