Traits Help

hemoglobin

Chieftain
Joined
Sep 3, 2012
Messages
44
I have two traits I would like to add that require the usage of Python. I am terrible at programming and I would appreciate step by step help with this one or at least the proper functions to work with.

The Traits Are:

Ceremonial
-10% chance of entering a Golden Age each time a wonder is built
-50% longer golden age length

Capitalist
-50% less corporation maintenance
-2 Other components that can be done through XML
 
1) Use changeGoldenAgeTurns(XXX) to trigger golden age.
2) CyGame().getSorenRandNum(X, "ABC") will randomly roll a number between 0 and X - 1, so you can use that to get 10% by simply using CyGame().getSorenRandNum(10, "ABC") == Any Number from 0 to 9.
3) X% Golden Age Length cannot be done properly without using dummy building.
4) Oh Yeah, has to be done onBuildingBuilt, use isWorldWonderClass(gc.getBuildingInfo(iBuildingType).getBuildingClassType()) check to check if it is world wonder.
5) I suppose you may know how to check if the player has XXX trait.

6) SDK for Corporation Maintenance

Since you have been trying out my stuff, there are working examples for 1 to 5, so I won't elaborate much.
 
2) CyGame().getSorenRandNum(X, "ABC") will randomly roll a number between 0 and X - 1, so you can use that to get 10% by simply using CyGame().getSorenRandNum(10, "ABC") == Any Number from 0 to 9.

Thanks. I always thought that was a number within [0,X] with X inclusively, which gives X+1 possibilities.
 
I've seen something with a Traditional trait from a mod, which involves 5 happiness in capital and a +25% production speed for buildings built already in palace. Where could I find that component individually?
 
I haven't seen any trait that provides 5 happiness, although you can affect happiness by changing the iHappiness tag in the CIV4TraitInfos.xml file. On the other hand, you can change the happiness for a trait by making a change to a building or Wonder. Here is an example, where a building provides 5 happiness to any Charismatic leader.

Code:
<HappinessTraits>
	<HappinessTrait>
		<HappinessTraitType>TRAIT_CHARISMATIC</HappinessTraitType>
		<iHappinessTrait>5</iHappinessTrait>
	</HappinessTrait>
</HappinessTraits>

Other tags in the CIV4BuildingInfos.xml file that affect happiness from a building or Wonder are:

Code:
bNoUnhappiness
iHappiness
iAreaHappiness
iGlobalHappiness
iStateReligionHappiness
CommerceHappinesses
BonusHappinessChanges
BuildingHappinessChanges

You could do something like this: Make a J.S. Bach Cathedral Wonder that provides:

Code:
+5 Happiness in the city it is built (Which could be the Capital)
+2 happiness in all cities on the continent. 
+1 happiness in All Cities
+1 Happiness from Incense
 
I believe, just changing the XML of Palace itself is much simpler.

Palace will always be present in capital.
This +5 happiness in capital is pure XML work

The other part is python using getBuildingCost
 
The other part is python using getBuildingCost

Then either tell me the code, redirect me to elsewhere or don't answer anything about it. I told you I don't know Python so you're just dangling words above my head, out of my reach.
 
I haven't seen any trait that provides 5 happiness, although you can affect happiness by changing the iHappiness tag in the CIV4TraitInfos.xml file. On the other hand, you can change the happiness for a trait by making a change to a building or Wonder. Here is an example, where a building provides 5 happiness to any Charismatic leader.

Code:
<HappinessTraits>
	<HappinessTrait>
		<HappinessTraitType>TRAIT_CHARISMATIC</HappinessTraitType>
		<iHappinessTrait>5</iHappinessTrait>
	</HappinessTrait>
</HappinessTraits>

Yeah, that one slipped my mind. I could do that.

Thank You.
 
If you saw the trait in a mod, you obviously downloaded the mod.
Now I already told you where to find the code in the mod, but if this is your attitude, so be it.
 
If you saw the trait in a mod, you obviously downloaded the mod.
Now I already told you where to find the code in the mod, but if this is your attitude, so be it.

That's because the mod has other code and I have no idea where that particular code is.

And MY attitude? My attitude is apparent because I'm getting frustrated with you. All the times you've replied to one of my questions, you've been zero help. I still can't decipher the answer you gave with the Ceremonial and Capitalist traits, the original purpose of this thread and I didn't say anything because I gave up. All you've done is answer bits and pieces as if I'm supposed to know intermediate programming after many times I have told you I don't.

You are not obligated to help me. I'd rather get help from somebody else, but keep in mind, when somebody supposedly replies to my question with an answer, I want to expect an answer I can actually work with. Because otherwise, it's only insulting me, insulting me more than somebody who doesn't answer my question.
 
