Help needed with Civic Free Specialist in Capital

CaptainMidnight

Warlord
Joined
Apr 16, 2006
Messages
141
I wrote (or kind of copied and changed more like) some python. My intention is that under a civic (Chiefdom) you get a Free Citizen specialist in your capital. I tried to implement this via the SDK but it was proving too difficult for me.

CvEventManager.py
Code:
def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList

		if not gc.getPlayer( iPlayer ).isHuman():
			self.doAIOperations( iPlayer )

## Chiefdom Civic CMedit ##
		
		pPlayer = gc.getPlayer(iPlayer)

		iCitizen = CvUtil.findInfoTypeNum(gc.getSpecialistInfo, gc.getNumSpecialistInfos(), 'SPECIALIST_CITIZEN', )
		iPalace = gc.getInfoTypeForString("BUILDING_PALACE")
		iChiefdom = CvUtil.findInfoTypeNum(gc.getCivicInfo,gc.getNumCivicInfos(),'CIVIC_CHIEFDOM')
				
		if (pPlayer.isCivic(iChiefdom) == true):
				for iCity in range(pPlayer.getNumCities()):
						ppCity = pPlayer.getCity(iCity)
						if ppCity.getNumActiveBuilding(iPalace) == true:
							ppCity.changeFreeSpecialistCount(iCitizen, 1)

## Chiefdom Civic CMedit ##

I'm not familiar with Python, so if anyone could show me what I've done wrong then I'd be really happy.
 
Firstly; what isn't working with the code?

Secondly; figure out how to enable Python exceptions - if you haven't already - and find the error logs. (Hint: search for it.)

Thirdly: you have been copy-pasting some rather poor code, so the implementation you have will always be buggy at best. (Hint: there is a way iterate cities with PyHelpers, but that means rewriting some of the code.)

Someone knowledgeable would be able to rewrite the code for you. Else you can just PM and I'll get the job done. Eventually.
 
2 things:
1) that will not work in this way, because you'll get a free specialist every new turn. Quite a few at the end :D.
2) if ppCity.getNumActiveBuilding(iPalace) == true:
I know, much stuff can be evaluated as bools in python, but not sure if that works here. Rather try ==1.
Or better don't loop at all. You could use pPlayer.getCapitalCity () to get the capital. Will not fix #1, though.
 
In Python, actually anything above zero equates as True. This is also true about arrays - a non-empty array will read True.

Very good points overall, The_J :goodjob:
 
I cleaned up the code a bit:
PHP:
def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList

		if not gc.getPlayer( iPlayer ).isHuman():
			self.doAIOperations( iPlayer )

## Chiefdom Civic CMedit ##
		
		pPlayer = gc.getPlayer(iPlayer)

		iCitizen = gc.getInfoTypeForString("SPECIALIST_CITIZEN")
		iChiefdom = gc.getInfoTypeForString("CIVIC_CHIEFDOM")
		pCapital = pPlayer.getCapitalCity ()
				
		if (pPlayer.isCivic(iChiefdom) == true):
			iCitizenCount = pCapital.getFreeSpecialistCount (iCitizen)
			## No more than 3 citizen in Capital
			iCitizenMax = 3
			if iCitizenCount < iCitizenMax:
				pCapital.changeFreeSpecialistCount(iCitizen, 1)

		## remove citizen specialist if civic isn't chiefdom
		else pCapital.setFreeSpecialistCount (iCitizen, 0)
		## WARNING: no more citizen specialists possible under other civics!!

## Chiefdom Civic CMedit ##
Might be buggy here and there as I didn't test it and made it up in 5 minutes :p
 
Top Bottom