Python Help: Striping Extra Food After Growth

fitchn

Civ Fanatic
Joined
Jun 27, 2003
Messages
332
Location
Delaware (USA)
Here's the deal: I've created a new wonder for my mod that stores 100% of city growth (using the same mechanisms as the granary) so that a city will grow one pop per turn until it reaches capacity. The problem is, with the extra food spillover, the city continues to grow, even though it is starving, until the food shortage exceeds the food spillover, which results in the city then loosing the extra pop points until it is back to a maintainable level.

What I need to do is write a python script that will cap the food surplus after the city has grown (ie, I still want to keep the overflow, I just don't want the overflow to exceed the growth amount).

Obviously I want to use the onCityGrowth event handler, but I don't even know where to begin as far as finding out what variables are available to me. The psuedo code would look something like this:

Code:
When the city grows {
    If (Food Storage Amount > Growth Threshold Amount) {
        Food Storage Amount = Growth Threshold Amount
    }
}

Any help would be greatly appreciated!
 
Code:
if pCity.getFood() > pCity.growthThreshold():
[tab]pCity.changeFood(- (pCity.getFood() - pCity.growthThreshold()))

I assume that works.
 
I'll give it a shot...

Thanks!
 
It worked Beautifully! I had to modify the code slightly to put it one under the threshold, since city growth occurs at the threshold and not over. Should anyone else need it, the final function is as follows:

Code:
	def onCityGrowth(self, argsList):
		'City Population Growth'
		pCity = argsList[0]
		iPlayer = argsList[1]
		CvUtil.pyPrint("%s has grown" %(pCity.getName(),))
		if pCity.getFood() >= pCity.growthThreshold():
		     pCity.changeFood(- (pCity.getFood() - pCity.growthThreshold() + 1))

Snarko: How did you find the names and parameters for these functions? I searched all of the python files and came up with very little (in the non-compiled files, anyway)

Thanks again, Snarko!
 
fitchn said:
Snarko: How did you find the names and parameters for these functions? I searched all of the python files and came up with very little (in the non-compiled files, anyway)
While I'm not Snarko - the functions are listed in the API, of which there are 2 versions. Here and here.
 
The Great Apple said:
While I'm not Snarko - the functions are listed in the API, of which there are 2 versions. Here and here.

Perfect! Thanks!
 
Back
Top Bottom