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

By the way, looking at the concept of the BeginPlayerTurn, it is looping through every player to check whether he is a vassal, then loop through the whole list of techs to see if there is a tech that vassal has that master does not and vice versa every single turn.

Why not rewrite the whole thing under onTA instead?
Such that, when a player gains a tech, check if he is a vassal or master, then gives the tech to the other player as well.
This way, it is only activated when tech is gained rather than every single turn. And you only check the new tech gained rather than loop through the whole list of techs

Right, but might be problematic for techs which found religions/give first-research-advantages. Or don't you think so?


Also, since you are looping through every single tech, and granting to the other player, those techs that are not researchable like TECH_ISRAEL will be granted as well...

No since TECH_ISRAEL has bTrade 0 and I'm checking .isTrade.
 
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
 
Btw... how can I check if someone is a master? I guess I have to loop over all players like I'm already doing...
 
if gc.getTeam(iTeamX).isVassal(iTeam) or gc.getTeam(iTeam).isVassal(iTeamX):

Checks both ways
 
Ah! Now I remember why I'm looping over all techs... you should get techs your master/vassal has researched before, too!
 
Hmm ok, but you can do that under def onVassalState(self, argsList):

Then for new additions, onTA will do a better job
 
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.
 
Here is the code:

PHP:
	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

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

		if iPlayer > -1 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(iTechTypeX, pTeam.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(iTechTypeX, vTeam.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.
 
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
 
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.
 
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 ------------------------------------------------------------------------------------------------
 
Top Bottom