Advertisement
Civilization Fanatics' Center  

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python

Reply
 
Thread Tools
Old May 01, 2012, 09:18 AM   #21
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
Quote:
Originally Posted by platyping View Post
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?


Quote:
Originally Posted by platyping View Post
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.
Cybah is offline   Reply With Quote
Old May 01, 2012, 09:22 AM   #22
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
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

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
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging
platyping is offline   Reply With Quote
Old May 01, 2012, 09:29 AM   #23
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
Btw... how can I check if someone is a master? I guess I have to loop over all players like I'm already doing...
Cybah is offline   Reply With Quote
Old May 01, 2012, 09:34 AM   #24
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
if gc.getTeam(iTeamX).isVassal(iTeam) or gc.getTeam(iTeam).isVassal(iTeamX):

Checks both ways
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging
platyping is offline   Reply With Quote
Old May 01, 2012, 09:38 AM   #25
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
Ah! Now I remember why I'm looping over all techs... you should get techs your master/vassal has researched before, too!
Cybah is offline   Reply With Quote
Old May 01, 2012, 09:43 AM   #26
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
Hmm ok, but you can do that under def onVassalState(self, argsList):

Then for new additions, onTA will do a better job
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging
platyping is offline   Reply With Quote
Old May 01, 2012, 09:51 AM   #27
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
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.
Cybah is offline   Reply With Quote
Old May 01, 2012, 09:55 AM   #28
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
Here is the code:

PHP Code:
    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.
Cybah is offline   Reply With Quote
Old May 01, 2012, 09:56 AM   #29
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
The code?
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging
platyping is offline   Reply With Quote
Old May 01, 2012, 09:57 AM   #30
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
Whats up?
Cybah is offline   Reply With Quote
Old May 01, 2012, 10:31 AM   #31
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
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

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
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging
platyping is offline   Reply With Quote
Old May 01, 2012, 11:58 AM   #32
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,467
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.
Cybah is offline   Reply With Quote
Old May 01, 2012, 06:50 PM   #33
platyping
Sleeping Dragon
 
platyping's Avatar
 
Join Date: Oct 2010
Location: Emerald Dreams
Posts: 4,033
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 ------------------------------------------------------------------------------------------------
__________________
Holiday Mood

Bug Reporting Procedures
1) Activate Python Exceptions
2) Screenshot
3) Whether bug exists in standalone or after merging

Last edited by platyping; May 01, 2012 at 11:26 PM.
platyping is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python > [PYTHON] onTechAcquired CustomCode not working correctly with Team/when giving Techs by Python

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 06:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
This site is copyright Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR