Getting Python to build a building

saltbush

Chieftain
Joined
Apr 29, 2006
Messages
50
I've been trying to make a trait that gives a free building to any city with 3 or more pop, which in itself is easy enough, however i can't seem to keep that seperate from another trait that gives a free building to any city with 8 or more pop

Code:
	def checkCityForTrait(self, argsList):
		city = argsList
		
		if (self.TolTrait < 0):
			for iTrait in range(gc.getNumTraitInfos()):
				if (gc.getTraitInfo(iTrait).getTextKey() == 'TXT_KEY_TRAIT_TOLERANT'):
					self.TolTrait = iTrait
		
		if (gc.getPlayer(city.getOwner()).hasTrait(self.TolTrait)):
			if (city.getPopulation() >7):
				if (self.TolBuilding < 0):
					for iBuild in range(gc.getNumBuildingInfos()):
						if (gc.getBuildingInfo(iBuild).getType() == 'BUILDING_TOLERANT'):
							self.TolBuilding = iBuild
				city.setHasRealBuilding(self.TolBuilding,1)
				#SevoMess("Added %s to %s" %(self.TolBuilding, city.getName()))


		if (self.civTrait < 0):
			for iTrait in range(gc.getNumTraitInfos()):
				if (gc.getTraitInfo(iTrait).getTextKey() == 'TXT_KEY_TRAIT_CIVIL'):
					self.civTrait = iTrait
		
		if (gc.getPlayer(city.getOwner()).hasTrait(self.civTrait)):
			if (city.getPopulation() >2):
				if (self.civBuilding < 0):
					for iBuild in range(gc.getNumBuildingInfos()):
						if (gc.getBuildingInfo(iBuild).getType() == 'BUILDING_CIVIL'):
							self.civBuilding = iBuild
				city.setHasRealBuilding(self.civBuilding,1)

They both work seperately but when put together any player with either trait gets the bonuses of both, so how can i seperate them and is it possible to have a civ with both traits still get both bonuses?

p.s credit go's to servomod for the tolerant bit of code,
 
Im having some trouble with that code (Im not a programmer so it may be that im just daft), I would use something like the following in onCityDoTurn:

Code:
	def onCityDoTurn(self, argsList):
		'City Production'
		pCity = argsList[0]
		iPlayer = argsList[1]
		pPlot = pCity.plot()
		pPlayer = gc.getPlayer(iPlayer)

		pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_TOLERANT'), False)
		if (pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_TOLERANT')) and pCity.getPopulation() > 7):
			pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_TOLERANT'), True)

		pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_CIVIL'), False)
		if (pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_CIVIL')) and pCity.getPopulation() > 2):
			pCity.setHasRealBuilding(gc.getInfoTypeForString('BUILDING_CIVIL'), True)

		CvAdvisorUtils.cityAdvise(pCity, iPlayer)

It just seems like similiar code to me. In this example the building dissappears if the city no longer complies with the requirements. If dfor exampel the city is taken over by someone who doesnt have the required trait or if the population drops beneath the required number.
 
thanks for that, seems to work much better, the conquest option was already covered by the building itself (can't be captured) although if a city was starved below its required pop it didn't loose the building, so your code not only works it has less errors :)
 
Top Bottom