Request for help with Scientific Trait

seasnake

Conquistador
Joined
Apr 21, 2006
Messages
2,003
Location
California, United States
Hi, making a mod that has a "scientific trait."

Wanted to use CvEventManager to do the following: Make it so that onfounding your first city, you get a free technology that you don't have if you have the trait scientific.

Has anyone done something like this or have some suggestions?
 
I'm afraid I'm not following, but whatever it is you need it shouldn't be a problem.

Are we talking about a "real" trait or some trait you're using just to identify a player/civ/leader?
 
Well, what I meant was something like when you research Liberalism or build the Oracle, you get to pick one tech of a kind you don't have. So you found the city, and if you have TRAIT_SCIENTIFIC you can select a free tech to start the game. This coupled with a bonus to research and double production of science buildings seemed like a strong trait.

So yeah, I was wondering if anyone had done something like it in the mod.

I PM'd you a response as well, Baldyr, but wanted to better explain msyelf in the public forum.
 
Aha, that would be possible. Firstly you need to make sure it really is the first city that gets founded. I guess it could be accomplished with CyPlayer.getNumCitites() and CyCity.getID(). If these two methods return 1 and 0 respectively, then the condition would pass.

Regarding the free Tech, I think I solved this particular issue once already. The context escapes me at the moment, so I'm a bit unsure on the implementation. But I'll look into it. Does anyone else know how to select and grant a free Tech? (Since onTechSelected will be called right after the first city is founded, perhaps it could be used to grant that Tech? But this of course need to be limited to once only per player with the trait in question...)
 
I hate to be the guy that does this, because in general I hate when people start trashing a request I make, but don't you think that this trait is a bit too powerful? Free tech, plus bonus to research, plus bonuses for all scientific buildings? I mean, I don't know about you but if I played using this trait it would be a no contest against the AI.
 
From a PM I learned that there will be "super traits" in the mod seasnake is working on. So I'm guessing this is one of them - all leaders will probably have some of this added punch. Its intended to be a bit much, then.
 
Does anyone else know how to select and grant a free Tech? (Since onTechSelected will be called right after the first city is founded, perhaps it could be used to grant that Tech? But this of course need to be limited to once only per player with the trait in question...)

:confused: you can just directly give the team a tech, the command for that is there, that's not a problem.

The graphical implementation would for me be a problem, because i've never been able to see where this bloody screen gets created and how :crazyeye:.
 
:confused: you can just directly give the team a tech, the command for that is there, that's not a problem.

The graphical implementation would for me be a problem, because i've never been able to see where this bloody screen gets created and how :crazyeye:.
I don't think that you can access the Tech selection screen with Python code either. But I believe I achieved the requested effect once, in some context...

Instead I propose granting the team of the players with the specified trait the current research project on onTechSelected. I never said that was any kind of a problem. But since this is only supposed to happen once there needs to be a flag of some sort set to prevent this from happening again. And again.

Simply setting some scriptData for the CyPlayer object in question would work, but then you'd have to make sure no other code is using that same field for storing data. Or you could save the scriptData with the CyGame object instead - in an array of PlayerType values. What should be used is case dependent.
 
Since I've pretty much signed on to take charge of Python work on the mod in question, this is probably what I will end up putting in a SuperTraits module:
Code:
def traitScientific(ePlayer, eTech):
	pPlayer = gc.getPlayer(ePlayer)
	if pPlayer.hasTrait(eScientific) and pPlayer.getScriptData() == "":
		eTeam = pPlayer.getTeam()
		pTeam = gc.getTeam(eTeam)
		pTeam.setHasTech(eTech, True, ePlayer, True, True)
		pPlayer.setScriptData("trait:scientific")
The SuperTraits.traitScientific() function call is done from within the onTechSelected() method in CvEventManager.
 
I think the tech choosing pop-up is launched via CvPlayer.chooseTech((INT iDiscover, STRING szText, BOOL bFront). This is exposed to Python. It looks like iDiscover appears to be the number of techs, szText is the text that is displayed at the top of the popup, and bFront is a mystery (maybe it forces it to be in front of all other things currently displayed, or maybe not - it defaults to false).

There is also a CvPlayerAI.AI_chooseFreeTech() which makes the AI pick one. It is, however, not exposed to Python. Seems like an unfortunate oversight.

A lot of this was determined by seeing how buildings that give free techs do it.
 
I think the tech choosing pop-up is launched via CvPlayer.chooseTech((INT iDiscover, STRING szText, BOOL bFront). This is exposed to Python. It looks like iDiscover appears to be the number of techs, szText is the text that is displayed at the top of the popup, and bFront is a mystery (maybe it forces it to be in front of all other things currently displayed, or maybe not - it defaults to false).

There is also a CvPlayerAI.AI_chooseFreeTech() which makes the AI pick one. It is, however, not exposed to Python. Seems like an unfortunate oversight.

A lot of this was determined by seeing how buildings that give free techs do it.
OMG! :eek: edit: I tested the CyPlayer.chooseTech() method in the console and it works exactly as you described! :goodjob:

This means that the code would look something like this:
Code:
def traitScientific(pCity):
	ePlayer = pCity.getOwner()
	pPlayer = gc.getPlayer(ePlayer)
	if ( pPlayer.hasTrait(eScientific)
	     and pCity.getID() == 0
	     and pPlayer.getNumCities() == 1 ):
		pPlayer.chooseTech(1, scientificFreeTechMessage, False)
Now the function call is coming from onCityBuilt() instead. This clearly is the superior implementation.

Nicely done God-Emperor! :king: You just made my day by sharing this information!
 
Well, duh! The CvPlayerAI.AI_chooseFreeTech() of course needs to be exposed to Python for this to work as intended. :rolleyes: Otherwise we're stuck with the first script I posted. : p (Luckily we're gonna use a custom DLL so we need to start compiling a list of stuff that need to be included in it.)
Spoiler :
Code:
def traitScientific(pCity):
	ePlayer = pCity.getOwner()
	pPlayer = gc.getPlayer(ePlayer)
	if ( pPlayer.hasTrait(eScientific)
	     and pCity.getID() == 0
	     and pPlayer.getNumCities() == 1 ):
		if pPlayer.isHuman():
			pPlayer.chooseTech(1, scientificFreeTechMessage, False)
		else:
			pPlayer.AI_chooseFreeTech()
 
Back
Top Bottom