Question re Python

ripple01

Emperor
Joined
Mar 7, 2006
Messages
1,254
Location
New York City
I'm writing some Python code and am in need of a little assistance. I am trying to achieve the effect of when a player with the Enlightened trait enters the Classical era, they get to pick a new technology.

My code now quasi works, but what happens is that when you select your free tech, the onTechAcquired tech fires before the era change, giving you another free tech, and so on. Could anyone give me a nudge in the right direction about how to fix this?



Code:
def onTechAcquired(self,argsList):
                'Tech Acquired'
                iTechType, iTeam, iPlayer, bAnnounce = argsList
                # Note that iPlayer may be NULL (-1) and not a refer to a player object


                pPlayer = gc.getPlayer(iPlayer)
                                        

        ## Enlightened Trait Start ##
                                
        
                iTrait = CvUtil.findInfoTypeNum(gc.getTraitInfo,gc.getNumTraitInfos(),'TRAIT_ENLIGHTENED')

                if (pPlayer.hasTrait(iTrait)):

                	iTechEra = gc.getTechInfo(iTechType).getEra()
                	iPlayerEra = CyPlayer().getCurrentEra()

			if iTechEra != iPlayerEra:

				if iTechEra == 1:

					szTitle = localText.getText( "TXT_KEY_SCI_TRAIT_FREE_TECH", ( ) )
					if (pPlayer.isHuman):
                                                pPlayer.chooseTech(1,szTitle,True)
                                        if (not pPlayer.isHuman()):
                                                techs = []
                                                team = gc.getTeam(pPlayer.getTeam())
                                                for iTech in range(gc.getNumTechInfos()):
                                                        if pPlayer.canResearch(iTech, false):
                                                                iCost = team.getResearchLeft(iTech)
                                                                if iCost > 0:
                                                                        techs.append((-iCost, iTech))
                                                if techs:
                                                        techs.sort()
                                                        iTech = techs[0][1]
                                                        team.setHasTech(iTech, True, iPlayer, false, false)
 
I'd suggest looping over all the if iTechEra != iPlayerEra: check loop over all the players techs, and check if he doesn't have any othertech with iTechEra. If not, let the rest of the code execute, if yes, then just skip it.

Not the nicest thing, but should work.
 
Top Bottom