Tsentom1 Python Traits

Ok, but where in that file? There's lots of stuff there, and my only python experience is copy/pasting tsentom's promos.

EDIT: As a matter of fact, the Revolutionary trait I'm working on also needs other discounts to the RevIndex: happiness and a garrison (need less).
 
Hey Tsentom, sorry to bother you you about it, but the main thing holding up a release of a BST beta build is the trait effect that allows non state :religion: to still produce culture. Any chance you could show me the code you have so far, and I could try to finish it up? That would be alot easier then me trying to start from scratch.

And @mechaerik, you really need to go through the Revolution.py code and try to figure it out. When I started working on adjusting city distance calculations I had no previous knowledge of coding, at all. I was still able to understand some of it because code is specifically designed to be interpreted by humans (code isn't understood by computers, computers only do binary, code is a language used by humans so that they can create functions they can understand and manipulate, which can then be compiled into something the computer can execute). Basically you need to figure out what you need to do, use common sense to find the parts of the code related to what you want to acomplish, and then write some code that expresses what you want. What you write is unlikely to work (because you don't understand coding), but that's what the Python & SDK forum are for. However people can only help you in that forum if you provide a working context of what you want, and some sort of example of what you are trying to do, then people can help you with the syntax etc.
This thread is where I wrote my first working code, it should provide an example of what I am talking about. Remember that when I created the thread I had absolutely zero experience with coding whatsoever: http://forums.civfanatics.com/showthread.php?t=277804
 
Hey Tsentom, sorry to bother you you about it, but the main thing holding up a release of a BST beta build is the trait effect that allows non state :religion: to still produce culture. Any chance you could show me the code you have so far, and I could try to finish it up? That would be alot easier then me trying to start from scratch.

And @mechaerik, you really need to go through the Revolution.py code and try to figure it out. When I started working on adjusting city distance calculations I had no previous knowledge of coding, at all. I was still able to understand some of it because code is specifically designed to be interpreted by humans (code isn't understood by computers, computers only do binary, code is a language used by humans so that they can create functions they can understand and manipulate, which can then be compiled into something the computer can execute). Basically you need to figure out what you need to do, use common sense to find the parts of the code related to what you want to acomplish, and then write some code that expresses what you want. What you write is unlikely to work (because you don't understand coding), but that's what the Python & SDK forum are for. However people can only help you in that forum if you provide a working context of what you want, and some sort of example of what you are trying to do, then people can help you with the syntax etc.
This thread is where I wrote my first working code, it should provide an example of what I am talking about. Remember that when I created the thread I had absolutely zero experience with coding whatsoever: http://forums.civfanatics.com/showthread.php?t=277804

Didn't mean to keep you waiting, but I actually fixed the code (simple error, don't know how I missed it):

Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList

############ Religion Code ####################

		pPlayer = gc.getPlayer(iPlayer)
		pPID = pPlayer.getID()

		for iCity in range(pPlayer.getNumCities()):
			pCity = pPlayer.getCity(iCity)
			for iReligion in range(gc.getNumReligionInfos( )):
				if pCity.isHasReligion( iReligion ):

					pCC = pCity.getCulture(pPID)
					pCC = int( +1)
					pCity.changeCulture(pPID, pCC, true)

Anyway, pCC = int( +1) controls the amount of culture awarded. So currently it's at +1 per religion in the city, +2 would be 2 per religion.

Since it's done with python there's no way to reflect this in the city screen (so the culture bar won't say +1 culture, it'll just be rewarded).
 
Thanks Tsentom, what python file is this? Also I'm assuming just throwing in an if(pPlayer.hasTrait(gc.getTypeForString(TRAIT_NAMEOFTRAIT))): at the begining of the function will make it only apply to the trait. Finally, looking at the code it appears like it will apply to all religions (including the state religion), do you have a quick solution on how to make it not apply to the state religion (If not, I'm sure I can figure it out, there must be a isHasStateReligion(i) call somewhere)?
 
Thanks Tsentom, what python file is this? Also I'm assuming just throwing in an if(pPlayer.hasTrait(gc.getTypeForString(TRAIT_NAMEOFTRAIT))): at the begining of the function will make it only apply to the trait. Finally, looking at the code it appears like it will apply to all religions (including the state religion), do you have a quick solution on how to make it not apply to the state religion (If not, I'm sure I can figure it out, there must be a isHasStateReligion(i) call somewhere)?

Code:
	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		iGameTurn, iPlayer = argsList