*sigh*...
Moderator Action: Back to the original question.

I've seen something with a Traditional trait from a mod, which involves 5 happiness in capital and a +25% production speed for buildings built already in palace. Where could I find that component individually?

Which mod?
 
*sigh*...
Moderator Action: Back to the original question.



Which mod?

I think it was History Rewritten. It came with many python scripts and the python codes were not labeled so it was hard to tell what I was looking for.
 
Author of History Rewritten here, just noticed this thread. The section you need is the bit between the ### below. It goes in getBuildingCostMod in CvGameUtils.py.

Code:
	def getBuildingCostMod(self, argsList):
		iPlayer, iCityID, iBuilding = argsList
		pPlayer = gc.getPlayer(iPlayer)
		pCity = pPlayer.getCity(iCityID)
		iCostMod = -1

	### Capital Building Cost Reduction
		if pPlayer.hasTrait(gc.getInfoTypeForString('YOUR_TRAIT')):
			if pCity.isCapital() == False:
				if pPlayer.getCapitalCity().isHasBuilding(iBuilding):
					iCostMod = 100 + yourmodifier
		###
		return iCostMod

'YOUR_TRAIT' needs to be replaced with the name of the trait you want, e.g 'TRAIT_TRADITIONAL'.

'yourmodifier' needs to be replaced with the percentage change in cost. For example, to make buildings 25% cheaper, use -25. To make buildings 50% more expensive use 50.

I'll subscribe to this thread in case you have any other questions.
 
I tried doing it the way you gave me the code:

Code:
	def getBuildingCostMod(self, argsList):
		iPlayer, iCityID, iBuilding = argsList
		pPlayer = gc.getPlayer(iPlayer)
		pCity = pPlayer.getCity(iCityID)
		iCostMod = -1

	### Capital Building Cost Reduction
		if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_TRADITIONAL')):
			if pCity.isCapital() == False:
				if pPlayer.getCapitalCity().isHasBuilding(iBuilding):
					iCostMod = 100 + -25
		###
		return iCostMod

and this way:

Code:
	def getBuildingCostMod(self, argsList):
		iPlayer, iCityID, iBuilding = argsList
		pPlayer = gc.getPlayer(iPlayer)
		pCity = pPlayer.getCity(iCityID)
		iCostMod = -1
		
	### Capital Building Cost Reduction
	
		pPlayer = gc.getPlayer( iPlayer )
		iTrait = CvUtil.findInfoTypeNum(gc.getTraitInfo,gc.getNumTraitInfos(),'TRAIT_TRADITIONAL')

		if (pPlayer.hasTrait(iTrait)):
			if pCity.isCapital() == False:
				if pPlayer.getCapitalCity().isHasBuilding(iBuilding):
					iCostMod = 100 + -25
		###
		return iCostMod

Both codes did not work under testing. I build a monument (30 hammers) in the capital and nothing changes in the other cities. The monument still costs 30 hammers to build.
 
The two methods achieve the same thing, but use the one I posted as it's a bit tidier. Do you use BUG? If so, it could be preventing the code from being called. Look for <your mod>/Assets/Python/BUG/BUGGameUtils.py, find the following line and comment it out:

Code:
		self._setDefault("getBuildingCostMod", -1)

That file seems to force defaults for many of the routines in GameUtils.py. I'm not entirely sure why it needs to do this, but there's no ill effects from commenting out the relevant lines. If you're not using BUG then I have no idea why it wouldn't be working.
 
I'm not using BUG. I did use it in the past but I uninstalled it.

As for the code, I couldn't find that segment of code anywhere, but I do have 5 other pythons which feature custom assets:

CvCultureLinkInterface
CvExoticForeignAdvisor
CvForeignAdvisor
CvMainInterface
CvReligionScreen

Update: I've checked, none of the 5 use any instance of getBuildingCost.
 
Ack, just thought of something that I should have mentioned straight away... do you have getBuildingCost enabled in PythonCallbackDefines.xml? If your mod doesn't have this file, you'll need to copy it from BTS. It's located in /Assets/XML/. In it, find the following section:

Code:
	<Define>
		<DefineName>USE_GET_BUILDING_COST_MOD_CALLBACK</DefineName>
		<iDefineIntVal>0</iDefineIntVal>
	</Define>

Set that 0 to 1 and it will enable it. Several Python routines are disabled by default as they can be performance-degrading. getBuildingCost is one of them, though nowhere near as much a performance hit as some of the other entries in that file. But yeah, if you attach code to any of the routines listed in that file in the future, you'll need to enable each of them there in the same manner.

Apologies for not mentioning that up front, my second child was born earlier this week so I'm a bit sleep deprived :)
 
Back
Top Bottom