remove bonus when feature is chopped

stefanhu

Chieftain
Joined
Jan 6, 2014
Messages
13
I need an advice for a python code which does the following changes:

A bonus ressource will be removed from a plot when the feature on this plot is chopped by workers.

(For example timber. It does not make sense to retain timber on a plot when the forest has been chopped.)

I have already tried to change the CvEventManager.py as follows:

Code:
    def onPlotFeatureRemoved(self, argsList):
        'Plot Revealed'
        pPlot = argsList[0]
        pCity = argsList[1]
        iFeatureType = argsList[2] # This can be null????
### Remove BONUS START
        if ( iFeatureType == gc.getInfoTypeForString("FEATURE_FOREST"):
            pPlot.setBonusType(-1)
### Remove BONUS END

It does not work! :(

Any suggestions?
 
Are you sure about the order in the argslist?
For me it's the other way around for iFeatureType and pCity:
Code:
def onPlotFeatureRemoved(self, argsList):
		'Plot Revealed'
		pPlot = argsList[0]
		iFeatureType = argsList[1]
		pCity = argsList[2] # This can be null
The pPlot.setBonusType(-1) definitely works (if pPlot is gc.getMap().plot(iX,iY), but I assume that's what it get's), I also use it in my mod

EDIT: yeah, checked in the dll
the argslist is: CvPlot *pPlot, FeatureTypes eFeature, CvCity* pCity
so just switch argsList[1] and argsList[2] in your code, and it will work
 
It still does not work :(

I am not adept at doing in python. Could you please show me the complete right working code? I will try again.

Btw: I have forgotten to set a second ")" at the end of FEATURE_FOREST, but that's not problem.

Thanks! :)
 
Turns out you were right
Didn't give enough attention, but the dll function does switch the argslist inside:
Code:
void CvDllPythonEvents::reportPlotFeatureRemoved([B]CvPlot *pPlot, FeatureTypes eFeature, CvCity* pCity[/B])
{
	if (preEvent())
	{
		CyArgsList eventData;
		eventData.add("plotFeatureRemoved");						// add key to lookup python handler fxn

		[B]CyPlot* pCyPlot = new CyPlot(pPlot);
		eventData.add(gDLL->getPythonIFace()->makePythonObject(pCyPlot));
		CyCity* pCyCity= new CyCity(pCity);
		eventData.add(gDLL->getPythonIFace()->makePythonObject(pCyCity));
		eventData.add((int)eFeature);[/B]

		postEvent(eventData);
		delete pCyPlot;
		delete pCyCity;
	}
}
The argslist is used in this order everywhere in the dll: CvPlot *pPlot, FeatureTypes eFeature, CvCity* pCity
But for some reason it gives those to python in a different one.

So the correct order in python is
pPlot, pCity, iFeatureType = argsList
Thus your code should look like this:
Code:
	def onPlotFeatureRemoved(self, argsList):
		'Plot Revealed'
		pPlot = argsList[0]
		iFeatureType = argsList[2]
		pCity = argsList[1] # This can be null
		if ( iFeatureType == gc.getInfoTypeForString("FEATURE_FOREST")):
			pPlot.setBonusType(-1)

Btw, this means we discovered a Firaxis mistake :cool:
Everyone should change the argslist if wants to use the onPlotFeatureRemoved function
 
This change (swap in the argsList) is in Platy's UI and other Python components which is probably were stefanhu took it in the first place.
 
This change (swap in the argsList) is in Platy's UI and other Python components which is probably were stefanhu took it in the first place.

Cool, the more of us know about these Firaxis issues the better :king:
 
Top Bottom