############ Religion Code ####################

		pPlayer = gc.getPlayer(iPlayer)
		pPID = pPlayer.getID()
		iTrait = CvUtil.findInfoTypeNum(gc.getTraitInfo,gc.getNumTraitInfos(),'TRAIT_XXXXXXXXX')

		if (pPlayer.hasTrait(iTrait)):

			for iCity in range(pPlayer.getNumCities()):
				pCity = pPlayer.getCity(iCity)
				for iReligion in range(gc.getNumReligionInfos( )):
					if iReligion != pPlayer.getStateReligion( ):
						if pCity.isHasReligion( iReligion ):

							pCC = pCity.getCulture(pPID)
							pCC = int( +1)
							pCity.changeCulture(pPID, pCC, true)

BeginPlayerTurn is found in EventManager. The edited code goes right below it, just like in the code above.
 
Sweet, thanks Tsentom :goodjob:
 
On survive (with survival promotion) there is a message: Unit got killed. Is there a chance to "fix" this?

[compare to: http://forums.civfanatics.com/showthread.php?t=308714 where is no message]

Well actually, if you look at the screenshots of the respawn version of the promotion it does still say the unit was killed, however it also adds another message after it. There's no real easy way to remove the unit is killed message. Adding another message after it is easy. For survival you just have to add the bolded lines at the end of this code:

Code:
	def onCombatResult(self, argsList):
		'Combat Result'
		pWinner,pLoser = argsList
		playerX = PyPlayer(pWinner.getOwner())
		unitX = PyInfo.UnitInfo(pWinner.getUnitType())
		playerY = PyPlayer(pLoser.getOwner())
		unitY = PyInfo.UnitInfo(pLoser.getUnitType())

## Survival Start ##

		pPlayer = gc.getPlayer(pLoser.getOwner())

		if pLoser.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SURVIVAL')):

			self.iResistance = self.getRandomNumber( 9 )

			if self.iResistance == 0:

				iUnit = pLoser.getUnitType()
				pClearPlot = self.findClearPlot(pLoser)
				pPlot = pLoser.plot()

				newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
				pLoser.setDamage(90, False)
				newUnit.convert(pLoser)
				pLoser.setDamage(100, False)
				newUnit.finishMoves()

[B]				pPID = pPlayer.getID()
				iX = pLoser.getX()
				iY = pLoser.getY()

				CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_XXXXXXXXXXXXXXXX",()),'',0,'Art/Survival.dds',ColorTypes(44), iX, iY, True,True)[/B]

## Survival End ##

Just replace TXT_KEY_XXXXXXXXXXXXXXXX with whatever text tag you want the message to say.
 
My I request a new trait, when you have time for it sometime? I am not sure, if it is possible to create. I'd like to have it with two effects:

- Increasing movement on roads by +1, on railroads by +2 or +3
- Every time a city of the leader is captured some infantry units (random not obsolete units) are created (owned by the leader). If possible it should be more units in the later game (because you have bigger armies then in general). Perhaps it is possible to be depending on the age the leader is in, for example 1-2 units (random) in ancient and classical age, 2-4 units in medieval and renaissance and 3-6 in industrial, modern and future age.

Should be more difficult to capture the lands of such an AI leader, for he can bring in reinforces more quickly and he gets more units every time you have the advantage over him. However, I have no clue how to call this trait, for Protective is allready in use. :)
 
Oh, Rugged just sounds like a cool trait name. But what should it do?
 
Every time a city of the leader is captured some infantry units (random not obsolete units) are created

where shall they spawn? even the capital city can be captured. if a captured city is surrounded by enemy units, you cannot let them spawn there either. maybe you could let them spawn randomly in other remaining cities. too complicated imo.
 
And this would be exploitable. Just create 50 new cities near your enemy and get hundreds of new units in your other cities when they get captured. :D
 
where shall they spawn? even the capital city can be captured. if a captured city is surrounded by enemy units, you cannot let them spawn there either. maybe you could let them spawn randomly in other remaining cities. too complicated imo.

Somewhere near the captured city, if possible, like in Civ3.
 
they would be immediately killed by the conquerer's units.

When a city is captured, the attacker has usually not many more units near the city to move. So there is a good chance that they can move before the attacker is able to start hunting them.
 
I'm sorry guys, I've been rather busy in real life at the moment.

@JustATourist

The only real way with python to increase road movement would be to 'cheat' and make a dummy technology that you can't research and have that grant extra road movement (similar to the Engineering tech). I don't have time to write anything at the moment for this but my Seafaring Trait has to code to award a free tech on game start, if you change Sailing to your dummy tech it should work.

Awarding units on city capture or when a unit is killed in the city is possible and not that difficult to do. I'll whip something up when I have some free time.

@Cybah

I know there's a few things you asked me to do. They're all like half-finished, just haven't had a free moment to complete them. I'll hopefully get to them soon.
 
Top Bottom