1. We have added the ability to collapse/expand forum categories and widgets on forum home.
    Dismiss Notice
  2. All Civ avatars are brought back and available for selection in the Avatar Gallery! There are 945 avatars total.
    Dismiss Notice
  3. To make the site more secure, we have installed SSL certificates and enabled HTTPS for both the main site and forums.
    Dismiss Notice
  4. Civ6 is released! Order now! (Amazon US | Amazon UK | Amazon CA | Amazon DE | Amazon FR)
    Dismiss Notice
  5. Dismiss Notice
  6. Forum account upgrades are available for ad-free browsing.
    Dismiss Notice

onTechAcquired CustomCode not working correctly with Team/when giving Techs by Python

Discussion in 'Civ4 - SDK/Python' started by Cybah, May 1, 2012.

  1. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Right, but might be problematic for techs which found religions/give first-research-advantages. Or don't you think so?


    No since TECH_ISRAEL has bTrade 0 and I'm checking .isTrade.
     
  2. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    Doubt so for those first player rewards, whether religion, free GP or free tech
    Because I think XML effects are triggered before python effects.
    Although, it is not hard to test :D

    Just try:
    1) If iTechType == Meditation for instance
    2) Grants Meditation to Human Player

    See who gets it and you can write your code in peace
     
  3. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Btw... how can I check if someone is a master? I guess I have to loop over all players like I'm already doing...
     
  4. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    if gc.getTeam(iTeamX).isVassal(iTeam) or gc.getTeam(iTeam).isVassal(iTeamX):

    Checks both ways
     
  5. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Ah! Now I remember why I'm looping over all techs... you should get techs your master/vassal has researched before, too!
     
  6. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    Hmm ok, but you can do that under def onVassalState(self, argsList):

    Then for new additions, onTA will do a better job
     
  7. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Okay, you may not use onTA instead:

    If you switch your research at beginning of every round while your vassal or master researches monotheism, you will not get the splash screen/great prophet (with israel for example).

    Cannot say why. Civ4 is strange sometimes.

    //Edit: I did not get the tech either lol.
     
  8. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Here is the code:

    PHP:
        def onTechAcquired(selfargsList):
            
    'Tech Acquired'
            
    iTechTypeiTeamiPlayerbAnnounce argsList
            
    # Note that iPlayer may be NULL (-1) and not a refer to a player object

    # Gameoption Hegemon/Vassal Shares Tech Start -----------------------------------------------------------------------------------------------

            
    if iPlayer > -and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_VASSAL_STATES):
                if 
    gc.getGame().isOption(GameOptionTypes.GAMEOPTION_HEGEMON_SHARES_TECHS) or gc.getGame().isOption(GameOptionTypes.GAMEOPTION_VASSAL_SHARES_TECHS):
                    
    pPlayer gc.getPlayer(iPlayer)
                    
    iTeam pPlayer.getTeam()
                    
    pTeam gc.getTeam(iTeam)
                    for 
    iSharePlayer in xrange(gc.getMAX_CIV_PLAYERS()):
                        
    vPlayer gc.getPlayer(iSharePlayer)
                        
    vTeam gc.getTeam(vPlayer.getTeam())    
                        if 
    vPlayer.isAlive():
                            if 
    gc.getTeam(vPlayer.getTeam()).isVassal(iTeam):
                                for 
    iTechTypeX in xrange(gc.getNumTechInfos()):
                                    if 
    gc.getTechInfo(iTechTypeX).isTrade():
                                        if ((
    vTeam.isHasTech(iTechTypeX)) and gc.getGame().isOption(GameOptionTypes.GAMEOPTION_VASSAL_SHARES_TECHS)):
                                            
    pTeam.changeResearchProgress(iTechTypeXpTeam.getResearchCost(iTechTypeX) - pTeam.getResearchProgress(iTechTypeX), iPlayer)
                                            
    # pTeam.setHasTech(iTechTypeX, true, iPlayer, false, false)
                                        
    if ((pTeam.isHasTech(iTechTypeX)) and gc.getGame().isOption(GameOptionTypes.GAMEOPTION_HEGEMON_SHARES_TECHS)):
                                            
    vTeam.changeResearchProgress(iTechTypeXvTeam.getResearchCost(iTechTypeX) - vTeam.getResearchProgress(iTechTypeX), iSharePlayer)
                                            
    # vTeam.setHasTech(iTechTypeX, true, iSharePlayer, false, false)

    # Gameoption Hegemon/Vassal Shares Tech End ------------------------------------------------------------------------------------------------

    Works if I'm not changing the current research every round.
     
  9. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    The code? :D
     
  10. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    Whats up? :p
     
  11. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    It means I posted that while you post the codes lol

    Anyway did a simple test to test the changing current tech thingy

    Code:
    ## Nalanda University Start ##
    		for iPlayerX in range(gc.getMAX_CIV_PLAYERS()):
    			pPlayerX = gc.getPlayer(iPlayerX)
    			if pPlayerX.isHuman():
    				iTeamX = pPlayerX.getTeam()
    				pTeamX = gc.getTeam(iTeamX)
    				if iTeamX != iTeam and not pTeamX.isHasTech(iTechType):
    					pTeamX.changeResearchProgress(iTechType, pTeamX.getResearchCost(iTechType) - pTeamX.getResearchProgress(iTechType), iPlayerX)
    ## Nalanda University End ##
    Grants tech researched by anyone to human player. Yeah, got easier way to get human player, but I lazy to type codes at 12 midnight, so just cut out unnecessary parts :D

    Anyway, even when I set research rate at 0% and switch every turn, I still get the techs once awhile with techscreen shown when others researched theirs.

    Also, when Polytheism was researched by some clown out there, I got it with techscreen as well, and Hindu was founded by him not me, so it proves first player rewards are working as intended too.

    Anyway, I think you should modify the codes to suit the onTA part first, to minimise errors.

    1) when new tech acquired
    2) loop through all teams rather than players using MAX_CIV_TEAMS, less loops, more efficient
    3) check if loop team is vassal or master or iTeam
    4) grants the tech to loop team. Yeah, I know changeResearchProgress needs a player ID at the end. Just use loop team instance .getLeaderID()

    This should be enough, as for the existing techs, just do it once in onVassalState will do
     
  12. Cybah

    Cybah Chieftain

    Joined:
    Jun 22, 2007
    Messages:
    1,477
    In my example there is not only one tech shared. Maybe that's the reason. Duno. I've tested it multiple times and I can reproduce the glitch with my code.
     
  13. platyping

    platyping Sleeping Dragon

    Joined:
    Oct 22, 2010
    Messages:
    4,620
    Location:
    Emerald Dreams
    Under onTA:
    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
    		if iPlayer > -1 and not CyGame().isOption(GameOptionTypes.GAMEOPTION_NO_VASSAL_STATES): 
    			if CyGame().isOption(GameOptionTypes.GAMEOPTION_HEGEMON_SHARES_TECHS) or CyGame().isOption(GameOptionTypes.GAMEOPTION_VASSAL_SHARES_TECHS):
    				pTeam = gc.getTeam(iTeam) 
    				for iTeamX in range(gc.getMAX_CIV_TEAMS()):
    					pTeamX = gc.getTeam(iTeamX)     
    					if pTeamX.isAlive() and not pTeamX.isHasTech(iTechType): 
    						if pTeam.isVassal(iTeamX) and CyGame().isOption(GameOptionTypes.GAMEOPTION_VASSAL_SHARES_TECHS): 
    							pTeamX.changeResearchProgress(iTechType, pTeamX.getResearchCost(iTechType) - pTeamX.getResearchProgress(iTechType), pTeamX.getLeaderID()) 
    						elif pTeamX.isVassal(iTeam) and CyGame().isOption(GameOptionTypes.GAMEOPTION_HEGEMON_SHARES_TECHS)): 
    							pTeamX.changeResearchProgress(iTechType, pTeamX.getResearchCost(iTechType) - pTeamX.getResearchProgress(iTechType), pTeamX.getLeaderID())
    Try this. Assuming VASSAL_SHARES_TECHS means the vassal shares the tech with the master and HEGEMON_SHARES_TECHS does the other way round

    And this chunk is for the existing techs
    Code:
    	def onVassalState(self, argsList):
    		'Vassal State'
    		iMaster, iVassal, bVassal = argsList
    		
    		if (bVassal):
    # Gameoption Hegemon/Vassal Shares Tech Start ----------------------------------------------------------------------------------------------- 
    			MasterTeam = gc.getTeam(iMaster)
    			VassalTeam = gc.getTeam(iVassal)
    			for iTechTypeX in range(gc.getNumTechInfos()): 
    				if gc.getTechInfo(iTechTypeX).isTrade(): 
    					if VassalTeam.isHasTech(iTechTypeX) and not MasterTeam.isHasTech(iTechTypeX):
    						if CyGame().isOption(GameOptionTypes.GAMEOPTION_VASSAL_SHARES_TECHS): 
    							MasterTeam.changeResearchProgress(iTechTypeX, MasterTeam.getResearchCost(iTechTypeX) - MasterTeam.getResearchProgress(iTechTypeX), MasterTeam.getLeaderID()) 
    					if MasterTeam.isHasTech(iTechTypeX) and not VassalTeam.isHasTech(iTechTypeX):
    						if CyGame().isOption(GameOptionTypes.GAMEOPTION_HEGEMON_SHARES_TECHS): 
    							VassalTeam.changeResearchProgress(iTechTypeX, VassalTeam.getResearchCost(iTechTypeX) - VassalTeam.getResearchProgress(iTechTypeX), VassalTeam.getLeaderID()) 
    # Gameoption Hegemon/Vassal Shares Tech End ------------------------------------------------------------------------------------------------  
     

Share This Page