Using calculateCulturePercent

Spocko

Warlord
Joined
Dec 18, 2005
Messages
170
Location
Kittery, Maine
I'm trying to build a mod called "executive briefing" whereby I announce various useful pieces of information about your civ, such as a city is unhappy, city is about to grow, etc. Similar to Dr. Jiggle's Civ4lerts Mod.

I'm trying to set up a warning for whenever one of my civ's cities falls below 70% of my own culture - that is, my civ is Germany, and whenever a city has less than 70% Germans in it, I want to know about it.

So, at http://www.sthurlow.com/cvDocs/cvDoc/CyCity.htm I find that CyCity has several methods that relate to culture, one of them being calculateCulturePercent(...)

I want to read this value and write an "if" statement similar to the following statement (one of six or seven I've already cobbled together successfully) invoked by CvEventManager's onCityDoTurn:

Code:
# Give a periodic status report on which cities are unhappy, but only every other three turns
if ((iturn % 3) == 0):
	if (city.angryPopulation(0) > 0):
		CyInterface().addMessage(CyGame().getActivePlayer(),True,10,'The people of %s are angry!' %(city.getName()),'',1,'Art/Interface/Population Heads/angrycitizen.dds',ColorTypes(7),city.getX(),city.getY(),True,True)

My ability to edit Python is limited to seeing how others manipulate a variable, and then cut and paste to taste- but I cannot find any code that illustrates how to use calculateCulturePercent, except the following code in CvMainInterface (by which it displays the nationality culture bar in the lower left corner of the city screen):

Code:
for h in range( gc.getMAX_CIV_PLAYERS() ):
	if ( gc.getPlayer(h).isAlive() ):
		fPercent = pHeadSelectedCity.plot().calculateCulturePercent(h)
		fPercent = fPercent / 100.0
		if ( fPercent != 0 ):

This example seems to be just what I want, but I don't know how to feed the method "h" - onCityDoTurn already knows what city it is working with, because so many of the methods listed for CyCity are invoked with the "city." prefix.

So, it seemed obvious to try "X = city.calculateCulturePercent()" ... but Py complained that it wasn't getting what C++ expects, namely "calculateCulturePercent(class CyCity {|value|, int).

{sighs} But I don't know how to interpret this error message.

I will appreciate any help on how to use the information at the above noted website - I've already worked with some of the methods that return integers... but what is this particular method returning?

Thanks!!!
Spocko

ps - I've attached a zip of the ExecutiveBriefing.Py file... the code at the bottom is junk regarding this method (I even tried CyPlot's version of calculateCulturePercent...)
 

Attachments

IMHO, the documentation at the URL below is better than what you're using. It's more obvious what the functions return and what arguments they require.

http://civilization4.net/files/modding/PythonAPI_v160/

For example, the function you're trying to use is described as shown below.

Code:
INT calculateCulturePercent(INT eIndex)
int (int eIndex)

That still doesn't make it very clear what eIndex is supposed to be, but you can deduce that from the example code you included.

Code:
for h in range( gc.getMAX_CIV_PLAYERS() ):

So h is an integer in the range 0 through MAX_CIV_PLAYERS. It's a player number.

In your case, you're interested in the calculated culture for the current player. If you're Germany, you don't really care how much culture the Mayans, Spanish, or English have. You just want to know what percentage of the city is German. You should be able to get that with something like this.

Code:
	def onCityDoTurn(self, argsList):
		'City Production'
		pCity = argsList[0]
		iPlayer = argsList[1]
		# ...
		fPercent = pCity.calculateCulturePercent(iPlayer)

Hope that helps.
 
Thanks Dr. Jiggle - this does help. I'm not getting error messages anymore, although I'm also not getting the data I expected - but this is a different problem for me to tackle :rolleyes:

And I agree your quoted website (Sid's Python...) has more information.

I plan to post ExecutiveBriefing once I've developed it further. Civ4 is fun because we are always making decisions, and more information means finer decisions.

Spocko
 
Back
Top Bottom