Tsentom1 Python Wonders

I have converted some of of Tsentom1's Ishtar gate to be BUG/WoC compatible. This makes it "easier" to add the RevDCM based mods.

Instillation
Spoiler :
Instillation is not straight forward. You will need to edit two XML files.

In the Assets/Modules folder edit MLF_CIV4ModularLoadingControls.xml to add in
Code:
				<Module>
					<Directory>tsentom1_python_wonders</Directory>
					<bLoad>1</bLoad>
				</Module>

In the Assets/Config folder edit init.xml to add in
Code:
	<load mod="Ishtar"/>

before the </bug> line at the end.

There may be problems with the schemas so copy the ones from your mod if you need to.

Ishtar Gate

The Great Bath of Mohenjo-daro

While doing this one I noticed a bug where it would forget that you had built the wonder if you saved the game and loaded later. So I fixed it but there is still one problem that I noticed.
 
Thanks for this, I used it in my mod!
 
I just don't get it. I installed the Sphinx in my new mode, but didn't install the python file, and it still works... WHY ? what is the python file there for ?
 
Recommend the following references be changed in all of your python files:

From:
Code:
pPlayer = gc.getPlayer(iPlayer)

for iCity in range(pPlayer.getNumCities()):
	pCity = pPlayer.getCity(iCity)


To:
Code:
iRefCityList = PyPlayer(iPlayer).getCityList()

for pyCity in iRefCityList:
	pCity = pyCity.GetCy()
	iCity = pCity.getID()


I have changed all of my mods to reflect this efficiency change.
 
Has anyone else had problems with the Leonardo's workshop wonder? Mine doesn't seem to work at all. I playted a test-game and built it (I actually built it, I didn't just plop it down anywhere), movie played, culture went up all that stuff, except the upgrade costs were the same. So it must be the python. Can someone help me out here?

I have attached the python file used in my mod, CvGameUtils.py, it was the only one that came in the download. Thanks in advance to anyone who could help me out with this. :goodjob:

Don't know if this still is of interest (it's been quite a while since Da Capo asked ;)), but just changing CvGameUtils.py of course won't work as BUG uses it's own version of getUpgradePriceOverride. But getting it to work is simple, you just have to do it the BUG way, as someone mentioned before: Tutorial

Works flawless for me...
 
·Imhotep·;11090177 said:
Don't know if this still is of interest (it's been quite a while since Da Capo asked ;)), but just changing CvGameUtils.py of course won't work as BUG uses it's own version of getUpgradePriceOverride. But getting it to work is simple, you just have to do it the BUG way, as someone mentioned before: Tutorial

Works flawless for me...

I can help. Download OGI 255E this weekend and you will get an improved method for Leonardo's workshop. It provides a free building, which lowers the cost of upgrades by 50% via promotion. Result: There is no longer a need for the Python method! :)

If you can't wait for this weekend you can download ver 255D now.
 
Strange, I'm using BUG mod and my workshop works fine. But I cannot give you the code since it's altered alot... but you can take a look if you want (CvGameUtils.py):

Spoiler :

PHP:
	def getUpgradePriceOverride(self, argsList):
		iPlayer, iUnitID, iUnitTypeUpgrade = argsList

