• Civilization 7 has been announced. For more info please check the forum here .

Call of a function does not work


Jan 16, 2010
I have a bit of terraforming code that is a bit lengthy and used by at least 2 other python functions, so i decided to put it into its own function that i would call from the other two. My problem is that it does not work (i get no python exceptions though) and i can not find the error.

So here is the one of the functions (which both work) that call my problem function:
Spoiler :
def onAristrakhProjectBuilt(argsList):
	'Project Completed'
	pCity, iProjectType = argsList
	game = gc.getGame()
	iPlayer = pCity.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlotC = pCity.plot()
	iWasteLand = gc.getInfoTypeForString('TERRAIN_WASTELAND')


	if iProjectType == gc.getInfoTypeForString('PROJECT_ADD_POPULATION_LOCAL1'):
		iTemp1 = pPlayer.getPurityCounterCache1()
		pPlayer.setPurityCounterCache1(iTemp1 + 15 + iBonus1)
		for i in range(21):
			pPlot = pCity.getCityIndexPlot(i)
			iTerrain = pPlot.getTerrainType()
			pPlayer2 = gc.getPlayer(pPlot.getOwner())
			if iTerrain != iWasteLand and pPlayer2 == pPlayer:
				if pPlot.getBonusType(-1)!=-1 and pPlot.isWater():
					iTFinc = AristrakhFunctions.doConsumeTerrain(AristrakhFunctions(),iPlayer,pPlot)
					itemp = pPlayer.getPurityCounterCache1()
					pPlayer.setPurityCounterCache1(itemp + iTFinc)

the cruicial part is the the call of "AristrakhFunctions.doConsumeTerrain(AristrakhFunctions(),iPlayer,pPlot)". Basically it needs iPlayer and pPlot as input and does a bit of stuff:
Spoiler :
class AristrakhFunctions:

	def doConsumeTerrain(self,iPlayer,pPlot):
		pPlayer = gc.getPlayer(iPlayer)
		iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')					
		iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')					
		iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')					
		iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')	
		iWasteLand = gc.getInfoTypeForString('TERRAIN_WASTELAND')
		iMarsh = gc.getInfoTypeForString('TERRAIN_MARSH')
		iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
		iDeer = gc.getInfoTypeForString('BONUS_DEER')
		iBison = gc.getInfoTypeForString('BONUS_BISON')
		iCow = gc.getInfoTypeForString('BONUS_COW')
		iFur = gc.getInfoTypeForString('BONUS_FUR')
		iTea = gc.getInfoTypeForString('BONUS_TEA')
		iReag = gc.getInfoTypeForString('BONUS_REAGENTS')
		iIncense = gc.getInfoTypeForString('BONUS_INCENSE')
		iHorse = gc.getInfoTypeForString('BONUS_HORSE')
		iCorn = gc.getInfoTypeForString('BONUS_CORN')
		iWheat = gc.getInfoTypeForString('BONUS_WHEAT')
		iSheep = gc.getInfoTypeForString('BONUS_SHEEP')
		iPig = gc.getInfoTypeForString('BONUS_PIG')
		iIvory = gc.getInfoTypeForString('BONUS_IVORY')
		iRice = gc.getInfoTypeForString('BONUS_RICE')
		iDye = gc.getInfoTypeForString('BONUS_DYE')
		iSilk = gc.getInfoTypeForString('BONUS_SILK')
		iSugar = gc.getInfoTypeForString('BONUS_SUGAR')
		iWine = gc.getInfoTypeForString('BONUS_WINE')
		iBanana = gc.getInfoTypeForString('BONUS_BANANA')
		iCotton = gc.getInfoTypeForString('BONUS_COTTON')
		#mana resources
		iMana = gc.getInfoTypeForString("BONUSCLASS_MANA")
		iRawMana = gc.getInfoTypeForString("BONUSCLASS_RAWMANA")
		iAncientForest = gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')
		iForest = gc.getInfoTypeForString('FEATURE_FOREST')
		iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
		iKelp = gc.getInfoTypeForString('FEATURE_KELP')
		iOasis = gc.getInfoTypeForString('FEATURE_OASIS')
		iFloodplains = gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')
		iScrubs = gc.getInfoTypeForString('FEATURE_SCRUB')
		iVolcano = gc.getInfoTypeForString('FEATURE_VOLCANO')
		#soul income
		iTerrainConv = 0
		iFeatureBonus = 0
		iResourceBonus = 0
		#terraform effect
		iTFEffect = gc.getInfoTypeForString('EFFECT_CONTAGION')
		#terrain conversion
		if not pPlot.isWater():
			if iOldTerrain == iGrass:
				iTerrainConv = 4
			if iOldTerrain == iPlains:
				iTerrainConv = 2
			if iOldTerrain == iMarsh:
				iTerrainConv = 3		
			if iOldTerrain == iTundra:
				iTerrainConv = 1
		#feature conversion
		if iFeature != -1:
			if iFeature == iAncientForest:
			if iFeature == iForest:
			if iFeature == iJungle:
			if iFeature == iKelp:
			if iFeature == iOasis:
				iFeatureBonus = 10
			if iFeature == iFloodplains:
				iFeatureBonus = 5
			if iFeature == iScrubs:
			#removes all features
			if iFeature != iVolcano:
		#resource conversion
		iValidRes = 0
		if pPlot.getBonusType(-1)!=-1:
			if iBonus == iDeer or iBonus == iBison or iBonus == iCow or iBonus == iHorse:
				iResourceBonus = 15
				iValidRes = 1
			if iBonus == iRice or iBonus == iPig or iBonus == iSheep or iBonus == iCorn or iBonus == iWheat or iBonus == iBanana:
				iResourceBonus = 15
				iValidRes = 1
			if iBonus == iFur or iBonus == iReag or iBonus == iIncense or iBonus == iIvory:
				iResourceBonus = 25
				iValidRes = 1
			if iBonus == iTea or iBonus == iDye or iBonus == iSilk or iBonus == iSugar or iBonus == iWine or iBonus == iCotton:
				iResourceBonus = 20
				iValidRes = 1	
			#places Dark Ritual (not on peaks, volcanoes, water or dragon bones)
			if iValidRes == 1:
				if (iFeature != iVolcano) and (not pPlot.isPeak()) and (not iImprovement != gc.getInfoTypeForString('IMPROVEMENT_DRAGON_BONES')) and (not pPlot.isWater()):
		#overall bonus
		iTerraformingSoulIncome = iResourceBonus + iFeatureBonus + iTerrainConv

		return iTerraformingSoulIncome

my problem is that neither do i get the value of "iTerraformingSoulIncome" nor does it change the terrain. Does anybody know why the call of this function gets ignored? I hope it is not the pPlot that i try to pass to it.
AristrakhFunctions is a class but you need an instance of the class to call a normal method.
So either instantiate AristrakhFunctions or make doConsumeTerrain a static method (which is done with the @staticmethod decorator in Python afaik).
AristrakhFunctions is a class but you need an instance of the class to call a normal method.
can you elaborate further on this, i took working code from other python files and the only major difference as far as i can tell is that i try to pass pPlot.
i take everything back, the call does work i just have a lot of errors in the code because i split it up from one function, so i missed certain declarations. i guess coding while nearly asleep will do that.
Top Bottom