population code

DrPepper836

Warlord
Joined
Oct 29, 2007
Messages
134
I'm working on a version of plague that will make the population become to if the bad health gets to be 8 above the good health. It won't work though... I've tried some minor variations that don't work either. Note: What I didn't add is in red.

Code:
	[COLOR="Red"]def onEndPlayerTurn(self, argsList):
		'Called at the end of a players turn'
		iGameTurn, iPlayer = argsList[/COLOR]

            	'Plague'
                if (iPlayer.isAlive()):
                    cityNumber = iPlayer.GetNumCities();
                    i = 1
                    while i <= cityNumber:
                        'get the city'
                        city = iPlayer.getCity(i)
                        'check unhealthyness'
                        if((city.badHealth(false) - city.goodHealth()) >= 8):
                            'set population'
                            city.setPopulation(2)
                        i = i + 1
                        
		
		[COLOR="Red"]if (gc.getGame().getElapsedGameTurns() == 1):
			if (gc.getPlayer(iPlayer).isHuman()):
				if (gc.getPlayer(iPlayer).canRevolution(0)):
					popupInfo = CyPopupInfo()
					  popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_CHANGECIVIC)
					popupInfo.addPopup(iPlayer)
		
		CvAdvisorUtils.resetAdvisorNags()
		CvAdvisorUtils.endTurnFeats(iPlayer)[/COLOR]
 
I'm guessing you don't have python exceptions turned on? Open the ini file (shortcut in your civ 4/warlords/bts directory) and change HidePythonExceptions = 1 to HidePythonExceptions = 0.

You are using iPlayer.XXX() several times. iPlayer is the number of the player, not the player itself. You want pPlayer = gc.getPlayer(iPlayer) and then call the functions for pPlayer.

Likewise your city loop function is not always going to work. The reason is a player can have cities that don't exist. For example index 0, 1 and 2 might be cities, while 3 is empty and then 4 and 5 are cities. getNumCities (note the lower case g - pretty much all functions start with lower case) will return the number of existing cities and not the total number. PyHelpers.py have a function for getting a city list. You can either call it or copy it in your code.
 
Ok, thanks. I'll try that.

Edit: Still won't work. Here's the plague part of the code:
Code:
            	'plague'
            	pPlayer = gc.getPlayer(iPlayer)
            	cList = pPlayer.getCityList()
                if (pPlayer.isAlive()):
                    for pCity in cList:
                        pyCity = getCity(pCity)
                        'check unhealthyness'
                        if((pyCity.badHealth(true) - pyCity.goodHealth()) >= 8):
                            'set population'
                            pyCity.setPopulation(2)

Also, I've tried the line that reads
Code:
pyCity = getCity(pCity)
as
Code:
pyCity = pCity.getCity()
in case it would make a difference.
 
Still haven't turned on python exceptions?

pPlayer = gc.getPlayer(iPlayer)
pPlayer is now a CyPlayer object.

cList = pPlayer.getCityList()
CyPlayer has no function "getCityList". A python exception should've told you that. (PyPlayer, the PyHelpers class, have such a function.) Guess I misslead you a bit by saying you want a CyPlayer object when you might want a PyPlayer one...


pyCity = getCity(pCity) / pyCity = pCity.getCity()
Neither will work. pCity is a PyCity object. It doesn't have any function called getCity. pyCity = pCity.getCy() otoh will work. (Why you call a CyCity object pyCity and a PyCity object pCity I don't understand. But the computer won't care.)
 
Well, I tried to turn on the error messages, but it didn't come up. So, I moved the code from my mod folder to the main file. I see what you mean now. How though, do I change my cyPlayer to a pyPlayer?
 
Near the start of the file there's problably this line:
PyPlayer = PyHelpers.PyPlayer
Then all you need is pPlayer = PyPlayer(iPlayer)

If PyPlayer is not set like that you can still use pPlayer = PyHelpers.PyPlayer(iPlayer)
 
Back
Top Bottom