1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Help needed with Civic Free Specialist in Capital

Discussion in 'Civ4 - SDK/Python' started by CaptainMidnight, Oct 9, 2011.

  1. CaptainMidnight

    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.
     
  2. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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.
     
  3. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    32,446
    Location:
    DE/NL/FR
    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.
     
  4. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    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:
     
  5. Arian

    Arian No more ghostbusting!!

    Joined:
    May 10, 2008
    Messages:
    2,088
    Location:
    The Netherlands
    I cleaned up the code a bit:
    PHP:
    def onBeginPlayerTurn(selfargsList):
            
    'Called at the beginning of a players turn'
            
    iGameTurniPlayer argsList

            
    if not gc.getPlayeriPlayer ).isHuman():
                
    self.doAIOperationsiPlayer )

    ## 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(iCitizen1)

            
    ## remove citizen specialist if civic isn't chiefdom
            
    else pCapital.setFreeSpecialistCount (iCitizen0)
            
    ## 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
     

Share This Page