Sorry to bring the conversation here down a notch. I am trying to implement my custom coding the "right" way using this component (you'll be horrified at what I was doing before

) but I now find myself in a maze of twisty passages all alike.
I am doing my best to learn from other mods that utilize this framework, e.g. Civ4Alerts and Great Statesman, but they are all a tad too complicated for me to deconstruct. Partly I'm not a great OOP thinker, and partly I'm still getting my head around Python syntax, and partly I'm trying to learn the hierarchy of Civ Python classes/functions/etc.
What is the
minimum that I need to do to get this component to "work"? To the best of my knowledge, it is:
1) Put D.E.G.'s CvCustomEventManager.py file in the root Python directory.
2) Assuming my custom .py file will be called TestMod, change the CvCustomEventManager.py code to read:
Code:
import CvEventManager
import TestMod
Code:
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 <--
TestMod.TestMod(self)
3) Create TestMod.py . This file can be created and put
anywhere under the root Python directory, yes, and "import TestMod" will know where to find it? For example, I see that CvGreatStatesmanEventManager.py is in a subdirectory called "GreatStatesman."
4) Now what must TestMod.py import in order to function properly? It seems funny to me that TestMod must now import CvEventManager again, but that seems to be the case across all the mods I've seen. Presumably you also need to import all functions called by this package?
Now that I've asked my general question, here is one specific example which I hope you can help me with to understand how to do more like it. This is the exact code that I inserted straight into CvEventManager (not even CvCustomEventManager -- yes, I know, do not pass Go, do not collect $200!):
Code:
def onImprovementBuilt(self, argsList):
'Improvement Built'
iImprovement, iX, iY = argsList
#################### BEGIN CUSTOM TERRAFORM ##################
# Moves terrain "up" one level (relies on terrain being sequential)
# Replaces the fake terraform improvement with a real improvement
pPlot = CyMap().plot(iX,iY)
iTerraform = gc.getInfoTypeForString('IMPROVEMENT_TERRAFORM1')
iHothouse = gc.getInfoTypeForString('IMPROVEMENT_HOTHOUSE')
iFTerran = gc.getInfoTypeForString('FEATURE_TERRAN1')
if (iImprovement==iHothouse):
pPlot.setFeatureType(iFTerran, -1)
elif (iImprovement==iTerraform):
iOldTerrain = CyMap().plot(iX, iY).getTerrainType()
pPlot.setTerrainType(iOldTerrain+1, 1, 1)
pPlot.setImprovementType(iHothouse)
pPlot.setFeatureType(-1, -1)
#################### END TERRAFORM ##################
if (not self.__LOG_IMPROVEMENT):
return
CvUtil.pyPrint('Improvement %s was built at %d, %d'
%(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
OK, so how would I refactor this the "right" way?
Thanks for all of your efforts to make Civ Modding a safe and healthy environment for everyone
