Simple Python Things

Weekend is over, and I have to say: Sorry keldath (and everyone else), I just don't have time to do any modding anymore (besides small bugfixes maybe).
I'm sorry :(.

Thank you, The_J for all your dedication to this community and Civ4 in general!
 
I guess your new job must be pretty taxing.
All the best
 
Thanks everyone.

It's not the job (...well...a bit), it's the private life, which just got....rough.
I don't think I'll be visiting the forum regularly from now on.
If there are any questions, modding or moderating wise, then please ask someone else (in the latter case: Leoreth, he's assigned to Civ4 C&C).
 
Would like to identify if a city has built a specific building or not. Any suggestions for code that can indicate, for example, if one was built a forge?

pHeadSelectedCity = CyInterface().getHeadSelectedCity()
if == 'hasforge'
 
Neither of which is correct.
Both of them will still return true if the city has the building without building it, such as monument from Stonehenge.
getNumRealBuilding
 
Don't think there's anything in the python API (or SDK for that matter) to even track that kind of thing. You'd have to implement it yourself.
 
FORGE not FORCE

plat is right, but it depends on whether or not you actually want to do it with 'real' buildings or all of them
 
Neither of which is correct.
Both of them will still return true if the city has the building without building it, such as monument from Stonehenge.
getNumRealBuilding

Good to know, thanks for correcting.

Just out of interest, getNumBuilding would then return 2 if you have built a monument and later got another from Stonehenge, right?

FORGE not FORCE

Thanks, corrected that.
 
Still be one, since that is the global defines limit.
 
Hello, just started reading this thread... I know it's been a while but why was the Hanseatic League Project done in Python. Could it not have been done as a normal Project with an Event tied to the Project's completion?
 
There's no even trigger for project completion, therefore this would also have involved some Python. An event can also give only 1 unit, not multiple.
But else that's not a bad idea, could probably be something done like that for world wonders.
 
There's no even trigger for project completion, therefore this would also have involved some Python. An event can also give only 1 unit, not multiple.
But else that's not a bad idea, could probably be something done like that for world wonders.

I see, I've done that kind of thing for World Wonders - and yeah I don't think two different unit types wouldn't work unless you have a second event that occurs after the first, two turns apart. Not as clean as getting both on the same turn.
 
I managed to get the Python version of the Heroic Strength Promotion mod to work and I want to share the code to make record of the function for future reference. The code works for 3 Heroic strength promotions.

Code:
def onUnitPromoted(self, argsList):
	'Unit Promoted'
	pUnit, iPromotion = argsList
	player = PyPlayer(pUnit.getOwner())
	###Heroic Strength Promotion start###
	pPlayer = gc.getPlayer(pUnit.getOwner())		
					
	lStrengthPromotions = [
		"PROMOTION_HEROIC_STRENGTH1",
		"PROMOTION_HEROIC_STRENGTH2",
		"PROMOTION_HEROIC_STRENGTH3"
	]
	
	if not pPlayer.isNone() and not pPlayer.isBarbarian() and pPlayer.isAlive():
		if (pUnit.getDomainType() == DomainTypes.DOMAIN_LAND):
			for iHeroicStrengthPro in range(len(lStrengthPromotions)):
				MyPromotion = str(lStrengthPromotions[iHeroicStrengthPro])
				#CyInterface().addImmediateMessage(str(MyPromotion), "")
				iStrPromotion = gc.getInfoTypeForString(str(MyPromotion))
				
				if pPlayer.isHuman():
					#CyInterface().addImmediateMessage("A", "")
					if (iPromotion == iStrPromotion):
						if pUnit.isHasPromotion(iStrPromotion):
							pUnit.setBaseCombatStr(pUnit.baseCombatStr() + 1)
							break
	
				elif not pPlayer.isHuman():
					if (iPromotion<>iStrPromotion):
						if not pUnit.isHasPromotion(iStrPromotion):
							if pUnit.canAcquirePromotion(iStrPromotion):
								decision = CyGame().getSorenRandNum(4, "strength")
								
								if (decision == 1 or decision == 2):
									# Remove promotion in favor of Heroic Strength promotion.
									pUnit.setHasPromotion(iPromotion, False)
									pUnit.setHasPromotion(iStrPromotion, True)
									pUnit.setBaseCombatStr(pUnit.baseCombatStr() + 1)
									
								break
								
###Heroic Strength Promotion End###

Enjoy! :king:
 
Wait a second, am I actually seeing the
Code:
<>
operator in there?! How weird, I've only ever seen != or not == used
 
Wait a second, am I actually seeing the
Code:
<>
operator in there?! How weird, I've only ever seen != or not == used

I was surprised to see the <> operator work, but it did. So I left it in the code. If you feel more confident with != then you can use that instead.
 
The Python assumes the XML is properly written. ...And yes it does work.

Perhaps later, I might just release a new complete Python version of the mod.

Edit:
I mean it fails when a unit is upgraded, not promoted.
The promotion remains on the upgraded unit, but not the effects.
 
Back
Top Bottom