## Militant Trait & Leonardo's Workshop Start ##

		pPlayer = gc.getPlayer(iPlayer)
		pUnit = pPlayer.getUnit(iUnitID)

		iPrice = gc.getDefineINT("BASE_UNIT_UPGRADE_COST")
		iPrice += (max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION"))

		if not pPlayer.isHuman() and not pPlayer.isBarbarian():
			pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
			iPrice = iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100
			iPrice = iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100

		iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getCombat() - gc.getUnitInfo(pUnit.getUnitType()).getCombat()) * 10)

		iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getAirCombat() - gc.getUnitInfo(pUnit.getUnitType()).getAirCombat()) * 10)

		if gc.getUnitInfo(iUnitTypeUpgrade).getUnitCombatType() != pUnit.getUnitCombatType():
			iPrice += 40

		iPrice = iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100)

		iTrait = CvUtil.findInfoTypeNum(gc.getTraitInfo,gc.getNumTraitInfos(),'TRAIT_MILITANT')		
		if pPlayer.hasTrait(iTrait):

			b_Leonardo = gc.getInfoTypeForString("BUILDING_LEONARDO")
			obsoleteTech = gc.getBuildingInfo(b_Leonardo).getObsoleteTech()
			if ( not gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) or obsoleteTech == -1 ):

				if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_LEONARDO")) > 0:

					iPrice = ((gc.getDefineINT("BASE_UNIT_UPGRADE_COST"))/8*3)
					iPrice += (((max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION")))/8*3)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getCombat() - gc.getUnitInfo(pUnit.getUnitType()).getCombat()) * 10/8*3)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getAirCombat() - gc.getUnitInfo(pUnit.getUnitType()).getAirCombat()) * 10/8*3)

					if gc.getUnitInfo(iUnitTypeUpgrade).getUnitCombatType() != pUnit.getUnitCombatType():
						iPrice += 40/8*3

					if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
						pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
						iPrice = ((iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100)/8*3)
						iPrice = ((iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100)/8*3)

						iPrice = ((iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100))/8*3)

				else:

					iPrice = ((gc.getDefineINT("BASE_UNIT_UPGRADE_COST"))/2)
					iPrice += (((max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION")))/2)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getCombat() - gc.getUnitInfo(pUnit.getUnitType()).getCombat()) * 10/2)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getAirCombat() - gc.getUnitInfo(pUnit.getUnitType()).getAirCombat()) * 10/2)

					if gc.getUnitInfo(iUnitTypeUpgrade).getUnitCombatType() != pUnit.getUnitCombatType():
						iPrice += 40/2

					if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
						pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
						iPrice = ((iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100)/2)
						iPrice = ((iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100)/2)

						iPrice = ((iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100))/2)

			else:

				iPrice = ((gc.getDefineINT("BASE_UNIT_UPGRADE_COST"))/2)
				iPrice += (((max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION")))/2)

				iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getCombat() - gc.getUnitInfo(pUnit.getUnitType()).getCombat()) * 10/2)

				iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getAirCombat() - gc.getUnitInfo(pUnit.getUnitType()).getAirCombat()) * 10/2)

				if gc.getUnitInfo(iUnitTypeUpgrade).getUnitCombatType() != pUnit.getUnitCombatType():
					iPrice += 40/2

				if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
					pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
					iPrice = ((iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100)/2)
					iPrice = ((iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100)/2)

					iPrice = ((iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100))/2)

		if not pPlayer.hasTrait(iTrait):

			b_Leonardo = gc.getInfoTypeForString("BUILDING_LEONARDO")
			obsoleteTech = gc.getBuildingInfo(b_Leonardo).getObsoleteTech()
			if ( not gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) or obsoleteTech == -1 ):

				if pPlayer.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_LEONARDO")) > 0:

					iPrice = ((gc.getDefineINT("BASE_UNIT_UPGRADE_COST")) * 3/4)
					iPrice += (((max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION"))) * 3/4)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getCombat() - gc.getUnitInfo(pUnit.getUnitType()).getCombat()) * 10*3/4)

					iPrice += ((gc.getUnitInfo(iUnitTypeUpgrade).getAirCombat() - gc.getUnitInfo(pUnit.getUnitType()).getAirCombat()) * 10*3/4)

					if gc.getUnitInfo(iUnitTypeUpgrade).getUnitCombatType() != pUnit.getUnitCombatType():
						iPrice += 40*3/4

					if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
						pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
						iPrice = ((iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100) * 3/4)
						iPrice = ((iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100) * 3/4)

						iPrice = ((iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100)) * 3/4)

# Populist Start -----------------------------------------------------------------------------------------------
#		if pUnit.isHasPromotion(gc.getInfoTypeForString("PROMOTION_POPULIST1")):
#			iPrice *= 5
#			iPrice /= 4
# Populist End -----------------------------------------------------------------------------------------------
		
		return iPrice

## Militant Trait & Leonardo's Workshop End ##
		
#		return -1	# Any value 0 or above will be used


But maybe I've changed my BUG mod so it uses the original CvGameUtils.py... dunno. Long time ago. I still also can use the old CvEventManager.py.
 
Found it. You should really change the Golden Dawn code to this:

Code:
## Golden Dawn Start ##

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

		b_Dawn = gc.getInfoTypeForString("BUILDING_GOLDEN_DAWN")
		obsoleteTech = gc.getBuildingInfo(b_Dawn).getObsoleteTech()

		if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
			for iCity in range(pPlayer.getNumCities()):
				ppCity = pPlayer.getCity(iCity)
				if ppCity.getNumActiveBuilding(b_Dawn) == true:

					iMissionary1 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_JEWISH_MISSIONARY')
					iMissionary2 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_CHRISTIAN_MISSIONARY')
					iMissionary3 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_HINDU_MISSIONARY')
					iMissionary4 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_BUDDHIST_MISSIONARY')
					iMissionary5 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_CONFUCIAN_MISSIONARY')
					iMissionary6 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_TAOIST_MISSIONARY')
					iMissionary7 = CvUtil.findInfoTypeNum(gc.getUnitInfo,gc.getNumUnitInfos(),'UNIT_ISLAMIC_MISSIONARY')

					aiMissionaryList = [iMissionary1, iMissionary2, iMissionary3, iMissionary4, iMissionary5, iMissionary6, iMissionary7]

					if (eUnit in aiMissionaryList):
						return True

## Golden Dawn End ##

Else you will lose ~50% game speed.

Hi, since the Golden Dawn link is still down, is this the only python code to add for Golden Dawn? If so where exactly to add this part?
 
Hi guys, learning Python codes so downloaded these wonders to analyze.

Code:
## Leonardo's Workshop Start ##

		pPlayer = gc.getPlayer(iPlayer)
		pUnit = pPlayer.getUnit(iUnitID)

		iPrice = gc.getDefineINT("BASE_UNIT_UPGRADE_COST")
		iPrice += (max(0, (pPlayer.getUnitProductionNeeded(iUnitTypeUpgrade) - pPlayer.getUnitProductionNeeded(pUnit.getUnitType()))) * gc.getDefineINT("UNIT_UPGRADE_COST_PER_PRODUCTION"))

		if ((not pPlayer.isHuman()) and (not pPlayer.isBarbarian())):
			pHandicapInfo = gc.getHandicapInfo(gc.getGame().getHandicapType())
			iPrice = iPrice * pHandicapInfo.getAIUnitUpgradePercent() / 100
			iPrice = iPrice * max(0, ((pHandicapInfo.getAIPerEraModifier() * pPlayer.getCurrentEra()) + 100)) / 100

		iPrice = iPrice - ((iPrice * pUnit.getUpgradeDiscount()) / 100)

		b_Leonardo = gc.getInfoTypeForString("BUILDING_LEONARDO")
		obsoleteTech = gc.getBuildingInfo(b_Leonardo).getObsoleteTech()
		if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
			for iCity in range(pPlayer.getNumCities()):
				ppCity = pPlayer.getCity(iCity)
				if ppCity.getNumActiveBuilding(b_Leonardo) == true:

					iPrice = iPrice/2

		return iPrice

##		return -1	# Any value 0 or above will be used
## Leonardo's Workshop End ##

I simplified the Leonardo's code. This way it will work even if you add some new promotions that reduce unit upgrade cost
 
Code:
## Himeji Samurai Castle Start ##

		pPlayer = gc.getPlayer( pUnit.getOwner( ) )
		pPlayer2 = gc.getPlayer( pPlot.getOwner( ) )

		b_Himeji = gc.getInfoTypeForString("BUILDING_HIMEJI_CASTLE")
		obsoleteTech = gc.getBuildingInfo(b_Himeji).getObsoleteTech()

		if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
			for iCity in range(pPlayer.getNumCities()):
				ppCity = pPlayer.getCity(iCity)
				if ppCity.getNumActiveBuilding(b_Himeji) == true:
					[B]iPillageGold = ( ( 0 ) * 2 ) 
					iPillageGold = ( ( CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 1") ) * 2 )
					iPillageGold += ( ( CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 2") ) * 2 )

					iPillageGold += ( ( (pUnit.getPillageChange() * iPillageGold) / 100 ) * 2 )[/B]
				else:
					iPillageGold = 0
					iPillageGold = CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 1")
					iPillageGold += CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 2")

					iPillageGold += (pUnit.getPillageChange() * iPillageGold) / 100

		if pPlot.getOwner( ) >= 0:
			if ( gc.getTeam(pPlayer2.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
				for iCity in range(pPlayer2.getNumCities()):
					ppCity = pPlayer2.getCity(iCity)
					if ppCity.getNumActiveBuilding(b_Himeji) == true:
						iPillageGold = 0

## Himeji Samurai Castle End ##

I believe Himeji part 1 Code is wrong in the calculations.
Assuming Pillage Gold 1 is 40, Pillage Gold 2 is 10, Pillage Change is 20

Without Himeji:
IPillageGold = PillageGold1 = 40
IPillageGold = IPillageGold + PillageGold2
= 40 + 10
= 50
IPillageGold = IPillageGold + (PillageChange*PillageGold)/100
= 50 + (20*50/100)
= 60

With Himeji:
IPillageGold = (PillageGold1)*2
= 40*2
= 80
IPillageGold = IPillageGold + (PillageGold2)*2
= 80 + 10*2
= 100
IPillageGold = IPillageGold + [(PillageChange*PillageGold)/100]*2
= 50 + (20*50/100)*2
= 50 + 20
= 70
Double counting, thus wrong formula
 
Again, a simplified Himeji part 1 code, got rid of the double counting
Code:
def doPillageGold(self, argsList):
		"controls the gold result of pillaging"
		pPlot = argsList[0]
		pUnit = argsList[1]
		
		iPillageGold = 0
		iPillageGold = CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 1")
		iPillageGold += CyGame().getSorenRandNum(gc.getImprovementInfo(pPlot.getImprovementType()).getPillageGold(), "Pillage Gold 2")

		iPillageGold += (pUnit.getPillageChange() * iPillageGold) / 100
		
## Himeji Samurai Castle Start ##
		pPlayer = gc.getPlayer( pUnit.getOwner( ) )
		pPlayer2 = gc.getPlayer( pPlot.getOwner( ) )

		b_Himeji = gc.getInfoTypeForString("BUILDING_HIMEJI_CASTLE")
		obsoleteTech = gc.getBuildingInfo(b_Himeji).getObsoleteTech()

		if ( gc.getTeam(pPlayer.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
			for iCity in range(pPlayer.getNumCities()):
				ppCity = pPlayer.getCity(iCity)
				if ppCity.getNumActiveBuilding(b_Himeji) == true:
					iPillageGold = iPillageGold * 2

		if pPlot.getOwner( ) >= 0:
			if ( gc.getTeam(pPlayer2.getTeam()).isHasTech(obsoleteTech) == false or obsoleteTech == -1 ):
				for iCity in range(pPlayer2.getNumCities()):
					ppCity = pPlayer2.getCity(iCity)
					if ppCity.getNumActiveBuilding(b_Himeji) == true:
						iPillageGold = 0
## Himeji Samurai Castle End ##
		return iPillageGold

Correct me if I am wrong pls, so that I can learn ^^
 
·Imhotep·;11090177 said:
Don't know if this still is of interest (it's been quite a while since Da Capo asked ;)), but just changing CvGameUtils.py of course won't work as BUG uses it's own version of getUpgradePriceOverride. But getting it to work is simple, you just have to do it the BUG way, as someone mentioned before: Tutorial

Works flawless for me...

Could you please help me then if it works flawless for you? I also have BUG mod and my Leonardo's Workshop doesn't work for me. I tried the tutorial, but well, I'm not skilled at Python, so I must be making a mistake - please, how do you do it?
 
Top Bottom